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 struct ethtool_ops;
45
46 /* source back-compat hooks */
47 #define SET_ETHTOOL_OPS(netdev,ops) \
48 ( (netdev)->ethtool_ops = (ops) )
49
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() */
54
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) */
62
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 */
70
71 #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
72
73 #endif
74
75 #define MAX_ADDR_LEN 8 /* Largest hardware address length */
76
77 /*
78 * Compute the worst case header length according to the protocols
79 * used.
80 */
81
82 #if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR)
83 #define LL_MAX_HEADER 32
84 #else
85 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
86 #define LL_MAX_HEADER 96
87 #else
88 #define LL_MAX_HEADER 48
89 #endif
90 #endif
91
92 #if !defined(CONFIG_NET_IPIP) && \
93 !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
94 #define MAX_HEADER LL_MAX_HEADER
95 #else
96 #define MAX_HEADER (LL_MAX_HEADER + 48)
97 #endif
98
99 /*
100 * Network device statistics. Akin to the 2.0 ether stats but
101 * with byte counters.
102 */
103
104 struct net_device_stats
105 {
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;
116
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 */
124
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;
131
132 /* for cslip etc */
133 unsigned long rx_compressed;
134 unsigned long tx_compressed;
135 };
136
137
138 /* Media selection options. */
139 enum {
140 IF_PORT_UNKNOWN = 0,
141 IF_PORT_10BASE2,
142 IF_PORT_10BASET,
143 IF_PORT_AUI,
144 IF_PORT_100BASET,
145 IF_PORT_100BASETX,
146 IF_PORT_100BASEFX
147 };
148
149 #ifdef __KERNEL__
150
151 extern const char *if_port_text[];
152
153 #include <linux/cache.h>
154 #include <linux/skbuff.h>
155
156 struct neighbour;
157 struct neigh_parms;
158 struct sk_buff;
159
160 struct netif_rx_stats
161 {
162 unsigned total;
163 unsigned dropped;
164 unsigned time_squeeze;
165 unsigned throttled;
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;
173
174 extern struct netif_rx_stats netdev_rx_stat[];
175
176
177 /*
178 * We tag multicasts with these structures.
179 */
180
181 struct dev_mc_list
182 {
183 struct dev_mc_list *next;
184 __u8 dmi_addr[MAX_ADDR_LEN];
185 unsigned char dmi_addrlen;
186 int dmi_users;
187 int dmi_gusers;
188 };
189
190 struct hh_cache
191 {
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
197 */
198 int hh_len; /* length of header */
199 int (*hh_output)(struct sk_buff *skb);
200 rwlock_t hh_lock;
201
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)];
209 };
210
211 /* These flag bits are private to the generic network queueing
212 * layer, they may not be explicitly referenced by any other
213 * code.
214 */
215
216 enum netdev_state_t
217 {
218 __LINK_STATE_XOFF=0,
219 __LINK_STATE_START,
220 __LINK_STATE_PRESENT,
221 __LINK_STATE_SCHED,
222 __LINK_STATE_NOCARRIER,
223 __LINK_STATE_RX_SCHED
224 };
225
226
227 /*
228 * This structure holds at boot time configured netdevice settings. They
229 * are then used in the device probing.
230 */
231 struct netdev_boot_setup {
232 char name[IFNAMSIZ];
233 struct ifmap map;
234 };
235 #define NETDEV_BOOT_SETUP_MAX 8
236
237
238 /*
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.
243 *
244 * FIXME: cleanup struct net_device such that network protocol info
245 * moves out.
246 */
247
248 struct net_device
249 {
250
251 /*
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
254 * the interface.
255 */
256 char name[IFNAMSIZ];
257
258 /*
259 * I/O specific fields
260 * FIXME: Merge these and struct ifmap into one
261 */
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 */
268
269 /*
270 * Some hardware also needs these fields, but they are not
271 * part of the usual set specified in Space.c.
272 */
273
274 unsigned char if_port; /* Selectable AUI, TP,..*/
275 unsigned char dma; /* DMA channel */
276
277 unsigned long state;
278
279 struct net_device *next;
280
281 /* The device initialization function. Called only once. */
282 int (*init)(struct net_device *dev);
283
284 /* ------- Fields preinitialized in Space.c finish here ------- */
285
286 struct net_device *next_sched;
287
288 /* Interface index. Unique device identifier */
289 int ifindex;
290 int iflink;
291
292
293 struct net_device_stats* (*get_stats)(struct net_device *dev);
294 struct iw_statistics* (*get_wireless_stats)(struct net_device *dev);
295
296 /* List of functions to handle Wireless Extensions (instead of ioctl).
297 * See <net/iw_handler.h> for details. Jean II */
298 struct iw_handler_def * wireless_handlers;
299
300 struct ethtool_ops *ethtool_ops;
301
302 /*
303 * This marks the end of the "visible" part of the structure. All
304 * fields hereafter are internal to the system, and may change at
305 * will (read: may be cleaned up at will).
306 */
307
308 /* These may be needed for future network-power-down code. */
309 unsigned long trans_start; /* Time (in jiffies) of last Tx */
310 unsigned long last_rx; /* Time of last Rx */
311
312 unsigned short flags; /* interface flags (a la BSD) */
313 unsigned short gflags;
314 unsigned short priv_flags; /* Like 'flags' but invisible to userspace. */
315 unsigned short unused_alignment_fixer; /* Because we need priv_flags,
316 * and we want to be 32-bit aligned.
317 */
318
319 unsigned mtu; /* interface MTU value */
320 unsigned short type; /* interface hardware type */
321 unsigned short hard_header_len; /* hardware hdr length */
322 void *priv; /* pointer to private data */
323
324 struct net_device *master; /* Pointer to master device of a group,
325 * which this device is member of.
326 */
327
328 /* Interface address info. */
329 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */
330 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address */
331 unsigned char addr_len; /* hardware address length */
332
333 struct dev_mc_list *mc_list; /* Multicast mac addresses */
334 int mc_count; /* Number of installed mcasts */
335 int promiscuity;
336 int allmulti;
337
338 int watchdog_timeo;
339 struct timer_list watchdog_timer;
340
341 /* Protocol specific pointers */
342
343 void *atalk_ptr; /* AppleTalk link */
344 void *ip_ptr; /* IPv4 specific data */
345 void *dn_ptr; /* DECnet specific data */
346 void *ip6_ptr; /* IPv6 specific data */
347 void *ec_ptr; /* Econet specific data */
348
349 struct list_head poll_list; /* Link to poll list */
350 int quota;
351 int weight;
352
353 struct Qdisc *qdisc;
354 struct Qdisc *qdisc_sleeping;
355 struct Qdisc *qdisc_ingress;
356 struct list_head qdisc_list;
357 unsigned long tx_queue_len; /* Max frames per queue allowed */
358
359 /* hard_start_xmit synchronizer */
360 spinlock_t xmit_lock;
361 /* cpu id of processor entered to hard_start_xmit or -1,
362 if nobody entered there.
363 */
364 int xmit_lock_owner;
365 /* device queue lock */
366 spinlock_t queue_lock;
367 /* Number of references to this device */
368 atomic_t refcnt;
369 /* The flag marking that device is unregistered, but held by an user */
370 int deadbeaf;
371
372 /* Net device features */
373 int features;
374 #define NETIF_F_SG 1 /* Scatter/gather IO. */
375 #define NETIF_F_IP_CSUM 2 /* Can checksum only TCP/UDP over IPv4. */
376 #define NETIF_F_NO_CSUM 4 /* Does not require checksum. F.e. loopack. */
377 #define NETIF_F_HW_CSUM 8 /* Can checksum all the packets. */
378 #define NETIF_F_DYNALLOC 16 /* Self-dectructable device. */
379 #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory. */
380 #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */
381 #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw acceleration */
382 #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw acceleration */
383 #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on VLAN */
384 #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */
385
386 /* Called after device is detached from network. */
387 void (*uninit)(struct net_device *dev);
388 /* Called after last user reference disappears. */
389 void (*destructor)(struct net_device *dev);
390
391 /* Pointers to interface service routines. */
392 int (*open)(struct net_device *dev);
393 int (*stop)(struct net_device *dev);
394 int (*hard_start_xmit) (struct sk_buff *skb,
395 struct net_device *dev);
396 #define HAVE_NETDEV_POLL
397 int (*poll) (struct net_device *dev, int *quota);
398 int (*hard_header) (struct sk_buff *skb,
399 struct net_device *dev,
400 unsigned short type,
401 void *daddr,
402 void *saddr,
403 unsigned len);
404 int (*rebuild_header)(struct sk_buff *skb);
405 #define HAVE_MULTICAST
406 void (*set_multicast_list)(struct net_device *dev);
407 #define HAVE_SET_MAC_ADDR
408 int (*set_mac_address)(struct net_device *dev,
409 void *addr);
410 #define HAVE_PRIVATE_IOCTL
411 int (*do_ioctl)(struct net_device *dev,
412 struct ifreq *ifr, int cmd);
413 #define HAVE_SET_CONFIG
414 int (*set_config)(struct net_device *dev,
415 struct ifmap *map);
416 #define HAVE_HEADER_CACHE
417 int (*hard_header_cache)(struct neighbour *neigh,
418 struct hh_cache *hh);
419 void (*header_cache_update)(struct hh_cache *hh,
420 struct net_device *dev,
421 unsigned char * haddr);
422 #define HAVE_CHANGE_MTU
423 int (*change_mtu)(struct net_device *dev, int new_mtu);
424
425 #define HAVE_TX_TIMEOUT
426 void (*tx_timeout) (struct net_device *dev);
427
428 void (*vlan_rx_register)(struct net_device *dev,
429 struct vlan_group *grp);
430 void (*vlan_rx_add_vid)(struct net_device *dev,
431 unsigned short vid);
432 void (*vlan_rx_kill_vid)(struct net_device *dev,
433 unsigned short vid);
434
435 int (*hard_header_parse)(struct sk_buff *skb,
436 unsigned char *haddr);
437 int (*neigh_setup)(struct net_device *dev, struct neigh_parms *);
438 int (*accept_fastpath)(struct net_device *, struct dst_entry*);
439
440 /* open/release and usage marking */
441 struct module *owner;
442
443 /* bridge stuff */
444 struct net_bridge_port *br_port;
445
446 #ifdef CONFIG_NET_FASTROUTE
447 #define NETDEV_FASTROUTE_HMASK 0xF
448 /* Semi-private data. Keep it at the end of device struct. */
449 rwlock_t fastpath_lock;
450 struct dst_entry *fastpath[NETDEV_FASTROUTE_HMASK+1];
451 #endif
452 #ifdef CONFIG_NET_DIVERT
453 /* this will get initialized at each interface type init routine */
454 struct divert_blk *divert;
455 #endif /* CONFIG_NET_DIVERT */
456 };
457
458 /* 2.6 compatibility */
459 #define SET_NETDEV_DEV(net, pdev) do { } while (0)
460
461 struct packet_type
462 {
463 unsigned short type; /* This is really htons(ether_type). */
464 struct net_device *dev; /* NULL is wildcarded here */
465 int (*func) (struct sk_buff *, struct net_device *,
466 struct packet_type *);
467 void *data; /* Private to the packet type */
468 struct packet_type *next;
469 };
470
netdev_priv(struct net_device * dev)471 static inline void *netdev_priv(struct net_device *dev)
472 {
473 return dev->priv;
474 }
475
476 #include <linux/interrupt.h>
477 #include <linux/notifier.h>
478
479 extern struct net_device loopback_dev; /* The loopback */
480 extern struct net_device *dev_base; /* All devices */
481 extern rwlock_t dev_base_lock; /* Device list lock */
482
483 extern int netdev_boot_setup_add(char *name, struct ifmap *map);
484 extern int netdev_boot_setup_check(struct net_device *dev);
485 extern struct net_device *dev_getbyhwaddr(unsigned short type, char *hwaddr);
486 extern void dev_add_pack(struct packet_type *pt);
487 extern void dev_remove_pack(struct packet_type *pt);
488 extern int dev_get(const char *name);
489 extern struct net_device *dev_get_by_flags(unsigned short flags,
490 unsigned short mask);
491 extern struct net_device *__dev_get_by_flags(unsigned short flags,
492 unsigned short mask);
493 extern struct net_device *dev_get_by_name(const char *name);
494 extern struct net_device *__dev_get_by_name(const char *name);
495 extern struct net_device *dev_alloc(const char *name, int *err);
496 extern int dev_alloc_name(struct net_device *dev, const char *name);
497 extern int dev_open(struct net_device *dev);
498 extern int dev_close(struct net_device *dev);
499 extern int dev_queue_xmit(struct sk_buff *skb);
500 extern int register_netdevice(struct net_device *dev);
501 extern int unregister_netdevice(struct net_device *dev);
502 extern int register_netdevice_notifier(struct notifier_block *nb);
503 extern int unregister_netdevice_notifier(struct notifier_block *nb);
504 extern int dev_new_index(void);
505 extern struct net_device *dev_get_by_index(int ifindex);
506 extern struct net_device *__dev_get_by_index(int ifindex);
507 extern int dev_restart(struct net_device *dev);
508
509 typedef int gifconf_func_t(struct net_device * dev, char * bufptr, int len);
510 extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf);
unregister_gifconf(unsigned int family)511 static inline int unregister_gifconf(unsigned int family)
512 {
513 return register_gifconf(family, 0);
514 }
515
516 /*
517 * Incoming packets are placed on per-cpu queues so that
518 * no locking is needed.
519 */
520
521 struct softnet_data
522 {
523 int throttle;
524 int cng_level;
525 int avg_blog;
526 struct sk_buff_head input_pkt_queue;
527 struct list_head poll_list;
528 struct net_device *output_queue;
529 struct sk_buff *completion_queue;
530
531 struct net_device blog_dev; /* Sorry. 8) */
532 } ____cacheline_aligned;
533
534
535 extern struct softnet_data softnet_data[NR_CPUS];
536
537 #define HAVE_NETIF_QUEUE
538
__netif_schedule(struct net_device * dev)539 static inline void __netif_schedule(struct net_device *dev)
540 {
541 if (!test_and_set_bit(__LINK_STATE_SCHED, &dev->state)) {
542 unsigned long flags;
543 int cpu = smp_processor_id();
544
545 local_irq_save(flags);
546 dev->next_sched = softnet_data[cpu].output_queue;
547 softnet_data[cpu].output_queue = dev;
548 cpu_raise_softirq(cpu, NET_TX_SOFTIRQ);
549 local_irq_restore(flags);
550 }
551 }
552
netif_schedule(struct net_device * dev)553 static inline void netif_schedule(struct net_device *dev)
554 {
555 if (!test_bit(__LINK_STATE_XOFF, &dev->state))
556 __netif_schedule(dev);
557 }
558
netif_start_queue(struct net_device * dev)559 static inline void netif_start_queue(struct net_device *dev)
560 {
561 clear_bit(__LINK_STATE_XOFF, &dev->state);
562 }
563
netif_wake_queue(struct net_device * dev)564 static inline void netif_wake_queue(struct net_device *dev)
565 {
566 if (test_and_clear_bit(__LINK_STATE_XOFF, &dev->state))
567 __netif_schedule(dev);
568 }
569
netif_stop_queue(struct net_device * dev)570 static inline void netif_stop_queue(struct net_device *dev)
571 {
572 set_bit(__LINK_STATE_XOFF, &dev->state);
573 }
574
netif_queue_stopped(struct net_device * dev)575 static inline int netif_queue_stopped(struct net_device *dev)
576 {
577 return test_bit(__LINK_STATE_XOFF, &dev->state);
578 }
579
netif_running(struct net_device * dev)580 static inline int netif_running(struct net_device *dev)
581 {
582 return test_bit(__LINK_STATE_START, &dev->state);
583 }
584
585
586 /* Use this variant when it is known for sure that it
587 * is executing from interrupt context.
588 */
dev_kfree_skb_irq(struct sk_buff * skb)589 static inline void dev_kfree_skb_irq(struct sk_buff *skb)
590 {
591 if (atomic_dec_and_test(&skb->users)) {
592 int cpu =smp_processor_id();
593 unsigned long flags;
594
595 local_irq_save(flags);
596 skb->next = softnet_data[cpu].completion_queue;
597 softnet_data[cpu].completion_queue = skb;
598 cpu_raise_softirq(cpu, NET_TX_SOFTIRQ);
599 local_irq_restore(flags);
600 }
601 }
602
603 /* Use this variant in places where it could be invoked
604 * either from interrupt or non-interrupt context.
605 */
dev_kfree_skb_any(struct sk_buff * skb)606 static inline void dev_kfree_skb_any(struct sk_buff *skb)
607 {
608 if (in_irq())
609 dev_kfree_skb_irq(skb);
610 else
611 dev_kfree_skb(skb);
612 }
613
614 #define HAVE_NETIF_RX 1
615 extern int netif_rx(struct sk_buff *skb);
616 #define HAVE_NETIF_RECEIVE_SKB 1
617 extern int netif_receive_skb(struct sk_buff *skb);
618 extern int dev_ioctl(unsigned int cmd, void *);
619 extern int dev_ethtool(struct ifreq *);
620 extern int dev_change_flags(struct net_device *, unsigned);
621 extern void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
622
623 extern void dev_init(void);
624
625 extern int netdev_nit;
626
627 /* Post buffer to the network code from _non interrupt_ context.
628 * see net/core/dev.c for netif_rx description.
629 */
netif_rx_ni(struct sk_buff * skb)630 static inline int netif_rx_ni(struct sk_buff *skb)
631 {
632 int err = netif_rx(skb);
633 if (softirq_pending(smp_processor_id()))
634 do_softirq();
635 return err;
636 }
637
dev_init_buffers(struct net_device * dev)638 static inline void dev_init_buffers(struct net_device *dev)
639 {
640 /* WILL BE REMOVED IN 2.5.0 */
641 }
642
643 extern int netdev_finish_unregister(struct net_device *dev);
644
dev_put(struct net_device * dev)645 static inline void dev_put(struct net_device *dev)
646 {
647 if (atomic_dec_and_test(&dev->refcnt))
648 netdev_finish_unregister(dev);
649 }
650
651 #define __dev_put(dev) atomic_dec(&(dev)->refcnt)
652 #define dev_hold(dev) atomic_inc(&(dev)->refcnt)
653
654 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
655 * and _off may be called from IRQ context, but it is caller
656 * who is responsible for serialization of these calls.
657 */
658
netif_carrier_ok(struct net_device * dev)659 static inline int netif_carrier_ok(struct net_device *dev)
660 {
661 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
662 }
663
664 extern void __netdev_watchdog_up(struct net_device *dev);
665
netif_carrier_on(struct net_device * dev)666 static inline void netif_carrier_on(struct net_device *dev)
667 {
668 clear_bit(__LINK_STATE_NOCARRIER, &dev->state);
669 if (netif_running(dev))
670 __netdev_watchdog_up(dev);
671 }
672
netif_carrier_off(struct net_device * dev)673 static inline void netif_carrier_off(struct net_device *dev)
674 {
675 set_bit(__LINK_STATE_NOCARRIER, &dev->state);
676 }
677
678 /* Hot-plugging. */
netif_device_present(struct net_device * dev)679 static inline int netif_device_present(struct net_device *dev)
680 {
681 return test_bit(__LINK_STATE_PRESENT, &dev->state);
682 }
683
netif_device_detach(struct net_device * dev)684 static inline void netif_device_detach(struct net_device *dev)
685 {
686 if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) &&
687 netif_running(dev)) {
688 netif_stop_queue(dev);
689 }
690 }
691
netif_device_attach(struct net_device * dev)692 static inline void netif_device_attach(struct net_device *dev)
693 {
694 if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) &&
695 netif_running(dev)) {
696 netif_wake_queue(dev);
697 __netdev_watchdog_up(dev);
698 }
699 }
700
701 /*
702 * Network interface message level settings
703 */
704 #define HAVE_NETIF_MSG 1
705
706 enum {
707 NETIF_MSG_DRV = 0x0001,
708 NETIF_MSG_PROBE = 0x0002,
709 NETIF_MSG_LINK = 0x0004,
710 NETIF_MSG_TIMER = 0x0008,
711 NETIF_MSG_IFDOWN = 0x0010,
712 NETIF_MSG_IFUP = 0x0020,
713 NETIF_MSG_RX_ERR = 0x0040,
714 NETIF_MSG_TX_ERR = 0x0080,
715 NETIF_MSG_TX_QUEUED = 0x0100,
716 NETIF_MSG_INTR = 0x0200,
717 NETIF_MSG_TX_DONE = 0x0400,
718 NETIF_MSG_RX_STATUS = 0x0800,
719 NETIF_MSG_PKTDATA = 0x1000,
720 NETIF_MSG_HW = 0x2000,
721 NETIF_MSG_WOL = 0x4000,
722 };
723
724 #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
725 #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
726 #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
727 #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
728 #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
729 #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
730 #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
731 #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
732 #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
733 #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
734 #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
735 #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
736 #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
737 #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
738 #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
739
netif_msg_init(int debug_value,int default_msg_enable_bits)740 static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
741 {
742 /* use default */
743 if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
744 return default_msg_enable_bits;
745 if (debug_value == 0) /* no output */
746 return 0;
747 /* set low N bits */
748 return (1 << debug_value) - 1;
749 }
750
751 /* Schedule rx intr now? */
752
netif_rx_schedule_prep(struct net_device * dev)753 static inline int netif_rx_schedule_prep(struct net_device *dev)
754 {
755 return netif_running(dev) &&
756 !test_and_set_bit(__LINK_STATE_RX_SCHED, &dev->state);
757 }
758
759 /* Add interface to tail of rx poll list. This assumes that _prep has
760 * already been called and returned 1.
761 */
762
__netif_rx_schedule(struct net_device * dev)763 static inline void __netif_rx_schedule(struct net_device *dev)
764 {
765 unsigned long flags;
766 int cpu = smp_processor_id();
767
768 local_irq_save(flags);
769 dev_hold(dev);
770 list_add_tail(&dev->poll_list, &softnet_data[cpu].poll_list);
771 if (dev->quota < 0)
772 dev->quota += dev->weight;
773 else
774 dev->quota = dev->weight;
775 __cpu_raise_softirq(cpu, NET_RX_SOFTIRQ);
776 local_irq_restore(flags);
777 }
778
779 /* Try to reschedule poll. Called by irq handler. */
780
netif_rx_schedule(struct net_device * dev)781 static inline void netif_rx_schedule(struct net_device *dev)
782 {
783 if (netif_rx_schedule_prep(dev))
784 __netif_rx_schedule(dev);
785 }
786
787 /* Try to reschedule poll. Called by dev->poll() after netif_rx_complete().
788 * Do not inline this?
789 */
netif_rx_reschedule(struct net_device * dev,int undo)790 static inline int netif_rx_reschedule(struct net_device *dev, int undo)
791 {
792 if (netif_rx_schedule_prep(dev)) {
793 unsigned long flags;
794 int cpu = smp_processor_id();
795
796 dev->quota += undo;
797
798 local_irq_save(flags);
799 list_add_tail(&dev->poll_list, &softnet_data[cpu].poll_list);
800 __cpu_raise_softirq(cpu, NET_RX_SOFTIRQ);
801 local_irq_restore(flags);
802 return 1;
803 }
804 return 0;
805 }
806
807 /* Remove interface from poll list: it must be in the poll list
808 * on current cpu. This primitive is called by dev->poll(), when
809 * it completes the work. The device cannot be out of poll list at this
810 * moment, it is BUG().
811 */
netif_rx_complete(struct net_device * dev)812 static inline void netif_rx_complete(struct net_device *dev)
813 {
814 unsigned long flags;
815
816 local_irq_save(flags);
817 if (!test_bit(__LINK_STATE_RX_SCHED, &dev->state)) BUG();
818 list_del(&dev->poll_list);
819 smp_mb__before_clear_bit();
820 clear_bit(__LINK_STATE_RX_SCHED, &dev->state);
821 local_irq_restore(flags);
822 }
823
netif_poll_disable(struct net_device * dev)824 static inline void netif_poll_disable(struct net_device *dev)
825 {
826 while (test_and_set_bit(__LINK_STATE_RX_SCHED, &dev->state)) {
827 /* No hurry. */
828 current->state = TASK_INTERRUPTIBLE;
829 schedule_timeout(1);
830 }
831 }
832
netif_poll_enable(struct net_device * dev)833 static inline void netif_poll_enable(struct net_device *dev)
834 {
835 clear_bit(__LINK_STATE_RX_SCHED, &dev->state);
836 }
837
838 /* same as netif_rx_complete, except that local_irq_save(flags)
839 * has already been issued
840 */
__netif_rx_complete(struct net_device * dev)841 static inline void __netif_rx_complete(struct net_device *dev)
842 {
843 if (!test_bit(__LINK_STATE_RX_SCHED, &dev->state)) BUG();
844 list_del(&dev->poll_list);
845 smp_mb__before_clear_bit();
846 clear_bit(__LINK_STATE_RX_SCHED, &dev->state);
847 }
848
netif_tx_disable(struct net_device * dev)849 static inline void netif_tx_disable(struct net_device *dev)
850 {
851 spin_lock_bh(&dev->xmit_lock);
852 netif_stop_queue(dev);
853 spin_unlock_bh(&dev->xmit_lock);
854 }
855
856 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
857
858 extern void ether_setup(struct net_device *dev);
859 extern void fddi_setup(struct net_device *dev);
860 extern void tr_setup(struct net_device *dev);
861 extern void fc_setup(struct net_device *dev);
862 extern void fc_freedev(struct net_device *dev);
863 /* Support for loadable net-drivers */
864 extern struct net_device *alloc_netdev(int sizeof_priv, const char *name,
865 void (*setup)(struct net_device *));
866 extern int register_netdev(struct net_device *dev);
867 extern void unregister_netdev(struct net_device *dev);
868 /* Functions used for multicast support */
869 extern void dev_mc_upload(struct net_device *dev);
870 extern int dev_mc_delete(struct net_device *dev, void *addr, int alen, int all);
871 extern int dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly);
872 extern void dev_mc_discard(struct net_device *dev);
873 extern void dev_set_promiscuity(struct net_device *dev, int inc);
874 extern void dev_set_allmulti(struct net_device *dev, int inc);
875 extern void netdev_state_change(struct net_device *dev);
876 /* Load a device via the kmod */
877 extern void dev_load(const char *name);
878 extern void dev_mcast_init(void);
879 extern int netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev));
880 extern void netdev_unregister_fc(int bit);
881 extern int netdev_max_backlog;
882 extern int weight_p;
883 extern unsigned long netdev_fc_xoff;
884 extern atomic_t netdev_dropping;
885 extern int netdev_set_master(struct net_device *dev, struct net_device *master);
886 extern struct sk_buff * skb_checksum_help(struct sk_buff *skb);
887 #ifdef CONFIG_NET_FASTROUTE
888 extern int netdev_fastroute;
889 extern int netdev_fastroute_obstacles;
890 extern void dev_clear_fastroute(struct net_device *dev);
891 #endif
892
free_netdev(struct net_device * dev)893 static inline void free_netdev(struct net_device *dev)
894 {
895 kfree(dev);
896 }
897
898 #endif /* __KERNEL__ */
899
900 #endif /* _LINUX_DEV_H */
901