Merge tag 'fscache-fixes-20141013' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / include / linux / netdevice.h
index c8e388e5fcccfa604d087ce33ccee5ace528e598..838407aea70503003e09c06fe17845f9e1c9d656 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/bug.h>
 #include <linux/delay.h>
 #include <linux/atomic.h>
+#include <linux/prefetch.h>
 #include <asm/cache.h>
 #include <asm/byteorder.h>
 
@@ -543,7 +544,7 @@ struct netdev_queue {
  * read mostly part
  */
        struct net_device       *dev;
-       struct Qdisc            *qdisc;
+       struct Qdisc __rcu      *qdisc;
        struct Qdisc            *qdisc_sleeping;
 #ifdef CONFIG_SYSFS
        struct kobject          kobj;
@@ -1206,6 +1207,7 @@ enum netdev_priv_flags {
        IFF_SUPP_NOFCS                  = 1<<19,
        IFF_LIVE_ADDR_CHANGE            = 1<<20,
        IFF_MACVLAN                     = 1<<21,
+       IFF_XMIT_DST_RELEASE_PERM       = 1<<22,
 };
 
 #define IFF_802_1Q_VLAN                        IFF_802_1Q_VLAN
@@ -1230,6 +1232,7 @@ enum netdev_priv_flags {
 #define IFF_SUPP_NOFCS                 IFF_SUPP_NOFCS
 #define IFF_LIVE_ADDR_CHANGE           IFF_LIVE_ADDR_CHANGE
 #define IFF_MACVLAN                    IFF_MACVLAN
+#define IFF_XMIT_DST_RELEASE_PERM      IFF_XMIT_DST_RELEASE_PERM
 
 /**
  *     struct net_device - The DEVICE structure.
@@ -1416,6 +1419,8 @@ enum netdev_priv_flags {
  *     @gso_max_size:  Maximum size of generic segmentation offload
  *     @gso_max_segs:  Maximum number of segments that can be passed to the
  *                     NIC for GSO
+ *     @gso_min_segs:  Minimum number of segments that can be passed to the
+ *                     NIC for GSO
  *
  *     @dcbnl_ops:     Data Center Bridging netlink ops
  *     @num_tc:        Number of traffic classes in the net device
@@ -1666,7 +1671,7 @@ struct net_device {
        unsigned int            gso_max_size;
 #define GSO_MAX_SEGS           65535
        u16                     gso_max_segs;
-
+       u16                     gso_min_segs;
 #ifdef CONFIG_DCB
        const struct dcbnl_rtnl_ops *dcbnl_ops;
 #endif
@@ -1747,6 +1752,12 @@ struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
        return &dev->_tx[index];
 }
 
+static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
+                                                   const struct sk_buff *skb)
+{
+       return netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
+}
+
 static inline void netdev_for_each_tx_queue(struct net_device *dev,
                                            void (*f)(struct net_device *,
                                                      struct netdev_queue *,
@@ -1781,24 +1792,13 @@ void dev_net_set(struct net_device *dev, struct net *net)
 #endif
 }
 
-static inline bool netdev_uses_dsa_tags(struct net_device *dev)
+static inline bool netdev_uses_dsa(struct net_device *dev)
 {
-#ifdef CONFIG_NET_DSA_TAG_DSA
-       if (dev->dsa_ptr != NULL)
-               return dsa_uses_dsa_tags(dev->dsa_ptr);
-#endif
-
-       return 0;
-}
-
-static inline bool netdev_uses_trailer_tags(struct net_device *dev)
-{
-#ifdef CONFIG_NET_DSA_TAG_TRAILER
+#if IS_ENABLED(CONFIG_NET_DSA)
        if (dev->dsa_ptr != NULL)
-               return dsa_uses_trailer_tags(dev->dsa_ptr);
+               return dsa_uses_tagged_protocol(dev->dsa_ptr);
 #endif
-
-       return 0;
+       return false;
 }
 
 /**
@@ -1879,11 +1879,20 @@ struct napi_gro_cb {
        /* jiffies when first packet was created/queued */
        unsigned long age;
 
-       /* Used in ipv6_gro_receive() */
+       /* Used in ipv6_gro_receive() and foo-over-udp */
        u16     proto;
 
        /* Used in udp_gro_receive */
-       u16     udp_mark;
+       u8      udp_mark:1;
+
+       /* GRO checksum is valid */
+       u8      csum_valid:1;
+
+       /* Number of checksums via CHECKSUM_UNNECESSARY */
+       u8      csum_cnt:3;
+
+       /* Used in foo-over-udp, set in udp[46]_gro_receive */
+       u8      is_ipv6:1;
 
        /* used to support CHECKSUM_COMPLETE for tunneling protocols */
        __wsum  csum;
@@ -1910,7 +1919,6 @@ struct packet_type {
 struct offload_callbacks {
        struct sk_buff          *(*gso_segment)(struct sk_buff *skb,
                                                netdev_features_t features);
-       int                     (*gso_send_check)(struct sk_buff *skb);
        struct sk_buff          **(*gro_receive)(struct sk_buff **head,
                                               struct sk_buff *skb);
        int                     (*gro_complete)(struct sk_buff *skb, int nhoff);
@@ -1924,6 +1932,7 @@ struct packet_offload {
 
 struct udp_offload {
        __be16                   port;
+       u8                       ipproto;
        struct offload_callbacks callbacks;
 };
 
@@ -1982,6 +1991,7 @@ struct pcpu_sw_netstats {
 #define NETDEV_CHANGEUPPER     0x0015
 #define NETDEV_RESEND_IGMP     0x0016
 #define NETDEV_PRECHANGEMTU    0x0017 /* notify before mtu change happened */
+#define NETDEV_CHANGEINFODATA  0x0018
 
 int register_netdevice_notifier(struct notifier_block *nb);
 int unregister_netdevice_notifier(struct notifier_block *nb);
@@ -2074,8 +2084,8 @@ void __dev_remove_pack(struct packet_type *pt);
 void dev_add_offload(struct packet_offload *po);
 void dev_remove_offload(struct packet_offload *po);
 
-struct net_device *dev_get_by_flags_rcu(struct net *net, unsigned short flags,
-                                       unsigned short mask);
+struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags,
+                                     unsigned short mask);
 struct net_device *dev_get_by_name(struct net *net, const char *name);
 struct net_device *dev_get_by_name_rcu(struct net *net, const char *name);
 struct net_device *__dev_get_by_name(struct net *net, const char *name);
@@ -2153,11 +2163,97 @@ static inline void *skb_gro_network_header(struct sk_buff *skb)
 static inline void skb_gro_postpull_rcsum(struct sk_buff *skb,
                                        const void *start, unsigned int len)
 {
-       if (skb->ip_summed == CHECKSUM_COMPLETE)
+       if (NAPI_GRO_CB(skb)->csum_valid)
                NAPI_GRO_CB(skb)->csum = csum_sub(NAPI_GRO_CB(skb)->csum,
                                                  csum_partial(start, len, 0));
 }
 
+/* GRO checksum functions. These are logical equivalents of the normal
+ * checksum functions (in skbuff.h) except that they operate on the GRO
+ * offsets and fields in sk_buff.
+ */
+
+__sum16 __skb_gro_checksum_complete(struct sk_buff *skb);
+
+static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb,
+                                                     bool zero_okay,
+                                                     __sum16 check)
+{
+       return (skb->ip_summed != CHECKSUM_PARTIAL &&
+               NAPI_GRO_CB(skb)->csum_cnt == 0 &&
+               (!zero_okay || check));
+}
+
+static inline __sum16 __skb_gro_checksum_validate_complete(struct sk_buff *skb,
+                                                          __wsum psum)
+{
+       if (NAPI_GRO_CB(skb)->csum_valid &&
+           !csum_fold(csum_add(psum, NAPI_GRO_CB(skb)->csum)))
+               return 0;
+
+       NAPI_GRO_CB(skb)->csum = psum;
+
+       return __skb_gro_checksum_complete(skb);
+}
+
+static inline void skb_gro_incr_csum_unnecessary(struct sk_buff *skb)
+{
+       if (NAPI_GRO_CB(skb)->csum_cnt > 0) {
+               /* Consume a checksum from CHECKSUM_UNNECESSARY */
+               NAPI_GRO_CB(skb)->csum_cnt--;
+       } else {
+               /* Update skb for CHECKSUM_UNNECESSARY and csum_level when we
+                * verified a new top level checksum or an encapsulated one
+                * during GRO. This saves work if we fallback to normal path.
+                */
+               __skb_incr_checksum_unnecessary(skb);
+       }
+}
+
+#define __skb_gro_checksum_validate(skb, proto, zero_okay, check,      \
+                                   compute_pseudo)                     \
+({                                                                     \
+       __sum16 __ret = 0;                                              \
+       if (__skb_gro_checksum_validate_needed(skb, zero_okay, check))  \
+               __ret = __skb_gro_checksum_validate_complete(skb,       \
+                               compute_pseudo(skb, proto));            \
+       if (__ret)                                                      \
+               __skb_mark_checksum_bad(skb);                           \
+       else                                                            \
+               skb_gro_incr_csum_unnecessary(skb);                     \
+       __ret;                                                          \
+})
+
+#define skb_gro_checksum_validate(skb, proto, compute_pseudo)          \
+       __skb_gro_checksum_validate(skb, proto, false, 0, compute_pseudo)
+
+#define skb_gro_checksum_validate_zero_check(skb, proto, check,                \
+                                            compute_pseudo)            \
+       __skb_gro_checksum_validate(skb, proto, true, check, compute_pseudo)
+
+#define skb_gro_checksum_simple_validate(skb)                          \
+       __skb_gro_checksum_validate(skb, 0, false, 0, null_compute_pseudo)
+
+static inline bool __skb_gro_checksum_convert_check(struct sk_buff *skb)
+{
+       return (NAPI_GRO_CB(skb)->csum_cnt == 0 &&
+               !NAPI_GRO_CB(skb)->csum_valid);
+}
+
+static inline void __skb_gro_checksum_convert(struct sk_buff *skb,
+                                             __sum16 check, __wsum pseudo)
+{
+       NAPI_GRO_CB(skb)->csum = ~pseudo;
+       NAPI_GRO_CB(skb)->csum_valid = 1;
+}
+
+#define skb_gro_checksum_try_convert(skb, proto, check, compute_pseudo)        \
+do {                                                                   \
+       if (__skb_gro_checksum_convert_check(skb))                      \
+               __skb_gro_checksum_convert(skb, check,                  \
+                                          compute_pseudo(skb, proto)); \
+} while (0)
+
 static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
                                  unsigned short type,
                                  const void *daddr, const void *saddr,
@@ -2261,12 +2357,7 @@ static inline void input_queue_tail_incr_save(struct softnet_data *sd,
 DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
 
 void __netif_schedule(struct Qdisc *q);
-
-static inline void netif_schedule_queue(struct netdev_queue *txq)
-{
-       if (!(txq->state & QUEUE_STATE_ANY_XOFF))
-               __netif_schedule(txq->qdisc);
-}
+void netif_schedule_queue(struct netdev_queue *txq);
 
 static inline void netif_tx_schedule_all(struct net_device *dev)
 {
@@ -2302,11 +2393,7 @@ static inline void netif_tx_start_all_queues(struct net_device *dev)
        }
 }
 
-static inline void netif_tx_wake_queue(struct netdev_queue *dev_queue)
-{
-       if (test_and_clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state))
-               __netif_schedule(dev_queue->qdisc);
-}
+void netif_tx_wake_queue(struct netdev_queue *dev_queue);
 
 /**
  *     netif_wake_queue - restart transmit
@@ -2394,6 +2481,34 @@ netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue)
        return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN;
 }
 
+/**
+ *     netdev_txq_bql_enqueue_prefetchw - prefetch bql data for write
+ *     @dev_queue: pointer to transmit queue
+ *
+ * BQL enabled drivers might use this helper in their ndo_start_xmit(),
+ * to give appropriate hint to the cpu.
+ */
+static inline void netdev_txq_bql_enqueue_prefetchw(struct netdev_queue *dev_queue)
+{
+#ifdef CONFIG_BQL
+       prefetchw(&dev_queue->dql.num_queued);
+#endif
+}
+
+/**
+ *     netdev_txq_bql_complete_prefetchw - prefetch bql data for write
+ *     @dev_queue: pointer to transmit queue
+ *
+ * BQL enabled drivers might use this helper in their TX completion path,
+ * to give appropriate hint to the cpu.
+ */
+static inline void netdev_txq_bql_complete_prefetchw(struct netdev_queue *dev_queue)
+{
+#ifdef CONFIG_BQL
+       prefetchw(&dev_queue->dql.limit);
+#endif
+}
+
 static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
                                        unsigned int bytes)
 {
@@ -2578,19 +2693,7 @@ static inline bool netif_subqueue_stopped(const struct net_device *dev,
        return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
 }
 
-/**
- *     netif_wake_subqueue - allow sending packets on subqueue
- *     @dev: network device
- *     @queue_index: sub queue index
- *
- * Resume individual transmit queue of a device with multiple transmit queues.
- */
-static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
-{
-       struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
-       if (test_and_clear_bit(__QUEUE_STATE_DRV_XOFF, &txq->state))
-               __netif_schedule(txq->qdisc);
-}
+void netif_wake_subqueue(struct net_device *dev, u16 queue_index);
 
 #ifdef CONFIG_XPS
 int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
@@ -2754,8 +2857,9 @@ int dev_set_mac_address(struct net_device *, struct sockaddr *);
 int dev_change_carrier(struct net_device *, bool new_carrier);
 int dev_get_phys_port_id(struct net_device *dev,
                         struct netdev_phys_port_id *ppid);
-int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
-                       struct netdev_queue *txq);
+struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev);
+struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
+                                   struct netdev_queue *txq, int *ret);
 int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
 int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
 bool is_skb_forwardable(struct net_device *dev, struct sk_buff *skb);
