Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / net / bonding / bonding.h
index f7b40ed..4581aa5 100644 (file)
 #include <linux/timer.h>
 #include <linux/proc_fs.h>
 #include <linux/if_bonding.h>
-#include <linux/kobject.h>
+#include <linux/cpumask.h>
+#include <linux/in6.h>
+#include <linux/netpoll.h>
+#include <linux/inetdevice.h>
 #include "bond_3ad.h"
 #include "bond_alb.h"
 
-#define DRV_VERSION    "3.3.0"
-#define DRV_RELDATE    "June 10, 2008"
+#define DRV_VERSION    "3.7.1"
+#define DRV_RELDATE    "April 27, 2011"
 #define DRV_NAME       "bonding"
 #define DRV_DESCRIPTION        "Ethernet Channel Bonding Driver"
 
-#define BOND_MAX_ARP_TARGETS   16
+#define bond_version DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n"
 
-#ifdef BONDING_DEBUG
-#define dprintk(fmt, args...) \
-       printk(KERN_DEBUG     \
-              DRV_NAME ": %s() %d: " fmt, __func__, __LINE__ , ## args )
-#else
-#define dprintk(fmt, args...)
-#endif /* BONDING_DEBUG */
+#define BOND_MAX_ARP_TARGETS   16
 
 #define IS_UP(dev)                                        \
              ((((dev)->flags & IFF_UP) == IFF_UP)      && \
               netif_carrier_ok(dev))
 
 /*
- * Checks whether bond is ready for transmit.
- *
- * Caller must hold bond->lock
- */
-#define BOND_IS_OK(bond)                            \
-                  (((bond)->dev->flags & IFF_UP) && \
-                   netif_running((bond)->dev)    && \
-                   ((bond)->slave_cnt > 0))
-
-/*
  * Checks whether slave is ready for transmit.
  */
 #define SLAVE_IS_OK(slave)                             \
                    (((slave)->dev->flags & IFF_UP)  && \
                     netif_running((slave)->dev)     && \
                     ((slave)->link == BOND_LINK_UP) && \
-                    ((slave)->state == BOND_STATE_ACTIVE))
+                    bond_is_active_slave(slave))
 
 
 #define USES_PRIMARY(mode)                             \
@@ -67,6 +54,9 @@
                 ((mode) == BOND_MODE_TLB)          ||  \
                 ((mode) == BOND_MODE_ALB))
 
+#define TX_QUEUE_OVERRIDE(mode)                                \
+                       (((mode) == BOND_MODE_ACTIVEBACKUP) ||  \
+                        ((mode) == BOND_MODE_ROUNDROBIN))
 /*
  * Less bad way to call ioctl from within the kernel; this needs to be
  * done some other way to get the call out of interrupt context.
                bond_for_each_slave_from(bond, pos, cnt, (bond)->first_slave)
 
 
+#ifdef CONFIG_NET_POLL_CONTROLLER
+extern atomic_t netpoll_block_tx;
+
+static inline void block_netpoll_tx(void)
+{
+       atomic_inc(&netpoll_block_tx);
+}
+
+static inline void unblock_netpoll_tx(void)
+{
+       atomic_dec(&netpoll_block_tx);
+}
+
+static inline int is_netpoll_tx_blocked(struct net_device *dev)
+{
+       if (unlikely(netpoll_tx_running(dev)))
+               return atomic_read(&netpoll_block_tx);
+       return 0;
+}
+#else
+#define block_netpoll_tx()
+#define unblock_netpoll_tx()
+#define is_netpoll_tx_blocked(dev) (0)
+#endif
+
 struct bond_params {
        int mode;
        int xmit_policy;
        int miimon;
-       int num_grat_arp;
+       u8 num_peer_notif;
        int arp_interval;
        int arp_validate;
        int use_carrier;
@@ -133,8 +148,14 @@ struct bond_params {
        int updelay;
        int downdelay;
        int lacp_fast;
+       unsigned int min_links;
+       int ad_select;
        char primary[IFNAMSIZ];
+       int primary_reselect;
        __be32 arp_targets[BOND_MAX_ARP_TARGETS];
+       int tx_queues;
+       int all_slaves_active;
+       int resend_igmp;
 };
 
 struct bond_parm_tbl {
@@ -146,7 +167,6 @@ struct bond_parm_tbl {
 
 struct vlan_entry {
        struct list_head vlan_list;
-       __be32 vlan_ip;
        unsigned short vlan_id;
 };
 
@@ -154,20 +174,26 @@ struct slave {
        struct net_device *dev; /* first - useful for panic debug */
        struct slave *next;
        struct slave *prev;
