History

Merge branch 'mlx5-next' of git://git.kernel.org/pub/scm/linux/kernel/git/mellanox/linux

This merge includes updates to bonding driver needed for the rdma stack, to avoid conflicts with the RDMA branch. Maor Gottlieb Says: ==================== Bonding: Add support to get xmit slave The following series adds support to get the LAG master xmit slave by introducing new .ndo - ndo_get_xmit_slave. Every LAG module can implement it and it first implemented in the bond driver. This is follow-up to the RFC discussion [1]. The main motivation for doing this is for drivers that offload part of the LAG functionality. For example, Mellanox Connect-X hardware implements RoCE LAG which selects the TX affinity when the resources are created and port is remapped when it goes down. The first part of this patchset introduces the new .ndo and add the support to the bonding module. The second part adds support to get the RoCE LAG xmit slave by building skb of the RoCE packet based on the AH attributes and call to the new .ndo. The third part change the mlx5 driver driver to set the QP's affinity port according to the slave which found by the .ndo. ====================

Saeed Mahameed committed 6 years ago

Commit 76cd6222 parents 5eb2bcf c6bc6048 files · +301 −99Browse files

Unified · Split

8 files
  1. drivers/net/bonding/bond_alb.c +28 −11
  2. drivers/net/bonding/bond_main.c +186 −66
  3. drivers/net/ethernet/mellanox/mlx5/core/lag.c +45 −21
  4. include/linux/mlx5/driver.h +2 −0
  5. include/linux/netdevice.h +12 −0
  6. include/net/bond_alb.h +4 −0
  7. include/net/bonding.h +2 −1
  8. net/core/dev.c +22 −0
