/kernel/2.6.32_froyo_photon_nightly/include/linux/netdevice.h

http://photon-android.googlecode.com/ · C Header · 2030 lines · 1209 code · 278 blank · 543 comment · 90 complexity · 34f6bf7f707f3324bb79b6534dc6af06 MD5 · raw file

Large files are truncated click here to view the full file

  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
  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@lxorguk.ukuu.org.uk>
  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. #ifdef __KERNEL__
  31. #include <linux/timer.h>
  32. #include <linux/delay.h>
  33. #include <linux/mm.h>
  34. #include <asm/atomic.h>
  35. #include <asm/cache.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/device.h>
  38. #include <linux/percpu.h>
  39. #include <linux/rculist.h>
  40. #include <linux/dmaengine.h>
  41. #include <linux/workqueue.h>
  42. #include <linux/ethtool.h>
  43. #include <net/net_namespace.h>
  44. #include <net/dsa.h>
  45. #ifdef CONFIG_DCB
  46. #include <net/dcbnl.h>
  47. #endif
  48. struct vlan_group;
  49. struct netpoll_info;
  50. /* 802.11 specific */
  51. struct wireless_dev;
  52. /* source back-compat hooks */
  53. #define SET_ETHTOOL_OPS(netdev,ops) \
  54. ( (netdev)->ethtool_ops = (ops) )
  55. #define HAVE_ALLOC_NETDEV /* feature macro: alloc_xxxdev
  56. functions are available. */
  57. #define HAVE_FREE_NETDEV /* free_netdev() */
  58. #define HAVE_NETDEV_PRIV /* netdev_priv() */
  59. #define NET_XMIT_SUCCESS 0
  60. #define NET_XMIT_DROP 1 /* skb dropped */
  61. #define NET_XMIT_CN 2 /* congestion notification */
  62. #define NET_XMIT_POLICED 3 /* skb is shot by police */
  63. #define NET_XMIT_MASK 0xFFFF /* qdisc flags in net/sch_generic.h */
  64. /* Backlog congestion levels */
  65. #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
  66. #define NET_RX_DROP 1 /* packet dropped */
  67. /* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It
  68. * indicates that the device will soon be dropping packets, or already drops
  69. * some packets of the same priority; prompting us to send less aggressively. */
  70. #define net_xmit_eval(e) ((e) == NET_XMIT_CN? 0 : (e))
  71. #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
  72. /* Driver transmit return codes */
  73. enum netdev_tx {
  74. NETDEV_TX_OK = 0, /* driver took care of packet */
  75. NETDEV_TX_BUSY, /* driver tx path was busy*/
  76. NETDEV_TX_LOCKED = -1, /* driver tx lock was already taken */
  77. };
  78. typedef enum netdev_tx netdev_tx_t;
  79. #endif
  80. #define MAX_ADDR_LEN 32 /* Largest hardware address length */
  81. #ifdef __KERNEL__
  82. /*
  83. * Compute the worst case header length according to the protocols
  84. * used.
  85. */
  86. #if defined(CONFIG_WLAN_80211) || defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
  87. # if defined(CONFIG_MAC80211_MESH)
  88. # define LL_MAX_HEADER 128
  89. # else
  90. # define LL_MAX_HEADER 96
  91. # endif
  92. #elif defined(CONFIG_TR) || defined(CONFIG_TR_MODULE)
  93. # define LL_MAX_HEADER 48
  94. #else
  95. # define LL_MAX_HEADER 32
  96. #endif
  97. /* Modified by Andy from QCT LTE0045 for LTE related function */
  98. #if defined(CONFIG_QCT_LTE)
  99. # if !defined(CONFIG_NET_IPIP) && !defined(CONFIG_NET_IPIP_MODULE) && \
  100. !defined(CONFIG_NET_IPGRE) && !defined(CONFIG_NET_IPGRE_MODULE) && \
  101. !defined(CONFIG_IPV6_SIT) && !defined(CONFIG_IPV6_SIT_MODULE) && \
  102. !defined(CONFIG_IPV6_TUNNEL) && !defined(CONFIG_IPV6_TUNNEL_MODULE)
  103. # define MAX_HEADER (LL_MAX_HEADER + 20)
  104. # else
  105. # define MAX_HEADER (LL_MAX_HEADER + 48 + 20)
  106. # endif
  107. #else
  108. # if !defined(CONFIG_NET_IPIP) && !defined(CONFIG_NET_IPIP_MODULE) && \
  109. !defined(CONFIG_NET_IPGRE) && !defined(CONFIG_NET_IPGRE_MODULE) && \
  110. !defined(CONFIG_IPV6_SIT) && !defined(CONFIG_IPV6_SIT_MODULE) && \
  111. !defined(CONFIG_IPV6_TUNNEL) && !defined(CONFIG_IPV6_TUNNEL_MODULE)
  112. # define MAX_HEADER LL_MAX_HEADER
  113. # else
  114. # define MAX_HEADER (LL_MAX_HEADER + 48)
  115. # endif
  116. #endif
  117. #endif /* __KERNEL__ */
  118. /*
  119. * Network device statistics. Akin to the 2.0 ether stats but
  120. * with byte counters.
  121. */
  122. struct net_device_stats
  123. {
  124. unsigned long rx_packets; /* total packets received */
  125. unsigned long tx_packets; /* total packets transmitted */
  126. unsigned long rx_bytes; /* total bytes received */
  127. unsigned long tx_bytes; /* total bytes transmitted */
  128. unsigned long rx_errors; /* bad packets received */
  129. unsigned long tx_errors; /* packet transmit problems */
  130. unsigned long rx_dropped; /* no space in linux buffers */
  131. unsigned long tx_dropped; /* no space available in linux */
  132. unsigned long multicast; /* multicast packets received */
  133. unsigned long collisions;
  134. /* detailed rx_errors: */
  135. unsigned long rx_length_errors;
  136. unsigned long rx_over_errors; /* receiver ring buff overflow */
  137. unsigned long rx_crc_errors; /* recved pkt with crc error */
  138. unsigned long rx_frame_errors; /* recv'd frame alignment error */
  139. unsigned long rx_fifo_errors; /* recv'r fifo overrun */
  140. unsigned long rx_missed_errors; /* receiver missed packet */
  141. /* detailed tx_errors */
  142. unsigned long tx_aborted_errors;
  143. unsigned long tx_carrier_errors;
  144. unsigned long tx_fifo_errors;
  145. unsigned long tx_heartbeat_errors;
  146. unsigned long tx_window_errors;
  147. /* for cslip etc */
  148. unsigned long rx_compressed;
  149. unsigned long tx_compressed;
  150. };
  151. /* Media selection options. */
  152. enum {
  153. IF_PORT_UNKNOWN = 0,
  154. IF_PORT_10BASE2,
  155. IF_PORT_10BASET,
  156. IF_PORT_AUI,
  157. IF_PORT_100BASET,
  158. IF_PORT_100BASETX,
  159. IF_PORT_100BASEFX
  160. };
  161. #ifdef __KERNEL__
  162. #include <linux/cache.h>
  163. #include <linux/skbuff.h>
  164. struct neighbour;
  165. struct neigh_parms;
  166. struct sk_buff;
  167. struct netif_rx_stats
  168. {
  169. unsigned total;
  170. unsigned dropped;
  171. unsigned time_squeeze;
  172. unsigned cpu_collision;
  173. };
  174. DECLARE_PER_CPU(struct netif_rx_stats, netdev_rx_stat);
  175. struct dev_addr_list
  176. {
  177. struct dev_addr_list *next;
  178. u8 da_addr[MAX_ADDR_LEN];
  179. u8 da_addrlen;
  180. u8 da_synced;
  181. int da_users;
  182. int da_gusers;
  183. };
  184. /*
  185. * We tag multicasts with these structures.
  186. */
  187. #define dev_mc_list dev_addr_list
  188. #define dmi_addr da_addr
  189. #define dmi_addrlen da_addrlen
  190. #define dmi_users da_users
  191. #define dmi_gusers da_gusers
  192. struct netdev_hw_addr {
  193. struct list_head list;
  194. unsigned char addr[MAX_ADDR_LEN];
  195. unsigned char type;
  196. #define NETDEV_HW_ADDR_T_LAN 1
  197. #define NETDEV_HW_ADDR_T_SAN 2
  198. #define NETDEV_HW_ADDR_T_SLAVE 3
  199. #define NETDEV_HW_ADDR_T_UNICAST 4
  200. int refcount;
  201. bool synced;
  202. struct rcu_head rcu_head;
  203. };
  204. struct netdev_hw_addr_list {
  205. struct list_head list;
  206. int count;
  207. };
  208. struct hh_cache
  209. {
  210. struct hh_cache *hh_next; /* Next entry */
  211. atomic_t hh_refcnt; /* number of users */
  212. /*
  213. * We want hh_output, hh_len, hh_lock and hh_data be a in a separate
  214. * cache line on SMP.
  215. * They are mostly read, but hh_refcnt may be changed quite frequently,
  216. * incurring cache line ping pongs.
  217. */
  218. __be16 hh_type ____cacheline_aligned_in_smp;
  219. /* protocol identifier, f.e ETH_P_IP
  220. * NOTE: For VLANs, this will be the
  221. * encapuslated type. --BLG
  222. */
  223. u16 hh_len; /* length of header */
  224. int (*hh_output)(struct sk_buff *skb);
  225. seqlock_t hh_lock;
  226. /* cached hardware header; allow for machine alignment needs. */
  227. #define HH_DATA_MOD 16
  228. #define HH_DATA_OFF(__len) \
  229. (HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1))
  230. #define HH_DATA_ALIGN(__len) \
  231. (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
  232. unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
  233. };
  234. /* Reserve HH_DATA_MOD byte aligned hard_header_len, but at least that much.
  235. * Alternative is:
  236. * dev->hard_header_len ? (dev->hard_header_len +
  237. * (HH_DATA_MOD - 1)) & ~(HH_DATA_MOD - 1) : 0
  238. *
  239. * We could use other alignment values, but we must maintain the
  240. * relationship HH alignment <= LL alignment.
  241. *
  242. * LL_ALLOCATED_SPACE also takes into account the tailroom the device
  243. * may need.
  244. */
  245. #define LL_RESERVED_SPACE(dev) \
  246. ((((dev)->hard_header_len+(dev)->needed_headroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
  247. #define LL_RESERVED_SPACE_EXTRA(dev,extra) \
  248. ((((dev)->hard_header_len+(dev)->needed_headroom+(extra))&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
  249. #define LL_ALLOCATED_SPACE(dev) \
  250. ((((dev)->hard_header_len+(dev)->needed_headroom+(dev)->needed_tailroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
  251. struct header_ops {
  252. int (*create) (struct sk_buff *skb, struct net_device *dev,
  253. unsigned short type, const void *daddr,
  254. const void *saddr, unsigned len);
  255. int (*parse)(const struct sk_buff *skb, unsigned char *haddr);
  256. int (*rebuild)(struct sk_buff *skb);
  257. #define HAVE_HEADER_CACHE
  258. int (*cache)(const struct neighbour *neigh, struct hh_cache *hh);
  259. void (*cache_update)(struct hh_cache *hh,
  260. const struct net_device *dev,
  261. const unsigned char *haddr);
  262. };
  263. /* These flag bits are private to the generic network queueing
  264. * layer, they may not be explicitly referenced by any other
  265. * code.
  266. */
  267. enum netdev_state_t
  268. {
  269. __LINK_STATE_START,
  270. __LINK_STATE_PRESENT,
  271. __LINK_STATE_NOCARRIER,
  272. __LINK_STATE_LINKWATCH_PENDING,
  273. __LINK_STATE_DORMANT,
  274. };
  275. /*
  276. * This structure holds at boot time configured netdevice settings. They
  277. * are then used in the device probing.
  278. */
  279. struct netdev_boot_setup {
  280. char name[IFNAMSIZ];
  281. struct ifmap map;
  282. };
  283. #define NETDEV_BOOT_SETUP_MAX 8
  284. extern int __init netdev_boot_setup(char *str);
  285. /*
  286. * Structure for NAPI scheduling similar to tasklet but with weighting
  287. */
  288. struct napi_struct {
  289. /* The poll_list must only be managed by the entity which
  290. * changes the state of the NAPI_STATE_SCHED bit. This means
  291. * whoever atomically sets that bit can add this napi_struct
  292. * to the per-cpu poll_list, and whoever clears that bit
  293. * can remove from the list right before clearing the bit.
  294. */
  295. struct list_head poll_list;
  296. unsigned long state;
  297. int weight;
  298. int (*poll)(struct napi_struct *, int);
  299. #ifdef CONFIG_NETPOLL
  300. spinlock_t poll_lock;
  301. int poll_owner;
  302. #endif
  303. unsigned int gro_count;
  304. struct net_device *dev;
  305. struct list_head dev_list;
  306. struct sk_buff *gro_list;
  307. struct sk_buff *skb;
  308. };
  309. enum
  310. {
  311. NAPI_STATE_SCHED, /* Poll is scheduled */
  312. NAPI_STATE_DISABLE, /* Disable pending */
  313. NAPI_STATE_NPSVC, /* Netpoll - don't dequeue from poll_list */
  314. };
  315. enum {
  316. GRO_MERGED,
  317. GRO_MERGED_FREE,
  318. GRO_HELD,
  319. GRO_NORMAL,
  320. GRO_DROP,
  321. };
  322. extern void __napi_schedule(struct napi_struct *n);
  323. static inline int napi_disable_pending(struct napi_struct *n)
  324. {
  325. return test_bit(NAPI_STATE_DISABLE, &n->state);
  326. }
  327. /**
  328. * napi_schedule_prep - check if napi can be scheduled
  329. * @n: napi context
  330. *
  331. * Test if NAPI routine is already running, and if not mark
  332. * it as running. This is used as a condition variable
  333. * insure only one NAPI poll instance runs. We also make
  334. * sure there is no pending NAPI disable.
  335. */
  336. static inline int napi_schedule_prep(struct napi_struct *n)
  337. {
  338. return !napi_disable_pending(n) &&
  339. !test_and_set_bit(NAPI_STATE_SCHED, &n->state);
  340. }
  341. /**
  342. * napi_schedule - schedule NAPI poll
  343. * @n: napi context
  344. *
  345. * Schedule NAPI poll routine to be called if it is not already
  346. * running.
  347. */
  348. static inline void napi_schedule(struct napi_struct *n)
  349. {
  350. if (napi_schedule_prep(n))
  351. __napi_schedule(n);
  352. }
  353. /* Try to reschedule poll. Called by dev->poll() after napi_complete(). */
  354. static inline int napi_reschedule(struct napi_struct *napi)
  355. {
  356. if (napi_schedule_prep(napi)) {
  357. __napi_schedule(napi);
  358. return 1;
  359. }
  360. return 0;
  361. }
  362. /**
  363. * napi_complete - NAPI processing complete
  364. * @n: napi context
  365. *
  366. * Mark NAPI processing as complete.
  367. */
  368. extern void __napi_complete(struct napi_struct *n);
  369. extern void napi_complete(struct napi_struct *n);
  370. /**
  371. * napi_disable - prevent NAPI from scheduling
  372. * @n: napi context
  373. *
  374. * Stop NAPI from being scheduled on this context.
  375. * Waits till any outstanding processing completes.
  376. */
  377. static inline void napi_disable(struct napi_struct *n)
  378. {
  379. set_bit(NAPI_STATE_DISABLE, &n->state);
  380. while (test_and_set_bit(NAPI_STATE_SCHED, &n->state))
  381. msleep(1);
  382. clear_bit(NAPI_STATE_DISABLE, &n->state);
  383. }
  384. /**
  385. * napi_enable - enable NAPI scheduling
  386. * @n: napi context
  387. *
  388. * Resume NAPI from being scheduled on this context.
  389. * Must be paired with napi_disable.
  390. */
  391. static inline void napi_enable(struct napi_struct *n)
  392. {
  393. BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
  394. smp_mb__before_clear_bit();
  395. clear_bit(NAPI_STATE_SCHED, &n->state);
  396. }
  397. #ifdef CONFIG_SMP
  398. /**
  399. * napi_synchronize - wait until NAPI is not running
  400. * @n: napi context
  401. *
  402. * Wait until NAPI is done being scheduled on this context.
  403. * Waits till any outstanding processing completes but
  404. * does not disable future activations.
  405. */
  406. static inline void napi_synchronize(const struct napi_struct *n)
  407. {
  408. while (test_bit(NAPI_STATE_SCHED, &n->state))
  409. msleep(1);
  410. }
  411. #else
  412. # define napi_synchronize(n) barrier()
  413. #endif
  414. enum netdev_queue_state_t
  415. {
  416. __QUEUE_STATE_XOFF,
  417. __QUEUE_STATE_FROZEN,
  418. };
  419. struct netdev_queue {
  420. /*
  421. * read mostly part
  422. */
  423. struct net_device *dev;
  424. struct Qdisc *qdisc;
  425. unsigned long state;
  426. struct Qdisc *qdisc_sleeping;
  427. /*
  428. * write mostly part
  429. */
  430. spinlock_t _xmit_lock ____cacheline_aligned_in_smp;
  431. int xmit_lock_owner;
  432. /*
  433. * please use this field instead of dev->trans_start
  434. */
  435. unsigned long trans_start;
  436. unsigned long tx_bytes;
  437. unsigned long tx_packets;
  438. unsigned long tx_dropped;
  439. } ____cacheline_aligned_in_smp;
  440. /*
  441. * This structure defines the management hooks for network devices.
  442. * The following hooks can be defined; unless noted otherwise, they are
  443. * optional and can be filled with a null pointer.
  444. *
  445. * int (*ndo_init)(struct net_device *dev);
  446. * This function is called once when network device is registered.
  447. * The network device can use this to any late stage initializaton
  448. * or semantic validattion. It can fail with an error code which will
  449. * be propogated back to register_netdev
  450. *
  451. * void (*ndo_uninit)(struct net_device *dev);
  452. * This function is called when device is unregistered or when registration
  453. * fails. It is not called if init fails.
  454. *
  455. * int (*ndo_open)(struct net_device *dev);
  456. * This function is called when network device transistions to the up
  457. * state.
  458. *
  459. * int (*ndo_stop)(struct net_device *dev);
  460. * This function is called when network device transistions to the down
  461. * state.
  462. *
  463. * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
  464. * struct net_device *dev);
  465. * Called when a packet needs to be transmitted.
  466. * Must return NETDEV_TX_OK , NETDEV_TX_BUSY.
  467. * (can also return NETDEV_TX_LOCKED iff NETIF_F_LLTX)
  468. * Required can not be NULL.
  469. *
  470. * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb);
  471. * Called to decide which queue to when device supports multiple
  472. * transmit queues.
  473. *
  474. * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
  475. * This function is called to allow device receiver to make
  476. * changes to configuration when multicast or promiscious is enabled.
  477. *
  478. * void (*ndo_set_rx_mode)(struct net_device *dev);
  479. * This function is called device changes address list filtering.
  480. *
  481. * void (*ndo_set_multicast_list)(struct net_device *dev);
  482. * This function is called when the multicast address list changes.
  483. *
  484. * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
  485. * This function is called when the Media Access Control address
  486. * needs to be changed. If this interface is not defined, the
  487. * mac address can not be changed.
  488. *
  489. * int (*ndo_validate_addr)(struct net_device *dev);
  490. * Test if Media Access Control address is valid for the device.
  491. *
  492. * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
  493. * Called when a user request an ioctl which can't be handled by
  494. * the generic interface code. If not defined ioctl's return
  495. * not supported error code.
  496. *
  497. * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
  498. * Used to set network devices bus interface parameters. This interface
  499. * is retained for legacy reason, new devices should use the bus
  500. * interface (PCI) for low level management.
  501. *
  502. * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
  503. * Called when a user wants to change the Maximum Transfer Unit
  504. * of a device. If not defined, any request to change MTU will
  505. * will return an error.
  506. *
  507. * void (*ndo_tx_timeout)(struct net_device *dev);
  508. * Callback uses when the transmitter has not made any progress
  509. * for dev->watchdog ticks.
  510. *
  511. * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
  512. * Called when a user wants to get the network device usage
  513. * statistics. If not defined, the counters in dev->stats will
  514. * be used.
  515. *
  516. * void (*ndo_vlan_rx_register)(struct net_device *dev, struct vlan_group *grp);
  517. * If device support VLAN receive accleration
  518. * (ie. dev->features & NETIF_F_HW_VLAN_RX), then this function is called
  519. * when vlan groups for the device changes. Note: grp is NULL
  520. * if no vlan's groups are being used.
  521. *
  522. * void (*ndo_vlan_rx_add_vid)(struct net_device *dev, unsigned short vid);
  523. * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
  524. * this function is called when a VLAN id is registered.
  525. *
  526. * void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, unsigned short vid);
  527. * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
  528. * this function is called when a VLAN id is unregistered.
  529. *
  530. * void (*ndo_poll_controller)(struct net_device *dev);
  531. */
  532. #define HAVE_NET_DEVICE_OPS
  533. struct net_device_ops {
  534. int (*ndo_init)(struct net_device *dev);
  535. void (*ndo_uninit)(struct net_device *dev);
  536. int (*ndo_open)(struct net_device *dev);
  537. int (*ndo_stop)(struct net_device *dev);
  538. netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb,
  539. struct net_device *dev);
  540. u16 (*ndo_select_queue)(struct net_device *dev,
  541. struct sk_buff *skb);
  542. #define HAVE_CHANGE_RX_FLAGS
  543. void (*ndo_change_rx_flags)(struct net_device *dev,
  544. int flags);
  545. #define HAVE_SET_RX_MODE
  546. void (*ndo_set_rx_mode)(struct net_device *dev);
  547. #define HAVE_MULTICAST
  548. void (*ndo_set_multicast_list)(struct net_device *dev);
  549. #define HAVE_SET_MAC_ADDR
  550. int (*ndo_set_mac_address)(struct net_device *dev,
  551. void *addr);
  552. #define HAVE_VALIDATE_ADDR
  553. int (*ndo_validate_addr)(struct net_device *dev);
  554. #define HAVE_PRIVATE_IOCTL
  555. int (*ndo_do_ioctl)(struct net_device *dev,
  556. struct ifreq *ifr, int cmd);
  557. #define HAVE_SET_CONFIG
  558. int (*ndo_set_config)(struct net_device *dev,
  559. struct ifmap *map);
  560. #define HAVE_CHANGE_MTU
  561. int (*ndo_change_mtu)(struct net_device *dev,
  562. int new_mtu);
  563. int (*ndo_neigh_setup)(struct net_device *dev,
  564. struct neigh_parms *);
  565. #define HAVE_TX_TIMEOUT
  566. void (*ndo_tx_timeout) (struct net_device *dev);
  567. struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
  568. void (*ndo_vlan_rx_register)(struct net_device *dev,
  569. struct vlan_group *grp);
  570. void (*ndo_vlan_rx_add_vid)(struct net_device *dev,
  571. unsigned short vid);
  572. void (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
  573. unsigned short vid);
  574. #ifdef CONFIG_NET_POLL_CONTROLLER
  575. #define HAVE_NETDEV_POLL
  576. void (*ndo_poll_controller)(struct net_device *dev);
  577. #endif
  578. #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
  579. int (*ndo_fcoe_enable)(struct net_device *dev);
  580. int (*ndo_fcoe_disable)(struct net_device *dev);
  581. int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
  582. u16 xid,
  583. struct scatterlist *sgl,
  584. unsigned int sgc);
  585. int (*ndo_fcoe_ddp_done)(struct net_device *dev,
  586. u16 xid);
  587. #endif
  588. };
  589. /*
  590. * The DEVICE structure.
  591. * Actually, this whole structure is a big mistake. It mixes I/O
  592. * data with strictly "high-level" data, and it has to know about
  593. * almost every data structure used in the INET module.
  594. *
  595. * FIXME: cleanup struct net_device such that network protocol info
  596. * moves out.
  597. */
  598. struct net_device
  599. {
  600. /*
  601. * This is the first field of the "visible" part of this structure
  602. * (i.e. as seen by users in the "Space.c" file). It is the name
  603. * the interface.
  604. */
  605. char name[IFNAMSIZ];
  606. /* device name hash chain */
  607. struct hlist_node name_hlist;
  608. /* snmp alias */
  609. char *ifalias;
  610. /*
  611. * I/O specific fields
  612. * FIXME: Merge these and struct ifmap into one
  613. */
  614. unsigned long mem_end; /* shared mem end */
  615. unsigned long mem_start; /* shared mem start */
  616. unsigned long base_addr; /* device I/O address */
  617. unsigned int irq; /* device IRQ number */
  618. /*
  619. * Some hardware also needs these fields, but they are not
  620. * part of the usual set specified in Space.c.
  621. */
  622. unsigned char if_port; /* Selectable AUI, TP,..*/
  623. unsigned char dma; /* DMA channel */
  624. unsigned long state;
  625. struct list_head dev_list;
  626. struct list_head napi_list;
  627. /* Net device features */
  628. unsigned long features;
  629. #define NETIF_F_SG 1 /* Scatter/gather IO. */
  630. #define NETIF_F_IP_CSUM 2 /* Can checksum TCP/UDP over IPv4. */
  631. #define NETIF_F_NO_CSUM 4 /* Does not require checksum. F.e. loopack. */
  632. #define NETIF_F_HW_CSUM 8 /* Can checksum all the packets. */
  633. #define NETIF_F_IPV6_CSUM 16 /* Can checksum TCP/UDP over IPV6 */
  634. #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory. */
  635. #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */
  636. #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw acceleration */
  637. #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw acceleration */
  638. #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on VLAN */
  639. #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */
  640. #define NETIF_F_GSO 2048 /* Enable software GSO. */
  641. #define NETIF_F_LLTX 4096 /* LockLess TX - deprecated. Please */
  642. /* do not use LLTX in new drivers */
  643. #define NETIF_F_NETNS_LOCAL 8192 /* Does not change network namespaces */
  644. #define NETIF_F_GRO 16384 /* Generic receive offload */
  645. #define NETIF_F_LRO 32768 /* large receive offload */
  646. /* the GSO_MASK reserves bits 16 through 23 */
  647. #define NETIF_F_FCOE_CRC (1 << 24) /* FCoE CRC32 */
  648. #define NETIF_F_SCTP_CSUM (1 << 25) /* SCTP checksum offload */
  649. #define NETIF_F_FCOE_MTU (1 << 26) /* Supports max FCoE MTU, 2158 bytes*/
  650. /* Segmentation offload features */
  651. #define NETIF_F_GSO_SHIFT 16
  652. #define NETIF_F_GSO_MASK 0x00ff0000
  653. #define NETIF_F_TSO (SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT)
  654. #define NETIF_F_UFO (SKB_GSO_UDP << NETIF_F_GSO_SHIFT)
  655. #define NETIF_F_GSO_ROBUST (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT)
  656. #define NETIF_F_TSO_ECN (SKB_GSO_TCP_ECN << NETIF_F_GSO_SHIFT)
  657. #define NETIF_F_TSO6 (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT)
  658. #define NETIF_F_FSO (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT)
  659. /* List of features with software fallbacks. */
  660. #define NETIF_F_GSO_SOFTWARE (NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6)
  661. #define NETIF_F_GEN_CSUM (NETIF_F_NO_CSUM | NETIF_F_HW_CSUM)
  662. #define NETIF_F_V4_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM)
  663. #define NETIF_F_V6_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)
  664. #define NETIF_F_ALL_CSUM (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM)
  665. /*
  666. * If one device supports one of these features, then enable them
  667. * for all in netdev_increment_features.
  668. */
  669. #define NETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \
  670. NETIF_F_SG | NETIF_F_HIGHDMA | \
  671. NETIF_F_FRAGLIST)
  672. /* Interface index. Unique device identifier */
  673. int ifindex;
  674. int iflink;
  675. struct net_device_stats stats;
  676. #ifdef CONFIG_WIRELESS_EXT
  677. /* List of functions to handle Wireless Extensions (instead of ioctl).
  678. * See <net/iw_handler.h> for details. Jean II */
  679. const struct iw_handler_def * wireless_handlers;
  680. /* Instance data managed by the core of Wireless Extensions. */
  681. struct iw_public_data * wireless_data;
  682. #endif
  683. /* Management operations */
  684. const struct net_device_ops *netdev_ops;
  685. const struct ethtool_ops *ethtool_ops;
  686. /* Hardware header description */
  687. const struct header_ops *header_ops;
  688. unsigned int flags; /* interface flags (a la BSD) */
  689. unsigned short gflags;
  690. unsigned short priv_flags; /* Like 'flags' but invisible to userspace. */
  691. unsigned short padded; /* How much padding added by alloc_netdev() */
  692. unsigned char operstate; /* RFC2863 operstate */
  693. unsigned char link_mode; /* mapping policy to operstate */
  694. unsigned mtu; /* interface MTU value */
  695. unsigned short type; /* interface hardware type */
  696. unsigned short hard_header_len; /* hardware hdr length */
  697. /* extra head- and tailroom the hardware may need, but not in all cases
  698. * can this be guaranteed, especially tailroom. Some cases also use
  699. * LL_MAX_HEADER instead to allocate the skb.
  700. */
  701. unsigned short needed_headroom;
  702. unsigned short needed_tailroom;
  703. struct net_device *master; /* Pointer to master device of a group,
  704. * which this device is member of.
  705. */
  706. /* Interface address info. */
  707. unsigned char perm_addr[MAX_ADDR_LEN]; /* permanent hw address */
  708. unsigned char addr_len; /* hardware address length */
  709. unsigned short dev_id; /* for shared network cards */
  710. struct netdev_hw_addr_list uc; /* Secondary unicast
  711. mac addresses */
  712. int uc_promisc;
  713. spinlock_t addr_list_lock;
  714. struct dev_addr_list *mc_list; /* Multicast mac addresses */
  715. int mc_count; /* Number of installed mcasts */
  716. unsigned int promiscuity;
  717. unsigned int allmulti;
  718. /* Protocol specific pointers */
  719. #ifdef CONFIG_NET_DSA
  720. void *dsa_ptr; /* dsa specific data */
  721. #endif
  722. void *atalk_ptr; /* AppleTalk link */
  723. void *ip_ptr; /* IPv4 specific data */
  724. void *dn_ptr; /* DECnet specific data */
  725. void *ip6_ptr; /* IPv6 specific data */
  726. void *ec_ptr; /* Econet specific data */
  727. void *ax25_ptr; /* AX.25 specific data */
  728. struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data,
  729. assign before registering */
  730. /*
  731. * Cache line mostly used on receive path (including eth_type_trans())
  732. */
  733. unsigned long last_rx; /* Time of last Rx */
  734. /* Interface address info used in eth_type_trans() */
  735. unsigned char *dev_addr; /* hw address, (before bcast
  736. because most packets are
  737. unicast) */
  738. struct netdev_hw_addr_list dev_addrs; /* list of device
  739. hw addresses */
  740. unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */
  741. struct netdev_queue rx_queue;
  742. struct netdev_queue *_tx ____cacheline_aligned_in_smp;
  743. /* Number of TX queues allocated at alloc_netdev_mq() time */
  744. unsigned int num_tx_queues;
  745. /* Number of TX queues currently active in device */
  746. unsigned int real_num_tx_queues;
  747. /* root qdisc from userspace point of view */
  748. struct Qdisc *qdisc;
  749. unsigned long tx_queue_len; /* Max frames per queue allowed */
  750. spinlock_t tx_global_lock;
  751. /*
  752. * One part is mostly used on xmit path (device)
  753. */
  754. /* These may be needed for future network-power-down code. */
  755. /*
  756. * trans_start here is expensive for high speed devices on SMP,
  757. * please use netdev_queue->trans_start instead.
  758. */
  759. unsigned long trans_start; /* Time (in jiffies) of last Tx */
  760. int watchdog_timeo; /* used by dev_watchdog() */
  761. struct timer_list watchdog_timer;
  762. /* Number of references to this device */
  763. atomic_t refcnt ____cacheline_aligned_in_smp;
  764. /* delayed register/unregister */
  765. struct list_head todo_list;
  766. /* device index hash chain */
  767. struct hlist_node index_hlist;
  768. struct net_device *link_watch_next;
  769. /* register/unregister state machine */
  770. enum { NETREG_UNINITIALIZED=0,
  771. NETREG_REGISTERED, /* completed register_netdevice */
  772. NETREG_UNREGISTERING, /* called unregister_netdevice */
  773. NETREG_UNREGISTERED, /* completed unregister todo */
  774. NETREG_RELEASED, /* called free_netdev */
  775. NETREG_DUMMY, /* dummy device for NAPI poll */
  776. } reg_state;
  777. /* Called from unregister, can be used to call free_netdev */
  778. void (*destructor)(struct net_device *dev);
  779. #ifdef CONFIG_NETPOLL
  780. struct netpoll_info *npinfo;
  781. #endif
  782. #ifdef CONFIG_NET_NS
  783. /* Network namespace this network device is inside */
  784. struct net *nd_net;
  785. #endif
  786. /* mid-layer private */
  787. void *ml_priv;
  788. /* bridge stuff */
  789. struct net_bridge_port *br_port;
  790. /* macvlan */
  791. struct macvlan_port *macvlan_port;
  792. /* GARP */
  793. struct garp_port *garp_port;
  794. /* class/net/name entry */
  795. struct device dev;
  796. /* space for optional statistics and wireless sysfs groups */
  797. const struct attribute_group *sysfs_groups[3];
  798. /* rtnetlink link ops */
  799. const struct rtnl_link_ops *rtnl_link_ops;
  800. /* VLAN feature mask */
  801. unsigned long vlan_features;
  802. /* for setting kernel sock attribute on TCP connection setup */
  803. #define GSO_MAX_SIZE 65536
  804. unsigned int gso_max_size;
  805. #ifdef CONFIG_DCB
  806. /* Data Center Bridging netlink ops */
  807. struct dcbnl_rtnl_ops *dcbnl_ops;
  808. #endif
  809. #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
  810. /* max exchange id for FCoE LRO by ddp */
  811. unsigned int fcoe_ddp_xid;
  812. #endif
  813. };
  814. #define to_net_dev(d) container_of(d, struct net_device, dev)
  815. #define NETDEV_ALIGN 32
  816. static inline
  817. struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
  818. unsigned int index)
  819. {
  820. return &dev->_tx[index];
  821. }
  822. static inline void netdev_for_each_tx_queue(struct net_device *dev,
  823. void (*f)(struct net_device *,
  824. struct netdev_queue *,
  825. void *),
  826. void *arg)
  827. {
  828. unsigned int i;
  829. for (i = 0; i < dev->num_tx_queues; i++)
  830. f(dev, &dev->_tx[i], arg);
  831. }
  832. /*
  833. * Net namespace inlines
  834. */
  835. static inline
  836. struct net *dev_net(const struct net_device *dev)
  837. {
  838. #ifdef CONFIG_NET_NS
  839. return dev->nd_net;
  840. #else
  841. return &init_net;
  842. #endif
  843. }
  844. static inline
  845. void dev_net_set(struct net_device *dev, struct net *net)
  846. {
  847. #ifdef CONFIG_NET_NS
  848. release_net(dev->nd_net);
  849. dev->nd_net = hold_net(net);
  850. #endif
  851. }
  852. static inline bool netdev_uses_dsa_tags(struct net_device *dev)
  853. {
  854. #ifdef CONFIG_NET_DSA_TAG_DSA
  855. if (dev->dsa_ptr != NULL)
  856. return dsa_uses_dsa_tags(dev->dsa_ptr);
  857. #endif
  858. return 0;
  859. }
  860. static inline bool netdev_uses_trailer_tags(struct net_device *dev)
  861. {
  862. #ifdef CONFIG_NET_DSA_TAG_TRAILER
  863. if (dev->dsa_ptr != NULL)
  864. return dsa_uses_trailer_tags(dev->dsa_ptr);
  865. #endif
  866. return 0;
  867. }
  868. /**
  869. * netdev_priv - access network device private data
  870. * @dev: network device
  871. *
  872. * Get network device private data
  873. */
  874. static inline void *netdev_priv(const struct net_device *dev)
  875. {
  876. return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
  877. }
  878. /* Set the sysfs physical device reference for the network logical device
  879. * if set prior to registration will cause a symlink during initialization.
  880. */
  881. #define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev))
  882. /* Set the sysfs device type for the network logical device to allow
  883. * fin grained indentification of different network device types. For
  884. * example Ethernet, Wirelss LAN, Bluetooth, WiMAX etc.
  885. */
  886. #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype))
  887. /**
  888. * netif_napi_add - initialize a napi context
  889. * @dev: network device
  890. * @napi: napi context
  891. * @poll: polling function
  892. * @weight: default weight
  893. *
  894. * netif_napi_add() must be used to initialize a napi context prior to calling
  895. * *any* of the other napi related functions.
  896. */
  897. void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
  898. int (*poll)(struct napi_struct *, int), int weight);
  899. /**
  900. * netif_napi_del - remove a napi context
  901. * @napi: napi context
  902. *
  903. * netif_napi_del() removes a napi context from the network device napi list
  904. */
  905. void netif_napi_del(struct napi_struct *napi);
  906. struct napi_gro_cb {
  907. /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */
  908. void *frag0;
  909. /* Length of frag0. */
  910. unsigned int frag0_len;
  911. /* This indicates where we are processing relative to skb->data. */
  912. int data_offset;
  913. /* This is non-zero if the packet may be of the same flow. */
  914. int same_flow;
  915. /* This is non-zero if the packet cannot be merged with the new skb. */
  916. int flush;
  917. /* Number of segments aggregated. */
  918. int count;
  919. /* Free the skb? */
  920. int free;
  921. };
  922. #define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb)
  923. struct packet_type {
  924. __be16 type; /* This is really htons(ether_type). */
  925. struct net_device *dev; /* NULL is wildcarded here */
  926. int (*func) (struct sk_buff *,
  927. struct net_device *,
  928. struct packet_type *,
  929. struct net_device *);
  930. struct sk_buff *(*gso_segment)(struct sk_buff *skb,
  931. int features);
  932. int (*gso_send_check)(struct sk_buff *skb);
  933. struct sk_buff **(*gro_receive)(struct sk_buff **head,
  934. struct sk_buff *skb);
  935. int (*gro_complete)(struct sk_buff *skb);
  936. void *af_packet_priv;
  937. struct list_head list;
  938. };
  939. #include <linux/interrupt.h>
  940. #include <linux/notifier.h>
  941. extern rwlock_t dev_base_lock; /* Device list lock */
  942. #define for_each_netdev(net, d) \
  943. list_for_each_entry(d, &(net)->dev_base_head, dev_list)
  944. #define for_each_netdev_safe(net, d, n) \
  945. list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
  946. #define for_each_netdev_continue(net, d) \
  947. list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
  948. #define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
  949. static inline struct net_device *next_net_device(struct net_device *dev)
  950. {
  951. struct list_head *lh;
  952. struct net *net;
  953. net = dev_net(dev);
  954. lh = dev->dev_list.next;
  955. return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
  956. }
  957. static inline struct net_device *first_net_device(struct net *net)
  958. {
  959. return list_empty(&net->dev_base_head) ? NULL :
  960. net_device_entry(net->dev_base_head.next);
  961. }
  962. extern int netdev_boot_setup_check(struct net_device *dev);
  963. extern unsigned long netdev_boot_base(const char *prefix, int unit);
  964. extern struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *hwaddr);
  965. extern struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
  966. extern struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type);
  967. extern void dev_add_pack(struct packet_type *pt);
  968. extern void dev_remove_pack(struct packet_type *pt);
  969. extern void __dev_remove_pack(struct packet_type *pt);
  970. extern struct net_device *dev_get_by_flags(struct net *net, unsigned short flags,
  971. unsigned short mask);
  972. extern struct net_device *dev_get_by_name(struct net *net, const char *name);
  973. extern struct net_device *__dev_get_by_name(struct net *net, const char *name);
  974. extern int dev_alloc_name(struct net_device *dev, const char *name);
  975. extern int dev_open(struct net_device *dev);
  976. extern int dev_close(struct net_device *dev);
  977. extern void dev_disable_lro(struct net_device *dev);
  978. extern int dev_queue_xmit(struct sk_buff *skb);
  979. extern int register_netdevice(struct net_device *dev);
  980. extern void unregister_netdevice(struct net_device *dev);
  981. extern void free_netdev(struct net_device *dev);
  982. extern void synchronize_net(void);
  983. extern int register_netdevice_notifier(struct notifier_block *nb);
  984. extern int unregister_netdevice_notifier(struct notifier_block *nb);
  985. extern int init_dummy_netdev(struct net_device *dev);
  986. extern void netdev_resync_ops(struct net_device *dev);
  987. extern int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
  988. extern struct net_device *dev_get_by_index(struct net *net, int ifindex);
  989. extern struct net_device *__dev_get_by_index(struct net *net, int ifindex);
  990. extern int dev_restart(struct net_device *dev);
  991. #ifdef CONFIG_NETPOLL_TRAP
  992. extern int netpoll_trap(void);
  993. #endif
  994. extern int skb_gro_receive(struct sk_buff **head,
  995. struct sk_buff *skb);
  996. extern void skb_gro_reset_offset(struct sk_buff *skb);
  997. static inline unsigned int skb_gro_offset(const struct sk_buff *skb)
  998. {
  999. return NAPI_GRO_CB(skb)->data_offset;
  1000. }
  1001. static inline unsigned int skb_gro_len(const struct sk_buff *skb)
  1002. {
  1003. return skb->len - NAPI_GRO_CB(skb)->data_offset;
  1004. }
  1005. static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len)
  1006. {
  1007. NAPI_GRO_CB(skb)->data_offset += len;
  1008. }
  1009. static inline void *skb_gro_header_fast(struct sk_buff *skb,
  1010. unsigned int offset)
  1011. {
  1012. return NAPI_GRO_CB(skb)->frag0 + offset;
  1013. }
  1014. static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen)
  1015. {
  1016. return NAPI_GRO_CB(skb)->frag0_len < hlen;
  1017. }
  1018. static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
  1019. unsigned int offset)
  1020. {
  1021. NAPI_GRO_CB(skb)->frag0 = NULL;
  1022. NAPI_GRO_CB(skb)->frag0_len = 0;
  1023. return pskb_may_pull(skb, hlen) ? skb->data + offset : NULL;
  1024. }
  1025. static inline void *skb_gro_mac_header(struct sk_buff *skb)
  1026. {
  1027. return NAPI_GRO_CB(skb)->frag0 ?: skb_mac_header(skb);
  1028. }
  1029. static inline void *skb_gro_network_header(struct sk_buff *skb)
  1030. {
  1031. return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) +
  1032. skb_network_offset(skb);
  1033. }
  1034. static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
  1035. unsigned short type,
  1036. const void *daddr, const void *saddr,
  1037. unsigned len)
  1038. {
  1039. if (!dev->header_ops || !dev->header_ops->create)
  1040. return 0;
  1041. return dev->header_ops->create(skb, dev, type, daddr, saddr, len);
  1042. }
  1043. static inline int dev_parse_header(const struct sk_buff *skb,
  1044. unsigned char *haddr)
  1045. {
  1046. const struct net_device *dev = skb->dev;
  1047. if (!dev->header_ops || !dev->header_ops->parse)
  1048. return 0;
  1049. return dev->header_ops->parse(skb, haddr);
  1050. }
  1051. typedef int gifconf_func_t(struct net_device * dev, char __user * bufptr, int len);
  1052. extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf);
  1053. static inline int unregister_gifconf(unsigned int family)
  1054. {
  1055. return register_gifconf(family, NULL);
  1056. }
  1057. /*
  1058. * Incoming packets are placed on per-cpu queues so that
  1059. * no locking is needed.
  1060. */
  1061. struct softnet_data
  1062. {
  1063. struct Qdisc *output_queue;
  1064. struct sk_buff_head input_pkt_queue;
  1065. struct list_head poll_list;
  1066. struct sk_buff *completion_queue;
  1067. struct napi_struct backlog;
  1068. };
  1069. DECLARE_PER_CPU(struct softnet_data,softnet_data);
  1070. #define HAVE_NETIF_QUEUE
  1071. extern void __netif_schedule(struct Qdisc *q);
  1072. static inline void netif_schedule_queue(struct netdev_queue *txq)
  1073. {
  1074. if (!test_bit(__QUEUE_STATE_XOFF, &txq->state))
  1075. __netif_schedule(txq->qdisc);
  1076. }
  1077. static inline void netif_tx_schedule_all(struct net_device *dev)
  1078. {
  1079. unsigned int i;
  1080. for (i = 0; i < dev->num_tx_queues; i++)
  1081. netif_schedule_queue(netdev_get_tx_queue(dev, i));
  1082. }
  1083. static inline void netif_tx_start_queue(struct netdev_queue *dev_queue)
  1084. {
  1085. clear_bit(__QUEUE_STATE_XOFF, &dev_queue->state);
  1086. }
  1087. /**
  1088. * netif_start_queue - allow transmit
  1089. * @dev: network device
  1090. *
  1091. * Allow upper layers to call the device hard_start_xmit routine.
  1092. */
  1093. static inline void netif_start_queue(struct net_device *dev)
  1094. {
  1095. netif_tx_start_queue(netdev_get_tx_queue(dev, 0));
  1096. }
  1097. static inline void netif_tx_start_all_queues(struct net_device *dev)
  1098. {
  1099. unsigned int i;
  1100. for (i = 0; i < dev->num_tx_queues; i++) {
  1101. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  1102. netif_tx_start_queue(txq);
  1103. }
  1104. }
  1105. static inline void netif_tx_wake_queue(struct netdev_queue *dev_queue)
  1106. {
  1107. #ifdef CONFIG_NETPOLL_TRAP
  1108. if (netpoll_trap()) {
  1109. netif_tx_start_queue(dev_queue);
  1110. return;
  1111. }
  1112. #endif
  1113. if (test_and_clear_bit(__QUEUE_STATE_XOFF, &dev_queue->state))
  1114. __netif_schedule(dev_queue->qdisc);
  1115. }
  1116. /**
  1117. * netif_wake_queue - restart transmit
  1118. * @dev: network device
  1119. *
  1120. * Allow upper layers to call the device hard_start_xmit routine.
  1121. * Used for flow control when transmit resources are available.
  1122. */
  1123. static inline void netif_wake_queue(struct net_device *dev)
  1124. {
  1125. netif_tx_wake_queue(netdev_get_tx_queue(dev, 0));
  1126. }
  1127. static inline void netif_tx_wake_all_queues(struct net_device *dev)
  1128. {
  1129. unsigned int i;
  1130. for (i = 0; i < dev->num_tx_queues; i++) {
  1131. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  1132. netif_tx_wake_queue(txq);
  1133. }
  1134. }
  1135. static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
  1136. {
  1137. set_bit(__QUEUE_STATE_XOFF, &dev_queue->state);
  1138. }
  1139. /**
  1140. * netif_stop_queue - stop transmitted packets
  1141. * @dev: network device
  1142. *
  1143. * Stop upper layers calling the device hard_start_xmit routine.
  1144. * Used for flow control when transmit resources are unavailable.
  1145. */
  1146. static inline void netif_stop_queue(struct net_device *dev)
  1147. {
  1148. netif_tx_stop_queue(netdev_get_tx_queue(dev, 0));
  1149. }
  1150. static inline void netif_tx_stop_all_queues(struct net_device *dev)
  1151. {
  1152. unsigned int i;
  1153. for (i = 0; i < dev->num_tx_queues; i++) {
  1154. struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
  1155. netif_tx_stop_queue(txq);
  1156. }
  1157. }
  1158. static inline int netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
  1159. {
  1160. return test_bit(__QUEUE_STATE_XOFF, &dev_queue->state);
  1161. }
  1162. /**
  1163. * netif_queue_stopped - test if transmit queue is flowblocked
  1164. * @dev: network device
  1165. *
  1166. * Test if transmit queue on device is currently unable to send.
  1167. */
  1168. static inline int netif_queue_stopped(const struct net_device *dev)
  1169. {
  1170. return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
  1171. }
  1172. static inline int netif_tx_queue_frozen(const struct netdev_queue *dev_queue)
  1173. {
  1174. return test_bit(__QUEUE_STATE_FROZEN, &dev_queue->state);
  1175. }
  1176. /**
  1177. * netif_running - test if up
  1178. * @dev: network device
  1179. *
  1180. * Test if the device has been brought up.
  1181. */
  1182. static inline int netif_running(const struct net_device *dev)
  1183. {
  1184. return test_bit(__LINK_STATE_START, &dev->state);
  1185. }
  1186. /*
  1187. * Routines to manage the subqueues on a device. We only need start
  1188. * stop, and a check if it's stopped. All other device management is
  1189. * done at the overall netdevice level.
  1190. * Also test the device if we're multiqueue.
  1191. */
  1192. /**
  1193. * netif_start_subqueue - allow sending packets on subqueue
  1194. * @dev: network device
  1195. * @queue_index: sub queue index
  1196. *
  1197. * Start individual transmit queue of a device with multiple transmit queues.
  1198. */
  1199. static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
  1200. {
  1201. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  1202. netif_tx_start_queue(txq);
  1203. }
  1204. /**
  1205. * netif_stop_subqueue - stop sending packets on subqueue
  1206. * @dev: network device
  1207. * @queue_index: sub queue index
  1208. *
  1209. * Stop individual transmit queue of a device with multiple transmit queues.
  1210. */
  1211. static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
  1212. {
  1213. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  1214. #ifdef CONFIG_NETPOLL_TRAP
  1215. if (netpoll_trap())
  1216. return;
  1217. #endif
  1218. netif_tx_stop_queue(txq);
  1219. }
  1220. /**
  1221. * netif_subqueue_stopped - test status of subqueue
  1222. * @dev: network device
  1223. * @queue_index: sub queue index
  1224. *
  1225. * Check individual transmit queue of a device with multiple transmit queues.
  1226. */
  1227. static inline int __netif_subqueue_stopped(const struct net_device *dev,
  1228. u16 queue_index)
  1229. {
  1230. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  1231. return netif_tx_queue_stopped(txq);
  1232. }
  1233. static inline int netif_subqueue_stopped(const struct net_device *dev,
  1234. struct sk_buff *skb)
  1235. {
  1236. return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
  1237. }
  1238. /**
  1239. * netif_wake_subqueue - allow sending packets on subqueue
  1240. * @dev: network device
  1241. * @queue_index: sub queue index
  1242. *
  1243. * Resume individual transmit queue of a device with multiple transmit queues.
  1244. */
  1245. static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
  1246. {
  1247. struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
  1248. #ifdef CONFIG_NETPOLL_TRAP
  1249. if (netpoll_trap())
  1250. return;
  1251. #endif
  1252. if (test_and_clear_bit(__QUEUE_STATE_XOFF, &txq->state))
  1253. __netif_schedule(txq->qdisc);
  1254. }
  1255. /**
  1256. * netif_is_multiqueue - test if device has multiple transmit queues
  1257. * @dev: network device
  1258. *
  1259. * Check if device has multiple transmit queues
  1260. */
  1261. static inline int netif_is_multiqueue(const struct net_device *dev)
  1262. {
  1263. return (dev->num_tx_queues > 1);
  1264. }
  1265. /* Use this variant when it is known for sure that it
  1266. * is executing from hardware interrupt context or with hardware interrupts
  1267. * disabled.
  1268. */
  1269. extern void dev_kfree_skb_irq(struct sk_buff *skb);
  1270. /* Use this variant in places where it could be invoked
  1271. * from either hardware interrupt or other context, with hardware interrupts
  1272. * either disabled or enabled.
  1273. */
  1274. extern void dev_kfree_skb_any(struct sk_buff *skb);
  1275. #define HAVE_NETIF_RX 1
  1276. extern int netif_rx(struct sk_buff *skb);
  1277. extern int netif_rx_ni(struct sk_buff *skb);
  1278. #define HAVE_NETIF_RECEIVE_SKB 1
  1279. extern int netif_receive_skb(struct sk_buff *skb);
  1280. extern void napi_gro_flush(struct napi_struct *napi);
  1281. extern int dev_gro_receive(struct napi_struct *napi,
  1282. struct sk_buff *skb);
  1283. extern int napi_skb_finish(int ret, struct sk_buff *skb);
  1284. extern int napi_gro_receive(struct napi_struct *napi,
  1285. struct sk_buff *skb);
  1286. extern void napi_reuse_skb(struct napi_struct *napi,
  1287. struct sk_buff *skb);
  1288. extern struct sk_buff * napi_get_frags(struct napi_struct *napi);
  1289. extern int napi_frags_finish(struct napi_struct *napi,
  1290. struct sk_buff *skb, int ret);
  1291. extern struct sk_buff * napi_frags_skb(struct napi_struct *napi);
  1292. extern int napi_gro_frags(struct napi_struct *napi);
  1293. static inline void napi_free_frags(struct napi_struct *napi)
  1294. {
  1295. kfree_skb(napi->skb);
  1296. napi->skb = NULL;
  1297. }
  1298. extern void netif_nit_deliver(struct sk_buff *skb);
  1299. extern int dev_valid_name(const char *name);
  1300. extern int dev_ioctl(struct net *net, unsigned int cmd, void __user *);
  1301. extern int dev_ethtool(struct net *net, struct ifreq *);
  1302. extern unsigned dev_get_flags(const struct net_device *);
  1303. extern int dev_change_flags(struct net_device *, unsigned);
  1304. extern int dev_change_name(struct net_device *, const char *);
  1305. extern int dev_set_alias(struct net_device *, const char *, size_t);
  1306. extern int dev_change_net_namespace(struct net_device *,
  1307. struct net *, const char *);
  1308. extern int dev_set_mtu(struct net_device *, int);
  1309. extern int dev_set_mac_address(struct net_device *,
  1310. struct sockaddr *);
  1311. extern int dev_hard_start_xmit(struct sk_buff *skb,
  1312. struct net_device *dev,
  1313. struct netdev_queue *txq);
  1314. extern int netdev_budget;
  1315. /* Called by rtnetlink.c:rtnl_unlock() */
  1316. extern void netdev_run_todo(void);
  1317. /**
  1318. * dev_put - release reference to device
  1319. * @dev: network device
  1320. *
  1321. * Release reference to device to allow it to be freed.
  1322. */
  1323. static inline void dev_put(struct net_device *dev)
  1324. {
  1325. atomic_dec(&dev->refcnt);
  1326. }
  1327. /**
  1328. * dev_hold - get reference to device
  1329. * @dev: network device
  1330. *
  1331. * Hold reference to device to keep it from being freed.
  1332. */
  1333. static inline void dev_hold(struct net_device *dev)
  1334. {
  1335. atomic_inc(&dev->refcnt);
  1336. }
  1337. /* Carrier loss detection, dial on demand. The functions netif_carrier_on
  1338. * and _off may be called from IRQ context, but it is caller
  1339. * who is responsible for serialization of these calls.
  1340. *
  1341. * The name carrier is inappropriate, these functions should really be
  1342. * called netif_lowerlayer_*() because they represent the state of any
  1343. * kind of lower layer not just hardware media.
  1344. */
  1345. extern void linkwatch_fire_event(struct net_device *dev);
  1346. /**
  1347. * netif_carrier_ok - test if carrier present
  1348. * @dev: network device
  1349. *
  1350. * Check if carrier is present on device
  1351. */
  1352. static inline int netif_carrier_ok(const struct net_device *dev)
  1353. {
  1354. return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
  1355. }
  1356. extern unsigned long dev_trans_start(struct net_device *dev);
  1357. extern void __netdev_watchdog_up(struct net_device *dev);
  1358. extern void netif_carrier_on(struct net_device *dev);
  1359. extern void netif_carrier_off(struct net_device *dev);
  1360. /**
  1361. * netif_dormant_on - mark device as dormant.
  1362. * @dev: network device
  1363. *
  1364. * Mark device as dormant (as per RFC2863).
  1365. *
  1366. * The dormant state indicates that the relevant interface is not
  1367. * actually in a condition to pass packets (i.e., it is not 'up') but is
  1368. * in a "pending" state, waiting for some external event. For "on-
  1369. * demand" interfaces, this new state identifies the situation where the
  1370. * interface is waiting for events to place it in the up state.
  1371. *
  1372. */
  1373. static inline void netif_dormant_on(struct net_device *dev)
  1374. {
  1375. if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
  1376. linkwatch_fire_event(dev);
  1377. }
  1378. /**
  1379. * netif_dormant_off - set device as not dormant.
  1380. * @dev: network device
  1381. *
  1382. * Device is not in dormant state.
  1383. */
  1384. static inline void netif_dormant_off(struct net_device *dev)
  1385. {
  1386. if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
  1387. linkwatch_fire_event(dev);
  1388. }
  1389. /**
  1390. * netif_dormant - test if carrier present
  1391. * @dev: network device
  1392. *
  1393. * Check if carrier is present on device
  1394. */
  1395. static inline int netif_dormant(const struct net_device *dev)
  1396. {
  1397. return test_bit(__LINK_STATE_DORMANT, &dev->state);
  1398. }
  1399. /**
  1400. * netif_oper_up - test if device is operational
  1401. * @dev: network device
  1402. *
  1403. * Check if carrier is operational
  1404. */
  1405. static inline int netif_oper_up(const struct net_device *dev) {
  1406. return (dev->operstate == IF_OPER_UP ||
  1407. dev->operstate == IF_OPER_UNKNOWN /* backward compat */);
  1408. }
  1409. /**
  1410. * netif_device_present - is device available or removed
  1411. * @dev: network device
  1412. *
  1413. * Check if device has not been removed from system.
  1414. */
  1415. static inline int netif_device_present(struct net_device *dev)
  1416. {
  1417. return test_bit(__LINK_STATE_PRESENT, &dev->state);
  1418. }
  1419. extern void netif_device_detach(struct net_device *dev);
  1420. extern void netif_device_attach(struct net_device *dev);
  1421. /*
  1422. * Network interface message level settings
  1423. */
  1424. #define HAVE_NETIF_MSG 1
  1425. enum {
  1426. NETIF_MSG_DRV = 0x0001,
  1427. NETIF_MSG_PROBE = 0x0002,
  1428. NETIF_MSG_LINK = 0x0004,
  1429. NETIF_MSG_TIMER = 0x0008,
  1430. NETIF_MSG_IFDOWN = 0x0010,
  1431. NETIF_MSG_IFUP = 0x0020,
  1432. NETIF_MSG_RX_ERR = 0x0040,
  1433. NETIF_MSG_TX_ERR = 0x0080,
  1434. NETIF_MSG_TX_QUEUED = 0x0100,
  1435. NETIF_MSG_INTR = 0x0200,
  1436. NETIF_MSG_TX_DONE = 0x0400,
  1437. NETIF_MSG_RX_STATUS = 0x0800,
  1438. NETIF_MSG_PKTDATA = 0x1000,
  1439. NETIF_MSG_HW = 0x2000,
  1440. NETIF_MSG_WOL = 0x4000,
  1441. };
  1442. #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
  1443. #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
  1444. #de