Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / drivers / net / bonding / bond_alb.c
index 3b7b040..2e1f806 100644 (file)
@@ -99,16 +99,26 @@ static inline u8 _simple_hash(const u8 *hash_start, int hash_size)
 
 /*********************** tlb specific functions ***************************/
 
-static inline void _lock_tx_hashtbl(struct bonding *bond)
+static inline void _lock_tx_hashtbl_bh(struct bonding *bond)
 {
        spin_lock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
 }
 
-static inline void _unlock_tx_hashtbl(struct bonding *bond)
+static inline void _unlock_tx_hashtbl_bh(struct bonding *bond)
 {
        spin_unlock_bh(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
 }
 
+static inline void _lock_tx_hashtbl(struct bonding *bond)
+{
+       spin_lock(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
+}
+
+static inline void _unlock_tx_hashtbl(struct bonding *bond)
+{
+       spin_unlock(&(BOND_ALB_INFO(bond).tx_hashtbl_lock));
+}
+
 /* Caller must hold tx_hashtbl lock */
 static inline void tlb_init_table_entry(struct tlb_client_info *entry, int save_load)
 {
@@ -129,14 +139,13 @@ static inline void tlb_init_slave(struct slave *slave)
        SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX;
 }
 
-/* Caller must hold bond lock for read */
-static void tlb_clear_slave(struct bonding *bond, struct slave *slave, int save_load)
+/* Caller must hold bond lock for read, BH disabled */
+static void __tlb_clear_slave(struct bonding *bond, struct slave *slave,
+                        int save_load)
 {
        struct tlb_client_info *tx_hash_table;
        u32 index;
 
-       _lock_tx_hashtbl(bond);
-
        /* clear slave from tx_hashtbl */
        tx_hash_table = BOND_ALB_INFO(bond).tx_hashtbl;
 
@@ -151,8 +160,15 @@ static void tlb_clear_slave(struct bonding *bond, struct slave *slave, int save_
        }
 
        tlb_init_slave(slave);
+}
 
-       _unlock_tx_hashtbl(bond);
+/* Caller must hold bond lock for read */
+static void tlb_clear_slave(struct bonding *bond, struct slave *slave,
+                        int save_load)
+{
+       _lock_tx_hashtbl_bh(bond);
+       __tlb_clear_slave(bond, slave, save_load);
+       _unlock_tx_hashtbl_bh(bond);
 }
 
 /* Must be called before starting the monitor timer */
@@ -163,15 +179,11 @@ static int tlb_initialize(struct bonding *bond)
        struct tlb_client_info *new_hashtbl;
        int i;
 
-       spin_lock_init(&(bond_info->tx_hashtbl_lock));
-
        new_hashtbl = kzalloc(size, GFP_KERNEL);
-       if (!new_hashtbl) {
-               pr_err("%s: Error: Failed to allocate TLB hash table\n",
-                      bond->dev->name);
+       if (!new_hashtbl)
                return -1;
-       }
-       _lock_tx_hashtbl(bond);
+
+       _lock_tx_hashtbl_bh(bond);
 
        bond_info->tx_hashtbl = new_hashtbl;
 
@@ -179,7 +191,7 @@ static int tlb_initialize(struct bonding *bond)
                tlb_init_table_entry(&bond_info->tx_hashtbl[i], 0);
        }
 
-       _unlock_tx_hashtbl(bond);
+       _unlock_tx_hashtbl_bh(bond);
 
        return 0;
 }
@@ -189,12 +201,12 @@ static void tlb_deinitialize(struct bonding *bond)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
 
-       _lock_tx_hashtbl(bond);
+       _lock_tx_hashtbl_bh(bond);
 
        kfree(bond_info->tx_hashtbl);
        bond_info->tx_hashtbl = NULL;
 
-       _unlock_tx_hashtbl(bond);
+       _unlock_tx_hashtbl_bh(bond);
 }
 
 static long long compute_gap(struct slave *slave)
@@ -228,15 +240,13 @@ static struct slave *tlb_get_least_loaded_slave(struct bonding *bond)
        return least_loaded;
 }
 
-/* Caller must hold bond lock for read */
-static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, u32 skb_len)
+static struct slave *__tlb_choose_channel(struct bonding *bond, u32 hash_index,
+                                               u32 skb_len)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
        struct tlb_client_info *hash_table;
        struct slave *assigned_slave;
 
