[20.11,09/20] raw/ioat: add vdev probe for DSA/idxd devices
diff mbox series

Message ID 20200721095140.719297-10-bruce.richardson@intel.com
State Superseded
Delegated to: Thomas Monjalon
Headers show
Series
  • raw/ioat: enhancements and new hardware support
Related show

Checks

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

Commit Message

Bruce Richardson July 21, 2020, 9:51 a.m. UTC
From: Kevin Laatz <kevin.laatz@intel.com>

The Intel DSA devices can be exposed to userspace via kernel driver, so can
be used without having to bind them to vfio/uio. Therefore we add support
for using those kernel-configured devices as vdevs, taking as parameter the
individual HW work queue to be used by the vdev.

Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/raw/ioat/idxd_vdev.c | 127 +++++++++++++++++++++++++++++++++++
 drivers/raw/ioat/meson.build |   6 +-
 2 files changed, 132 insertions(+), 1 deletion(-)
 create mode 100644 drivers/raw/ioat/idxd_vdev.c

Patch
diff mbox series

diff --git a/drivers/raw/ioat/idxd_vdev.c b/drivers/raw/ioat/idxd_vdev.c
new file mode 100644
index 000000000..73fce6d87
--- /dev/null
+++ b/drivers/raw/ioat/idxd_vdev.c
@@ -0,0 +1,127 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2020 Intel Corporation
+ */
+
+#include <rte_bus_vdev.h>
+#include <rte_kvargs.h>
+#include <rte_string_fns.h>
+#include <rte_rawdev_pmd.h>
+
+#include "ioat_private.h"
+
+/** Name of the device driver */
+#define IDXD_PMD_RAWDEV_NAME rawdev_idxd
+/* takes a work queue(WQ) as parameter */
+#define IDXD_ARG_WQ		"wq"
+
+extern struct rte_vdev_driver idxd_rawdev_drv_vdev;
+
+static const char * const valid_args[] = {
+	IDXD_ARG_WQ,
+	NULL
+};
+
+struct idxd_vdev_args {
+	uint8_t device_id;
+	uint8_t wq_id;
+};
+
+static int
+idxd_rawdev_parse_wq(const char *key __rte_unused, const char *value,
+			  void *extra_args)
+{
+	struct idxd_vdev_args *args = (struct idxd_vdev_args *)extra_args;
+	int dev, wq, bytes = -1;
+	int read = sscanf(value, "%d.%d%n", &dev, &wq, &bytes);
+
+	if (read != 2 || bytes != (int)strlen(value)) {
+		IOAT_PMD_ERR("Error parsing work-queue id. Must be in <dev_id>.<queue_id> format");
+		return -EINVAL;
+	}
+
+	if (dev >= UINT8_MAX || wq >= UINT8_MAX) {
+		IOAT_PMD_ERR("Device or work queue id out of range");
+		return -EINVAL;
+	}
+
+	args->device_id = dev;
+	args->wq_id = wq;
+
+	return 0;
+}
+
+static int
+idxd_vdev_parse_params(struct rte_kvargs *kvlist, struct idxd_vdev_args *args)
+{
+	if (rte_kvargs_count(kvlist, IDXD_ARG_WQ) == 1) {
+		if (rte_kvargs_process(kvlist, IDXD_ARG_WQ,
+				&idxd_rawdev_parse_wq, args) < 0) {
+			IOAT_PMD_ERR("Error parsing %s", IDXD_ARG_WQ);
+			goto free;
+		}
+	} else {
+		IOAT_PMD_ERR("%s is a mandatory arg", IDXD_ARG_WQ);
+		return -EINVAL;
+	}
+
+	return 0;
+
+free:
+	if (kvlist)
+		rte_kvargs_free(kvlist);
+	return -EINVAL;
+}
+
+static int
+idxd_rawdev_probe_vdev(struct rte_vdev_device *vdev)
+{
+	struct rte_kvargs *kvlist;
+	struct idxd_vdev_args vdev_args;
+	const char *name;
+	int ret = 0;
+
+	name = rte_vdev_device_name(vdev);
+	if (name == NULL)
+		return -EINVAL;
+
+	IOAT_PMD_INFO("Initializing pmd_idxd for %s", name);
+
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(vdev), valid_args);
+	if (kvlist == NULL) {
+		IOAT_PMD_ERR("Invalid kvargs key");
+		return -EINVAL;
+	}
+
+	ret = idxd_vdev_parse_params(kvlist, &vdev_args);
+	if (ret) {
+		IOAT_PMD_ERR("Failed to parse kvargs");
+		return -EINVAL;
+	}
+
+	vdev->device.driver = &idxd_rawdev_drv_vdev.driver;
+
+	return 0;
+}
+
+static int
+idxd_rawdev_remove_vdev(struct rte_vdev_device *vdev)
+{
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
+	if (name == NULL)
+		return -EINVAL;
+
+	IOAT_PMD_INFO("Remove DSA vdev %p", name);
+
+	return 0;
+}
+
+struct rte_vdev_driver idxd_rawdev_drv_vdev = {
+	.probe = idxd_rawdev_probe_vdev,
+	.remove = idxd_rawdev_remove_vdev,
+};
+
+RTE_PMD_REGISTER_VDEV(IDXD_PMD_RAWDEV_NAME, idxd_rawdev_drv_vdev);
+RTE_PMD_REGISTER_PARAM_STRING(IDXD_PMD_RAWDEV_NAME,
+			      "wq=<string>");
diff --git a/drivers/raw/ioat/meson.build b/drivers/raw/ioat/meson.build
index 3529635e9..b343b7367 100644
--- a/drivers/raw/ioat/meson.build
+++ b/drivers/raw/ioat/meson.build
@@ -5,9 +5,13 @@  build = dpdk_conf.has('RTE_ARCH_X86')
 reason = 'only supported on x86'
 sources = files(
 	'idxd_pci.c',
+	'idxd_vdev.c',
 	'ioat_rawdev.c',
 	'ioat_rawdev_test.c')
-deps += ['rawdev', 'bus_pci', 'mbuf']
+deps += ['bus_pci',
+	'bus_vdev',
+	'mbuf',
+	'rawdev']
 
 install_headers('rte_ioat_rawdev.h',
 		'rte_ioat_rawdev_fns.h')