Ok, test10-final is out there now. This has no _known_ bugs that I
[davej-history.git] / include / linux / netdevice.h
blob32677edae7d04fc1e0853fad5a84dc6d5a8a9c99
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>
16 * Pekka Riikonen <priikone@poseidon.pspt.fi>
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
23 * Moved to /usr/include/linux for NET3
25 #ifndef _LINUX_NETDEVICE_H
26 #define _LINUX_NETDEVICE_H
28 #include <linux/if.h>
29 #include <linux/if_ether.h>
30 #include <linux/if_packet.h>
32 #include <asm/atomic.h>
33 #include <asm/cache.h>
34 #include <asm/byteorder.h>
36 #ifdef __KERNEL__
37 #include <linux/config.h>
38 #ifdef CONFIG_NET_PROFILE
39 #include <net/profile.h>
40 #endif
42 struct divert_blk;
44 #define NET_XMIT_SUCCESS 0
45 #define NET_XMIT_DROP 1 /* skb dropped */
46 #define NET_XMIT_CN 2 /* congestion notification */
47 #define NET_XMIT_POLICED 3 /* skb is shot by police */
48 #define NET_XMIT_BYPASS 4 /* packet does not leave via dequeue;
49 (TC use only - dev_queue_xmit
50 returns this as NET_XMIT_SUCCESS) */
52 /* Backlog congestion levels */
53 #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
54 #define NET_RX_CN_LOW 1 /* storm alert, just in case */
55 #define NET_RX_CN_MOD 2 /* Storm on its way! */
56 #define NET_RX_CN_HIGH 5 /* The storm is here */
57 #define NET_RX_DROP -1 /* packet dropped */
58 #define NET_RX_BAD -2 /* packet dropped due to kernel error */
60 #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
62 #endif
64 #define MAX_ADDR_LEN 7 /* Largest hardware address length */
67 * Compute the worst case header length according to the protocols
68 * used.
71 #if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR)
72 #define LL_MAX_HEADER 32
73 #else
74 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
75 #define LL_MAX_HEADER 96
76 #else
77 #define LL_MAX_HEADER 48
78 #endif
79 #endif
81 #if !defined(CONFIG_NET_IPIP) && \
82 !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
83 #define MAX_HEADER LL_MAX_HEADER
84 #else
85 #define MAX_HEADER (LL_MAX_HEADER + 48)
86 #endif
89 * Network device statistics. Akin to the 2.0 ether stats but
90 * with byte counters.
93 struct net_device_stats
95 unsigned long rx_packets; /* total packets received */
96 unsigned long tx_packets; /* total packets transmitted */
97 unsigned long rx_bytes; /* total bytes received */
98 unsigned long tx_bytes; /* total bytes transmitted */
99 unsigned long rx_errors; /* bad packets received */
100 unsigned long tx_errors; /* packet transmit problems */
101 unsigned long rx_dropped; /* no space in linux buffers */
102 unsigned long tx_dropped; /* no space available in linux */
103 unsigned long multicast; /* multicast packets received */
104 unsigned long collisions;
106 /* detailed rx_errors: */
107 unsigned long rx_length_errors;
108 unsigned long rx_over_errors; /* receiver ring buff overflow */
109 unsigned long rx_crc_errors; /* recved pkt with crc error */
110 unsigned long rx_frame_errors; /* recv'd frame alignment error */
111 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
112 unsigned long rx_missed_errors; /* receiver missed packet */
114 /* detailed tx_errors */
115 unsigned long tx_aborted_errors;
116 unsigned long tx_carrier_errors;
117 unsigned long tx_fifo_errors;
118 unsigned long tx_heartbeat_errors;
119 unsigned long tx_window_errors;
121 /* for cslip etc */
122 unsigned long rx_compressed;
123 unsigned long tx_compressed;
127 /* Media selection options. */
128 enum {
129 IF_PORT_UNKNOWN = 0,
130 IF_PORT_10BASE2,
131 IF_PORT_10BASET,
132 IF_PORT_AUI,
133 IF_PORT_100BASET,
134 IF_PORT_100BASETX,
135 IF_PORT_100BASEFX
138 #ifdef __KERNEL__
140 extern const char *if_port_text[];
142 #include <linux/cache.h>
143 #include <linux/skbuff.h>
145 struct neighbour;
146 struct neigh_parms;
147 struct sk_buff;
149 struct netif_rx_stats
151 unsigned total;
152 unsigned dropped;
153 unsigned time_squeeze;
154 unsigned throttled;
155 unsigned fastroute_hit;
156 unsigned fastroute_success;
157 unsigned fastroute_defer;
158 unsigned fastroute_deferred_out;
159 unsigned fastroute_latency_reduction;
160 unsigned cpu_collision;
161 } __attribute__ ((__aligned__(SMP_CACHE_BYTES)));
163 extern struct netif_rx_stats netdev_rx_stat[];
167 * We tag multicasts with these structures.
170 struct dev_mc_list
172 struct dev_mc_list *next;
173 __u8 dmi_addr[MAX_ADDR_LEN];
174 unsigned char dmi_addrlen;
175 int dmi_users;
176 int dmi_gusers;
179 struct hh_cache
181 struct hh_cache *hh_next; /* Next entry */
182 atomic_t hh_refcnt; /* number of users */
183 unsigned short hh_type; /* protocol identifier, f.e ETH_P_IP */
184 int hh_len; /* length of header */
185 int (*hh_output)(struct sk_buff *skb);
186 rwlock_t hh_lock;
187 /* cached hardware header; allow for machine alignment needs. */
188 unsigned long hh_data[16/sizeof(unsigned long)];
191 /* These flag bits are private to the generic network queueing
192 * layer, they may not be explicitly referenced by any other
193 * code.
196 enum netdev_state_t
198 __LINK_STATE_XOFF=0,
199 __LINK_STATE_START,
200 __LINK_STATE_PRESENT,
201 __LINK_STATE_SCHED,
202 __LINK_STATE_NOCARRIER
207 * This structure holds at boot time configured netdevice settings. They
208 * are then used in the device probing.
210 struct netdev_boot_setup {
211 char name[IFNAMSIZ];
212 struct ifmap map;
214 #define NETDEV_BOOT_SETUP_MAX 8
218 * The DEVICE structure.
219 * Actually, this whole structure is a big mistake. It mixes I/O
220 * data with strictly "high-level" data, and it has to know about
221 * almost every data structure used in the INET module.
223 * FIXME: cleanup struct net_device such that network protocol info
224 * moves out.
227 struct net_device
231 * This is the first field of the "visible" part of this structure
232 * (i.e. as seen by users in the "Space.c" file). It is the name
233 * the interface.
235 char name[IFNAMSIZ];
238 * I/O specific fields
239 * FIXME: Merge these and struct ifmap into one
241 unsigned long rmem_end; /* shmem "recv" end */
242 unsigned long rmem_start; /* shmem "recv" start */
243 unsigned long mem_end; /* shared mem end */
244 unsigned long mem_start; /* shared mem start */
245 unsigned long base_addr; /* device I/O address */
246 unsigned int irq; /* device IRQ number */
249 * Some hardware also needs these fields, but they are not
250 * part of the usual set specified in Space.c.
253 unsigned char if_port; /* Selectable AUI, TP,..*/
254 unsigned char dma; /* DMA channel */
256 unsigned long state;
258 struct net_device *next;
260 /* The device initialization function. Called only once. */
261 int (*init)(struct net_device *dev);
263 /* ------- Fields preinitialized in Space.c finish here ------- */
265 struct net_device *next_sched;
267 /* Interface index. Unique device identifier */
268 int ifindex;
269 int iflink;
272 struct net_device_stats* (*get_stats)(struct net_device *dev);
273 struct iw_statistics* (*get_wireless_stats)(struct net_device *dev);
276 * This marks the end of the "visible" part of the structure. All
277 * fields hereafter are internal to the system, and may change at
278 * will (read: may be cleaned up at will).
281 /* These may be needed for future network-power-down code. */
282 unsigned long trans_start; /* Time (in jiffies) of last Tx */
283 unsigned long last_rx; /* Time of last Rx */
285 unsigned short flags; /* interface flags (a la BSD) */
286 unsigned short gflags;
287 unsigned mtu; /* interface MTU value */
288 unsigned short type; /* interface hardware type */
289 unsigned short hard_header_len; /* hardware hdr length */
290 void *priv; /* pointer to private data */
292 struct net_device *master; /* Pointer to master device of a group,
293 * which this device is member of.
296 /* Interface address info. */
297 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */
298 unsigned char pad; /* make dev_addr aligned to 8 bytes */
299 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address */
300 unsigned char addr_len; /* hardware address length */
302 struct dev_mc_list *mc_list; /* Multicast mac addresses */
303 int mc_count; /* Number of installed mcasts */
304 int promiscuity;
305 int allmulti;
307 int watchdog_timeo;
308 struct timer_list watchdog_timer;
310 /* Protocol specific pointers */
312 void *atalk_ptr; /* AppleTalk link */
313 void *ip_ptr; /* IPv4 specific data */
314 void *dn_ptr; /* DECnet specific data */
315 void *ip6_ptr; /* IPv6 specific data */
316 void *ec_ptr; /* Econet specific data */
318 struct Qdisc *qdisc;
319 struct Qdisc *qdisc_sleeping;
320 struct Qdisc *qdisc_list;
321 struct Qdisc *qdisc_ingress;
322 unsigned long tx_queue_len; /* Max frames per queue allowed */
324 /* hard_start_xmit synchronizer */
325 spinlock_t xmit_lock;
326 /* cpu id of processor entered to hard_start_xmit or -1,
327 if nobody entered there.
329 int xmit_lock_owner;
330 /* device queue lock */
331 spinlock_t queue_lock;
332 /* Number of references to this device */
333 atomic_t refcnt;
334 /* The flag marking that device is unregistered, but held by an user */
335 int deadbeaf;
336 /* New style devices allow asynchronous destruction;
337 netdevice_unregister for old style devices blocks until
338 the last user will dereference this device.
340 int new_style;
341 /* Called after device is detached from network. */
342 void (*uninit)(struct net_device *dev);
343 /* Called after last user reference disappears. */
344 void (*destructor)(struct net_device *dev);
346 /* Pointers to interface service routines. */
347 int (*open)(struct net_device *dev);
348 int (*stop)(struct net_device *dev);
349 int (*hard_start_xmit) (struct sk_buff *skb,
350 struct net_device *dev);
351 int (*hard_header) (struct sk_buff *skb,
352 struct net_device *dev,
353 unsigned short type,
354 void *daddr,
355 void *saddr,
356 unsigned len);
357 int (*rebuild_header)(struct sk_buff *skb);
358 #define HAVE_MULTICAST
359 void (*set_multicast_list)(struct net_device *dev);
360 #define HAVE_SET_MAC_ADDR
361 int (*set_mac_address)(struct net_device *dev,
362 void *addr);
363 #define HAVE_PRIVATE_IOCTL
364 int (*do_ioctl)(struct net_device *dev,
365 struct ifreq *ifr, int cmd);
366 #define HAVE_SET_CONFIG
367 int (*set_config)(struct net_device *dev,
368 struct ifmap *map);
369 #define HAVE_HEADER_CACHE
370 int (*hard_header_cache)(struct neighbour *neigh,
371 struct hh_cache *hh);
372 void (*header_cache_update)(struct hh_cache *hh,
373 struct net_device *dev,
374 unsigned char * haddr);
375 #define HAVE_CHANGE_MTU
376 int (*change_mtu)(struct net_device *dev, int new_mtu);
378 #define HAVE_TX_TIMEOUT
379 void (*tx_timeout) (struct net_device *dev);
381 int (*hard_header_parse)(struct sk_buff *skb,
382 unsigned char *haddr);
383 int (*neigh_setup)(struct net_device *dev, struct neigh_parms *);
384 int (*accept_fastpath)(struct net_device *, struct dst_entry*);
386 /* bridge stuff */
387 struct net_bridge_port *br_port;
389 #ifdef CONFIG_NET_FASTROUTE
390 #define NETDEV_FASTROUTE_HMASK 0xF
391 /* Semi-private data. Keep it at the end of device struct. */
392 rwlock_t fastpath_lock;
393 struct dst_entry *fastpath[NETDEV_FASTROUTE_HMASK+1];
394 #endif
395 #ifdef CONFIG_NET_DIVERT
396 /* this will get initialized at each interface type init routine */
397 struct divert_blk *divert;
398 #endif /* CONFIG_NET_DIVERT */
402 struct packet_type
404 unsigned short type; /* This is really htons(ether_type). */
405 struct net_device *dev; /* NULL is wildcarded here */
406 int (*func) (struct sk_buff *, struct net_device *,
407 struct packet_type *);
408 void *data; /* Private to the packet type */
409 struct packet_type *next;
413 #include <linux/interrupt.h>
414 #include <linux/notifier.h>
416 extern struct net_device loopback_dev; /* The loopback */
417 extern struct net_device *dev_base; /* All devices */
418 extern rwlock_t dev_base_lock; /* Device list lock */
420 extern int netdev_boot_setup_add(char *name, struct ifmap *map);
421 extern int netdev_boot_setup_check(struct net_device *dev);
422 extern struct net_device *dev_getbyhwaddr(unsigned short type, char *hwaddr);
423 extern void dev_add_pack(struct packet_type *pt);
424 extern void dev_remove_pack(struct packet_type *pt);
425 extern int dev_get(const char *name);
426 extern struct net_device *dev_get_by_name(const char *name);
427 extern struct net_device *__dev_get_by_name(const char *name);
428 extern struct net_device *dev_alloc(const char *name, int *err);
429 extern int dev_alloc_name(struct net_device *dev, const char *name);
430 extern int dev_open(struct net_device *dev);
431 extern int dev_close(struct net_device *dev);
432 extern int dev_queue_xmit(struct sk_buff *skb);
433 extern int register_netdevice(struct net_device *dev);
434 extern int unregister_netdevice(struct net_device *dev);
435 extern int register_netdevice_notifier(struct notifier_block *nb);
436 extern int unregister_netdevice_notifier(struct notifier_block *nb);
437 extern int dev_new_index(void);
438 extern struct net_device *dev_get_by_index(int ifindex);
439 extern struct net_device *__dev_get_by_index(int ifindex);
440 extern int dev_restart(struct net_device *dev);
442 typedef int gifconf_func_t(struct net_device * dev, char * bufptr, int len);
443 extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf);
444 static inline int unregister_gifconf(unsigned int family)
446 return register_gifconf(family, 0);
450 * Incoming packets are placed on per-cpu queues so that
451 * no locking is needed.
454 struct softnet_data
456 int throttle;
457 int cng_level;
458 int avg_blog;
459 struct sk_buff_head input_pkt_queue;
460 struct net_device *output_queue;
461 struct sk_buff *completion_queue;
462 } __attribute__((__aligned__(SMP_CACHE_BYTES)));
465 extern struct softnet_data softnet_data[NR_CPUS];
467 #define HAVE_NETIF_QUEUE
469 static inline void __netif_schedule(struct net_device *dev)
471 if (!test_and_set_bit(__LINK_STATE_SCHED, &dev->state)) {
472 unsigned long flags;
473 int cpu = smp_processor_id();
475 local_irq_save(flags);
476 dev->next_sched = softnet_data[cpu].output_queue;
477 softnet_data[cpu].output_queue = dev;
478 __cpu_raise_softirq(cpu, NET_TX_SOFTIRQ);
479 local_irq_restore(flags);
483 static inline void netif_schedule(struct net_device *dev)
485 if (!test_bit(__LINK_STATE_XOFF, &dev->state))
486 __netif_schedule(dev);
489 static inline void netif_start_queue(struct net_device *dev)
491 clear_bit(__LINK_STATE_XOFF, &dev->state);
494 static inline void netif_wake_queue(struct net_device *dev)
496 if (test_and_clear_bit(__LINK_STATE_XOFF, &dev->state))
497 __netif_schedule(dev);
500 static inline void netif_stop_queue(struct net_device *dev)
502 set_bit(__LINK_STATE_XOFF, &dev->state);
505 static inline int netif_queue_stopped(struct net_device *dev)
507 return test_bit(__LINK_STATE_XOFF, &dev->state);
510 static inline int netif_running(struct net_device *dev)
512 return test_bit(__LINK_STATE_START, &dev->state);
515 /* Use this variant when it is known for sure that it
516 * is executing from interrupt context.
518 static inline void dev_kfree_skb_irq(struct sk_buff *skb)
520 if (atomic_dec_and_test(&skb->users)) {
521 int cpu =smp_processor_id();
522 unsigned long flags;
524 local_irq_save(flags);
525 skb->next = softnet_data[cpu].completion_queue;
526 softnet_data[cpu].completion_queue = skb;
527 __cpu_raise_softirq(cpu, NET_TX_SOFTIRQ);
528 local_irq_restore(flags);
532 /* Use this variant in places where it could be invoked
533 * either from interrupt or non-interrupt context.
535 static inline void dev_kfree_skb_any(struct sk_buff *skb)
537 if (in_irq())
538 dev_kfree_skb_irq(skb);
539 else
540 dev_kfree_skb(skb);
543 extern void net_call_rx_atomic(void (*fn)(void));
544 #define HAVE_NETIF_RX 1
545 extern int netif_rx(struct sk_buff *skb);
546 extern int dev_ioctl(unsigned int cmd, void *);
547 extern int dev_change_flags(struct net_device *, unsigned);
548 extern void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
550 extern void dev_init(void);
552 extern int netdev_nit;
554 static inline void dev_init_buffers(struct net_device *dev)
556 /* DO NOTHING */
559 extern int netdev_finish_unregister(struct net_device *dev);
561 static inline void dev_put(struct net_device *dev)
563 if (atomic_dec_and_test(&dev->refcnt))
564 netdev_finish_unregister(dev);
567 #define __dev_put(dev) atomic_dec(&(dev)->refcnt)
568 #define dev_hold(dev) atomic_inc(&(dev)->refcnt)
570 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
571 * and _off may be called from IRQ context, but it is caller
572 * who is responsible for serialization of these calls.
575 static inline int netif_carrier_ok(struct net_device *dev)
577 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
580 extern void __netdev_watchdog_up(struct net_device *dev);
582 static inline void netif_carrier_on(struct net_device *dev)
584 clear_bit(__LINK_STATE_NOCARRIER, &dev->state);
585 if (netif_running(dev))
586 __netdev_watchdog_up(dev);
589 static inline void netif_carrier_off(struct net_device *dev)
591 set_bit(__LINK_STATE_NOCARRIER, &dev->state);
594 /* Hot-plugging. */
595 static inline int netif_device_present(struct net_device *dev)
597 return test_bit(__LINK_STATE_PRESENT, &dev->state);
600 static inline void netif_device_detach(struct net_device *dev)
602 if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) &&
603 netif_running(dev)) {
604 netif_stop_queue(dev);
608 static inline void netif_device_attach(struct net_device *dev)
610 if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) &&
611 netif_running(dev)) {
612 netif_wake_queue(dev);
613 __netdev_watchdog_up(dev);
617 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
619 extern void ether_setup(struct net_device *dev);
620 extern void fddi_setup(struct net_device *dev);
621 extern void tr_setup(struct net_device *dev);
622 extern void fc_setup(struct net_device *dev);
623 extern void fc_freedev(struct net_device *dev);
624 extern int ether_config(struct net_device *dev, struct ifmap *map);
625 /* Support for loadable net-drivers */
626 extern int register_netdev(struct net_device *dev);
627 extern void unregister_netdev(struct net_device *dev);
628 extern int register_trdev(struct net_device *dev);
629 extern void unregister_trdev(struct net_device *dev);
630 extern int register_fcdev(struct net_device *dev);
631 extern void unregister_fcdev(struct net_device *dev);
632 /* Functions used for multicast support */
633 extern void dev_mc_upload(struct net_device *dev);
634 extern int dev_mc_delete(struct net_device *dev, void *addr, int alen, int all);
635 extern int dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly);
636 extern void dev_mc_discard(struct net_device *dev);
637 extern void dev_set_promiscuity(struct net_device *dev, int inc);
638 extern void dev_set_allmulti(struct net_device *dev, int inc);
639 extern void netdev_state_change(struct net_device *dev);
640 /* Load a device via the kmod */
641 extern void dev_load(const char *name);
642 extern void dev_mcast_init(void);
643 extern int netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev));
644 extern void netdev_unregister_fc(int bit);
645 extern int netdev_max_backlog;
646 extern unsigned long netdev_fc_xoff;
647 extern atomic_t netdev_dropping;
648 extern int netdev_set_master(struct net_device *dev, struct net_device *master);
649 #ifdef CONFIG_NET_FASTROUTE
650 extern int netdev_fastroute;
651 extern int netdev_fastroute_obstacles;
652 extern void dev_clear_fastroute(struct net_device *dev);
653 #endif
656 #endif /* __KERNEL__ */
658 #endif /* _LINUX_DEV_H */