net: introduce rx_handler results and logic around that
[pandora-kernel.git] / include / linux / netdevice.h
index 8858422..5eeb2cd 100644 (file)
@@ -75,9 +75,6 @@ struct wireless_dev;
 #define NET_RX_SUCCESS         0       /* keep 'em coming, baby */
 #define NET_RX_DROP            1       /* packet dropped */
 
-/* Initial net device group. All devices belong to group 0 by default. */
-#define INIT_NETDEV_GROUP      0
-
 /*
  * Transmit return codes: transmit return codes originate from three different
  * namespaces:
@@ -141,6 +138,9 @@ static inline bool dev_xmit_complete(int rc)
 
 #define MAX_ADDR_LEN   32              /* Largest hardware address length */
 
+/* Initial net device group. All devices belong to group 0 by default. */
+#define INIT_NETDEV_GROUP      0
+
 #ifdef  __KERNEL__
 /*
  *     Compute the worst case header length according to the protocols
@@ -390,7 +390,55 @@ enum gro_result {
 };
 typedef enum gro_result gro_result_t;
 
-typedef struct sk_buff *rx_handler_func_t(struct sk_buff *skb);
+/*
+ * enum rx_handler_result - Possible return values for rx_handlers.
+ * @RX_HANDLER_CONSUMED: skb was consumed by rx_handler, do not process it
+ * further.
+ * @RX_HANDLER_ANOTHER: Do another round in receive path. This is indicated in
+ * case skb->dev was changed by rx_handler.
+ * @RX_HANDLER_EXACT: Force exact delivery, no wildcard.
+ * @RX_HANDLER_PASS: Do nothing, passe the skb as if no rx_handler was called.
+ *
+ * rx_handlers are functions called from inside __netif_receive_skb(), to do
+ * special processing of the skb, prior to delivery to protocol handlers.
+ *
+ * Currently, a net_device can only have a single rx_handler registered. Trying
+ * to register a second rx_handler will return -EBUSY.
+ *
+ * To register a rx_handler on a net_device, use netdev_rx_handler_register().
+ * To unregister a rx_handler on a net_device, use
+ * netdev_rx_handler_unregister().
+ *
+ * Upon return, rx_handler is expected to tell __netif_receive_skb() what to
+ * do with the skb.
+ *
+ * If the rx_handler consumed to skb in some way, it should return
+ * RX_HANDLER_CONSUMED. This is appropriate when the rx_handler arranged for
+ * the skb to be delivered in some other ways.
+ *
+ * If the rx_handler changed skb->dev, to divert the skb to another
+ * net_device, it should return RX_HANDLER_ANOTHER. The rx_handler for the
+ * new device will be called if it exists.
+ *
+ * If the rx_handler consider the skb should be ignored, it should return
+ * RX_HANDLER_EXACT. The skb will only be delivered to protocol handlers that
+ * are registred on exact device (ptype->dev == skb->dev).
+ *
+ * If the rx_handler didn't changed skb->dev, but want the skb to be normally
+ * delivered, it should return RX_HANDLER_PASS.
+ *
+ * A device without a registered rx_handler will behave as if rx_handler
+ * returned RX_HANDLER_PASS.
+ */
+
+enum rx_handler_result {
+       RX_HANDLER_CONSUMED,
+       RX_HANDLER_ANOTHER,
+       RX_HANDLER_EXACT,
+       RX_HANDLER_PASS,
+};
+typedef enum rx_handler_result rx_handler_result_t;
+typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
 
 extern void __napi_schedule(struct napi_struct *n);
 
