Xenomai  3.0.8
rtdev.h
1 /***
2  *
3  * rtdev.h
4  *
5  * RTnet - real-time networking subsystem
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  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  */
25 
26 #ifndef __RTDEV_H_
27 #define __RTDEV_H_
28 
29 #define MAX_RT_DEVICES 8
30 
31 
32 #ifdef __KERNEL__
33 
34 #include <asm/atomic.h>
35 #include <linux/netdevice.h>
36 
37 #include <rtskb.h>
38 #include <rtnet_internal.h>
39 
40 #define RTDEV_VERS_2_0 0x0200
41 
42 #define PRIV_FLAG_UP 0
43 #define PRIV_FLAG_ADDING_ROUTE 1
44 
45 #ifndef NETIF_F_LLTX
46 #define NETIF_F_LLTX 4096
47 #endif
48 
49 #define RTDEV_TX_OK 0
50 #define RTDEV_TX_BUSY 1
51 
52 enum rtnet_link_state {
53  __RTNET_LINK_STATE_XOFF = 0,
54  __RTNET_LINK_STATE_START,
55  __RTNET_LINK_STATE_PRESENT,
56  __RTNET_LINK_STATE_NOCARRIER,
57 };
58 #define RTNET_LINK_STATE_XOFF (1 << __RTNET_LINK_STATE_XOFF)
59 #define RTNET_LINK_STATE_START (1 << __RTNET_LINK_STATE_START)
60 #define RTNET_LINK_STATE_PRESENT (1 << __RTNET_LINK_STATE_PRESENT)
61 #define RTNET_LINK_STATE_NOCARRIER (1 << __RTNET_LINK_STATE_NOCARRIER)
62 
63 /***
64  * rtnet_device
65  */
66 struct rtnet_device {
67  /* Many field are borrowed from struct net_device in
68  * <linux/netdevice.h> - WY
69  */
70  unsigned int vers;
71 
72  char name[IFNAMSIZ];
73 
74  unsigned long rmem_end; /* shmem "recv" end */
75  unsigned long rmem_start; /* shmem "recv" start */
76  unsigned long mem_end; /* shared mem end */
77  unsigned long mem_start; /* shared mem start */
78  unsigned long base_addr; /* device I/O address */
79  unsigned int irq; /* device IRQ number */
80 
81  /*
82  * Some hardware also needs these fields, but they are not
83  * part of the usual set specified in Space.c.
84  */
85  unsigned char if_port; /* Selectable AUI, TP,..*/
86  unsigned char dma; /* DMA channel */
87  __u16 __padding;
88 
89  unsigned long link_state;
90  int ifindex;
91  atomic_t refcount;
92 
93  struct module *rt_owner; /* like classic owner, but *
94  * forces correct macro usage */
95 
96  unsigned int flags; /* interface flags (a la BSD) */
97  unsigned long priv_flags; /* internal flags */
98  unsigned short type; /* interface hardware type */
99  unsigned short hard_header_len; /* hardware hdr length */
100  unsigned int mtu; /* eth = 1536, tr = 4... */
101  void *priv; /* pointer to private data */
102  netdev_features_t features; /* [RT]NETIF_F_* */
103 
104  /* Interface address info. */
105  unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */
106  unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address */
107  unsigned char addr_len; /* hardware address length */
108 
109  int promiscuity;
110  int allmulti;
111 
112  __u32 local_ip; /* IP address in network order */
113  __u32 broadcast_ip; /* broadcast IP in network order */
114 
115  rtdm_event_t *stack_event;
116 
117  rtdm_mutex_t xmit_mutex; /* protects xmit routine */
118  rtdm_lock_t rtdev_lock; /* management lock */
119  struct mutex nrt_lock; /* non-real-time locking */
120 
121  unsigned int add_rtskbs; /* additionally allocated global rtskbs */
122 
123  struct rtskb_pool dev_pool;
124 
125  /* RTmac related fields */
126  struct rtmac_disc *mac_disc;
127  struct rtmac_priv *mac_priv;
128  int (*mac_detach)(struct rtnet_device *rtdev);
129 
130  /* Device operations */
131  int (*open)(struct rtnet_device *rtdev);
132  int (*stop)(struct rtnet_device *rtdev);
133  int (*hard_header)(struct rtskb *, struct rtnet_device *,
134  unsigned short type, void *daddr,
135  void *saddr, unsigned int len);
136  int (*rebuild_header)(struct rtskb *);
137  int (*hard_start_xmit)(struct rtskb *skb,
138  struct rtnet_device *dev);
139  int (*hw_reset)(struct rtnet_device *rtdev);
140 
141  /* Transmission hook, managed by the stack core, RTcap, and RTmac
142  *
143  * If xmit_lock is used, start_xmit points either to rtdev_locked_xmit or
144  * the RTmac discipline handler. If xmit_lock is not required, start_xmit
145  * points to hard_start_xmit or the discipline handler.
146  */
147  int (*start_xmit)(struct rtskb *skb,
148  struct rtnet_device *dev);
149 
150  /* MTU hook, managed by the stack core and RTmac */
151  unsigned int (*get_mtu)(struct rtnet_device *rtdev,
152  unsigned int priority);
153 
154  int (*do_ioctl)(struct rtnet_device *rtdev,
155  struct ifreq *ifr, int cmd);
156  struct net_device_stats *(*get_stats)(struct rtnet_device *rtdev);
157 
158  /* DMA pre-mapping hooks */
159  dma_addr_t (*map_rtskb)(struct rtnet_device *rtdev,
160  struct rtskb *skb);
161  void (*unmap_rtskb)(struct rtnet_device *rtdev,
162  struct rtskb *skb);
163 };
164 
165 struct rtnet_core_cmd;
166 
167 struct rtdev_event_hook {
168  struct list_head entry;
169  void (*register_device)(struct rtnet_device *rtdev);
170  void (*unregister_device)(struct rtnet_device *rtdev);
171  void (*ifup)(struct rtnet_device *rtdev,
172  struct rtnet_core_cmd *up_cmd);
173  void (*ifdown)(struct rtnet_device *rtdev);
174 };
175 
176 extern struct list_head event_hook_list;
177 extern struct mutex rtnet_devices_nrt_lock;
178 extern struct rtnet_device *rtnet_devices[];
179 
180 
181 struct rtnet_device *__rt_alloc_etherdev(unsigned sizeof_priv,
182  unsigned dev_pool_size,
183  struct module *module);
184 #define rt_alloc_etherdev(priv_size, rx_size) \
185  __rt_alloc_etherdev(priv_size, rx_size, THIS_MODULE)
186 
187 void rtdev_free(struct rtnet_device *rtdev);
188 
189 int rt_register_rtnetdev(struct rtnet_device *rtdev);
190 int rt_unregister_rtnetdev(struct rtnet_device *rtdev);
191 
192 void rtdev_add_event_hook(struct rtdev_event_hook *hook);
193 void rtdev_del_event_hook(struct rtdev_event_hook *hook);
194 
195 void rtdev_alloc_name (struct rtnet_device *rtdev, const char *name_mask);
196 
202 static inline struct rtnet_device *__rtdev_get_by_index(int ifindex)
203 {
204  return rtnet_devices[ifindex-1];
205 }
206 
207 struct rtnet_device *rtdev_get_by_name(const char *if_name);
208 struct rtnet_device *rtdev_get_by_index(int ifindex);
209 struct rtnet_device *rtdev_get_by_hwaddr(unsigned short type,char *ha);
210 struct rtnet_device *rtdev_get_loopback(void);
211 
212 int rtdev_reference(struct rtnet_device *rtdev);
213 
214 static inline void rtdev_dereference(struct rtnet_device *rtdev)
215 {
216  smp_mb__before_atomic();
217  if (rtdev->rt_owner && atomic_dec_and_test(&rtdev->refcount))
218  module_put(rtdev->rt_owner);
219 }
220 
221 int rtdev_xmit(struct rtskb *skb);
222 
223 #if IS_ENABLED(CONFIG_XENO_DRIVERS_NET_ADDON_PROXY)
224 int rtdev_xmit_proxy(struct rtskb *skb);
225 #endif
226 
227 unsigned int rt_hard_mtu(struct rtnet_device *rtdev, unsigned int priority);
228 
229 int rtdev_open(struct rtnet_device *rtdev);
230 int rtdev_close(struct rtnet_device *rtdev);
231 
232 int rtdev_map_rtskb(struct rtskb *skb);
233 void rtdev_unmap_rtskb(struct rtskb *skb);
234 
235 struct rtskb *rtnetdev_alloc_rtskb(struct rtnet_device *dev, unsigned int size);
236 
237 #define rtnetdev_priv(dev) ((dev)->priv)
238 
239 #define rtdev_emerg(__dev, format, args...) \
240  pr_emerg("%s: " format, (__dev)->name, ##args)
241 #define rtdev_alert(__dev, format, args...) \
242  pr_alert("%s: " format, (__dev)->name, ##args)
243 #define rtdev_crit(__dev, format, args...) \
244  pr_crit("%s: " format, (__dev)->name, ##args)
245 #define rtdev_err(__dev, format, args...) \
246  pr_err("%s: " format, (__dev)->name, ##args)
247 #define rtdev_warn(__dev, format, args...) \
248  pr_warn("%s: " format, (__dev)->name, ##args)
249 #define rtdev_notice(__dev, format, args...) \
250  pr_notice("%s: " format, (__dev)->name, ##args)
251 #define rtdev_info(__dev, format, args...) \
252  pr_info("%s: " format, (__dev)->name, ##args)
253 #define rtdev_dbg(__dev, format, args...) \
254  pr_debug("%s: " format, (__dev)->name, ##args)
255 
256 #ifdef VERBOSE_DEBUG
257 #define rtdev_vdbg rtdev_dbg
258 #else
259 #define rtdev_vdbg(__dev, format, args...) \
260 ({ \
261  if (0) \
262  pr_debug("%s: " format, (__dev)->name, ##args); \
263  \
264  0; \
265 })
266 #endif
267 
268 #endif /* __KERNEL__ */
269 
270 #endif /* __RTDEV_H_ */
ipipe_spinlock_t rtdm_lock_t
Lock variable.
Definition: driver.h:551
Copyright © 2011 Gilles Chanteperdrix gilles.chanteperdrix@xenomai.org.
Definition: atomic.h:24