net: allocate tx queues in register_netdevice
[pandora-kernel.git] / include / linux / netdevice.h
index b21e405..880d565 100644 (file)
@@ -54,6 +54,7 @@
 
 struct vlan_group;
 struct netpoll_info;
+struct phy_device;
 /* 802.11 specific */
 struct wireless_dev;
                                        /* source back-compat hooks */
@@ -65,6 +66,11 @@ struct wireless_dev;
 #define HAVE_FREE_NETDEV               /* free_netdev() */
 #define HAVE_NETDEV_PRIV               /* netdev_priv() */
 
+/* hardware address assignment types */
+#define NET_ADDR_PERM          0       /* address is permanent (default) */
+#define NET_ADDR_RANDOM                1       /* address is generated randomly */
+#define NET_ADDR_STOLEN                2       /* address is stolen from other device */
+
 /* Backlog congestion levels */
 #define NET_RX_SUCCESS         0       /* keep 'em coming, baby */
 #define NET_RX_DROP            1       /* packet dropped */
@@ -159,45 +165,39 @@ static inline bool dev_xmit_complete(int rc)
 #define MAX_HEADER (LL_MAX_HEADER + 48)
 #endif
 
-#endif  /*  __KERNEL__  */
-
 /*
- *     Network device statistics. Akin to the 2.0 ether stats but
- *     with byte counters.
+ *     Old network device statistics. Fields are native words
+ *     (unsigned long) so they can be read and written atomically.
  */
 
 struct net_device_stats {
-       unsigned long   rx_packets;             /* total packets received       */
-       unsigned long   tx_packets;             /* total packets transmitted    */
-       unsigned long   rx_bytes;               /* total bytes received         */
-       unsigned long   tx_bytes;               /* total bytes transmitted      */
-       unsigned long   rx_errors;              /* bad packets received         */
-       unsigned long   tx_errors;              /* packet transmit problems     */
-       unsigned long   rx_dropped;             /* no space in linux buffers    */
-       unsigned long   tx_dropped;             /* no space available in linux  */
-       unsigned long   multicast;              /* multicast packets received   */
+       unsigned long   rx_packets;
+       unsigned long   tx_packets;
+       unsigned long   rx_bytes;
+       unsigned long   tx_bytes;
+       unsigned long   rx_errors;
+       unsigned long   tx_errors;
+       unsigned long   rx_dropped;
+       unsigned long   tx_dropped;
+       unsigned long   multicast;
        unsigned long   collisions;
-
-       /* detailed rx_errors: */
        unsigned long   rx_length_errors;
-       unsigned long   rx_over_errors;         /* receiver ring buff overflow  */
-       unsigned long   rx_crc_errors;          /* recved pkt with crc error    */
-       unsigned long   rx_frame_errors;        /* recv'd frame alignment error */
-       unsigned long   rx_fifo_errors;         /* recv'r fifo overrun          */
-       unsigned long   rx_missed_errors;       /* receiver missed packet       */
-
-       /* detailed tx_errors */
+       unsigned long   rx_over_errors;
+       unsigned long   rx_crc_errors;
+       unsigned long   rx_frame_errors;
+       unsigned long   rx_fifo_errors;
+       unsigned long   rx_missed_errors;
        unsigned long   tx_aborted_errors;
        unsigned long   tx_carrier_errors;
        unsigned long   tx_fifo_errors;
        unsigned long   tx_heartbeat_errors;
        unsigned long   tx_window_errors;
-       
-       /* for cslip etc */
        unsigned long   rx_compressed;
        unsigned long   tx_compressed;
 };
 
