Skip to content

Commit c85023e

Browse files
Huy Nguyendledford
authored andcommitted
IB/mlx5: Add raw ethernet local loopback support
Currently, unicast/multicast loopback raw ethernet (non-RDMA) packets are sent back to the vport. A unicast loopback packet is the packet with destination MAC address the same as the source MAC address. For multicast, the destination MAC address is in the vport's multicast filter list. Moreover, the local loopback is not needed if there is one or none user space context. After this patch, the raw ethernet unicast and multicast local loopback are disabled by default. When there is more than one user space context, the local loopback is enabled. Note that when local loopback is disabled, raw ethernet packets are not looped back to the vport and are forwarded to the next routing level (eswitch, or multihost switch, or out to the wire depending on the configuration). Signed-off-by: Huy Nguyen <huyn@mellanox.com> Reviewed-by: Daniel Jurgens <danielj@mellanox.com> Signed-off-by: Leon Romanovsky <leon@kernel.org> Signed-off-by: Doug Ledford <dledford@redhat.com>
1 parent bded747 commit c85023e

File tree

3 files changed

+73
-7
lines changed

3 files changed

+73
-7
lines changed

drivers/infiniband/hw/mlx5/main.c

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <linux/mlx5/vport.h>
5959
#include "mlx5_ib.h"
6060
#include "cmd.h"
61+
#include <linux/mlx5/vport.h>
6162

6263
#define DRIVER_NAME "mlx5_ib"
6364
#define DRIVER_VERSION "5.0-0"
@@ -1187,6 +1188,45 @@ static int deallocate_uars(struct mlx5_ib_dev *dev, struct mlx5_ib_ucontext *con
11871188
return 0;
11881189
}
11891190

