added a lot of printk output to ease writing of emulator
[linux-2.4.21-pre4.git] / include / linux / netdevice.h
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.
5  *
6  *              Definitions for the Interfaces handler.
7  *
8  * Version:     @(#)dev.h       1.0.10  08/12/93
9  *
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>
17  *
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.
22  *
23  *              Moved to /usr/include/linux for NET3
24  */
25 #ifndef _LINUX_NETDEVICE_H
26 #define _LINUX_NETDEVICE_H
27
28 #include <linux/if.h>
29 #include <linux/if_ether.h>
30 #include <linux/if_packet.h>
31
32 #include <asm/atomic.h>
33 #include <asm/cache.h>
34 #include <asm/byteorder.h>
35
36 #ifdef __KERNEL__
37 #include <linux/config.h>
38 #ifdef CONFIG_NET_PROFILE
39 #include <net/profile.h>
40 #endif
41
42 struct divert_blk;
43 struct vlan_group;
44
45 #define HAVE_ALLOC_NETDEV               /* feature macro: alloc_xxxdev
46                                            functions are available. */
47
48 #define NET_XMIT_SUCCESS        0
49 #define NET_XMIT_DROP           1       /* skb dropped                  */
50 #define NET_XMIT_CN             2       /* congestion notification      */
51 #define NET_XMIT_POLICED        3       /* skb is shot by police        */
52 #define NET_XMIT_BYPASS         4       /* packet does not leave via dequeue;
53                                            (TC use only - dev_queue_xmit
54                                            returns this as NET_XMIT_SUCCESS) */
55
56 /* Backlog congestion levels */
57 #define NET_RX_SUCCESS          0   /* keep 'em coming, baby */
58 #define NET_RX_DROP             1  /* packet dropped */
59 #define NET_RX_CN_LOW           2   /* storm alert, just in case */
60 #define NET_RX_CN_MOD           3   /* Storm on its way! */
61 #define NET_RX_CN_HIGH          4   /* The storm is here */
62 #define NET_RX_BAD              5  /* packet dropped due to kernel error */
63
64 #define net_xmit_errno(e)       ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
65
66 #endif
67
68 #define MAX_ADDR_LEN    8               /* Largest hardware address length */
69
70 /*
71  *      Compute the worst case header length according to the protocols
72  *      used.
73  */
74  
75 #if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR)
76 #define LL_MAX_HEADER   32
77 #else
78 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
79 #define LL_MAX_HEADER   96
80 #else
81 #define LL_MAX_HEADER   48
82 #endif
83 #endif
84
85 #if !defined(CONFIG_NET_IPIP) && \
86     !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
87 #define MAX_HEADER LL_MAX_HEADER
88 #else
89 #define MAX_HEADER (LL_MAX_HEADER + 48)
90 #endif
91
92 /*
93  *      Network device statistics. Akin to the 2.0 ether stats but
94  *      with byte counters.
95  */
96  
97 struct net_device_stats
98 {
99         unsigned long   rx_packets;             /* total packets received       */
100         unsigned long   tx_packets;             /* total packets transmitted    */
101         unsigned long   rx_bytes;               /* total bytes received         */
102         unsigned long   tx_bytes;               /* total bytes transmitted      */
103         unsigned long   rx_errors;              /* bad packets received         */
104         unsigned long   tx_errors;              /* packet transmit problems     */
105         unsigned long   rx_dropped;             /* no space in linux buffers    */
106         unsigned long   tx_dropped;             /* no space available in linux  */
107         unsigned long   multicast;              /* multicast packets received   */
108         unsigned long   collisions;
109
110         /* detailed rx_errors: */
111         unsigned long   rx_length_errors;
112         unsigned long   rx_over_errors;         /* receiver ring buff overflow  */
113         unsigned long   rx_crc_errors;          /* recved pkt with crc error    */
114         unsigned long   rx_frame_errors;        /* recv'd frame alignment error */
115         unsigned long   rx_fifo_errors;         /* recv'r fifo overrun          */
116         unsigned long   rx_missed_errors;       /* receiver missed packet       */
117
118         /* detailed tx_errors */
119         unsigned long   tx_aborted_errors;
120         unsigned long   tx_carrier_errors;
121         unsigned long   tx_fifo_errors;
122         unsigned long   tx_heartbeat_errors;
123         unsigned long   tx_window_errors;
124         
125         /* for cslip etc */
126         unsigned long   rx_compressed;
127         unsigned long   tx_compressed;
128 };
129
130
131 /* Media selection options. */
132 enum {
133         IF_PORT_UNKNOWN = 0,
134         IF_PORT_10BASE2,
135         IF_PORT_10BASET,
136         IF_PORT_AUI,
137         IF_PORT_100BASET,
138         IF_PORT_100BASETX,
139         IF_PORT_100BASEFX
140 };
141
142 #ifdef __KERNEL__
143
144 extern const char *if_port_text[];
145
146 #include <linux/cache.h>
147 #include <linux/skbuff.h>
148
149 struct neighbour;
150 struct neigh_parms;
151 struct sk_buff;
152
153 struct netif_rx_stats
154 {
155         unsigned total;
156         unsigned dropped;
157         unsigned time_squeeze;
158         unsigned throttled;
159         unsigned fastroute_hit;
160         unsigned fastroute_success;
161         unsigned fastroute_defer;
162         unsigned fastroute_deferred_out;
163         unsigned fastroute_latency_reduction;
164         unsigned cpu_collision;
165 } ____cacheline_aligned;
166
167 extern struct netif_rx_stats netdev_rx_stat[];
168
169
170 /*
171  *      We tag multicasts with these structures.
172  */
173  
174 struct dev_mc_list
175 {       
176         struct dev_mc_list      *next;
177         __u8                    dmi_addr[MAX_ADDR_LEN];
178         unsigned char           dmi_addrlen;
179         int                     dmi_users;
180         int                     dmi_gusers;
181 };
182
183 struct hh_cache
184 {
185         struct hh_cache *hh_next;       /* Next entry                        */
186         atomic_t        hh_refcnt;      /* number of users                   */
187         unsigned short  hh_type;        /* protocol identifier, f.e ETH_P_IP
188                                          *  NOTE:  For VLANs, this will be the
189                                          *  encapuslated type. --BLG
190                                          */
191         int             hh_len;         /* length of header */
192         int             (*hh_output)(struct sk_buff *skb);
193         rwlock_t        hh_lock;
194         /* cached hardware header; allow for machine alignment needs.        */
195         unsigned long   hh_data[16/sizeof(unsigned long)];
196 };
197
198 /* These flag bits are private to the generic network queueing
199  * layer, they may not be explicitly referenced by any other
200  * code.
201  */
202
203 enum netdev_state_t
204 {
205         __LINK_STATE_XOFF=0,
206         __LINK_STATE_START,
207         __LINK_STATE_PRESENT,
208         __LINK_STATE_SCHED,
209         __LINK_STATE_NOCARRIER,
210         __LINK_STATE_RX_SCHED
211 };
212
213
214 /*
215  * This structure holds at boot time configured netdevice settings. They
216  * are then used in the device probing. 
217  */
218 struct netdev_boot_setup {
219         char name[IFNAMSIZ];
220         struct ifmap map;
221 };
222 #define NETDEV_BOOT_SETUP_MAX 8
223
224
225 /*
226  *      The DEVICE structure.
227  *      Actually, this whole structure is a big mistake.  It mixes I/O
228  *      data with strictly "high-level" data, and it has to know about
229  *      almost every data structure used in the INET module.
230  *
231  *      FIXME: cleanup struct net_device such that network protocol info
232  *      moves out.
233  */
234
235 struct net_device
236 {
237
238         /*
239          * This is the first field of the "visible" part of this structure
240          * (i.e. as seen by users in the "Space.c" file).  It is the name
241          * the interface.
242          */
243         char                    name[IFNAMSIZ];
244
245         /*
246          *      I/O specific fields
247          *      FIXME: Merge these and struct ifmap into one
248          */
249         unsigned long           rmem_end;       /* shmem "recv" end     */
250         unsigned long           rmem_start;     /* shmem "recv" start   */
251         unsigned long           mem_end;        /* shared mem end       */
252         unsigned long           mem_start;      /* shared mem start     */
253         unsigned long           base_addr;      /* device I/O address   */
254         unsigned int            irq;            /* device IRQ number    */
255
256         /*
257          *      Some hardware also needs these fields, but they are not
258          *      part of the usual set specified in Space.c.
259          */
260
261         unsigned char           if_port;        /* Selectable AUI, TP,..*/
262         unsigned char           dma;            /* DMA channel          */
263
264         unsigned long           state;
265
266         struct net_device       *next;
267         
268         /* The device initialization function. Called only once. */
269         int                     (*init)(struct net_device *dev);
270
271         /* ------- Fields preinitialized in Space.c finish here ------- */
272
273         struct net_device       *next_sched;
274
275         /* Interface index. Unique device identifier    */
276         int                     ifindex;
277         int                     iflink;
278
279
280         struct net_device_stats* (*get_stats)(struct net_device *dev);
281         struct iw_statistics*   (*get_wireless_stats)(struct net_device *dev);
282
283         /* List of functions to handle Wireless Extensions (instead of ioctl).
284          * See <net/iw_handler.h> for details. Jean II */
285         struct iw_handler_def * wireless_handlers;
286
287         /*
288          * This marks the end of the "visible" part of the structure. All
289          * fields hereafter are internal to the system, and may change at
290          * will (read: may be cleaned up at will).
291          */
292
293         /* These may be needed for future network-power-down code. */
294         unsigned long           trans_start;    /* Time (in jiffies) of last Tx */
295         unsigned long           last_rx;        /* Time of last Rx      */
296
297         unsigned short          flags;  /* interface flags (a la BSD)   */
298         unsigned short          gflags;
299         unsigned short          priv_flags; /* Like 'flags' but invisible to userspace. */
300         unsigned short          unused_alignment_fixer; /* Because we need priv_flags,
301                                                          * and we want to be 32-bit aligned.
302                                                          */
303
304         unsigned                mtu;    /* interface MTU value          */
305         unsigned short          type;   /* interface hardware type      */
306         unsigned short          hard_header_len;        /* hardware hdr length  */
307         void                    *priv;  /* pointer to private data      */
308
309         struct net_device       *master; /* Pointer to master device of a group,
310                                           * which this device is member of.
311                                           */
312
313         /* Interface address info. */
314         unsigned char           broadcast[MAX_ADDR_LEN];        /* hw bcast add */
315         unsigned char           dev_addr[MAX_ADDR_LEN]; /* hw address   */
316         unsigned char           addr_len;       /* hardware address length      */
317
318         struct dev_mc_list      *mc_list;       /* Multicast mac addresses      */
319         int                     mc_count;       /* Number of installed mcasts   */
320         int                     promiscuity;
321         int                     allmulti;
322
323         int                     watchdog_timeo;
324         struct timer_list       watchdog_timer;
325
326         /* Protocol specific pointers */
327         
328         void                    *atalk_ptr;     /* AppleTalk link       */
329         void                    *ip_ptr;        /* IPv4 specific data   */  
330         void                    *dn_ptr;        /* DECnet specific data */
331         void                    *ip6_ptr;       /* IPv6 specific data */
332         void                    *ec_ptr;        /* Econet specific data */
333
334         struct list_head        poll_list;      /* Link to poll list    */
335         int                     quota;
336         int                     weight;
337
338         struct Qdisc            *qdisc;
339         struct Qdisc            *qdisc_sleeping;
340         struct Qdisc            *qdisc_list;
341         struct Qdisc            *qdisc_ingress;
342         unsigned long           tx_queue_len;   /* Max frames per queue allowed */
343
344         /* hard_start_xmit synchronizer */
345         spinlock_t              xmit_lock;
346         /* cpu id of processor entered to hard_start_xmit or -1,
347            if nobody entered there.
348          */
349         int                     xmit_lock_owner;
350         /* device queue lock */
351         spinlock_t              queue_lock;
352         /* Number of references to this device */
353         atomic_t                refcnt;
354         /* The flag marking that device is unregistered, but held by an user */
355         int                     deadbeaf;
356
357         /* Net device features */
358         int                     features;
359 #define NETIF_F_SG              1       /* Scatter/gather IO. */
360 #define NETIF_F_IP_CSUM         2       /* Can checksum only TCP/UDP over IPv4. */
361 #define NETIF_F_NO_CSUM         4       /* Does not require checksum. F.e. loopack. */
362 #define NETIF_F_HW_CSUM         8       /* Can checksum all the packets. */
363 #define NETIF_F_DYNALLOC        16      /* Self-dectructable device. */
364 #define NETIF_F_HIGHDMA         32      /* Can DMA to high memory. */
365 #define NETIF_F_FRAGLIST        64      /* Scatter/gather IO. */
366 #define NETIF_F_HW_VLAN_TX      128     /* Transmit VLAN hw acceleration */
367 #define NETIF_F_HW_VLAN_RX      256     /* Receive VLAN hw acceleration */
368 #define NETIF_F_HW_VLAN_FILTER  512     /* Receive filtering on VLAN */
369 #define NETIF_F_VLAN_CHALLENGED 1024    /* Device cannot handle VLAN packets */
370
371         /* Called after device is detached from network. */
372         void                    (*uninit)(struct net_device *dev);
373         /* Called after last user reference disappears. */
374         void                    (*destructor)(struct net_device *dev);
375
376         /* Pointers to interface service routines.      */
377         int                     (*open)(struct net_device *dev);
378         int                     (*stop)(struct net_device *dev);
379         int                     (*hard_start_xmit) (struct sk_buff *skb,
380                                                     struct net_device *dev);
381 #define HAVE_NETDEV_POLL
382         int                     (*poll) (struct net_device *dev, int *quota);
383         int                     (*hard_header) (struct sk_buff *skb,
384                                                 struct net_device *dev,
385                                                 unsigned short type,
386                                                 void *daddr,
387                                                 void *saddr,
388                                                 unsigned len);
389         int                     (*rebuild_header)(struct sk_buff *skb);
390 #define HAVE_MULTICAST                   
391         void                    (*set_multicast_list)(struct net_device *dev);
392 #define HAVE_SET_MAC_ADDR                
393         int                     (*set_mac_address)(struct net_device *dev,
394                                                    void *addr);
395 #define HAVE_PRIVATE_IOCTL
396         int                     (*do_ioctl)(struct net_device *dev,
397                                             struct ifreq *ifr, int cmd);
398 #define HAVE_SET_CONFIG
399         int                     (*set_config)(struct net_device *dev,
400                                               struct ifmap *map);
401 #define HAVE_HEADER_CACHE
402         int                     (*hard_header_cache)(struct neighbour *neigh,
403                                                      struct hh_cache *hh);
404         void                    (*header_cache_update)(struct hh_cache *hh,
405                                                        struct net_device *dev,
406                                                        unsigned char *  haddr);
407 #define HAVE_CHANGE_MTU
408         int                     (*change_mtu)(struct net_device *dev, int new_mtu);
409
410 #define HAVE_TX_TIMEOUT
411         void                    (*tx_timeout) (struct net_device *dev);
412
413         void                    (*vlan_rx_register)(struct net_device *dev,
414                                                     struct vlan_group *grp);
415         void                    (*vlan_rx_add_vid)(struct net_device *dev,
416                                                    unsigned short vid);
417         void                    (*vlan_rx_kill_vid)(struct net_device *dev,
418                                                     unsigned short vid);
419
420         int                     (*hard_header_parse)(struct sk_buff *skb,
421                                                      unsigned char *haddr);
422         int                     (*neigh_setup)(struct net_device *dev, struct neigh_parms *);
423         int                     (*accept_fastpath)(struct net_device *, struct dst_entry*);
424
425         /* open/release and usage marking */
426         struct module *owner;
427
428         /* bridge stuff */
429         struct net_bridge_port  *br_port;
430
431 #ifdef CONFIG_NET_FASTROUTE
432 #define NETDEV_FASTROUTE_HMASK 0xF
433         /* Semi-private data. Keep it at the end of device struct. */
434         rwlock_t                fastpath_lock;
435         struct dst_entry        *fastpath[NETDEV_FASTROUTE_HMASK+1];
436 #endif
437 #ifdef CONFIG_NET_DIVERT
438         /* this will get initialized at each interface type init routine */
439         struct divert_blk       *divert;
440 #endif /* CONFIG_NET_DIVERT */
441 };
442
443
444 struct packet_type 
445 {
446         unsigned short          type;   /* This is really htons(ether_type).    */
447         struct net_device               *dev;   /* NULL is wildcarded here              */
448         int                     (*func) (struct sk_buff *, struct net_device *,
449                                          struct packet_type *);
450         void                    *data;  /* Private to the packet type           */
451         struct packet_type      *next;
452 };
453
454
455 #include <linux/interrupt.h>
456 #include <linux/notifier.h>
457
458 extern struct net_device                loopback_dev;           /* The loopback */
459 extern struct net_device                *dev_base;              /* All devices */
460 extern rwlock_t                         dev_base_lock;          /* Device list lock */
461
462 extern int                      netdev_boot_setup_add(char *name, struct ifmap *map);
463 extern int                      netdev_boot_setup_check(struct net_device *dev);
464 extern struct net_device    *dev_getbyhwaddr(unsigned short type, char *hwaddr);
465 extern void             dev_add_pack(struct packet_type *pt);
466 extern void             dev_remove_pack(struct packet_type *pt);
467 extern int              dev_get(const char *name);
468 extern struct net_device        *dev_get_by_name(const char *name);
469 extern struct net_device        *__dev_get_by_name(const char *name);
470 extern struct net_device        *dev_alloc(const char *name, int *err);
471 extern int              dev_alloc_name(struct net_device *dev, const char *name);
472 extern int              dev_open(struct net_device *dev);
473 extern int              dev_close(struct net_device *dev);
474 extern int              dev_queue_xmit(struct sk_buff *skb);
475 extern int              register_netdevice(struct net_device *dev);
476 extern int              unregister_netdevice(struct net_device *dev);
477 extern int              register_netdevice_notifier(struct notifier_block *nb);
478 extern int              unregister_netdevice_notifier(struct notifier_block *nb);
479 extern int              dev_new_index(void);
480 extern struct net_device        *dev_get_by_index(int ifindex);
481 extern struct net_device        *__dev_get_by_index(int ifindex);
482 extern int              dev_restart(struct net_device *dev);
483
484 typedef int gifconf_func_t(struct net_device * dev, char * bufptr, int len);
485 extern int              register_gifconf(unsigned int family, gifconf_func_t * gifconf);
486 static inline int unregister_gifconf(unsigned int family)
487 {
488         return register_gifconf(family, 0);
489 }
490
491 /*
492  * Incoming packets are placed on per-cpu queues so that
493  * no locking is needed.
494  */
495
496 struct softnet_data
497 {
498         int                     throttle;
499         int                     cng_level;
500         int                     avg_blog;
501         struct sk_buff_head     input_pkt_queue;
502         struct list_head        poll_list;
503         struct net_device       *output_queue;
504         struct sk_buff          *completion_queue;
505
506         struct net_device       blog_dev;       /* Sorry. 8) */
507 } ____cacheline_aligned;
508
509
510 extern struct softnet_data softnet_data[NR_CPUS];
511
512 #define HAVE_NETIF_QUEUE
513
514 static inline void __netif_schedule(struct net_device *dev)
515 {
516         if (!test_and_set_bit(__LINK_STATE_SCHED, &dev->state)) {
517                 unsigned long flags;
518                 int cpu = smp_processor_id();
519
520                 local_irq_save(flags);
521                 dev->next_sched = softnet_data[cpu].output_queue;
522                 softnet_data[cpu].output_queue = dev;
523                 cpu_raise_softirq(cpu, NET_TX_SOFTIRQ);
524                 local_irq_restore(flags);
525         }
526 }
527
528 static inline void netif_schedule(struct net_device *dev)
529 {
530         if (!test_bit(__LINK_STATE_XOFF, &dev->state))
531                 __netif_schedule(dev);
532 }
533
534 static inline void netif_start_queue(struct net_device *dev)
535 {
536         clear_bit(__LINK_STATE_XOFF, &dev->state);
537 }
538
539 static inline void netif_wake_queue(struct net_device *dev)
540 {
541         if (test_and_clear_bit(__LINK_STATE_XOFF, &dev->state))
542                 __netif_schedule(dev);
543 }
544
545 static inline void netif_stop_queue(struct net_device *dev)
546 {
547         set_bit(__LINK_STATE_XOFF, &dev->state);
548 }
549
550 static inline int netif_queue_stopped(struct net_device *dev)
551 {
552         return test_bit(__LINK_STATE_XOFF, &dev->state);
553 }
554
555 static inline int netif_running(struct net_device *dev)
556 {
557         return test_bit(__LINK_STATE_START, &dev->state);
558 }
559
560
561 /* Use this variant when it is known for sure that it
562  * is executing from interrupt context.
563  */
564 static inline void dev_kfree_skb_irq(struct sk_buff *skb)
565 {
566         if (atomic_dec_and_test(&skb->users)) {
567                 int cpu =smp_processor_id();
568                 unsigned long flags;
569
570                 local_irq_save(flags);
571                 skb->next = softnet_data[cpu].completion_queue;
572                 softnet_data[cpu].completion_queue = skb;
573                 cpu_raise_softirq(cpu, NET_TX_SOFTIRQ);
574                 local_irq_restore(flags);
575         }
576 }
577
578 /* Use this variant in places where it could be invoked
579  * either from interrupt or non-interrupt context.
580  */
581 static inline void dev_kfree_skb_any(struct sk_buff *skb)
582 {
583         if (in_irq())
584                 dev_kfree_skb_irq(skb);
585         else
586                 dev_kfree_skb(skb);
587 }
588
589 #define HAVE_NETIF_RX 1
590 extern int              netif_rx(struct sk_buff *skb);
591 #define HAVE_NETIF_RECEIVE_SKB 1
592 extern int              netif_receive_skb(struct sk_buff *skb);
593 extern int              dev_ioctl(unsigned int cmd, void *);
594 extern int              dev_change_flags(struct net_device *, unsigned);
595 extern void             dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
596
597 extern void             dev_init(void);
598
599 extern int              netdev_nit;
600
601 /* Post buffer to the network code from _non interrupt_ context.
602  * see net/core/dev.c for netif_rx description.
603  */
604 static inline int netif_rx_ni(struct sk_buff *skb)
605 {
606        int err = netif_rx(skb);
607        if (softirq_pending(smp_processor_id()))
608                do_softirq();
609        return err;
610 }
611
612 static inline void dev_init_buffers(struct net_device *dev)
613 {
614         /* WILL BE REMOVED IN 2.5.0 */
615 }
616
617 extern int netdev_finish_unregister(struct net_device *dev);
618
619 static inline void dev_put(struct net_device *dev)
620 {
621         if (atomic_dec_and_test(&dev->refcnt))
622                 netdev_finish_unregister(dev);
623 }
624
625 #define __dev_put(dev) atomic_dec(&(dev)->refcnt)
626 #define dev_hold(dev) atomic_inc(&(dev)->refcnt)
627
628 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
629  * and _off may be called from IRQ context, but it is caller
630  * who is responsible for serialization of these calls.
631  */
632
633 static inline int netif_carrier_ok(struct net_device *dev)
634 {
635         return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
636 }
637
638 extern void __netdev_watchdog_up(struct net_device *dev);
639
640 static inline void netif_carrier_on(struct net_device *dev)
641 {
642         clear_bit(__LINK_STATE_NOCARRIER, &dev->state);
643         if (netif_running(dev))
644                 __netdev_watchdog_up(dev);
645 }
646
647 static inline void netif_carrier_off(struct net_device *dev)
648 {
649         set_bit(__LINK_STATE_NOCARRIER, &dev->state);
650 }
651
652 /* Hot-plugging. */
653 static inline int netif_device_present(struct net_device *dev)
654 {
655         return test_bit(__LINK_STATE_PRESENT, &dev->state);
656 }
657
658 static inline void netif_device_detach(struct net_device *dev)
659 {
660         if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) &&
661             netif_running(dev)) {
662                 netif_stop_queue(dev);
663         }
664 }
665
666 static inline void netif_device_attach(struct net_device *dev)
667 {
668         if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) &&
669             netif_running(dev)) {
670                 netif_wake_queue(dev);
671                 __netdev_watchdog_up(dev);
672         }
673 }
674
675 /*
676  * Network interface message level settings
677  */
678 #define HAVE_NETIF_MSG 1
679
680 enum {
681         NETIF_MSG_DRV           = 0x0001,
682         NETIF_MSG_PROBE         = 0x0002,
683         NETIF_MSG_LINK          = 0x0004,
684         NETIF_MSG_TIMER         = 0x0008,
685         NETIF_MSG_IFDOWN        = 0x0010,
686         NETIF_MSG_IFUP          = 0x0020,
687         NETIF_MSG_RX_ERR        = 0x0040,
688         NETIF_MSG_TX_ERR        = 0x0080,
689         NETIF_MSG_TX_QUEUED     = 0x0100,
690         NETIF_MSG_INTR          = 0x0200,
691         NETIF_MSG_TX_DONE       = 0x0400,
692         NETIF_MSG_RX_STATUS     = 0x0800,
693         NETIF_MSG_PKTDATA       = 0x1000,
694         NETIF_MSG_HW            = 0x2000,
695         NETIF_MSG_WOL           = 0x4000,
696 };
697
698 #define netif_msg_drv(p)        ((p)->msg_enable & NETIF_MSG_DRV)
699 #define netif_msg_probe(p)      ((p)->msg_enable & NETIF_MSG_PROBE)
700 #define netif_msg_link(p)       ((p)->msg_enable & NETIF_MSG_LINK)
701 #define netif_msg_timer(p)      ((p)->msg_enable & NETIF_MSG_TIMER)
702 #define netif_msg_ifdown(p)     ((p)->msg_enable & NETIF_MSG_IFDOWN)
703 #define netif_msg_ifup(p)       ((p)->msg_enable & NETIF_MSG_IFUP)
704 #define netif_msg_rx_err(p)     ((p)->msg_enable & NETIF_MSG_RX_ERR)
705 #define netif_msg_tx_err(p)     ((p)->msg_enable & NETIF_MSG_TX_ERR)
706 #define netif_msg_tx_queued(p)  ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
707 #define netif_msg_intr(p)       ((p)->msg_enable & NETIF_MSG_INTR)
708 #define netif_msg_tx_done(p)    ((p)->msg_enable & NETIF_MSG_TX_DONE)
709 #define netif_msg_rx_status(p)  ((p)->msg_enable & NETIF_MSG_RX_STATUS)
710 #define netif_msg_pktdata(p)    ((p)->msg_enable & NETIF_MSG_PKTDATA)
711 #define netif_msg_hw(p)         ((p)->msg_enable & NETIF_MSG_HW)
712 #define netif_msg_wol(p)        ((p)->msg_enable & NETIF_MSG_WOL)
713
714 /* Schedule rx intr now? */
715
716 static inline int netif_rx_schedule_prep(struct net_device *dev)
717 {
718         return netif_running(dev) &&
719                 !test_and_set_bit(__LINK_STATE_RX_SCHED, &dev->state);
720 }
721
722 /* Add interface to tail of rx poll list. This assumes that _prep has
723  * already been called and returned 1.
724  */
725
726 static inline void __netif_rx_schedule(struct net_device *dev)
727 {
728         unsigned long flags;
729         int cpu = smp_processor_id();
730
731         local_irq_save(flags);
732         dev_hold(dev);
733         list_add_tail(&dev->poll_list, &softnet_data[cpu].poll_list);
734         if (dev->quota < 0)
735                 dev->quota += dev->weight;
736         else
737                 dev->quota = dev->weight;
738         __cpu_raise_softirq(cpu, NET_RX_SOFTIRQ);
739         local_irq_restore(flags);
740 }
741
742 /* Try to reschedule poll. Called by irq handler. */
743
744 static inline void netif_rx_schedule(struct net_device *dev)
745 {
746         if (netif_rx_schedule_prep(dev))
747                 __netif_rx_schedule(dev);
748 }
749
750 /* Try to reschedule poll. Called by dev->poll() after netif_rx_complete().
751  * Do not inline this?
752  */
753 static inline int netif_rx_reschedule(struct net_device *dev, int undo)
754 {
755         if (netif_rx_schedule_prep(dev)) {
756                 unsigned long flags;
757                 int cpu = smp_processor_id();
758
759                 dev->quota += undo;
760
761                 local_irq_save(flags);
762                 list_add_tail(&dev->poll_list, &softnet_data[cpu].poll_list);
763                 __cpu_raise_softirq(cpu, NET_RX_SOFTIRQ);
764                 local_irq_restore(flags);
765                 return 1;
766         }
767         return 0;
768 }
769
770 /* Remove interface from poll list: it must be in the poll list
771  * on current cpu. This primitive is called by dev->poll(), when
772  * it completes the work. The device cannot be out of poll list at this
773  * moment, it is BUG().
774  */
775 static inline void netif_rx_complete(struct net_device *dev)
776 {
777         unsigned long flags;
778
779         local_irq_save(flags);
780         if (!test_bit(__LINK_STATE_RX_SCHED, &dev->state)) BUG();
781         list_del(&dev->poll_list);
782         clear_bit(__LINK_STATE_RX_SCHED, &dev->state);
783         local_irq_restore(flags);
784 }
785
786 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
787
788 extern void             ether_setup(struct net_device *dev);
789 extern void             fddi_setup(struct net_device *dev);
790 extern void             tr_setup(struct net_device *dev);
791 extern void             fc_setup(struct net_device *dev);
792 extern void             fc_freedev(struct net_device *dev);
793 /* Support for loadable net-drivers */
794 extern int              register_netdev(struct net_device *dev);
795 extern void             unregister_netdev(struct net_device *dev);
796 /* Functions used for multicast support */
797 extern void             dev_mc_upload(struct net_device *dev);
798 extern int              dev_mc_delete(struct net_device *dev, void *addr, int alen, int all);
799 extern int              dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly);
800 extern void             dev_mc_discard(struct net_device *dev);
801 extern void             dev_set_promiscuity(struct net_device *dev, int inc);
802 extern void             dev_set_allmulti(struct net_device *dev, int inc);
803 extern void             netdev_state_change(struct net_device *dev);
804 /* Load a device via the kmod */
805 extern void             dev_load(const char *name);
806 extern void             dev_mcast_init(void);
807 extern int              netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev));
808 extern void             netdev_unregister_fc(int bit);
809 extern int              netdev_max_backlog;
810 extern int              weight_p;
811 extern unsigned long    netdev_fc_xoff;
812 extern atomic_t netdev_dropping;
813 extern int              netdev_set_master(struct net_device *dev, struct net_device *master);
814 extern struct sk_buff * skb_checksum_help(struct sk_buff *skb);
815 #ifdef CONFIG_NET_FASTROUTE
816 extern int              netdev_fastroute;
817 extern int              netdev_fastroute_obstacles;
818 extern void             dev_clear_fastroute(struct net_device *dev);
819 #endif
820
821
822 #endif /* __KERNEL__ */
823
824 #endif  /* _LINUX_DEV_H */