Skip to content

Commit 7c34ec1

Browse files
Aviv HellerSaeed Mahameed
authored andcommitted
net/mlx5: Make RoCE and SR-IOV LAG modes explicit
With the introduction of SR-IOV LAG, checking whether LAG is active is no longer good enough, since RoCE and SR-IOV LAG each entails different behavior by both the core and infiniband drivers. This patch introduces facilities to discern LAG type, in addition to mlx5_lag_is_active(). These are implemented in such a way as to allow more complex mode combinations in the future. Signed-off-by: Aviv Heller <[email protected]> Reviewed-by: Roi Dayan <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 292612d commit 7c34ec1

File tree

8 files changed

+79
-26
lines changed

8 files changed

+79
-26
lines changed

drivers/infiniband/hw/mlx5/main.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static int mlx5_query_port_roce(struct ib_device *device, u8 port_num,
445445
if (!ndev)
446446
goto out;
447447

448-
if (mlx5_lag_is_active(dev->mdev)) {
448+
if (dev->lag_active) {
449449
rcu_read_lock();
450450
upper = netdev_master_upper_dev_get_rcu(ndev);
451451
if (upper) {
@@ -1848,7 +1848,7 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
18481848
context->lib_caps = req.lib_caps;
18491849
print_lib_caps(dev, context->lib_caps);
18501850

1851-
if (mlx5_lag_is_active(dev->mdev)) {
1851+
if (dev->lag_active) {
18521852
u8 port = mlx5_core_native_port_num(dev->mdev);
18531853

18541854
atomic_set(&context->tx_port_affinity,
@@ -4841,7 +4841,7 @@ static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev)
48414841
struct mlx5_flow_table *ft;
48424842
int err;
48434843

4844-
if (!ns || !mlx5_lag_is_active(mdev))
4844+
if (!ns || !mlx5_lag_is_roce(mdev))
48454845
return 0;
48464846

48474847
err = mlx5_cmd_create_vport_lag(mdev);
@@ -4855,6 +4855,7 @@ static int mlx5_eth_lag_init(struct mlx5_ib_dev *dev)
48554855
}
48564856

48574857
dev->flow_db->lag_demux_ft = ft;
4858+
dev->lag_active = true;
48584859
return 0;
48594860

48604861
err_destroy_vport_lag:
@@ -4866,7 +4867,9 @@ static void mlx5_eth_lag_cleanup(struct mlx5_ib_dev *dev)
48664867
{
48674868
struct mlx5_core_dev *mdev = dev->mdev;
48684869

4869-
if (dev->flow_db->lag_demux_ft) {
4870+
if (dev->lag_active) {
4871+
dev->lag_active = false;
4872+
48704873
mlx5_destroy_flow_table(dev->flow_db->lag_demux_ft);
48714874
dev->flow_db->lag_demux_ft = NULL;
48724875

@@ -6173,7 +6176,7 @@ int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev)
61736176
const char *name;
61746177

61756178
rdma_set_device_sysfs_group(&dev->ib_dev, &mlx5_attr_group);
6176-
if (!mlx5_lag_is_active(dev->mdev))
6179+
if (!mlx5_lag_is_roce(dev->mdev))
61776180
name = "mlx5_%d";
61786181
else
61796182
name = "mlx5_bond_%d";

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ struct mlx5_ib_dev {
936936
struct mlx5_ib_delay_drop delay_drop;
937937
const struct mlx5_ib_profile *profile;
938938
struct mlx5_eswitch_rep *rep;
939+
int lag_active;
939940

940941
struct mlx5_ib_lb_state lb;
941942
u8 umr_fence;

drivers/infiniband/hw/mlx5/qp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3258,7 +3258,7 @@ static int __mlx5_ib_modify_qp(struct ib_qp *ibqp,
32583258
(ibqp->qp_type == IB_QPT_RAW_PACKET) ||
32593259
(ibqp->qp_type == IB_QPT_XRC_INI) ||
32603260
(ibqp->qp_type == IB_QPT_XRC_TGT)) {
3261-
if (mlx5_lag_is_active(dev->mdev)) {
3261+
if (dev->lag_active) {
32623262
u8 p = mlx5_core_native_port_num(dev->mdev);
32633263
tx_affinity = get_tx_affinity(dev, pd, base, p);
32643264
context->flags |= cpu_to_be32(tx_affinity << 24);

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static int mlx5e_route_lookup_ipv4(struct mlx5e_priv *priv,
3535
dst_is_lag_dev = (uplink_upper &&
3636
netif_is_lag_master(uplink_upper) &&
3737
rt->dst.dev == uplink_upper &&
38-
mlx5_lag_is_active(priv->mdev));
38+
mlx5_lag_is_sriov(priv->mdev));
3939

4040
/* if the egress device isn't on the same HW e-switch or
4141
* it's a LAG device, use the uplink
@@ -94,7 +94,7 @@ static int mlx5e_route_lookup_ipv6(struct mlx5e_priv *priv,
9494
dst_is_lag_dev = (uplink_upper &&
9595
netif_is_lag_master(uplink_upper) &&
9696
dst->dev == uplink_upper &&
97-
mlx5_lag_is_active(priv->mdev));
97+
mlx5_lag_is_sriov(priv->mdev));
9898

9999
/* if the egress device isn't on the same HW e-switch or
100100
* it's a LAG device, use the uplink

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ int mlx5e_attr_get(struct net_device *dev, struct switchdev_attr *attr)
314314
switch (attr->id) {
315315
case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
316316
attr->u.ppid.id_len = ETH_ALEN;
317-
if (uplink_upper && mlx5_lag_is_active(uplink_priv->mdev)) {
317+
if (uplink_upper && mlx5_lag_is_sriov(uplink_priv->mdev)) {
318318
ether_addr_copy(attr->u.ppid.id, uplink_upper->dev_addr);
319319
} else {
320320
struct mlx5e_rep_priv *rpriv = priv->ppriv;

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2718,7 +2718,7 @@ static bool is_peer_flow_needed(struct mlx5e_tc_flow *flow)
27182718
bool esw_paired = mlx5_devcom_is_paired(attr->in_mdev->priv.devcom,
27192719
MLX5_DEVCOM_ESW_OFFLOADS);
27202720

2721-
return esw_paired && mlx5_lag_is_active(attr->in_mdev) &&
2721+
return esw_paired && mlx5_lag_is_sriov(attr->in_mdev) &&
27222722
(is_rep_ingress || act_is_encap);
27232723
}
27242724

drivers/net/ethernet/mellanox/mlx5/core/lag.c

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@
3737
#include "eswitch.h"
3838

3939
enum {
40-
MLX5_LAG_FLAG_BONDED = 1 << 0,
40+
MLX5_LAG_FLAG_ROCE = 1 << 0,
41+
MLX5_LAG_FLAG_SRIOV = 1 << 1,
4142
};
4243

44+
#define MLX5_LAG_MODE_FLAGS (MLX5_LAG_FLAG_ROCE | MLX5_LAG_FLAG_SRIOV)
45+
4346
struct lag_func {
4447
struct mlx5_core_dev *dev;
4548
struct net_device *netdev;
@@ -161,9 +164,19 @@ static int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev,
161164
return -1;
162165
}
163166

167+
static bool __mlx5_lag_is_roce(struct mlx5_lag *ldev)
168+
{
169+
return !!(ldev->flags & MLX5_LAG_FLAG_ROCE);
170+
}
171+
172+
static bool __mlx5_lag_is_sriov(struct mlx5_lag *ldev)
173+
{
174+
return !!(ldev->flags & MLX5_LAG_FLAG_SRIOV);
175+
}
176+
164177
static bool __mlx5_lag_is_active(struct mlx5_lag *ldev)
165178
{
166-
return !!(ldev->flags & MLX5_LAG_FLAG_BONDED);
179+
return !!(ldev->flags & MLX5_LAG_MODE_FLAGS);
167180
}
168181

169182
static void mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker,
@@ -229,9 +242,10 @@ static int mlx5_create_lag(struct mlx5_lag *ldev,
229242
}
230243

231244
static void mlx5_activate_lag(struct mlx5_lag *ldev,
232-
struct lag_tracker *tracker)
245+
struct lag_tracker *tracker,
246+
u8 flags)
233247
{
234-
ldev->flags |= MLX5_LAG_FLAG_BONDED;
248+
ldev->flags |= flags;
235249
mlx5_create_lag(ldev, tracker);
236250
}
237251

@@ -240,7 +254,7 @@ static void mlx5_deactivate_lag(struct mlx5_lag *ldev)
240254
struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
241255
int err;
242256

243-
ldev->flags &= ~MLX5_LAG_FLAG_BONDED;
257+
ldev->flags &= ~MLX5_LAG_MODE_FLAGS;
244258

245259
err = mlx5_cmd_destroy_lag(dev0);
246260
if (err)
@@ -263,44 +277,49 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)
263277
{
264278
struct mlx5_core_dev *dev0 = ldev->pf[0].dev;
265279
struct mlx5_core_dev *dev1 = ldev->pf[1].dev;
266-
bool do_bond, sriov_enabled;
267280
struct lag_tracker tracker;
281+
bool do_bond, roce_lag;
268282
int i;
269283

270284
if (!dev0 || !dev1)
271285
return;
272286

273-
sriov_enabled = mlx5_sriov_is_enabled(dev0) || mlx5_sriov_is_enabled(dev1);
274-
275287
mutex_lock(&lag_mutex);
276288
tracker = ldev->tracker;
277289
mutex_unlock(&lag_mutex);
278290

279291
do_bond = tracker.is_bonded && mlx5_lag_check_prereq(ldev);
280292

281293
if (do_bond && !__mlx5_lag_is_active(ldev)) {
282-
if (!sriov_enabled)
294+
roce_lag = !mlx5_sriov_is_enabled(dev0) &&
295+
!mlx5_sriov_is_enabled(dev1);
296+
297+
if (roce_lag)
283298
for (i = 0; i < MLX5_MAX_PORTS; i++)
284299
mlx5_remove_dev_by_protocol(ldev->pf[i].dev,
285300
MLX5_INTERFACE_PROTOCOL_IB);
286301

287-
mlx5_activate_lag(ldev, &tracker);
302+
mlx5_activate_lag(ldev, &tracker,
303+
roce_lag ? MLX5_LAG_FLAG_ROCE :
304+
MLX5_LAG_FLAG_SRIOV);
288305

289-
if (!sriov_enabled) {
306+
if (roce_lag) {
290307
mlx5_add_dev_by_protocol(dev0, MLX5_INTERFACE_PROTOCOL_IB);
291308
mlx5_nic_vport_enable_roce(dev1);
292309
}
293310
} else if (do_bond && __mlx5_lag_is_active(ldev)) {
294311
mlx5_modify_lag(ldev, &tracker);
295312
} else if (!do_bond && __mlx5_lag_is_active(ldev)) {
296-
if (!sriov_enabled) {
313+
roce_lag = __mlx5_lag_is_roce(ldev);
314+
315+
if (roce_lag) {
297316
mlx5_remove_dev_by_protocol(dev0, MLX5_INTERFACE_PROTOCOL_IB);
298317
mlx5_nic_vport_disable_roce(dev1);
299318
}
300319

301320
mlx5_deactivate_lag(ldev);
302321

303-
if (!sriov_enabled)
322+
if (roce_lag)
304323
for (i = 0; i < MLX5_MAX_PORTS; i++)
305324
if (ldev->pf[i].dev)
306325
mlx5_add_dev_by_protocol(ldev->pf[i].dev,
@@ -572,6 +591,20 @@ void mlx5_lag_remove(struct mlx5_core_dev *dev)
572591
}
573592
}
574593

594+
bool mlx5_lag_is_roce(struct mlx5_core_dev *dev)
595+
{
596+
struct mlx5_lag *ldev;
597+
bool res;
598+
599+
mutex_lock(&lag_mutex);
600+
ldev = mlx5_lag_dev_get(dev);
601+
res = ldev && __mlx5_lag_is_roce(ldev);
602+
mutex_unlock(&lag_mutex);
603+
604+
return res;
605+
}
606+
EXPORT_SYMBOL(mlx5_lag_is_roce);
607+
575608
bool mlx5_lag_is_active(struct mlx5_core_dev *dev)
576609
{
577610
struct mlx5_lag *ldev;
@@ -586,6 +619,20 @@ bool mlx5_lag_is_active(struct mlx5_core_dev *dev)
586619
}
587620
EXPORT_SYMBOL(mlx5_lag_is_active);
588621

622+
bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev)
623+
{
624+
struct mlx5_lag *ldev;
625+
bool res;
626+
627+
mutex_lock(&lag_mutex);
628+
ldev = mlx5_lag_dev_get(dev);
629+
res = ldev && __mlx5_lag_is_sriov(ldev);
630+
mutex_unlock(&lag_mutex);
631+
632+
return res;
633+
}
634+
EXPORT_SYMBOL(mlx5_lag_is_sriov);
635+
589636
void mlx5_lag_update(struct mlx5_core_dev *dev)
590637
{
591638
struct mlx5_lag *ldev;
@@ -609,7 +656,7 @@ struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev)
609656
mutex_lock(&lag_mutex);
610657
ldev = mlx5_lag_dev_get(dev);
611658

612-
if (!(ldev && __mlx5_lag_is_active(ldev)))
659+
if (!(ldev && __mlx5_lag_is_roce(ldev)))
613660
goto unlock;
614661

615662
if (ldev->tracker.tx_type == NETDEV_LAG_TX_TYPE_ACTIVEBACKUP) {
@@ -638,7 +685,7 @@ bool mlx5_lag_intf_add(struct mlx5_interface *intf, struct mlx5_priv *priv)
638685
return true;
639686

640687
ldev = mlx5_lag_dev_get(dev);
641-
if (!ldev || !__mlx5_lag_is_active(ldev) || ldev->pf[0].dev == dev)
688+
if (!ldev || !__mlx5_lag_is_roce(ldev) || ldev->pf[0].dev == dev)
642689
return true;
643690

644691
/* If bonded, we do not add an IB device for PF1. */
@@ -665,7 +712,7 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
665712

666713
mutex_lock(&lag_mutex);
667714
ldev = mlx5_lag_dev_get(dev);
668-
if (ldev && __mlx5_lag_is_active(ldev)) {
715+
if (ldev && __mlx5_lag_is_roce(ldev)) {
669716
num_ports = MLX5_MAX_PORTS;
670717
mdev[0] = ldev->pf[0].dev;
671718
mdev[1] = ldev->pf[1].dev;

include/linux/mlx5/driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,8 @@ int mlx5_core_query_vendor_id(struct mlx5_core_dev *mdev, u32 *vendor_id);
10191019

10201020
int mlx5_cmd_create_vport_lag(struct mlx5_core_dev *dev);
10211021
int mlx5_cmd_destroy_vport_lag(struct mlx5_core_dev *dev);
1022+
bool mlx5_lag_is_roce(struct mlx5_core_dev *dev);
1023+
bool mlx5_lag_is_sriov(struct mlx5_core_dev *dev);
10221024
bool mlx5_lag_is_active(struct mlx5_core_dev *dev);
10231025
struct net_device *mlx5_lag_get_roce_netdev(struct mlx5_core_dev *dev);
10241026
int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,

0 commit comments

Comments
 (0)