* better
[mascara-docs.git] / i386 / linux-2.3.21 / include / linux / netdevice.h
blob75d6f872dd9e5d1f68c36fecd8f4cf484c5b62fd
1 /*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
6 * Definitions for the Interfaces handler.
8 * Version: @(#)dev.h 1.0.10 08/12/93
10 * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Corey Minyard <wf-rch!minyard@relay.EU.net>
13 * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov>
14 * Alan Cox, <Alan.Cox@linux.org>
15 * Bjorn Ekwall. <bj0rn@blox.se>
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
22 * Moved to /usr/include/linux for NET3
24 #ifndef _LINUX_NETDEVICE_H
25 #define _LINUX_NETDEVICE_H
27 #include <linux/config.h>
28 #include <linux/if.h>
29 #include <linux/if_ether.h>
30 #include <linux/if_packet.h>
32 #include <asm/atomic.h>
34 #ifdef __KERNEL__
35 #ifdef CONFIG_NET_PROFILE
36 #include <net/profile.h>
37 #endif
39 #define NET_XMIT_SUCCESS 0
40 #define NET_XMIT_DROP 1 /* skb dropped */
41 #define NET_XMIT_CN 2 /* congestion notification */
42 #define NET_XMIT_POLICED 3 /* skb is shot by police */
44 #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
46 #endif
48 #define MAX_ADDR_LEN 7 /* Largest hardware address length */
51 * Compute the worst case header length according to the protocols
52 * used.
55 #if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR)
56 #define LL_MAX_HEADER 32
57 #else
58 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
59 #define LL_MAX_HEADER 96
60 #else
61 #define LL_MAX_HEADER 48
62 #endif
63 #endif
65 #if !defined(CONFIG_NET_IPIP) && \
66 !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
67 #define MAX_HEADER LL_MAX_HEADER
68 #else
69 #define MAX_HEADER (LL_MAX_HEADER + 48)
70 #endif
73 * Network device statistics. Akin to the 2.0 ether stats but
74 * with byte counters.
77 struct net_device_stats
79 unsigned long rx_packets; /* total packets received */
80 unsigned long tx_packets; /* total packets transmitted */
81 unsigned long rx_bytes; /* total bytes received */
82 unsigned long tx_bytes; /* total bytes transmitted */
83 unsigned long rx_errors; /* bad packets received */
84 unsigned long tx_errors; /* packet transmit problems */
85 unsigned long rx_dropped; /* no space in linux buffers */
86 unsigned long tx_dropped; /* no space available in linux */
87 unsigned long multicast; /* multicast packets received */
88 unsigned long collisions;
90 /* detailed rx_errors: */
91 unsigned long rx_length_errors;
92 unsigned long rx_over_errors; /* receiver ring buff overflow */
93 unsigned long rx_crc_errors; /* recved pkt with crc error */
94 unsigned long rx_frame_errors; /* recv'd frame alignment error */
95 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
96 unsigned long rx_missed_errors; /* receiver missed packet */
98 /* detailed tx_errors */
99 unsigned long tx_aborted_errors;
100 unsigned long tx_carrier_errors;
101 unsigned long tx_fifo_errors;
102 unsigned long tx_heartbeat_errors;
103 unsigned long tx_window_errors;
105 /* for cslip etc */
106 unsigned long rx_compressed;
107 unsigned long tx_compressed;
110 #ifdef CONFIG_NET_FASTROUTE
111 struct net_fastroute_stats
113 int hits;
114 int succeed;
115 int deferred;
116 int latency_reduction;
118 #endif
120 /* Media selection options. */
121 enum {
122 IF_PORT_UNKNOWN = 0,
123 IF_PORT_10BASE2,
124 IF_PORT_10BASET,
125 IF_PORT_AUI,
126 IF_PORT_100BASET,
127 IF_PORT_100BASETX,
128 IF_PORT_100BASEFX
131 #ifdef __KERNEL__
133 extern const char *if_port_text[];
135 #include <linux/skbuff.h>
137 struct neighbour;
138 struct neigh_parms;
139 struct sk_buff;
142 * We tag multicasts with these structures.
145 struct dev_mc_list
147 struct dev_mc_list *next;
148 __u8 dmi_addr[MAX_ADDR_LEN];
149 unsigned char dmi_addrlen;
150 int dmi_users;
151 int dmi_gusers;
154 struct hh_cache
156 struct hh_cache *hh_next; /* Next entry */
157 atomic_t hh_refcnt; /* number of users */
158 unsigned short hh_type; /* protocol identifier, f.e ETH_P_IP */
159 int hh_len; /* length of header */
160 int (*hh_output)(struct sk_buff *skb);
161 rwlock_t hh_lock;
162 /* cached hardware header; allow for machine alignment needs. */
163 unsigned long hh_data[16/sizeof(unsigned long)];
168 * The DEVICE structure.
169 * Actually, this whole structure is a big mistake. It mixes I/O
170 * data with strictly "high-level" data, and it has to know about
171 * almost every data structure used in the INET module.
173 * FIXME: cleanup struct net_device such that network protocol info
174 * moves out.
177 struct net_device
181 * This is the first field of the "visible" part of this structure
182 * (i.e. as seen by users in the "Space.c" file). It is the name
183 * the interface.
185 char *name;
188 * I/O specific fields
189 * FIXME: Merge these and struct ifmap into one
191 unsigned long rmem_end; /* shmem "recv" end */
192 unsigned long rmem_start; /* shmem "recv" start */
193 unsigned long mem_end; /* shared mem end */
194 unsigned long mem_start; /* shared mem start */
195 unsigned long base_addr; /* device I/O address */
196 unsigned int irq; /* device IRQ number */
198 /* Low-level status flags. */
199 volatile unsigned char start; /* start an operation */
201 * These two are just single-bit flags, but due to atomicity
202 * reasons they have to be inside a "unsigned long". However,
203 * they should be inside the SAME unsigned long instead of
204 * this wasteful use of memory..
206 unsigned long interrupt; /* bitops.. */
207 unsigned long tbusy; /* transmitter busy */
209 struct net_device *next;
211 /* The device initialization function. Called only once. */
212 int (*init)(struct net_device *dev);
214 /* Interface index. Unique device identifier */
215 int ifindex;
216 int iflink;
219 * Some hardware also needs these fields, but they are not
220 * part of the usual set specified in Space.c.
223 unsigned char if_port; /* Selectable AUI, TP,..*/
224 unsigned char dma; /* DMA channel */
226 struct net_device_stats* (*get_stats)(struct net_device *dev);
227 struct iw_statistics* (*get_wireless_stats)(struct net_device *dev);
230 * This marks the end of the "visible" part of the structure. All
231 * fields hereafter are internal to the system, and may change at
232 * will (read: may be cleaned up at will).
235 /* These may be needed for future network-power-down code. */
236 unsigned long trans_start; /* Time (in jiffies) of last Tx */
237 unsigned long last_rx; /* Time of last Rx */
239 unsigned short flags; /* interface flags (a la BSD) */
240 unsigned short gflags;
241 unsigned mtu; /* interface MTU value */
242 unsigned short type; /* interface hardware type */
243 unsigned short hard_header_len; /* hardware hdr length */
244 void *priv; /* pointer to private data */
246 /* Interface address info. */
247 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */
248 unsigned char pad; /* make dev_addr aligned to 8 bytes */
249 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address */
250 unsigned char addr_len; /* hardware address length */
252 struct dev_mc_list *mc_list; /* Multicast mac addresses */
253 int mc_count; /* Number of installed mcasts */
254 int promiscuity;
255 int allmulti;
257 /* For load balancing driver pair support */
259 unsigned long pkt_queue; /* Packets queued */
260 struct net_device *slave; /* Slave device */
262 /* Protocol specific pointers */
264 void *atalk_ptr; /* AppleTalk link */
265 void *ip_ptr; /* IPv4 specific data */
266 void *dn_ptr; /* DECnet specific data */
267 void *ip6_ptr; /* IPv6 specific data */
269 struct Qdisc *qdisc;
270 struct Qdisc *qdisc_sleeping;
271 struct Qdisc *qdisc_list;
272 unsigned long tx_queue_len; /* Max frames per queue allowed */
274 /* hard_start_xmit synchronizer */
275 spinlock_t xmit_lock;
276 /* cpu id of processor entered to hard_start_xmit or -1,
277 if nobody entered there.
279 int xmit_lock_owner;
280 /* device queue lock */
281 spinlock_t queue_lock;
282 /* Number of references to this device */
283 atomic_t refcnt;
284 /* The flag marking that device is unregistered, but held by an user */
285 int deadbeaf;
286 /* New style devices allow asynchronous destruction;
287 netdevice_unregister for old style devices blocks until
288 the last user will dereference this device.
290 int new_style;
291 /* Called after device is detached from network. */
292 void (*uninit)(struct net_device *dev);
293 /* Called after last user reference disappears. */
294 void (*destructor)(struct net_device *dev);
296 /* Pointers to interface service routines. */
297 int (*open)(struct net_device *dev);
298 int (*stop)(struct net_device *dev);
299 int (*hard_start_xmit) (struct sk_buff *skb,
300 struct net_device *dev);
301 int (*hard_header) (struct sk_buff *skb,
302 struct net_device *dev,
303 unsigned short type,
304 void *daddr,
305 void *saddr,
306 unsigned len);
307 int (*rebuild_header)(struct sk_buff *skb);
308 #define HAVE_MULTICAST
309 void (*set_multicast_list)(struct net_device *dev);
310 #define HAVE_SET_MAC_ADDR
311 int (*set_mac_address)(struct net_device *dev,
312 void *addr);
313 #define HAVE_PRIVATE_IOCTL
314 int (*do_ioctl)(struct net_device *dev,
315 struct ifreq *ifr, int cmd);
316 #define HAVE_SET_CONFIG
317 int (*set_config)(struct net_device *dev,
318 struct ifmap *map);
319 #define HAVE_HEADER_CACHE
320 int (*hard_header_cache)(struct neighbour *neigh,
321 struct hh_cache *hh);
322 void (*header_cache_update)(struct hh_cache *hh,
323 struct net_device *dev,
324 unsigned char * haddr);
325 #define HAVE_CHANGE_MTU
326 int (*change_mtu)(struct net_device *dev, int new_mtu);
328 int (*hard_header_parse)(struct sk_buff *skb,
329 unsigned char *haddr);
330 int (*neigh_setup)(struct net_device *dev, struct neigh_parms *);
331 int (*accept_fastpath)(struct net_device *, struct dst_entry*);
333 #ifdef CONFIG_NET_FASTROUTE
334 unsigned long tx_semaphore;
335 #define NETDEV_FASTROUTE_HMASK 0xF
336 /* Semi-private data. Keep it at the end of device struct. */
337 rwlock_t fastpath_lock;
338 struct dst_entry *fastpath[NETDEV_FASTROUTE_HMASK+1];
339 #endif
343 struct packet_type
345 unsigned short type; /* This is really htons(ether_type). */
346 struct net_device *dev; /* NULL is wildcarded here */
347 int (*func) (struct sk_buff *, struct net_device *,
348 struct packet_type *);
349 void *data; /* Private to the packet type */
350 struct packet_type *next;
354 #include <linux/interrupt.h>
355 #include <linux/notifier.h>
357 extern struct net_device loopback_dev; /* The loopback */
358 extern struct net_device *dev_base; /* All devices */
359 extern rwlock_t dev_base_lock; /* Device list lock */
360 extern int netdev_dropping;
361 extern int net_cpu_congestion;
363 extern struct net_device *dev_getbyhwaddr(unsigned short type, char *hwaddr);
364 extern void dev_add_pack(struct packet_type *pt);
365 extern void dev_remove_pack(struct packet_type *pt);
366 extern int dev_get(const char *name);
367 extern struct net_device *dev_get_by_name(const char *name);
368 extern struct net_device *__dev_get_by_name(const char *name);
369 extern struct net_device *dev_alloc(const char *name, int *err);
370 extern int dev_alloc_name(struct net_device *dev, const char *name);
371 extern int dev_open(struct net_device *dev);
372 extern int dev_close(struct net_device *dev);
373 extern int dev_queue_xmit(struct sk_buff *skb);
374 extern void dev_loopback_xmit(struct sk_buff *skb);
375 extern int register_netdevice(struct net_device *dev);
376 extern int unregister_netdevice(struct net_device *dev);
377 extern int register_netdevice_notifier(struct notifier_block *nb);
378 extern int unregister_netdevice_notifier(struct notifier_block *nb);
379 extern int dev_new_index(void);
380 extern struct net_device *dev_get_by_index(int ifindex);
381 extern struct net_device *__dev_get_by_index(int ifindex);
382 extern int dev_restart(struct net_device *dev);
384 typedef int gifconf_func_t(struct net_device * dev, char * bufptr, int len);
385 extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf);
386 extern __inline__ int unregister_gifconf(unsigned int family)
388 return register_gifconf(family, 0);
391 #define HAVE_NETIF_RX 1
392 extern void netif_rx(struct sk_buff *skb);
393 extern void net_bh(void);
394 extern int dev_get_info(char *buffer, char **start, off_t offset, int length, int dummy);
395 extern int dev_ioctl(unsigned int cmd, void *);
396 extern int dev_change_flags(struct net_device *, unsigned);
397 extern void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
399 extern void dev_init(void);
401 extern int netdev_nit;
403 extern __inline__ void dev_init_buffers(struct net_device *dev)
405 /* DO NOTHING */
408 extern int netdev_finish_unregister(struct net_device *dev);
410 extern __inline__ void dev_put(struct net_device *dev)
412 if (atomic_dec_and_test(&dev->refcnt))
413 netdev_finish_unregister(dev);
416 #define __dev_put(dev) atomic_dec(&(dev)->refcnt)
417 #define dev_hold(dev) atomic_inc(&(dev)->refcnt)
420 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
422 extern void ether_setup(struct net_device *dev);
423 extern void fddi_setup(struct net_device *dev);
424 extern void tr_setup(struct net_device *dev);
425 extern void fc_setup(struct net_device *dev);
426 extern void tr_freedev(struct net_device *dev);
427 extern void fc_freedev(struct net_device *dev);
428 extern int ether_config(struct net_device *dev, struct ifmap *map);
429 /* Support for loadable net-drivers */
430 extern int register_netdev(struct net_device *dev);
431 extern void unregister_netdev(struct net_device *dev);
432 extern int register_trdev(struct net_device *dev);
433 extern void unregister_trdev(struct net_device *dev);
434 extern int register_fcdev(struct net_device *dev);
435 extern void unregister_fcdev(struct net_device *dev);
436 /* Functions used for multicast support */
437 extern void dev_mc_upload(struct net_device *dev);
438 extern int dev_mc_delete(struct net_device *dev, void *addr, int alen, int all);
439 extern int dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly);
440 extern void dev_mc_discard(struct net_device *dev);
441 extern void dev_set_promiscuity(struct net_device *dev, int inc);
442 extern void dev_set_allmulti(struct net_device *dev, int inc);
443 extern void netdev_state_change(struct net_device *dev);
444 /* Load a device via the kmod */
445 extern void dev_load(const char *name);
446 extern void dev_mcast_init(void);
447 extern int netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev));
448 extern void netdev_unregister_fc(int bit);
449 extern int netdev_dropping;
450 extern int netdev_max_backlog;
451 extern atomic_t netdev_rx_dropped;
452 extern unsigned long netdev_fc_xoff;
453 #ifdef CONFIG_NET_FASTROUTE
454 extern int netdev_fastroute;
455 extern int netdev_fastroute_obstacles;
456 extern void dev_clear_fastroute(struct net_device *dev);
457 extern struct net_fastroute_stats dev_fastroute_stat;
458 #endif
461 #endif /* __KERNEL__ */
463 #endif /* _LINUX_DEV_H */