[SRU][F:linux-bluefield][PATCH 20/32] bonding: Add helper function to get the xmit slave based on hash
Daniel Jurgens
danielj at nvidia.com
Mon May 3 19:39:05 UTC 2021
From: Maor Gottlieb <maorg at mellanox.com>
BugLink: https://bugs.launchpad.net/bugs/1926994
Both xor and 802.3ad modes use bond_xmit_hash to get the xmit slave.
Export the logic to helper function so it could be used in the
following patches by the .ndo to get the xmit slave.
Signed-off-by: Maor Gottlieb <maorg at mellanox.com>
Reviewed-by: Jiri Pirko <jiri at mellanox.com>
Reviewed-by: Jay Vosburgh <jay.vosburgh at canonical.com>
Acked-by: David S. Miller <davem at davemloft.net>
Signed-off-by: Saeed Mahameed <saeedm at mellanox.com>
(backported from commit c071d91d2a89b0dac1354673810b36453aed62c4)
Signed-off-by: Daniel Jurgens <danielj at nvidia.com>
Conflicts:
drivers/net/bonding/bond_main.c
---
drivers/net/bonding/bond_main.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 09bae5b..a0f2697 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4247,6 +4247,23 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
return ret;
}
+static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
+ struct sk_buff *skb,
+ struct bond_up_slave *slaves)
+{
+ struct slave *slave;
+ unsigned int count;
+ u32 hash;
+
+ hash = bond_xmit_hash(bond, skb);
+ count = slaves ? READ_ONCE(slaves->count) : 0;
+ if (unlikely(!count))
+ return NULL;
+
+ slave = slaves->arr[hash % count];
+ return slave;
+}
+
/* Use this Xmit function for 3AD as well as XOR modes. The current
* usable slave array is formed in the control path. The xmit function
* just calculates hash and sends the packet out.
@@ -4255,16 +4272,13 @@ static netdev_tx_t bond_3ad_xor_xmit(struct sk_buff *skb,
struct net_device *dev)
{
struct bonding *bond = netdev_priv(dev);
- struct slave *slave;
struct bond_up_slave *slaves;
- unsigned int count;
+ struct slave *slave;
slaves = rcu_dereference(bond->usable_slaves);
- count = slaves ? READ_ONCE(slaves->count) : 0;
- if (likely(count)) {
- slave = slaves->arr[bond_xmit_hash(bond, skb) % count];
+ slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
+ if (likely(slave))
return bond_dev_queue_xmit(bond, skb, slave->dev);
- }
return bond_tx_drop(dev, skb);
}
--
1.8.3.1
More information about the kernel-team
mailing list