[v3,21/25] net/mlx5: select driver by vDPA device argument

Message ID 1580228860-10665-22-git-send-email-matan@mellanox.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series Introduce mlx5 common library |

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation fail apply issues

Commit Message

Matan Azrad Jan. 28, 2020, 4:27 p.m. UTC
There might be a case that one Mellanox device can be probed by
multiple mlx5 drivers.

One case is that any mlx5 vDPA device can be probed by bothe net/mlx5
and vdpa/mlx5.

Add a new mlx5 common API to get the requested driver by devargs:
vdpa=1.

Skip net/mlx5 PMD probing while the device is selected to be probed by
the vDPA driver.

Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/common/mlx5/Makefile                    |  2 +-
 drivers/common/mlx5/meson.build                 |  2 +-
 drivers/common/mlx5/mlx5_common.c               | 36 +++++++++++++++++++++++++
 drivers/common/mlx5/mlx5_common.h               |  3 +++
 drivers/common/mlx5/rte_common_mlx5_version.map |  1 +
 drivers/net/mlx5/mlx5.c                         |  5 ++++
 6 files changed, 47 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/common/mlx5/Makefile b/drivers/common/mlx5/Makefile
index d1de3ec..b9e9803 100644
--- a/drivers/common/mlx5/Makefile
+++ b/drivers/common/mlx5/Makefile
@@ -41,7 +41,7 @@  else
 LDLIBS += -libverbs -lmlx5
 endif
 
-LDLIBS += -lrte_eal -lrte_pci
+LDLIBS += -lrte_eal -lrte_pci -lrte_kvargs
 
 # A few warnings cannot be avoided in external headers.
 CFLAGS += -Wno-error=cast-qual -DNDEBUG -UPEDANTIC
diff --git a/drivers/common/mlx5/meson.build b/drivers/common/mlx5/meson.build
index 3e130cb..b88822e 100644
--- a/drivers/common/mlx5/meson.build
+++ b/drivers/common/mlx5/meson.build
@@ -37,7 +37,7 @@  endforeach
 
 if build
 	allow_experimental_apis = true
-	deps += ['hash', 'pci', 'net', 'eal']
+	deps += ['hash', 'pci', 'net', 'eal', 'kvargs']
 	ext_deps += libs
 	sources = files(
 		'mlx5_devx_cmds.c',
diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index 2381208..f756b6b 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -71,6 +71,42 @@ 
 	return 0;
 }
 
+static int
+mlx5_vdpa_check_handler(__rte_unused const char *key, const char *value,
+			__rte_unused void *opaque)
+{
+	if (strcmp(value, "1"))
+		return -1;
+	return 0;
+}
+
+int
+mlx5_vdpa_mode_selected(struct rte_devargs *devargs)
+{
+	struct rte_kvargs *kvlist;
+	const char *key = "vdpa";
+	int ret = 0;
+
+	if (devargs == NULL)
+		return 0;
+
+	kvlist = rte_kvargs_parse(devargs->args, NULL);
+	if (kvlist == NULL)
+		return 0;
+
+	if (!rte_kvargs_count(kvlist, key))
+		goto exit;
+
+	/* Vdpa mode selected when there's a key-value pair: vdpa=1. */
+	if (rte_kvargs_process(kvlist, key, mlx5_vdpa_check_handler, NULL) < 0)
+		goto exit;
+	ret = 1;
+
+exit:
+	rte_kvargs_free(kvlist);
+	return ret;
+}
+
 #ifdef RTE_IBVERBS_LINK_DLOPEN
 
 /**
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 9d464d4..aeaa7b9 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -11,6 +11,8 @@ 
 #include <rte_pci.h>
 #include <rte_atomic.h>
 #include <rte_log.h>
+#include <rte_kvargs.h>
+#include <rte_devargs.h>
 
 #include "mlx5_prm.h"
 
@@ -149,5 +151,6 @@  enum mlx5_cqe_status {
 }
 
 int mlx5_dev_to_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr);
+int mlx5_vdpa_mode_selected(struct rte_devargs *devargs);
 
 #endif /* RTE_PMD_MLX5_COMMON_H_ */
diff --git a/drivers/common/mlx5/rte_common_mlx5_version.map b/drivers/common/mlx5/rte_common_mlx5_version.map
index 95ca54a..d32d631 100644
--- a/drivers/common/mlx5/rte_common_mlx5_version.map
+++ b/drivers/common/mlx5/rte_common_mlx5_version.map
@@ -26,4 +26,5 @@  DPDK_20.02 {
 	mlx5_devx_get_out_command_status;
 
 	mlx5_dev_to_pci_addr;
+	mlx5_vdpa_mode_selected;
 };
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index d0fa2da..353196b 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -2967,6 +2967,11 @@  struct mlx5_flow_id_pool *
 	struct mlx5_dev_config dev_config;
 	int ret;
 
+	if (mlx5_vdpa_mode_selected(pci_dev->device.devargs)) {
+		DRV_LOG(DEBUG, "Skip probing - should be probed by the vdpa"
+			" driver.");
+		return 1;
+	}
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 		mlx5_pmd_socket_init();
 	ret = mlx5_init_once();