+       struct bonding *bond; /* our master */
        int    delay;
        unsigned long jiffies;
        unsigned long last_arp_rx;
        s8     link;    /* one of BOND_LINK_XXXX */
        s8     new_link;
-       s8     state;   /* one of BOND_STATE_XXXX */
-       u32    original_flags;
+       u8     backup:1,   /* indicates backup slave. Value corresponds with
+                             BOND_STATE_ACTIVE and BOND_STATE_BACKUP */
+              inactive:1; /* indicates inactive slave */
+       u8     duplex;
        u32    original_mtu;
        u32    link_failure_count;
-       u16    speed;
-       u8     duplex;
+       u32    speed;
+       u16    queue_id;
        u8     perm_hwaddr[ETH_ALEN];
        struct ad_slave_info ad_info; /* HUGE - better to dynamically alloc */
        struct tlb_slave_info tlb_info;
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       struct netpoll *np;
+#endif
 };
 
 /*
@@ -190,53 +216,65 @@ struct bonding {
        struct   slave *curr_active_slave;
        struct   slave *current_arp_slave;
        struct   slave *primary_slave;
+       bool     force_primary;
        s32      slave_cnt; /* never change this value outside the attach/detach wrappers */
+       int     (*recv_probe)(struct sk_buff *, struct bonding *,
+                              struct slave *);
        rwlock_t lock;
        rwlock_t curr_slave_lock;
-       s8       kill_timers;
-       s8       send_grat_arp;
+       u8       send_peer_notif;
        s8       setup_by_slave;
-       struct   net_device_stats stats;
+       s8       igmp_retrans;
 #ifdef CONFIG_PROC_FS
        struct   proc_dir_entry *proc_entry;
        char     proc_file_name[IFNAMSIZ];
 #endif /* CONFIG_PROC_FS */
        struct   list_head bond_list;
-       struct   dev_mc_list *mc_list;
-       int      (*xmit_hash_policy)(struct sk_buff *, struct net_device *, int);
-       __be32   master_ip;
-       u16      flags;
+       struct   netdev_hw_addr_list mc_list;
+       int      (*xmit_hash_policy)(struct sk_buff *, int);
        u16      rr_tx_counter;
        struct   ad_bond_info ad_info;
        struct   alb_bond_info alb_info;
        struct   bond_params params;
        struct   list_head vlan_list;
-       struct   vlan_group *vlgrp;
-       struct   packet_type arp_mon_pt;
        struct   workqueue_struct *wq;
        struct   delayed_work mii_work;
        struct   delayed_work arp_work;
        struct   delayed_work alb_work;
        struct   delayed_work ad_work;
+       struct   delayed_work mcast_work;
+#ifdef CONFIG_DEBUG_FS
+       /* debugging suport via debugfs */
+       struct   dentry *debug_dir;
+#endif /* CONFIG_DEBUG_FS */
 };
 
+static inline bool bond_vlan_used(struct bonding *bond)
+{
+       return !list_empty(&bond->vlan_list);
+}
+
+#define bond_slave_get_rcu(dev) \
+       ((struct slave *) rcu_dereference(dev->rx_handler_data))
+
 /**
  * Returns NULL if the net_device does not belong to any of the bond's slaves
  *
  * Caller must hold bond lock for read
  */
-static inline struct slave *bond_get_slave_by_dev(struct bonding *bond, struct net_device *slave_dev)
+static inline struct slave *bond_get_slave_by_dev(struct bonding *bond,
+                                                 struct net_device *slave_dev)
 {
        struct slave *slave = NULL;
        int i;
 
        bond_for_each_slave(bond, slave, i) {
                if (slave->dev == slave_dev) {
-                       break;
+                       return slave;
                }
        }
 
-       return slave;
+       return NULL;
 }
 
 static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