+#endif  /*  __KERNEL__  */
+
 
 /* Media selection options. */
 enum {
@@ -228,9 +228,9 @@ struct netdev_hw_addr {
 #define NETDEV_HW_ADDR_T_SLAVE         3
 #define NETDEV_HW_ADDR_T_UNICAST       4
 #define NETDEV_HW_ADDR_T_MULTICAST     5
-       int                     refcount;
        bool                    synced;
        bool                    global_use;
+       int                     refcount;
        struct rcu_head         rcu_head;
 };
 
@@ -281,6 +281,12 @@ struct hh_cache {
        unsigned long   hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
 };
 
+static inline void hh_cache_put(struct hh_cache *hh)
+{
+       if (atomic_dec_and_test(&hh->hh_refcnt))
+               kfree(hh);
+}
+
 /* Reserve HH_DATA_MOD byte aligned hard_header_len, but at least that much.
  * Alternative is:
  *   dev->hard_header_len ? (dev->hard_header_len +
@@ -381,6 +387,8 @@ enum gro_result {
 };
 typedef enum gro_result gro_result_t;
 
+typedef struct sk_buff *rx_handler_func_t(struct sk_buff *skb);
+
 extern void __napi_schedule(struct napi_struct *n);
 
 static inline int napi_disable_pending(struct napi_struct *n)
@@ -504,9 +512,9 @@ struct netdev_queue {
         * please use this field instead of dev->trans_start
         */
        unsigned long           trans_start;
-       unsigned long           tx_bytes;
-       unsigned long           tx_packets;
-       unsigned long           tx_dropped;
+       u64                     tx_bytes;
+       u64                     tx_packets;
+       u64                     tx_dropped;
 } ____cacheline_aligned_in_smp;
 
 #ifdef CONFIG_RPS
@@ -660,10 +668,19 @@ struct netdev_rx_queue {
  *     Callback uses when the transmitter has not made any progress
  *     for dev->watchdog ticks.
  *
+ * struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
+ *                      struct rtnl_link_stats64 *storage);
  * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
  *     Called when a user wants to get the network device usage
- *     statistics. If not defined, the counters in dev->stats will
- *     be used.
+ *     statistics. Drivers must do one of the following:
+ *     1. Define @ndo_get_stats64 to fill in a zero-initialised
+ *        rtnl_link_stats64 structure passed by the caller.
+ *     2. Define @ndo_get_stats to update a net_device_stats structure
+ *        (which should normally be dev->stats) and return a pointer to
+ *        it. The structure may be changed asynchronously only if each
+ *        field is written atomically.
+ *     3. Update dev->stats asynchronously and atomically, and define
+ *        neither operation.
  *
  * void (*ndo_vlan_rx_register)(struct net_device *dev, struct vlan_group *grp);
  *     If device support VLAN receive accleration
@@ -718,6 +735,8 @@ struct net_device_ops {
                                                   struct neigh_parms *);
        void                    (*ndo_tx_timeout) (struct net_device *dev);
 
