Main Page | Class List | File List | Class Members | File Members

netdevice.h

Go to the documentation of this file.
00001 /* 00002 * INET An implementation of the TCP/IP protocol suite for the LINUX 00003 * operating system. INET is implemented using the BSD Socket 00004 * interface as the means of communication with the user level. 00005 * 00006 * Definitions for the Interfaces handler. 00007 * 00008 * Version: @(#)dev.h 1.0.10 08/12/93 00009 * 00010 * Authors: Ross Biro, <bir7@leland.Stanford.Edu> 00011 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 00012 * Corey Minyard <wf-rch!minyard@relay.EU.net> 00013 * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov> 00014 * Alan Cox, <Alan.Cox@linux.org> 00015 * Bjorn Ekwall. <bj0rn@blox.se> 00016 * Pekka Riikonen <priikone@poseidon.pspt.fi> 00017 * 00018 * This program is free software; you can redistribute it and/or 00019 * modify it under the terms of the GNU General Public License 00020 * as published by the Free Software Foundation; either version 00021 * 2 of the License, or (at your option) any later version. 00022 * 00023 * Moved to /usr/include/linux for NET3 00024 */ 00025 #ifndef _LINUX_NETDEVICE_H 00026 #define _LINUX_NETDEVICE_H 00027 00028 #include <linux/if.h> 00029 #include <linux/if_ether.h> 00030 #include <linux/if_packet.h> 00031 00032 #include <asm/atomic.h> 00033 #include <asm/cache.h> 00034 #include <asm/byteorder.h> 00035 00036 #ifdef __KERNEL__ 00037 #include <linux/config.h> 00038 #ifdef CONFIG_NET_PROFILE 00039 #include <net/profile.h> 00040 #endif 00041 00042 struct divert_blk; 00043 struct vlan_group; 00044 struct ethtool_ops; 00045 00046 /* source back-compat hook */ 00047 #define SET_ETHTOOL_OPS(netdev,ops) \ 00048 ( (netdev)->ethtool_ops = (ops) ) 00049 00050 #define HAVE_ALLOC_NETDEV /* feature macro: alloc_xxxdev 00051 functions are available. */ 00052 #define HAVE_FREE_NETDEV 00053 00054 #define NET_XMIT_SUCCESS 0 00055 #define NET_XMIT_DROP 1 /* skb dropped */ 00056 #define NET_XMIT_CN 2 /* congestion notification */ 00057 #define NET_XMIT_POLICED 3 /* skb is shot by police */ 00058 #define NET_XMIT_BYPASS 4 /* packet does not leave via dequeue; 00059 (TC use only - dev_queue_xmit 00060 returns this as NET_XMIT_SUCCESS) */ 00061 00062 /* Backlog congestion levels */ 00063 #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ 00064 #define NET_RX_DROP 1 /* packet dropped */ 00065 #define NET_RX_CN_LOW 2 /* storm alert, just in case */ 00066 #define NET_RX_CN_MOD 3 /* Storm on its way! */ 00067 #define NET_RX_CN_HIGH 4 /* The storm is here */ 00068 #define NET_RX_BAD 5 /* packet dropped due to kernel error */ 00069 00070 #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0) 00071 00072 #endif 00073 00074 #define MAX_ADDR_LEN 8 /* Largest hardware address length */ 00075 00076 /* 00077 * Compute the worst case header length according to the protocols 00078 * used. 00079 */ 00080 00081 #if !defined(CONFIG_AX25) && !defined(CONFIG_AX25_MODULE) && !defined(CONFIG_TR) 00082 #define LL_MAX_HEADER 32 00083 #else 00084 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) 00085 #define LL_MAX_HEADER 96 00086 #else 00087 #define LL_MAX_HEADER 48 00088 #endif 00089 #endif 00090 00091 #if !defined(CONFIG_NET_IPIP) && \ 00092 !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE) 00093 #define MAX_HEADER LL_MAX_HEADER 00094 #else 00095 #define MAX_HEADER (LL_MAX_HEADER + 48) 00096 #endif 00097 00098 /* 00099 * Network device statistics. Akin to the 2.0 ether stats but 00100 * with byte counters. 00101 */ 00102 00103 struct net_device_stats 00104 { 00105 unsigned long rx_packets; /* total packets received */ 00106 unsigned long tx_packets; /* total packets transmitted */ 00107 unsigned long rx_bytes; /* total bytes received */ 00108 unsigned long tx_bytes; /* total bytes transmitted */ 00109 unsigned long rx_errors; /* bad packets received */ 00110 unsigned long tx_errors; /* packet transmit problems */ 00111 unsigned long rx_dropped; /* no space in linux buffers */ 00112 unsigned long tx_dropped; /* no space available in linux */ 00113 unsigned long multicast; /* multicast packets received */ 00114 unsigned long collisions; 00115 00116 /* detailed rx_errors: */ 00117 unsigned long rx_length_errors; 00118 unsigned long rx_over_errors; /* receiver ring buff overflow */ 00119 unsigned long rx_crc_errors; /* recved pkt with crc error */ 00120 unsigned long rx_frame_errors; /* recv'd frame alignment error */ 00121 unsigned long rx_fifo_errors; /* recv'r fifo overrun */ 00122 unsigned long rx_missed_errors; /* receiver missed packet */ 00123 00124 /* detailed tx_errors */ 00125 unsigned long tx_aborted_errors; 00126 unsigned long tx_carrier_errors; 00127 unsigned long tx_fifo_errors; 00128 unsigned long tx_heartbeat_errors; 00129 unsigned long tx_window_errors; 00130 00131 /* for cslip etc */ 00132 unsigned long rx_compressed; 00133 unsigned long tx_compressed; 00134 }; 00135 00136 00137 /* Media selection options. */ 00138 enum { 00139 IF_PORT_UNKNOWN = 0, 00140 IF_PORT_10BASE2, 00141 IF_PORT_10BASET, 00142 IF_PORT_AUI, 00143 IF_PORT_100BASET, 00144 IF_PORT_100BASETX, 00145 IF_PORT_100BASEFX 00146 }; 00147 00148 #ifdef __KERNEL__ 00149 00150 extern const char *if_port_text[]; 00151 00152 #include <linux/cache.h> 00153 #include <linux/skbuff.h> 00154 00155 struct neighbour; 00156 struct neigh_parms; 00157 struct sk_buff; 00158 00159 struct netif_rx_stats 00160 { 00161 unsigned total; 00162 unsigned dropped; 00163 unsigned time_squeeze; 00164 unsigned throttled; 00165 unsigned fastroute_hit; 00166 unsigned fastroute_success; 00167 unsigned fastroute_defer; 00168 unsigned fastroute_deferred_out; 00169 unsigned fastroute_latency_reduction; 00170 unsigned cpu_collision; 00171 } ____cacheline_aligned; 00172 00173 extern struct netif_rx_stats netdev_rx_stat[]; 00174 00175 00176 /* 00177 * We tag multicasts with these structures. 00178 */ 00179 00180 struct dev_mc_list 00181 { 00182 struct dev_mc_list *next; 00183 __u8 dmi_addr[MAX_ADDR_LEN]; 00184 unsigned char dmi_addrlen; 00185 int dmi_users; 00186 int dmi_gusers; 00187 }; 00188 00189 struct hh_cache 00190 { 00191 struct hh_cache *hh_next; /* Next entry */ 00192 atomic_t hh_refcnt; /* number of users */ 00193 unsigned short hh_type; /* protocol identifier, f.e ETH_P_IP 00194 * NOTE: For VLANs, this will be the 00195 * encapuslated type. --BLG 00196 */ 00197 int hh_len; /* length of header */ 00198 int (*hh_output)(struct sk_buff *skb); 00199 rwlock_t hh_lock; 00200 00201 /* cached hardware header; allow for machine alignment needs. */ 00202 #define HH_DATA_MOD 16 00203 #define HH_DATA_OFF(__len) \ 00204 (HH_DATA_MOD - ((__len) & (HH_DATA_MOD - 1))) 00205 #define HH_DATA_ALIGN(__len) \ 00206 (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1)) 00207 unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)]; 00208 }; 00209 00210 /* These flag bits are private to the generic network queueing 00211 * layer, they may not be explicitly referenced by any other 00212 * code. 00213 */ 00214 00215 enum netdev_state_t 00216 { 00217 __LINK_STATE_XOFF=0, 00218 __LINK_STATE_START, 00219 __LINK_STATE_PRESENT, 00220 __LINK_STATE_SCHED, 00221 __LINK_STATE_NOCARRIER, 00222 __LINK_STATE_RX_SCHED 00223 }; 00224 00225 00226 /* 00227 * This structure holds at boot time configured netdevice settings. They 00228 * are then used in the device probing. 00229 */ 00230 struct netdev_boot_setup { 00231 char name[IFNAMSIZ]; 00232 struct ifmap map; 00233 }; 00234 #define NETDEV_BOOT_SETUP_MAX 8 00235 00236 00237 /* 00238 * The DEVICE structure. 00239 * Actually, this whole structure is a big mistake. It mixes I/O 00240 * data with strictly "high-level" data, and it has to know about 00241 * almost every data structure used in the INET module. 00242 * 00243 * FIXME: cleanup struct net_device such that network protocol info 00244 * moves out. 00245 */ 00246 00247 struct net_device 00248 { 00249 00250 /* 00251 * This is the first field of the "visible" part of this structure 00252 * (i.e. as seen by users in the "Space.c" file). It is the name 00253 * the interface. 00254 */ 00255 char name[IFNAMSIZ]; 00256 00257 /* 00258 * I/O specific fields 00259 * FIXME: Merge these and struct ifmap into one 00260 */ 00261 unsigned long rmem_end; /* shmem "recv" end */ 00262 unsigned long rmem_start; /* shmem "recv" start */ 00263 unsigned long mem_end; /* shared mem end */ 00264 unsigned long mem_start; /* shared mem start */ 00265 unsigned long base_addr; /* device I/O address */ 00266 unsigned int irq; /* device IRQ number */ 00267 00268 /* 00269 * Some hardware also needs these fields, but they are not 00270 * part of the usual set specified in Space.c. 00271 */ 00272 00273 unsigned char if_port; /* Selectable AUI, TP,..*/ 00274 unsigned char dma; /* DMA channel */ 00275 00276 unsigned long state; 00277 00278 struct net_device *next; 00279 00280 /* The device initialization function. Called only once. */ 00281 int (*init)(struct net_device *dev); 00282 00283 /* ------- Fields preinitialized in Space.c finish here ------- */ 00284 00285 struct net_device *next_sched; 00286 00287 /* Interface index. Unique device identifier */ 00288 int ifindex; 00289 int iflink; 00290 00291 00292 struct net_device_stats* (*get_stats)(struct net_device *dev); 00293 struct iw_statistics* (*get_wireless_stats)(struct net_device *dev); 00294 00295 /* List of functions to handle Wireless Extensions (instead of ioctl). 00296 * See <net/iw_handler.h> for details. Jean II */ 00297 struct iw_handler_def * wireless_handlers; 00298 00299 struct ethtool_ops *ethtool_ops; 00300 00301 /* 00302 * This marks the end of the "visible" part of the structure. All 00303 * fields hereafter are internal to the system, and may change at 00304 * will (read: may be cleaned up at will). 00305 */ 00306 00307 /* These may be needed for future network-power-down code. */ 00308 unsigned long trans_start; /* Time (in jiffies) of last Tx */ 00309 unsigned long last_rx; /* Time of last Rx */ 00310 00311 unsigned short flags; /* interface flags (a la BSD) */ 00312 unsigned short gflags; 00313 unsigned short priv_flags; /* Like 'flags' but invisible to userspace. */ 00314 unsigned short unused_alignment_fixer; /* Because we need priv_flags, 00315 * and we want to be 32-bit aligned. 00316 */ 00317 00318 unsigned mtu; /* interface MTU value */ 00319 unsigned short type; /* interface hardware type */ 00320 unsigned short hard_header_len; /* hardware hdr length */ 00321 void *priv; /* pointer to private data */ 00322 00323 struct net_device *master; /* Pointer to master device of a group, 00324 * which this device is member of. 00325 */ 00326 00327 /* Interface address info. */ 00328 unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */ 00329 unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address */ 00330 unsigned char addr_len; /* hardware address length */ 00331 00332 struct dev_mc_list *mc_list; /* Multicast mac addresses */ 00333 int mc_count; /* Number of installed mcasts */ 00334 int promiscuity; 00335 int allmulti; 00336 00337 int watchdog_timeo; 00338 struct timer_list watchdog_timer; 00339 00340 /* Protocol specific pointers */ 00341 00342 void *atalk_ptr; /* AppleTalk link */ 00343 void *ip_ptr; /* IPv4 specific data */ 00344 void *dn_ptr; /* DECnet specific data */ 00345 void *ip6_ptr; /* IPv6 specific data */ 00346 void *ec_ptr; /* Econet specific data */ 00347 00348 struct list_head poll_list; /* Link to poll list */ 00349 int quota; 00350 int weight; 00351 00352 struct Qdisc *qdisc; 00353 struct Qdisc *qdisc_sleeping; 00354 struct Qdisc *qdisc_list; 00355 struct Qdisc *qdisc_ingress; 00356 unsigned long tx_queue_len; /* Max frames per queue allowed */ 00357 00358 /* hard_start_xmit synchronizer */ 00359 spinlock_t xmit_lock; 00360 /* cpu id of processor entered to hard_start_xmit or -1, 00361 if nobody entered there. 00362 */ 00363 int xmit_lock_owner; 00364 /* device queue lock */ 00365 spinlock_t queue_lock; 00366 /* Number of references to this device */ 00367 atomic_t refcnt; 00368 /* The flag marking that device is unregistered, but held by an user */ 00369 int deadbeaf; 00370 00371 /* Net device features */ 00372 int features; 00373 #define NETIF_F_SG 1 /* Scatter/gather IO. */ 00374 #define NETIF_F_IP_CSUM 2 /* Can checksum only TCP/UDP over IPv4. */ 00375 #define NETIF_F_NO_CSUM 4 /* Does not require checksum. F.e. loopack. */ 00376 #define NETIF_F_HW_CSUM 8 /* Can checksum all the packets. */ 00377 #define NETIF_F_DYNALLOC 16 /* Self-dectructable device. */ 00378 #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory. */ 00379 #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */ 00380 #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw acceleration */ 00381 #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw acceleration */ 00382 #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on VLAN */ 00383 #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */ 00384 00385 /* Called after device is detached from network. */ 00386 void (*uninit)(struct net_device *dev); 00387 /* Called after last user reference disappears. */ 00388 void (*destructor)(struct net_device *dev); 00389 00390 /* Pointers to interface service routines. */ 00391 int (*open)(struct net_device *dev); 00392 int (*stop)(struct net_device *dev); 00393 int (*hard_start_xmit) (struct sk_buff *skb, 00394 struct net_device *dev); 00395 #define HAVE_NETDEV_POLL 00396 int (*poll) (struct net_device *dev, int *quota); 00397 int (*hard_header) (struct sk_buff *skb, 00398 struct net_device *dev, 00399 unsigned short type, 00400 void *daddr, 00401 void *saddr, 00402 unsigned len); 00403 int (*rebuild_header)(struct sk_buff *skb); 00404 #define HAVE_MULTICAST 00405 void (*set_multicast_list)(struct net_device *dev); 00406 #define HAVE_SET_MAC_ADDR 00407 int (*set_mac_address)(struct net_device *dev, 00408 void *addr); 00409 #define HAVE_PRIVATE_IOCTL 00410 int (*do_ioctl)(struct net_device *dev, 00411 struct ifreq *ifr, int cmd); 00412 #define HAVE_SET_CONFIG 00413 int (*set_config)(struct net_device *dev, 00414 struct ifmap *map); 00415 #define HAVE_HEADER_CACHE 00416 int (*hard_header_cache)(struct neighbour *neigh, 00417 struct hh_cache *hh); 00418 void (*header_cache_update)(struct hh_cache *hh, 00419 struct net_device *dev, 00420 unsigned char * haddr); 00421 #define HAVE_CHANGE_MTU 00422 int (*change_mtu)(struct net_device *dev, int new_mtu); 00423 00424 #define HAVE_TX_TIMEOUT 00425 void (*tx_timeout) (struct net_device *dev); 00426 00427 void (*vlan_rx_register)(struct net_device *dev, 00428 struct vlan_group *grp); 00429 void (*vlan_rx_add_vid)(struct net_device *dev, 00430 unsigned short vid); 00431 void (*vlan_rx_kill_vid)(struct net_device *dev, 00432 unsigned short vid); 00433 00434 int (*hard_header_parse)(struct sk_buff *skb, 00435 unsigned char *haddr); 00436 int (*neigh_setup)(struct net_device *dev, struct neigh_parms *); 00437 int (*accept_fastpath)(struct net_device *, struct dst_entry*); 00438 00439 /* open/release and usage marking */ 00440 struct module *owner; 00441 00442 /* bridge stuff */ 00443 struct net_bridge_port *br_port; 00444 00445 #ifdef CONFIG_NET_FASTROUTE 00446 #define NETDEV_FASTROUTE_HMASK 0xF 00447 /* Semi-private data. Keep it at the end of device struct. */ 00448 rwlock_t fastpath_lock; 00449 struct dst_entry *fastpath[NETDEV_FASTROUTE_HMASK+1]; 00450 #endif 00451 #ifdef CONFIG_NET_DIVERT 00452 /* this will get initialized at each interface type init routine */ 00453 struct divert_blk *divert; 00454 #endif /* CONFIG_NET_DIVERT */ 00455 }; 00456 00457 00458 struct packet_type 00459 { 00460 unsigned short type; /* This is really htons(ether_type). */ 00461 struct net_device *dev; /* NULL is wildcarded here */ 00462 int (*func) (struct sk_buff *, struct net_device *, 00463 struct packet_type *); 00464 void *data; /* Private to the packet type */ 00465 struct packet_type *next; 00466 }; 00467 00468 00469 #include <linux/interrupt.h> 00470 #include <linux/notifier.h> 00471 00472 extern struct net_device loopback_dev; /* The loopback */ 00473 extern struct net_device *dev_base; /* All devices */ 00474 extern rwlock_t dev_base_lock; /* Device list lock */ 00475 00476 extern int netdev_boot_setup_add(char *name, struct ifmap *map); 00477 extern int netdev_boot_setup_check(struct net_device *dev); 00478 extern struct net_device *dev_getbyhwaddr(unsigned short type, char *hwaddr); 00479 extern void dev_add_pack(struct packet_type *pt); 00480 extern void dev_remove_pack(struct packet_type *pt); 00481 extern int dev_get(const char *name); 00482 extern struct net_device *dev_get_by_flags(unsigned short flags, 00483 unsigned short mask); 00484 extern struct net_device *__dev_get_by_flags(unsigned short flags, 00485 unsigned short mask); 00486 extern struct net_device *dev_get_by_name(const char *name); 00487 extern struct net_device *__dev_get_by_name(const char *name); 00488 extern struct net_device *dev_alloc(const char *name, int *err); 00489 extern int dev_alloc_name(struct net_device *dev, const char *name); 00490 extern int dev_open(struct net_device *dev); 00491 extern int dev_close(struct net_device *dev); 00492 extern int dev_queue_xmit(struct sk_buff *skb); 00493 extern int register_netdevice(struct net_device *dev); 00494 extern int unregister_netdevice(struct net_device *dev); 00495 extern int register_netdevice_notifier(struct notifier_block *nb); 00496 extern int unregister_netdevice_notifier(struct notifier_block *nb); 00497 extern int dev_new_index(void); 00498 extern struct net_device *dev_get_by_index(int ifindex); 00499 extern struct net_device *__dev_get_by_index(int ifindex); 00500 extern int dev_restart(struct net_device *dev); 00501 00502 typedef int gifconf_func_t(struct net_device * dev, char * bufptr, int len); 00503 extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf); 00504 static inline int unregister_gifconf(unsigned int family) 00505 { 00506 return register_gifconf(family, 0); 00507 } 00508 00509 /* 00510 * Incoming packets are placed on per-cpu queues so that 00511 * no locking is needed. 00512 */ 00513 00514 struct softnet_data 00515 { 00516 int throttle; 00517 int cng_level; 00518 int avg_blog; 00519 struct sk_buff_head input_pkt_queue; 00520 struct list_head poll_list; 00521 struct net_device *output_queue; 00522 struct sk_buff *completion_queue; 00523 00524 struct net_device blog_dev; /* Sorry. 8) */ 00525 } ____cacheline_aligned; 00526 00527 00528 extern struct softnet_data softnet_data[NR_CPUS]; 00529 00530 #define HAVE_NETIF_QUEUE 00531 00532 static inline void __netif_schedule(struct net_device *dev) 00533 { 00534 if (!test_and_set_bit(__LINK_STATE_SCHED, &dev->state)) { 00535 unsigned long flags; 00536 int cpu = smp_processor_id(); 00537 00538 local_irq_save(flags); 00539 dev->next_sched = softnet_data[cpu].output_queue; 00540 softnet_data[cpu].output_queue = dev; 00541 cpu_raise_softirq(cpu, NET_TX_SOFTIRQ); 00542 local_irq_restore(flags); 00543 } 00544 } 00545 00546 static inline void netif_schedule(struct net_device *dev) 00547 { 00548 if (!test_bit(__LINK_STATE_XOFF, &dev->state)) 00549 __netif_schedule(dev); 00550 } 00551 00552 static inline void netif_start_queue(struct net_device *dev) 00553 { 00554 clear_bit(__LINK_STATE_XOFF, &dev->state); 00555 } 00556 00557 static inline void netif_wake_queue(struct net_device *dev) 00558 { 00559 if (test_and_clear_bit(__LINK_STATE_XOFF, &dev->state)) 00560 __netif_schedule(dev); 00561 } 00562 00563 static inline void netif_stop_queue(struct net_device *dev) 00564 { 00565 set_bit(__LINK_STATE_XOFF, &dev->state); 00566 } 00567 00568 static inline int netif_queue_stopped(struct net_device *dev) 00569 { 00570 return test_bit(__LINK_STATE_XOFF, &dev->state); 00571 } 00572 00573 static inline int netif_running(struct net_device *dev) 00574 { 00575 return test_bit(__LINK_STATE_START, &dev->state); 00576 } 00577 00578 00579 /* Use this variant when it is known for sure that it 00580 * is executing from interrupt context. 00581 */ 00582 static inline void dev_kfree_skb_irq(struct sk_buff *skb) 00583 { 00584 if (atomic_dec_and_test(&skb->users)) { 00585 int cpu =smp_processor_id(); 00586 unsigned long flags; 00587 00588 local_irq_save(flags); 00589 skb->next = softnet_data[cpu].completion_queue; 00590 softnet_data[cpu].completion_queue = skb; 00591 cpu_raise_softirq(cpu, NET_TX_SOFTIRQ); 00592 local_irq_restore(flags); 00593 } 00594 } 00595 00596 /* Use this variant in places where it could be invoked 00597 * either from interrupt or non-interrupt context. 00598 */ 00599 static inline void dev_kfree_skb_any(struct sk_buff *skb) 00600 { 00601 if (in_irq()) 00602 dev_kfree_skb_irq(skb); 00603 else 00604 dev_kfree_skb(skb); 00605 } 00606 00607 #define HAVE_NETIF_RX 1 00608 extern int netif_rx(struct sk_buff *skb); 00609 #define HAVE_NETIF_RECEIVE_SKB 1 00610 extern int netif_receive_skb(struct sk_buff *skb); 00611 extern int dev_ioctl(unsigned int cmd, void *); 00612 extern int dev_ethtool(struct ifreq *); 00613 extern int dev_change_flags(struct net_device *, unsigned); 00614 extern void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev); 00615 00616 extern void dev_init(void); 00617 00618 extern int netdev_nit; 00619 00620 /* Post buffer to the network code from _non interrupt_ context. 00621 * see net/core/dev.c for netif_rx description. 00622 */ 00623 static inline int netif_rx_ni(struct sk_buff *skb) 00624 { 00625 int err = netif_rx(skb); 00626 if (softirq_pending(smp_processor_id())) 00627 do_softirq(); 00628 return err; 00629 } 00630 00631 static inline void dev_init_buffers(struct net_device *dev) 00632 { 00633 /* WILL BE REMOVED IN 2.5.0 */ 00634 } 00635 00636 extern int netdev_finish_unregister(struct net_device *dev); 00637 00638 static inline void dev_put(struct net_device *dev) 00639 { 00640 if (atomic_dec_and_test(&dev->refcnt)) 00641 netdev_finish_unregister(dev); 00642 } 00643 00644 #define __dev_put(dev) atomic_dec(&(dev)->refcnt) 00645 #define dev_hold(dev) atomic_inc(&(dev)->refcnt) 00646 00647 /* Carrier loss detection, dial on demand. The functions netif_carrier_on 00648 * and _off may be called from IRQ context, but it is caller 00649 * who is responsible for serialization of these calls. 00650 */ 00651 00652 static inline int netif_carrier_ok(struct net_device *dev) 00653 { 00654 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state); 00655 } 00656 00657 extern void __netdev_watchdog_up(struct net_device *dev); 00658 00659 static inline void netif_carrier_on(struct net_device *dev) 00660 { 00661 clear_bit(__LINK_STATE_NOCARRIER, &dev->state); 00662 if (netif_running(dev)) 00663 __netdev_watchdog_up(dev); 00664 } 00665 00666 static inline void netif_carrier_off(struct net_device *dev) 00667 { 00668 set_bit(__LINK_STATE_NOCARRIER, &dev->state); 00669 } 00670 00671 /* Hot-plugging. */ 00672 static inline int netif_device_present(struct net_device *dev) 00673 { 00674 return test_bit(__LINK_STATE_PRESENT, &dev->state); 00675 } 00676 00677 static inline void netif_device_detach(struct net_device *dev) 00678 { 00679 if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) && 00680 netif_running(dev)) { 00681 netif_stop_queue(dev); 00682 } 00683 } 00684 00685 static inline void netif_device_attach(struct net_device *dev) 00686 { 00687 if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) && 00688 netif_running(dev)) { 00689 netif_wake_queue(dev); 00690 __netdev_watchdog_up(dev); 00691 } 00692 } 00693 00694 /* 00695 * Network interface message level settings 00696 */ 00697 #define HAVE_NETIF_MSG 1 00698 00699 enum { 00700 NETIF_MSG_DRV = 0x0001, 00701 NETIF_MSG_PROBE = 0x0002, 00702 NETIF_MSG_LINK = 0x0004, 00703 NETIF_MSG_TIMER = 0x0008, 00704 NETIF_MSG_IFDOWN = 0x0010, 00705 NETIF_MSG_IFUP = 0x0020, 00706 NETIF_MSG_RX_ERR = 0x0040, 00707 NETIF_MSG_TX_ERR = 0x0080, 00708 NETIF_MSG_TX_QUEUED = 0x0100, 00709 NETIF_MSG_INTR = 0x0200, 00710 NETIF_MSG_TX_DONE = 0x0400, 00711 NETIF_MSG_RX_STATUS = 0x0800, 00712 NETIF_MSG_PKTDATA = 0x1000, 00713 NETIF_MSG_HW = 0x2000, 00714 NETIF_MSG_WOL = 0x4000, 00715 }; 00716 00717 #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV) 00718 #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE) 00719 #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK) 00720 #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER) 00721 #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN) 00722 #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP) 00723 #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR) 00724 #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR) 00725 #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED) 00726 #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR) 00727 #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE) 00728 #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS) 00729 #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA) 00730 #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW) 00731 #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL) 00732 00733 /* Schedule rx intr now? */ 00734 00735 static inline int netif_rx_schedule_prep(struct net_device *dev) 00736 { 00737 return netif_running(dev) && 00738 !test_and_set_bit(__LINK_STATE_RX_SCHED, &dev->state); 00739 } 00740 00741 /* Add interface to tail of rx poll list. This assumes that _prep has 00742 * already been called and returned 1. 00743 */ 00744 00745 static inline void __netif_rx_schedule(struct net_device *dev) 00746 { 00747 unsigned long flags; 00748 int cpu = smp_processor_id(); 00749 00750 local_irq_save(flags); 00751 dev_hold(dev); 00752 list_add_tail(&dev->poll_list, &softnet_data[cpu].poll_list); 00753 if (dev->quota < 0) 00754 dev->quota += dev->weight; 00755 else 00756 dev->quota = dev->weight; 00757 __cpu_raise_softirq(cpu, NET_RX_SOFTIRQ); 00758 local_irq_restore(flags); 00759 } 00760 00761 /* Try to reschedule poll. Called by irq handler. */ 00762 00763 static inline void netif_rx_schedule(struct net_device *dev) 00764 { 00765 if (netif_rx_schedule_prep(dev)) 00766 __netif_rx_schedule(dev); 00767 } 00768 00769 /* Try to reschedule poll. Called by dev->poll() after netif_rx_complete(). 00770 * Do not inline this? 00771 */ 00772 static inline int netif_rx_reschedule(struct net_device *dev, int undo) 00773 { 00774 if (netif_rx_schedule_prep(dev)) { 00775 unsigned long flags; 00776 int cpu = smp_processor_id(); 00777 00778 dev->quota += undo; 00779 00780 local_irq_save(flags); 00781 list_add_tail(&dev->poll_list, &softnet_data[cpu].poll_list); 00782 __cpu_raise_softirq(cpu, NET_RX_SOFTIRQ); 00783 local_irq_restore(flags); 00784 return 1; 00785 } 00786 return 0; 00787 } 00788 00789 /* Remove interface from poll list: it must be in the poll list 00790 * on current cpu. This primitive is called by dev->poll(), when 00791 * it completes the work. The device cannot be out of poll list at this 00792 * moment, it is BUG(). 00793 */ 00794 static inline void netif_rx_complete(struct net_device *dev) 00795 { 00796 unsigned long flags; 00797 00798 local_irq_save(flags); 00799 if (!test_bit(__LINK_STATE_RX_SCHED, &dev->state)) BUG(); 00800 list_del(&dev->poll_list); 00801 smp_mb__before_clear_bit(); 00802 clear_bit(__LINK_STATE_RX_SCHED, &dev->state); 00803 local_irq_restore(flags); 00804 } 00805 00806 static inline void netif_poll_disable(struct net_device *dev) 00807 { 00808 while (test_and_set_bit(__LINK_STATE_RX_SCHED, &dev->state)) { 00809 /* No hurry. */ 00810 current->state = TASK_INTERRUPTIBLE; 00811 schedule_timeout(1); 00812 } 00813 } 00814 00815 static inline void netif_poll_enable(struct net_device *dev) 00816 { 00817 clear_bit(__LINK_STATE_RX_SCHED, &dev->state); 00818 } 00819 00820 /* same as netif_rx_complete, except that local_irq_save(flags) 00821 * has already been issued 00822 */ 00823 static inline void __netif_rx_complete(struct net_device *dev) 00824 { 00825 if (!test_bit(__LINK_STATE_RX_SCHED, &dev->state)) BUG(); 00826 list_del(&dev->poll_list); 00827 smp_mb__before_clear_bit(); 00828 clear_bit(__LINK_STATE_RX_SCHED, &dev->state); 00829 } 00830 00831 static inline void netif_tx_disable(struct net_device *dev) 00832 { 00833 spin_lock_bh(&dev->xmit_lock); 00834 netif_stop_queue(dev); 00835 spin_unlock_bh(&dev->xmit_lock); 00836 } 00837 00838 /* These functions live elsewhere (drivers/net/net_init.c, but related) */ 00839 00840 extern void ether_setup(struct net_device *dev); 00841 extern void fddi_setup(struct net_device *dev); 00842 extern void tr_setup(struct net_device *dev); 00843 extern void fc_setup(struct net_device *dev); 00844 extern void fc_freedev(struct net_device *dev); 00845 /* Support for loadable net-drivers */ 00846 extern struct net_device *alloc_netdev(int sizeof_priv, const char *name, 00847 void (*setup)(struct net_device *)); 00848 extern int register_netdev(struct net_device *dev); 00849 extern void unregister_netdev(struct net_device *dev); 00850 /* Functions used for multicast support */ 00851 extern void dev_mc_upload(struct net_device *dev); 00852 extern int dev_mc_delete(struct net_device *dev, void *addr, int alen, int all); 00853 extern int dev_mc_add(struct net_device *dev, void *addr, int alen, int newonly); 00854 extern void dev_mc_discard(struct net_device *dev); 00855 extern void dev_set_promiscuity(struct net_device *dev, int inc); 00856 extern void dev_set_allmulti(struct net_device *dev, int inc); 00857 extern void netdev_state_change(struct net_device *dev); 00858 /* Load a device via the kmod */ 00859 extern void dev_load(const char *name); 00860 extern void dev_mcast_init(void); 00861 extern int netdev_register_fc(struct net_device *dev, void (*stimul)(struct net_device *dev)); 00862 extern void netdev_unregister_fc(int bit); 00863 extern int netdev_max_backlog; 00864 extern int weight_p; 00865 extern unsigned long netdev_fc_xoff; 00866 extern atomic_t netdev_dropping; 00867 extern int netdev_set_master(struct net_device *dev, struct net_device *master); 00868 extern struct sk_buff * skb_checksum_help(struct sk_buff *skb); 00869 #ifdef CONFIG_NET_FASTROUTE 00870 extern int netdev_fastroute; 00871 extern int netdev_fastroute_obstacles; 00872 extern void dev_clear_fastroute(struct net_device *dev); 00873 #endif 00874 00875 static inline void free_netdev(struct net_device *dev) 00876 { 00877 kfree(dev); 00878 } 00879 00880 #endif /* __KERNEL__ */ 00881 00882 #endif /* _LINUX_DEV_H */

Generated on Wed Dec 1 21:25:32 2004 for Linux 2.4.23 Networking by doxygen 1.3.8