- Kai Germaschewski: ymfpci cleanups and resource leak fixes
[davej-history.git] / include / linux / netdevice.h
blob46209167406562f2ccac7058abdbe3da6182cf79
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_DROP 1 /* packet dropped */
55 #define NET_RX_CN_LOW 2 /* storm alert, just in case */
56 #define NET_RX_CN_MOD 3 /* Storm on its way! */
57 #define NET_RX_CN_HIGH 4 /* The storm is here */
58 #define NET_RX_BAD 5 /* 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;
337 /* Net device features */
338 int features;
339 #define NETIF_F_SG 1 /* Scatter/gather IO. */
340 #define NETIF_F_IP_CSUM 2 /* Can checksum only TCP/UDP over IPv4. */
341 #define NETIF_F_NO_CSUM 4 /* Does not require checksum. F.e. loopack. */
342 #define NETIF_F_HW_CSUM 8 /* Can checksum all the packets. */
343 #define NETIF_F_DYNALLOC 16 /* Self-dectructable device. */
344 #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory. */
345 #define NETIF_F_FRAGLIST 1 /* Scatter/gather IO. */
347 /* Called after device is detached from network. */
348 void (*uninit)(struct net_device *dev);
349 /* Called after last user reference disappears. */
350 void (*destructor)(struct net_device *dev);
352 /* Pointers to interface service routines. */
353 int (*open)(struct net_device *dev);
354 int (*stop)(struct net_device *dev);
355 int (*hard_start_xmit) (struct sk_buff *skb,
356 struct net_device *dev);
357 int (*hard_header) (struct sk_buff *skb,
358 struct net_device *dev,
359 unsigned short type,
360 void *daddr,
361 void *saddr,
362 unsigned len);
363 int (*rebuild_header)(struct sk_buff *skb);
364 #define HAVE_MULTICAST
365 void (*set_multicast_list)(struct net_device *dev);
366 #define HAVE_SET_MAC_ADDR
367 int (*set_mac_address)(struct net_device *dev,
368 void *addr);
369 #define HAVE_PRIVATE_IOCTL
370 int (*do_ioctl)(struct net_device *dev,
371 struct ifreq *ifr, int cmd);
372 #define HAVE_SET_CONFIG
373 int (*set_config)(struct net_device *dev,
374 struct ifmap *map);
375 #define HAVE_HEADER_CACHE
376 int (*hard_header_cache)(struct neighbour *neigh,
377 struct hh_cache *hh);
378 void (*header_cache_update)(struct hh_cache *hh,
379 struct net_device *dev,
380 unsigned char * haddr);
381 #define HAVE_CHANGE_MTU
382 int (*change_mtu)(struct net_device *dev, int new_mtu);
384 #define HAVE_TX_TIMEOUT
385 void (*tx_timeout) (struct net_device *dev);
387 int (*hard_header_parse)(struct sk_buff *skb,
388 unsigned char *haddr);
389 int (*neigh_setup)(struct net_device *dev, struct neigh_parms *);
390 int (*accept_fastpath)(struct net_device *, struct dst_entry*);
392 /* open/release and usage marking */
393 struct module *owner;
395 /* bridge stuff */
396 struct net_bridge_port *br_port;
398 #ifdef CONFIG_NET_FASTROUTE
399 #define NETDEV_FASTROUTE_HMASK 0xF
400 /* Semi-private data. Keep it at the end of device struct. */
401 rwlock_t fastpath_lock;
402 struct dst_entry *fastpath[NETDEV_FASTROUTE_HMASK+1];
403 #endif
404 #ifdef CONFIG_NET_DIVERT
405 /* this will get initialized at each interface type init routine */
406 struct divert_blk *divert;
407 #endif /* CONFIG_NET_DIVERT */
411 struct packet_type
413 unsigned short type; /* This is really htons(ether_type). */
414 struct net_device *dev; /* NULL is wildcarded here */
415 int (*func) (struct sk_buff *, struct net_device *,
416 struct packet_type *);
417 void *data; /* Private to the packet type */
418 struct packet_type *next;
422 #include <linux/interrupt.h>
423 #include <linux/notifier.h>
425 extern struct net_device loopback_dev; /* The loopback */
426 extern struct net_device *dev_base; /* All devices */
427 extern rwlock_t dev_base_lock; /* Device list lock */
429 extern int netdev_boot_setup_add(char *name, struct ifmap *map);
430 extern int netdev_boot_setup_check(struct net_device *dev);
431 extern struct net_device *dev_getbyhwaddr(unsigned short type, char *hwaddr);
432 extern void dev_add_pack(struct packet_type *pt);
433 extern void dev_remove_pack(struct packet_type *pt);
434 extern int dev_get(const char *name);
435 extern struct net_device *dev_get_by_name(const char *name);
436 extern struct net_device *__dev_get_by_name(const char *name);
437 extern struct net_device *dev_alloc(const char *name, int *err);
438 extern int dev_alloc_name(struct net_device *dev, const char *name);
439 extern int dev_open(struct net_device *dev);
440 extern int dev_close(struct net_device *dev);
441 extern int dev_queue_xmit(struct sk_buff *skb);
442 extern int register_netdevice(struct net_device *dev);
443 extern int unregister_netdevice(struct net_device *dev);
444 extern int register_netdevice_notifier(struct notifier_block *nb);
445 extern int unregister_netdevice_notifier(struct notifier_block *nb);
446 extern int dev_new_index(void);
447 extern struct net_device *dev_get_by_index(int ifindex);
448 extern struct net_device *__dev_get_by_index(int ifindex);
449 extern int dev_restart(struct net_device *dev);
451 typedef int gifconf_func_t(struct net_device * dev, char * bufptr, int len);
452 extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf);
453 static inline int unregister_gifconf(unsigned int family)
455 return register_gifconf(family, 0);
459 * Incoming packets are placed on per-cpu queues so that
460 * no locking is needed.
463 struct softnet_data
465 int throttle;
466 int cng_level;
467 int avg_blog;
468 struct sk_buff_head input_pkt_queue;
469 struct net_device *output_queue;
470 struct sk_buff *completion_queue;
471 } __attribute__((__aligned__(SMP_CACHE_BYTES)));
474 extern struct softnet_data softnet_data[NR_CPUS];
476 #define HAVE_NETIF_QUEUE
478 static inline void __netif_schedule(struct net_device *dev)
480 if (!test_and_set_bit(__LINK_STATE_SCHED, &dev->state)) {
481 unsigned long flags;
482 int cpu = smp_processor_id();
484 local_irq_save(flags);
485 dev->next_sched = softnet_data[cpu].output_queue;
486 softnet_data[cpu].output_queue = dev;
487 __cpu_raise_softirq(cpu, NET_TX_SOFTIRQ);
488 local_irq_restore(flags);
492 static inline void netif_schedule(struct net_device *dev)
494 if (!test_bit(__LINK_STATE_XOFF, &dev->state))
495 __netif_schedule(dev);
498 static inline void netif_start_queue(struct net_device *dev)
500 clear_bit(__LINK_STATE_XOFF, &dev->state);
503 static inline void netif_wake_queue(struct net_device *dev)
505 if (test_and_clear_bit(__LINK_STATE_XOFF, &dev->state))
506 __netif_schedule(dev);
509 static inline void netif_stop_queue(struct net_device *dev)
511 set_bit(__LINK_STATE_XOFF, &dev->state);
514 static inline int netif_queue_stopped(struct net_device *dev)
516 return test_bit(__LINK_STATE_XOFF, &dev->state);
519 static inline int netif_running(struct net_device *dev)
521 return test_bit(__LINK_STATE_START, &dev->state);
524 /* Use this variant when it is known for sure that it
525 * is executing from interrupt context.
527 static inline void dev_kfree_skb_irq(struct sk_buff *skb)
529 if (atomic_dec_and_test(&skb->users)) {
530 int cpu =smp_processor_id();
531 unsigned long flags;
533 local_irq_save(flags);
534 skb->next = softnet_data[cpu].completion_queue;
535 softnet_data[cpu].completion_queue = skb;
536 __cpu_raise_softirq(cpu, NET_TX_SOFTIRQ);
537 local_irq_restore(flags);
541 /* Use this variant in places where it could be invoked
542 * either from interrupt or non-interrupt context.
544 static inline void dev_kfree_skb_any(struct sk_buff *skb)
546 if (in_irq())
547 dev_kfree_skb_irq(skb);
548 else
549 dev_kfree_skb(skb);
552 extern void net_call_rx_atomic(void (*fn)(void));
553 #define HAVE_NETIF_RX 1
554 extern int netif_rx(struct sk_buff *skb);
555 extern int dev_ioctl(unsigned int cmd, void *);
556 extern int dev_change_flags(struct net_device *, unsigned);
557 extern void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
559 extern void dev_init(void);
561 extern int netdev_nit;
563 static inline void dev_init_buffers(struct net_device *dev)
565 /* DO NOTHING */
568 extern int netdev_finish_unregister(struct net_device *dev);
570 static inline void dev_put(struct net_device *dev)
572 if (atomic_dec_and_test(&dev->refcnt))
573 netdev_finish_unregister(dev);
576 #define __dev_put(dev) atomic_dec(&(dev)->refcnt)
577 #define dev_hold(dev) atomic_inc(&(dev)->refcnt)
579 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
580 * and _off may be called from IRQ context, but it is caller
581 * who is responsible for serialization of these calls.
584 static inline int netif_carrier_ok(struct net_device *dev)
586 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
589 extern void __netdev_watchdog_up(struct net_device *dev);
591 static inline void netif_carrier_on(struct net_device *dev)
593 clear_bit(__LINK_STATE_NOCARRIER, &dev->state);
594 if (netif_running(dev))
595 __netdev_watchdog_up(dev);
598 static inline void netif_carrier_off(struct net_device *dev)
600 set_bit(__LINK_STATE_NOCARRIER, &dev->state);
603 /* Hot-plugging. */
604 static inline int netif_device_present(struct net_device *dev)
606 return test_bit(__LINK_STATE_PRESENT, &dev->state);
609 static inline void netif_device_detach(struct net_device *dev)
611 if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) &&
612 netif_running(dev)) {
613 netif_stop_queue(dev);
617 static inline void netif_device_attach(struct net_device *dev)
619 if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) &&
620 netif_running(dev)) {
621 netif_wake_queue(dev);
622 __netdev_watchdog_up(dev);
626 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
628 extern void ether_setup(struct net_device *dev);
629 extern void fddi_setup(struct net_device *dev);
630 extern void tr_setup(struct net_device *dev);
631 extern void fc_setup(struct net_device *dev);
632 extern void fc_freedev(struct net_device *dev);
633 extern int ether_config(struct net_device *dev, struct ifmap *map);
634 /* Support for loadable net-drivers */
635 extern int register_netdev(struct net_device *dev);
636 extern void unregister_netdev(struct net_device *dev);
637 extern int register_trdev(struct net_device *dev);
638 extern void unregister_trdev(struct net_device *dev);
639 extern int register_fcdev(struct net_device *dev);
640 extern void unregister_fcdev(struct net_device *dev);
641 /* Functions used for multicast support */
642 extern void dev_mc_upload(struct net_device *dev);
643 extern int dev_mc_delete(struct net_device *dev, void *addr, int alen, int all);
644 extern int dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly);
645 extern void dev_mc_discard(struct net_device *dev);
646 extern void dev_set_promiscuity(struct net_device *dev, int inc);
647 extern void dev_set_allmulti(struct net_device *dev, int inc);
648 extern void netdev_state_change(struct net_device *dev);
649 /* Load a device via the kmod */
650 extern void dev_load(const char *name);
651 extern void dev_mcast_init(void);
652 extern int netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev));
653 extern void netdev_unregister_fc(int bit);
654 extern int netdev_max_backlog;
655 extern unsigned long netdev_fc_xoff;
656 extern atomic_t netdev_dropping;
657 extern int netdev_set_master(struct net_device *dev, struct net_device *master);
658 #ifdef CONFIG_NET_FASTROUTE
659 extern int netdev_fastroute;
660 extern int netdev_fastroute_obstacles;
661 extern void dev_clear_fastroute(struct net_device *dev);
662 #endif
665 #endif /* __KERNEL__ */
667 #endif /* _LINUX_DEV_H */