@@ -3357,6 +3461,27 @@ int __init dev_proc_init(void);
 #define dev_proc_init() 0
 #endif
 
+static inline netdev_tx_t __netdev_start_xmit(const struct net_device_ops *ops,
+                                             struct sk_buff *skb, struct net_device *dev,
+                                             bool more)
+{
+       skb->xmit_more = more ? 1 : 0;
+       return ops->ndo_start_xmit(skb, dev);
+}
+
+static inline netdev_tx_t netdev_start_xmit(struct sk_buff *skb, struct net_device *dev,
+                                           struct netdev_queue *txq, bool more)
+{
+       const struct net_device_ops *ops = dev->netdev_ops;
+       int rc;
+
+       rc = __netdev_start_xmit(ops, skb, dev, more);
+       if (rc == NETDEV_TX_OK)
+               txq_trans_update(txq);
+
+       return rc;
+}
+
 int netdev_class_create_file_ns(struct class_attribute *class_attr,
                                const void *ns);
 void netdev_class_remove_file_ns(struct class_attribute *class_attr,
@@ -3494,6 +3619,12 @@ static inline bool netif_supports_nofcs(struct net_device *dev)
        return dev->priv_flags & IFF_SUPP_NOFCS;
 }
 
+/* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
+static inline void netif_keep_dst(struct net_device *dev)
+{
+       dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM);
+}
+
 extern struct pernet_operations __net_initdata loopback_net_ops;
 
 /* Logging, debugging and troubleshooting/diagnostic helpers. */
