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
1331 return bond_tx_drop(bond->dev, skb);1331 return bond_tx_drop(bond->dev, skb);
1332}1332}
1333 1333
1334netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev)1334struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
1335 struct sk_buff *skb)
1335{1336{
1336 struct bonding *bond = netdev_priv(bond_dev);
1337 struct ethhdr *eth_data;
1338 struct slave *tx_slave = NULL;1337 struct slave *tx_slave = NULL;
1338 struct ethhdr *eth_data;
1339 u32 hash_index;1339 u32 hash_index;
1340 1340
1341 skb_reset_mac_header(skb);1341 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
1357 struct bond_up_slave *slaves;1357 struct bond_up_slave *slaves;
1358 unsigned int count;1358 unsigned int count;
1359 1359
1360 slaves = rcu_dereference(bond->slave_arr);1360 slaves = rcu_dereference(bond->usable_slaves);
1361 count = slaves ? READ_ONCE(slaves->count) : 0;1361 count = slaves ? READ_ONCE(slaves->count) : 0;
1362 if (likely(count))1362 if (likely(count))
1363 tx_slave = slaves->arr[hash_index %1363 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
1366 break;1366 break;
1367 }1367 }
1368 }1368 }
1369 return bond_do_alb_xmit(skb, bond, tx_slave);1369 return tx_slave;
1370}1370}
1371 1371
1372netdev_tx_t bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev)1372netdev_tx_t bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev)
1373{1373{
1374 struct bonding *bond = netdev_priv(bond_dev);1374 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
1381struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
1382 struct sk_buff *skb)
1383{
1376 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));1384 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
1377 struct slave *tx_slave = NULL;
1378 static const __be32 ip_bcast = htonl(0xffffffff);1385 static const __be32 ip_bcast = htonl(0xffffffff);
1379 int hash_size = 0;1386 struct slave *tx_slave = NULL;
1387 const u8 *hash_start = NULL;
1380 bool do_tx_balance = true;1388 bool do_tx_balance = true;
1389 struct ethhdr *eth_data;
1381 u32 hash_index = 0;1390 u32 hash_index = 0;
1382 const u8 *hash_start = NULL;1391 int hash_size = 0;
1383 1392
1384 skb_reset_mac_header(skb);1393 skb_reset_mac_header(skb);
1385 eth_data = eth_hdr(skb);1394 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
1491 struct bond_up_slave *slaves;1500 struct bond_up_slave *slaves;
1492 unsigned int count;1501 unsigned int count;
1493 1502
1494 slaves = rcu_dereference(bond->slave_arr);1503 slaves = rcu_dereference(bond->usable_slaves);
1495 count = slaves ? READ_ONCE(slaves->count) : 0;1504 count = slaves ? READ_ONCE(slaves->count) : 0;
1496 if (likely(count))1505 if (likely(count))
1497 tx_slave = slaves->arr[bond_xmit_hash(bond, skb) %1506 tx_slave = slaves->arr[bond_xmit_hash(bond, skb) %
1498 count];1507 count];
1499 }1508 }
1500 }1509 }
1510 return tx_slave;
1511}
1512
1513netdev_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;
1501 1517
1518 tx_slave = bond_xmit_alb_slave_get(bond, skb);
1502 return bond_do_alb_xmit(skb, bond, tx_slave);1519 return bond_do_alb_xmit(skb, bond, tx_slave);
1503}1520}
1504 1521
drivers/net/bonding/bond_main.c+186−66
@@ -3923,16 +3923,15 @@ unwind: · 3922 unmodified lines
3923}3923}
3924 3924
3925/**3925/**
3926 * bond_xmit_slave_id - transmit skb through slave with slave_id3926 * bond_get_slave_by_id - get xmit slave with slave_id
3927 * @bond: bonding device that is transmitting3927 * @bond: bonding device that is transmitting
3928 * @skb: buffer to transmit
3929 * @slave_id: slave id up to slave_cnt-1 through which to transmit3928 * @slave_id: slave id up to slave_cnt-1 through which to transmit
3930 *3929 *
3931 * This function tries to transmit through slave with slave_id but in case3930 * This function tries to get slave with slave_id but in case
3932 * it fails, it tries to find the first available slave for transmission.3931 * 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.
3934 */3932 */
3935static netdev_tx_t bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, int slave_id)3933static struct slave *bond_get_slave_by_id(struct bonding *bond,
3934 int slave_id)
3936{3935{
3937 struct list_head *iter;3936 struct list_head *iter;
3938 struct slave *slave;3937 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
3942 bond_for_each_slave_rcu(bond, slave, iter) {3941 bond_for_each_slave_rcu(bond, slave, iter) {
3943 if (--i < 0) {3942 if (--i < 0) {
3944 if (bond_slave_can_tx(slave))3943 if (bond_slave_can_tx(slave))
3945 return bond_dev_queue_xmit(bond, skb, slave->dev);3944 return slave;
3946 }3945 }
3947 }3946 }
3948 3947
@@ -3952,10 +3951,10 @@ static netdev_tx_t bond_xmit_slave_id(struct bonding *bond, struct sk_buff *skb, · 3 unmodified lines
3952 if (--i < 0)3951 if (--i < 0)
3953 break;3952 break;
3954 if (bond_slave_can_tx(slave))3953 if (bond_slave_can_tx(slave))
3955 return bond_dev_queue_xmit(bond, skb, slave->dev);3954 return slave;
3956 }3955 }
3957 /* no slave that can tx has been found */3956 /* no slave that can tx has been found */
3958 return bond_tx_drop(bond->dev, skb);3957 return NULL;
3959}3958}
3960 3959
3961/**3960/**
@@ -3991,10 +3990,9 @@ static u32 bond_rr_gen_slave_id(struct bonding *bond) · 29 unmodified lines
3991 return slave_id;3990 return slave_id;
3992}3991}
3993 3992
3994static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb,3993static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
3995 struct net_device *bond_dev)3994 struct sk_buff *skb)
3996{3995{
3997 struct bonding *bond = netdev_priv(bond_dev);
3998 struct slave *slave;3996 struct slave *slave;
3999 int slave_cnt;3997 int slave_cnt;
4000 u32 slave_id;3998 u32 slave_id;
@@ -4016,20 +4014,39 @@ static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb, · 15 unmodified lines
4016 if (iph->protocol == IPPROTO_IGMP) {4014 if (iph->protocol == IPPROTO_IGMP) {
4017 slave = rcu_dereference(bond->curr_active_slave);4015 slave = rcu_dereference(bond->curr_active_slave);
4018 if (slave)4016 if (slave)
4019 return bond_dev_queue_xmit(bond, skb, slave->dev);4017 return slave;
4020 return bond_xmit_slave_id(bond, skb, 0);4018 return bond_get_slave_by_id(bond, 0);
4021 }4019 }
4022 }4020 }
4023 4021
4024non_igmp:4022non_igmp:
4025 slave_cnt = READ_ONCE(bond->slave_cnt);4023 slave_cnt = READ_ONCE(bond->slave_cnt);
4026 if (likely(slave_cnt)) {4024 if (likely(slave_cnt)) {
4027 slave_id = bond_rr_gen_slave_id(bond);4025 slave_id = bond_rr_gen_slave_id(bond) % slave_cnt;
4028 return bond_xmit_slave_id(bond, skb, slave_id % slave_cnt);4026 return bond_get_slave_by_id(bond, slave_id);
4029 }4027 }
4028 return NULL;
4029}
4030
4031static 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
4030 return bond_tx_drop(bond_dev, skb);4041 return bond_tx_drop(bond_dev, skb);
4031}4042}
4032 4043
4044static 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
4033/* In active-backup mode, we know that bond->curr_active_slave is always valid if4050/* In active-backup mode, we know that bond->curr_active_slave is always valid if
4034 * the bond has a usable interface.4051 * the bond has a usable interface.
4035 */4052 */
@@ -4039,7 +4056,7 @@ static netdev_tx_t bond_xmit_activebackup(struct sk_buff *skb, · 3 unmodified lines
4039 struct bonding *bond = netdev_priv(bond_dev);4056 struct bonding *bond = netdev_priv(bond_dev);
4040 struct slave *slave;4057 struct slave *slave;
4041 4058
4042 slave = rcu_dereference(bond->curr_active_slave);4059 slave = bond_xmit_activebackup_slave_get(bond, skb);
4043 if (slave)4060 if (slave)
4044 return bond_dev_queue_xmit(bond, skb, slave->dev);4061 return bond_dev_queue_xmit(bond, skb, slave->dev);
4045 4062
@@ -4077,6 +4094,61 @@ err: · 31 unmodified lines
4077 bond_slave_arr_work_rearm(bond, 1);4094 bond_slave_arr_work_rearm(bond, 1);
4078}4095}
4079 4096
4097static 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
4120static 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
4135static 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
4080/* Build the usable slaves array in control path for modes that use xmit-hash4152/* Build the usable slaves array in control path for modes that use xmit-hash
4081 * to determine the slave interface -4153 * to determine the slave interface -
4082 * (a) BOND_MODE_8023AD4154 * (a) BOND_MODE_8023AD
@@ -4087,9 +4159,9 @@ err: · 4 unmodified lines
4087 */4159 */
4088int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)4160int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
4089{4161{
4162 struct bond_up_slave *usable_slaves = NULL, *all_slaves = NULL;
4090 struct slave *slave;4163 struct slave *slave;
4091 struct list_head *iter;4164 struct list_head *iter;
4092 struct bond_up_slave *new_arr, *old_arr;
4093 int agg_id = 0;4165 int agg_id = 0;
4094 int ret = 0;4166 int ret = 0;
4095 4167
@@ -4097,11 +4169,12 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave) · 1 unmodified line
4097 WARN_ON(lockdep_is_held(&bond->mode_lock));4169 WARN_ON(lockdep_is_held(&bond->mode_lock));
4098#endif4170#endif
4099 4171
4100 new_arr = kzalloc(offsetof(struct bond_up_slave, arr[bond->slave_cnt]),4172 usable_slaves = kzalloc(struct_size(usable_slaves, arr,
4101 GFP_KERNEL);4173 bond->slave_cnt), GFP_KERNEL);
4102 if (!new_arr) {4174 all_slaves = kzalloc(struct_size(all_slaves, arr,
4175 bond->slave_cnt), GFP_KERNEL);
4176 if (!usable_slaves || !all_slaves) {
4103 ret = -ENOMEM;4177 ret = -ENOMEM;
4104 pr_err("Failed to build slave-array.\n");
4105 goto out;4178 goto out;
4106 }4179 }
4107 if (BOND_MODE(bond) == BOND_MODE_8023AD) {4180 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
4109 4182
4110 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {4183 if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
4111 pr_debug("bond_3ad_get_active_agg_info failed\n");4184 pr_debug("bond_3ad_get_active_agg_info failed\n");
4112 kfree_rcu(new_arr, rcu);
4113 /* No active aggragator means it's not safe to use4185 /* No active aggragator means it's not safe to use
4114 * the previous array.4186 * the previous array.
4115 */4187 */
4116 old_arr = rtnl_dereference(bond->slave_arr);4188 bond_reset_slave_arr(bond);
4117 if (old_arr) {
4118 RCU_INIT_POINTER(bond->slave_arr, NULL);
4119 kfree_rcu(old_arr, rcu);
4120 }
4121 goto out;4189 goto out;
4122 }4190 }
4123 agg_id = ad_info.aggregator_id;4191 agg_id = ad_info.aggregator_id;
4124 }4192 }
4125 bond_for_each_slave(bond, slave, iter) {4193 bond_for_each_slave(bond, slave, iter) {
4194 if (skipslave == slave)
4195 continue;
4196
4197 all_slaves->arr[all_slaves->count++] = slave;
4126 if (BOND_MODE(bond) == BOND_MODE_8023AD) {4198 if (BOND_MODE(bond) == BOND_MODE_8023AD) {
4127 struct aggregator *agg;4199 struct aggregator *agg;
4128 4200
@@ -4132,44 +4204,45 @@ int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave) · 3 unmodified lines
4132 }4204 }
4133 if (!bond_slave_can_tx(slave))4205 if (!bond_slave_can_tx(slave))
4134 continue;4206 continue;
4135 if (skipslave == slave)
4136 continue;
4137 4207
4138 slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",4208 slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
4139 new_arr->count);4209 usable_slaves->count);
4140 4210
4141 new_arr->arr[new_arr->count++] = slave;4211 usable_slaves->arr[usable_slaves->count++] = slave;
4142 }4212 }
4143 4213
4144 old_arr = rtnl_dereference(bond->slave_arr);4214 bond_set_slave_arr(bond, usable_slaves, all_slaves);
4145 rcu_assign_pointer(bond->slave_arr, new_arr);4215 return ret;
4146 if (old_arr)
4147 kfree_rcu(old_arr, rcu);
4148out:4216out:
4149 if (ret != 0 && skipslave) {4217 if (ret != 0 && skipslave) {
4150 int idx;4218 bond_skip_slave(rtnl_dereference(bond->all_slaves),
4151 4219 skipslave);
4152 /* Rare situation where caller has asked to skip a specific4220 bond_skip_slave(rtnl_dereference(bond->usable_slaves),
4153 * slave but allocation failed (most likely!). BTW this is4221 skipslave);
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 }
4169 }4222 }
4223 kfree_rcu(all_slaves, rcu);
4224 kfree_rcu(usable_slaves, rcu);
4225
4170 return ret;4226 return ret;
4171}4227}
4172 4228
4229static 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
4173/* Use this Xmit function for 3AD as well as XOR modes. The current4246/* Use this Xmit function for 3AD as well as XOR modes. The current
4174 * usable slave array is formed in the control path. The xmit function4247 * usable slave array is formed in the control path. The xmit function
4175 * just calculates hash and sends the packet out.4248 * 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
4178 struct net_device *dev)4251 struct net_device *dev)
4179{4252{
4180 struct bonding *bond = netdev_priv(dev);4253 struct bonding *bond = netdev_priv(dev);
4181 struct slave *slave;
4182 struct bond_up_slave *slaves;4254 struct bond_up_slave *slaves;
4183 unsigned int count;4255 struct slave *slave;
4184 4256
4185 slaves = rcu_dereference(bond->slave_arr);4257 slaves = rcu_dereference(bond->usable_slaves);
4186 count = slaves ? READ_ONCE(slaves->count) : 0;4258 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4187 if (likely(count)) {4259 if (likely(slave))
4188 slave = slaves->arr[bond_xmit_hash(bond, skb) % count];
4189 return bond_dev_queue_xmit(bond, skb, slave->dev);4260 return bond_dev_queue_xmit(bond, skb, slave->dev);
4190 }4261
4191 return bond_tx_drop(dev, skb);4262 return bond_tx_drop(dev, skb);
4192}4263}
4193 4264
@@ -4269,6 +4340,48 @@ static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb, · 75 unmodified lines
4269 return txq;4340 return txq;
4270}4341}
4271 4342
4343static 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
4272static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev)4385static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
4273{4386{
4274 struct bonding *bond = netdev_priv(dev);4387 struct bonding *bond = netdev_priv(dev);
@@ -4389,6 +4502,7 @@ static const struct net_device_ops bond_netdev_ops = { · 114 unmodified lines
4389 .ndo_del_slave = bond_release,4502 .ndo_del_slave = bond_release,
4390 .ndo_fix_features = bond_fix_features,4503 .ndo_fix_features = bond_fix_features,
4391 .ndo_features_check = passthru_features_check,4504 .ndo_features_check = passthru_features_check,
4505 .ndo_get_xmit_slave = bond_xmit_get_slave,
4392};4506};
4393 4507
4394static const struct device_type bond_type = {4508static const struct device_type bond_type = {
@@ -4456,9 +4570,9 @@ void bond_setup(struct net_device *bond_dev) · 61 unmodified lines
4456static void bond_uninit(struct net_device *bond_dev)4570static void bond_uninit(struct net_device *bond_dev)
4457{4571{
4458 struct bonding *bond = netdev_priv(bond_dev);4572 struct bonding *bond = netdev_priv(bond_dev);
4573 struct bond_up_slave *usable, *all;
4459 struct list_head *iter;4574 struct list_head *iter;
4460 struct slave *slave;4575 struct slave *slave;
4461 struct bond_up_slave *arr;
4462 4576
4463 bond_netpoll_cleanup(bond_dev);4577 bond_netpoll_cleanup(bond_dev);
4464 4578
@@ -4467,10 +4581,16 @@ static void bond_uninit(struct net_device *bond_dev) · 2 unmodified lines
4467 __bond_release_one(bond_dev, slave->dev, true, true);4581 __bond_release_one(bond_dev, slave->dev, true, true);
4468 netdev_info(bond_dev, "Released all slaves\n");4582 netdev_info(bond_dev, "Released all slaves\n");
4469 4583
4470 arr = rtnl_dereference(bond->slave_arr);4584 usable = rtnl_dereference(bond->usable_slaves);
4471 if (arr) {4585 if (usable) {
4472 RCU_INIT_POINTER(bond->slave_arr, NULL);4586 RCU_INIT_POINTER(bond->usable_slaves, NULL);
4473 kfree_rcu(arr, rcu);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);
4474 }4594 }
4475 4595
4476 list_del(&bond->bond_list);4596 list_del(&bond->bond_list);
drivers/net/ethernet/mellanox/mlx5/core/lag.c+45−21
@@ -42,7 +42,7 @@ · 41 unmodified lines
42 * Beware of lock dependencies (preferably, no locks should be acquired42 * Beware of lock dependencies (preferably, no locks should be acquired
43 * under it).43 * under it).
44 */44 */
45static DEFINE_MUTEX(lag_mutex);45static DEFINE_SPINLOCK(lag_lock);
46 46
47static int mlx5_cmd_create_lag(struct mlx5_core_dev *dev, u8 remap_port1,47static int mlx5_cmd_create_lag(struct mlx5_core_dev *dev, u8 remap_port1,
48 u8 remap_port2)48 u8 remap_port2)
@@ -274,9 +274,9 @@ static void mlx5_do_bond(struct mlx5_lag *ldev) · 225 unmodified lines
274 if (!dev0 || !dev1)274 if (!dev0 || !dev1)
275 return;275 return;
276 276
277 mutex_lock(&lag_mutex);277 spin_lock(&lag_lock);
278 tracker = ldev->tracker;278 tracker = ldev->tracker;
279 mutex_unlock(&lag_mutex);279 spin_unlock(&lag_lock);
280 280
281 do_bond = tracker.is_bonded && mlx5_lag_check_prereq(ldev);281 do_bond = tracker.is_bonded && mlx5_lag_check_prereq(ldev);
282 282
@@ -458,9 +458,9 @@ static int mlx5_lag_netdev_event(struct notifier_block *this, · 175 unmodified lines
458 break;458 break;
459 }459 }
460 460
461 mutex_lock(&lag_mutex);461 spin_lock(&lag_lock);
462 ldev->tracker = tracker;462 ldev->tracker = tracker;
463 mutex_unlock(&lag_mutex);463 spin_unlock(&lag_lock);
464 464
465 if (changed)465 if (changed)
466 mlx5_queue_bond_work(ldev, 0);466 mlx5_queue_bond_work(ldev, 0);
@@ -502,7 +502,7 @@ static void mlx5_lag_dev_add_pf(struct mlx5_lag *ldev, · 35 unmodified lines
502 if (fn >= MLX5_MAX_PORTS)502 if (fn >= MLX5_MAX_PORTS)
503 return;503 return;
504 504
505 mutex_lock(&lag_mutex);505 spin_lock(&lag_lock);
506 ldev->pf[fn].dev = dev;506 ldev->pf[fn].dev = dev;
507 ldev->pf[fn].netdev = netdev;507 ldev->pf[fn].netdev = netdev;
508 ldev->tracker.netdev_state[fn].link_up = 0;508 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
510 510
511 dev->priv.lag = ldev;511 dev->priv.lag = ldev;
512 512
513 mutex_unlock(&lag_mutex);513 spin_unlock(&lag_lock);
514}514}
515 515
516static void mlx5_lag_dev_remove_pf(struct mlx5_lag *ldev,516static 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
525 if (i == MLX5_MAX_PORTS)525 if (i == MLX5_MAX_PORTS)
526 return;526 return;
527 527
528 mutex_lock(&lag_mutex);528 spin_lock(&lag_lock);
529 memset(&ldev->pf[i], 0, sizeof(*ldev->pf));529 memset(&ldev->pf[i], 0, sizeof(*ldev->pf));
530 530
531 dev->priv.lag = NULL;531 dev->priv.lag = NULL;
532 mutex_unlock(&lag_mutex);532 spin_unlock(&lag_lock);
533}533}
534 534
535/* Must be called with intf_mutex held */535/* Must be called with intf_mutex held */
@@ -607,10 +607,10 @@ bool mlx5_lag_is_roce(struct mlx5_core_dev *dev) · 71 unmodified lines
607 struct mlx5_lag *ldev;607 struct mlx5_lag *ldev;
608 bool res;608 bool res;
609 609
610 mutex_lock(&lag_mutex);610 spin_lock(&lag_lock);
611 ldev = mlx5_lag_dev_get(dev);611 ldev = mlx5_lag_dev_get(dev);
612 res = ldev && __mlx5_lag_is_roce(ldev);612 res = ldev && __mlx5_lag_is_roce(ldev);
613 mutex_unlock(&lag_mutex);613 spin_unlock(&lag_lock);
614 614
615 return res;615 return res;
616}616}
@@ -621,10 +621,10 @@ bool mlx5_lag_is_active(struct mlx5_core_dev *dev) · 4 unmodified lines
621 struct mlx5_lag *ldev;621 struct mlx5_lag *ldev;
622 bool res;622 bool res;
623 623
624 mutex_lock(&lag_mutex);624 spin_lock(&lag_lock);
625 ldev = mlx5_lag_dev_get(dev);625 ldev = mlx5_lag_dev_get(dev);
626 res = ldev && __mlx5_lag_is_active(ldev);626 res = ldev && __mlx5_lag_is_active(ldev);
627 mutex_unlock(&lag_mutex);627 spin_unlock(&lag_lock);
628 628
629 return res;629 return res;
630}630}
@@ -635,10 +635,10 @@ bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev) · 4 unmodified lines
635 struct mlx5_lag *ldev;635 struct mlx5_lag *ldev;
636 bool res;636 bool res;
637 637
638 mutex_lock(&lag_mutex);638 spin_lock(&lag_lock);
639 ldev = mlx5_lag_dev_get(dev);639 ldev = mlx5_lag_dev_get(dev);
640 res = ldev && __mlx5_lag_is_sriov(ldev);640 res = ldev && __mlx5_lag_is_sriov(ldev);
641 mutex_unlock(&lag_mutex);641 spin_unlock(&lag_lock);
642 642
643 return res;643 return res;
644}644}
@@ -664,7 +664,7 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev) · 19 unmodified lines
664 struct net_device *ndev = NULL;664 struct net_device *ndev = NULL;
665 struct mlx5_lag *ldev;665 struct mlx5_lag *ldev;
666 666
667 mutex_lock(&lag_mutex);667 spin_lock(&lag_lock);
668 ldev = mlx5_lag_dev_get(dev);668 ldev = mlx5_lag_dev_get(dev);
669 669
670 if (!(ldev && __mlx5_lag_is_roce(ldev)))670 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
681 dev_hold(ndev);681 dev_hold(ndev);
682 682
683unlock:683unlock:
684 mutex_unlock(&lag_mutex);684 spin_unlock(&lag_lock);
685 685
686 return ndev;686 return ndev;
687}687}
688EXPORT_SYMBOL(mlx5_lag_get_roce_netdev);688EXPORT_SYMBOL(mlx5_lag_get_roce_netdev);
689 689
690u8 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
708unlock:
709 spin_unlock(&lag_lock);
710 return port;
711}
712EXPORT_SYMBOL(mlx5_lag_get_slave_port);
713
690bool mlx5_lag_intf_add(struct mlx5_interface *intf, struct mlx5_priv *priv)714bool mlx5_lag_intf_add(struct mlx5_interface *intf, struct mlx5_priv *priv)
691{715{
692 struct mlx5_core_dev *dev = container_of(priv, struct mlx5_core_dev,716 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
723 747
724 memset(values, 0, sizeof(*values) * num_counters);748 memset(values, 0, sizeof(*values) * num_counters);
725 749
726 mutex_lock(&lag_mutex);750 spin_lock(&lag_lock);
727 ldev = mlx5_lag_dev_get(dev);751 ldev = mlx5_lag_dev_get(dev);
728 if (ldev && __mlx5_lag_is_roce(ldev)) {752 if (ldev && __mlx5_lag_is_roce(ldev)) {
729 num_ports = MLX5_MAX_PORTS;753 num_ports = MLX5_MAX_PORTS;
@@ -733,6 +757,7 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev, · 3 unmodified lines
733 num_ports = 1;757 num_ports = 1;
734 mdev[MLX5_LAG_P1] = dev;758 mdev[MLX5_LAG_P1] = dev;
735 }759 }
760 spin_unlock(&lag_lock);
736 761
737 for (i = 0; i < num_ports; ++i) {762 for (i = 0; i < num_ports; ++i) {
738 u32 in[MLX5_ST_SZ_DW(query_cong_statistics_in)] = {};763 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
742 ret = mlx5_cmd_exec_inout(mdev[i], query_cong_statistics, in,767 ret = mlx5_cmd_exec_inout(mdev[i], query_cong_statistics, in,
743 out);768 out);
744 if (ret)769 if (ret)
745 goto unlock;770 goto free;
746 771
747 for (j = 0; j < num_counters; ++j)772 for (j = 0; j < num_counters; ++j)
748 values[j] += be64_to_cpup((__be64 *)(out + offsets[j]));773 values[j] += be64_to_cpup((__be64 *)(out + offsets[j]));
749 }774 }
750 775
751unlock:776free:
752 mutex_unlock(&lag_mutex);
753 kvfree(out);777 kvfree(out);
754 return ret;778 return ret;
755}779}
include/linux/mlx5/driver.h+2−0
@@ -1074,6 +1074,8 @@ bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev); · 1073 unmodified lines
1074bool mlx5_lag_is_multipath(struct mlx5_core_dev *dev);1074bool mlx5_lag_is_multipath(struct mlx5_core_dev *dev);
1075bool mlx5_lag_is_active(struct mlx5_core_dev *dev);1075bool mlx5_lag_is_active(struct mlx5_core_dev *dev);
1076struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev);1076struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev);
1077u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev,
1078 struct net_device *slave);
1077int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,1079int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
1078 u64 *values,1080 u64 *values,
1079 int num_counters,1081 int num_counters,
include/linux/netdevice.h+12−0
@@ -1148,6 +1148,12 @@ struct netdev_net_notifier { · 1147 unmodified lines
1148 * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);1148 * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);
1149 * Called to release previously enslaved netdev.1149 * Called to release previously enslaved netdev.
1150 *1150 *
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 *
1151 * Feature/offload setting functions.1157 * Feature/offload setting functions.
1152 * netdev_features_t (*ndo_fix_features)(struct net_device *dev,1158 * netdev_features_t (*ndo_fix_features)(struct net_device *dev,
1153 * netdev_features_t features);1159 * netdev_features_t features);
@@ -1391,6 +1397,9 @@ struct net_device_ops { · 237 unmodified lines
1391 struct netlink_ext_ack *extack);1397 struct netlink_ext_ack *extack);
1392 int (*ndo_del_slave)(struct net_device *dev,1398 int (*ndo_del_slave)(struct net_device *dev,
1393 struct net_device *slave_dev);1399 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);
1394 netdev_features_t (*ndo_fix_features)(struct net_device *dev,1403 netdev_features_t (*ndo_fix_features)(struct net_device *dev,
1395 netdev_features_t features);1404 netdev_features_t features);
1396 int (*ndo_set_features)(struct net_device *dev,1405 int (*ndo_set_features)(struct net_device *dev,
@@ -2745,6 +2754,9 @@ void netdev_freemem(struct net_device *dev); · 1348 unmodified lines
2745void synchronize_net(void);2754void synchronize_net(void);
2746int init_dummy_netdev(struct net_device *dev);2755int init_dummy_netdev(struct net_device *dev);
2747 2756
2757struct net_device *netdev_get_xmit_slave(struct net_device *dev,
2758 struct sk_buff *skb,
2759 bool all_slaves);
2748struct net_device *dev_get_by_index(struct net *net, int ifindex);2760struct net_device *dev_get_by_index(struct net *net, int ifindex);
2749struct net_device *__dev_get_by_index(struct net *net, int ifindex);2761struct net_device *__dev_get_by_index(struct net *net, int ifindex);
2750struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);2762struct 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
158void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave);158void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave);
159int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev);159int bond_alb_xmit(struct sk_buff *skb, struct net_device *bond_dev);
160int bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev);160int bond_tlb_xmit(struct sk_buff *skb, struct net_device *bond_dev);
161struct slave *bond_xmit_alb_slave_get(struct bonding *bond,
162 struct sk_buff *skb);
163struct slave *bond_xmit_tlb_slave_get(struct bonding *bond,
164 struct sk_buff *skb);
161void bond_alb_monitor(struct work_struct *);165void bond_alb_monitor(struct work_struct *);
162int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr);166int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr);
163void bond_alb_clear_vlan(struct bonding *bond, unsigned short vlan_id);167void 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
200 struct slave __rcu *curr_active_slave;200 struct slave __rcu *curr_active_slave;
201 struct slave __rcu *current_arp_slave;201 struct slave __rcu *current_arp_slave;
202 struct slave __rcu *primary_slave;202 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;
204 bool force_primary;205 bool force_primary;
205 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */206 s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
206 int (*recv_probe)(const struct sk_buff *, struct bonding *,207 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
7861}7861}
7862EXPORT_SYMBOL(netdev_bonding_info_change);7862EXPORT_SYMBOL(netdev_bonding_info_change);
7863 7863
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
7874struct 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}
7884EXPORT_SYMBOL(netdev_get_xmit_slave);
7885
7864static void netdev_adjacent_add_links(struct net_device *dev)7886static void netdev_adjacent_add_links(struct net_device *dev)
7865{7887{
7866 struct netdev_adjacent *iter;7888 struct netdev_adjacent *iter;