netdevice.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:24k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

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