Skip to content

Commit 1a86b37

Browse files
Eli Cohenmstsirkin
authored andcommitted
vdpa/mlx5: Add VDPA driver for supported mlx5 devices
Add a front end VDPA driver that registers in the VDPA bus and provides networking to a guest. The VDPA driver creates the necessary resources on the VF it is driving such that data path will be offloaded. Notifications are being communicated through the driver. Currently, only VFs are supported. In subsequent patches we will have devlink support to control which VF is used for VDPA and which function is used for regular networking. Reviewed-by: Parav Pandit <[email protected]> Signed-off-by: Eli Cohen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent 94abbcc commit 1a86b37

File tree

6 files changed

+2080
-2
lines changed

6 files changed

+2080
-2
lines changed

drivers/vdpa/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,14 @@ config MLX5_VDPA
3737
common for all types of VDPA drivers. The following drivers are planned:
3838
net, block.
3939

40+
config MLX5_VDPA_NET
41+
tristate "vDPA driver for ConnectX devices"
42+
depends on MLX5_VDPA
43+
default n
44+
help
45+
VDPA network driver for ConnectX6 and newer. Provides offloading
46+
of virtio net datapath such that descriptors put on the ring will
47+
be executed by the hardware. It also supports a variety of stateless
48+
offloads depending on the actual device used and firmware version.
49+
4050
endif # VDPA

drivers/vdpa/mlx5/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
obj-$(CONFIG_MLX5_VDPA) += core/resources.o core/mr.o
1+
subdir-ccflags-y += -I$(srctree)/drivers/vdpa/mlx5/core
2+
3+
obj-$(CONFIG_MLX5_VDPA_NET) += mlx5_vdpa.o
4+
mlx5_vdpa-$(CONFIG_MLX5_VDPA_NET) += net/main.o net/mlx5_vnet.o core/resources.o core/mr.o

drivers/vdpa/mlx5/core/mr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *io
464464
bool *change_map)
465465
{
466466
struct mlx5_vdpa_mr *mr = &mvdev->mr;
467-
int err;
467+
int err = 0;
468468

469469
*change_map = false;
470470
if (map_empty(iotlb)) {

drivers/vdpa/mlx5/net/main.c

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
/* Copyright (c) 2020 Mellanox Technologies Ltd. */
3+
4+
#include <linux/module.h>
5+
#include <linux/mlx5/driver.h>
6+
#include <linux/mlx5/device.h>
7+
#include "mlx5_vdpa_ifc.h"
8+
#include "mlx5_vnet.h"
9+
10+
MODULE_AUTHOR("Eli Cohen <[email protected]>");
11+
MODULE_DESCRIPTION("Mellanox VDPA driver");
12+
MODULE_LICENSE("Dual BSD/GPL");
13+
14+
static bool required_caps_supported(struct mlx5_core_dev *mdev)
15+
{
16+
u8 event_mode;
17+
u64 got;
18+
19+
got = MLX5_CAP_GEN_64(mdev, general_obj_types);
20+
21+
if (!(got & MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_NET_Q))
22+
return false;
23+
24+
event_mode = MLX5_CAP_DEV_VDPA_EMULATION(mdev, event_mode);
25+
if (!(event_mode & MLX5_VIRTIO_Q_EVENT_MODE_QP_MODE))
26+
return false;
27+
28+
if (!MLX5_CAP_DEV_VDPA_EMULATION(mdev, eth_frame_offload_type))
29+
return false;
30+
31+
return true;
32+
}
33+
34+
static void *mlx5_vdpa_add(struct mlx5_core_dev *mdev)
35+
{
36+
struct mlx5_vdpa_dev *vdev;
37+
38+
if (mlx5_core_is_pf(mdev))
39+
return NULL;
40+
41+
if (!required_caps_supported(mdev)) {
42+
dev_info(mdev->device, "virtio net emulation not supported\n");
43+
return NULL;
44+
}
45+
vdev = mlx5_vdpa_add_dev(mdev);
46+
if (IS_ERR(vdev))
47+
return NULL;
48+
49+
return vdev;
50+
}
51+
52+
static void mlx5_vdpa_remove(struct mlx5_core_dev *mdev, void *context)
53+
{
54+
struct mlx5_vdpa_dev *vdev = context;
55+
56+
mlx5_vdpa_remove_dev(vdev);
57+
}
58+
59+
static struct mlx5_interface mlx5_vdpa_interface = {
60+
.add = mlx5_vdpa_add,
61+
.remove = mlx5_vdpa_remove,
62+
.protocol = MLX5_INTERFACE_PROTOCOL_VDPA,
63+
};
64+
65+
static int __init mlx5_vdpa_init(void)
66+
{
67+
return mlx5_register_interface(&mlx5_vdpa_interface);
68+
}
69+
70+
static void __exit mlx5_vdpa_exit(void)
71+
{
72+
mlx5_unregister_interface(&mlx5_vdpa_interface);
73+
}
74+
75+
module_init(mlx5_vdpa_init);
76+
module_exit(mlx5_vdpa_exit);

0 commit comments

Comments
 (0)