1191+
static int mlx5_ib_alloc_transport_domain(struct mlx5_ib_dev *dev, u32 *tdn)
1192+
{
1193+
int err;
1194+
1195+
err = mlx5_core_alloc_transport_domain(dev->mdev, tdn);
1196+
if (err)
1197+
return err;
1198+
1199+
if ((MLX5_CAP_GEN(dev->mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH) ||
1200+
!MLX5_CAP_GEN(dev->mdev, disable_local_lb))
1201+
return err;
1202+
1203+
mutex_lock(&dev->lb_mutex);
1204+
dev->user_td++;
1205+
1206+
if (dev->user_td == 2)
1207+
err = mlx5_nic_vport_update_local_lb(dev->mdev, true);
1208+
1209+
mutex_unlock(&dev->lb_mutex);
1210+
return err;
1211+
}
1212+
1213+
static void mlx5_ib_dealloc_transport_domain(struct mlx5_ib_dev *dev, u32 tdn)
1214+
{
1215+
mlx5_core_dealloc_transport_domain(dev->mdev, tdn);
1216+
1217+
if ((MLX5_CAP_GEN(dev->mdev, port_type) != MLX5_CAP_PORT_TYPE_ETH) ||
1218+
!MLX5_CAP_GEN(dev->mdev, disable_local_lb))
1219+
return;
1220+
1221+
mutex_lock(&dev->lb_mutex);
1222+
dev->user_td--;
1223+
1224+
if (dev->user_td < 2)
1225+
mlx5_nic_vport_update_local_lb(dev->mdev, false);
1226+
1227+
mutex_unlock(&dev->lb_mutex);
1228+
}
1229+
11901230
static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
11911231
struct ib_udata *udata)
11921232
{
@@ -1295,8 +1335,7 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
12951335
mutex_init(&context->upd_xlt_page_mutex);
12961336

12971337
if (MLX5_CAP_GEN(dev->mdev, log_max_transport_domain)) {
1298-
err = mlx5_core_alloc_transport_domain(dev->mdev,
1299-
&context->tdn);
1338+
err = mlx5_ib_alloc_transport_domain(dev, &context->tdn);
13001339
if (err)
13011340
goto out_page;
13021341
}
@@ -1362,7 +1401,7 @@ static struct ib_ucontext *mlx5_ib_alloc_ucontext(struct ib_device *ibdev,
13621401

13631402
out_td:
13641403
if (MLX5_CAP_GEN(dev->mdev, log_max_transport_domain))
1365-
mlx5_core_dealloc_transport_domain(dev->mdev, context->tdn);
1404+
mlx5_ib_dealloc_transport_domain(dev, context->tdn);
13661405

13671406
out_page:
13681407
free_page(context->upd_xlt_page);
@@ -1390,7 +1429,7 @@ static int mlx5_ib_dealloc_ucontext(struct ib_ucontext *ibcontext)
13901429

13911430
bfregi = &context->bfregi;
13921431
if (MLX5_CAP_GEN(dev->mdev, log_max_transport_domain))
1393-
mlx5_core_dealloc_transport_domain(dev->mdev, context->tdn);
1432+
mlx5_ib_dealloc_transport_domain(dev, context->tdn);
13941433

13951434
free_page(context->upd_xlt_page);
13961435
deallocate_uars(dev, context);
@@ -3797,6 +3836,10 @@ static void *mlx5_ib_add(struct mlx5_core_dev *mdev)
37973836
goto err_umrc;
37983837
}
37993838

3839+
if ((MLX5_CAP_GEN(mdev, port_type) == MLX5_CAP_PORT_TYPE_ETH) &&
3840+
MLX5_CAP_GEN(mdev, disable_local_lb))
3841+
mutex_init(&dev->lb_mutex);
3842+
38003843
dev->ib_active = true;
38013844

38023845
return dev;

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,13 @@ struct mlx5_ib_dev {
652652
struct list_head qp_list;
653653
/* Array with num_ports elements */
654654
struct mlx5_ib_port *port;
655-
struct mlx5_sq_bfreg bfreg;
656-
struct mlx5_sq_bfreg fp_bfreg;
657-
u8 umr_fence;
655+
struct mlx5_sq_bfreg bfreg;
656+
struct mlx5_sq_bfreg fp_bfreg;
657+
658+
/* protect the user_td */
659+
struct mutex lb_mutex;
660+
u32 user_td;
661+
u8 umr_fence;
658662
};
659663

660664
static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <linux/debugfs.h>
4848
#include <linux/kmod.h>
4949
#include <linux/mlx5/mlx5_ifc.h>
50+
#include <linux/mlx5/vport.h>
5051
#ifdef CONFIG_RFS_ACCEL
5152
#include <linux/cpu_rmap.h>
5253
#endif
@@ -579,6 +580,18 @@ static int set_hca_ctrl(struct mlx5_core_dev *dev)
579580
return err;
580581
}
581582

583+
static int mlx5_core_set_hca_defaults(struct mlx5_core_dev *dev)
584+
{
585+
int ret = 0;
586+
587+
/* Disable local_lb by default */
588+
if ((MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_ETH) &&
589+
MLX5_CAP_GEN(dev, disable_local_lb))
590+
ret = mlx5_nic_vport_update_local_lb(dev, false);
591+
592+
return ret;
593+
}
594+
582595
int mlx5_core_enable_hca(struct mlx5_core_dev *dev, u16 func_id)
583596
{
584597
u32 out[MLX5_ST_SZ_DW(enable_hca_out)] = {0};
@@ -1155,6 +1168,12 @@ static int mlx5_load_one(struct mlx5_core_dev *dev, struct mlx5_priv *priv,
11551168
goto err_fs;
11561169
}
11571170

1171+
err = mlx5_core_set_hca_defaults(dev);
1172+
if (err) {
1173+
dev_err(&pdev->dev, "Failed to set hca defaults\n");
1174+
goto err_fs;
1175+
}
1176+
11581177
#ifdef CONFIG_MLX5_CORE_EN
11591178
mlx5_eswitch_attach(dev->priv.eswitch);
11601179
#endif

0 commit comments

Comments
 (0)