@@ -245,9 +283,39 @@ static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
                return NULL;
        }
 
-       return (struct bonding *)slave->dev->master->priv;
+       return netdev_priv(slave->dev->master);
+}
+
+static inline bool bond_is_lb(const struct bonding *bond)
+{
+       return (bond->params.mode == BOND_MODE_TLB ||
+               bond->params.mode == BOND_MODE_ALB);
+}
+
+static inline void bond_set_active_slave(struct slave *slave)
+{
+       slave->backup = 0;
+}
+
+static inline void bond_set_backup_slave(struct slave *slave)
+{
+       slave->backup = 1;
+}
+
+static inline int bond_slave_state(struct slave *slave)
+{
+       return slave->backup;
 }
 
+static inline bool bond_is_active_slave(struct slave *slave)
+{
+       return !bond_slave_state(slave);
+}
+
+#define BOND_PRI_RESELECT_ALWAYS       0
+#define BOND_PRI_RESELECT_BETTER       1
+#define BOND_PRI_RESELECT_FAILURE      2
+
 #define BOND_FOM_NONE                  0
 #define BOND_FOM_ACTIVE                        1
 #define BOND_FOM_FOLLOW                        2
@@ -261,7 +329,7 @@ static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
 static inline int slave_do_arp_validate(struct bonding *bond,
                                        struct slave *slave)
 {
-       return bond->params.arp_validate & (1 << slave->state);
+       return bond->params.arp_validate & (1 << bond_slave_state(slave));
 }
 
 static inline unsigned long slave_last_rx(struct bonding *bond,
@@ -273,52 +341,65 @@ static inline unsigned long slave_last_rx(struct bonding *bond,
        return slave->dev->last_rx;
 }
 
-static inline void bond_set_slave_inactive_flags(struct slave *slave)
+#ifdef CONFIG_NET_POLL_CONTROLLER
+static inline void bond_netpoll_send_skb(const struct slave *slave,
+                                        struct sk_buff *skb)
 {
-       struct bonding *bond = slave->dev->master->priv;
-       if (bond->params.mode != BOND_MODE_TLB &&
-           bond->params.mode != BOND_MODE_ALB)
-               slave->state = BOND_STATE_BACKUP;
-       slave->dev->priv_flags |= IFF_SLAVE_INACTIVE;
-       if (slave_do_arp_validate(bond, slave))
-               slave->dev->priv_flags |= IFF_SLAVE_NEEDARP;
-}
+       struct netpoll *np = slave->np;
 
-static inline void bond_set_slave_active_flags(struct slave *slave)
+       if (np)
+               netpoll_send_skb(np, skb);
+}
+#else
+static inline void bond_netpoll_send_skb(const struct slave *slave,
+                                        struct sk_buff *skb)
 {
-       slave->state = BOND_STATE_ACTIVE;
-       slave->dev->priv_flags &= ~(IFF_SLAVE_INACTIVE | IFF_SLAVE_NEEDARP);
 }
+#endif
 
-static inline void bond_set_master_3ad_flags(struct bonding *bond)
+static inline void bond_set_slave_inactive_flags(struct slave *slave)
 {
-       bond->dev->priv_flags |= IFF_MASTER_8023AD;
+       struct bonding *bond = netdev_priv(slave->dev->master);
+       if (!bond_is_lb(bond))
+               bond_set_backup_slave(slave);
+       if (!bond->params.all_slaves_active)
+               slave->inactive = 1;
 }
 
-static inline void bond_unset_master_3ad_flags(struct bonding *bond)
+static inline void bond_set_slave_active_flags(struct slave *slave)
 {
-       bond->dev->priv_flags &= ~IFF_MASTER_8023AD;
+       bond_set_active_slave(slave);
+       slave->inactive = 0;
 }
 
-static inline void bond_set_master_alb_flags(struct bonding *bond)
+static inline bool bond_is_slave_inactive(struct slave *slave)
 {
-       bond->dev->priv_flags |= IFF_MASTER_ALB;
+       return slave->inactive;
 }
 