-       _lock_tx_hashtbl(bond);
-
        hash_table = bond_info->tx_hashtbl;
        assigned_slave = hash_table[hash_index].tx_slave;
        if (!assigned_slave) {
@@ -265,22 +275,46 @@ static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, u3
                hash_table[hash_index].tx_bytes += skb_len;
        }
 
-       _unlock_tx_hashtbl(bond);
-
        return assigned_slave;
 }
 
+/* Caller must hold bond lock for read */
+static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index,
+                                       u32 skb_len)
+{
+       struct slave *tx_slave;
+       /*
+        * We don't need to disable softirq here, becase
+        * tlb_choose_channel() is only called by bond_alb_xmit()
+        * which already has softirq disabled.
+        */
+       _lock_tx_hashtbl(bond);
+       tx_slave = __tlb_choose_channel(bond, hash_index, skb_len);
+       _unlock_tx_hashtbl(bond);
+       return tx_slave;
+}
+
 /*********************** rlb specific functions ***************************/
-static inline void _lock_rx_hashtbl(struct bonding *bond)
+static inline void _lock_rx_hashtbl_bh(struct bonding *bond)
 {
        spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
 }
 
-static inline void _unlock_rx_hashtbl(struct bonding *bond)
+static inline void _unlock_rx_hashtbl_bh(struct bonding *bond)
 {
        spin_unlock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
 }
 
+static inline void _lock_rx_hashtbl(struct bonding *bond)
+{
+       spin_lock(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
+}
+
+static inline void _unlock_rx_hashtbl(struct bonding *bond)
+{
+       spin_unlock(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
+}
+
 /* when an ARP REPLY is received from a client update its info
  * in the rx_hashtbl
  */
@@ -290,7 +324,7 @@ static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
        struct rlb_client_info *client_info;
        u32 hash_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        hash_index = _simple_hash((u8*)&(arp->ip_src), sizeof(arp->ip_src));
        client_info = &(bond_info->rx_hashtbl[hash_index]);
@@ -305,29 +339,29 @@ static void rlb_update_entry_from_arp(struct bonding *bond, struct arp_pkt *arp)
                bond_info->rx_ntt = 1;
        }
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
-static void rlb_arp_recv(struct sk_buff *skb, struct bonding *bond,
+static int rlb_arp_recv(struct sk_buff *skb, struct bonding *bond,
                         struct slave *slave)
 {
        struct arp_pkt *arp;
 
        if (skb->protocol != cpu_to_be16(ETH_P_ARP))
-               return;
+               goto out;
 
        arp = (struct arp_pkt *) skb->data;
        if (!arp) {
                pr_debug("Packet has no ARP data\n");
-               return;
+               goto out;
        }
 
        if (!pskb_may_pull(skb, arp_hdr_len(bond->dev)))
-               return;
+               goto out;
 
        if (skb->len < sizeof(struct arp_pkt)) {
                pr_debug("Packet is too small to be an ARP\n");
-               return;
+               goto out;
        }
 
        if (arp->op_code == htons(ARPOP_REPLY)) {
@@ -335,6 +369,8 @@ static void rlb_arp_recv(struct sk_buff *skb, struct bonding *bond,
                rlb_update_entry_from_arp(bond, arp);
                pr_debug("Server received an ARP Reply from client\n");
        }
+out:
+       return RX_HANDLER_ANOTHER;
 }
 
 /* Caller must hold bond lock for read */
@@ -403,7 +439,7 @@ static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
        u32 index, next_index;
 
        /* clear slave from rx_hashtbl */
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        rx_hash_table = bond_info->rx_hashtbl;
        index = bond_info->rx_hashtbl_head;
@@ -434,7 +470,7 @@ static void rlb_clear_slave(struct bonding *bond, struct slave *slave)
                }
        }
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 
        write_lock_bh(&bond->curr_slave_lock);
 
@@ -491,7 +527,7 @@ static void rlb_update_rx_clients(struct bonding *bond)
        struct rlb_client_info *client_info;
        u32 hash_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        hash_index = bond_info->rx_hashtbl_head;
        for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
@@ -509,7 +545,7 @@ static void rlb_update_rx_clients(struct bonding *bond)
         */
        bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY;
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 /* The slave was assigned a new mac address - update the clients */
@@ -520,7 +556,7 @@ static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *sla
        int ntt = 0;
        u32 hash_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        hash_index = bond_info->rx_hashtbl_head;
        for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->next) {
@@ -540,7 +576,7 @@ static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *sla
                bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY;
        }
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 /* mark all clients using src_ip to be updated */
@@ -637,7 +673,7 @@ static struct slave *rlb_choose_channel(struct sk_buff *skb, struct bonding *bon
                        client_info->ntt = 0;
                }
 