drivers/net/bonding/bond_alb.c+28−11
@@ -1331,11 +1331,11 @@ static netdev_tx_t bond_do_alb_xmit(struct sk_buff *skb, struct bonding *bond, · 1330 unmodified lines
13311331 return bond_tx_drop(bond->dev, skb);
13321332 }
13331333
1334−netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1334+struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
1335+ struct sk_buff *skb)
13351336 {
1336− struct bonding *bond = netdev_priv(bond_dev);
1337− struct ethhdr *eth_data;
13381337 struct slave *tx_slave = NULL;
1338+ struct ethhdr *eth_data;
13391339 u32 hash_index;
13401340
13411341 skb_reset_mac_header(skb);
@@ -1357,7 +1357,7 @@ netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev) · 15 unmodified lines
13571357 struct bond_up_slave *slaves;
13581358 unsigned int count;
13591359
1360− slaves = rcu_dereference(bond->slave_arr);
1360+ slaves = rcu_dereference(bond->usable_slaves);
13611361 count = slaves ? READ_ONCE(slaves->count) : 0;
13621362 if (likely(count))
13631363 tx_slave = slaves->arr[hash_index %
@@ -1366,20 +1366,29 @@ netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev) · 2 unmodified lines
13661366 break;
13671367 }
13681368 }
1369− return bond_do_alb_xmit(skb, bond, tx_slave);
1369+ return tx_slave;
13701370 }
13711371
1372−netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1372+netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
13731373 {
13741374 struct bonding *bond = netdev_priv(bond_dev);
1375− struct ethhdr *eth_data;
1375+ struct slave *tx_slave;
1376+
1377+ tx_slave = bond_xmit_tlb_slave_get(bond, skb);
1378+ return bond_do_alb_xmit(skb, bond, tx_slave);
1379+}
1380+
1381+struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
1382+ struct sk_buff *skb)
1383+{
13761384 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1377− struct slave *tx_slave = NULL;
13781385 static const __be32 ip_bcast = htonl(0xffffffff);
1379− int hash_size = 0;
1386+ struct slave *tx_slave = NULL;
1387+ const u8 *hash_start = NULL;
13801388 bool do_tx_balance = true;
1389+ struct ethhdr *eth_data;
13811390 u32 hash_index = 0;
1382− const u8 *hash_start = NULL;
1391+ int hash_size = 0;
13831392
13841393 skb_reset_mac_header(skb);
13851394 eth_data = eth_hdr(skb);
@@ -1491,14 +1500,22 @@ netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev) · 105 unmodified lines
14911500 struct bond_up_slave *slaves;
14921501 unsigned int count;
14931502
1494− slaves = rcu_dereference(bond->slave_arr);
1503+ slaves = rcu_dereference(bond->usable_slaves);
14951504 count = slaves ? READ_ONCE(slaves->count) : 0;
14961505 if (likely(count))
14971506 tx_slave = slaves->arr[bond_xmit_hash(bond, skb) %
14981507 count];
14991508 }
15001509 }
1510+ return tx_slave;
1511+}
1512+
1513+netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1514+{
1515+ struct bonding *bond = netdev_priv(bond_dev);
1516+ struct slave *tx_slave = NULL;
15011517
1518+ tx_slave = bond_xmit_alb_slave_get(bond, skb);
15021519 return bond_do_alb_xmit(skb, bond, tx_slave);
15031520 }
15041521
drivers/net/bonding/bond_main.c+186−66
@@ -3923,16 +3923,15 @@ unwind: · 3922 unmodified lines
39233923 }
39243924
39253925 /**
3926− * bond_xmit_slave_id - transmit skb through slave with slave_id
3926+ * bond_get_slave_by_id - get xmit slave with slave_id
39273927 * @bond: bonding device that is transmitting
3928− * @skb: buffer to transmit
39293928 * @slave_id: slave id up to slave_cnt-1 through which to transmit
39303929 *
3931− * This function tries to transmit through slave with slave_id but in case
3930+ * This function tries to get slave with slave_id but in case
39323931 * it fails, it tries to find the first available slave for transmission.
3933− * The skb is consumed in all cases, thus the function is void.
39343932 */
3935−static netdev_tx_t bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id)
3933+static struct slave *bond_get_slave_by_id(struct bonding *bond,
3934+ int slave_id)
39363935 {
39373936 struct list_head *iter;
39383937 struct slave *slave;
@@ -3942,7 +3941,7 @@ static netdev_tx_t bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, · 3 unmodified lines
39423941 bond_for_each_slave_rcu(bond, slave, iter) {
39433942 if (--i < 0) {
39443943 if (bond_slave_can_tx(slave))
3945− return bond_dev_queue_xmit(bond, skb, slave->dev);
3944+ return slave;
39463945 }
39473946 }
39483947
@@ -3952,10 +3951,10 @@ static netdev_tx_t bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, · 3 unmodified lines
39523951 if (--i < 0)
39533952 break;
39543953 if (bond_slave_can_tx(slave))
3955− return bond_dev_queue_xmit(bond, skb, slave->dev);
3954+ return slave;
39563955 }
39573956 /* no slave that can tx has been found */
3958− return bond_tx_drop(bond->dev, skb);
3957+ return NULL;
39593958 }
39603959
39613960 /**
@@ -3991,10 +3990,9 @@ static u32 bond_rr_gen_slave_id(struct bonding *bond) · 29 unmodified lines
39913990 return slave_id;
39923991 }
39933992
3994−static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb,
3995− struct net_device *bond_dev)
3993+static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
3994+ struct sk_buff *skb)
39963995 {
3997− struct bonding *bond = netdev_priv(bond_dev);
39983996 struct slave *slave;
39993997 int slave_cnt;
40003998 u32 slave_id;
@@ -4016,20 +4014,39 @@ static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb, · 15 unmodified lines
40164014 if (iph->protocol == IPPROTO_IGMP) {
40174015 slave = rcu_dereference(bond->curr_active_slave);
40184016 if (slave)
4019− return bond_dev_queue_xmit(bond, skb, slave->dev);
4020− return bond_xmit_slave_id(bond, skb, 0);
4017+ return slave;
4018+ return bond_get_slave_by_id(bond, 0);
40214019 }
40224020 }
40234021
40244022 non_igmp:
40254023 slave_cnt = READ_ONCE(bond->slave_cnt);
40264024 if (likely(slave_cnt)) {
4027− slave_id = bond_rr_gen_slave_id(bond);
4028− return bond_xmit_slave_id(bond, skb, slave_id % slave_cnt);
4025+ slave_id = bond_rr_gen_slave_id(bond) % slave_cnt;
4026+ return bond_get_slave_by_id(bond, slave_id);
40294027 }
4028+ return NULL;
4029+}
4030+
4031+static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb,
4032+ struct net_device *bond_dev)
4033+{
4034+ struct bonding *bond = netdev_priv(bond_dev);
4035+ struct slave *slave;
4036+
4037+ slave = bond_xmit_roundrobin_slave_get(bond, skb);
4038+ if (likely(slave))
4039+ return bond_dev_queue_xmit(bond, skb, slave->dev);
4040+
40304041 return bond_tx_drop(bond_dev, skb);
40314042 }
40324043
4044+static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond,
4045+ struct sk_buff *skb)
4046+{
4047+ return rcu_dereference(bond->curr_active_slave);
4048+}
4049+
40334050 /* In active-backup mode, we know that bond->curr_active_slave is always valid if
40344051 * the bond has a usable interface.
40354052 */
@@ -4039,7 +4056,7 @@ static netdev_tx_t bond_xmit_activebackup(struct sk_buff *skb, · 3 unmodified lines
40394056 struct bonding *bond = netdev_priv(bond_dev);
40404057 struct slave *slave;
40414058
4042− slave = rcu_dereference(bond->curr_active_slave);
4059+ slave = bond_xmit_activebackup_slave_get(bond, skb);
40434060 if (slave)
40444061 return bond_dev_queue_xmit(bond, skb, slave->dev);
40454062
@@ -4077,6 +4094,61 @@ err: · 31 unmodified lines
40774094 bond_slave_arr_work_rearm(bond, 1);
40784095 }
40794096
4097+static void bond_skip_slave(struct bond_up_slave *slaves,
4098+ struct slave *skipslave)
4099+{
4100+ int idx;
4101+
4102+ /* Rare situation where caller has asked to skip a specific
4103+ * slave but allocation failed (most likely!). BTW this is
4104+ * only possible when the call is initiated from
4105+ * __bond_release_one(). In this situation; overwrite the
4106+ * skipslave entry in the array with the last entry from the
4107+ * array to avoid a situation where the xmit path may choose
4108+ * this to-be-skipped slave to send a packet out.
4109+ */
4110+ for (idx = 0; slaves && idx < slaves->count; idx++) {
4111+ if (skipslave == slaves->arr[idx]) {
4112+ slaves->arr[idx] =
4113+ slaves->arr[slaves->count - 1];
4114+ slaves->count--;
4115+ break;
4116+ }
4117+ }
4118+}
4119+
4120+static void bond_set_slave_arr(struct bonding *bond,
4121+ struct bond_up_slave *usable_slaves,
4122+ struct bond_up_slave *all_slaves)
4123+{
4124+ struct bond_up_slave *usable, *all;
4125+
4126+ usable = rtnl_dereference(bond->usable_slaves);
4127+ rcu_assign_pointer(bond->usable_slaves, usable_slaves);
4128+ kfree_rcu(usable, rcu);
4129+
4130+ all = rtnl_dereference(bond->all_slaves);
4131+ rcu_assign_pointer(bond->all_slaves, all_slaves);
4132+ kfree_rcu(all, rcu);
4133+}
4134+
4135+static void bond_reset_slave_arr(struct bonding *bond)
4136+{
4137+ struct bond_up_slave *usable, *all;
4138+
4139+ usable = rtnl_dereference(bond->usable_slaves);
4140+ if (usable) {
4141+ RCU_INIT_POINTER(bond->usable_slaves, NULL);
4142+ kfree_rcu(usable, rcu);
4143+ }
4144+
4145+ all = rtnl_dereference(bond->all_slaves);
4146+ if (all) {
4147+ RCU_INIT_POINTER(bond->all_slaves, NULL);
4148+ kfree_rcu(all, rcu);
4149+ }
4150+}
4151+
40804152 /* Build the usable slaves array in control path for modes that use xmit-hash
40814153 * to determine the slave interface -
40824154 * (a) BOND_MODE_8023AD
@@ -4087,9 +4159,9 @@ err: · 4 unmodified lines
40874159 */
40884160 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
40894161 {
4162+ struct bond_up_slave *usable_slaves = NULL, *all_slaves = NULL;
40904163 struct slave *slave;
40914164 struct list_head *iter;
4092− struct bond_up_slave *new_arr, *old_arr;
40934165 int agg_id = 0;
40944166 int ret = 0;
40954167
@@ -4097,11 +4169,12 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave) · 1 unmodified line
40974169 WARN_ON(lockdep_is_held(&bond->mode_lock));
40984170 #endif
40994171
4100− new_arr = kzalloc(offsetof(struct bond_up_slave, arr[bond->slave_cnt]),
4101− GFP_KERNEL);
4102− if (!new_arr) {
4172+ usable_slaves = kzalloc(struct_size(usable_slaves, arr,
4173+ bond->slave_cnt), GFP_KERNEL);
4174+ all_slaves = kzalloc(struct_size(all_slaves, arr,
4175+ bond->slave_cnt), GFP_KERNEL);
4176+ if (!usable_slaves || !all_slaves) {
41034177 ret = -ENOMEM;
4104− pr_err("Failed to build slave-array.\n");
41054178 goto out;
41064179 }
41074180 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
@@ -4109,20 +4182,19 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave) · 1 unmodified line
41094182
41104183 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
41114184 pr_debug("bond_3ad_get_active_agg_info failed\n");
4112− kfree_rcu(new_arr, rcu);
41134185 /* No active aggragator means it's not safe to use
41144186 * the previous array.
41154187 */
4116− old_arr = rtnl_dereference(bond->slave_arr);
4117− if (old_arr) {
4118− RCU_INIT_POINTER(bond->slave_arr, NULL);
4119− kfree_rcu(old_arr, rcu);
4120− }
4188+ bond_reset_slave_arr(bond);
41214189 goto out;
41224190 }
41234191 agg_id = ad_info.aggregator_id;
41244192 }
41254193 bond_for_each_slave(bond, slave, iter) {
4194+ if (skipslave == slave)
4195+ continue;
4196+
4197+ all_slaves->arr[all_slaves->count++] = slave;
41264198 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
41274199 struct aggregator *agg;
41284200
@@ -4132,44 +4204,45 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave) · 3 unmodified lines
41324204 }
41334205 if (!bond_slave_can_tx(slave))
41344206 continue;
4135− if (skipslave == slave)
4136− continue;
41374207
41384208 slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
4139− new_arr->count);
4209+ usable_slaves->count);
41404210
4141− new_arr->arr[new_arr->count++] = slave;
4211+ usable_slaves->arr[usable_slaves->count++] = slave;
41424212 }
41434213
4144− old_arr = rtnl_dereference(bond->slave_arr);
4145− rcu_assign_pointer(bond->slave_arr, new_arr);
4146− if (old_arr)
4147− kfree_rcu(old_arr, rcu);
4214+ bond_set_slave_arr(bond, usable_slaves, all_slaves);
4215+ return ret;
41484216 out:
41494217 if (ret != 0 && skipslave) {
4150− int idx;
4151−
4152− /* Rare situation where caller has asked to skip a specific
4153− * slave but allocation failed (most likely!). BTW this is
4154− * only possible when the call is initiated from
4155− * __bond_release_one(). In this situation; overwrite the
4156− * skipslave entry in the array with the last entry from the
4157− * array to avoid a situation where the xmit path may choose
4158− * this to-be-skipped slave to send a packet out.
4159− */
4160− old_arr = rtnl_dereference(bond->slave_arr);
4161− for (idx = 0; old_arr != NULL && idx < old_arr->count; idx++) {
4162− if (skipslave == old_arr->arr[idx]) {
4163− old_arr->arr[idx] =
4164− old_arr->arr[old_arr->count-1];
4165− old_arr->count--;
4166− break;
4167− }
4168− }
4218+ bond_skip_slave(rtnl_dereference(bond->all_slaves),
4219+ skipslave);
4220+ bond_skip_slave(rtnl_dereference(bond->usable_slaves),
4221+ skipslave);
41694222 }
4223+ kfree_rcu(all_slaves, rcu);
4224+ kfree_rcu(usable_slaves, rcu);
4225+
41704226 return ret;
41714227 }
41724228
4229+static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
4230+ struct sk_buff *skb,
4231+ struct bond_up_slave *slaves)
4232+{
4233+ struct slave *slave;
4234+ unsigned int count;
4235+ u32 hash;
4236+
4237+ hash = bond_xmit_hash(bond, skb);
4238+ count = slaves ? READ_ONCE(slaves->count) : 0;
4239+ if (unlikely(!count))
4240+ return NULL;
4241+
4242+ slave = slaves->arr[hash % count];
4243+ return slave;
4244+}
4245+
41734246 /* Use this Xmit function for 3AD as well as XOR modes. The current
41744247 * usable slave array is formed in the control path. The xmit function
41754248 * just calculates hash and sends the packet out.
@@ -4178,16 +4251,14 @@ static netdev_tx_t bond_3ad_xor_xmit(struct sk_buff *skb, · 2 unmodified lines
41784251 struct net_device *dev)
41794252 {
41804253 struct bonding *bond = netdev_priv(dev);
4181− struct slave *slave;
41824254 struct bond_up_slave *slaves;
4183− unsigned int count;
4255+ struct slave *slave;
41844256
4185− slaves = rcu_dereference(bond->slave_arr);
4186− count = slaves ? READ_ONCE(slaves->count) : 0;
4187− if (likely(count)) {
4188− slave = slaves->arr[bond_xmit_hash(bond, skb) % count];
4257+ slaves = rcu_dereference(bond->usable_slaves);
4258+ slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4259+ if (likely(slave))
41894260 return bond_dev_queue_xmit(bond, skb, slave->dev);
4190− }
4261+
41914262 return bond_tx_drop(dev, skb);
41924263 }
41934264
@@ -4269,6 +4340,48 @@ static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb, · 75 unmodified lines
42694340 return txq;
42704341 }
42714342
4343+static struct net_device *bond_xmit_get_slave(struct net_device *master_dev,
4344+ struct sk_buff *skb,
4345+ bool all_slaves)
4346+{
4347+ struct bonding *bond = netdev_priv(master_dev);
4348+ struct bond_up_slave *slaves;
4349+ struct slave *slave = NULL;
4350+
4351+ switch (BOND_MODE(bond)) {
4352+ case BOND_MODE_ROUNDROBIN:
4353+ slave = bond_xmit_roundrobin_slave_get(bond, skb);
4354+ break;
4355+ case BOND_MODE_ACTIVEBACKUP:
4356+ slave = bond_xmit_activebackup_slave_get(bond, skb);
4357+ break;
4358+ case BOND_MODE_8023AD:
4359+ case BOND_MODE_XOR:
4360+ if (all_slaves)
4361+ slaves = rcu_dereference(bond->all_slaves);
4362+ else
4363+ slaves = rcu_dereference(bond->usable_slaves);
4364+ slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4365+ break;
4366+ case BOND_MODE_BROADCAST:
4367+ break;
4368+ case BOND_MODE_ALB:
4369+ slave = bond_xmit_alb_slave_get(bond, skb);
4370+ break;
4371+ case BOND_MODE_TLB:
4372+ slave = bond_xmit_tlb_slave_get(bond, skb);
4373+ break;
4374+ default:
4375+ /* Should never happen, mode already checked */
4376+ WARN_ONCE(true, "Unknown bonding mode");
4377+ break;
4378+ }
4379+
4380+ if (slave)
4381+ return slave->dev;
4382+ return NULL;
4383+}
4384+
42724385 static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
42734386 {
42744387 struct bonding *bond = netdev_priv(dev);
@@ -4389,6 +4502,7 @@ static const struct net_device_ops bond_netdev_ops = { · 114 unmodified lines
43894502 .ndo_del_slave = bond_release,
43904503 .ndo_fix_features = bond_fix_features,
43914504 .ndo_features_check = passthru_features_check,
4505+ .ndo_get_xmit_slave = bond_xmit_get_slave,
43924506 };
43934507
43944508 static const struct device_type bond_type = {
@@ -4456,9 +4570,9 @@ void bond_setup(struct net_device *bond_dev) · 61 unmodified lines
44564570 static void bond_uninit(struct net_device *bond_dev)
44574571 {
44584572 struct bonding *bond = netdev_priv(bond_dev);
4573+ struct bond_up_slave *usable, *all;
44594574 struct list_head *iter;
44604575 struct slave *slave;
4461− struct bond_up_slave *arr;
44624576
44634577 bond_netpoll_cleanup(bond_dev);
44644578
@@ -4467,10 +4581,16 @@ static void bond_uninit(struct net_device *bond_dev) · 2 unmodified lines
44674581 __bond_release_one(bond_dev, slave->dev, true, true);
44684582 netdev_info(bond_dev, "Released all slaves\n");
44694583
4470− arr = rtnl_dereference(bond->slave_arr);
4471− if (arr) {
4472− RCU_INIT_POINTER(bond->slave_arr, NULL);
4473− kfree_rcu(arr, rcu);
4584+ usable = rtnl_dereference(bond->usable_slaves);
4585+ if (usable) {
4586+ RCU_INIT_POINTER(bond->usable_slaves, NULL);
4587+ kfree_rcu(usable, rcu);
4588+ }
4589+
4590+ all = rtnl_dereference(bond->all_slaves);
4591+ if (all) {
4592+ RCU_INIT_POINTER(bond->all_slaves, NULL);
4593+ kfree_rcu(all, rcu);
44744594 }
44754595
44764596 list_del(&bond->bond_list);
drivers/net/ethernet/mellanox/mlx5/core/lag.c+45−21
@@ -42,7 +42,7 @@ · 41 unmodified lines
4242 * Beware of lock dependencies (preferably, no locks should be acquired
4343 * under it).
4444 */
45−static DEFINE_MUTEX(lag_mutex);
45+static DEFINE_SPINLOCK(lag_lock);
4646
4747 static int mlx5_cmd_create_lag(struct mlx5_core_dev *dev, u8 remap_port1,
4848 u8 remap_port2)
@@ -274,9 +274,9 @@ static void mlx5_do_bond(struct mlx5_lag *ldev) · 225 unmodified lines
274274 if (!dev0 || !dev1)
275275 return;
276276
277− mutex_lock(&lag_mutex);
277+ spin_lock(&lag_lock);
278278 tracker = ldev->tracker;
279− mutex_unlock(&lag_mutex);
279+ spin_unlock(&lag_lock);
280280
281281 do_bond = tracker.is_bonded && mlx5_lag_check_prereq(ldev);
282282
@@ -458,9 +458,9 @@ static int mlx5_lag_netdev_event(struct notifier_block *this, · 175 unmodified lines
458458 break;
459459 }
460460
461− mutex_lock(&lag_mutex);
461+ spin_lock(&lag_lock);
462462 ldev->tracker = tracker;
463− mutex_unlock(&lag_mutex);
463+ spin_unlock(&lag_lock);
464464
465465 if (changed)
466466 mlx5_queue_bond_work(ldev, 0);
@@ -502,7 +502,7 @@ static void mlx5_lag_dev_add_pf(struct mlx5_lag *ldev, · 35 unmodified lines
502502 if (fn >= MLX5_MAX_PORTS)
503503 return;
504504
505− mutex_lock(&lag_mutex);
505+ spin_lock(&lag_lock);
506506 ldev->pf[fn].dev = dev;
507507 ldev->pf[fn].netdev = netdev;
508508 ldev->tracker.netdev_state[fn].link_up = 0;
@@ -510,7 +510,7 @@ static void mlx5_lag_dev_add_pf(struct mlx5_lag *ldev, · 1 unmodified line
510510
511511 dev->priv.lag = ldev;
512512
513− mutex_unlock(&lag_mutex);
513+ spin_unlock(&lag_lock);
514514 }
515515
516516 static void mlx5_lag_dev_remove_pf(struct mlx5_lag *ldev,
@@ -525,11 +525,11 @@ static void mlx5_lag_dev_remove_pf(struct mlx5_lag *ldev, · 8 unmodified lines
525525 if (i == MLX5_MAX_PORTS)
526526 return;
527527
528− mutex_lock(&lag_mutex);
528+ spin_lock(&lag_lock);
529529 memset(&ldev->pf[i], 0, sizeof(*ldev->pf));
530530
531531 dev->priv.lag = NULL;
532− mutex_unlock(&lag_mutex);
532+ spin_unlock(&lag_lock);
533533 }
534534
535535 /* Must be called with intf_mutex held */
@@ -607,10 +607,10 @@ bool mlx5_lag_is_roce(struct mlx5_core_dev *dev) · 71 unmodified lines
607607 struct mlx5_lag *ldev;
608608 bool res;
609609
610− mutex_lock(&lag_mutex);
610+ spin_lock(&lag_lock);
611611 ldev = mlx5_lag_dev_get(dev);
612612 res = ldev && __mlx5_lag_is_roce(ldev);
613− mutex_unlock(&lag_mutex);
613+ spin_unlock(&lag_lock);
614614
615615 return res;
616616 }
@@ -621,10 +621,10 @@ bool mlx5_lag_is_active(struct mlx5_core_dev *dev) · 4 unmodified lines
621621 struct mlx5_lag *ldev;
622622 bool res;
623623
624− mutex_lock(&lag_mutex);
624+ spin_lock(&lag_lock);
625625 ldev = mlx5_lag_dev_get(dev);
626626 res = ldev && __mlx5_lag_is_active(ldev);
627− mutex_unlock(&lag_mutex);
627+ spin_unlock(&lag_lock);
628628
629629 return res;
630630 }
@@ -635,10 +635,10 @@ bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev) · 4 unmodified lines
635635 struct mlx5_lag *ldev;
636636 bool res;
637637
638− mutex_lock(&lag_mutex);
638+ spin_lock(&lag_lock);
639639 ldev = mlx5_lag_dev_get(dev);
640640 res = ldev && __mlx5_lag_is_sriov(ldev);
641− mutex_unlock(&lag_mutex);
641+ spin_unlock(&lag_lock);
642642
643643 return res;
644644 }
@@ -664,7 +664,7 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev) · 19 unmodified lines
664664 struct net_device *ndev = NULL;
665665 struct mlx5_lag *ldev;
666666
667− mutex_lock(&lag_mutex);
667+ spin_lock(&lag_lock);
668668 ldev = mlx5_lag_dev_get(dev);
669669
670670 if (!(ldev && __mlx5_lag_is_roce(ldev)))
@@ -681,12 +681,36 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev) · 10 unmodified lines
681681 dev_hold(ndev);
682682
683683 unlock:
684− mutex_unlock(&lag_mutex);
684+ spin_unlock(&lag_lock);
685685
686686 return ndev;
687687 }
688688 EXPORT_SYMBOL(mlx5_lag_get_roce_netdev);
689689
690+u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev,
691+ struct net_device *slave)
692+{
693+ struct mlx5_lag *ldev;
694+ u8 port = 0;
695+
696+ spin_lock(&lag_lock);
697+ ldev = mlx5_lag_dev_get(dev);
698+ if (!(ldev && __mlx5_lag_is_roce(ldev)))
699+ goto unlock;
700+
701+ if (ldev->pf[MLX5_LAG_P1].netdev == slave)
702+ port = MLX5_LAG_P1;
703+ else
704+ port = MLX5_LAG_P2;
705+
706+ port = ldev->v2p_map[port];
707+
708+unlock:
709+ spin_unlock(&lag_lock);
710+ return port;
711+}
712+EXPORT_SYMBOL(mlx5_lag_get_slave_port);
713+
690714 bool mlx5_lag_intf_add(struct mlx5_interface *intf, struct mlx5_priv *priv)
691715 {
692716 struct mlx5_core_dev *dev = container_of(priv, struct mlx5_core_dev,
@@ -723,7 +747,7 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev, · 30 unmodified lines
723747
724748 memset(values, 0, sizeof(*values) * num_counters);
725749
726− mutex_lock(&lag_mutex);
750+ spin_lock(&lag_lock);
727751 ldev = mlx5_lag_dev_get(dev);
728752 if (ldev && __mlx5_lag_is_roce(ldev)) {
729753 num_ports = MLX5_MAX_PORTS;
@@ -733,6 +757,7 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev, · 3 unmodified lines
733757 num_ports = 1;
734758 mdev[MLX5_LAG_P1] = dev;
735759 }
760+ spin_unlock(&lag_lock);
736761
737762 for (i = 0; i < num_ports; ++i) {
738763 u32 in[MLX5_ST_SZ_DW(query_cong_statistics_in)] = {};
@@ -742,14 +767,13 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev, · 3 unmodified lines
742767 ret = mlx5_cmd_exec_inout(mdev[i], query_cong_statistics, in,
743768 out);
744769 if (ret)
745− goto unlock;
770+ goto free;
746771
747772 for (j = 0; j < num_counters; ++j)
748773 values[j] += be64_to_cpup((__be64 *)(out + offsets[j]));
749774 }
750775
751−unlock:
752− mutex_unlock(&lag_mutex);
776+free:
753777 kvfree(out);
754778 return ret;
755779 }
include/linux/mlx5/driver.h+2−0
@@ -1074,6 +1074,8 @@ bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev); · 1073 unmodified lines
10741074 bool mlx5_lag_is_multipath(struct mlx5_core_dev *dev);
10751075 bool mlx5_lag_is_active(struct mlx5_core_dev *dev);
10761076 struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev);
1077+u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev,
1078+ struct net_device *slave);
10771079 int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
10781080 u64 *values,
10791081 int num_counters,
include/linux/netdevice.h+12−0
@@ -1148,6 +1148,12 @@ struct netdev_net_notifier { · 1147 unmodified lines
11481148 * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);
11491149 * Called to release previously enslaved netdev.
11501150 *
1151+ * struct net_device *(*ndo_get_xmit_slave)(struct net_device *dev,
1152+ * struct sk_buff *skb,
1153+ * bool all_slaves);
1154+ * Get the xmit slave of master device. If all_slaves is true, function
1155+ * assume all the slaves can transmit.
1156+ *
11511157 * Feature/offload setting functions.
11521158 * netdev_features_t (*ndo_fix_features)(struct net_device *dev,
11531159 * netdev_features_t features);
@@ -1391,6 +1397,9 @@ struct net_device_ops { · 237 unmodified lines
13911397 struct netlink_ext_ack *extack);
13921398 int (*ndo_del_slave)(struct net_device *dev,
13931399 struct net_device *slave_dev);
1400+ struct net_device* (*ndo_get_xmit_slave)(struct net_device *dev,
1401+ struct sk_buff *skb,
1402+ bool all_slaves);
13941403 netdev_features_t (*ndo_fix_features)(struct net_device *dev,
13951404 netdev_features_t features);
13961405 int (*ndo_set_features)(struct net_device *dev,
@@ -2745,6 +2754,9 @@ void netdev_freemem(struct net_device *dev); · 1348 unmodified lines
27452754 void synchronize_net(void);
27462755 int init_dummy_netdev(struct net_device *dev);
27472756
2757+struct net_device *netdev_get_xmit_slave(struct net_device *dev,
2758+ struct sk_buff *skb,
2759+ bool all_slaves);
27482760 struct net_device *dev_get_by_index(struct net *net, int ifindex);
27492761 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
27502762 struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
include/net/bond_alb.h+4−0
@@ -158,6 +158,10 @@ void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char · 157 unmodified lines
158158 void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave);
159159 int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev);
160160 int bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev);
161+struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
162+ struct sk_buff *skb);
163+struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
164+ struct sk_buff *skb);
161165 void bond_alb_monitor(struct work_struct *);
162166 int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr);
163167 void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id);
include/net/bonding.h+2−1
@@ -200,7 +200,8 @@ struct bonding { · 199 unmodified lines
200200 struct slave __rcu *curr_active_slave;
201201 struct slave __rcu *current_arp_slave;
202202 struct slave __rcu *primary_slave;
203− struct bond_up_slave __rcu *slave_arr; /* Array of usable slaves */
203+ struct bond_up_slave __rcu *usable_slaves;
204+ struct bond_up_slave __rcu *all_slaves;
204205 bool force_primary;
205206 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
206207 int (*recv_probe)(const struct sk_buff *, struct bonding *,
net/core/dev.c+22−0
@@ -7861,6 +7861,28 @@ void netdev_bonding_info_change(struct net_device *dev, · 7860 unmodified lines
78617861 }
78627862 EXPORT_SYMBOL(netdev_bonding_info_change);
78637863
7864+/**
7865+ * netdev_get_xmit_slave - Get the xmit slave of master device
7866+ * @skb: The packet
7867+ * @all_slaves: assume all the slaves are active
7868+ *
7869+ * The reference counters are not incremented so the caller must be
7870+ * careful with locks. The caller must hold RCU lock.
7871+ * %NULL is returned if no slave is found.
7872+ */
7873+
7874+struct net_device *netdev_get_xmit_slave(struct net_device *dev,
7875+ struct sk_buff *skb,
7876+ bool all_slaves)
7877+{
7878+ const struct net_device_ops *ops = dev->netdev_ops;
7879+
7880+ if (!ops->ndo_get_xmit_slave)
7881+ return NULL;
7882+ return ops->ndo_get_xmit_slave(dev, skb, all_slaves);
7883+}
7884+EXPORT_SYMBOL(netdev_get_xmit_slave);
7885+
78647886 static void netdev_adjacent_add_links(struct net_device *dev)
78657887 {
78667888 struct netdev_adjacent *iter;