[dpdk-dev] [PATCH v6 17/22] bus/vdev: implement device iteration

Gaetan Rivet gaetan.rivet at 6wind.com
Fri Apr 13 15:22:32 CEST 2018


Signed-off-by: Gaetan Rivet <gaetan.rivet at 6wind.com>
---
 drivers/bus/vdev/Makefile |  2 +-
 drivers/bus/vdev/vdev.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/vdev/Makefile b/drivers/bus/vdev/Makefile
index 24d424a38..52728833c 100644
--- a/drivers/bus/vdev/Makefile
+++ b/drivers/bus/vdev/Makefile
@@ -19,7 +19,7 @@ LIBABIVER := 1
 
 SRCS-y += vdev.c
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_eal -lrte_kvargs
 
 #
 # Export include files
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index c135554c0..5bb87af28 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -15,6 +15,7 @@
 #include <rte_bus.h>
 #include <rte_common.h>
 #include <rte_devargs.h>
+#include <rte_kvargs.h>
 #include <rte_memory.h>
 #include <rte_tailq.h>
 #include <rte_spinlock.h>
@@ -387,6 +388,46 @@ vdev_unplug(struct rte_device *dev)
 	return rte_vdev_uninit(dev->name);
 }
 
+enum vdev_params {
+	RTE_VDEV_PARAMS_MAX,
+};
+
+static const char * const vdev_params_keys[] = {
+	[RTE_VDEV_PARAMS_MAX] = NULL,
+};
+
+static int
+vdev_dev_match(const struct rte_device *dev,
+	       const void *_kvlist)
+{
+	const struct rte_kvargs *kvlist = _kvlist;
+
+	(void) kvlist;
+	(void) dev;
+	return 0;
+}
+
+static void *
+vdev_dev_iterate(const void *start,
+		 const char *str,
+		 const struct rte_dev_iterator *it __rte_unused)
+{
+	struct rte_kvargs *kvargs = NULL;
+	struct rte_device *dev;
+
+	if (str != NULL) {
+		kvargs = rte_kvargs_parse(str, vdev_params_keys);
+		if (kvargs == NULL) {
+			VDEV_LOG(ERR, "cannot parse argument list\n");
+			rte_errno = EINVAL;
+			return NULL;
+		}
+	}
+	dev = vdev_find_device(start, vdev_dev_match, kvargs);
+	rte_kvargs_free(kvargs);
+	return dev;
+}
+
 static struct rte_bus rte_vdev_bus = {
 	.scan = vdev_scan,
 	.probe = vdev_probe,
@@ -394,6 +435,7 @@ static struct rte_bus rte_vdev_bus = {
 	.plug = vdev_plug,
 	.unplug = vdev_unplug,
 	.parse = vdev_parse,
+	.dev_iterate = vdev_dev_iterate,
 };
 
 RTE_REGISTER_BUS(vdev, rte_vdev_bus);
-- 
2.11.0



More information about the dev mailing list