+       struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
+                                                    struct rtnl_link_stats64 *storage);
        struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
 
        void                    (*ndo_vlan_rx_register)(struct net_device *dev,
@@ -728,6 +747,8 @@ struct net_device_ops {
                                                        unsigned short vid);
 #ifdef CONFIG_NET_POLL_CONTROLLER
        void                    (*ndo_poll_controller)(struct net_device *dev);
+       int                     (*ndo_netpoll_setup)(struct net_device *dev,
+                                                    struct netpoll_info *info);
        void                    (*ndo_netpoll_cleanup)(struct net_device *dev);
 #endif
        int                     (*ndo_set_vf_mac)(struct net_device *dev,
@@ -775,11 +796,11 @@ struct net_device {
        /*
         * This is the first field of the "visible" part of this structure
         * (i.e. as seen by users in the "Space.c" file).  It is the name
-        * the interface.
+        * of the interface.
         */
        char                    name[IFNAMSIZ];
 
-       struct pm_qos_request_list *pm_qos_req;
+       struct pm_qos_request_list pm_qos_req;
 
        /* device name hash chain */
        struct hlist_node       name_hlist;
@@ -847,7 +868,8 @@ struct net_device {
 #define NETIF_F_FSO            (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT)
 
        /* List of features with software fallbacks. */
-#define NETIF_F_GSO_SOFTWARE   (NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6)
+#define NETIF_F_GSO_SOFTWARE   (NETIF_F_TSO | NETIF_F_TSO_ECN | \
+                                NETIF_F_TSO6 | NETIF_F_UFO)
 
 
 #define NETIF_F_GEN_CSUM       (NETIF_F_NO_CSUM | NETIF_F_HW_CSUM)
@@ -868,6 +890,9 @@ struct net_device {
        int                     iflink;
 
        struct net_device_stats stats;
+       atomic_long_t           rx_dropped; /* dropped packets by core network
+                                            * Do not use this in drivers.
+                                            */
 
 #ifdef CONFIG_WIRELESS_EXT
        /* List of functions to handle Wireless Extensions (instead of ioctl).
@@ -885,7 +910,7 @@ struct net_device {
 
        unsigned int            flags;  /* interface flags (a la BSD)   */
        unsigned short          gflags;
-        unsigned short          priv_flags; /* Like 'flags' but invisible to userspace. */
+        unsigned int            priv_flags; /* Like 'flags' but invisible to userspace. */
        unsigned short          padded; /* How much padding added by alloc_netdev() */
 
        unsigned char           operstate; /* RFC2863 operstate */
@@ -902,12 +927,9 @@ struct net_device {
        unsigned short          needed_headroom;
        unsigned short          needed_tailroom;
 
-       struct net_device       *master; /* Pointer to master device of a group,
-                                         * which this device is member of.
-                                         */
-
        /* Interface address info. */
        unsigned char           perm_addr[MAX_ADDR_LEN]; /* permanent hw address */
+       unsigned char           addr_assign_type; /* hw address assignment type */
        unsigned char           addr_len;       /* hardware address length      */
        unsigned short          dev_id;         /* for shared network cards */
 
@@ -925,7 +947,7 @@ struct net_device {
        void                    *dsa_ptr;       /* dsa specific data */
 #endif
        void                    *atalk_ptr;     /* AppleTalk link       */
-       void                    *ip_ptr;        /* IPv4 specific data   */
+       struct in_device __rcu  *ip_ptr;        /* IPv4 specific data   */
        void                    *dn_ptr;        /* DECnet specific data */
        void                    *ip6_ptr;       /* IPv6 specific data */
        void                    *ec_ptr;        /* Econet specific data */
@@ -934,9 +956,20 @@ struct net_device {
                                                   assign before registering */
 
 /*
- * Cache line mostly used on receive path (including eth_type_trans())
+ * Cache lines mostly used on receive path (including eth_type_trans())
  */
-       unsigned long           last_rx;        /* Time of last Rx      */
+       unsigned long           last_rx;        /* Time of last Rx
+                                                * This should not be set in
+                                                * drivers, unless really needed,
+                                                * because network stack (bonding)
+                                                * use it if/when necessary, to
+                                                * avoid dirtying this cache line.
+                                                */
+
+       struct net_device       *master; /* Pointer to master device of a group,
+                                         * which this device is member of.
+                                         */
+
        /* Interface address info used in eth_type_trans() */
        unsigned char           *dev_addr;      /* hw address, (before bcast
                                                   because most packets are
@@ -952,12 +985,21 @@ struct net_device {
 
        struct netdev_rx_queue  *_rx;
 
-       /* Number of RX queues allocated at alloc_netdev_mq() time  */
+       /* Number of RX queues allocated at register_netdev() time */
        unsigned int            num_rx_queues;
+
+       /* Number of RX queues currently active in device */
+       unsigned int            real_num_rx_queues;
 #endif
 
-       struct netdev_queue     rx_queue;
+       rx_handler_func_t       *rx_handler;
+       void                    *rx_handler_data;
+
+       struct netdev_queue __rcu *ingress_queue;
 
+/*
+ * Cache lines mostly used on transmit path
+ */
        struct netdev_queue     *_tx ____cacheline_aligned_in_smp;
 
        /* Number of TX queues allocated at alloc_netdev_mq() time  */
@@ -971,9 +1013,7 @@ struct net_device {
 
        unsigned long           tx_queue_len;   /* Max frames per queue allowed */
        spinlock_t              tx_global_lock;
-/*
- * One part is mostly used on xmit path (device)
- */
+
        /* These may be needed for future network-power-down code. */
 
        /*
@@ -986,7 +1026,7 @@ struct net_device {
        struct timer_list       watchdog_timer;
 
        /* Number of references to this device */
-       atomic_t                refcnt ____cacheline_aligned_in_smp;
+       int __percpu            *pcpu_refcnt;
 
        /* delayed register/unregister */
        struct list_head        todo_list;
@@ -1022,12 +1062,12 @@ struct net_device {
 #endif
 
        /* mid-layer private */
-       void                    *ml_priv;
-
-       /* bridge stuff */
-       struct net_bridge_port  *br_port;
-       /* macvlan */
-       struct macvlan_port     *macvlan_port;
+       union {
+               void                            *ml_priv;
+               struct pcpu_lstats __percpu     *lstats; /* loopback stats */
+               struct pcpu_tstats __percpu     *tstats; /* tunnel stats */
+               struct pcpu_dstats __percpu     *dstats; /* dummy stats */
+       };
        /* GARP */
        struct garp_port        *garp_port;
 
@@ -1057,6 +1097,9 @@ struct net_device {
 #endif
        /* n-tuple filter list attached to this device */
        struct ethtool_rx_ntuple_list ethtool_ntuple_list;
+
+       /* phy device may attach itself for hardware timestamping */
+       struct phy_device *phydev;
 };
 #define to_net_dev(d) container_of(d, struct net_device, dev)
 
@@ -1087,11 +1130,7 @@ static inline void netdev_for_each_tx_queue(struct net_device *dev,
 static inline
 struct net *dev_net(const struct net_device *dev)
 {
-#ifdef CONFIG_NET_NS
-       return dev->nd_net;
-#else
-       return &init_net;
-#endif
+       return read_pnet(&dev->nd_net);
 }
 
 static inline
@@ -1272,8 +1311,8 @@ extern void               dev_add_pack(struct packet_type *pt);
 extern void            dev_remove_pack(struct packet_type *pt);
 extern void            __dev_remove_pack(struct packet_type *pt);
 
-extern struct net_device       *dev_get_by_flags(struct net *net, unsigned short flags,
-                                                 unsigned short mask);
+extern struct net_device       *dev_get_by_flags_rcu(struct net *net, unsigned short flags,
+                                                     unsigned short mask);
 extern struct net_device       *dev_get_by_name(struct net *net, const char *name);
 extern struct net_device       *dev_get_by_name_rcu(struct net *net, const char *name);
 extern struct net_device       *__dev_get_by_name(struct net *net, const char *name);
@@ -1291,6 +1330,7 @@ static inline void unregister_netdevice(struct net_device *dev)
        unregister_netdevice_queue(dev, NULL);
 }
 
+extern int             netdev_refcnt_read(const struct net_device *dev);
 extern void            free_netdev(struct net_device *dev);
 extern void            synchronize_net(void);
 extern int             register_netdevice_notifier(struct notifier_block *nb);
@@ -1653,11 +1693,34 @@ static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
  */
 static inline int netif_is_multiqueue(const struct net_device *dev)
 {
-       return (dev->num_tx_queues > 1);
+       return dev->num_tx_queues > 1;
+}
+
+extern int netif_set_real_num_tx_queues(struct net_device *dev,
+                                       unsigned int txq);
+
+#ifdef CONFIG_RPS
+extern int netif_set_real_num_rx_queues(struct net_device *dev,
+                                       unsigned int rxq);
+#else
+static inline int netif_set_real_num_rx_queues(struct net_device *dev,
+                                               unsigned int rxq)
+{
+       return 0;
 }
+#endif
 
-extern void netif_set_real_num_tx_queues(struct net_device *dev,
-                                        unsigned int txq);
+static inline int netif_copy_real_num_queues(struct net_device *to_dev,
+                                            const struct net_device *from_dev)
+{
+       netif_set_real_num_tx_queues(to_dev, from_dev->real_num_tx_queues);
+#ifdef CONFIG_RPS
+       return netif_set_real_num_rx_queues(to_dev,
+                                           from_dev->real_num_rx_queues);
+#else
+       return 0;
+#endif
+}
 
 /* Use this variant when it is known for sure that it
  * is executing from hardware interrupt context or with hardware interrupts
@@ -1681,6 +1744,7 @@ extern gro_result_t       dev_gro_receive(struct napi_struct *napi,
 extern gro_result_t    napi_skb_finish(gro_result_t ret, struct sk_buff *skb);
 extern gro_result_t    napi_gro_receive(struct napi_struct *napi,
                                         struct sk_buff *skb);
+extern void            napi_gro_flush(struct napi_struct *napi);
 extern void            napi_reuse_skb(struct napi_struct *napi,
                                       struct sk_buff *skb);
 extern struct sk_buff *        napi_get_frags(struct napi_struct *napi);
@@ -1696,6 +1760,11 @@ static inline void napi_free_frags(struct napi_struct *napi)
        napi->skb = NULL;
 }
 
+extern int netdev_rx_handler_register(struct net_device *dev,
+                                     rx_handler_func_t *rx_handler,
+                                     void *rx_handler_data);
+extern void netdev_rx_handler_unregister(struct net_device *dev);
+
 extern void            netif_nit_deliver(struct sk_buff *skb);
 extern int             dev_valid_name(const char *name);
 extern int             dev_ioctl(struct net *net, unsigned int cmd, void __user *);
@@ -1730,7 +1799,7 @@ extern void netdev_run_todo(void);
  */
 static inline void dev_put(struct net_device *dev)
 {
-       atomic_dec(&dev->refcnt);
+       irqsafe_cpu_dec(*dev->pcpu_refcnt);
 }
 
 /**
@@ -1741,7 +1810,7 @@ static inline void dev_put(struct net_device *dev)
  */
 static inline void dev_hold(struct net_device *dev)
 {
-       atomic_inc(&dev->refcnt);
+       irqsafe_cpu_inc(*dev->pcpu_refcnt);
 }
 
 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
@@ -1775,6 +1844,8 @@ extern void netif_carrier_on(struct net_device *dev);
 
 extern void netif_carrier_off(struct net_device *dev);
 
+extern void netif_notify_peers(struct net_device *dev);
+
 /**
  *     netif_dormant_on - mark device as dormant.
  *     @dev: network device
@@ -2119,8 +2190,10 @@ extern void              netdev_features_change(struct net_device *dev);
 /* Load a device via the kmod */
 extern void            dev_load(struct net *net, const char *name);
 extern void            dev_mcast_init(void);
-extern const struct net_device_stats *dev_get_stats(struct net_device *dev);
-extern void            dev_txq_stats_fold(const struct net_device *dev, struct net_device_stats *stats);
+extern struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
+                                              struct rtnl_link_stats64 *storage);
+extern void            dev_txq_stats_fold(const struct net_device *dev,
+                                          struct rtnl_link_stats64 *stats);
 
 extern int             netdev_max_backlog;
 extern int             netdev_tstamp_prequeue;
@@ -2148,6 +2221,8 @@ extern void dev_seq_stop(struct seq_file *seq, void *v);
 extern int netdev_class_create_file(struct class_attribute *class_attr);
 extern void netdev_class_remove_file(struct class_attribute *class_attr);
 
+extern struct kobj_ns_type_operations net_ns_type_operations;
+
 extern char *netdev_drivername(const struct net_device *dev, char *buffer, int len);
 
 extern void linkwatch_run_queue(void);
@@ -2168,7 +2243,7 @@ static inline int net_gso_ok(int features, int gso_type)
 static inline int skb_gso_ok(struct sk_buff *skb, int features)
 {
        return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
-              (!skb_has_frags(skb) || (features & NETIF_F_FRAGLIST));
+              (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
 }
 
 static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb)
@@ -2230,25 +2305,23 @@ static inline const char *netdev_name(const struct net_device *dev)
        return dev->name;
 }
 
-#define netdev_printk(level, netdev, format, args...)          \
-       dev_printk(level, (netdev)->dev.parent,                 \
-                  "%s: " format,                               \
-                  netdev_name(netdev), ##args)
-
-#define netdev_emerg(dev, format, args...)                     \
-       netdev_printk(KERN_EMERG, dev, format, ##args)
-#define netdev_alert(dev, format, args...)                     \
-       netdev_printk(KERN_ALERT, dev, format, ##args)
-#define netdev_crit(dev, format, args...)                      \
-       netdev_printk(KERN_CRIT, dev, format, ##args)
-#define netdev_err(dev, format, args...)                       \
-       netdev_printk(KERN_ERR, dev, format, ##args)
-#define netdev_warn(dev, format, args...)                      \
-       netdev_printk(KERN_WARNING, dev, format, ##args)
-#define netdev_notice(dev, format, args...)                    \
-       netdev_printk(KERN_NOTICE, dev, format, ##args)
-#define netdev_info(dev, format, args...)                      \
-       netdev_printk(KERN_INFO, dev, format, ##args)
+extern int netdev_printk(const char *level, const struct net_device *dev,
+                        const char *format, ...)
+       __attribute__ ((format (printf, 3, 4)));
+extern int netdev_emerg(const struct net_device *dev, const char *format, ...)
+       __attribute__ ((format (printf, 2, 3)));
+extern int netdev_alert(const struct net_device *dev, const char *format, ...)
+       __attribute__ ((format (printf, 2, 3)));
+extern int netdev_crit(const struct net_device *dev, const char *format, ...)
+       __attribute__ ((format (printf, 2, 3)));
+extern int netdev_err(const struct net_device *dev, const char *format, ...)
+       __attribute__ ((format (printf, 2, 3)));
+extern int netdev_warn(const struct net_device *dev, const char *format, ...)
+       __attribute__ ((format (printf, 2, 3)));
+extern int netdev_notice(const struct net_device *dev, const char *format, ...)
+       __attribute__ ((format (printf, 2, 3)));
+extern int netdev_info(const struct net_device *dev, const char *format, ...)
+       __attribute__ ((format (printf, 2, 3)));
 
 #if defined(DEBUG)
 #define netdev_dbg(__dev, format, args...)                     \
@@ -2296,20 +2369,26 @@ do {                                                            \
                netdev_printk(level, (dev), fmt, ##args);       \
 } while (0)
 
+#define netif_level(level, priv, type, dev, fmt, args...)      \
+do {                                                           \
+       if (netif_msg_##type(priv))                             \
+               netdev_##level(dev, fmt, ##args);               \
+} while (0)
+
 #define netif_emerg(priv, type, dev, fmt, args...)             \
-       netif_printk(priv, type, KERN_EMERG, dev, fmt, ##args)
+       netif_level(emerg, priv, type, dev, fmt, ##args)
 #define netif_alert(priv, type, dev, fmt, args...)             \
-       netif_printk(priv, type, KERN_ALERT, dev, fmt, ##args)
+       netif_level(alert, priv, type, dev, fmt, ##args)
 #define netif_crit(priv, type, dev, fmt, args...)              \
-       netif_printk(priv, type, KERN_CRIT, dev, fmt, ##args)
+       netif_level(crit, priv, type, dev, fmt, ##args)
 #define netif_err(priv, type, dev, fmt, args...)               \
-       netif_printk(priv, type, KERN_ERR, dev, fmt, ##args)
+       netif_level(err, priv, type, dev, fmt, ##args)
 #define netif_warn(priv, type, dev, fmt, args...)              \
-       netif_printk(priv, type, KERN_WARNING, dev, fmt, ##args)
+       netif_level(warn, priv, type, dev, fmt, ##args)
 #define netif_notice(priv, type, dev, fmt, args...)            \
-       netif_printk(priv, type, KERN_NOTICE, dev, fmt, ##args)
+       netif_level(notice, priv, type, dev, fmt, ##args)
 #define netif_info(priv, type, dev, fmt, args...)              \
-       netif_printk(priv, type, KERN_INFO, (dev), fmt, ##args)
+       netif_level(info, priv, type, dev, fmt, ##args)
 
 #if defined(DEBUG)
 #define netif_dbg(priv, type, dev, format, args...)            \