@@ -3523,22 +3654,22 @@ static inline const char *netdev_reg_state(const struct net_device *dev)
 }
 
 __printf(3, 4)
-int netdev_printk(const char *level, const struct net_device *dev,
-                 const char *format, ...);
+void netdev_printk(const char *level, const struct net_device *dev,
+                  const char *format, ...);
 __printf(2, 3)
-int netdev_emerg(const struct net_device *dev, const char *format, ...);
+void netdev_emerg(const struct net_device *dev, const char *format, ...);
 __printf(2, 3)
-int netdev_alert(const struct net_device *dev, const char *format, ...);
+void netdev_alert(const struct net_device *dev, const char *format, ...);
 __printf(2, 3)
-int netdev_crit(const struct net_device *dev, const char *format, ...);
+void netdev_crit(const struct net_device *dev, const char *format, ...);
 __printf(2, 3)
-int netdev_err(const struct net_device *dev, const char *format, ...);
+void netdev_err(const struct net_device *dev, const char *format, ...);
 __printf(2, 3)
-int netdev_warn(const struct net_device *dev, const char *format, ...);
+void netdev_warn(const struct net_device *dev, const char *format, ...);
 __printf(2, 3)
-int netdev_notice(const struct net_device *dev, const char *format, ...);
+void netdev_notice(const struct net_device *dev, const char *format, ...);
 __printf(2, 3)
-int netdev_info(const struct net_device *dev, const char *format, ...);
+void netdev_info(const struct net_device *dev, const char *format, ...);
 
 #define MODULE_ALIAS_NETDEV(device) \
        MODULE_ALIAS("netdev-" device)
@@ -3556,7 +3687,6 @@ do {                                                              \
 ({                                                             \
        if (0)                                                  \
                netdev_printk(KERN_DEBUG, __dev, format, ##args); \
-       0;                                                      \
 })
 #endif