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
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>
37 #include <linux/config.h>
38 #ifdef CONFIG_NET_PROFILE
39 #include <net/profile.h>
46 /* source back-compat hooks */
47 #define SET_ETHTOOL_OPS(netdev,ops) \
48 ( (netdev)->ethtool_ops = (ops) )
50 #define HAVE_ALLOC_NETDEV /* feature macro: alloc_xxxdev
51 functions are available. */
52 #define HAVE_FREE_NETDEV /* free_netdev() */
53 #define HAVE_NETDEV_PRIV /* netdev_priv() */
55 #define NET_XMIT_SUCCESS 0
56 #define NET_XMIT_DROP 1 /* skb dropped */
57 #define NET_XMIT_CN 2 /* congestion notification */
58 #define NET_XMIT_POLICED 3 /* skb is shot by police */
59 #define NET_XMIT_BYPASS 4 /* packet does not leave via dequeue;
60 (TC use only - dev_queue_xmit
61 returns this as NET_XMIT_SUCCESS) */
63 /* Backlog congestion levels */
64 #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
65 #define NET_RX_DROP 1 /* packet dropped */
66 #define NET_RX_CN_LOW 2 /* storm alert, just in case */
67 #define NET_RX_CN_MOD 3 /* Storm on its way! */
68 #define NET_RX_CN_HIGH 4 /* The storm is here */
69 #define NET_RX_BAD 5 /* packet dropped due to kernel error */
71 #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
75 #define MAX_ADDR_LEN 8 /* Largest hardware address length */
78 * Compute the worst case header length according to the protocols
82 #if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR)
83 #define LL_MAX_HEADER 32
85 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
86 #define LL_MAX_HEADER 96
88 #define LL_MAX_HEADER 48
92 #if !defined(CONFIG_NET_IPIP) && \
93 !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
94 #define MAX_HEADER LL_MAX_HEADER
96 #define MAX_HEADER (LL_MAX_HEADER + 48)
100 * Network device statistics. Akin to the 2.0 ether stats but
101 * with byte counters.
104 struct net_device_stats
106 unsigned long rx_packets
; /* total packets received */
107 unsigned long tx_packets
; /* total packets transmitted */
108 unsigned long rx_bytes
; /* total bytes received */
109 unsigned long tx_bytes
; /* total bytes transmitted */
110 unsigned long rx_errors
; /* bad packets received */
111 unsigned long tx_errors
; /* packet transmit problems */
112 unsigned long rx_dropped
; /* no space in linux buffers */
113 unsigned long tx_dropped
; /* no space available in linux */
114 unsigned long multicast
; /* multicast packets received */
115 unsigned long collisions
;
117 /* detailed rx_errors: */
118 unsigned long rx_length_errors
;
119 unsigned long rx_over_errors
; /* receiver ring buff overflow */
120 unsigned long rx_crc_errors
; /* recved pkt with crc error */
121 unsigned long rx_frame_errors
; /* recv'd frame alignment error */
122 unsigned long rx_fifo_errors
; /* recv'r fifo overrun */
123 unsigned long rx_missed_errors
; /* receiver missed packet */
125 /* detailed tx_errors */
126 unsigned long tx_aborted_errors
;
127 unsigned long tx_carrier_errors
;
128 unsigned long tx_fifo_errors
;
129 unsigned long tx_heartbeat_errors
;
130 unsigned long tx_window_errors
;
133 unsigned long rx_compressed
;
134 unsigned long tx_compressed
;
138 /* Media selection options. */
151 extern const char *if_port_text
[];
153 #include <linux/cache.h>
154 #include <linux/skbuff.h>
160 struct netif_rx_stats
164 unsigned time_squeeze
;
166 unsigned fastroute_hit
;
167 unsigned fastroute_success
;
168 unsigned fastroute_defer
;
169 unsigned fastroute_deferred_out
;
170 unsigned fastroute_latency_reduction
;
171 unsigned cpu_collision
;
172 } ____cacheline_aligned
;
174 extern struct netif_rx_stats netdev_rx_stat
[];
178 * We tag multicasts with these structures.
183 struct dev_mc_list
*next
;
184 __u8 dmi_addr
[MAX_ADDR_LEN
];
185 unsigned char dmi_addrlen
;
192 struct hh_cache
*hh_next
; /* Next entry */
193 atomic_t hh_refcnt
; /* number of users */
194 unsigned short hh_type
; /* protocol identifier, f.e ETH_P_IP
195 * NOTE: For VLANs, this will be the
196 * encapuslated type. --BLG
198 int hh_len
; /* length of header */
199 int (*hh_output
)(struct sk_buff
*skb
);
202 /* cached hardware header; allow for machine alignment needs. */
203 #define HH_DATA_MOD 16
204 #define HH_DATA_OFF(__len) \
205 (HH_DATA_MOD - ((__len) & (HH_DATA_MOD - 1)))
206 #define HH_DATA_ALIGN(__len) \
207 (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
208 unsigned long hh_data
[HH_DATA_ALIGN(LL_MAX_HEADER
) / sizeof(long)];
211 /* These flag bits are private to the generic network queueing
212 * layer, they may not be explicitly referenced by any other
220 __LINK_STATE_PRESENT
,
222 __LINK_STATE_NOCARRIER
,
223 __LINK_STATE_RX_SCHED
228 * This structure holds at boot time configured netdevice settings. They
229 * are then used in the device probing.
231 struct netdev_boot_setup
{
235 #define NETDEV_BOOT_SETUP_MAX 8
239 * The DEVICE structure.
240 * Actually, this whole structure is a big mistake. It mixes I/O
241 * data with strictly "high-level" data, and it has to know about
242 * almost every data structure used in the INET module.
244 * FIXME: cleanup struct net_device such that network protocol info
252 * This is the first field of the "visible" part of this structure
253 * (i.e. as seen by users in the "Space.c" file). It is the name
259 * I/O specific fields
260 * FIXME: Merge these and struct ifmap into one
262 unsigned long rmem_end
; /* shmem "recv" end */
263 unsigned long rmem_start
; /* shmem "recv" start */
264 unsigned long mem_end
; /* shared mem end */
265 unsigned long mem_start
; /* shared mem start */
266 unsigned long base_addr
; /* device I/O address */
267 unsigned int irq
; /* device IRQ number */
270 * Some hardware also needs these fields, but they are not
271 * part of the usual set specified in Space.c.
274 unsigned char if_port
; /* Selectable AUI, TP,..*/
275 unsigned char dma
; /* DMA channel */
279 struct net_device
*next
;
281 /* The device initialization function. Called only once. */
282 int (*init
)(struct net_device
*dev
);
284 /* ------- Fields preinitialized in Space.c finish here ------- */
286 struct net_device
*next_sched
;
288 /* Interface index. Unique device identifier */
293 struct net_device_stats
* (*get_stats
)(struct net_device
*dev
);
294 struct iw_statistics
* (*get_wireless_stats
)(struct net_device
*dev
);
296 /* List of functions to handle Wireless Extensions (instead of ioctl).
297 * See <net/iw_handler.h> for details. Jean II */
298 const struct iw_handler_def
* wireless_handlers
;
302 * This marks the end of the "visible" part of the structure. All
303 * fields hereafter are internal to the system, and may change at
304 * will (read: may be cleaned up at will).
307 /* These may be needed for future network-power-down code. */
308 unsigned long trans_start
; /* Time (in jiffies) of last Tx */
309 unsigned long last_rx
; /* Time of last Rx */
311 unsigned short flags
; /* interface flags (a la BSD) */
312 unsigned short gflags
;
313 unsigned short priv_flags
; /* Like 'flags' but invisible to userspace. */
314 unsigned short unused_alignment_fixer
; /* Because we need priv_flags,
315 * and we want to be 32-bit aligned.
318 unsigned mtu
; /* interface MTU value */
319 unsigned short type
; /* interface hardware type */
320 unsigned short hard_header_len
; /* hardware hdr length */
321 void *priv
; /* pointer to private data */
323 struct net_device
*master
; /* Pointer to master device of a group,
324 * which this device is member of.
327 /* Interface address info. */
328 unsigned char broadcast
[MAX_ADDR_LEN
]; /* hw bcast add */
329 unsigned char dev_addr
[MAX_ADDR_LEN
]; /* hw address */
330 unsigned char addr_len
; /* hardware address length */
332 struct dev_mc_list
*mc_list
; /* Multicast mac addresses */
333 int mc_count
; /* Number of installed mcasts */
338 struct timer_list watchdog_timer
;
340 /* Protocol specific pointers */
342 void *atalk_ptr
; /* AppleTalk link */
343 void *ip_ptr
; /* IPv4 specific data */
344 void *dn_ptr
; /* DECnet specific data */
345 void *ip6_ptr
; /* IPv6 specific data */
346 void *ec_ptr
; /* Econet specific data */
348 struct list_head poll_list
; /* Link to poll list */
353 struct Qdisc
*qdisc_sleeping
;
354 struct Qdisc
*qdisc_list
;
355 struct Qdisc
*qdisc_ingress
;
356 unsigned long tx_queue_len
; /* Max frames per queue allowed */
358 /* hard_start_xmit synchronizer */
359 spinlock_t xmit_lock
;
360 /* cpu id of processor entered to hard_start_xmit or -1,
361 if nobody entered there.
364 /* device queue lock */
365 spinlock_t queue_lock
;
366 /* Number of references to this device */
368 /* The flag marking that device is unregistered, but held by an user */
371 /* Net device features */
373 #define NETIF_F_SG 1 /* Scatter/gather IO. */
374 #define NETIF_F_IP_CSUM 2 /* Can checksum only TCP/UDP over IPv4. */
375 #define NETIF_F_NO_CSUM 4 /* Does not require checksum. F.e. loopack. */
376 #define NETIF_F_HW_CSUM 8 /* Can checksum all the packets. */
377 #define NETIF_F_DYNALLOC 16 /* Self-dectructable device. */
378 #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory. */
379 #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */
380 #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw acceleration */
381 #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw acceleration */
382 #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on VLAN */
383 #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */
385 /* Called after device is detached from network. */
386 void (*uninit
)(struct net_device
*dev
);
387 /* Called after last user reference disappears. */
388 void (*destructor
)(struct net_device
*dev
);
390 /* Pointers to interface service routines. */
391 int (*open
)(struct net_device
*dev
);
392 int (*stop
)(struct net_device
*dev
);
393 int (*hard_start_xmit
) (struct sk_buff
*skb
,
394 struct net_device
*dev
);
395 #define HAVE_NETDEV_POLL
396 int (*poll
) (struct net_device
*dev
, int *quota
);
397 int (*hard_header
) (struct sk_buff
*skb
,
398 struct net_device
*dev
,
403 int (*rebuild_header
)(struct sk_buff
*skb
);
404 #define HAVE_MULTICAST
405 void (*set_multicast_list
)(struct net_device
*dev
);
406 #define HAVE_SET_MAC_ADDR
407 int (*set_mac_address
)(struct net_device
*dev
,
409 #define HAVE_PRIVATE_IOCTL
410 int (*do_ioctl
)(struct net_device
*dev
,
411 struct ifreq
*ifr
, int cmd
);
412 #define HAVE_SET_CONFIG
413 int (*set_config
)(struct net_device
*dev
,
415 #define HAVE_HEADER_CACHE
416 int (*hard_header_cache
)(struct neighbour
*neigh
,
417 struct hh_cache
*hh
);
418 void (*header_cache_update
)(struct hh_cache
*hh
,
419 struct net_device
*dev
,
420 unsigned char * haddr
);
421 #define HAVE_CHANGE_MTU
422 int (*change_mtu
)(struct net_device
*dev
, int new_mtu
);
424 #define HAVE_TX_TIMEOUT
425 void (*tx_timeout
) (struct net_device
*dev
);
427 void (*vlan_rx_register
)(struct net_device
*dev
,
428 struct vlan_group
*grp
);
429 void (*vlan_rx_add_vid
)(struct net_device
*dev
,
431 void (*vlan_rx_kill_vid
)(struct net_device
*dev
,
434 int (*hard_header_parse
)(struct sk_buff
*skb
,
435 unsigned char *haddr
);
436 int (*neigh_setup
)(struct net_device
*dev
, struct neigh_parms
*);
437 int (*accept_fastpath
)(struct net_device
*, struct dst_entry
*);
439 /* open/release and usage marking */
440 struct module
*owner
;
443 struct net_bridge_port
*br_port
;
445 #ifdef CONFIG_NET_FASTROUTE
446 #define NETDEV_FASTROUTE_HMASK 0xF
447 /* Semi-private data. Keep it at the end of device struct. */
448 rwlock_t fastpath_lock
;
449 struct dst_entry
*fastpath
[NETDEV_FASTROUTE_HMASK
+1];
451 #ifdef CONFIG_NET_DIVERT
452 /* this will get initialized at each interface type init routine */
453 struct divert_blk
*divert
;
454 #endif /* CONFIG_NET_DIVERT */
455 struct ethtool_ops
*ethtool_ops
;
457 /* Instance data managed by the core of Wireless Extensions. */
458 struct iw_public_data
* wireless_data
;
461 /* 2.6 compatibility */
462 #define SET_NETDEV_DEV(net, pdev) do { } while (0)
466 unsigned short type
; /* This is really htons(ether_type). */
467 struct net_device
*dev
; /* NULL is wildcarded here */
468 int (*func
) (struct sk_buff
*, struct net_device
*,
469 struct packet_type
*);
470 void *data
; /* Private to the packet type */
471 struct packet_type
*next
;
474 static inline void *netdev_priv(struct net_device
*dev
)
479 #include <linux/interrupt.h>
480 #include <linux/notifier.h>
482 extern struct net_device loopback_dev
; /* The loopback */
483 extern struct net_device
*dev_base
; /* All devices */
484 extern rwlock_t dev_base_lock
; /* Device list lock */
486 extern int netdev_boot_setup_add(char *name
, struct ifmap
*map
);
487 extern int netdev_boot_setup_check(struct net_device
*dev
);
488 extern struct net_device
*dev_getbyhwaddr(unsigned short type
, char *hwaddr
);
489 extern void dev_add_pack(struct packet_type
*pt
);
490 extern void dev_remove_pack(struct packet_type
*pt
);
491 extern int dev_get(const char *name
);
492 extern struct net_device
*dev_get_by_flags(unsigned short flags
,
493 unsigned short mask
);
494 extern struct net_device
*__dev_get_by_flags(unsigned short flags
,
495 unsigned short mask
);
496 extern struct net_device
*dev_get_by_name(const char *name
);
497 extern struct net_device
*__dev_get_by_name(const char *name
);
498 extern struct net_device
*dev_alloc(const char *name
, int *err
);
499 extern int dev_alloc_name(struct net_device
*dev
, const char *name
);
500 extern int dev_open(struct net_device
*dev
);
501 extern int dev_close(struct net_device
*dev
);
502 extern int dev_queue_xmit(struct sk_buff
*skb
);
503 extern int register_netdevice(struct net_device
*dev
);
504 extern int unregister_netdevice(struct net_device
*dev
);
505 extern int register_netdevice_notifier(struct notifier_block
*nb
);
506 extern int unregister_netdevice_notifier(struct notifier_block
*nb
);
507 extern int dev_new_index(void);
508 extern struct net_device
*dev_get_by_index(int ifindex
);
509 extern struct net_device
*__dev_get_by_index(int ifindex
);
510 extern int dev_restart(struct net_device
*dev
);
512 typedef int gifconf_func_t(struct net_device
* dev
, char * bufptr
, int len
);
513 extern int register_gifconf(unsigned int family
, gifconf_func_t
* gifconf
);
514 static inline int unregister_gifconf(unsigned int family
)
516 return register_gifconf(family
, 0);
520 * Incoming packets are placed on per-cpu queues so that
521 * no locking is needed.
529 struct sk_buff_head input_pkt_queue
;
530 struct list_head poll_list
;
531 struct net_device
*output_queue
;
532 struct sk_buff
*completion_queue
;
534 struct net_device blog_dev
; /* Sorry. 8) */
535 } ____cacheline_aligned
;
538 extern struct softnet_data softnet_data
[NR_CPUS
];
540 #define HAVE_NETIF_QUEUE
542 static inline void __netif_schedule(struct net_device
*dev
)
544 if (!test_and_set_bit(__LINK_STATE_SCHED
, &dev
->state
)) {
546 int cpu
= smp_processor_id();
548 local_irq_save(flags
);
549 dev
->next_sched
= softnet_data
[cpu
].output_queue
;
550 softnet_data
[cpu
].output_queue
= dev
;
551 cpu_raise_softirq(cpu
, NET_TX_SOFTIRQ
);
552 local_irq_restore(flags
);
556 static inline void netif_schedule(struct net_device
*dev
)
558 if (!test_bit(__LINK_STATE_XOFF
, &dev
->state
))
559 __netif_schedule(dev
);
562 static inline void netif_start_queue(struct net_device
*dev
)
564 clear_bit(__LINK_STATE_XOFF
, &dev
->state
);
567 static inline void netif_wake_queue(struct net_device
*dev
)
569 if (test_and_clear_bit(__LINK_STATE_XOFF
, &dev
->state
))
570 __netif_schedule(dev
);
573 static inline void netif_stop_queue(struct net_device
*dev
)
575 set_bit(__LINK_STATE_XOFF
, &dev
->state
);
578 static inline int netif_queue_stopped(struct net_device
*dev
)
580 return test_bit(__LINK_STATE_XOFF
, &dev
->state
);
583 static inline int netif_running(struct net_device
*dev
)
585 return test_bit(__LINK_STATE_START
, &dev
->state
);
589 /* Use this variant when it is known for sure that it
590 * is executing from interrupt context.
592 static inline void dev_kfree_skb_irq(struct sk_buff
*skb
)
594 if (atomic_dec_and_test(&skb
->users
)) {
595 int cpu
=smp_processor_id();
598 local_irq_save(flags
);
599 skb
->next
= softnet_data
[cpu
].completion_queue
;
600 softnet_data
[cpu
].completion_queue
= skb
;
601 cpu_raise_softirq(cpu
, NET_TX_SOFTIRQ
);
602 local_irq_restore(flags
);
606 /* Use this variant in places where it could be invoked
607 * either from interrupt or non-interrupt context.
609 static inline void dev_kfree_skb_any(struct sk_buff
*skb
)
612 dev_kfree_skb_irq(skb
);
617 #define HAVE_NETIF_RX 1
618 extern int netif_rx(struct sk_buff
*skb
);
619 #define HAVE_NETIF_RECEIVE_SKB 1
620 extern int netif_receive_skb(struct sk_buff
*skb
);
621 extern int dev_ioctl(unsigned int cmd
, void *);
622 extern int dev_ethtool(struct ifreq
*);
623 extern int dev_change_flags(struct net_device
*, unsigned);
624 extern void dev_queue_xmit_nit(struct sk_buff
*skb
, struct net_device
*dev
);
626 extern void dev_init(void);
628 extern int netdev_nit
;
630 /* Post buffer to the network code from _non interrupt_ context.
631 * see net/core/dev.c for netif_rx description.
633 static inline int netif_rx_ni(struct sk_buff
*skb
)
635 int err
= netif_rx(skb
);
636 if (softirq_pending(smp_processor_id()))
641 static inline void dev_init_buffers(struct net_device
*dev
)
643 /* WILL BE REMOVED IN 2.5.0 */
646 extern int netdev_finish_unregister(struct net_device
*dev
);
648 static inline void dev_put(struct net_device
*dev
)
650 if (atomic_dec_and_test(&dev
->refcnt
))
651 netdev_finish_unregister(dev
);
654 #define __dev_put(dev) atomic_dec(&(dev)->refcnt)
655 #define dev_hold(dev) atomic_inc(&(dev)->refcnt)
657 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
658 * and _off may be called from IRQ context, but it is caller
659 * who is responsible for serialization of these calls.
662 static inline int netif_carrier_ok(struct net_device
*dev
)
664 return !test_bit(__LINK_STATE_NOCARRIER
, &dev
->state
);
667 extern void __netdev_watchdog_up(struct net_device
*dev
);
669 static inline void netif_carrier_on(struct net_device
*dev
)
671 clear_bit(__LINK_STATE_NOCARRIER
, &dev
->state
);
672 if (netif_running(dev
))
673 __netdev_watchdog_up(dev
);
676 static inline void netif_carrier_off(struct net_device
*dev
)
678 set_bit(__LINK_STATE_NOCARRIER
, &dev
->state
);
682 static inline int netif_device_present(struct net_device
*dev
)
684 return test_bit(__LINK_STATE_PRESENT
, &dev
->state
);
687 static inline void netif_device_detach(struct net_device
*dev
)
689 if (test_and_clear_bit(__LINK_STATE_PRESENT
, &dev
->state
) &&
690 netif_running(dev
)) {
691 netif_stop_queue(dev
);
695 static inline void netif_device_attach(struct net_device
*dev
)
697 if (!test_and_set_bit(__LINK_STATE_PRESENT
, &dev
->state
) &&
698 netif_running(dev
)) {
699 netif_wake_queue(dev
);
700 __netdev_watchdog_up(dev
);
705 * Network interface message level settings
707 #define HAVE_NETIF_MSG 1
710 NETIF_MSG_DRV
= 0x0001,
711 NETIF_MSG_PROBE
= 0x0002,
712 NETIF_MSG_LINK
= 0x0004,
713 NETIF_MSG_TIMER
= 0x0008,
714 NETIF_MSG_IFDOWN
= 0x0010,
715 NETIF_MSG_IFUP
= 0x0020,
716 NETIF_MSG_RX_ERR
= 0x0040,
717 NETIF_MSG_TX_ERR
= 0x0080,
718 NETIF_MSG_TX_QUEUED
= 0x0100,
719 NETIF_MSG_INTR
= 0x0200,
720 NETIF_MSG_TX_DONE
= 0x0400,
721 NETIF_MSG_RX_STATUS
= 0x0800,
722 NETIF_MSG_PKTDATA
= 0x1000,
723 NETIF_MSG_HW
= 0x2000,
724 NETIF_MSG_WOL
= 0x4000,
727 #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
728 #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
729 #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
730 #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
731 #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
732 #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
733 #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
734 #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
735 #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
736 #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
737 #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
738 #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
739 #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
740 #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
741 #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
743 static inline u32
netif_msg_init(int debug_value
, int default_msg_enable_bits
)
746 if (debug_value
< 0 || debug_value
>= (sizeof(u32
) * 8))
747 return default_msg_enable_bits
;
748 if (debug_value
== 0) /* no output */
751 return (1 << debug_value
) - 1;
754 /* Schedule rx intr now? */
756 static inline int netif_rx_schedule_prep(struct net_device
*dev
)
758 return netif_running(dev
) &&
759 !test_and_set_bit(__LINK_STATE_RX_SCHED
, &dev
->state
);
762 /* Add interface to tail of rx poll list. This assumes that _prep has
763 * already been called and returned 1.
766 static inline void __netif_rx_schedule(struct net_device
*dev
)
769 int cpu
= smp_processor_id();
771 local_irq_save(flags
);
773 list_add_tail(&dev
->poll_list
, &softnet_data
[cpu
].poll_list
);
775 dev
->quota
+= dev
->weight
;
777 dev
->quota
= dev
->weight
;
778 __cpu_raise_softirq(cpu
, NET_RX_SOFTIRQ
);
779 local_irq_restore(flags
);
782 /* Try to reschedule poll. Called by irq handler. */
784 static inline void netif_rx_schedule(struct net_device
*dev
)
786 if (netif_rx_schedule_prep(dev
))
787 __netif_rx_schedule(dev
);
790 /* Try to reschedule poll. Called by dev->poll() after netif_rx_complete().
791 * Do not inline this?
793 static inline int netif_rx_reschedule(struct net_device
*dev
, int undo
)
795 if (netif_rx_schedule_prep(dev
)) {
797 int cpu
= smp_processor_id();
801 local_irq_save(flags
);
802 list_add_tail(&dev
->poll_list
, &softnet_data
[cpu
].poll_list
);
803 __cpu_raise_softirq(cpu
, NET_RX_SOFTIRQ
);
804 local_irq_restore(flags
);
810 /* Remove interface from poll list: it must be in the poll list
811 * on current cpu. This primitive is called by dev->poll(), when
812 * it completes the work. The device cannot be out of poll list at this
813 * moment, it is BUG().
815 static inline void netif_rx_complete(struct net_device
*dev
)
819 local_irq_save(flags
);
820 if (!test_bit(__LINK_STATE_RX_SCHED
, &dev
->state
)) BUG();
821 list_del(&dev
->poll_list
);
822 smp_mb__before_clear_bit();
823 clear_bit(__LINK_STATE_RX_SCHED
, &dev
->state
);
824 local_irq_restore(flags
);
827 static inline void netif_poll_disable(struct net_device
*dev
)
829 while (test_and_set_bit(__LINK_STATE_RX_SCHED
, &dev
->state
)) {
831 current
->state
= TASK_INTERRUPTIBLE
;
836 static inline void netif_poll_enable(struct net_device
*dev
)
838 clear_bit(__LINK_STATE_RX_SCHED
, &dev
->state
);
841 /* same as netif_rx_complete, except that local_irq_save(flags)
842 * has already been issued
844 static inline void __netif_rx_complete(struct net_device
*dev
)
846 if (!test_bit(__LINK_STATE_RX_SCHED
, &dev
->state
)) BUG();
847 list_del(&dev
->poll_list
);
848 smp_mb__before_clear_bit();
849 clear_bit(__LINK_STATE_RX_SCHED
, &dev
->state
);
852 static inline void netif_tx_disable(struct net_device
*dev
)
854 spin_lock_bh(&dev
->xmit_lock
);
855 netif_stop_queue(dev
);
856 spin_unlock_bh(&dev
->xmit_lock
);
859 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
861 extern void ether_setup(struct net_device
*dev
);
862 extern void fddi_setup(struct net_device
*dev
);
863 extern void tr_setup(struct net_device
*dev
);
864 extern void fc_setup(struct net_device
*dev
);
865 extern void fc_freedev(struct net_device
*dev
);
866 /* Support for loadable net-drivers */
867 extern struct net_device
*alloc_netdev(int sizeof_priv
, const char *name
,
868 void (*setup
)(struct net_device
*));
869 extern int register_netdev(struct net_device
*dev
);
870 extern void unregister_netdev(struct net_device
*dev
);
871 /* Functions used for multicast support */
872 extern void dev_mc_upload(struct net_device
*dev
);
873 extern int dev_mc_delete(struct net_device
*dev
, void *addr
, int alen
, int all
);
874 extern int dev_mc_add(struct net_device
*dev
, void *addr
, int alen
, int newonly
);
875 extern void dev_mc_discard(struct net_device
*dev
);
876 extern void dev_set_promiscuity(struct net_device
*dev
, int inc
);
877 extern void dev_set_allmulti(struct net_device
*dev
, int inc
);
878 extern void netdev_state_change(struct net_device
*dev
);
879 /* Load a device via the kmod */
880 extern void dev_load(const char *name
);
881 extern void dev_mcast_init(void);
882 extern int netdev_register_fc(struct net_device
*dev
, void (*stimul
)(struct net_device
*dev
));
883 extern void netdev_unregister_fc(int bit
);
884 extern int netdev_max_backlog
;
886 extern unsigned long netdev_fc_xoff
;
887 extern atomic_t netdev_dropping
;
888 extern int netdev_set_master(struct net_device
*dev
, struct net_device
*master
);
889 extern struct sk_buff
* skb_checksum_help(struct sk_buff
*skb
);
890 #ifdef CONFIG_NET_FASTROUTE
891 extern int netdev_fastroute
;
892 extern int netdev_fastroute_obstacles
;
893 extern void dev_clear_fastroute(struct net_device
*dev
);
896 static inline void free_netdev(struct net_device
*dev
)
901 #endif /* __KERNEL__ */
903 #endif /* _LINUX_DEV_H */