-               if (bond->vlgrp) {
+               if (bond_vlan_used(bond)) {
                        if (!vlan_get_tag(skb, &client_info->vlan_id))
                                client_info->tag = 1;
                }
@@ -711,7 +747,7 @@ static void rlb_rebalance(struct bonding *bond)
        int ntt;
        u32 hash_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        ntt = 0;
        hash_index = bond_info->rx_hashtbl_head;
@@ -729,7 +765,7 @@ static void rlb_rebalance(struct bonding *bond)
        if (ntt) {
                bond_info->rx_ntt = 1;
        }
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 /* Caller must hold rx_hashtbl lock */
@@ -747,15 +783,11 @@ static int rlb_initialize(struct bonding *bond)
        int size = RLB_HASH_TABLE_SIZE * sizeof(struct rlb_client_info);
        int i;
 
-       spin_lock_init(&(bond_info->rx_hashtbl_lock));
-
        new_hashtbl = kmalloc(size, GFP_KERNEL);
-       if (!new_hashtbl) {
-               pr_err("%s: Error: Failed to allocate RLB hash table\n",
-                      bond->dev->name);
+       if (!new_hashtbl)
                return -1;
-       }
-       _lock_rx_hashtbl(bond);
+
+       _lock_rx_hashtbl_bh(bond);
 
        bond_info->rx_hashtbl = new_hashtbl;
 
@@ -765,7 +797,7 @@ static int rlb_initialize(struct bonding *bond)
                rlb_init_table_entry(bond_info->rx_hashtbl + i);
        }
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 
        /* register to receive ARPs */
        bond->recv_probe = rlb_arp_recv;
@@ -777,13 +809,13 @@ static void rlb_deinitialize(struct bonding *bond)
 {
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        kfree(bond_info->rx_hashtbl);
        bond_info->rx_hashtbl = NULL;
        bond_info->rx_hashtbl_head = RLB_NULL_INDEX;
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
@@ -791,7 +823,7 @@ static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
        struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
        u32 curr_index;
 
-       _lock_rx_hashtbl(bond);
+       _lock_rx_hashtbl_bh(bond);
 
        curr_index = bond_info->rx_hashtbl_head;
        while (curr_index != RLB_NULL_INDEX) {
@@ -816,7 +848,7 @@ static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)
                curr_index = next_index;
        }
 
-       _unlock_rx_hashtbl(bond);
+       _unlock_rx_hashtbl_bh(bond);
 }
 
 /*********************** tlb/rlb shared functions *********************/
@@ -851,7 +883,7 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
                skb->priority = TC_PRIO_CONTROL;
                skb->dev = slave->dev;
 
-               if (bond->vlgrp) {
+               if (bond_vlan_used(bond)) {
                        struct vlan_entry *vlan;
 
                        vlan = bond_next_vlan(bond,
@@ -875,16 +907,12 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[])
        }
 }
 
-/* hw is a boolean parameter that determines whether we should try and
- * set the hw address of the device as well as the hw address of the
- * net_device
- */
-static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[], int hw)
+static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[])
 {
        struct net_device *dev = slave->dev;
        struct sockaddr s_addr;
 
-       if (!hw) {
+       if (slave->bond->params.mode == BOND_MODE_TLB) {
                memcpy(dev->dev_addr, addr, dev->addr_len);
                return 0;
        }
@@ -914,8 +942,8 @@ static void alb_swap_mac_addr(struct bonding *bond, struct slave *slave1, struct
        u8 tmp_mac_addr[ETH_ALEN];
 
        memcpy(tmp_mac_addr, slave1->dev->dev_addr, ETH_ALEN);
-       alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr, bond->alb_info.rlb_enabled);
-       alb_set_slave_mac_addr(slave2, tmp_mac_addr, bond->alb_info.rlb_enabled);
+       alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr);
+       alb_set_slave_mac_addr(slave2, tmp_mac_addr);
 
 }
 