@@ -777,12 +825,68 @@ struct netdev_tc_txq {
  *     queues stopped. This allows the netdevice to perform queue management
  *     safely.
  *
+ *     Fiber Channel over Ethernet (FCoE) offload functions.
+ * int (*ndo_fcoe_enable)(struct net_device *dev);
+ *     Called when the FCoE protocol stack wants to start using LLD for FCoE
+ *     so the underlying device can perform whatever needed configuration or
+ *     initialization to support acceleration of FCoE traffic.
+ *
+ * int (*ndo_fcoe_disable)(struct net_device *dev);
+ *     Called when the FCoE protocol stack wants to stop using LLD for FCoE
+ *     so the underlying device can perform whatever needed clean-ups to
+ *     stop supporting acceleration of FCoE traffic.
+ *
+ * int (*ndo_fcoe_ddp_setup)(struct net_device *dev, u16 xid,
+ *                          struct scatterlist *sgl, unsigned int sgc);
+ *     Called when the FCoE Initiator wants to initialize an I/O that
+ *     is a possible candidate for Direct Data Placement (DDP). The LLD can
+ *     perform necessary setup and returns 1 to indicate the device is set up
+ *     successfully to perform DDP on this I/O, otherwise this returns 0.
+ *
+ * int (*ndo_fcoe_ddp_done)(struct net_device *dev,  u16 xid);
+ *     Called when the FCoE Initiator/Target is done with the DDPed I/O as
+ *     indicated by the FC exchange id 'xid', so the underlying device can
+ *     clean up and reuse resources for later DDP requests.
+ *
+ * int (*ndo_fcoe_ddp_target)(struct net_device *dev, u16 xid,
+ *                           struct scatterlist *sgl, unsigned int sgc);
+ *     Called when the FCoE Target wants to initialize an I/O that
+ *     is a possible candidate for Direct Data Placement (DDP). The LLD can
+ *     perform necessary setup and returns 1 to indicate the device is set up
+ *     successfully to perform DDP on this I/O, otherwise this returns 0.
+ *
+ * int (*ndo_fcoe_get_wwn)(struct net_device *dev, u64 *wwn, int type);
+ *     Called when the underlying device wants to override default World Wide
+ *     Name (WWN) generation mechanism in FCoE protocol stack to pass its own
+ *     World Wide Port Name (WWPN) or World Wide Node Name (WWNN) to the FCoE
+ *     protocol stack to use.
+ *
  *     RFS acceleration.
  * int (*ndo_rx_flow_steer)(struct net_device *dev, const struct sk_buff *skb,
  *                         u16 rxq_index, u32 flow_id);
  *     Set hardware filter for RFS.  rxq_index is the target queue index;
  *     flow_id is a flow ID to be passed to rps_may_expire_flow() later.
  *     Return the filter ID on success, or a negative error code.
+ *
+ *     Slave management functions (for bridge, bonding, etc). User should
+ *     call netdev_set_master() to set dev->master properly.
+ * int (*ndo_add_slave)(struct net_device *dev, struct net_device *slave_dev);
+ *     Called to make another netdev an underling.
+ *
+ * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);
+ *     Called to release previously enslaved netdev.
+ *
+ *      Feature/offload setting functions.
+ * u32 (*ndo_fix_features)(struct net_device *dev, u32 features);
+ *     Adjusts the requested feature flags according to device-specific
+ *     constraints, and returns the resulting flags. Must not modify
+ *     the device state.
+ *
+ * int (*ndo_set_features)(struct net_device *dev, u32 features);
+ *     Called to update device configuration to new features. Passed
+ *     feature set might be less than what was returned by ndo_fix_features()).
+ *     Must return >0 or -errno if it changed dev->features itself.
+ *
  */
 #define HAVE_NET_DEVICE_OPS
 struct net_device_ops {
@@ -851,6 +955,10 @@ struct net_device_ops {
                                                      unsigned int sgc);
        int                     (*ndo_fcoe_ddp_done)(struct net_device *dev,
                                                     u16 xid);
+       int                     (*ndo_fcoe_ddp_target)(struct net_device *dev,
+                                                      u16 xid,
+                                                      struct scatterlist *sgl,
+                                                      unsigned int sgc);
 #define NETDEV_FCOE_WWNN 0
 #define NETDEV_FCOE_WWPN 1
        int                     (*ndo_fcoe_get_wwn)(struct net_device *dev,
@@ -862,6 +970,14 @@ struct net_device_ops {
                                                     u16 rxq_index,
                                                     u32 flow_id);
 #endif
+       int                     (*ndo_add_slave)(struct net_device *dev,
+                                                struct net_device *slave_dev);
+       int                     (*ndo_del_slave)(struct net_device *dev,
+                                                struct net_device *slave_dev);
+       u32                     (*ndo_fix_features)(struct net_device *dev,
+                                                   u32 features);
+       int                     (*ndo_set_features)(struct net_device *dev,
+                                                   u32 features);
 };
 
 /*
@@ -913,12 +1029,18 @@ struct net_device {
        struct list_head        napi_list;
        struct list_head        unreg_list;
 
-       /* Net device features */
+       /* currently active device features */
        u32                     features;
-
+       /* user-changeable features */
+       u32                     hw_features;
+       /* user-requested features */
+       u32                     wanted_features;
        /* VLAN feature mask */
        u32                     vlan_features;
 
+       /* Net device feature bits; if you change something,
+        * also update netdev_features_strings[] in ethtool.c */
+
 #define NETIF_F_SG             1       /* Scatter/gather IO. */
 #define NETIF_F_IP_CSUM                2       /* Can checksum TCP/UDP over IPv4. */
 #define NETIF_F_NO_CSUM                4       /* Does not require checksum. F.e. loopack. */
@@ -943,6 +1065,7 @@ struct net_device {
 #define NETIF_F_FCOE_MTU       (1 << 26) /* Supports max FCoE MTU, 2158 bytes*/
 #define NETIF_F_NTUPLE         (1 << 27) /* N-tuple filters supported */
 #define NETIF_F_RXHASH         (1 << 28) /* Receive hashing offload */
+#define NETIF_F_RXCSUM         (1 << 29) /* Receive checksumming offload */
 
        /* Segmentation offload features */
 #define NETIF_F_GSO_SHIFT      16
@@ -954,6 +1077,12 @@ struct net_device {
 #define NETIF_F_TSO6           (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT)
 #define NETIF_F_FSO            (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT)
 
+       /* Features valid for ethtool to change */
+       /* = all defined minus driver/device-class-related */
+#define NETIF_F_NEVER_CHANGE   (NETIF_F_HIGHDMA | NETIF_F_VLAN_CHALLENGED | \
+                                 NETIF_F_LLTX | NETIF_F_NETNS_LOCAL)
+#define NETIF_F_ETHTOOL_BITS   (0x3f3fffff & ~NETIF_F_NEVER_CHANGE)
+
        /* List of features with software fallbacks. */
 #define NETIF_F_GSO_SOFTWARE   (NETIF_F_TSO | NETIF_F_TSO_ECN | \
                                 NETIF_F_TSO6 | NETIF_F_UFO)
@@ -964,6 +1093,12 @@ struct net_device {
 #define NETIF_F_V6_CSUM                (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM)
 #define NETIF_F_ALL_CSUM       (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM)
 
+#define NETIF_F_ALL_TSO        (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
+
+#define NETIF_F_ALL_TX_OFFLOADS        (NETIF_F_ALL_CSUM | NETIF_F_SG | \
+                                NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \
+                                NETIF_F_SCTP_CSUM | NETIF_F_FCOE_CRC)
+
        /*
         * If one device supports one of these features, then enable them
         * for all in netdev_increment_features.
@@ -972,6 +1107,9 @@ struct net_device {
                                 NETIF_F_SG | NETIF_F_HIGHDMA |         \
                                 NETIF_F_FRAGLIST)
 
+       /* changeable features with no special hardware requirements */
+#define NETIF_F_SOFT_FEATURES  (NETIF_F_GSO | NETIF_F_GRO)
+
        /* Interface index. Unique device identifier    */
        int                     ifindex;
        int                     iflink;
@@ -1447,7 +1585,7 @@ static inline struct net_device *next_net_device_rcu(struct net_device *dev)
        struct net *net;
 
        net = dev_net(dev);
-       lh = rcu_dereference(dev->dev_list.next);
+       lh = rcu_dereference(list_next_rcu(&dev->dev_list));
        return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
 }
 
