aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/netdevice.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/netdevice.h')
-rw-r--r--include/linux/netdevice.h128
1 files changed, 78 insertions, 50 deletions
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 7dfaae7846ab..1f77540bdc95 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -33,12 +33,12 @@
33#ifdef __KERNEL__ 33#ifdef __KERNEL__
34#include <linux/pm_qos.h> 34#include <linux/pm_qos.h>
35#include <linux/timer.h> 35#include <linux/timer.h>
36#include <linux/bug.h>
36#include <linux/delay.h> 37#include <linux/delay.h>
37#include <linux/atomic.h> 38#include <linux/atomic.h>
38#include <asm/cache.h> 39#include <asm/cache.h>
39#include <asm/byteorder.h> 40#include <asm/byteorder.h>
40 41
41#include <linux/device.h>
42#include <linux/percpu.h> 42#include <linux/percpu.h>
43#include <linux/rculist.h> 43#include <linux/rculist.h>
44#include <linux/dmaengine.h> 44#include <linux/dmaengine.h>
@@ -56,6 +56,7 @@
56#include <linux/netdev_features.h> 56#include <linux/netdev_features.h>
57 57
58struct netpoll_info; 58struct netpoll_info;
59struct device;
59struct phy_device; 60struct phy_device;
60/* 802.11 specific */ 61/* 802.11 specific */
61struct wireless_dev; 62struct wireless_dev;
@@ -417,7 +418,7 @@ typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
417 418
418extern void __napi_schedule(struct napi_struct *n); 419extern void __napi_schedule(struct napi_struct *n);
419 420
420static inline int napi_disable_pending(struct napi_struct *n) 421static inline bool napi_disable_pending(struct napi_struct *n)
421{ 422{
422 return test_bit(NAPI_STATE_DISABLE, &n->state); 423 return test_bit(NAPI_STATE_DISABLE, &n->state);
423} 424}
@@ -431,7 +432,7 @@ static inline int napi_disable_pending(struct napi_struct *n)
431 * insure only one NAPI poll instance runs. We also make 432 * insure only one NAPI poll instance runs. We also make
432 * sure there is no pending NAPI disable. 433 * sure there is no pending NAPI disable.
433 */ 434 */
434static inline int napi_schedule_prep(struct napi_struct *n) 435static inline bool napi_schedule_prep(struct napi_struct *n)
435{ 436{
436 return !napi_disable_pending(n) && 437 return !napi_disable_pending(n) &&
437 !test_and_set_bit(NAPI_STATE_SCHED, &n->state); 438 !test_and_set_bit(NAPI_STATE_SCHED, &n->state);
@@ -451,13 +452,13 @@ static inline void napi_schedule(struct napi_struct *n)
451} 452}
452 453
453/* Try to reschedule poll. Called by dev->poll() after napi_complete(). */ 454/* Try to reschedule poll. Called by dev->poll() after napi_complete(). */
454static inline int napi_reschedule(struct napi_struct *napi) 455static inline bool napi_reschedule(struct napi_struct *napi)
455{ 456{
456 if (napi_schedule_prep(napi)) { 457 if (napi_schedule_prep(napi)) {
457 __napi_schedule(napi); 458 __napi_schedule(napi);
458 return 1; 459 return true;
459 } 460 }
460 return 0; 461 return false;
461} 462}
462 463
463/** 464/**
@@ -1082,7 +1083,8 @@ struct net_device {
1082 const struct header_ops *header_ops; 1083 const struct header_ops *header_ops;
1083 1084
1084 unsigned int flags; /* interface flags (a la BSD) */ 1085 unsigned int flags; /* interface flags (a la BSD) */
1085 unsigned int priv_flags; /* Like 'flags' but invisible to userspace. */ 1086 unsigned int priv_flags; /* Like 'flags' but invisible to userspace.
1087 * See if.h for definitions. */
1086 unsigned short gflags; 1088 unsigned short gflags;
1087 unsigned short padded; /* How much padding added by alloc_netdev() */ 1089 unsigned short padded; /* How much padding added by alloc_netdev() */
1088 1090
@@ -1867,7 +1869,7 @@ static inline void netif_tx_stop_all_queues(struct net_device *dev)
1867 } 1869 }
1868} 1870}
1869 1871
1870static inline int netif_tx_queue_stopped(const struct netdev_queue *dev_queue) 1872static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
1871{ 1873{
1872 return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state); 1874 return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
1873} 1875}
@@ -1878,17 +1880,17 @@ static inline int netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
1878 * 1880 *
1879 * Test if transmit queue on device is currently unable to send. 1881 * Test if transmit queue on device is currently unable to send.
1880 */ 1882 */
1881static inline int netif_queue_stopped(const struct net_device *dev) 1883static inline bool netif_queue_stopped(const struct net_device *dev)
1882{ 1884{
1883 return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0)); 1885 return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
1884} 1886}
1885 1887
1886static inline int netif_xmit_stopped(const struct netdev_queue *dev_queue) 1888static inline bool netif_xmit_stopped(const struct netdev_queue *dev_queue)
1887{ 1889{
1888 return dev_queue->state & QUEUE_STATE_ANY_XOFF; 1890 return dev_queue->state & QUEUE_STATE_ANY_XOFF;
1889} 1891}
1890 1892
1891static inline int netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue) 1893static inline bool netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue)
1892{ 1894{
1893 return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN; 1895 return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN;
1894} 1896}
@@ -1898,12 +1900,22 @@ static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
1898{ 1900{
1899#ifdef CONFIG_BQL 1901#ifdef CONFIG_BQL
1900 dql_queued(&dev_queue->dql, bytes); 1902 dql_queued(&dev_queue->dql, bytes);
1901 if (unlikely(dql_avail(&dev_queue->dql) < 0)) { 1903
1902 set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state); 1904 if (likely(dql_avail(&dev_queue->dql) >= 0))
1903 if (unlikely(dql_avail(&dev_queue->dql) >= 0)) 1905 return;
1904 clear_bit(__QUEUE_STATE_STACK_XOFF, 1906
1905 &dev_queue->state); 1907 set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
1906 } 1908
1909 /*
1910 * The XOFF flag must be set before checking the dql_avail below,
1911 * because in netdev_tx_completed_queue we update the dql_completed
1912 * before checking the XOFF flag.
1913 */
1914 smp_mb();
1915
1916 /* check again in case another CPU has just made room avail */
1917 if (unlikely(dql_avail(&dev_queue->dql) >= 0))
1918 clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
1907#endif 1919#endif
1908} 1920}
1909 1921
@@ -1916,16 +1928,23 @@ static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue,
1916 unsigned pkts, unsigned bytes) 1928 unsigned pkts, unsigned bytes)
1917{ 1929{
1918#ifdef CONFIG_BQL 1930#ifdef CONFIG_BQL
1919 if (likely(bytes)) { 1931 if (unlikely(!bytes))
1920 dql_completed(&dev_queue->dql, bytes); 1932 return;
1921 if (unlikely(test_bit(__QUEUE_STATE_STACK_XOFF, 1933
1922 &dev_queue->state) && 1934 dql_completed(&dev_queue->dql, bytes);
1923 dql_avail(&dev_queue->dql) >= 0)) { 1935
1924 if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF, 1936 /*
1925 &dev_queue->state)) 1937 * Without the memory barrier there is a small possiblity that
1926 netif_schedule_queue(dev_queue); 1938 * netdev_tx_sent_queue will miss the update and cause the queue to
1927 } 1939 * be stopped forever
1928 } 1940 */
1941 smp_mb();
1942
1943 if (dql_avail(&dev_queue->dql) < 0)
1944 return;
1945
1946 if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state))
1947 netif_schedule_queue(dev_queue);
1929#endif 1948#endif
1930} 1949}
1931 1950
@@ -1938,6 +1957,7 @@ static inline void netdev_completed_queue(struct net_device *dev,
1938static inline void netdev_tx_reset_queue(struct netdev_queue *q) 1957static inline void netdev_tx_reset_queue(struct netdev_queue *q)
1939{ 1958{
1940#ifdef CONFIG_BQL 1959#ifdef CONFIG_BQL
1960 clear_bit(__QUEUE_STATE_STACK_XOFF, &q->state);
1941 dql_reset(&q->dql); 1961 dql_reset(&q->dql);
1942#endif 1962#endif
1943} 1963}
@@ -1953,7 +1973,7 @@ static inline void netdev_reset_queue(struct net_device *dev_queue)
1953 * 1973 *
1954 * Test if the device has been brought up. 1974 * Test if the device has been brought up.
1955 */ 1975 */
1956static inline int netif_running(const struct net_device *dev) 1976static inline bool netif_running(const struct net_device *dev)
1957{ 1977{
1958 return test_bit(__LINK_STATE_START, &dev->state); 1978 return test_bit(__LINK_STATE_START, &dev->state);
1959} 1979}
@@ -2003,16 +2023,16 @@ static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
2003 * 2023 *
2004 * Check individual transmit queue of a device with multiple transmit queues. 2024 * Check individual transmit queue of a device with multiple transmit queues.
2005 */ 2025 */
2006static inline int __netif_subqueue_stopped(const struct net_device *dev, 2026static inline bool __netif_subqueue_stopped(const struct net_device *dev,
2007 u16 queue_index) 2027 u16 queue_index)
2008{ 2028{
2009 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index); 2029 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
2010 2030
2011 return netif_tx_queue_stopped(txq); 2031 return netif_tx_queue_stopped(txq);
2012} 2032}
2013 2033
2014static inline int netif_subqueue_stopped(const struct net_device *dev, 2034static inline bool netif_subqueue_stopped(const struct net_device *dev,
2015 struct sk_buff *skb) 2035 struct sk_buff *skb)
2016{ 2036{
2017 return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb)); 2037 return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
2018} 2038}
@@ -2051,7 +2071,7 @@ static inline u16 skb_tx_hash(const struct net_device *dev,
2051 * 2071 *
2052 * Check if device has multiple transmit queues 2072 * Check if device has multiple transmit queues
2053 */ 2073 */
2054static inline int netif_is_multiqueue(const struct net_device *dev) 2074static inline bool netif_is_multiqueue(const struct net_device *dev)
2055{ 2075{
2056 return dev->num_tx_queues > 1; 2076 return dev->num_tx_queues > 1;
2057} 2077}
@@ -2121,7 +2141,7 @@ extern int netdev_rx_handler_register(struct net_device *dev,
2121 void *rx_handler_data); 2141 void *rx_handler_data);
2122extern void netdev_rx_handler_unregister(struct net_device *dev); 2142extern void netdev_rx_handler_unregister(struct net_device *dev);
2123 2143
2124extern int dev_valid_name(const char *name); 2144extern bool dev_valid_name(const char *name);
2125extern int dev_ioctl(struct net *net, unsigned int cmd, void __user *); 2145extern int dev_ioctl(struct net *net, unsigned int cmd, void __user *);
2126extern int dev_ethtool(struct net *net, struct ifreq *); 2146extern int dev_ethtool(struct net *net, struct ifreq *);
2127extern unsigned dev_get_flags(const struct net_device *); 2147extern unsigned dev_get_flags(const struct net_device *);
@@ -2187,7 +2207,7 @@ extern void linkwatch_forget_dev(struct net_device *dev);
2187 * 2207 *
2188 * Check if carrier is present on device 2208 * Check if carrier is present on device
2189 */ 2209 */
2190static inline int netif_carrier_ok(const struct net_device *dev) 2210static inline bool netif_carrier_ok(const struct net_device *dev)
2191{ 2211{
2192 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state); 2212 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
2193} 2213}
@@ -2239,7 +2259,7 @@ static inline void netif_dormant_off(struct net_device *dev)
2239 * 2259 *
2240 * Check if carrier is present on device 2260 * Check if carrier is present on device
2241 */ 2261 */
2242static inline int netif_dormant(const struct net_device *dev) 2262static inline bool netif_dormant(const struct net_device *dev)
2243{ 2263{
2244 return test_bit(__LINK_STATE_DORMANT, &dev->state); 2264 return test_bit(__LINK_STATE_DORMANT, &dev->state);
2245} 2265}
@@ -2251,7 +2271,7 @@ static inline int netif_dormant(const struct net_device *dev)
2251 * 2271 *
2252 * Check if carrier is operational 2272 * Check if carrier is operational
2253 */ 2273 */
2254static inline int netif_oper_up(const struct net_device *dev) 2274static inline bool netif_oper_up(const struct net_device *dev)
2255{ 2275{
2256 return (dev->operstate == IF_OPER_UP || 2276 return (dev->operstate == IF_OPER_UP ||
2257 dev->operstate == IF_OPER_UNKNOWN /* backward compat */); 2277 dev->operstate == IF_OPER_UNKNOWN /* backward compat */);
@@ -2263,7 +2283,7 @@ static inline int netif_oper_up(const struct net_device *dev)
2263 * 2283 *
2264 * Check if device has not been removed from system. 2284 * Check if device has not been removed from system.
2265 */ 2285 */
2266static inline int netif_device_present(struct net_device *dev) 2286static inline bool netif_device_present(struct net_device *dev)
2267{ 2287{
2268 return test_bit(__LINK_STATE_PRESENT, &dev->state); 2288 return test_bit(__LINK_STATE_PRESENT, &dev->state);
2269} 2289}
@@ -2333,9 +2353,9 @@ static inline void __netif_tx_lock_bh(struct netdev_queue *txq)
2333 txq->xmit_lock_owner = smp_processor_id(); 2353 txq->xmit_lock_owner = smp_processor_id();
2334} 2354}
2335 2355
2336static inline int __netif_tx_trylock(struct netdev_queue *txq) 2356static inline bool __netif_tx_trylock(struct netdev_queue *txq)
2337{ 2357{
2338 int ok = spin_trylock(&txq->_xmit_lock); 2358 bool ok = spin_trylock(&txq->_xmit_lock);
2339 if (likely(ok)) 2359 if (likely(ok))
2340 txq->xmit_lock_owner = smp_processor_id(); 2360 txq->xmit_lock_owner = smp_processor_id();
2341 return ok; 2361 return ok;
@@ -2556,6 +2576,8 @@ extern void dev_load(struct net *net, const char *name);
2556extern void dev_mcast_init(void); 2576extern void dev_mcast_init(void);
2557extern struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, 2577extern struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
2558 struct rtnl_link_stats64 *storage); 2578 struct rtnl_link_stats64 *storage);
2579extern void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
2580 const struct net_device_stats *netdev_stats);
2559 2581
2560extern int netdev_max_backlog; 2582extern int netdev_max_backlog;
2561extern int netdev_tstamp_prequeue; 2583extern int netdev_tstamp_prequeue;
@@ -2611,7 +2633,7 @@ void netif_stacked_transfer_operstate(const struct net_device *rootdev,
2611 2633
2612netdev_features_t netif_skb_features(struct sk_buff *skb); 2634netdev_features_t netif_skb_features(struct sk_buff *skb);
2613 2635
2614static inline int net_gso_ok(netdev_features_t features, int gso_type) 2636static inline bool net_gso_ok(netdev_features_t features, int gso_type)
2615{ 2637{
2616 netdev_features_t feature = gso_type << NETIF_F_GSO_SHIFT; 2638 netdev_features_t feature = gso_type << NETIF_F_GSO_SHIFT;
2617 2639
@@ -2626,17 +2648,18 @@ static inline int net_gso_ok(netdev_features_t features, int gso_type)
2626 return (features & feature) == feature; 2648 return (features & feature) == feature;
2627} 2649}
2628 2650
2629static inline int skb_gso_ok(struct sk_buff *skb, netdev_features_t features) 2651static inline bool skb_gso_ok(struct sk_buff *skb, netdev_features_t features)
2630{ 2652{
2631 return net_gso_ok(features, skb_shinfo(skb)->gso_type) && 2653 return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
2632 (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST)); 2654 (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
2633} 2655}
2634 2656
2635static inline int netif_needs_gso(struct sk_buff *skb, 2657static inline bool netif_needs_gso(struct sk_buff *skb,
2636 netdev_features_t features) 2658 netdev_features_t features)
2637{ 2659{
2638 return skb_is_gso(skb) && (!skb_gso_ok(skb, features) || 2660 return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
2639 unlikely(skb->ip_summed != CHECKSUM_PARTIAL)); 2661 unlikely((skb->ip_summed != CHECKSUM_PARTIAL) &&
2662 (skb->ip_summed != CHECKSUM_UNNECESSARY)));
2640} 2663}
2641 2664
2642static inline void netif_set_gso_max_size(struct net_device *dev, 2665static inline void netif_set_gso_max_size(struct net_device *dev,
@@ -2645,11 +2668,16 @@ static inline void netif_set_gso_max_size(struct net_device *dev,
2645 dev->gso_max_size = size; 2668 dev->gso_max_size = size;
2646} 2669}
2647 2670
2648static inline int netif_is_bond_slave(struct net_device *dev) 2671static inline bool netif_is_bond_slave(struct net_device *dev)
2649{ 2672{
2650 return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING; 2673 return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
2651} 2674}
2652 2675
2676static inline bool netif_supports_nofcs(struct net_device *dev)
2677{
2678 return dev->priv_flags & IFF_SUPP_NOFCS;
2679}
2680
2653extern struct pernet_operations __net_initdata loopback_net_ops; 2681extern struct pernet_operations __net_initdata loopback_net_ops;
2654 2682
2655/* Logging, debugging and troubleshooting/diagnostic helpers. */ 2683/* Logging, debugging and troubleshooting/diagnostic helpers. */
@@ -2687,14 +2715,14 @@ int netdev_info(const struct net_device *dev, const char *format, ...);
2687#define MODULE_ALIAS_NETDEV(device) \ 2715#define MODULE_ALIAS_NETDEV(device) \
2688 MODULE_ALIAS("netdev-" device) 2716 MODULE_ALIAS("netdev-" device)
2689 2717
2690#if defined(DEBUG) 2718#if defined(CONFIG_DYNAMIC_DEBUG)
2691#define netdev_dbg(__dev, format, args...) \
2692 netdev_printk(KERN_DEBUG, __dev, format, ##args)
2693#elif defined(CONFIG_DYNAMIC_DEBUG)
2694#define netdev_dbg(__dev, format, args...) \ 2719#define netdev_dbg(__dev, format, args...) \
2695do { \ 2720do { \
2696 dynamic_netdev_dbg(__dev, format, ##args); \ 2721 dynamic_netdev_dbg(__dev, format, ##args); \
2697} while (0) 2722} while (0)
2723#elif defined(DEBUG)
2724#define netdev_dbg(__dev, format, args...) \
2725 netdev_printk(KERN_DEBUG, __dev, format, ##args)
2698#else 2726#else
2699#define netdev_dbg(__dev, format, args...) \ 2727#define netdev_dbg(__dev, format, args...) \
2700({ \ 2728({ \