@@ -1062,8 +1090,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
 
                /* Try setting slave mac to bond address and fall-through
                   to code handling that situation below... */
-               alb_set_slave_mac_addr(slave, bond->dev->dev_addr,
-                                      bond->alb_info.rlb_enabled);
+               alb_set_slave_mac_addr(slave, bond->dev->dev_addr);
        }
 
        /* The slave's address is equal to the address of the bond.
@@ -1099,8 +1126,7 @@ static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slav
        }
 
        if (free_mac_slave) {
-               alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr,
-                                      bond->alb_info.rlb_enabled);
+               alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr);
 
                pr_warning("%s: Warning: the hw address of slave %s is in use by the bond; giving it the hw address of %s\n",
                           bond->dev->name, slave->dev->name,
@@ -1225,16 +1251,10 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
        skb_reset_mac_header(skb);
        eth_data = eth_hdr(skb);
 
-       /* make sure that the curr_active_slave and the slaves list do
-        * not change during tx
+       /* make sure that the curr_active_slave do not change during tx
         */
-       read_lock(&bond->lock);
        read_lock(&bond->curr_slave_lock);
 
-       if (!BOND_IS_OK(bond)) {
-               goto out;
-       }
-
        switch (ntohs(skb->protocol)) {
        case ETH_P_IP: {
                const struct iphdr *iph = ip_hdr(skb);
@@ -1330,17 +1350,18 @@ int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
                res = bond_dev_queue_xmit(bond, skb, tx_slave->dev);
        } else {
                if (tx_slave) {
-                       tlb_clear_slave(bond, tx_slave, 0);
+                       _lock_tx_hashtbl(bond);
+                       __tlb_clear_slave(bond, tx_slave, 0);
+                       _unlock_tx_hashtbl(bond);
                }
        }
 
-out:
        if (res) {
                /* no suitable interface, frame not sent */
                dev_kfree_skb(skb);
        }
        read_unlock(&bond->curr_slave_lock);
-       read_unlock(&bond->lock);
+
        return NETDEV_TX_OK;
 }
 
@@ -1354,10 +1375,6 @@ void bond_alb_monitor(struct work_struct *work)
 
        read_lock(&bond->lock);
 
-       if (bond->kill_timers) {
-               goto out;
-       }
-
        if (bond->slave_cnt == 0) {
                bond_info->tx_rebalance_counter = 0;
                bond_info->lp_counter = 0;
@@ -1412,10 +1429,13 @@ void bond_alb_monitor(struct work_struct *work)
 
                        /*
                         * dev_set_promiscuity requires rtnl and
-                        * nothing else.
+                        * nothing else.  Avoid race with bond_close.
                         */
                        read_unlock(&bond->lock);
-                       rtnl_lock();
+                       if (!rtnl_trylock()) {
+                               read_lock(&bond->lock);
+                               goto re_arm;
+                       }
 
                        bond_info->rlb_promisc_timeout_counter = 0;
 
@@ -1452,7 +1472,7 @@ void bond_alb_monitor(struct work_struct *work)
 
 re_arm:
        queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks);
-out:
+
        read_unlock(&bond->lock);
 }
 
@@ -1463,8 +1483,7 @@ int bond_alb_init_slave(struct bonding *bond, struct slave *slave)
 {
        int res;
 
-       res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr,
-                                    bond->alb_info.rlb_enabled);
+       res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr);
        if (res) {
                return res;
        }
@@ -1615,8 +1634,7 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
                alb_swap_mac_addr(bond, swap_slave, new_slave);
        } else {
                /* set the new_slave to the bond mac address */
-               alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr,
-                                      bond->alb_info.rlb_enabled);
+               alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr);
        }
 
        if (swap_slave) {
@@ -1676,8 +1694,7 @@ int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
                alb_swap_mac_addr(bond, swap_slave, bond->curr_active_slave);
                alb_fasten_mac_swap(bond, swap_slave, bond->curr_active_slave);
        } else {
-               alb_set_slave_mac_addr(bond->curr_active_slave, bond_dev->dev_addr,
-                                      bond->alb_info.rlb_enabled);
+               alb_set_slave_mac_addr(bond->curr_active_slave, bond_dev->dev_addr);
 
                read_lock(&bond->lock);
                alb_send_learning_packets(bond->curr_active_slave, bond_dev->dev_addr);