-static inline void bond_unset_master_alb_flags(struct bonding *bond)
+static inline __be32 bond_confirm_addr(struct net_device *dev, __be32 dst, __be32 local)
 {
-       bond->dev->priv_flags &= ~IFF_MASTER_ALB;
+       struct in_device *in_dev;
+       __be32 addr = 0;
+
+       rcu_read_lock();
+       in_dev = __in_dev_get_rcu(dev);
+
+       if (in_dev)
+               addr = inet_confirm_addr(in_dev, dst, local, RT_SCOPE_HOST);
+
+       rcu_read_unlock();
+       return addr;
 }
 
+struct bond_net;
+
 struct vlan_entry *bond_next_vlan(struct bonding *bond, struct vlan_entry *curr);
 int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
-int bond_create(char *name, struct bond_params *params);
-void bond_destroy(struct bonding *bond);
-int  bond_release_and_destroy(struct net_device *bond_dev, struct net_device *slave_dev);
-int bond_create_sysfs(void);
-void bond_destroy_sysfs(void);
-void bond_destroy_sysfs_entry(struct bonding *bond);
-int bond_create_sysfs_entry(struct bonding *bond);
+int bond_create(struct net *net, const char *name);
+int bond_create_sysfs(struct bond_net *net);
+void bond_destroy_sysfs(struct bond_net *net);
+void bond_prepare_sysfs_group(struct bonding *bond);
 int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave);
 void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave);
 int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev);
@@ -327,11 +408,57 @@ void bond_mii_monitor(struct work_struct *);
 void bond_loadbalance_arp_mon(struct work_struct *);
 void bond_activebackup_arp_mon(struct work_struct *);
 void bond_set_mode_ops(struct bonding *bond, int mode);
-int bond_parse_parm(const char *mode_arg, struct bond_parm_tbl *tbl);
+int bond_parse_parm(const char *mode_arg, const struct bond_parm_tbl *tbl);
 void bond_select_active_slave(struct bonding *bond);
 void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
-void bond_register_arp(struct bonding *);
-void bond_unregister_arp(struct bonding *);
+void bond_create_debugfs(void);
+void bond_destroy_debugfs(void);
+void bond_debug_register(struct bonding *bond);
+void bond_debug_unregister(struct bonding *bond);
+void bond_debug_reregister(struct bonding *bond);
+const char *bond_mode_name(int mode);
+
+struct bond_net {
+       struct net *            net;    /* Associated network namespace */
+       struct list_head        dev_list;
+#ifdef CONFIG_PROC_FS
+       struct proc_dir_entry * proc_dir;
+#endif
+       struct class_attribute  class_attr_bonding_masters;
+};
 
-#endif /* _LINUX_BONDING_H */
+#ifdef CONFIG_PROC_FS
+void bond_create_proc_entry(struct bonding *bond);
+void bond_remove_proc_entry(struct bonding *bond);
+void bond_create_proc_dir(struct bond_net *bn);
+void bond_destroy_proc_dir(struct bond_net *bn);
+#else
+static inline void bond_create_proc_entry(struct bonding *bond)
+{
+}
+
+static inline void bond_remove_proc_entry(struct bonding *bond)
+{
+}
 
+static inline void bond_create_proc_dir(struct bond_net *bn)
+{
+}
+
+static inline void bond_destroy_proc_dir(struct bond_net *bn)
+{
+}
+#endif
+
+
+/* exported from bond_main.c */
+extern int bond_net_id;
+extern const struct bond_parm_tbl bond_lacp_tbl[];
+extern const struct bond_parm_tbl bond_mode_tbl[];
+extern const struct bond_parm_tbl xmit_hashtype_tbl[];
+extern const struct bond_parm_tbl arp_validate_tbl[];
+extern const struct bond_parm_tbl fail_over_mac_tbl[];
+extern const struct bond_parm_tbl pri_reselect_tbl[];
+extern struct bond_parm_tbl ad_select_tbl[];
+
+#endif /* _LINUX_BONDING_H */