@@ -1457,6 +1595,13 @@ static inline struct net_device *first_net_device(struct net *net)
                net_device_entry(net->dev_base_head.next);
 }
 
+static inline struct net_device *first_net_device_rcu(struct net *net)
+{
+       struct list_head *lh = rcu_dereference(list_next_rcu(&net->dev_base_head));
+
+       return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
+}
+
 extern int                     netdev_boot_setup_check(struct net_device *dev);
 extern unsigned long           netdev_boot_base(const char *prefix, int unit);
 extern struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
@@ -1708,8 +1853,7 @@ static inline void netif_tx_wake_all_queues(struct net_device *dev)
 static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
 {
        if (WARN_ON(!dev_queue)) {
-               printk(KERN_INFO "netif_stop_queue() cannot be called before "
-                      "register_netdev()");
+               pr_info("netif_stop_queue() cannot be called before register_netdev()\n");
                return;
        }
        set_bit(__QUEUE_STATE_XOFF, &dev_queue->state);
@@ -2370,6 +2514,8 @@ extern int                netdev_max_backlog;
 extern int             netdev_tstamp_prequeue;
 extern int             weight_p;
 extern int             netdev_set_master(struct net_device *dev, struct net_device *master);
+extern int netdev_set_bond_master(struct net_device *dev,
+                                 struct net_device *master);
 extern int skb_checksum_help(struct sk_buff *skb);
 extern struct sk_buff *skb_gso_segment(struct sk_buff *skb, u32 features);
 #ifdef CONFIG_BUG
@@ -2398,8 +2544,13 @@ extern char *netdev_drivername(const struct net_device *dev, char *buffer, int l
 
 extern void linkwatch_run_queue(void);
 
+static inline u32 netdev_get_wanted_features(struct net_device *dev)
+{
+       return (dev->features & ~dev->hw_features) | dev->wanted_features;
+}
 u32 netdev_increment_features(u32 all, u32 one, u32 mask);
 u32 netdev_fix_features(struct net_device *dev, u32 features);
+void netdev_update_features(struct net_device *dev);
 
 void netif_stacked_transfer_operstate(const struct net_device *rootdev,
                                        struct net_device *dev);
@@ -2430,15 +2581,9 @@ static inline void netif_set_gso_max_size(struct net_device *dev,
        dev->gso_max_size = size;
 }
 
-extern int __skb_bond_should_drop(struct sk_buff *skb,
-                                 struct net_device *master);
-
-static inline int skb_bond_should_drop(struct sk_buff *skb,
-                                      struct net_device *master)
+static inline int netif_is_bond_slave(struct net_device *dev)
 {
-       if (master)
-               return __skb_bond_should_drop(skb, master);
-       return 0;
+       return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
 }
 
 extern struct pernet_operations __net_initdata loopback_net_ops;
@@ -2453,6 +2598,8 @@ static inline int dev_ethtool_get_settings(struct net_device *dev,
 
 static inline u32 dev_ethtool_get_rx_csum(struct net_device *dev)
 {
+       if (dev->hw_features & NETIF_F_RXCSUM)
+               return !!(dev->features & NETIF_F_RXCSUM);
        if (!dev->ethtool_ops || !dev->ethtool_ops->get_rx_csum)
                return 0;
        return dev->ethtool_ops->get_rx_csum(dev);
@@ -2494,6 +2641,9 @@ extern int netdev_notice(const struct net_device *dev, const char *format, ...)
 extern int netdev_info(const struct net_device *dev, const char *format, ...)
        __attribute__ ((format (printf, 2, 3)));
 
+#define MODULE_ALIAS_NETDEV(device) \
+       MODULE_ALIAS("netdev-" device)
+
 #if defined(DEBUG)
 #define netdev_dbg(__dev, format, args...)                     \
        netdev_printk(KERN_DEBUG, __dev, format, ##args)