Xenomai 3.3.2
Loading...
Searching...
No Matches
rtcan_dev.h
1/*
2 * Copyright (C) 2006 Wolfgang Grandegger <wg@grandegger.com>
3 *
4 * Derived from RTnet project file stack/include/rtdev.h:
5 *
6 * Copyright (C) 1999 Lineo, Inc
7 * 1999, 2002 David A. Schleef <ds@schleef.org>
8 * 2003-2005 Jan Kiszka <jan.kiszka@web.de>
9 *
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#ifndef __RTCAN_DEV_H_
27#define __RTCAN_DEV_H_
28
29
30#ifdef __KERNEL__
31
32#include <asm/atomic.h>
33#include <linux/mutex.h>
34#include <linux/netdevice.h>
35
36#include "rtcan_list.h"
37#include "rtcan_ethtool.h"
38
39/* Number of MSCAN devices the driver can handle */
40#define RTCAN_MAX_DEVICES CONFIG_XENO_DRIVERS_CAN_MAX_DEVICES
41
42/* Maximum number of single filters per controller which can be registered
43 * for reception at the same time using Bind */
44#define RTCAN_MAX_RECEIVERS CONFIG_XENO_DRIVERS_CAN_MAX_RECEIVERS
45
46/* Suppress handling of refcount if module support is not enabled
47 * or modules cannot be unloaded */
48
49#if defined(CONFIG_MODULES) && defined(CONFIG_MODULE_UNLOAD)
50#define RTCAN_USE_REFCOUNT
51#endif
52
53/*
54 * CAN harware-dependent bit-timing constant
55 *
56 * Used for calculating and checking bit-timing parameters
57 */
58struct can_bittiming_const {
59 char name[16]; /* Name of the CAN controller hardware */
60 __u32 tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */
61 __u32 tseg1_max;
62 __u32 tseg2_min; /* Time segement 2 = phase_seg2 */
63 __u32 tseg2_max;
64 __u32 sjw_max; /* Synchronisation jump width */
65 __u32 brp_min; /* Bit-rate prescaler */
66 __u32 brp_max;
67 __u32 brp_inc;
68};
69
70struct rtcan_device {
71 unsigned int version;
72
73 char name[IFNAMSIZ];
74
75 char *ctrl_name; /* Name of CAN controller */
76 char *board_name;/* Name of CAN board */
77
78 unsigned long base_addr; /* device I/O address */
79 rtdm_irq_t irq_handle; /* RTDM IRQ handle */
80
81 int ifindex;
82#ifdef RTCAN_USE_REFCOUNT
83 atomic_t refcount;
84#endif
85
86 void *priv; /* pointer to chip private data */
87
88 void *board_priv;/* pointer to board private data*/
89
90 struct semaphore nrt_lock; /* non-real-time locking */
91
92 /* Spinlock for all devices (but not for all attributes) and also for HW
93 * access to all CAN controllers
94 */
95 rtdm_lock_t device_lock;
96
97 /* Acts as a mutex allowing only one sender to write to the MSCAN
98 * simultaneously. Created when the controller goes into operating mode,
99 * destroyed if it goes into reset mode. */
100 rtdm_sem_t tx_sem;
101
102 /* Baudrate of this device. Protected by device_lock in all device
103 * structures. */
104 unsigned int can_sys_clock;
105
106
107 /* Baudrate of this device. Protected by device_lock in all device
108 * structures. */
109 can_baudrate_t baudrate;
110
111 struct can_bittime bit_time;
112 const struct can_bittiming_const *bittiming_const;
113
114 /* State which the controller is in. Protected by device_lock in all
115 * device structures. */
116 can_state_t state;
117
118 /* State which the controller was before sleeping. Protected by
119 * device_lock in all device structures. */
120 can_state_t state_before_sleep;
121
122 /* Controller specific settings. Protected by device_lock in all
123 * device structures. */
124 can_ctrlmode_t ctrl_mode;
125
126 /* Device operations */
127 int (*hard_start_xmit)(struct rtcan_device *dev,
128 struct can_frame *frame);
129 int (*do_set_mode)(struct rtcan_device *dev,
130 can_mode_t mode,
131 rtdm_lockctx_t *lock_ctx);
132 can_state_t (*do_get_state)(struct rtcan_device *dev);
133 int (*do_set_bit_time)(struct rtcan_device *dev,
134 struct can_bittime *bit_time,
135 rtdm_lockctx_t *lock_ctx);
136#ifdef CONFIG_XENO_DRIVERS_CAN_BUS_ERR
137 void (*do_enable_bus_err)(struct rtcan_device *dev);
138#endif
139
140 const struct rtcan_ethtool_ops *ethtool_ops;
141
142 /* Reception list head. This list contains all filters which have been
143 * registered via a bind call. */
144 struct rtcan_recv *recv_list;
145
146 /* Empty list head. This list contains all empty entries not needed
147 * by the reception list and therefore is disjunctive with it. */
148 struct rtcan_recv *empty_list;
149
150 /* Preallocated array for the list entries. To increase cache
151 * locality all list elements are kept in this array. */
152 struct rtcan_recv receivers[RTCAN_MAX_RECEIVERS];
153
154 /* Indicates the length of the empty list */
155 int free_entries;
156
157 /* A few statistics counters */
158 unsigned int tx_count;
159 unsigned int rx_count;
160 unsigned int err_count;
161
162#ifdef CONFIG_PROC_FS
163 struct proc_dir_entry *proc_root;
164#endif
165#ifdef CONFIG_XENO_DRIVERS_CAN_LOOPBACK
166 struct rtcan_skb tx_skb;
167 struct rtcan_socket *tx_socket;
168#endif /* CONFIG_XENO_DRIVERS_CAN_LOOPBACK */
169};
170
171
172extern struct mutex rtcan_devices_nrt_lock;
173
174
175void rtcan_dev_free(struct rtcan_device *dev);
176
177int rtcan_dev_register(struct rtcan_device *dev);
178int rtcan_dev_unregister(struct rtcan_device *dev);
179
180struct rtcan_device *rtcan_dev_alloc(int sizeof_priv, int sizeof_board_priv);
181void rtcan_dev_alloc_name (struct rtcan_device *dev, const char *name_mask);
182
183struct rtcan_device *rtcan_dev_get_by_name(const char *if_name);
184struct rtcan_device *rtcan_dev_get_by_index(int ifindex);
185
186#ifdef RTCAN_USE_REFCOUNT
187#define rtcan_dev_reference(dev) atomic_inc(&(dev)->refcount)
188#define rtcan_dev_dereference(dev) atomic_dec(&(dev)->refcount)
189#else
190#define rtcan_dev_reference(dev) do {} while(0)
191#define rtcan_dev_dereference(dev) do {} while(0)
192#endif
193
194#ifdef CONFIG_PROC_FS
195int rtcan_dev_create_proc(struct rtcan_device* dev);
196void rtcan_dev_remove_proc(struct rtcan_device* dev);
197#else /* !CONFIG_PROC_FS */
198static inline int rtcan_dev_create_proc(struct rtcan_device* dev)
199{
200 return 0;
201}
202static inline void rtcan_dev_remove_proc(struct rtcan_device* dev) { }
203#endif /* !CONFIG_PROC_FS */
204
205#endif /* __KERNEL__ */
206
207#endif /* __RTCAN_DEV_H_ */
enum CAN_STATE can_state_t
See CAN_STATE.
Definition can.h:258
uint32_t can_baudrate_t
Baudrate definition in bits per second.
Definition can.h:110
enum CAN_MODE can_mode_t
See CAN_MODE.
Definition can.h:187
int can_ctrlmode_t
See CAN_CTRLMODE.
Definition can.h:221
unsigned long rtdm_lockctx_t
Variable to save the context while holding a lock.
Definition driver.h:555
pipeline_spinlock_t rtdm_lock_t
Lock variable.
Definition driver.h:552
Copyright © 2011 Gilles Chanteperdrix gilles.chanteperdrix@xenomai.org.
Definition atomic.h:24
Custom CAN bit-time definition.
Definition can.h:151
Raw CAN frame.
Definition can.h:313