All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure
@ 2017-02-15 10:02 Jan Blunck
  2017-02-15 10:02 ` [PATCH 1/7] eal: use different constructor priorities for initcalls Jan Blunck
                   ` (16 more replies)
  0 siblings, 17 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 10:02 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain

With the rte_bus infrastructure present in 17.02 it is possible to refactor
the virtual device probing into a bus. This series also introduces the
rte_vdev_device to better keep track of devices.

Jan Blunck (7):
  eal: use different constructor priorities for initcalls
  eal: probe legacy PCI devices before other bus devices
  eal: move virtual device probing into a bus
  eal: remove unused rte_eal_dev_init()
  eal: Refactor vdev driver probe/remove
  eal: add struct rte_vdev_device
  eal: make virtual bus use rte_vdev_device

 lib/librte_eal/bsdapp/eal/eal.c           |   9 +-
 lib/librte_eal/common/eal_common_dev.c    |  28 ----
 lib/librte_eal/common/eal_common_vdev.c   | 245 ++++++++++++++++++++++++++----
 lib/librte_eal/common/include/rte_bus.h   |  17 ++-
 lib/librte_eal/common/include/rte_dev.h   |   5 -
 lib/librte_eal/common/include/rte_eal.h   |  12 +-
 lib/librte_eal/common/include/rte_tailq.h |   2 +-
 lib/librte_eal/common/include/rte_vdev.h  |   5 +
 lib/librte_eal/linuxapp/eal/eal.c         |   9 +-
 9 files changed, 253 insertions(+), 79 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH 1/7] eal: use different constructor priorities for initcalls
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
@ 2017-02-15 10:02 ` Jan Blunck
  2017-02-15 14:37   ` Shreyansh Jain
  2017-02-15 10:02 ` [PATCH 2/7] eal: probe legacy PCI devices before other bus devices Jan Blunck
                   ` (15 subsequent siblings)
  16 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 10:02 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain

This introduces different initcall macros to allow for late registration of
the virtual device bus.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_bus.h   | 17 ++++++++++++++++-
 lib/librte_eal/common/include/rte_eal.h   | 12 ++++++++++--
 lib/librte_eal/common/include/rte_tailq.h |  2 +-
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 7c36969..9f161f2 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -50,6 +50,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 
+#include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_dev.h>
 
@@ -145,7 +146,21 @@ void rte_bus_dump(FILE *f);
  * The constructor has higher priority than PMD constructors.
  */
 #define RTE_REGISTER_BUS(nm, bus) \
-static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
+RTE_EAL_INIT(businitfn_ ##nm); \
+static void businitfn_ ##nm(void) \
+{\
+	(bus).name = RTE_STR(nm);\
+	rte_bus_register(&bus); \
+}
+
+/**
+ * Helper for late Bus registration.
+ * The constructor still has higher priority than PMD constructors but has
+ * lower priority than RTE_REGISTER_BUS.
+ */
+#define RTE_REGISTER_BUS_LATE(nm, bus) \
+RTE_POST_EAL_INIT(businitfn_ ##nm); \
+static void businitfn_ ##nm(void) \
 {\
 	(bus).name = RTE_STR(nm);\
 	rte_bus_register(&bus); \
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 03fee50..3a6bd71 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -258,8 +258,16 @@ static inline int rte_gettid(void)
 	return RTE_PER_LCORE(_thread_id);
 }
 
-#define RTE_INIT(func) \
-static void __attribute__((constructor, used)) func(void)
+#define RTE_EAL_INIT(func) \
+static void __attribute__((constructor(101), used)) func(void)
+
+#define RTE_POST_EAL_INIT(func) \
+static void __attribute__((constructor(102), used)) func(void)
+
+#define RTE_DEV_INIT(func) \
+static void __attribute__((constructor(103), used)) func(void)
+
+#define RTE_INIT(func) RTE_DEV_INIT(func)
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_eal/common/include/rte_tailq.h b/lib/librte_eal/common/include/rte_tailq.h
index 3aae098..07ceec1 100644
--- a/lib/librte_eal/common/include/rte_tailq.h
+++ b/lib/librte_eal/common/include/rte_tailq.h
@@ -148,7 +148,7 @@ struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
 int rte_eal_tailq_register(struct rte_tailq_elem *t);
 
 #define EAL_REGISTER_TAILQ(t) \
-RTE_INIT(tailqinitfn_ ##t); \
+RTE_EAL_INIT(tailqinitfn_ ##t); \
 static void tailqinitfn_ ##t(void) \
 { \
 	if (rte_eal_tailq_register(&t) < 0) \
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 2/7] eal: probe legacy PCI devices before other bus devices
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
  2017-02-15 10:02 ` [PATCH 1/7] eal: use different constructor priorities for initcalls Jan Blunck
@ 2017-02-15 10:02 ` Jan Blunck
  2017-02-15 14:03   ` Shreyansh Jain
  2017-02-15 10:02 ` [PATCH 3/7] eal: move virtual device probing into a bus Jan Blunck
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 10:02 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain

Make sure that the PCI devices are probed before the virtual devices after
the legacy virtual device probing has been moved to a bus.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/bsdapp/eal/eal.c   | 8 ++++----
 lib/librte_eal/linuxapp/eal/eal.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index ee7c9de..a584447 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -613,14 +613,14 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe all the buses and devices/drivers on them */
-	if (rte_bus_probe())
-		rte_panic("Cannot probe devices\n");
-
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	/* Probe all the buses and devices/drivers on them */
+	if (rte_bus_probe())
+		rte_panic("Cannot probe devices\n");
+
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index bf6b818..f77ff5c 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -884,14 +884,14 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe all the buses and devices/drivers on them */
-	if (rte_bus_probe())
-		rte_panic("Cannot probe devices\n");
-
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	/* Probe all the buses and devices/drivers on them */
+	if (rte_bus_probe())
+		rte_panic("Cannot probe devices\n");
+
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
  2017-02-15 10:02 ` [PATCH 1/7] eal: use different constructor priorities for initcalls Jan Blunck
  2017-02-15 10:02 ` [PATCH 2/7] eal: probe legacy PCI devices before other bus devices Jan Blunck
@ 2017-02-15 10:02 ` Jan Blunck
  2017-02-15 14:11   ` Shreyansh Jain
  2017-02-15 10:02 ` [PATCH 4/7] eal: remove unused rte_eal_dev_init() Jan Blunck
                   ` (13 subsequent siblings)
  16 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 10:02 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain

This is a refactoring of the virtual device probing which moves into into
a proper bus structure.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/eal_common_dev.c  | 22 -----------------
 lib/librte_eal/common/eal_common_vdev.c | 44 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4f3b493..1ce90f6 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -79,28 +79,6 @@ void rte_eal_device_remove(struct rte_device *dev)
 int
 rte_eal_dev_init(void)
 {
-	struct rte_devargs *devargs;
-
-	/*
-	 * Note that the dev_driver_list is populated here
-	 * from calls made to rte_eal_driver_register from constructor functions
-	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
-	 */
-
-	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
-
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
-			continue;
-
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-					devargs->args)) {
-			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-					devargs->virt.drv_name);
-			return -1;
-		}
-	}
-
 	return 0;
 }
 
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 7d6e54f..523a3d6 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -37,8 +37,10 @@
 #include <stdint.h>
 #include <sys/queue.h>
 
+#include <rte_bus.h>
 #include <rte_vdev.h>
 #include <rte_common.h>
+#include <rte_devargs.h>
 
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
@@ -122,3 +124,45 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+static int
+vdev_scan(void)
+{
+	/* for virtual devices we don't need to scan anything */
+	return 0;
+}
+
+static int
+vdev_probe(void)
+{
+	struct rte_devargs *devargs;
+
+	/*
+	 * Note that the dev_driver_list is populated here
+	 * from calls made to rte_eal_driver_register from constructor functions
+	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
+	 */
+
+	/* call the init function for each virtual device */
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		if (rte_eal_vdev_init(devargs->virt.drv_name,
+				      devargs->args)) {
+			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
+				devargs->virt.drv_name);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+static struct rte_bus rte_vdev_bus = {
+	.scan = vdev_scan,
+	.probe = vdev_probe,
+};
+
+RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 4/7] eal: remove unused rte_eal_dev_init()
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (2 preceding siblings ...)
  2017-02-15 10:02 ` [PATCH 3/7] eal: move virtual device probing into a bus Jan Blunck
@ 2017-02-15 10:02 ` Jan Blunck
  2017-02-15 17:11   ` Ferruh Yigit
  2017-02-15 10:02 ` [PATCH 5/7] eal: Refactor vdev driver probe/remove Jan Blunck
                   ` (12 subsequent siblings)
  16 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 10:02 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/bsdapp/eal/eal.c         | 3 ---
 lib/librte_eal/common/eal_common_dev.c  | 6 ------
 lib/librte_eal/common/include/rte_dev.h | 5 -----
 lib/librte_eal/linuxapp/eal/eal.c       | 3 ---
 4 files changed, 17 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index a584447..3d29fcb 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -621,9 +621,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	if (rte_eal_dev_init() < 0)
-		rte_panic("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 1ce90f6..4bde430 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -76,12 +76,6 @@ void rte_eal_device_remove(struct rte_device *dev)
 	TAILQ_REMOVE(&dev_device_list, dev, next);
 }
 
-int
-rte_eal_dev_init(void)
-{
-	return 0;
-}
-
 int rte_eal_dev_attach(const char *name, const char *devargs)
 {
 	struct rte_pci_addr addr;
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index b17791f..4251099 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -171,11 +171,6 @@ void rte_eal_driver_register(struct rte_driver *driver);
 void rte_eal_driver_unregister(struct rte_driver *driver);
 
 /**
- * Initalize all the registered drivers in this process
- */
-int rte_eal_dev_init(void);
-
-/**
  * Initialize a driver specified by name.
  *
  * @param name
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index f77ff5c..88479de 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -892,9 +892,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	if (rte_eal_dev_init() < 0)
-		rte_panic("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 5/7] eal: Refactor vdev driver probe/remove
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (3 preceding siblings ...)
  2017-02-15 10:02 ` [PATCH 4/7] eal: remove unused rte_eal_dev_init() Jan Blunck
@ 2017-02-15 10:02 ` Jan Blunck
  2017-02-15 10:02 ` [PATCH 6/7] eal: add struct rte_vdev_device Jan Blunck
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 10:02 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain

This is a preparation for the introduction of the struct rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/eal_common_vdev.c | 44 ++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 523a3d6..6ba3c91 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -61,14 +61,11 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 	TAILQ_REMOVE(&vdev_driver_list, driver, next);
 }
 
-int
-rte_eal_vdev_init(const char *name, const char *args)
+static int
+vdev_probe_all_drivers(const char *name, const char *args)
 {
 	struct rte_vdev_driver *driver;
 
-	if (name == NULL)
-		return -EINVAL;
-
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -89,18 +86,29 @@ rte_eal_vdev_init(const char *name, const char *args)
 			return driver->probe(name, args);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
 }
 
 int
-rte_eal_vdev_uninit(const char *name)
+rte_eal_vdev_init(const char *name, const char *args)
 {
-	struct rte_vdev_driver *driver;
+	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
+	ret = vdev_probe_all_drivers(name, args);
+	if (ret  > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
+}
+
+static int
+vdev_remove_driver(const char *name)
+{
+	struct rte_vdev_driver *driver;
+
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -121,8 +129,22 @@ rte_eal_vdev_uninit(const char *name)
 			return driver->remove(name);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
+}
+
+int
+rte_eal_vdev_uninit(const char *name)
+{
+	int ret;
+
+	if (name == NULL)
+		return -EINVAL;
+
+	ret = vdev_remove_driver(name);
+	if (ret > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
 }
 
 static int
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 6/7] eal: add struct rte_vdev_device
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (4 preceding siblings ...)
  2017-02-15 10:02 ` [PATCH 5/7] eal: Refactor vdev driver probe/remove Jan Blunck
@ 2017-02-15 10:02 ` Jan Blunck
  2017-02-15 17:11   ` Ferruh Yigit
  2017-02-15 10:02 ` [PATCH 7/7] eal: make virtual bus use rte_vdev_device Jan Blunck
                   ` (10 subsequent siblings)
  16 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 10:02 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain

This adds the rte_vdev_device structure which embeds a generic rte_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/eal_common_vdev.c  | 5 +++++
 lib/librte_eal/common/include/rte_vdev.h | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 6ba3c91..61677de 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -42,6 +42,11 @@
 #include <rte_common.h>
 #include <rte_devargs.h>
 
+/** Double linked list of virtual device drivers. */
+TAILQ_HEAD(vdev_device_list, rte_vdev_device);
+
+static struct vdev_device_list vdev_device_list =
+	TAILQ_HEAD_INITIALIZER(vdev_device_list);
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
 
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 784e837..8f98372 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -40,6 +40,11 @@ extern "C" {
 #include <sys/queue.h>
 #include <rte_dev.h>
 
+struct rte_vdev_device {
+	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
+	struct rte_device device;               /**< Inherit core device */
+};
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH 7/7] eal: make virtual bus use rte_vdev_device
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (5 preceding siblings ...)
  2017-02-15 10:02 ` [PATCH 6/7] eal: add struct rte_vdev_device Jan Blunck
@ 2017-02-15 10:02 ` Jan Blunck
  2017-02-15 17:11   ` Ferruh Yigit
  2017-02-15 17:11 ` [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Ferruh Yigit
                   ` (9 subsequent siblings)
  16 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 10:02 UTC (permalink / raw)
  To: dev; +Cc: shreyansh.jain

This allows the virtual bus to be rescanned and probed by tracking the
creation of rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/eal_common_vdev.c | 194 +++++++++++++++++++++++++-------
 1 file changed, 154 insertions(+), 40 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 61677de..5909c85 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -67,9 +67,12 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 }
 
 static int
-vdev_probe_all_drivers(const char *name, const char *args)
+vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
+	char *name = dev->device.devargs->virt.drv_name;
+	char *args = dev->device.devargs->args;
 	struct rte_vdev_driver *driver;
+	int ret;
 
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
@@ -79,90 +82,202 @@ vdev_probe_all_drivers(const char *name, const char *args)
 		 * So use strncmp to compare.
 		 */
 		if (!strncmp(driver->driver.name, name,
-			    strlen(driver->driver.name)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.name))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	/* Give new names precedence over aliases. */
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		if (driver->driver.alias &&
 		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.alias))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	return 1;
 }
 
+static struct rte_vdev_device *
+find_vdev(const char *name)
+{
+	struct rte_vdev_device *dev;
+
+	if (!name)
+		return NULL;
+
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
+		if (!strncmp(dev->device.devargs->virt.drv_name, name,
+			strlen(name)))
+			return dev;
+	}
+
+	return NULL;
+}
+
+static struct rte_devargs *
+alloc_devargs(const char *name, const char *args)
+{
+	struct rte_devargs *devargs;
+	int ret;
+
+	devargs = calloc(1, sizeof(*devargs));
+	if (!devargs)
+		return NULL;
+
+	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	if (args)
+		devargs->args = strdup(args);
+
+	ret = snprintf(devargs->virt.drv_name,
+			       sizeof(devargs->virt.drv_name), "%s", name);
+	if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name)) {
+		free(devargs->args);
+		free(devargs);
+		return NULL;
+	}
+
+	return devargs;
+}
+
 int
 rte_eal_vdev_init(const char *name, const char *args)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_probe_all_drivers(name, args);
-	if (ret  > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (dev)
+		return -EEXIST;
+
+	devargs = alloc_devargs(name, args);
+	if (!devargs)
+		return -ENOMEM;
+
+	dev = calloc(1, sizeof(*dev));
+	if (!dev) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+
+	dev->device.devargs = devargs;
+	dev->device.numa_node = -1;
+
+	ret = vdev_probe_all_drivers(dev);
+	if (ret) {
+		if (ret > 0)
+			RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+		goto fail;
+	}
+
+	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
+
+	rte_eal_device_insert(&dev->device);
+	TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	return 0;
 
+fail:
+	free(devargs->args);
+	free(devargs);
+	free(dev);
 	return ret;
 }
 
 static int
-vdev_remove_driver(const char *name)
+vdev_remove_driver(struct rte_vdev_device *dev)
 {
-	struct rte_vdev_driver *driver;
+	char *name = dev->device.devargs->virt.drv_name;
+	const struct rte_vdev_driver *driver;
 
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		/*
-		 * search a driver prefix in virtual device name.
-		 * For example, if the driver is pcap PMD, driver->name
-		 * will be "net_pcap", but "name" will be "net_pcapN".
-		 * So use strncmp to compare.
-		 */
-		if (!strncmp(driver->driver.name, name,
-			     strlen(driver->driver.name)))
-			return driver->remove(name);
-	}
-
-	/* Give new names precedence over aliases. */
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		if (driver->driver.alias &&
-		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->remove(name);
+	if (!dev->device.driver) {
+		RTE_LOG(DEBUG, EAL, "no driver attach to device %s\n", name);
+		return 1;
 	}
 
-	return 1;
+	driver = container_of(dev->device.driver, const struct rte_vdev_driver,
+		driver);
+	return driver->remove(name);
 }
 
 int
 rte_eal_vdev_uninit(const char *name)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_remove_driver(name);
-	if (ret > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (!dev)
+		return -ENOENT;
 
-	return ret;
+	devargs = dev->device.devargs;
+
+	ret = vdev_remove_driver(dev);
+	if (ret)
+		return ret;
+
+	TAILQ_REMOVE(&vdev_device_list, dev, next);
+	rte_eal_device_remove(&dev->device);
+
+	TAILQ_REMOVE(&devargs_list, devargs, next);
+
+	free(devargs->args);
+	free(devargs);
+	free(dev);
+	return 0;
 }
 
 static int
 vdev_scan(void)
 {
-	/* for virtual devices we don't need to scan anything */
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
+
+	/* for virtual devices we scan the devargs_list populated via cmdline */
+
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		dev = find_vdev(devargs->virt.drv_name);
+		if (dev)
+			continue;
+
+		dev = calloc(1, sizeof(*dev));
+		if (!dev)
+			return -1;
+
+		dev->device.devargs = devargs;
+		dev->device.numa_node = -1;
+
+		rte_eal_device_insert(&dev->device);
+		TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	}
+
 	return 0;
 }
 
 static int
 vdev_probe(void)
 {
-	struct rte_devargs *devargs;
+	struct rte_vdev_device *dev;
 
 	/*
 	 * Note that the dev_driver_list is populated here
@@ -171,15 +286,14 @@ vdev_probe(void)
 	 */
 
 	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (dev->device.driver)
 			continue;
 
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-				      devargs->args)) {
+		if (vdev_probe_all_drivers(dev)) {
 			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-				devargs->virt.drv_name);
+				dev->device.devargs->virt.drv_name);
 			return -1;
 		}
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* Re: [PATCH 2/7] eal: probe legacy PCI devices before other bus devices
  2017-02-15 10:02 ` [PATCH 2/7] eal: probe legacy PCI devices before other bus devices Jan Blunck
@ 2017-02-15 14:03   ` Shreyansh Jain
  0 siblings, 0 replies; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-15 14:03 UTC (permalink / raw)
  To: Jan Blunck, dev

On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
> Make sure that the PCI devices are probed before the virtual devices after
> the legacy virtual device probing has been moved to a bus.
>
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> ---

Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 10:02 ` [PATCH 3/7] eal: move virtual device probing into a bus Jan Blunck
@ 2017-02-15 14:11   ` Shreyansh Jain
  2017-02-15 14:13     ` Jan Blunck
  2017-02-15 14:15     ` Shreyansh Jain
  0 siblings, 2 replies; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-15 14:11 UTC (permalink / raw)
  To: Jan Blunck, dev

On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
> This is a refactoring of the virtual device probing which moves into into
> a proper bus structure.
>
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> ---
>  lib/librte_eal/common/eal_common_dev.c  | 22 -----------------
>  lib/librte_eal/common/eal_common_vdev.c | 44 +++++++++++++++++++++++++++++++++
>  2 files changed, 44 insertions(+), 22 deletions(-)
>

[...]

>
> diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
> index 7d6e54f..523a3d6 100644
> --- a/lib/librte_eal/common/eal_common_vdev.c
> +++ b/lib/librte_eal/common/eal_common_vdev.c
> @@ -37,8 +37,10 @@
>  #include <stdint.h>
>  #include <sys/queue.h>
>
[...]

> +
> +static struct rte_bus rte_vdev_bus = {
> +	.scan = vdev_scan,
> +	.probe = vdev_probe,
> +};
> +
> +RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
>

Does it matter if VDEV buses are registered before or after other
buses? Either way, the callbacks would be called in the order specified
in EAL.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 14:11   ` Shreyansh Jain
@ 2017-02-15 14:13     ` Jan Blunck
  2017-02-15 14:20       ` Shreyansh Jain
  2017-02-15 14:15     ` Shreyansh Jain
  1 sibling, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 14:13 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: dev

On Wed, Feb 15, 2017 at 3:11 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
>>
>
>> +
>> +static struct rte_bus rte_vdev_bus = {
>> +       .scan = vdev_scan,
>> +       .probe = vdev_probe,
>> +};
>> +
>> +RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
>>
>
> Does it matter if VDEV buses are registered before or after other
> buses?

Yes, it does. Also see commit f4ce209a ("eal: postpone vdev initialization").

> Either way, the callbacks would be called in the order specified
> in EAL.

They are called in order of registration. That is why this defers the
registration of the vdev bus.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 14:11   ` Shreyansh Jain
  2017-02-15 14:13     ` Jan Blunck
@ 2017-02-15 14:15     ` Shreyansh Jain
  2017-02-15 14:22       ` Wiles, Keith
  1 sibling, 1 reply; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-15 14:15 UTC (permalink / raw)
  To: Jan Blunck, dev

On Wednesday 15 February 2017 07:41 PM, Shreyansh Jain wrote:
> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
>> This is a refactoring of the virtual device probing which moves into into
>> a proper bus structure.
>>
>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>> ---
>>  lib/librte_eal/common/eal_common_dev.c  | 22 -----------------
>>  lib/librte_eal/common/eal_common_vdev.c | 44
>> +++++++++++++++++++++++++++++++++
>>  2 files changed, 44 insertions(+), 22 deletions(-)
>>
>
> [...]
>
>>
>> diff --git a/lib/librte_eal/common/eal_common_vdev.c
>> b/lib/librte_eal/common/eal_common_vdev.c
>> index 7d6e54f..523a3d6 100644
>> --- a/lib/librte_eal/common/eal_common_vdev.c
>> +++ b/lib/librte_eal/common/eal_common_vdev.c
>> @@ -37,8 +37,10 @@
>>  #include <stdint.h>
>>  #include <sys/queue.h>
>>
> [...]
>
>> +
>> +static struct rte_bus rte_vdev_bus = {
>> +    .scan = vdev_scan,
>> +    .probe = vdev_probe,
>> +};
>> +
>> +RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
>>
>
> Does it matter if VDEV buses are registered before or after other
> buses? Either way, the callbacks would be called in the order specified
> in EAL.
>
>

Just ignore this comment - I am misunderstood something.

But another question: Is there specific reason VDEV should be 
registered/scanned *after* other devices? Is there some specific problem 
if we do otherwise? (I think this is should be done, but I don't have a 
specific reason).

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 14:13     ` Jan Blunck
@ 2017-02-15 14:20       ` Shreyansh Jain
  0 siblings, 0 replies; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-15 14:20 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev

On Wednesday 15 February 2017 07:43 PM, Jan Blunck wrote:
> On Wed, Feb 15, 2017 at 3:11 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
>>>
>>
>>> +
>>> +static struct rte_bus rte_vdev_bus = {
>>> +       .scan = vdev_scan,
>>> +       .probe = vdev_probe,
>>> +};
>>> +
>>> +RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
>>>
>>
>> Does it matter if VDEV buses are registered before or after other
>> buses?
>
> Yes, it does. Also see commit f4ce209a ("eal: postpone vdev initialization").
>
>> Either way, the callbacks would be called in the order specified
>> in EAL.
>
> They are called in order of registration. That is why this defers the
> registration of the vdev bus.

Agree - I realized the problem in my statement after I had sent the email.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 14:15     ` Shreyansh Jain
@ 2017-02-15 14:22       ` Wiles, Keith
  2017-02-15 14:27         ` Shreyansh Jain
  2017-02-15 17:06         ` Jan Blunck
  0 siblings, 2 replies; 91+ messages in thread
From: Wiles, Keith @ 2017-02-15 14:22 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: Jan Blunck, dev


> On Feb 15, 2017, at 8:15 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> 
> On Wednesday 15 February 2017 07:41 PM, Shreyansh Jain wrote:
>> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
>>> This is a refactoring of the virtual device probing which moves into into
>>> a proper bus structure.
>>> 
>>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>>> ---
>>> lib/librte_eal/common/eal_common_dev.c  | 22 -----------------
>>> lib/librte_eal/common/eal_common_vdev.c | 44
>>> +++++++++++++++++++++++++++++++++
>>> 2 files changed, 44 insertions(+), 22 deletions(-)
>>> 
>> 
>> [...]
>> 
>>> 
>>> diff --git a/lib/librte_eal/common/eal_common_vdev.c
>>> b/lib/librte_eal/common/eal_common_vdev.c
>>> index 7d6e54f..523a3d6 100644
>>> --- a/lib/librte_eal/common/eal_common_vdev.c
>>> +++ b/lib/librte_eal/common/eal_common_vdev.c
>>> @@ -37,8 +37,10 @@
>>> #include <stdint.h>
>>> #include <sys/queue.h>
>>> 
>> [...]
>> 
>>> +
>>> +static struct rte_bus rte_vdev_bus = {
>>> +    .scan = vdev_scan,
>>> +    .probe = vdev_probe,
>>> +};
>>> +
>>> +RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
>>> 
>> 
>> Does it matter if VDEV buses are registered before or after other
>> buses? Either way, the callbacks would be called in the order specified
>> in EAL.
>> 
>> 
> 
> Just ignore this comment - I am misunderstood something.
> 
> But another question: Is there specific reason VDEV should be registered/scanned *after* other devices? Is there some specific problem if we do otherwise? (I think this is should be done, but I don't have a specific reason).

Does the bonding driver which uses physical devices need to be registered after physical ones? In Pktgen I noticed the vdev after the physical ports and I could not blacklist them as the bonding driver needed them, which caused the bonding ports to have a greater port number. In the case of pktgen the bonding ports were up around 8 or 10 and caused the display to not show the bonding ports. This is really just a usability problem for the developer using Pktgen. I would like to see the vdev devices first, but as long as the drivers (like bonding) are fine with them being first.

Regards,
Keith

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 14:22       ` Wiles, Keith
@ 2017-02-15 14:27         ` Shreyansh Jain
  2017-02-15 17:25           ` Jerin Jacob
  2017-02-15 17:06         ` Jan Blunck
  1 sibling, 1 reply; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-15 14:27 UTC (permalink / raw)
  To: Wiles, Keith, jerin.jacob; +Cc: Jan Blunck, dev

> -----Original Message-----
> From: Wiles, Keith [mailto:keith.wiles@intel.com]
> Sent: Wednesday, February 15, 2017 7:53 PM
> To: Shreyansh Jain <shreyansh.jain@nxp.com>
> Cc: Jan Blunck <jblunck@infradead.org>; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH 3/7] eal: move virtual device probing into a
> bus
> 
> 
> > On Feb 15, 2017, at 8:15 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> >
> > On Wednesday 15 February 2017 07:41 PM, Shreyansh Jain wrote:
> >> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
> >>> This is a refactoring of the virtual device probing which moves into into
> >>> a proper bus structure.
> >>>
> >>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> >>> ---
> >>> lib/librte_eal/common/eal_common_dev.c  | 22 -----------------
> >>> lib/librte_eal/common/eal_common_vdev.c | 44
> >>> +++++++++++++++++++++++++++++++++
> >>> 2 files changed, 44 insertions(+), 22 deletions(-)
> >>>
> >>
> >> [...]
> >>
> >>>
> >>> diff --git a/lib/librte_eal/common/eal_common_vdev.c
> >>> b/lib/librte_eal/common/eal_common_vdev.c
> >>> index 7d6e54f..523a3d6 100644
> >>> --- a/lib/librte_eal/common/eal_common_vdev.c
> >>> +++ b/lib/librte_eal/common/eal_common_vdev.c
> >>> @@ -37,8 +37,10 @@
> >>> #include <stdint.h>
> >>> #include <sys/queue.h>
> >>>
> >> [...]
> >>
> >>> +
> >>> +static struct rte_bus rte_vdev_bus = {
> >>> +    .scan = vdev_scan,
> >>> +    .probe = vdev_probe,
> >>> +};
> >>> +
> >>> +RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
> >>>
> >>
> >> Does it matter if VDEV buses are registered before or after other
> >> buses? Either way, the callbacks would be called in the order specified
> >> in EAL.
> >>
> >>
> >
> > Just ignore this comment - I am misunderstood something.
> >
> > But another question: Is there specific reason VDEV should be
> registered/scanned *after* other devices? Is there some specific problem if
> we do otherwise? (I think this is should be done, but I don't have a specific
> reason).
> 
> Does the bonding driver which uses physical devices need to be registered
> after physical ones? In Pktgen I noticed the vdev after the physical ports
> and I could not blacklist them as the bonding driver needed them, which
> caused the bonding ports to have a greater port number. In the case of pktgen
> the bonding ports were up around 8 or 10 and caused the display to not show
> the bonding ports. This is really just a usability problem for the developer
> using Pktgen. I would like to see the vdev devices first, but as long as the
> drivers (like bonding) are fine with them being first.

Ah, now I remember - there was a patch from Jerin for this.
Probably he is the best person to comment here.
(I don't have much insight here). 

> 
> Regards,
> Keith

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 1/7] eal: use different constructor priorities for initcalls
  2017-02-15 10:02 ` [PATCH 1/7] eal: use different constructor priorities for initcalls Jan Blunck
@ 2017-02-15 14:37   ` Shreyansh Jain
  2017-02-15 15:05     ` Jan Blunck
  0 siblings, 1 reply; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-15 14:37 UTC (permalink / raw)
  To: Jan Blunck, dev

On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
> This introduces different initcall macros to allow for late registration of
> the virtual device bus.
>
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> ---
>  lib/librte_eal/common/include/rte_bus.h   | 17 ++++++++++++++++-
>  lib/librte_eal/common/include/rte_eal.h   | 12 ++++++++++--
>  lib/librte_eal/common/include/rte_tailq.h |  2 +-
>  3 files changed, 27 insertions(+), 4 deletions(-)
>
> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> index 7c36969..9f161f2 100644
> --- a/lib/librte_eal/common/include/rte_bus.h
> +++ b/lib/librte_eal/common/include/rte_bus.h
> @@ -50,6 +50,7 @@ extern "C" {
>  #include <stdio.h>
>  #include <sys/queue.h>
>
> +#include <rte_eal.h>
>  #include <rte_log.h>
>  #include <rte_dev.h>
>
> @@ -145,7 +146,21 @@ void rte_bus_dump(FILE *f);
>   * The constructor has higher priority than PMD constructors.
>   */
>  #define RTE_REGISTER_BUS(nm, bus) \
> -static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
> +RTE_EAL_INIT(businitfn_ ##nm); \
> +static void businitfn_ ##nm(void) \
> +{\
> +	(bus).name = RTE_STR(nm);\
> +	rte_bus_register(&bus); \
> +}
> +
> +/**
> + * Helper for late Bus registration.
> + * The constructor still has higher priority than PMD constructors but has
> + * lower priority than RTE_REGISTER_BUS.
> + */
> +#define RTE_REGISTER_BUS_LATE(nm, bus) \
> +RTE_POST_EAL_INIT(businitfn_ ##nm); \
> +static void businitfn_ ##nm(void) \
>  {\
>  	(bus).name = RTE_STR(nm);\
>  	rte_bus_register(&bus); \
> diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
> index 03fee50..3a6bd71 100644
> --- a/lib/librte_eal/common/include/rte_eal.h
> +++ b/lib/librte_eal/common/include/rte_eal.h
> @@ -258,8 +258,16 @@ static inline int rte_gettid(void)
>  	return RTE_PER_LCORE(_thread_id);
>  }
>
> -#define RTE_INIT(func) \
> -static void __attribute__((constructor, used)) func(void)
> +#define RTE_EAL_INIT(func) \
> +static void __attribute__((constructor(101), used)) func(void)
> +
> +#define RTE_POST_EAL_INIT(func) \
> +static void __attribute__((constructor(102), used)) func(void)
> +
> +#define RTE_DEV_INIT(func) \
> +static void __attribute__((constructor(103), used)) func(void)

Shouldn't we simply allow this priority to be default to allow for some
priority space between buses and default init?

> +
> +#define RTE_INIT(func) RTE_DEV_INIT(func)
>
>  #ifdef __cplusplus
>  }
> diff --git a/lib/librte_eal/common/include/rte_tailq.h b/lib/librte_eal/common/include/rte_tailq.h
> index 3aae098..07ceec1 100644
> --- a/lib/librte_eal/common/include/rte_tailq.h
> +++ b/lib/librte_eal/common/include/rte_tailq.h
> @@ -148,7 +148,7 @@ struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
>  int rte_eal_tailq_register(struct rte_tailq_elem *t);
>
>  #define EAL_REGISTER_TAILQ(t) \
> -RTE_INIT(tailqinitfn_ ##t); \
> +RTE_EAL_INIT(tailqinitfn_ ##t); \
>  static void tailqinitfn_ ##t(void) \
>  { \
>  	if (rte_eal_tailq_register(&t) < 0) \
>

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 1/7] eal: use different constructor priorities for initcalls
  2017-02-15 14:37   ` Shreyansh Jain
@ 2017-02-15 15:05     ` Jan Blunck
  2017-02-16  5:59       ` Shreyansh Jain
  0 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 15:05 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: dev

On Wed, Feb 15, 2017 at 3:37 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
>>
>> --- a/lib/librte_eal/common/include/rte_eal.h
>> +++ b/lib/librte_eal/common/include/rte_eal.h
>> @@ -258,8 +258,16 @@ static inline int rte_gettid(void)
>>         return RTE_PER_LCORE(_thread_id);
>>  }
>>
>> -#define RTE_INIT(func) \
>> -static void __attribute__((constructor, used)) func(void)
>> +#define RTE_EAL_INIT(func) \
>> +static void __attribute__((constructor(101), used)) func(void)
>> +
>> +#define RTE_POST_EAL_INIT(func) \
>> +static void __attribute__((constructor(102), used)) func(void)
>> +
>> +#define RTE_DEV_INIT(func) \
>> +static void __attribute__((constructor(103), used)) func(void)
>
>
> Shouldn't we simply allow this priority to be default to allow for some
> priority space between buses and default init?
>

The absolute numbers are not that important. We can always adjust
them. Important is the relative order. If you have a use-case for
something that needs to be initialized before the devices but can't
get initialized with the eal/post-eal then please speak up.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 14:22       ` Wiles, Keith
  2017-02-15 14:27         ` Shreyansh Jain
@ 2017-02-15 17:06         ` Jan Blunck
  2017-02-15 17:10           ` Wiles, Keith
  1 sibling, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 17:06 UTC (permalink / raw)
  To: Wiles, Keith; +Cc: Shreyansh Jain, dev

On Wed, Feb 15, 2017 at 3:22 PM, Wiles, Keith <keith.wiles@intel.com> wrote:
>
>> On Feb 15, 2017, at 8:15 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>>
>>
>> Just ignore this comment - I am misunderstood something.
>>
>> But another question: Is there specific reason VDEV should be registered/scanned *after* other devices? Is there some specific problem if we do otherwise? (I think this is should be done, but I don't have a specific reason).
>

Just for context: the vdev's are probed after the physical devices
because of commit f4ce209a ("eal: postpone vdev initialization").

> Does the bonding driver which uses physical devices need to be registered after physical ones? In Pktgen I noticed the vdev after the physical ports and I could not blacklist them as the bonding driver needed them, which caused the bonding ports to have a greater port number. In the case of pktgen the bonding ports were up around 8 or 10 and caused the display to not show the bonding ports. This is really just a usability problem for the developer using Pktgen. I would like to see the vdev devices first, but as long as the drivers (like bonding) are fine with them being first.
>

The bonding devargs might specify slaves that get attached during
device probe. If the referenced devices are physical interfaces we
need to probe them first. This is really a chicken-egg-problem.

Maybe you could improve the usability in your case and sort the
virtual devices first or even hide enslaved ports?

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 17:06         ` Jan Blunck
@ 2017-02-15 17:10           ` Wiles, Keith
  2017-02-15 17:22             ` Wiles, Keith
  0 siblings, 1 reply; 91+ messages in thread
From: Wiles, Keith @ 2017-02-15 17:10 UTC (permalink / raw)
  To: Jan Blunck; +Cc: Shreyansh Jain, dev


> On Feb 15, 2017, at 11:06 AM, Jan Blunck <jblunck@infradead.org> wrote:
> 
> On Wed, Feb 15, 2017 at 3:22 PM, Wiles, Keith <keith.wiles@intel.com> wrote:
>> 
>>> On Feb 15, 2017, at 8:15 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>>> 
>>> 
>>> Just ignore this comment - I am misunderstood something.
>>> 
>>> But another question: Is there specific reason VDEV should be registered/scanned *after* other devices? Is there some specific problem if we do otherwise? (I think this is should be done, but I don't have a specific reason).
>> 
> 
> Just for context: the vdev's are probed after the physical devices
> because of commit f4ce209a ("eal: postpone vdev initialization").
> 
>> Does the bonding driver which uses physical devices need to be registered after physical ones? In Pktgen I noticed the vdev after the physical ports and I could not blacklist them as the bonding driver needed them, which caused the bonding ports to have a greater port number. In the case of pktgen the bonding ports were up around 8 or 10 and caused the display to not show the bonding ports. This is really just a usability problem for the developer using Pktgen. I would like to see the vdev devices first, but as long as the drivers (like bonding) are fine with them being first.
>> 
> 
> The bonding devargs might specify slaves that get attached during
> device probe. If the referenced devices are physical interfaces we
> need to probe them first. This is really a chicken-egg-problem.
> 
> Maybe you could improve the usability in your case and sort the
> virtual devices first or even hide enslaved ports?

The port numbering comes from DPDK and I use that directly, was trying to avoid a translation of real port to Pktgen port :-(

Regards,
Keith

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (6 preceding siblings ...)
  2017-02-15 10:02 ` [PATCH 7/7] eal: make virtual bus use rte_vdev_device Jan Blunck
@ 2017-02-15 17:11 ` Ferruh Yigit
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 91+ messages in thread
From: Ferruh Yigit @ 2017-02-15 17:11 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: shreyansh.jain

On 2/15/2017 10:02 AM, Jan Blunck wrote:
> With the rte_bus infrastructure present in 17.02 it is possible to refactor
> the virtual device probing into a bus. This series also introduces the
> rte_vdev_device to better keep track of devices.
> 
> Jan Blunck (7):
>   eal: use different constructor priorities for initcalls
>   eal: probe legacy PCI devices before other bus devices
>   eal: move virtual device probing into a bus
>   eal: remove unused rte_eal_dev_init()
>   eal: Refactor vdev driver probe/remove
>   eal: add struct rte_vdev_device
>   eal: make virtual bus use rte_vdev_device

It looks like this patchset depends [1], worth mentioning here.

[1]
http://dpdk.org/dev/patchwork/patch/20416/
http://dpdk.org/dev/patchwork/patch/20417/


Overall, after dependent patches get:

Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 4/7] eal: remove unused rte_eal_dev_init()
  2017-02-15 10:02 ` [PATCH 4/7] eal: remove unused rte_eal_dev_init() Jan Blunck
@ 2017-02-15 17:11   ` Ferruh Yigit
  0 siblings, 0 replies; 91+ messages in thread
From: Ferruh Yigit @ 2017-02-15 17:11 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: shreyansh.jain

On 2/15/2017 10:02 AM, Jan Blunck wrote:
> Signed-off-by: Jan Blunck <jblunck@infradead.org>

<...>

> -int
> -rte_eal_dev_init(void)
> -{
> -	return 0;
> -}
> -

API should be removed from .map files too (rte_eal_version.map).

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 6/7] eal: add struct rte_vdev_device
  2017-02-15 10:02 ` [PATCH 6/7] eal: add struct rte_vdev_device Jan Blunck
@ 2017-02-15 17:11   ` Ferruh Yigit
  2017-02-16 15:55     ` Jan Blunck
  0 siblings, 1 reply; 91+ messages in thread
From: Ferruh Yigit @ 2017-02-15 17:11 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: shreyansh.jain

On 2/15/2017 10:02 AM, Jan Blunck wrote:
> This adds the rte_vdev_device structure which embeds a generic rte_device.
> 
> Signed-off-by: Jan Blunck <jblunck@infradead.org>

<...>

>  
> +struct rte_vdev_device {
> +	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
> +	struct rte_device device;               /**< Inherit core device */

What do you think adding a name field here ?

"dev->device.devargs->virt.drv_name" used a few times, since probing
virtual devices done based on name.

This is device name, and accessing it via "devargs->virt.drv_name" is
not that clear. It is possible to create a name field here, set it
during probe or init to point devargs field and use it wherever
required, does it make sense?

> +};
> +
>  /** Double linked list of virtual device drivers. */
>  TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
>  
> 

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 7/7] eal: make virtual bus use rte_vdev_device
  2017-02-15 10:02 ` [PATCH 7/7] eal: make virtual bus use rte_vdev_device Jan Blunck
@ 2017-02-15 17:11   ` Ferruh Yigit
  0 siblings, 0 replies; 91+ messages in thread
From: Ferruh Yigit @ 2017-02-15 17:11 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: shreyansh.jain

On 2/15/2017 10:02 AM, Jan Blunck wrote:
> This allows the virtual bus to be rescanned and probed by tracking the
> creation of rte_vdev_device.
> 
> Signed-off-by: Jan Blunck <jblunck@infradead.org>

<...>

> +
> +	dev->device.devargs = devargs;
> +	dev->device.numa_node = -1;

SOCKET_ID_ANY can be used instead of -1

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 17:10           ` Wiles, Keith
@ 2017-02-15 17:22             ` Wiles, Keith
  0 siblings, 0 replies; 91+ messages in thread
From: Wiles, Keith @ 2017-02-15 17:22 UTC (permalink / raw)
  To: Jan Blunck; +Cc: Shreyansh Jain, dev


> On Feb 15, 2017, at 11:10 AM, Wiles, Keith <keith.wiles@intel.com> wrote:
> 
> 
>> On Feb 15, 2017, at 11:06 AM, Jan Blunck <jblunck@infradead.org> wrote:
>> 
>> On Wed, Feb 15, 2017 at 3:22 PM, Wiles, Keith <keith.wiles@intel.com> wrote:
>>> 
>>>> On Feb 15, 2017, at 8:15 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>>>> 
>>>> 
>>>> Just ignore this comment - I am misunderstood something.
>>>> 
>>>> But another question: Is there specific reason VDEV should be registered/scanned *after* other devices? Is there some specific problem if we do otherwise? (I think this is should be done, but I don't have a specific reason).
>>> 
>> 
>> Just for context: the vdev's are probed after the physical devices
>> because of commit f4ce209a ("eal: postpone vdev initialization").
>> 
>>> Does the bonding driver which uses physical devices need to be registered after physical ones? In Pktgen I noticed the vdev after the physical ports and I could not blacklist them as the bonding driver needed them, which caused the bonding ports to have a greater port number. In the case of pktgen the bonding ports were up around 8 or 10 and caused the display to not show the bonding ports. This is really just a usability problem for the developer using Pktgen. I would like to see the vdev devices first, but as long as the drivers (like bonding) are fine with them being first.
>>> 
>> 
>> The bonding devargs might specify slaves that get attached during
>> device probe. If the referenced devices are physical interfaces we
>> need to probe them first. This is really a chicken-egg-problem.
>> 
>> Maybe you could improve the usability in your case and sort the
>> virtual devices first or even hide enslaved ports?
> 
> The port numbering comes from DPDK and I use that directly, was trying to avoid a translation of real port to Pktgen port :-(
> 
> Regards,
> Keith
> 

Looking at the bonding driver it does not attempt to access the physical ports until bond_ethdev_configure call (I believe). This means the vdev devices should be following the same flow and moving them to before the physical probes would be fine, right?

Regards,
Keith

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 14:27         ` Shreyansh Jain
@ 2017-02-15 17:25           ` Jerin Jacob
  2017-02-15 18:09             ` Wiles, Keith
  0 siblings, 1 reply; 91+ messages in thread
From: Jerin Jacob @ 2017-02-15 17:25 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: Wiles, Keith, Jan Blunck, dev

On Wed, Feb 15, 2017 at 02:27:47PM +0000, Shreyansh Jain wrote:
> > -----Original Message-----
> > From: Wiles, Keith [mailto:keith.wiles@intel.com]
> > Sent: Wednesday, February 15, 2017 7:53 PM
> > To: Shreyansh Jain <shreyansh.jain@nxp.com>
> > Cc: Jan Blunck <jblunck@infradead.org>; dev@dpdk.org
> > Subject: Re: [dpdk-dev] [PATCH 3/7] eal: move virtual device probing into a
> > bus
> > 
> > 
> > > On Feb 15, 2017, at 8:15 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> > >
> > > On Wednesday 15 February 2017 07:41 PM, Shreyansh Jain wrote:
> > >> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
> > >>> This is a refactoring of the virtual device probing which moves into into
> > >>> a proper bus structure.
> > >>>
> > >>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> > >>> ---
> > >>> lib/librte_eal/common/eal_common_dev.c  | 22 -----------------
> > >>> lib/librte_eal/common/eal_common_vdev.c | 44
> > >>> +++++++++++++++++++++++++++++++++
> > >>> 2 files changed, 44 insertions(+), 22 deletions(-)
> > >>>
> > >>
> > >> [...]
> > >>
> > >>>
> > >>> diff --git a/lib/librte_eal/common/eal_common_vdev.c
> > >>> b/lib/librte_eal/common/eal_common_vdev.c
> > >>> index 7d6e54f..523a3d6 100644
> > >>> --- a/lib/librte_eal/common/eal_common_vdev.c
> > >>> +++ b/lib/librte_eal/common/eal_common_vdev.c
> > >>> @@ -37,8 +37,10 @@
> > >>> #include <stdint.h>
> > >>> #include <sys/queue.h>
> > >>>
> > >> [...]
> > >>
> > >>> +
> > >>> +static struct rte_bus rte_vdev_bus = {
> > >>> +    .scan = vdev_scan,
> > >>> +    .probe = vdev_probe,
> > >>> +};
> > >>> +
> > >>> +RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
> > >>>
> > >>
> > >> Does it matter if VDEV buses are registered before or after other
> > >> buses? Either way, the callbacks would be called in the order specified
> > >> in EAL.
> > >>
> > >>
> > >
> > > Just ignore this comment - I am misunderstood something.
> > >
> > > But another question: Is there specific reason VDEV should be
> > registered/scanned *after* other devices? Is there some specific problem if
> > we do otherwise? (I think this is should be done, but I don't have a specific
> > reason).
> > 
> > Does the bonding driver which uses physical devices need to be registered
> > after physical ones? In Pktgen I noticed the vdev after the physical ports
> > and I could not blacklist them as the bonding driver needed them, which
> > caused the bonding ports to have a greater port number. In the case of pktgen
> > the bonding ports were up around 8 or 10 and caused the display to not show
> > the bonding ports. This is really just a usability problem for the developer
> > using Pktgen. I would like to see the vdev devices first, but as long as the
> > drivers (like bonding) are fine with them being first.
> 
> Ah, now I remember - there was a patch from Jerin for this.
> Probably he is the best person to comment here.
> (I don't have much insight here).

commit f4ce209a8ce5f416b61c76cee773bc54749e2048
Author: Jerin Jacob <jerin.jacob@caviumnetworks.com>
Date:   Sun Nov 20 13:30:50 2016 +0530

    eal: postpone vdev initialization

    Some platform like octeontx may use pci and
    vdev based combined device to represent a logical
    dpdk functional device.In such case, postponing the
    vdev initialization after pci device
    initialization will provide the better view of
    the pci device resources in the system in
    vdev's probe function, and it allows better
    functional subsystem registration in vdev probe
    function.

    As a bonus, This patch fixes a bond device
    initialization use case.

    example command to reproduce the issue:
    ./testpmd -c 0x2  --vdev 'eth_bond0,mode=0,
    slave=0000:02:00.0,slave=0000:03:00.0' --
    --port-topology=chained

    root cause:
    In existing case(vdev initialization and then pci
    initialization), creates three Ethernet ports with
    following port ids
    0 - Bond device
    1 - PCI device 0
    2 - PCI devive 1

    Since testpmd, calls the configure/start on all the ports on
    start up,it will translate to following illegal setup sequence

    1)bond device configure/start
    1.1) pci device0 stop/configure/start
    1.2) pci device1 stop/configure/start
    2)pci device 0 configure(illegal setup case,
    as device in start state)

    The fix changes the initialization sequence and
    allow initialization in following valid setup order
    1) pcie device 0 configure/start
    2) pcie device 1 configure/start
    3) bond device 2 configure/start
    3.1) pcie device 0/stop/configure/start
    3.2) pcie device 1/stop/configure/start

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 17:25           ` Jerin Jacob
@ 2017-02-15 18:09             ` Wiles, Keith
  2017-02-15 20:06               ` Jan Blunck
  0 siblings, 1 reply; 91+ messages in thread
From: Wiles, Keith @ 2017-02-15 18:09 UTC (permalink / raw)
  To: Jerin Jacob; +Cc: Shreyansh Jain, Jan Blunck, dev


> On Feb 15, 2017, at 11:25 AM, Jerin Jacob <jerin.jacob@caviumnetworks.com> wrote:
> 
> On Wed, Feb 15, 2017 at 02:27:47PM +0000, Shreyansh Jain wrote:
>>> -----Original Message-----
>>> From: Wiles, Keith [mailto:keith.wiles@intel.com]
>>> Sent: Wednesday, February 15, 2017 7:53 PM
>>> To: Shreyansh Jain <shreyansh.jain@nxp.com>
>>> Cc: Jan Blunck <jblunck@infradead.org>; dev@dpdk.org
>>> Subject: Re: [dpdk-dev] [PATCH 3/7] eal: move virtual device probing into a
>>> bus
>>> 
>>> 
>>>> On Feb 15, 2017, at 8:15 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>>>> 
>>>> On Wednesday 15 February 2017 07:41 PM, Shreyansh Jain wrote:
>>>>> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
>>>>>> This is a refactoring of the virtual device probing which moves into into
>>>>>> a proper bus structure.
>>>>>> 
>>>>>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>>>>>> ---
>>>>>> lib/librte_eal/common/eal_common_dev.c  | 22 -----------------
>>>>>> lib/librte_eal/common/eal_common_vdev.c | 44
>>>>>> +++++++++++++++++++++++++++++++++
>>>>>> 2 files changed, 44 insertions(+), 22 deletions(-)
>>>>>> 
>>>>> 
>>>>> [...]
>>>>> 
>>>>>> 
>>>>>> diff --git a/lib/librte_eal/common/eal_common_vdev.c
>>>>>> b/lib/librte_eal/common/eal_common_vdev.c
>>>>>> index 7d6e54f..523a3d6 100644
>>>>>> --- a/lib/librte_eal/common/eal_common_vdev.c
>>>>>> +++ b/lib/librte_eal/common/eal_common_vdev.c
>>>>>> @@ -37,8 +37,10 @@
>>>>>> #include <stdint.h>
>>>>>> #include <sys/queue.h>
>>>>>> 
>>>>> [...]
>>>>> 
>>>>>> +
>>>>>> +static struct rte_bus rte_vdev_bus = {
>>>>>> +    .scan = vdev_scan,
>>>>>> +    .probe = vdev_probe,
>>>>>> +};
>>>>>> +
>>>>>> +RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
>>>>>> 
>>>>> 
>>>>> Does it matter if VDEV buses are registered before or after other
>>>>> buses? Either way, the callbacks would be called in the order specified
>>>>> in EAL.
>>>>> 
>>>>> 
>>>> 
>>>> Just ignore this comment - I am misunderstood something.
>>>> 
>>>> But another question: Is there specific reason VDEV should be
>>> registered/scanned *after* other devices? Is there some specific problem if
>>> we do otherwise? (I think this is should be done, but I don't have a specific
>>> reason).
>>> 
>>> Does the bonding driver which uses physical devices need to be registered
>>> after physical ones? In Pktgen I noticed the vdev after the physical ports
>>> and I could not blacklist them as the bonding driver needed them, which
>>> caused the bonding ports to have a greater port number. In the case of pktgen
>>> the bonding ports were up around 8 or 10 and caused the display to not show
>>> the bonding ports. This is really just a usability problem for the developer
>>> using Pktgen. I would like to see the vdev devices first, but as long as the
>>> drivers (like bonding) are fine with them being first.
>> 
>> Ah, now I remember - there was a patch from Jerin for this.
>> Probably he is the best person to comment here.
>> (I don't have much insight here).
> 
> commit f4ce209a8ce5f416b61c76cee773bc54749e2048
> Author: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> Date:   Sun Nov 20 13:30:50 2016 +0530
> 
>    eal: postpone vdev initialization
> 
>    Some platform like octeontx may use pci and
>    vdev based combined device to represent a logical
>    dpdk functional device.In such case, postponing the
>    vdev initialization after pci device
>    initialization will provide the better view of
>    the pci device resources in the system in
>    vdev's probe function, and it allows better
>    functional subsystem registration in vdev probe
>    function.
> 
>    As a bonus, This patch fixes a bond device
>    initialization use case.
> 
>    example command to reproduce the issue:
>    ./testpmd -c 0x2  --vdev 'eth_bond0,mode=0,
>    slave=0000:02:00.0,slave=0000:03:00.0' --
>    --port-topology=chained
> 
>    root cause:
>    In existing case(vdev initialization and then pci
>    initialization), creates three Ethernet ports with
>    following port ids
>    0 - Bond device
>    1 - PCI device 0
>    2 - PCI devive 1
> 
>    Since testpmd, calls the configure/start on all the ports on
>    start up,it will translate to following illegal setup sequence

I guess I see this differently, meaning we modified the system to put vdev devices last only because we do not have clean way to startup the system for pdev/vdev devices. The application should be agnostic to the devices being started and the system needs to determine the correct order without a chicken and egg problem. The test-pmd application just starts from 0 to n to initialize devices, which he should be able to do in any order. It is possible the application could initialize the devices (pdev/vdev) in any order, which the current design would break if they tried to init the bonding driver first.

What happens if a vdev needs to be initialized before a pdev device?

Not saying we need to solve this problem now, but need to figure this out some how. Maybe we need a priority for pdev/vdev devices to determine init order????

> 
>    1)bond device configure/start
>    1.1) pci device0 stop/configure/start
>    1.2) pci device1 stop/configure/start
>    2)pci device 0 configure(illegal setup case,
>    as device in start state)
> 
>    The fix changes the initialization sequence and
>    allow initialization in following valid setup order
>    1) pcie device 0 configure/start
>    2) pcie device 1 configure/start
>    3) bond device 2 configure/start
>    3.1) pcie device 0/stop/configure/start
>    3.2) pcie device 1/stop/configure/start

Regards,
Keith

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 18:09             ` Wiles, Keith
@ 2017-02-15 20:06               ` Jan Blunck
  2017-02-15 21:56                 ` Wiles, Keith
  0 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-15 20:06 UTC (permalink / raw)
  To: Wiles, Keith; +Cc: Jerin Jacob, Shreyansh Jain, dev

On Wed, Feb 15, 2017 at 7:09 PM, Wiles, Keith <keith.wiles@intel.com> wrote:
>
> I guess I see this differently, meaning we modified the system to put vdev devices last only because we do not have clean way to startup the system for pdev/vdev devices. The application should be agnostic to the devices being started and the system needs to determine the correct order without a chicken and egg problem. The test-pmd application just starts from 0 to n to initialize devices, which he should be able to do in any order. It is possible the application could initialize the devices (pdev/vdev) in any order, which the current design would break if they tried to init the bonding driver first.
>

Apart from the usability (vdevs always first) I wonder what kind of
usecase you are after. If I understand you correctly you want to:
- probe the virtual devices first
- start/configure the virtual devices last

... and only in some cases. From what I understand this requires a
domain specific way to model dependencies between ports, e.g. some
standardized device arguments parsed by EAL, and combined with your
requirement to assign the lowest port numbers for the vdev devices
even a scheduler.

Maybe we could reduce complexity by doing some simple things instead:
if you present the ports in reverse order to the users the vdev come
first. Probably this even increases usability because the most recent
created port is the one that the user is anyway most interested in.

> What happens if a vdev needs to be initialized before a pdev device?
>

This should never happen. The pdev devices offer a plain view on the
"system", which means no topology at all. The vdev devices are devices
that do not have a "system" representation, e.g. a library. I don't
think the EAL should offer an alternative API to system programming in
a way that you enumerate your PCI devices through a vdev that is
accessing hardware through another library.

> Not saying we need to solve this problem now, but need to figure this out some how. Maybe we need a priority for pdev/vdev devices to determine init order????
>

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 3/7] eal: move virtual device probing into a bus
  2017-02-15 20:06               ` Jan Blunck
@ 2017-02-15 21:56                 ` Wiles, Keith
  0 siblings, 0 replies; 91+ messages in thread
From: Wiles, Keith @ 2017-02-15 21:56 UTC (permalink / raw)
  To: Jan Blunck; +Cc: Jerin Jacob, Shreyansh Jain, dev


> On Feb 15, 2017, at 2:06 PM, Jan Blunck <jblunck@infradead.org> wrote:
> 
> On Wed, Feb 15, 2017 at 7:09 PM, Wiles, Keith <keith.wiles@intel.com> wrote:
>> 
>> I guess I see this differently, meaning we modified the system to put vdev devices last only because we do not have clean way to startup the system for pdev/vdev devices. The application should be agnostic to the devices being started and the system needs to determine the correct order without a chicken and egg problem. The test-pmd application just starts from 0 to n to initialize devices, which he should be able to do in any order. It is possible the application could initialize the devices (pdev/vdev) in any order, which the current design would break if they tried to init the bonding driver first.
>> 
> 
> Apart from the usability (vdevs always first) I wonder what kind of
> usecase you are after. If I understand you correctly you want to:
> - probe the virtual devices first
> - start/configure the virtual devices last
> 
> ... and only in some cases. From what I understand this requires a
> domain specific way to model dependencies between ports, e.g. some
> standardized device arguments parsed by EAL, and combined with your
> requirement to assign the lowest port numbers for the vdev devices
> even a scheduler.

I do not think moving vdev to the front is going to really solve my use case it, as it will create more problems then solve. The real case here is if the application developer inits devices out of order then he can hit the bonding driver bug. The current solution does not really fix the problem only bandaid the problem for the common ordered case.

Do we need to solve this problem, maybe not, but it needs to be documented or we need to provide a cleaner way for the application to startup all devices in the correct order. A possible way is to have callback to the application in the correct order for him to initialize the devices, but not a great solution per say.

> 
> Maybe we could reduce complexity by doing some simple things instead:
> if you present the ports in reverse order to the users the vdev come
> first. Probably this even increases usability because the most recent
> created port is the one that the user is anyway most interested in.
> 
>> What happens if a vdev needs to be initialized before a pdev device?
>> 
> 
> This should never happen. The pdev devices offer a plain view on the
> "system", which means no topology at all. The vdev devices are devices
> that do not have a "system" representation, e.g. a library. I don't
> think the EAL should offer an alternative API to system programming in
> a way that you enumerate your PCI devices through a vdev that is
> accessing hardware through another library.
> 
>> Not saying we need to solve this problem now, but need to figure this out some how. Maybe we need a priority for pdev/vdev devices to determine init order????
>> 

Regards,
Keith

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 1/7] eal: use different constructor priorities for initcalls
  2017-02-15 15:05     ` Jan Blunck
@ 2017-02-16  5:59       ` Shreyansh Jain
  0 siblings, 0 replies; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-16  5:59 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev

On Wednesday 15 February 2017 08:35 PM, Jan Blunck wrote:
> On Wed, Feb 15, 2017 at 3:37 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
>>>
>>> --- a/lib/librte_eal/common/include/rte_eal.h
>>> +++ b/lib/librte_eal/common/include/rte_eal.h
>>> @@ -258,8 +258,16 @@ static inline int rte_gettid(void)
>>>         return RTE_PER_LCORE(_thread_id);
>>>  }
>>>
>>> -#define RTE_INIT(func) \
>>> -static void __attribute__((constructor, used)) func(void)
>>> +#define RTE_EAL_INIT(func) \
>>> +static void __attribute__((constructor(101), used)) func(void)
>>> +
>>> +#define RTE_POST_EAL_INIT(func) \
>>> +static void __attribute__((constructor(102), used)) func(void)
>>> +
>>> +#define RTE_DEV_INIT(func) \
>>> +static void __attribute__((constructor(103), used)) func(void)
>>
>>
>> Shouldn't we simply allow this priority to be default to allow for some
>> priority space between buses and default init?
>>
>
> The absolute numbers are not that important. We can always adjust
> them. Important is the relative order. If you have a use-case for
> something that needs to be initialized before the devices but can't
> get initialized with the eal/post-eal then please speak up.
>

No use-case as of now.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH 6/7] eal: add struct rte_vdev_device
  2017-02-15 17:11   ` Ferruh Yigit
@ 2017-02-16 15:55     ` Jan Blunck
  0 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-16 15:55 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev, Shreyansh Jain

On Wed, Feb 15, 2017 at 6:11 PM, Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> On 2/15/2017 10:02 AM, Jan Blunck wrote:
>> This adds the rte_vdev_device structure which embeds a generic rte_device.
>>
>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>
> <...>
>
>>
>> +struct rte_vdev_device {
>> +     TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
>> +     struct rte_device device;               /**< Inherit core device */
>
> What do you think adding a name field here ?
>
> "dev->device.devargs->virt.drv_name" used a few times, since probing
> virtual devices done based on name.
>
> This is device name, and accessing it via "devargs->virt.drv_name" is
> not that clear. It is possible to create a name field here, set it
> during probe or init to point devargs field and use it wherever
> required, does it make sense?
>

Why don't we add such a thing to the generic rte_device instead? While
we are at it we might want to also add a driver private data field.

Thoughts?

^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH v2 0/8] Rework vdev probing to use rte_bus infrastructure
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (7 preceding siblings ...)
  2017-02-15 17:11 ` [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Ferruh Yigit
@ 2017-02-20 14:17 ` Jan Blunck
  2017-02-21  6:44   ` Shreyansh Jain
                     ` (11 more replies)
  2017-02-20 14:17 ` [PATCH v2 1/8] eal: use different constructor priorities for initcalls Jan Blunck
                   ` (7 subsequent siblings)
  16 siblings, 12 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-20 14:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

With the rte_bus infrastructure present in 17.02 it is possible to refactor
the virtual device probing into a bus. This series also introduces the
rte_vdev_device to better keep track of devices.

This patchset depends on:
http://dpdk.org/dev/patchwork/patch/20416/
http://dpdk.org/dev/patchwork/patch/20417/

Changes since version 1:
 * addition of rte_vdev_device_name() helper
 * removed rte_eal_dev_init() from *.map files
 * use SOCKET_ID_ANY

Jan Blunck (8):
  eal: use different constructor priorities for initcalls
  eal: probe legacy PCI devices before other bus devices
  eal: move virtual device probing into a bus
  eal: remove unused rte_eal_dev_init()
  eal: Refactor vdev driver probe/remove
  eal: add struct rte_vdev_device
  eal: add virtual device name helper function
  eal: make virtual bus use rte_vdev_device

 lib/librte_eal/bsdapp/eal/eal.c                 |   9 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   7 +-
 lib/librte_eal/common/eal_common_dev.c          |  28 ---
 lib/librte_eal/common/eal_common_vdev.c         | 252 +++++++++++++++++++++---
 lib/librte_eal/common/include/rte_bus.h         |  17 +-
 lib/librte_eal/common/include/rte_dev.h         |   5 -
 lib/librte_eal/common/include/rte_eal.h         |  12 +-
 lib/librte_eal/common/include/rte_tailq.h       |   2 +-
 lib/librte_eal/common/include/rte_vdev.h        |   7 +
 lib/librte_eal/linuxapp/eal/eal.c               |   9 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 -
 11 files changed, 268 insertions(+), 81 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH v2 1/8] eal: use different constructor priorities for initcalls
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (8 preceding siblings ...)
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
@ 2017-02-20 14:17 ` Jan Blunck
  2017-02-21 12:30   ` Ferruh Yigit
  2017-02-20 14:17 ` [PATCH v2 2/8] eal: probe legacy PCI devices before other bus devices Jan Blunck
                   ` (6 subsequent siblings)
  16 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-20 14:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This introduces different initcall macros to allow for late registration of
the virtual device bus.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_eal/common/include/rte_bus.h   | 17 ++++++++++++++++-
 lib/librte_eal/common/include/rte_eal.h   | 12 ++++++++++--
 lib/librte_eal/common/include/rte_tailq.h |  2 +-
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 7c36969..9f161f2 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -50,6 +50,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 
+#include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_dev.h>
 
@@ -145,7 +146,21 @@ void rte_bus_dump(FILE *f);
  * The constructor has higher priority than PMD constructors.
  */
 #define RTE_REGISTER_BUS(nm, bus) \
-static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
+RTE_EAL_INIT(businitfn_ ##nm); \
+static void businitfn_ ##nm(void) \
+{\
+	(bus).name = RTE_STR(nm);\
+	rte_bus_register(&bus); \
+}
+
+/**
+ * Helper for late Bus registration.
+ * The constructor still has higher priority than PMD constructors but has
+ * lower priority than RTE_REGISTER_BUS.
+ */
+#define RTE_REGISTER_BUS_LATE(nm, bus) \
+RTE_POST_EAL_INIT(businitfn_ ##nm); \
+static void businitfn_ ##nm(void) \
 {\
 	(bus).name = RTE_STR(nm);\
 	rte_bus_register(&bus); \
diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
index 03fee50..3a6bd71 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -258,8 +258,16 @@ static inline int rte_gettid(void)
 	return RTE_PER_LCORE(_thread_id);
 }
 
-#define RTE_INIT(func) \
-static void __attribute__((constructor, used)) func(void)
+#define RTE_EAL_INIT(func) \
+static void __attribute__((constructor(101), used)) func(void)
+
+#define RTE_POST_EAL_INIT(func) \
+static void __attribute__((constructor(102), used)) func(void)
+
+#define RTE_DEV_INIT(func) \
+static void __attribute__((constructor(103), used)) func(void)
+
+#define RTE_INIT(func) RTE_DEV_INIT(func)
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_eal/common/include/rte_tailq.h b/lib/librte_eal/common/include/rte_tailq.h
index 3aae098..07ceec1 100644
--- a/lib/librte_eal/common/include/rte_tailq.h
+++ b/lib/librte_eal/common/include/rte_tailq.h
@@ -148,7 +148,7 @@ struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
 int rte_eal_tailq_register(struct rte_tailq_elem *t);
 
 #define EAL_REGISTER_TAILQ(t) \
-RTE_INIT(tailqinitfn_ ##t); \
+RTE_EAL_INIT(tailqinitfn_ ##t); \
 static void tailqinitfn_ ##t(void) \
 { \
 	if (rte_eal_tailq_register(&t) < 0) \
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v2 2/8] eal: probe legacy PCI devices before other bus devices
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (9 preceding siblings ...)
  2017-02-20 14:17 ` [PATCH v2 1/8] eal: use different constructor priorities for initcalls Jan Blunck
@ 2017-02-20 14:17 ` Jan Blunck
  2017-02-20 14:17 ` [PATCH v2 3/8] eal: move virtual device probing into a bus Jan Blunck
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-20 14:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

Make sure that the PCI devices are probed before the virtual devices after
the legacy virtual device probing has been moved to a bus.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c   | 8 ++++----
 lib/librte_eal/linuxapp/eal/eal.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index ee7c9de..a584447 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -613,14 +613,14 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe all the buses and devices/drivers on them */
-	if (rte_bus_probe())
-		rte_panic("Cannot probe devices\n");
-
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	/* Probe all the buses and devices/drivers on them */
+	if (rte_bus_probe())
+		rte_panic("Cannot probe devices\n");
+
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index bf6b818..f77ff5c 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -884,14 +884,14 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe all the buses and devices/drivers on them */
-	if (rte_bus_probe())
-		rte_panic("Cannot probe devices\n");
-
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	/* Probe all the buses and devices/drivers on them */
+	if (rte_bus_probe())
+		rte_panic("Cannot probe devices\n");
+
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v2 3/8] eal: move virtual device probing into a bus
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (10 preceding siblings ...)
  2017-02-20 14:17 ` [PATCH v2 2/8] eal: probe legacy PCI devices before other bus devices Jan Blunck
@ 2017-02-20 14:17 ` Jan Blunck
  2017-02-20 14:17 ` [PATCH v2 4/8] eal: remove unused rte_eal_dev_init() Jan Blunck
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-20 14:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This is a refactoring of the virtual device probing which moves into into
a proper bus structure.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_eal/common/eal_common_dev.c  | 22 -----------------
 lib/librte_eal/common/eal_common_vdev.c | 44 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4f3b493..1ce90f6 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -79,28 +79,6 @@ void rte_eal_device_remove(struct rte_device *dev)
 int
 rte_eal_dev_init(void)
 {
-	struct rte_devargs *devargs;
-
-	/*
-	 * Note that the dev_driver_list is populated here
-	 * from calls made to rte_eal_driver_register from constructor functions
-	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
-	 */
-
-	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
-
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
-			continue;
-
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-					devargs->args)) {
-			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-					devargs->virt.drv_name);
-			return -1;
-		}
-	}
-
 	return 0;
 }
 
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 7d6e54f..523a3d6 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -37,8 +37,10 @@
 #include <stdint.h>
 #include <sys/queue.h>
 
+#include <rte_bus.h>
 #include <rte_vdev.h>
 #include <rte_common.h>
+#include <rte_devargs.h>
 
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
@@ -122,3 +124,45 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+static int
+vdev_scan(void)
+{
+	/* for virtual devices we don't need to scan anything */
+	return 0;
+}
+
+static int
+vdev_probe(void)
+{
+	struct rte_devargs *devargs;
+
+	/*
+	 * Note that the dev_driver_list is populated here
+	 * from calls made to rte_eal_driver_register from constructor functions
+	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
+	 */
+
+	/* call the init function for each virtual device */
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		if (rte_eal_vdev_init(devargs->virt.drv_name,
+				      devargs->args)) {
+			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
+				devargs->virt.drv_name);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+static struct rte_bus rte_vdev_bus = {
+	.scan = vdev_scan,
+	.probe = vdev_probe,
+};
+
+RTE_REGISTER_BUS_LATE(virtual, rte_vdev_bus);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v2 4/8] eal: remove unused rte_eal_dev_init()
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (11 preceding siblings ...)
  2017-02-20 14:17 ` [PATCH v2 3/8] eal: move virtual device probing into a bus Jan Blunck
@ 2017-02-20 14:17 ` Jan Blunck
  2017-02-20 14:17 ` [PATCH v2 5/8] eal: Refactor vdev driver probe/remove Jan Blunck
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-20 14:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal.c                 | 3 ---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   | 1 -
 lib/librte_eal/common/eal_common_dev.c          | 6 ------
 lib/librte_eal/common/include/rte_dev.h         | 5 -----
 lib/librte_eal/linuxapp/eal/eal.c               | 3 ---
 lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 -
 6 files changed, 19 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index a584447..3d29fcb 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -621,9 +621,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	if (rte_eal_dev_init() < 0)
-		rte_panic("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 2cf1ac8..0116085 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -22,7 +22,6 @@ DPDK_2.0 {
 	rte_dump_tailq;
 	rte_eal_alarm_cancel;
 	rte_eal_alarm_set;
-	rte_eal_dev_init;
 	rte_eal_devargs_add;
 	rte_eal_devargs_dump;
 	rte_eal_devargs_type_count;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 1ce90f6..4bde430 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -76,12 +76,6 @@ void rte_eal_device_remove(struct rte_device *dev)
 	TAILQ_REMOVE(&dev_device_list, dev, next);
 }
 
-int
-rte_eal_dev_init(void)
-{
-	return 0;
-}
-
 int rte_eal_dev_attach(const char *name, const char *devargs)
 {
 	struct rte_pci_addr addr;
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index b17791f..4251099 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -171,11 +171,6 @@ void rte_eal_driver_register(struct rte_driver *driver);
 void rte_eal_driver_unregister(struct rte_driver *driver);
 
 /**
- * Initalize all the registered drivers in this process
- */
-int rte_eal_dev_init(void);
-
-/**
  * Initialize a driver specified by name.
  *
  * @param name
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index f77ff5c..88479de 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -892,9 +892,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	if (rte_eal_dev_init() < 0)
-		rte_panic("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 3c68ff5..41b0cb4 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -22,7 +22,6 @@ DPDK_2.0 {
 	rte_dump_tailq;
 	rte_eal_alarm_cancel;
 	rte_eal_alarm_set;
-	rte_eal_dev_init;
 	rte_eal_devargs_add;
 	rte_eal_devargs_dump;
 	rte_eal_devargs_type_count;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v2 5/8] eal: Refactor vdev driver probe/remove
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (12 preceding siblings ...)
  2017-02-20 14:17 ` [PATCH v2 4/8] eal: remove unused rte_eal_dev_init() Jan Blunck
@ 2017-02-20 14:17 ` Jan Blunck
  2017-02-20 14:17 ` [PATCH v2 6/8] eal: add struct rte_vdev_device Jan Blunck
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-20 14:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This is a preparation for the introduction of the struct rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 44 ++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 523a3d6..6ba3c91 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -61,14 +61,11 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 	TAILQ_REMOVE(&vdev_driver_list, driver, next);
 }
 
-int
-rte_eal_vdev_init(const char *name, const char *args)
+static int
+vdev_probe_all_drivers(const char *name, const char *args)
 {
 	struct rte_vdev_driver *driver;
 
-	if (name == NULL)
-		return -EINVAL;
-
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -89,18 +86,29 @@ rte_eal_vdev_init(const char *name, const char *args)
 			return driver->probe(name, args);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
 }
 
 int
-rte_eal_vdev_uninit(const char *name)
+rte_eal_vdev_init(const char *name, const char *args)
 {
-	struct rte_vdev_driver *driver;
+	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
+	ret = vdev_probe_all_drivers(name, args);
+	if (ret  > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
+}
+
+static int
+vdev_remove_driver(const char *name)
+{
+	struct rte_vdev_driver *driver;
+
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -121,8 +129,22 @@ rte_eal_vdev_uninit(const char *name)
 			return driver->remove(name);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
+}
+
+int
+rte_eal_vdev_uninit(const char *name)
+{
+	int ret;
+
+	if (name == NULL)
+		return -EINVAL;
+
+	ret = vdev_remove_driver(name);
+	if (ret > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
 }
 
 static int
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v2 6/8] eal: add struct rte_vdev_device
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (13 preceding siblings ...)
  2017-02-20 14:17 ` [PATCH v2 5/8] eal: Refactor vdev driver probe/remove Jan Blunck
@ 2017-02-20 14:17 ` Jan Blunck
  2017-02-20 14:17 ` [PATCH v2 7/8] eal: add virtual device name helper function Jan Blunck
  2017-02-20 14:17 ` [PATCH v2 8/8] eal: make virtual bus use rte_vdev_device Jan Blunck
  16 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-20 14:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This adds the rte_vdev_device structure which embeds a generic rte_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_eal/common/eal_common_vdev.c  | 5 +++++
 lib/librte_eal/common/include/rte_vdev.h | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 6ba3c91..61677de 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -42,6 +42,11 @@
 #include <rte_common.h>
 #include <rte_devargs.h>
 
+/** Double linked list of virtual device drivers. */
+TAILQ_HEAD(vdev_device_list, rte_vdev_device);
+
+static struct vdev_device_list vdev_device_list =
+	TAILQ_HEAD_INITIALIZER(vdev_device_list);
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
 
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 784e837..8f98372 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -40,6 +40,11 @@ extern "C" {
 #include <sys/queue.h>
 #include <rte_dev.h>
 
+struct rte_vdev_device {
+	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
+	struct rte_device device;               /**< Inherit core device */
+};
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v2 7/8] eal: add virtual device name helper function
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (14 preceding siblings ...)
  2017-02-20 14:17 ` [PATCH v2 6/8] eal: add struct rte_vdev_device Jan Blunck
@ 2017-02-20 14:17 ` Jan Blunck
  2017-02-21 12:25   ` Ferruh Yigit
  2017-02-20 14:17 ` [PATCH v2 8/8] eal: make virtual bus use rte_vdev_device Jan Blunck
  16 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-20 14:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This adds the rte_vdev_device_name() helper function to retrieve the
rte_vdev_device name which makes moving the name of the low-level
device into struct rte_device easier in the future.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map | 6 ++++++
 lib/librte_eal/common/eal_common_vdev.c       | 6 ++++++
 lib/librte_eal/common/include/rte_vdev.h      | 2 ++
 3 files changed, 14 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 0116085..4afa1c5 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -184,3 +184,9 @@ DPDK_17.02 {
 	rte_bus_unregister;
 
 } DPDK_16.11;
+
+DPDK_17.05 {
+	global:
+
+	rte_vdev_device_name;
+} DPDK_17.02;
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 61677de..a9798d0 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -66,6 +66,12 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 	TAILQ_REMOVE(&vdev_driver_list, driver, next);
 }
 
+const char *
+rte_vdev_device_name(const struct rte_vdev_device *dev)
+{
+	return dev->device.devargs->virt.drv_name;
+}
+
 static int
 vdev_probe_all_drivers(const char *name, const char *args)
 {
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 8f98372..ffa48bd 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -45,6 +45,8 @@ struct rte_vdev_device {
 	struct rte_device device;               /**< Inherit core device */
 };
 
+const char *rte_vdev_device_name(const struct rte_vdev_device *dev);
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v2 8/8] eal: make virtual bus use rte_vdev_device
  2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
                   ` (15 preceding siblings ...)
  2017-02-20 14:17 ` [PATCH v2 7/8] eal: add virtual device name helper function Jan Blunck
@ 2017-02-20 14:17 ` Jan Blunck
  16 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-20 14:17 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This allows the virtual bus to be rescanned and probed by tracking the
creation of rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 195 +++++++++++++++++++++++++-------
 1 file changed, 155 insertions(+), 40 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index a9798d0..531c61b 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -41,6 +41,7 @@
 #include <rte_vdev.h>
 #include <rte_common.h>
 #include <rte_devargs.h>
+#include <rte_memory.h>
 
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_device_list, rte_vdev_device);
@@ -73,9 +74,12 @@ rte_vdev_device_name(const struct rte_vdev_device *dev)
 }
 
 static int
-vdev_probe_all_drivers(const char *name, const char *args)
+vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
+	char *args = dev->device.devargs->args;
 	struct rte_vdev_driver *driver;
+	int ret;
 
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
@@ -85,90 +89,202 @@ vdev_probe_all_drivers(const char *name, const char *args)
 		 * So use strncmp to compare.
 		 */
 		if (!strncmp(driver->driver.name, name,
-			    strlen(driver->driver.name)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.name))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	/* Give new names precedence over aliases. */
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		if (driver->driver.alias &&
 		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.alias))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	return 1;
 }
 
+static struct rte_vdev_device *
+find_vdev(const char *name)
+{
+	struct rte_vdev_device *dev;
+
+	if (!name)
+		return NULL;
+
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
+		const char *devname = rte_vdev_device_name(dev);
+		if (!strncmp(devname, name, strlen(name)))
+			return dev;
+	}
+
+	return NULL;
+}
+
+static struct rte_devargs *
+alloc_devargs(const char *name, const char *args)
+{
+	struct rte_devargs *devargs;
+	int ret;
+
+	devargs = calloc(1, sizeof(*devargs));
+	if (!devargs)
+		return NULL;
+
+	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	if (args)
+		devargs->args = strdup(args);
+
+	ret = snprintf(devargs->virt.drv_name,
+			       sizeof(devargs->virt.drv_name), "%s", name);
+	if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name)) {
+		free(devargs->args);
+		free(devargs);
+		return NULL;
+	}
+
+	return devargs;
+}
+
 int
 rte_eal_vdev_init(const char *name, const char *args)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_probe_all_drivers(name, args);
-	if (ret  > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (dev)
+		return -EEXIST;
+
+	devargs = alloc_devargs(name, args);
+	if (!devargs)
+		return -ENOMEM;
+
+	dev = calloc(1, sizeof(*dev));
+	if (!dev) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+
+	dev->device.devargs = devargs;
+	dev->device.numa_node = SOCKET_ID_ANY;
+
+	ret = vdev_probe_all_drivers(dev);
+	if (ret) {
+		if (ret > 0)
+			RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+		goto fail;
+	}
+
+	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
+
+	rte_eal_device_insert(&dev->device);
+	TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	return 0;
 
+fail:
+	free(devargs->args);
+	free(devargs);
+	free(dev);
 	return ret;
 }
 
 static int
-vdev_remove_driver(const char *name)
+vdev_remove_driver(struct rte_vdev_device *dev)
 {
-	struct rte_vdev_driver *driver;
+	const char *name = rte_vdev_device_name(dev);
+	const struct rte_vdev_driver *driver;
 
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		/*
-		 * search a driver prefix in virtual device name.
-		 * For example, if the driver is pcap PMD, driver->name
-		 * will be "net_pcap", but "name" will be "net_pcapN".
-		 * So use strncmp to compare.
-		 */
-		if (!strncmp(driver->driver.name, name,
-			     strlen(driver->driver.name)))
-			return driver->remove(name);
-	}
-
-	/* Give new names precedence over aliases. */
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		if (driver->driver.alias &&
-		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->remove(name);
+	if (!dev->device.driver) {
+		RTE_LOG(DEBUG, EAL, "no driver attach to device %s\n", name);
+		return 1;
 	}
 
-	return 1;
+	driver = container_of(dev->device.driver, const struct rte_vdev_driver,
+		driver);
+	return driver->remove(name);
 }
 
 int
 rte_eal_vdev_uninit(const char *name)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_remove_driver(name);
-	if (ret > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (!dev)
+		return -ENOENT;
 
-	return ret;
+	devargs = dev->device.devargs;
+
+	ret = vdev_remove_driver(dev);
+	if (ret)
+		return ret;
+
+	TAILQ_REMOVE(&vdev_device_list, dev, next);
+	rte_eal_device_remove(&dev->device);
+
+	TAILQ_REMOVE(&devargs_list, devargs, next);
+
+	free(devargs->args);
+	free(devargs);
+	free(dev);
+	return 0;
 }
 
 static int
 vdev_scan(void)
 {
-	/* for virtual devices we don't need to scan anything */
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
+
+	/* for virtual devices we scan the devargs_list populated via cmdline */
+
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		dev = find_vdev(devargs->virt.drv_name);
+		if (dev)
+			continue;
+
+		dev = calloc(1, sizeof(*dev));
+		if (!dev)
+			return -1;
+
+		dev->device.devargs = devargs;
+		dev->device.numa_node = SOCKET_ID_ANY;
+
+		rte_eal_device_insert(&dev->device);
+		TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	}
+
 	return 0;
 }
 
 static int
 vdev_probe(void)
 {
-	struct rte_devargs *devargs;
+	struct rte_vdev_device *dev;
 
 	/*
 	 * Note that the dev_driver_list is populated here
@@ -177,15 +293,14 @@ vdev_probe(void)
 	 */
 
 	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (dev->device.driver)
 			continue;
 
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-				      devargs->args)) {
+		if (vdev_probe_all_drivers(dev)) {
 			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-				devargs->virt.drv_name);
+				rte_vdev_device_name(dev));
 			return -1;
 		}
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* Re: [PATCH v2 0/8] Rework vdev probing to use rte_bus infrastructure
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
@ 2017-02-21  6:44   ` Shreyansh Jain
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                     ` (10 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-21  6:44 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: david.marchand, ferruh.yigit

On Monday 20 February 2017 07:47 PM, Jan Blunck wrote:
> With the rte_bus infrastructure present in 17.02 it is possible to refactor
> the virtual device probing into a bus. This series also introduces the
> rte_vdev_device to better keep track of devices.
>
> This patchset depends on:
> http://dpdk.org/dev/patchwork/patch/20416/
> http://dpdk.org/dev/patchwork/patch/20417/
>
> Changes since version 1:
>  * addition of rte_vdev_device_name() helper
>  * removed rte_eal_dev_init() from *.map files
>  * use SOCKET_ID_ANY
>

Series Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v2 7/8] eal: add virtual device name helper function
  2017-02-20 14:17 ` [PATCH v2 7/8] eal: add virtual device name helper function Jan Blunck
@ 2017-02-21 12:25   ` Ferruh Yigit
  0 siblings, 0 replies; 91+ messages in thread
From: Ferruh Yigit @ 2017-02-21 12:25 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: david.marchand, shreyansh.jain

On 2/20/2017 2:17 PM, Jan Blunck wrote:
> This adds the rte_vdev_device_name() helper function to retrieve the
> rte_vdev_device name which makes moving the name of the low-level
> device into struct rte_device easier in the future.
> 
> Signed-off-by: Jan Blunck <jblunck@infradead.org>

<...>

> +const char *
> +rte_vdev_device_name(const struct rte_vdev_device *dev)
> +{
> +	return dev->device.devargs->virt.drv_name;
> +}

Can this function be static?

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v2 1/8] eal: use different constructor priorities for initcalls
  2017-02-20 14:17 ` [PATCH v2 1/8] eal: use different constructor priorities for initcalls Jan Blunck
@ 2017-02-21 12:30   ` Ferruh Yigit
  0 siblings, 0 replies; 91+ messages in thread
From: Ferruh Yigit @ 2017-02-21 12:30 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: david.marchand, shreyansh.jain

On 2/20/2017 2:17 PM, Jan Blunck wrote:
> This introduces different initcall macros to allow for late registration of
> the virtual device bus.
> 
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>

<...>

>  
> -#define RTE_INIT(func) \
> -static void __attribute__((constructor, used)) func(void)
> +#define RTE_EAL_INIT(func) \
> +static void __attribute__((constructor(101), used)) func(void)
> +
> +#define RTE_POST_EAL_INIT(func) \
> +static void __attribute__((constructor(102), used)) func(void)
> +
> +#define RTE_DEV_INIT(func) \
> +static void __attribute__((constructor(103), used)) func(void)
> +
> +#define RTE_INIT(func) RTE_DEV_INIT(func)

Does it make sense to give some gaps among priorities,
101, 102, 103 --> 100, 200 , 300

When new priorities added (not sure if that ever will happen), is
changing previous priorities cause a ABI breakage?

^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH v3 00/10] Rework vdev probing to use rte_bus infrastructure
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
  2017-02-21  6:44   ` Shreyansh Jain
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-27 13:09     ` Jan Blunck
                       ` (11 more replies)
  2017-02-25 10:28   ` [PATCH v3 01/10] eal: probe legacy PCI devices before other bus devices Jan Blunck
                     ` (9 subsequent siblings)
  11 siblings, 12 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

With the rte_bus infrastructure present in 17.02 it is possible to refactor
the virtual device probing into a bus. This series also introduces the
rte_vdev_device to better keep track of devices.

This patchset depends on:
http://dpdk.org/dev/patchwork/patch/20416/
http://dpdk.org/dev/patchwork/patch/20417/

Changes since version 2:
 * implicit bus registration through rte_eal_vdrv_register()
 * explicit delay probing of virtual bus in rte_bus_probe()
 * addition of rte_vdev_device_args() helper
 * make virtual driver probe and remove take rte_vdev_device

Changes since version 1:
 * addition of rte_vdev_device_name() helper
 * removed rte_eal_dev_init() from *.map files
 * use SOCKET_ID_ANY

Jan Blunck (10):
  eal: probe legacy PCI devices before other bus devices
  eal: probe new virtual bus after other bus devices
  eal: move virtual device probing into a bus
  eal: remove unused rte_eal_dev_init()
  eal: Refactor vdev driver probe/remove
  eal: add struct rte_vdev_device
  eal: add virtual device name helper function
  eal: add virtual device arguments helper function
  eal: make virtual bus use rte_vdev_device
  eal: make virtual driver probe and remove take rte_vdev_device

 drivers/crypto/null/null_crypto_pmd.c           |  18 +-
 drivers/net/af_packet/rte_eth_af_packet.c       |  11 +-
 drivers/net/bonding/rte_eth_bond_pmd.c          |  13 +-
 drivers/net/mpipe/mpipe_tilegx.c                |  10 +-
 drivers/net/null/rte_eth_null.c                 |  13 +-
 drivers/net/pcap/rte_eth_pcap.c                 |  12 +-
 drivers/net/ring/rte_eth_ring.c                 |   9 +-
 drivers/net/tap/rte_eth_tap.c                   |  10 +-
 drivers/net/vhost/rte_eth_vhost.c               |  10 +-
 drivers/net/virtio/virtio_user_ethdev.c         |  18 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c           |   9 +-
 lib/librte_eal/bsdapp/eal/eal.c                 |   9 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 -
 lib/librte_eal/common/eal_common_bus.c          |  16 +-
 lib/librte_eal/common/eal_common_dev.c          |  28 ---
 lib/librte_eal/common/eal_common_vdev.c         | 259 +++++++++++++++++++++---
 lib/librte_eal/common/include/rte_dev.h         |   5 -
 lib/librte_eal/common/include/rte_vdev.h        |  26 ++-
 lib/librte_eal/linuxapp/eal/eal.c               |   9 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 -
 20 files changed, 355 insertions(+), 132 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH v3 01/10] eal: probe legacy PCI devices before other bus devices
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
  2017-02-21  6:44   ` Shreyansh Jain
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-25 10:28   ` [PATCH v3 02/10] eal: probe new virtual bus after " Jan Blunck
                     ` (8 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

Make sure that the PCI devices are probed before the virtual devices after
the legacy virtual device probing has been moved to a bus.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal.c   | 8 ++++----
 lib/librte_eal/linuxapp/eal/eal.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index ee7c9de..a584447 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -613,14 +613,14 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe all the buses and devices/drivers on them */
-	if (rte_bus_probe())
-		rte_panic("Cannot probe devices\n");
-
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	/* Probe all the buses and devices/drivers on them */
+	if (rte_bus_probe())
+		rte_panic("Cannot probe devices\n");
+
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index bf6b818..f77ff5c 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -884,14 +884,14 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe all the buses and devices/drivers on them */
-	if (rte_bus_probe())
-		rte_panic("Cannot probe devices\n");
-
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	/* Probe all the buses and devices/drivers on them */
+	if (rte_bus_probe())
+		rte_panic("Cannot probe devices\n");
+
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v3 02/10] eal: probe new virtual bus after other bus devices
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                     ` (2 preceding siblings ...)
  2017-02-25 10:28   ` [PATCH v3 01/10] eal: probe legacy PCI devices before other bus devices Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-27  8:59     ` Shreyansh Jain
  2017-02-25 10:28   ` [PATCH v3 03/10] eal: move virtual device probing into a bus Jan Blunck
                     ` (7 subsequent siblings)
  11 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

Also see commit f4ce209a ("eal: postpone vdev initialization").

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/eal_common_bus.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 4638e78..8f9baf8 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -86,9 +86,14 @@ int
 rte_bus_probe(void)
 {
 	int ret;
-	struct rte_bus *bus;
+	struct rte_bus *bus, *vbus = NULL;
 
 	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		if (!strcmp(bus->name, "virtual")) {
+			vbus = bus;
+			continue;
+		}
+
 		ret = bus->probe();
 		if (ret) {
 			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
@@ -97,6 +102,15 @@ rte_bus_probe(void)
 		}
 	}
 
+	if (vbus) {
+		ret = vbus->probe();
+		if (ret) {
+			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
+				vbus->name);
+			return ret;
+		}
+	}
+
 	return 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v3 03/10] eal: move virtual device probing into a bus
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                     ` (3 preceding siblings ...)
  2017-02-25 10:28   ` [PATCH v3 02/10] eal: probe new virtual bus after " Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-25 10:28   ` [PATCH v3 04/10] eal: remove unused rte_eal_dev_init() Jan Blunck
                     ` (6 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This is a refactoring of the virtual device probing which moves into into
a proper bus structure.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_dev.c  | 22 -------------
 lib/librte_eal/common/eal_common_vdev.c | 58 +++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4f3b493..1ce90f6 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -79,28 +79,6 @@ void rte_eal_device_remove(struct rte_device *dev)
 int
 rte_eal_dev_init(void)
 {
-	struct rte_devargs *devargs;
-
-	/*
-	 * Note that the dev_driver_list is populated here
-	 * from calls made to rte_eal_driver_register from constructor functions
-	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
-	 */
-
-	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
-
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
-			continue;
-
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-					devargs->args)) {
-			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-					devargs->virt.drv_name);
-			return -1;
-		}
-	}
-
 	return 0;
 }
 
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 7d6e54f..0fcfdd7 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -37,16 +37,22 @@
 #include <stdint.h>
 #include <sys/queue.h>
 
+#include <rte_bus.h>
 #include <rte_vdev.h>
 #include <rte_common.h>
+#include <rte_devargs.h>
 
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
 
+static void rte_vdev_bus_register(void);
+
 /* register a driver */
 void
 rte_eal_vdrv_register(struct rte_vdev_driver *driver)
 {
+	rte_vdev_bus_register();
+
 	TAILQ_INSERT_TAIL(&vdev_driver_list, driver, next);
 	rte_eal_driver_register(&driver->driver);
 }
@@ -122,3 +128,55 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+static int
+vdev_scan(void)
+{
+	/* for virtual devices we don't need to scan anything */
+	return 0;
+}
+
+static int
+vdev_probe(void)
+{
+	struct rte_devargs *devargs;
+
+	/*
+	 * Note that the dev_driver_list is populated here
+	 * from calls made to rte_eal_driver_register from constructor functions
+	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
+	 */
+
+	/* call the init function for each virtual device */
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		if (rte_eal_vdev_init(devargs->virt.drv_name,
+				      devargs->args)) {
+			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
+				devargs->virt.drv_name);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+static struct rte_bus rte_vdev_bus = {
+	.scan = vdev_scan,
+	.probe = vdev_probe,
+};
+
+static void rte_vdev_bus_register(void)
+{
+	static int registered = 0;
+
+	if (registered)
+		return;
+
+	registered = 1;
+	rte_vdev_bus.name = RTE_STR(virtual);
+	rte_bus_register(&rte_vdev_bus);
+}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v3 04/10] eal: remove unused rte_eal_dev_init()
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                     ` (4 preceding siblings ...)
  2017-02-25 10:28   ` [PATCH v3 03/10] eal: move virtual device probing into a bus Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-25 10:28   ` [PATCH v3 05/10] eal: Refactor vdev driver probe/remove Jan Blunck
                     ` (5 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal.c                 | 3 ---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   | 1 -
 lib/librte_eal/common/eal_common_dev.c          | 6 ------
 lib/librte_eal/common/include/rte_dev.h         | 5 -----
 lib/librte_eal/linuxapp/eal/eal.c               | 3 ---
 lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 -
 6 files changed, 19 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index a584447..3d29fcb 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -621,9 +621,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	if (rte_eal_dev_init() < 0)
-		rte_panic("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 67f2ffb..b1996e0 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -22,7 +22,6 @@ DPDK_2.0 {
 	rte_dump_tailq;
 	rte_eal_alarm_cancel;
 	rte_eal_alarm_set;
-	rte_eal_dev_init;
 	rte_eal_devargs_add;
 	rte_eal_devargs_dump;
 	rte_eal_devargs_type_count;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 1ce90f6..4bde430 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -76,12 +76,6 @@ void rte_eal_device_remove(struct rte_device *dev)
 	TAILQ_REMOVE(&dev_device_list, dev, next);
 }
 
-int
-rte_eal_dev_init(void)
-{
-	return 0;
-}
-
 int rte_eal_dev_attach(const char *name, const char *devargs)
 {
 	struct rte_pci_addr addr;
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index b17791f..4251099 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -171,11 +171,6 @@ void rte_eal_driver_register(struct rte_driver *driver);
 void rte_eal_driver_unregister(struct rte_driver *driver);
 
 /**
- * Initalize all the registered drivers in this process
- */
-int rte_eal_dev_init(void);
-
-/**
  * Initialize a driver specified by name.
  *
  * @param name
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index f77ff5c..88479de 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -892,9 +892,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	if (rte_eal_dev_init() < 0)
-		rte_panic("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 9c134b4..2ada2f0 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -22,7 +22,6 @@ DPDK_2.0 {
 	rte_dump_tailq;
 	rte_eal_alarm_cancel;
 	rte_eal_alarm_set;
-	rte_eal_dev_init;
 	rte_eal_devargs_add;
 	rte_eal_devargs_dump;
 	rte_eal_devargs_type_count;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v3 05/10] eal: Refactor vdev driver probe/remove
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                     ` (5 preceding siblings ...)
  2017-02-25 10:28   ` [PATCH v3 04/10] eal: remove unused rte_eal_dev_init() Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-25 10:28   ` [PATCH v3 06/10] eal: add struct rte_vdev_device Jan Blunck
                     ` (4 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This is a preparation for the introduction of the struct rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 44 ++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 0fcfdd7..5a267ee 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -65,14 +65,11 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 	TAILQ_REMOVE(&vdev_driver_list, driver, next);
 }
 
-int
-rte_eal_vdev_init(const char *name, const char *args)
+static int
+vdev_probe_all_drivers(const char *name, const char *args)
 {
 	struct rte_vdev_driver *driver;
 
-	if (name == NULL)
-		return -EINVAL;
-
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -93,18 +90,29 @@ rte_eal_vdev_init(const char *name, const char *args)
 			return driver->probe(name, args);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
 }
 
 int
-rte_eal_vdev_uninit(const char *name)
+rte_eal_vdev_init(const char *name, const char *args)
 {
-	struct rte_vdev_driver *driver;
+	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
+	ret = vdev_probe_all_drivers(name, args);
+	if (ret  > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
+}
+
+static int
+vdev_remove_driver(const char *name)
+{
+	struct rte_vdev_driver *driver;
+
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -125,8 +133,22 @@ rte_eal_vdev_uninit(const char *name)
 			return driver->remove(name);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
+}
+
+int
+rte_eal_vdev_uninit(const char *name)
+{
+	int ret;
+
+	if (name == NULL)
+		return -EINVAL;
+
+	ret = vdev_remove_driver(name);
+	if (ret > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
 }
 
 static int
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v3 06/10] eal: add struct rte_vdev_device
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                     ` (6 preceding siblings ...)
  2017-02-25 10:28   ` [PATCH v3 05/10] eal: Refactor vdev driver probe/remove Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-25 10:28   ` [PATCH v3 07/10] eal: add virtual device name helper function Jan Blunck
                     ` (3 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This adds the rte_vdev_device structure which embeds a generic rte_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_vdev.c  | 5 +++++
 lib/librte_eal/common/include/rte_vdev.h | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 5a267ee..c88cae9 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -42,6 +42,11 @@
 #include <rte_common.h>
 #include <rte_devargs.h>
 
+/** Double linked list of virtual device drivers. */
+TAILQ_HEAD(vdev_device_list, rte_vdev_device);
+
+static struct vdev_device_list vdev_device_list =
+	TAILQ_HEAD_INITIALIZER(vdev_device_list);
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
 
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 784e837..8f98372 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -40,6 +40,11 @@ extern "C" {
 #include <sys/queue.h>
 #include <rte_dev.h>
 
+struct rte_vdev_device {
+	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
+	struct rte_device device;               /**< Inherit core device */
+};
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v3 07/10] eal: add virtual device name helper function
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                     ` (7 preceding siblings ...)
  2017-02-25 10:28   ` [PATCH v3 06/10] eal: add struct rte_vdev_device Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-25 10:28   ` [PATCH v3 08/10] eal: add virtual device arguments " Jan Blunck
                     ` (2 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This adds the rte_vdev_device_name() helper function to retrieve the
rte_vdev_device name which makes moving the name of the low-level
device into struct rte_device easier in the future.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/include/rte_vdev.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 8f98372..abdefab 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -39,12 +39,21 @@ extern "C" {
 
 #include <sys/queue.h>
 #include <rte_dev.h>
+#include <rte_devargs.h>
 
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
 };
 
+static inline const char *
+rte_vdev_device_name(const struct rte_vdev_device *dev)
+{
+	if (dev && dev->device.devargs)
+		return dev->device.devargs->virt.drv_name;
+	return NULL;
+}
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v3 08/10] eal: add virtual device arguments helper function
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                     ` (8 preceding siblings ...)
  2017-02-25 10:28   ` [PATCH v3 07/10] eal: add virtual device name helper function Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-25 10:28   ` [PATCH v3 09/10] eal: make virtual bus use rte_vdev_device Jan Blunck
  2017-02-25 10:28   ` [PATCH v3 10/10] eal: make virtual driver probe and remove take rte_vdev_device Jan Blunck
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This adds the rte_vdev_device_args() helper function to prepare for
changing the virtual drivers probe() functions take a rte_vdev_device
pointer instead of the name+args strings.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_vdev.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index abdefab..81f6beb 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -54,6 +54,14 @@ rte_vdev_device_name(const struct rte_vdev_device *dev)
 	return NULL;
 }
 
+static inline const char *
+rte_vdev_device_args(const struct rte_vdev_device *dev)
+{
+	if (dev && dev->device.devargs)
+		return dev->device.devargs->args;
+	return "";
+}
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v3 09/10] eal: make virtual bus use rte_vdev_device
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                     ` (9 preceding siblings ...)
  2017-02-25 10:28   ` [PATCH v3 08/10] eal: add virtual device arguments " Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  2017-02-25 10:28   ` [PATCH v3 10/10] eal: make virtual driver probe and remove take rte_vdev_device Jan Blunck
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This allows the virtual bus to be rescanned and probed by tracking the
creation of rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 195 +++++++++++++++++++++++++-------
 1 file changed, 155 insertions(+), 40 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index c88cae9..7215b50 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -41,6 +41,7 @@
 #include <rte_vdev.h>
 #include <rte_common.h>
 #include <rte_devargs.h>
+#include <rte_memory.h>
 
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_device_list, rte_vdev_device);
@@ -71,9 +72,12 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 }
 
 static int
-vdev_probe_all_drivers(const char *name, const char *args)
+vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
+	const char *args = rte_vdev_device_args(dev);
 	struct rte_vdev_driver *driver;
+	int ret;
 
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
@@ -83,90 +87,202 @@ vdev_probe_all_drivers(const char *name, const char *args)
 		 * So use strncmp to compare.
 		 */
 		if (!strncmp(driver->driver.name, name,
-			    strlen(driver->driver.name)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.name))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	/* Give new names precedence over aliases. */
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		if (driver->driver.alias &&
 		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.alias))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	return 1;
 }
 
+static struct rte_vdev_device *
+find_vdev(const char *name)
+{
+	struct rte_vdev_device *dev;
+
+	if (!name)
+		return NULL;
+
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
+		const char *devname = rte_vdev_device_name(dev);
+		if (!strncmp(devname, name, strlen(name)))
+			return dev;
+	}
+
+	return NULL;
+}
+
+static struct rte_devargs *
+alloc_devargs(const char *name, const char *args)
+{
+	struct rte_devargs *devargs;
+	int ret;
+
+	devargs = calloc(1, sizeof(*devargs));
+	if (!devargs)
+		return NULL;
+
+	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	if (args)
+		devargs->args = strdup(args);
+
+	ret = snprintf(devargs->virt.drv_name,
+			       sizeof(devargs->virt.drv_name), "%s", name);
+	if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name)) {
+		free(devargs->args);
+		free(devargs);
+		return NULL;
+	}
+
+	return devargs;
+}
+
 int
 rte_eal_vdev_init(const char *name, const char *args)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_probe_all_drivers(name, args);
-	if (ret  > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (dev)
+		return -EEXIST;
+
+	devargs = alloc_devargs(name, args);
+	if (!devargs)
+		return -ENOMEM;
+
+	dev = calloc(1, sizeof(*dev));
+	if (!dev) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+
+	dev->device.devargs = devargs;
+	dev->device.numa_node = SOCKET_ID_ANY;
+
+	ret = vdev_probe_all_drivers(dev);
+	if (ret) {
+		if (ret > 0)
+			RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+		goto fail;
+	}
+
+	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
+
+	rte_eal_device_insert(&dev->device);
+	TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	return 0;
 
+fail:
+	free(devargs->args);
+	free(devargs);
+	free(dev);
 	return ret;
 }
 
 static int
-vdev_remove_driver(const char *name)
+vdev_remove_driver(struct rte_vdev_device *dev)
 {
-	struct rte_vdev_driver *driver;
+	const char *name = rte_vdev_device_name(dev);
+	const struct rte_vdev_driver *driver;
 
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		/*
-		 * search a driver prefix in virtual device name.
-		 * For example, if the driver is pcap PMD, driver->name
-		 * will be "net_pcap", but "name" will be "net_pcapN".
-		 * So use strncmp to compare.
-		 */
-		if (!strncmp(driver->driver.name, name,
-			     strlen(driver->driver.name)))
-			return driver->remove(name);
-	}
-
-	/* Give new names precedence over aliases. */
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		if (driver->driver.alias &&
-		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->remove(name);
+	if (!dev->device.driver) {
+		RTE_LOG(DEBUG, EAL, "no driver attach to device %s\n", name);
+		return 1;
 	}
 
-	return 1;
+	driver = container_of(dev->device.driver, const struct rte_vdev_driver,
+		driver);
+	return driver->remove(name);
 }
 
 int
 rte_eal_vdev_uninit(const char *name)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_remove_driver(name);
-	if (ret > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (!dev)
+		return -ENOENT;
 
-	return ret;
+	devargs = dev->device.devargs;
+
+	ret = vdev_remove_driver(dev);
+	if (ret)
+		return ret;
+
+	TAILQ_REMOVE(&vdev_device_list, dev, next);
+	rte_eal_device_remove(&dev->device);
+
+	TAILQ_REMOVE(&devargs_list, devargs, next);
+
+	free(devargs->args);
+	free(devargs);
+	free(dev);
+	return 0;
 }
 
 static int
 vdev_scan(void)
 {
-	/* for virtual devices we don't need to scan anything */
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
+
+	/* for virtual devices we scan the devargs_list populated via cmdline */
+
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		dev = find_vdev(devargs->virt.drv_name);
+		if (dev)
+			continue;
+
+		dev = calloc(1, sizeof(*dev));
+		if (!dev)
+			return -1;
+
+		dev->device.devargs = devargs;
+		dev->device.numa_node = SOCKET_ID_ANY;
+
+		rte_eal_device_insert(&dev->device);
+		TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	}
+
 	return 0;
 }
 
 static int
 vdev_probe(void)
 {
-	struct rte_devargs *devargs;
+	struct rte_vdev_device *dev;
 
 	/*
 	 * Note that the dev_driver_list is populated here
@@ -175,15 +291,14 @@ vdev_probe(void)
 	 */
 
 	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (dev->device.driver)
 			continue;
 
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-				      devargs->args)) {
+		if (vdev_probe_all_drivers(dev)) {
 			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-				devargs->virt.drv_name);
+				rte_vdev_device_name(dev));
 			return -1;
 		}
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v3 10/10] eal: make virtual driver probe and remove take rte_vdev_device
  2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
                     ` (10 preceding siblings ...)
  2017-02-25 10:28   ` [PATCH v3 09/10] eal: make virtual bus use rte_vdev_device Jan Blunck
@ 2017-02-25 10:28   ` Jan Blunck
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-25 10:28 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This is a preparation to embed the generic rte_device into the rte_eth_dev
also for virtual devices.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/crypto/null/null_crypto_pmd.c     | 18 ++++++++++++------
 drivers/net/af_packet/rte_eth_af_packet.c | 11 ++++++-----
 drivers/net/bonding/rte_eth_bond_pmd.c    | 13 +++++++++----
 drivers/net/mpipe/mpipe_tilegx.c          | 10 ++++++----
 drivers/net/null/rte_eth_null.c           | 13 ++++++++-----
 drivers/net/pcap/rte_eth_pcap.c           | 12 +++++++-----
 drivers/net/ring/rte_eth_ring.c           |  9 +++++++--
 drivers/net/tap/rte_eth_tap.c             | 10 +++++++---
 drivers/net/vhost/rte_eth_vhost.c         | 10 +++++++---
 drivers/net/virtio/virtio_user_ethdev.c   | 18 +++++++-----------
 drivers/net/xenvirt/rte_eth_xenvirt.c     |  9 +++++----
 lib/librte_eal/common/eal_common_vdev.c   |  7 +++----
 lib/librte_eal/common/include/rte_vdev.h  |  4 ++--
 13 files changed, 86 insertions(+), 58 deletions(-)

diff --git a/drivers/crypto/null/null_crypto_pmd.c b/drivers/crypto/null/null_crypto_pmd.c
index ed5a9fc..51d6de0 100644
--- a/drivers/crypto/null/null_crypto_pmd.c
+++ b/drivers/crypto/null/null_crypto_pmd.c
@@ -218,8 +218,7 @@ cryptodev_null_create(struct rte_crypto_vdev_init_params *init_params)
 
 /** Initialise null crypto device */
 static int
-cryptodev_null_probe(const char *name,
-		const char *input_args)
+cryptodev_null_probe(struct rte_vdev_device *dev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -228,10 +227,11 @@ cryptodev_null_probe(const char *name,
 		{0}
 	};
 
-	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
+	rte_cryptodev_parse_vdev_init_params(&init_params,
+		rte_vdev_device_args(dev));
 
-	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
-			init_params.socket_id);
+	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n",
+		rte_vdev_device_name(dev), init_params.socket_id);
 	if (init_params.name[0] != '\0')
 		RTE_LOG(INFO, PMD, "  User defined name = %s\n",
 			init_params.name);
@@ -256,9 +256,15 @@ cryptodev_null_remove(const char *name)
 	return 0;
 }
 
+static int
+cryptodev_null_remove_dev(struct rte_vdev_device *dev)
+{
+	return cryptodev_null_remove(rte_vdev_device_name(dev));
+}
+
 static struct rte_vdev_driver cryptodev_null_pmd_drv = {
 	.probe = cryptodev_null_probe,
-	.remove = cryptodev_null_remove
+	.remove = cryptodev_null_remove_dev,
 };
 
 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_NULL_PMD, cryptodev_null_pmd_drv);
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 2f87553..77536e8 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -923,8 +923,9 @@ rte_eth_from_packet(const char *name,
 }
 
 static int
-rte_pmd_af_packet_probe(const char *name, const char *params)
+rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
 	unsigned numa_node;
 	int ret = 0;
 	struct rte_kvargs *kvlist;
@@ -934,7 +935,7 @@ rte_pmd_af_packet_probe(const char *name, const char *params)
 
 	numa_node = rte_socket_id();
 
-	kvlist = rte_kvargs_parse(params, valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
 	if (kvlist == NULL) {
 		ret = -1;
 		goto exit;
@@ -961,7 +962,7 @@ rte_pmd_af_packet_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_af_packet_remove(const char *name)
+rte_pmd_af_packet_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 	struct pmd_internals *internals;
@@ -970,11 +971,11 @@ rte_pmd_af_packet_remove(const char *name)
 	RTE_LOG(INFO, PMD, "Closing AF_PACKET ethdev on numa socket %u\n",
 			rte_socket_id());
 
-	if (name == NULL)
+	if (dev == NULL)
 		return -1;
 
 	/* find the ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (eth_dev == NULL)
 		return -1;
 
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index f3ac9e2..6c03920 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -2230,16 +2230,19 @@ const struct eth_dev_ops default_dev_ops = {
 };
 
 static int
-bond_probe(const char *name, const char *params)
+bond_probe(struct rte_vdev_device *dev)
 {
+	const char *name;
 	struct bond_dev_private *internals;
 	struct rte_kvargs *kvlist;
 	uint8_t bonding_mode, socket_id;
 	int  arg_count, port_id;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, EAL, "Initializing pmd_bond for %s\n", name);
 
-	kvlist = rte_kvargs_parse(params, pmd_bond_init_valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev),
+		pmd_bond_init_valid_arguments);
 	if (kvlist == NULL)
 		return -1;
 
@@ -2297,13 +2300,15 @@ bond_probe(const char *name, const char *params)
 }
 
 static int
-bond_remove(const char *name)
+bond_remove(struct rte_vdev_device *dev)
 {
+	const char *name;
 	int  ret;
 
-	if (name == NULL)
+	if (!dev)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, EAL, "Uninitializing pmd_bond for %s\n", name);
 
 	/* free link bonding eth device */
diff --git a/drivers/net/mpipe/mpipe_tilegx.c b/drivers/net/mpipe/mpipe_tilegx.c
index 7bbd168..572c0a5 100644
--- a/drivers/net/mpipe/mpipe_tilegx.c
+++ b/drivers/net/mpipe/mpipe_tilegx.c
@@ -1622,15 +1622,17 @@ rte_pmd_mpipe_probe_common(struct rte_vdev_driver *drv, const char *ifname,
 }
 
 static int
-rte_pmd_mpipe_xgbe_probe(const char *ifname, const char *params __rte_unused)
+rte_pmd_mpipe_xgbe_probe(struct rte_vdev_device *dev)
 {
-	return rte_pmd_mpipe_probe_common(&pmd_mpipe_xgbe_drv, ifname, params);
+	return rte_pmd_mpipe_probe_common(&pmd_mpipe_xgbe_drv,
+		rte_vdev_device_name(dev), rte_vdev_device_args(dev));
 }
 
 static int
-rte_pmd_mpipe_gbe_probe(const char *ifname, const char *params __rte_unused)
+rte_pmd_mpipe_gbe_probe(struct rte_vdev_device *dev)
 {
-	return rte_pmd_mpipe_probe_common(&pmd_mpipe_gbe_drv, ifname, params);
+	return rte_pmd_mpipe_probe_common(&pmd_mpipe_gbe_drv,
+		rte_vdev_device_name(dev), rte_vdev_device_args(dev));
 }
 
 static struct rte_vdev_driver pmd_mpipe_xgbe_drv = {
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index 57203e2..f4242b0 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -608,17 +608,20 @@ get_packet_copy_arg(const char *key __rte_unused,
 }
 
 static int
-rte_pmd_null_probe(const char *name, const char *params)
+rte_pmd_null_probe(struct rte_vdev_device *dev)
 {
+	const char *name, *params;
 	unsigned numa_node;
 	unsigned packet_size = default_packet_size;
 	unsigned packet_copy = default_packet_copy;
 	struct rte_kvargs *kvlist = NULL;
 	int ret;
 
-	if (name == NULL)
+	if (!dev)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(dev);
+	params = rte_vdev_device_args(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_null for %s\n", name);
 
 	numa_node = rte_socket_id();
@@ -660,18 +663,18 @@ rte_pmd_null_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_null_remove(const char *name)
+rte_pmd_null_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 
-	if (name == NULL)
+	if (!dev)
 		return -EINVAL;
 
 	RTE_LOG(INFO, PMD, "Closing null ethdev on numa socket %u\n",
 			rte_socket_id());
 
 	/* find the ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (eth_dev == NULL)
 		return -1;
 
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 7f0b650..ab9cde1 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -936,8 +936,9 @@ eth_from_pcaps(const char *name, struct pmd_devargs *rx_queues,
 }
 
 static int
-pmd_pcap_probe(const char *name, const char *params)
+pmd_pcap_probe(struct rte_vdev_device *dev)
 {
+	const char *name;
 	unsigned int is_rx_pcap = 0, is_tx_pcap = 0;
 	struct rte_kvargs *kvlist;
 	struct pmd_devargs pcaps = {0};
@@ -945,13 +946,14 @@ pmd_pcap_probe(const char *name, const char *params)
 	int single_iface = 0;
 	int ret;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_pcap for %s\n", name);
 
 	gettimeofday(&start_time, NULL);
 	start_cycles = rte_get_timer_cycles();
 	hz = rte_get_timer_hz();
 
-	kvlist = rte_kvargs_parse(params, valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
 	if (kvlist == NULL)
 		return -1;
 
@@ -1035,18 +1037,18 @@ pmd_pcap_probe(const char *name, const char *params)
 }
 
 static int
-pmd_pcap_remove(const char *name)
+pmd_pcap_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 
 	RTE_LOG(INFO, PMD, "Closing pcap ethdev on numa socket %u\n",
 			rte_socket_id());
 
-	if (name == NULL)
+	if (!dev)
 		return -1;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (eth_dev == NULL)
 		return -1;
 
diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c
index 6f9cc1a..62606e7 100644
--- a/drivers/net/ring/rte_eth_ring.c
+++ b/drivers/net/ring/rte_eth_ring.c
@@ -502,12 +502,16 @@ static int parse_kvlist (const char *key __rte_unused, const char *value, void *
 }
 
 static int
-rte_pmd_ring_probe(const char *name, const char *params)
+rte_pmd_ring_probe(struct rte_vdev_device *dev)
 {
+	const char *name, *params;
 	struct rte_kvargs *kvlist = NULL;
 	int ret = 0;
 	struct node_action_list *info = NULL;
 
+	name = rte_vdev_device_name(dev);
+	params = rte_vdev_device_args(dev);
+
 	RTE_LOG(INFO, PMD, "Initializing pmd_ring for %s\n", name);
 
 	if (params == NULL || params[0] == '\0') {
@@ -577,8 +581,9 @@ rte_pmd_ring_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_ring_remove(const char *name)
+rte_pmd_ring_remove(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
 	struct rte_eth_dev *eth_dev = NULL;
 	struct pmd_internals *internals = NULL;
 	struct ring_queue *r = NULL;
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index efc4426..941150f 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -741,13 +741,17 @@ set_interface_speed(const char *key __rte_unused,
 /* Open a TAP interface device.
  */
 static int
-rte_pmd_tap_probe(const char *name, const char *params)
+rte_pmd_tap_probe(struct rte_vdev_device *dev)
 {
+	const char *name, *params;
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
 	int speed;
 	char tap_name[RTE_ETH_NAME_MAX_LEN];
 
+	name = rte_vdev_device_name(dev);
+	params = rte_vdev_device_args(dev);
+
 	speed = ETH_SPEED_NUM_10G;
 	snprintf(tap_name, sizeof(tap_name), "%s%d",
 		 DEFAULT_TAP_NAME, tap_unit++);
@@ -797,7 +801,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 /* detach a TAP device.
  */
 static int
-rte_pmd_tap_remove(const char *name)
+rte_pmd_tap_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 	struct pmd_internals *internals;
@@ -807,7 +811,7 @@ rte_pmd_tap_remove(const char *name)
 		rte_socket_id());
 
 	/* find the ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (!eth_dev)
 		return 0;
 
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index e98cffd..d0d0474 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -1156,8 +1156,9 @@ open_int(const char *key __rte_unused, const char *value, void *extra_args)
 }
 
 static int
-rte_pmd_vhost_probe(const char *name, const char *params)
+rte_pmd_vhost_probe(struct rte_vdev_device *dev)
 {
+	const char *name;
 	struct rte_kvargs *kvlist = NULL;
 	int ret = 0;
 	char *iface_name;
@@ -1166,9 +1167,10 @@ rte_pmd_vhost_probe(const char *name, const char *params)
 	int client_mode = 0;
 	int dequeue_zero_copy = 0;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_vhost for %s\n", name);
 
-	kvlist = rte_kvargs_parse(params, valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
 	if (kvlist == NULL)
 		return -1;
 
@@ -1219,11 +1221,13 @@ rte_pmd_vhost_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_vhost_remove(const char *name)
+rte_pmd_vhost_remove(struct rte_vdev_device *dev)
 {
+	const char *name;
 	struct rte_eth_dev *eth_dev = NULL;
 	unsigned int i;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, PMD, "Un-Initializing pmd_vhost for %s\n", name);
 
 	/* find an ethdev entry */
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 0b226ac..42ad8a2 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -338,7 +338,7 @@ virtio_user_eth_dev_free(struct rte_eth_dev *eth_dev)
  * Returns 0 on success.
  */
 static int
-virtio_user_pmd_probe(const char *name, const char *params)
+virtio_user_pmd_probe(struct rte_vdev_device *dev)
 {
 	struct rte_kvargs *kvlist = NULL;
 	struct rte_eth_dev *eth_dev;
@@ -350,13 +350,7 @@ virtio_user_pmd_probe(const char *name, const char *params)
 	char *mac_addr = NULL;
 	int ret = -1;
 
-	if (!params || params[0] == '\0') {
-		PMD_INIT_LOG(ERR, "arg %s is mandatory for virtio_user",
-			  VIRTIO_USER_ARG_QUEUE_SIZE);
-		goto end;
-	}
-
-	kvlist = rte_kvargs_parse(params, valid_args);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_args);
 	if (!kvlist) {
 		PMD_INIT_LOG(ERR, "error when parsing param");
 		goto end;
@@ -418,7 +412,7 @@ virtio_user_pmd_probe(const char *name, const char *params)
 		goto end;
 	}
 
-	eth_dev = virtio_user_eth_dev_alloc(name);
+	eth_dev = virtio_user_eth_dev_alloc(rte_vdev_device_name(dev));
 	if (!eth_dev) {
 		PMD_INIT_LOG(ERR, "virtio_user fails to alloc device");
 		goto end;
@@ -452,15 +446,17 @@ virtio_user_pmd_probe(const char *name, const char *params)
 
 /** Called by rte_eth_dev_detach() */
 static int
-virtio_user_pmd_remove(const char *name)
+virtio_user_pmd_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
 	struct rte_eth_dev *eth_dev;
 	struct virtio_hw *hw;
 	struct virtio_user_dev *dev;
 
-	if (!name)
+	if (!vdev)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(vdev);
 	PMD_DRV_LOG(INFO, "Un-Initializing %s", name);
 	eth_dev = rte_eth_dev_allocated(name);
 	if (!eth_dev)
diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c b/drivers/net/xenvirt/rte_eth_xenvirt.c
index 19bc09a..6ec8c08 100644
--- a/drivers/net/xenvirt/rte_eth_xenvirt.c
+++ b/drivers/net/xenvirt/rte_eth_xenvirt.c
@@ -726,7 +726,7 @@ eth_dev_xenvirt_free(const char *name, const unsigned numa_node)
 
 /*TODO: Support multiple process model */
 static int
-rte_pmd_xenvirt_probe(const char *name, const char *params)
+rte_pmd_xenvirt_probe(struct rte_vdev_device *dev)
 {
 	if (virtio_idx == 0) {
 		if (xenstore_init() != 0) {
@@ -738,14 +738,15 @@ rte_pmd_xenvirt_probe(const char *name, const char *params)
 			return -1;
 		}
 	}
-	eth_dev_xenvirt_create(name, params, rte_socket_id(), DEV_CREATE);
+	eth_dev_xenvirt_create(rte_vdev_device_name(dev),
+		rte_vdev_device_args(dev), rte_socket_id(), DEV_CREATE);
 	return 0;
 }
 
 static int
-rte_pmd_xenvirt_remove(const char *name)
+rte_pmd_xenvirt_remove(struct rte_vdev_device *dev)
 {
-	eth_dev_xenvirt_free(name, rte_socket_id());
+	eth_dev_xenvirt_free(rte_vdev_device_name(dev), rte_socket_id());
 
 	if (virtio_idx == 0) {
 		if (xenstore_uninit() != 0)
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 7215b50..3ee24b1 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -75,7 +75,6 @@ static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
 	const char *name = rte_vdev_device_name(dev);
-	const char *args = rte_vdev_device_args(dev);
 	struct rte_vdev_driver *driver;
 	int ret;
 
@@ -89,7 +88,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 		if (!strncmp(driver->driver.name, name,
 			    strlen(driver->driver.name))) {
 			dev->device.driver = &driver->driver;
-			ret = driver->probe(name, args);
+			ret = driver->probe(dev);
 			if (ret)
 				dev->device.driver = NULL;
 			return ret;
@@ -102,7 +101,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 		    !strncmp(driver->driver.alias, name,
 			    strlen(driver->driver.alias))) {
 			dev->device.driver = &driver->driver;
-			ret = driver->probe(name, args);
+			ret = driver->probe(dev);
 			if (ret)
 				dev->device.driver = NULL;
 			return ret;
@@ -214,7 +213,7 @@ vdev_remove_driver(struct rte_vdev_device *dev)
 
 	driver = container_of(dev->device.driver, const struct rte_vdev_driver,
 		driver);
-	return driver->remove(name);
+	return driver->remove(dev);
 }
 
 int
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 81f6beb..8db2c00 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -68,12 +68,12 @@ TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 /**
  * Probe function called for each virtual device driver once.
  */
-typedef int (rte_vdev_probe_t)(const char *name, const char *args);
+typedef int (rte_vdev_probe_t)(struct rte_vdev_device *dev);
 
 /**
  * Remove function called for each virtual device driver once.
  */
-typedef int (rte_vdev_remove_t)(const char *name);
+typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev);
 
 /**
  * A virtual device driver abstraction.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* Re: [PATCH v3 02/10] eal: probe new virtual bus after other bus devices
  2017-02-25 10:28   ` [PATCH v3 02/10] eal: probe new virtual bus after " Jan Blunck
@ 2017-02-27  8:59     ` Shreyansh Jain
  2017-02-27  9:09       ` Jan Blunck
  0 siblings, 1 reply; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-27  8:59 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: david.marchand, ferruh.yigit

On Saturday 25 February 2017 03:58 PM, Jan Blunck wrote:
> Also see commit f4ce209a ("eal: postpone vdev initialization").
>
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> ---
>  lib/librte_eal/common/eal_common_bus.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> index 4638e78..8f9baf8 100644
> --- a/lib/librte_eal/common/eal_common_bus.c
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -86,9 +86,14 @@ int
>  rte_bus_probe(void)
>  {
>  	int ret;
> -	struct rte_bus *bus;
> +	struct rte_bus *bus, *vbus = NULL;
>
>  	TAILQ_FOREACH(bus, &rte_bus_list, next) {
> +		if (!strcmp(bus->name, "virtual")) {
> +			vbus = bus;
> +			continue;
> +		}
> +
>  		ret = bus->probe();
>  		if (ret) {
>  			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
> @@ -97,6 +102,15 @@ rte_bus_probe(void)
>  		}
>  	}
>
> +	if (vbus) {
> +		ret = vbus->probe();
> +		if (ret) {
> +			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
> +				vbus->name);
> +			return ret;
> +		}
> +	}
> +

This has probably changed to do away with priority of RTE_REGISTER_*
macro.

This is based on an assumption that there is only a single 'virtual'
bus and no driver ever registers another bus with the same name.

The problem originates from the fact that rte_bus_register is
_not_ checking for duplicate entries while registering.
(Apparently, it would be a problem in case of RTE_* macros as well).

I think that should be fixed.

If we are in sync, I will push a patch.

>  	return 0;
>  }
>
>

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v3 02/10] eal: probe new virtual bus after other bus devices
  2017-02-27  8:59     ` Shreyansh Jain
@ 2017-02-27  9:09       ` Jan Blunck
  0 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-02-27  9:09 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: dev, David Marchand, Ferruh Yigit

On Mon, Feb 27, 2017 at 9:59 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> On Saturday 25 February 2017 03:58 PM, Jan Blunck wrote:
>>
>> Also see commit f4ce209a ("eal: postpone vdev initialization").
>>
>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>> ---
>>  lib/librte_eal/common/eal_common_bus.c | 16 +++++++++++++++-
>>  1 file changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/lib/librte_eal/common/eal_common_bus.c
>> b/lib/librte_eal/common/eal_common_bus.c
>> index 4638e78..8f9baf8 100644
>> --- a/lib/librte_eal/common/eal_common_bus.c
>> +++ b/lib/librte_eal/common/eal_common_bus.c
>> @@ -86,9 +86,14 @@ int
>>  rte_bus_probe(void)
>>  {
>>         int ret;
>> -       struct rte_bus *bus;
>> +       struct rte_bus *bus, *vbus = NULL;
>>
>>         TAILQ_FOREACH(bus, &rte_bus_list, next) {
>> +               if (!strcmp(bus->name, "virtual")) {
>> +                       vbus = bus;
>> +                       continue;
>> +               }
>> +
>>                 ret = bus->probe();
>>                 if (ret) {
>>                         RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
>> @@ -97,6 +102,15 @@ rte_bus_probe(void)
>>                 }
>>         }
>>
>> +       if (vbus) {
>> +               ret = vbus->probe();
>> +               if (ret) {
>> +                       RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
>> +                               vbus->name);
>> +                       return ret;
>> +               }
>> +       }
>> +
>
>
> This has probably changed to do away with priority of RTE_REGISTER_*
> macro.
>
> This is based on an assumption that there is only a single 'virtual'
> bus and no driver ever registers another bus with the same name.
>
> The problem originates from the fact that rte_bus_register is
> _not_ checking for duplicate entries while registering.
> (Apparently, it would be a problem in case of RTE_* macros as well).
>
> I think that should be fixed.
>
> If we are in sync, I will push a patch.
>

Indeed. The buses should have a unique name.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v3 00/10] Rework vdev probing to use rte_bus infrastructure
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
@ 2017-02-27 13:09     ` Jan Blunck
  2017-02-28  8:48       ` Shreyansh Jain
  2017-03-06 10:56     ` [PATCH v4 " Jan Blunck
                       ` (10 subsequent siblings)
  11 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-27 13:09 UTC (permalink / raw)
  To: dev; +Cc: David Marchand, Shreyansh Jain, Ferruh Yigit

On Sat, Feb 25, 2017 at 11:28 AM, Jan Blunck <jblunck@infradead.org> wrote:
> With the rte_bus infrastructure present in 17.02 it is possible to refactor
> the virtual device probing into a bus. This series also introduces the
> rte_vdev_device to better keep track of devices.
>
> This patchset depends on:
> http://dpdk.org/dev/patchwork/patch/20416/
> http://dpdk.org/dev/patchwork/patch/20417/
>
> Changes since version 2:
>  * implicit bus registration through rte_eal_vdrv_register()

On a second thought I don't think that this is correct though since it
opens up the possibility of racing an alternative "virtual" bus. I
don't think that this is a good thing though. I'll fix this in v4.

Thoughts?

Thanks,
Jan

>  * explicit delay probing of virtual bus in rte_bus_probe()
>  * addition of rte_vdev_device_args() helper
>  * make virtual driver probe and remove take rte_vdev_device
>
> Changes since version 1:
>  * addition of rte_vdev_device_name() helper
>  * removed rte_eal_dev_init() from *.map files
>  * use SOCKET_ID_ANY
>
> Jan Blunck (10):
>   eal: probe legacy PCI devices before other bus devices
>   eal: probe new virtual bus after other bus devices
>   eal: move virtual device probing into a bus
>   eal: remove unused rte_eal_dev_init()
>   eal: Refactor vdev driver probe/remove
>   eal: add struct rte_vdev_device
>   eal: add virtual device name helper function
>   eal: add virtual device arguments helper function
>   eal: make virtual bus use rte_vdev_device
>   eal: make virtual driver probe and remove take rte_vdev_device
>
>  drivers/crypto/null/null_crypto_pmd.c           |  18 +-
>  drivers/net/af_packet/rte_eth_af_packet.c       |  11 +-
>  drivers/net/bonding/rte_eth_bond_pmd.c          |  13 +-
>  drivers/net/mpipe/mpipe_tilegx.c                |  10 +-
>  drivers/net/null/rte_eth_null.c                 |  13 +-
>  drivers/net/pcap/rte_eth_pcap.c                 |  12 +-
>  drivers/net/ring/rte_eth_ring.c                 |   9 +-
>  drivers/net/tap/rte_eth_tap.c                   |  10 +-
>  drivers/net/vhost/rte_eth_vhost.c               |  10 +-
>  drivers/net/virtio/virtio_user_ethdev.c         |  18 +-
>  drivers/net/xenvirt/rte_eth_xenvirt.c           |   9 +-
>  lib/librte_eal/bsdapp/eal/eal.c                 |   9 +-
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 -
>  lib/librte_eal/common/eal_common_bus.c          |  16 +-
>  lib/librte_eal/common/eal_common_dev.c          |  28 ---
>  lib/librte_eal/common/eal_common_vdev.c         | 259 +++++++++++++++++++++---
>  lib/librte_eal/common/include/rte_dev.h         |   5 -
>  lib/librte_eal/common/include/rte_vdev.h        |  26 ++-
>  lib/librte_eal/linuxapp/eal/eal.c               |   9 +-
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 -
>  20 files changed, 355 insertions(+), 132 deletions(-)
>
> --
> 2.7.4
>

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v3 00/10] Rework vdev probing to use rte_bus infrastructure
  2017-02-27 13:09     ` Jan Blunck
@ 2017-02-28  8:48       ` Shreyansh Jain
  2017-02-28  9:19         ` Jan Blunck
  0 siblings, 1 reply; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-28  8:48 UTC (permalink / raw)
  To: Jan Blunck, dev; +Cc: David Marchand, Ferruh Yigit

On Monday 27 February 2017 06:39 PM, Jan Blunck wrote:
> On Sat, Feb 25, 2017 at 11:28 AM, Jan Blunck <jblunck@infradead.org> wrote:
>> With the rte_bus infrastructure present in 17.02 it is possible to refactor
>> the virtual device probing into a bus. This series also introduces the
>> rte_vdev_device to better keep track of devices.
>>
>> This patchset depends on:
>> http://dpdk.org/dev/patchwork/patch/20416/
>> http://dpdk.org/dev/patchwork/patch/20417/
>>
>> Changes since version 2:
>>  * implicit bus registration through rte_eal_vdrv_register()
>
> On a second thought I don't think that this is correct though since it
> opens up the possibility of racing an alternative "virtual" bus. I
> don't think that this is a good thing though. I'll fix this in v4.
>
> Thoughts?

I prefer the RTE_REGISTER* way.
The issue of duplicate bus remains whether we use the macro or the
implicit way.

If you use RTE_*, do you think that duplicate registration issue
is worth fixing?
(It would mean rte_bus_register to return error which the caller
would then need to handle).

>
> Thanks,
> Jan
>
>>  * explicit delay probing of virtual bus in rte_bus_probe()
>>  * addition of rte_vdev_device_args() helper
>>  * make virtual driver probe and remove take rte_vdev_device
>>
>> Changes since version 1:
>>  * addition of rte_vdev_device_name() helper
>>  * removed rte_eal_dev_init() from *.map files
>>  * use SOCKET_ID_ANY
>>
>> Jan Blunck (10):
>>   eal: probe legacy PCI devices before other bus devices
>>   eal: probe new virtual bus after other bus devices
>>   eal: move virtual device probing into a bus
>>   eal: remove unused rte_eal_dev_init()
>>   eal: Refactor vdev driver probe/remove
>>   eal: add struct rte_vdev_device
>>   eal: add virtual device name helper function
>>   eal: add virtual device arguments helper function
>>   eal: make virtual bus use rte_vdev_device
>>   eal: make virtual driver probe and remove take rte_vdev_device
>>
>>  drivers/crypto/null/null_crypto_pmd.c           |  18 +-
>>  drivers/net/af_packet/rte_eth_af_packet.c       |  11 +-
>>  drivers/net/bonding/rte_eth_bond_pmd.c          |  13 +-
>>  drivers/net/mpipe/mpipe_tilegx.c                |  10 +-
>>  drivers/net/null/rte_eth_null.c                 |  13 +-
>>  drivers/net/pcap/rte_eth_pcap.c                 |  12 +-
>>  drivers/net/ring/rte_eth_ring.c                 |   9 +-
>>  drivers/net/tap/rte_eth_tap.c                   |  10 +-
>>  drivers/net/vhost/rte_eth_vhost.c               |  10 +-
>>  drivers/net/virtio/virtio_user_ethdev.c         |  18 +-
>>  drivers/net/xenvirt/rte_eth_xenvirt.c           |   9 +-
>>  lib/librte_eal/bsdapp/eal/eal.c                 |   9 +-
>>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 -
>>  lib/librte_eal/common/eal_common_bus.c          |  16 +-
>>  lib/librte_eal/common/eal_common_dev.c          |  28 ---
>>  lib/librte_eal/common/eal_common_vdev.c         | 259 +++++++++++++++++++++---
>>  lib/librte_eal/common/include/rte_dev.h         |   5 -
>>  lib/librte_eal/common/include/rte_vdev.h        |  26 ++-
>>  lib/librte_eal/linuxapp/eal/eal.c               |   9 +-
>>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 -
>>  20 files changed, 355 insertions(+), 132 deletions(-)
>>
>> --
>> 2.7.4
>>
>

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v3 00/10] Rework vdev probing to use rte_bus infrastructure
  2017-02-28  8:48       ` Shreyansh Jain
@ 2017-02-28  9:19         ` Jan Blunck
  2017-02-28  9:28           ` Shreyansh Jain
  0 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-02-28  9:19 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: dev, David Marchand, Ferruh Yigit

On Tue, Feb 28, 2017 at 9:48 AM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> On Monday 27 February 2017 06:39 PM, Jan Blunck wrote:
>>
>> On Sat, Feb 25, 2017 at 11:28 AM, Jan Blunck <jblunck@infradead.org>
>> wrote:
>>>
>>> With the rte_bus infrastructure present in 17.02 it is possible to
>>> refactor
>>> the virtual device probing into a bus. This series also introduces the
>>> rte_vdev_device to better keep track of devices.
>>>
>>> This patchset depends on:
>>> http://dpdk.org/dev/patchwork/patch/20416/
>>> http://dpdk.org/dev/patchwork/patch/20417/
>>>
>>> Changes since version 2:
>>>  * implicit bus registration through rte_eal_vdrv_register()
>>
>>
>> On a second thought I don't think that this is correct though since it
>> opens up the possibility of racing an alternative "virtual" bus. I
>> don't think that this is a good thing though. I'll fix this in v4.
>>
>> Thoughts?
>
>
> I prefer the RTE_REGISTER* way.
> The issue of duplicate bus remains whether we use the macro or the
> implicit way.
>
> If you use RTE_*, do you think that duplicate registration issue
> is worth fixing?
> (It would mean rte_bus_register to return error which the caller
> would then need to handle).
>

I don't think that there is a good way to handle this if we use the
library constructors. It is better to fail the registration of the bus
and log the error via RTE_LOG(). That introduces a dependency on the
initialization of the logging system to be available before the
library constructors run (before main()).

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v3 00/10] Rework vdev probing to use rte_bus infrastructure
  2017-02-28  9:19         ` Jan Blunck
@ 2017-02-28  9:28           ` Shreyansh Jain
  0 siblings, 0 replies; 91+ messages in thread
From: Shreyansh Jain @ 2017-02-28  9:28 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, David Marchand, Ferruh Yigit

> -----Original Message-----
> From: jblunck@gmail.com [mailto:jblunck@gmail.com] On Behalf Of Jan Blunck
> Sent: Tuesday, February 28, 2017 2:49 PM
> To: Shreyansh Jain <shreyansh.jain@nxp.com>
> Cc: dev <dev@dpdk.org>; David Marchand <david.marchand@6wind.com>; Ferruh
> Yigit <ferruh.yigit@intel.com>
> Subject: Re: [PATCH v3 00/10] Rework vdev probing to use rte_bus
> infrastructure
> 
> On Tue, Feb 28, 2017 at 9:48 AM, Shreyansh Jain <shreyansh.jain@nxp.com>
> wrote:
> > On Monday 27 February 2017 06:39 PM, Jan Blunck wrote:
> >>
> >> On Sat, Feb 25, 2017 at 11:28 AM, Jan Blunck <jblunck@infradead.org>
> >> wrote:
> >>>
> >>> With the rte_bus infrastructure present in 17.02 it is possible to
> >>> refactor
> >>> the virtual device probing into a bus. This series also introduces the
> >>> rte_vdev_device to better keep track of devices.
> >>>
> >>> This patchset depends on:
> >>> http://dpdk.org/dev/patchwork/patch/20416/
> >>> http://dpdk.org/dev/patchwork/patch/20417/
> >>>
> >>> Changes since version 2:
> >>>  * implicit bus registration through rte_eal_vdrv_register()
> >>
> >>
> >> On a second thought I don't think that this is correct though since it
> >> opens up the possibility of racing an alternative "virtual" bus. I
> >> don't think that this is a good thing though. I'll fix this in v4.
> >>
> >> Thoughts?
> >
> >
> > I prefer the RTE_REGISTER* way.
> > The issue of duplicate bus remains whether we use the macro or the
> > implicit way.
> >
> > If you use RTE_*, do you think that duplicate registration issue
> > is worth fixing?
> > (It would mean rte_bus_register to return error which the caller
> > would then need to handle).
> >
> 
> I don't think that there is a good way to handle this if we use the
> library constructors. It is better to fail the registration of the bus
> and log the error via RTE_LOG(). That introduces a dependency on the
> initialization of the logging system to be available before the
> library constructors run (before main()).

Agree. Log dependency is the tricky part. Log subsystem is in turn
dependent on users input for level.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH v4 00/10] Rework vdev probing to use rte_bus infrastructure
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
  2017-02-27 13:09     ` Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-13 17:55       ` Thomas Monjalon
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
  2017-03-06 10:56     ` [PATCH v4 01/10] eal: probe legacy PCI devices before other bus devices Jan Blunck
                       ` (9 subsequent siblings)
  11 siblings, 2 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

With the rte_bus infrastructure present in 17.02 it is possible to refactor
the virtual device probing into a bus. This series also introduces the
rte_vdev_device to better keep track of devices.

This patchset depends on:
http://dpdk.org/dev/patchwork/patch/20416/
http://dpdk.org/dev/patchwork/patch/20417/

Changes since version 3:
 * revert implicit registration changes

Changes since version 2:
 * implicit bus registration through rte_eal_vdrv_register()
 * explicit delay probing of virtual bus in rte_bus_probe()
 * addition of rte_vdev_device_args() helper
 * make virtual driver probe and remove take rte_vdev_device

Changes since version 1:
 * addition of rte_vdev_device_name() helper
 * removed rte_eal_dev_init() from *.map files
 * use SOCKET_ID_ANY

Jan Blunck (10):
  eal: probe legacy PCI devices before other bus devices
  eal: probe new virtual bus after other bus devices
  eal: move virtual device probing into a bus
  eal: remove unused rte_eal_dev_init()
  eal: Refactor vdev driver probe/remove
  eal: add struct rte_vdev_device
  eal: add virtual device name helper function
  eal: add virtual device arguments helper function
  eal: make virtual bus use rte_vdev_device
  eal: make virtual driver probe and remove take rte_vdev_device

 drivers/crypto/null/null_crypto_pmd.c           |  18 +-
 drivers/net/af_packet/rte_eth_af_packet.c       |  11 +-
 drivers/net/bonding/rte_eth_bond_pmd.c          |  13 +-
 drivers/net/mpipe/mpipe_tilegx.c                |  10 +-
 drivers/net/null/rte_eth_null.c                 |  13 +-
 drivers/net/pcap/rte_eth_pcap.c                 |  12 +-
 drivers/net/ring/rte_eth_ring.c                 |   9 +-
 drivers/net/tap/rte_eth_tap.c                   |  10 +-
 drivers/net/vhost/rte_eth_vhost.c               |  10 +-
 drivers/net/virtio/virtio_user_ethdev.c         |  18 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c           |   9 +-
 lib/librte_eal/bsdapp/eal/eal.c                 |   9 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 -
 lib/librte_eal/common/eal_common_bus.c          |  16 +-
 lib/librte_eal/common/eal_common_dev.c          |  28 ---
 lib/librte_eal/common/eal_common_vdev.c         | 245 +++++++++++++++++++++---
 lib/librte_eal/common/include/rte_dev.h         |   5 -
 lib/librte_eal/common/include/rte_vdev.h        |  26 ++-
 lib/librte_eal/linuxapp/eal/eal.c               |   9 +-
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 -
 20 files changed, 341 insertions(+), 132 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH v4 01/10] eal: probe legacy PCI devices before other bus devices
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
  2017-02-27 13:09     ` Jan Blunck
  2017-03-06 10:56     ` [PATCH v4 " Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-06 10:56     ` [PATCH v4 02/10] eal: probe new virtual bus after " Jan Blunck
                       ` (8 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

Make sure that the PCI devices are probed before the virtual devices after
the legacy virtual device probing has been moved to a bus.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal.c   | 8 ++++----
 lib/librte_eal/linuxapp/eal/eal.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index ee7c9de..a584447 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -613,14 +613,14 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe all the buses and devices/drivers on them */
-	if (rte_bus_probe())
-		rte_panic("Cannot probe devices\n");
-
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	/* Probe all the buses and devices/drivers on them */
+	if (rte_bus_probe())
+		rte_panic("Cannot probe devices\n");
+
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index bf6b818..f77ff5c 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -884,14 +884,14 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe all the buses and devices/drivers on them */
-	if (rte_bus_probe())
-		rte_panic("Cannot probe devices\n");
-
 	/* Probe & Initialize PCI devices */
 	if (rte_eal_pci_probe())
 		rte_panic("Cannot probe PCI\n");
 
+	/* Probe all the buses and devices/drivers on them */
+	if (rte_bus_probe())
+		rte_panic("Cannot probe devices\n");
+
 	if (rte_eal_dev_init() < 0)
 		rte_panic("Cannot init pmd devices\n");
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v4 02/10] eal: probe new virtual bus after other bus devices
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                       ` (2 preceding siblings ...)
  2017-03-06 10:56     ` [PATCH v4 01/10] eal: probe legacy PCI devices before other bus devices Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-13 17:42       ` Thomas Monjalon
  2017-03-06 10:56     ` [PATCH v4 03/10] eal: move virtual device probing into a bus Jan Blunck
                       ` (7 subsequent siblings)
  11 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

Also see commit f4ce209a8ce5 ("eal: postpone vdev initialization").

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/eal_common_bus.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 4638e78..8f9baf8 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -86,9 +86,14 @@ int
 rte_bus_probe(void)
 {
 	int ret;
-	struct rte_bus *bus;
+	struct rte_bus *bus, *vbus = NULL;
 
 	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		if (!strcmp(bus->name, "virtual")) {
+			vbus = bus;
+			continue;
+		}
+
 		ret = bus->probe();
 		if (ret) {
 			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
@@ -97,6 +102,15 @@ rte_bus_probe(void)
 		}
 	}
 
+	if (vbus) {
+		ret = vbus->probe();
+		if (ret) {
+			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
+				vbus->name);
+			return ret;
+		}
+	}
+
 	return 0;
 }
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v4 03/10] eal: move virtual device probing into a bus
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                       ` (3 preceding siblings ...)
  2017-03-06 10:56     ` [PATCH v4 02/10] eal: probe new virtual bus after " Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-13 17:44       ` Thomas Monjalon
  2017-03-06 10:56     ` [PATCH v4 04/10] eal: remove unused rte_eal_dev_init() Jan Blunck
                       ` (6 subsequent siblings)
  11 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This is a refactoring of the virtual device probing which moves into into
a proper bus structure.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_dev.c  | 22 -----------------
 lib/librte_eal/common/eal_common_vdev.c | 44 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4f3b493..1ce90f6 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -79,28 +79,6 @@ void rte_eal_device_remove(struct rte_device *dev)
 int
 rte_eal_dev_init(void)
 {
-	struct rte_devargs *devargs;
-
-	/*
-	 * Note that the dev_driver_list is populated here
-	 * from calls made to rte_eal_driver_register from constructor functions
-	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
-	 */
-
-	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
-
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
-			continue;
-
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-					devargs->args)) {
-			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-					devargs->virt.drv_name);
-			return -1;
-		}
-	}
-
 	return 0;
 }
 
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 7d6e54f..b1f490c 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -37,8 +37,10 @@
 #include <stdint.h>
 #include <sys/queue.h>
 
+#include <rte_bus.h>
 #include <rte_vdev.h>
 #include <rte_common.h>
+#include <rte_devargs.h>
 
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
@@ -122,3 +124,45 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+static int
+vdev_scan(void)
+{
+	/* for virtual devices we don't need to scan anything */
+	return 0;
+}
+
+static int
+vdev_probe(void)
+{
+	struct rte_devargs *devargs;
+
+	/*
+	 * Note that the dev_driver_list is populated here
+	 * from calls made to rte_eal_driver_register from constructor functions
+	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
+	 */
+
+	/* call the init function for each virtual device */
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		if (rte_eal_vdev_init(devargs->virt.drv_name,
+				      devargs->args)) {
+			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
+				devargs->virt.drv_name);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+static struct rte_bus rte_vdev_bus = {
+	.scan = vdev_scan,
+	.probe = vdev_probe,
+};
+
+RTE_REGISTER_BUS(virtual, rte_vdev_bus);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v4 04/10] eal: remove unused rte_eal_dev_init()
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                       ` (4 preceding siblings ...)
  2017-03-06 10:56     ` [PATCH v4 03/10] eal: move virtual device probing into a bus Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-06 10:56     ` [PATCH v4 05/10] eal: Refactor vdev driver probe/remove Jan Blunck
                       ` (5 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal.c                 | 3 ---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   | 1 -
 lib/librte_eal/common/eal_common_dev.c          | 6 ------
 lib/librte_eal/common/include/rte_dev.h         | 5 -----
 lib/librte_eal/linuxapp/eal/eal.c               | 3 ---
 lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 -
 6 files changed, 19 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index a584447..3d29fcb 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -621,9 +621,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	if (rte_eal_dev_init() < 0)
-		rte_panic("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 67f2ffb..b1996e0 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -22,7 +22,6 @@ DPDK_2.0 {
 	rte_dump_tailq;
 	rte_eal_alarm_cancel;
 	rte_eal_alarm_set;
-	rte_eal_dev_init;
 	rte_eal_devargs_add;
 	rte_eal_devargs_dump;
 	rte_eal_devargs_type_count;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 1ce90f6..4bde430 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -76,12 +76,6 @@ void rte_eal_device_remove(struct rte_device *dev)
 	TAILQ_REMOVE(&dev_device_list, dev, next);
 }
 
-int
-rte_eal_dev_init(void)
-{
-	return 0;
-}
-
 int rte_eal_dev_attach(const char *name, const char *devargs)
 {
 	struct rte_pci_addr addr;
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index b17791f..4251099 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -171,11 +171,6 @@ void rte_eal_driver_register(struct rte_driver *driver);
 void rte_eal_driver_unregister(struct rte_driver *driver);
 
 /**
- * Initalize all the registered drivers in this process
- */
-int rte_eal_dev_init(void);
-
-/**
  * Initialize a driver specified by name.
  *
  * @param name
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index f77ff5c..88479de 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -892,9 +892,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
-	if (rte_eal_dev_init() < 0)
-		rte_panic("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 9c134b4..2ada2f0 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -22,7 +22,6 @@ DPDK_2.0 {
 	rte_dump_tailq;
 	rte_eal_alarm_cancel;
 	rte_eal_alarm_set;
-	rte_eal_dev_init;
 	rte_eal_devargs_add;
 	rte_eal_devargs_dump;
 	rte_eal_devargs_type_count;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v4 05/10] eal: Refactor vdev driver probe/remove
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                       ` (5 preceding siblings ...)
  2017-03-06 10:56     ` [PATCH v4 04/10] eal: remove unused rte_eal_dev_init() Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-06 10:56     ` [PATCH v4 06/10] eal: add struct rte_vdev_device Jan Blunck
                       ` (4 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This is a preparation for the introduction of the struct rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 44 ++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index b1f490c..07974c5 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -61,14 +61,11 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 	TAILQ_REMOVE(&vdev_driver_list, driver, next);
 }
 
-int
-rte_eal_vdev_init(const char *name, const char *args)
+static int
+vdev_probe_all_drivers(const char *name, const char *args)
 {
 	struct rte_vdev_driver *driver;
 
-	if (name == NULL)
-		return -EINVAL;
-
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -89,18 +86,29 @@ rte_eal_vdev_init(const char *name, const char *args)
 			return driver->probe(name, args);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
 }
 
 int
-rte_eal_vdev_uninit(const char *name)
+rte_eal_vdev_init(const char *name, const char *args)
 {
-	struct rte_vdev_driver *driver;
+	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
+	ret = vdev_probe_all_drivers(name, args);
+	if (ret  > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
+}
+
+static int
+vdev_remove_driver(const char *name)
+{
+	struct rte_vdev_driver *driver;
+
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -121,8 +129,22 @@ rte_eal_vdev_uninit(const char *name)
 			return driver->remove(name);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
+}
+
+int
+rte_eal_vdev_uninit(const char *name)
+{
+	int ret;
+
+	if (name == NULL)
+		return -EINVAL;
+
+	ret = vdev_remove_driver(name);
+	if (ret > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
 }
 
 static int
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v4 06/10] eal: add struct rte_vdev_device
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                       ` (6 preceding siblings ...)
  2017-03-06 10:56     ` [PATCH v4 05/10] eal: Refactor vdev driver probe/remove Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-06 10:56     ` [PATCH v4 07/10] eal: add virtual device name helper function Jan Blunck
                       ` (3 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This adds the rte_vdev_device structure which embeds a generic rte_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_vdev.c  | 5 +++++
 lib/librte_eal/common/include/rte_vdev.h | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 07974c5..f884c7b 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -42,6 +42,11 @@
 #include <rte_common.h>
 #include <rte_devargs.h>
 
+/** Double linked list of virtual device drivers. */
+TAILQ_HEAD(vdev_device_list, rte_vdev_device);
+
+static struct vdev_device_list vdev_device_list =
+	TAILQ_HEAD_INITIALIZER(vdev_device_list);
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
 
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 784e837..8f98372 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -40,6 +40,11 @@ extern "C" {
 #include <sys/queue.h>
 #include <rte_dev.h>
 
+struct rte_vdev_device {
+	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
+	struct rte_device device;               /**< Inherit core device */
+};
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v4 07/10] eal: add virtual device name helper function
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                       ` (7 preceding siblings ...)
  2017-03-06 10:56     ` [PATCH v4 06/10] eal: add struct rte_vdev_device Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-06 10:56     ` [PATCH v4 08/10] eal: add virtual device arguments " Jan Blunck
                       ` (2 subsequent siblings)
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This adds the rte_vdev_device_name() helper function to retrieve the
rte_vdev_device name which makes moving the name of the low-level
device into struct rte_device easier in the future.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/include/rte_vdev.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 8f98372..abdefab 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -39,12 +39,21 @@ extern "C" {
 
 #include <sys/queue.h>
 #include <rte_dev.h>
+#include <rte_devargs.h>
 
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
 };
 
+static inline const char *
+rte_vdev_device_name(const struct rte_vdev_device *dev)
+{
+	if (dev && dev->device.devargs)
+		return dev->device.devargs->virt.drv_name;
+	return NULL;
+}
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v4 08/10] eal: add virtual device arguments helper function
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                       ` (8 preceding siblings ...)
  2017-03-06 10:56     ` [PATCH v4 07/10] eal: add virtual device name helper function Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-06 10:56     ` [PATCH v4 09/10] eal: make virtual bus use rte_vdev_device Jan Blunck
  2017-03-06 10:56     ` [PATCH v4 10/10] eal: make virtual driver probe and remove take rte_vdev_device Jan Blunck
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This adds the rte_vdev_device_args() helper function to prepare for
changing the virtual drivers probe() functions take a rte_vdev_device
pointer instead of the name+args strings.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_vdev.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index abdefab..81f6beb 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -54,6 +54,14 @@ rte_vdev_device_name(const struct rte_vdev_device *dev)
 	return NULL;
 }
 
+static inline const char *
+rte_vdev_device_args(const struct rte_vdev_device *dev)
+{
+	if (dev && dev->device.devargs)
+		return dev->device.devargs->args;
+	return "";
+}
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v4 09/10] eal: make virtual bus use rte_vdev_device
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                       ` (9 preceding siblings ...)
  2017-03-06 10:56     ` [PATCH v4 08/10] eal: add virtual device arguments " Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  2017-03-13 17:51       ` Thomas Monjalon
  2017-03-06 10:56     ` [PATCH v4 10/10] eal: make virtual driver probe and remove take rte_vdev_device Jan Blunck
  11 siblings, 1 reply; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This allows the virtual bus to be rescanned and probed by tracking the
creation of rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 195 +++++++++++++++++++++++++-------
 1 file changed, 155 insertions(+), 40 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index f884c7b..d7a586b 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -41,6 +41,7 @@
 #include <rte_vdev.h>
 #include <rte_common.h>
 #include <rte_devargs.h>
+#include <rte_memory.h>
 
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_device_list, rte_vdev_device);
@@ -67,9 +68,12 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 }
 
 static int
-vdev_probe_all_drivers(const char *name, const char *args)
+vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
+	const char *args = rte_vdev_device_args(dev);
 	struct rte_vdev_driver *driver;
+	int ret;
 
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
@@ -79,90 +83,202 @@ vdev_probe_all_drivers(const char *name, const char *args)
 		 * So use strncmp to compare.
 		 */
 		if (!strncmp(driver->driver.name, name,
-			    strlen(driver->driver.name)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.name))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	/* Give new names precedence over aliases. */
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		if (driver->driver.alias &&
 		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.alias))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	return 1;
 }
 
+static struct rte_vdev_device *
+find_vdev(const char *name)
+{
+	struct rte_vdev_device *dev;
+
+	if (!name)
+		return NULL;
+
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
+		const char *devname = rte_vdev_device_name(dev);
+		if (!strncmp(devname, name, strlen(name)))
+			return dev;
+	}
+
+	return NULL;
+}
+
+static struct rte_devargs *
+alloc_devargs(const char *name, const char *args)
+{
+	struct rte_devargs *devargs;
+	int ret;
+
+	devargs = calloc(1, sizeof(*devargs));
+	if (!devargs)
+		return NULL;
+
+	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	if (args)
+		devargs->args = strdup(args);
+
+	ret = snprintf(devargs->virt.drv_name,
+			       sizeof(devargs->virt.drv_name), "%s", name);
+	if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name)) {
+		free(devargs->args);
+		free(devargs);
+		return NULL;
+	}
+
+	return devargs;
+}
+
 int
 rte_eal_vdev_init(const char *name, const char *args)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_probe_all_drivers(name, args);
-	if (ret  > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (dev)
+		return -EEXIST;
+
+	devargs = alloc_devargs(name, args);
+	if (!devargs)
+		return -ENOMEM;
+
+	dev = calloc(1, sizeof(*dev));
+	if (!dev) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+
+	dev->device.devargs = devargs;
+	dev->device.numa_node = SOCKET_ID_ANY;
+
+	ret = vdev_probe_all_drivers(dev);
+	if (ret) {
+		if (ret > 0)
+			RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+		goto fail;
+	}
+
+	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
+
+	rte_eal_device_insert(&dev->device);
+	TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	return 0;
 
+fail:
+	free(devargs->args);
+	free(devargs);
+	free(dev);
 	return ret;
 }
 
 static int
-vdev_remove_driver(const char *name)
+vdev_remove_driver(struct rte_vdev_device *dev)
 {
-	struct rte_vdev_driver *driver;
+	const char *name = rte_vdev_device_name(dev);
+	const struct rte_vdev_driver *driver;
 
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		/*
-		 * search a driver prefix in virtual device name.
-		 * For example, if the driver is pcap PMD, driver->name
-		 * will be "net_pcap", but "name" will be "net_pcapN".
-		 * So use strncmp to compare.
-		 */
-		if (!strncmp(driver->driver.name, name,
-			     strlen(driver->driver.name)))
-			return driver->remove(name);
-	}
-
-	/* Give new names precedence over aliases. */
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		if (driver->driver.alias &&
-		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->remove(name);
+	if (!dev->device.driver) {
+		RTE_LOG(DEBUG, EAL, "no driver attach to device %s\n", name);
+		return 1;
 	}
 
-	return 1;
+	driver = container_of(dev->device.driver, const struct rte_vdev_driver,
+		driver);
+	return driver->remove(name);
 }
 
 int
 rte_eal_vdev_uninit(const char *name)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_remove_driver(name);
-	if (ret > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (!dev)
+		return -ENOENT;
 
-	return ret;
+	devargs = dev->device.devargs;
+
+	ret = vdev_remove_driver(dev);
+	if (ret)
+		return ret;
+
+	TAILQ_REMOVE(&vdev_device_list, dev, next);
+	rte_eal_device_remove(&dev->device);
+
+	TAILQ_REMOVE(&devargs_list, devargs, next);
+
+	free(devargs->args);
+	free(devargs);
+	free(dev);
+	return 0;
 }
 
 static int
 vdev_scan(void)
 {
-	/* for virtual devices we don't need to scan anything */
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
+
+	/* for virtual devices we scan the devargs_list populated via cmdline */
+
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		dev = find_vdev(devargs->virt.drv_name);
+		if (dev)
+			continue;
+
+		dev = calloc(1, sizeof(*dev));
+		if (!dev)
+			return -1;
+
+		dev->device.devargs = devargs;
+		dev->device.numa_node = SOCKET_ID_ANY;
+
+		rte_eal_device_insert(&dev->device);
+		TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	}
+
 	return 0;
 }
 
 static int
 vdev_probe(void)
 {
-	struct rte_devargs *devargs;
+	struct rte_vdev_device *dev;
 
 	/*
 	 * Note that the dev_driver_list is populated here
@@ -171,15 +287,14 @@ vdev_probe(void)
 	 */
 
 	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (dev->device.driver)
 			continue;
 
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-				      devargs->args)) {
+		if (vdev_probe_all_drivers(dev)) {
 			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-				devargs->virt.drv_name);
+				rte_vdev_device_name(dev));
 			return -1;
 		}
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v4 10/10] eal: make virtual driver probe and remove take rte_vdev_device
  2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
                       ` (10 preceding siblings ...)
  2017-03-06 10:56     ` [PATCH v4 09/10] eal: make virtual bus use rte_vdev_device Jan Blunck
@ 2017-03-06 10:56     ` Jan Blunck
  11 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-06 10:56 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, shreyansh.jain, ferruh.yigit

This is a preparation to embed the generic rte_device into the rte_eth_dev
also for virtual devices.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/crypto/null/null_crypto_pmd.c     | 18 ++++++++++++------
 drivers/net/af_packet/rte_eth_af_packet.c | 11 ++++++-----
 drivers/net/bonding/rte_eth_bond_pmd.c    | 13 +++++++++----
 drivers/net/mpipe/mpipe_tilegx.c          | 10 ++++++----
 drivers/net/null/rte_eth_null.c           | 13 ++++++++-----
 drivers/net/pcap/rte_eth_pcap.c           | 12 +++++++-----
 drivers/net/ring/rte_eth_ring.c           |  9 +++++++--
 drivers/net/tap/rte_eth_tap.c             | 10 +++++++---
 drivers/net/vhost/rte_eth_vhost.c         | 10 +++++++---
 drivers/net/virtio/virtio_user_ethdev.c   | 18 +++++++-----------
 drivers/net/xenvirt/rte_eth_xenvirt.c     |  9 +++++----
 lib/librte_eal/common/eal_common_vdev.c   |  7 +++----
 lib/librte_eal/common/include/rte_vdev.h  |  4 ++--
 13 files changed, 86 insertions(+), 58 deletions(-)

diff --git a/drivers/crypto/null/null_crypto_pmd.c b/drivers/crypto/null/null_crypto_pmd.c
index ed5a9fc..51d6de0 100644
--- a/drivers/crypto/null/null_crypto_pmd.c
+++ b/drivers/crypto/null/null_crypto_pmd.c
@@ -218,8 +218,7 @@ cryptodev_null_create(struct rte_crypto_vdev_init_params *init_params)
 
 /** Initialise null crypto device */
 static int
-cryptodev_null_probe(const char *name,
-		const char *input_args)
+cryptodev_null_probe(struct rte_vdev_device *dev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -228,10 +227,11 @@ cryptodev_null_probe(const char *name,
 		{0}
 	};
 
-	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
+	rte_cryptodev_parse_vdev_init_params(&init_params,
+		rte_vdev_device_args(dev));
 
-	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
-			init_params.socket_id);
+	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n",
+		rte_vdev_device_name(dev), init_params.socket_id);
 	if (init_params.name[0] != '\0')
 		RTE_LOG(INFO, PMD, "  User defined name = %s\n",
 			init_params.name);
@@ -256,9 +256,15 @@ cryptodev_null_remove(const char *name)
 	return 0;
 }
 
+static int
+cryptodev_null_remove_dev(struct rte_vdev_device *dev)
+{
+	return cryptodev_null_remove(rte_vdev_device_name(dev));
+}
+
 static struct rte_vdev_driver cryptodev_null_pmd_drv = {
 	.probe = cryptodev_null_probe,
-	.remove = cryptodev_null_remove
+	.remove = cryptodev_null_remove_dev,
 };
 
 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_NULL_PMD, cryptodev_null_pmd_drv);
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 2f87553..77536e8 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -923,8 +923,9 @@ rte_eth_from_packet(const char *name,
 }
 
 static int
-rte_pmd_af_packet_probe(const char *name, const char *params)
+rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
 	unsigned numa_node;
 	int ret = 0;
 	struct rte_kvargs *kvlist;
@@ -934,7 +935,7 @@ rte_pmd_af_packet_probe(const char *name, const char *params)
 
 	numa_node = rte_socket_id();
 
-	kvlist = rte_kvargs_parse(params, valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
 	if (kvlist == NULL) {
 		ret = -1;
 		goto exit;
@@ -961,7 +962,7 @@ rte_pmd_af_packet_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_af_packet_remove(const char *name)
+rte_pmd_af_packet_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 	struct pmd_internals *internals;
@@ -970,11 +971,11 @@ rte_pmd_af_packet_remove(const char *name)
 	RTE_LOG(INFO, PMD, "Closing AF_PACKET ethdev on numa socket %u\n",
 			rte_socket_id());
 
-	if (name == NULL)
+	if (dev == NULL)
 		return -1;
 
 	/* find the ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (eth_dev == NULL)
 		return -1;
 
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index f3ac9e2..6c03920 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -2230,16 +2230,19 @@ const struct eth_dev_ops default_dev_ops = {
 };
 
 static int
-bond_probe(const char *name, const char *params)
+bond_probe(struct rte_vdev_device *dev)
 {
+	const char *name;
 	struct bond_dev_private *internals;
 	struct rte_kvargs *kvlist;
 	uint8_t bonding_mode, socket_id;
 	int  arg_count, port_id;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, EAL, "Initializing pmd_bond for %s\n", name);
 
-	kvlist = rte_kvargs_parse(params, pmd_bond_init_valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev),
+		pmd_bond_init_valid_arguments);
 	if (kvlist == NULL)
 		return -1;
 
@@ -2297,13 +2300,15 @@ bond_probe(const char *name, const char *params)
 }
 
 static int
-bond_remove(const char *name)
+bond_remove(struct rte_vdev_device *dev)
 {
+	const char *name;
 	int  ret;
 
-	if (name == NULL)
+	if (!dev)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, EAL, "Uninitializing pmd_bond for %s\n", name);
 
 	/* free link bonding eth device */
diff --git a/drivers/net/mpipe/mpipe_tilegx.c b/drivers/net/mpipe/mpipe_tilegx.c
index 60d5f81..e6f73ba 100644
--- a/drivers/net/mpipe/mpipe_tilegx.c
+++ b/drivers/net/mpipe/mpipe_tilegx.c
@@ -1642,15 +1642,17 @@ static struct rte_vdev_driver pmd_mpipe_gbe_drv = {
 };
 
 static int
-rte_pmd_mpipe_xgbe_probe(const char *ifname, const char *params __rte_unused)
+rte_pmd_mpipe_xgbe_probe(struct rte_vdev_device *dev)
 {
-	return rte_pmd_mpipe_probe_common(&pmd_mpipe_xgbe_drv, ifname, params);
+	return rte_pmd_mpipe_probe_common(&pmd_mpipe_xgbe_drv,
+		rte_vdev_device_name(dev), rte_vdev_device_args(dev));
 }
 
 static int
-rte_pmd_mpipe_gbe_probe(const char *ifname, const char *params __rte_unused)
+rte_pmd_mpipe_gbe_probe(struct rte_vdev_device *dev)
 {
-	return rte_pmd_mpipe_probe_common(&pmd_mpipe_gbe_drv, ifname, params);
+	return rte_pmd_mpipe_probe_common(&pmd_mpipe_gbe_drv,
+		rte_vdev_device_name(dev), rte_vdev_device_args(dev));
 }
 
 RTE_PMD_REGISTER_VDEV(net_mpipe_xgbe, pmd_mpipe_xgbe_drv);
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index 57203e2..f4242b0 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -608,17 +608,20 @@ get_packet_copy_arg(const char *key __rte_unused,
 }
 
 static int
-rte_pmd_null_probe(const char *name, const char *params)
+rte_pmd_null_probe(struct rte_vdev_device *dev)
 {
+	const char *name, *params;
 	unsigned numa_node;
 	unsigned packet_size = default_packet_size;
 	unsigned packet_copy = default_packet_copy;
 	struct rte_kvargs *kvlist = NULL;
 	int ret;
 
-	if (name == NULL)
+	if (!dev)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(dev);
+	params = rte_vdev_device_args(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_null for %s\n", name);
 
 	numa_node = rte_socket_id();
@@ -660,18 +663,18 @@ rte_pmd_null_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_null_remove(const char *name)
+rte_pmd_null_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 
-	if (name == NULL)
+	if (!dev)
 		return -EINVAL;
 
 	RTE_LOG(INFO, PMD, "Closing null ethdev on numa socket %u\n",
 			rte_socket_id());
 
 	/* find the ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (eth_dev == NULL)
 		return -1;
 
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 7f0b650..ab9cde1 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -936,8 +936,9 @@ eth_from_pcaps(const char *name, struct pmd_devargs *rx_queues,
 }
 
 static int
-pmd_pcap_probe(const char *name, const char *params)
+pmd_pcap_probe(struct rte_vdev_device *dev)
 {
+	const char *name;
 	unsigned int is_rx_pcap = 0, is_tx_pcap = 0;
 	struct rte_kvargs *kvlist;
 	struct pmd_devargs pcaps = {0};
@@ -945,13 +946,14 @@ pmd_pcap_probe(const char *name, const char *params)
 	int single_iface = 0;
 	int ret;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_pcap for %s\n", name);
 
 	gettimeofday(&start_time, NULL);
 	start_cycles = rte_get_timer_cycles();
 	hz = rte_get_timer_hz();
 
-	kvlist = rte_kvargs_parse(params, valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
 	if (kvlist == NULL)
 		return -1;
 
@@ -1035,18 +1037,18 @@ pmd_pcap_probe(const char *name, const char *params)
 }
 
 static int
-pmd_pcap_remove(const char *name)
+pmd_pcap_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 
 	RTE_LOG(INFO, PMD, "Closing pcap ethdev on numa socket %u\n",
 			rte_socket_id());
 
-	if (name == NULL)
+	if (!dev)
 		return -1;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (eth_dev == NULL)
 		return -1;
 
diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c
index 6f9cc1a..62606e7 100644
--- a/drivers/net/ring/rte_eth_ring.c
+++ b/drivers/net/ring/rte_eth_ring.c
@@ -502,12 +502,16 @@ static int parse_kvlist (const char *key __rte_unused, const char *value, void *
 }
 
 static int
-rte_pmd_ring_probe(const char *name, const char *params)
+rte_pmd_ring_probe(struct rte_vdev_device *dev)
 {
+	const char *name, *params;
 	struct rte_kvargs *kvlist = NULL;
 	int ret = 0;
 	struct node_action_list *info = NULL;
 
+	name = rte_vdev_device_name(dev);
+	params = rte_vdev_device_args(dev);
+
 	RTE_LOG(INFO, PMD, "Initializing pmd_ring for %s\n", name);
 
 	if (params == NULL || params[0] == '\0') {
@@ -577,8 +581,9 @@ rte_pmd_ring_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_ring_remove(const char *name)
+rte_pmd_ring_remove(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
 	struct rte_eth_dev *eth_dev = NULL;
 	struct pmd_internals *internals = NULL;
 	struct ring_queue *r = NULL;
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index efc4426..941150f 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -741,13 +741,17 @@ set_interface_speed(const char *key __rte_unused,
 /* Open a TAP interface device.
  */
 static int
-rte_pmd_tap_probe(const char *name, const char *params)
+rte_pmd_tap_probe(struct rte_vdev_device *dev)
 {
+	const char *name, *params;
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
 	int speed;
 	char tap_name[RTE_ETH_NAME_MAX_LEN];
 
+	name = rte_vdev_device_name(dev);
+	params = rte_vdev_device_args(dev);
+
 	speed = ETH_SPEED_NUM_10G;
 	snprintf(tap_name, sizeof(tap_name), "%s%d",
 		 DEFAULT_TAP_NAME, tap_unit++);
@@ -797,7 +801,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 /* detach a TAP device.
  */
 static int
-rte_pmd_tap_remove(const char *name)
+rte_pmd_tap_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 	struct pmd_internals *internals;
@@ -807,7 +811,7 @@ rte_pmd_tap_remove(const char *name)
 		rte_socket_id());
 
 	/* find the ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (!eth_dev)
 		return 0;
 
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index e98cffd..d0d0474 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -1156,8 +1156,9 @@ open_int(const char *key __rte_unused, const char *value, void *extra_args)
 }
 
 static int
-rte_pmd_vhost_probe(const char *name, const char *params)
+rte_pmd_vhost_probe(struct rte_vdev_device *dev)
 {
+	const char *name;
 	struct rte_kvargs *kvlist = NULL;
 	int ret = 0;
 	char *iface_name;
@@ -1166,9 +1167,10 @@ rte_pmd_vhost_probe(const char *name, const char *params)
 	int client_mode = 0;
 	int dequeue_zero_copy = 0;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_vhost for %s\n", name);
 
-	kvlist = rte_kvargs_parse(params, valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
 	if (kvlist == NULL)
 		return -1;
 
@@ -1219,11 +1221,13 @@ rte_pmd_vhost_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_vhost_remove(const char *name)
+rte_pmd_vhost_remove(struct rte_vdev_device *dev)
 {
+	const char *name;
 	struct rte_eth_dev *eth_dev = NULL;
 	unsigned int i;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, PMD, "Un-Initializing pmd_vhost for %s\n", name);
 
 	/* find an ethdev entry */
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 0b226ac..42ad8a2 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -338,7 +338,7 @@ virtio_user_eth_dev_free(struct rte_eth_dev *eth_dev)
  * Returns 0 on success.
  */
 static int
-virtio_user_pmd_probe(const char *name, const char *params)
+virtio_user_pmd_probe(struct rte_vdev_device *dev)
 {
 	struct rte_kvargs *kvlist = NULL;
 	struct rte_eth_dev *eth_dev;
@@ -350,13 +350,7 @@ virtio_user_pmd_probe(const char *name, const char *params)
 	char *mac_addr = NULL;
 	int ret = -1;
 
-	if (!params || params[0] == '\0') {
-		PMD_INIT_LOG(ERR, "arg %s is mandatory for virtio_user",
-			  VIRTIO_USER_ARG_QUEUE_SIZE);
-		goto end;
-	}
-
-	kvlist = rte_kvargs_parse(params, valid_args);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_args);
 	if (!kvlist) {
 		PMD_INIT_LOG(ERR, "error when parsing param");
 		goto end;
@@ -418,7 +412,7 @@ virtio_user_pmd_probe(const char *name, const char *params)
 		goto end;
 	}
 
-	eth_dev = virtio_user_eth_dev_alloc(name);
+	eth_dev = virtio_user_eth_dev_alloc(rte_vdev_device_name(dev));
 	if (!eth_dev) {
 		PMD_INIT_LOG(ERR, "virtio_user fails to alloc device");
 		goto end;
@@ -452,15 +446,17 @@ virtio_user_pmd_probe(const char *name, const char *params)
 
 /** Called by rte_eth_dev_detach() */
 static int
-virtio_user_pmd_remove(const char *name)
+virtio_user_pmd_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
 	struct rte_eth_dev *eth_dev;
 	struct virtio_hw *hw;
 	struct virtio_user_dev *dev;
 
-	if (!name)
+	if (!vdev)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(vdev);
 	PMD_DRV_LOG(INFO, "Un-Initializing %s", name);
 	eth_dev = rte_eth_dev_allocated(name);
 	if (!eth_dev)
diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c b/drivers/net/xenvirt/rte_eth_xenvirt.c
index 19bc09a..6ec8c08 100644
--- a/drivers/net/xenvirt/rte_eth_xenvirt.c
+++ b/drivers/net/xenvirt/rte_eth_xenvirt.c
@@ -726,7 +726,7 @@ eth_dev_xenvirt_free(const char *name, const unsigned numa_node)
 
 /*TODO: Support multiple process model */
 static int
-rte_pmd_xenvirt_probe(const char *name, const char *params)
+rte_pmd_xenvirt_probe(struct rte_vdev_device *dev)
 {
 	if (virtio_idx == 0) {
 		if (xenstore_init() != 0) {
@@ -738,14 +738,15 @@ rte_pmd_xenvirt_probe(const char *name, const char *params)
 			return -1;
 		}
 	}
-	eth_dev_xenvirt_create(name, params, rte_socket_id(), DEV_CREATE);
+	eth_dev_xenvirt_create(rte_vdev_device_name(dev),
+		rte_vdev_device_args(dev), rte_socket_id(), DEV_CREATE);
 	return 0;
 }
 
 static int
-rte_pmd_xenvirt_remove(const char *name)
+rte_pmd_xenvirt_remove(struct rte_vdev_device *dev)
 {
-	eth_dev_xenvirt_free(name, rte_socket_id());
+	eth_dev_xenvirt_free(rte_vdev_device_name(dev), rte_socket_id());
 
 	if (virtio_idx == 0) {
 		if (xenstore_uninit() != 0)
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index d7a586b..58e9fed 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -71,7 +71,6 @@ static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
 	const char *name = rte_vdev_device_name(dev);
-	const char *args = rte_vdev_device_args(dev);
 	struct rte_vdev_driver *driver;
 	int ret;
 
@@ -85,7 +84,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 		if (!strncmp(driver->driver.name, name,
 			    strlen(driver->driver.name))) {
 			dev->device.driver = &driver->driver;
-			ret = driver->probe(name, args);
+			ret = driver->probe(dev);
 			if (ret)
 				dev->device.driver = NULL;
 			return ret;
@@ -98,7 +97,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 		    !strncmp(driver->driver.alias, name,
 			    strlen(driver->driver.alias))) {
 			dev->device.driver = &driver->driver;
-			ret = driver->probe(name, args);
+			ret = driver->probe(dev);
 			if (ret)
 				dev->device.driver = NULL;
 			return ret;
@@ -210,7 +209,7 @@ vdev_remove_driver(struct rte_vdev_device *dev)
 
 	driver = container_of(dev->device.driver, const struct rte_vdev_driver,
 		driver);
-	return driver->remove(name);
+	return driver->remove(dev);
 }
 
 int
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 81f6beb..8db2c00 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -68,12 +68,12 @@ TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 /**
  * Probe function called for each virtual device driver once.
  */
-typedef int (rte_vdev_probe_t)(const char *name, const char *args);
+typedef int (rte_vdev_probe_t)(struct rte_vdev_device *dev);
 
 /**
  * Remove function called for each virtual device driver once.
  */
-typedef int (rte_vdev_remove_t)(const char *name);
+typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev);
 
 /**
  * A virtual device driver abstraction.
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* Re: [PATCH v4 02/10] eal: probe new virtual bus after other bus devices
  2017-03-06 10:56     ` [PATCH v4 02/10] eal: probe new virtual bus after " Jan Blunck
@ 2017-03-13 17:42       ` Thomas Monjalon
  0 siblings, 0 replies; 91+ messages in thread
From: Thomas Monjalon @ 2017-03-13 17:42 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, david.marchand, shreyansh.jain, ferruh.yigit

2017-03-06 11:56, Jan Blunck:
> @@ -86,9 +86,14 @@ int
>  rte_bus_probe(void)
>  {
>  	int ret;
> -	struct rte_bus *bus;
> +	struct rte_bus *bus, *vbus = NULL;
>  
>  	TAILQ_FOREACH(bus, &rte_bus_list, next) {
> +		if (!strcmp(bus->name, "virtual")) {
> +			vbus = bus;
> +			continue;
> +		}

Why this special handling?

[...]
> +	if (vbus) {
> +		ret = vbus->probe();
> +		if (ret) {
> +			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
> +				vbus->name);
> +			return ret;
> +		}
> +	}

We should not have any special code in this function.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v4 03/10] eal: move virtual device probing into a bus
  2017-03-06 10:56     ` [PATCH v4 03/10] eal: move virtual device probing into a bus Jan Blunck
@ 2017-03-13 17:44       ` Thomas Monjalon
  2017-03-27  7:46         ` Jan Blunck
  0 siblings, 1 reply; 91+ messages in thread
From: Thomas Monjalon @ 2017-03-13 17:44 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, david.marchand, shreyansh.jain, ferruh.yigit

2017-03-06 11:56, Jan Blunck:
> +static int
> +vdev_scan(void)
> +{
> +	/* for virtual devices we don't need to scan anything */
> +	return 0;
> +}

The vdev_scan could save the devargs.
The vdev args are the equivalent of PCI BDF.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v4 09/10] eal: make virtual bus use rte_vdev_device
  2017-03-06 10:56     ` [PATCH v4 09/10] eal: make virtual bus use rte_vdev_device Jan Blunck
@ 2017-03-13 17:51       ` Thomas Monjalon
  2017-03-27  7:43         ` Jan Blunck
  0 siblings, 1 reply; 91+ messages in thread
From: Thomas Monjalon @ 2017-03-13 17:51 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, david.marchand, shreyansh.jain, ferruh.yigit

2017-03-06 11:56, Jan Blunck:
> This allows the virtual bus to be rescanned and probed by tracking the
> creation of rte_vdev_device.
> 
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>

There are a lot of strcmp in this patch.
Maybe it should be abstracted in a "match" function.
It would allow bringing new vdev rules in future.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v4 00/10] Rework vdev probing to use rte_bus infrastructure
  2017-03-06 10:56     ` [PATCH v4 " Jan Blunck
@ 2017-03-13 17:55       ` Thomas Monjalon
  2017-03-27  7:47         ` Jan Blunck
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
  1 sibling, 1 reply; 91+ messages in thread
From: Thomas Monjalon @ 2017-03-13 17:55 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, david.marchand, shreyansh.jain, ferruh.yigit

2017-03-06 11:56, Jan Blunck:
> Jan Blunck (10):
>   eal: probe legacy PCI devices before other bus devices
>   eal: probe new virtual bus after other bus devices
>   eal: move virtual device probing into a bus
>   eal: remove unused rte_eal_dev_init()
>   eal: Refactor vdev driver probe/remove
>   eal: add struct rte_vdev_device
>   eal: add virtual device name helper function
>   eal: add virtual device arguments helper function
>   eal: make virtual bus use rte_vdev_device
>   eal: make virtual driver probe and remove take rte_vdev_device
> 
>  drivers/crypto/null/null_crypto_pmd.c           |  18 +-
>  drivers/net/af_packet/rte_eth_af_packet.c       |  11 +-
>  drivers/net/bonding/rte_eth_bond_pmd.c          |  13 +-
>  drivers/net/mpipe/mpipe_tilegx.c                |  10 +-
>  drivers/net/null/rte_eth_null.c                 |  13 +-
>  drivers/net/pcap/rte_eth_pcap.c                 |  12 +-
>  drivers/net/ring/rte_eth_ring.c                 |   9 +-
>  drivers/net/tap/rte_eth_tap.c                   |  10 +-
>  drivers/net/vhost/rte_eth_vhost.c               |  10 +-
>  drivers/net/virtio/virtio_user_ethdev.c         |  18 +-
>  drivers/net/xenvirt/rte_eth_xenvirt.c           |   9 +-
>  lib/librte_eal/bsdapp/eal/eal.c                 |   9 +-
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 -
>  lib/librte_eal/common/eal_common_bus.c          |  16 +-
>  lib/librte_eal/common/eal_common_dev.c          |  28 ---
>  lib/librte_eal/common/eal_common_vdev.c         | 245 +++++++++++++++++++++---
>  lib/librte_eal/common/include/rte_dev.h         |   5 -
>  lib/librte_eal/common/include/rte_vdev.h        |  26 ++-
>  lib/librte_eal/linuxapp/eal/eal.c               |   9 +-
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 -
>  20 files changed, 341 insertions(+), 132 deletions(-)

When it will be merged, it would be nice to move the vdev bus files
to drivers/bus/vdev/.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v4 09/10] eal: make virtual bus use rte_vdev_device
  2017-03-13 17:51       ` Thomas Monjalon
@ 2017-03-27  7:43         ` Jan Blunck
  0 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-27  7:43 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, David Marchand, Shreyansh Jain, Ferruh Yigit

On Mon, Mar 13, 2017 at 6:51 PM, Thomas Monjalon
<thomas.monjalon@6wind.com> wrote:
> 2017-03-06 11:56, Jan Blunck:
>> This allows the virtual bus to be rescanned and probed by tracking the
>> creation of rte_vdev_device.
>>
>> Signed-off-by: Jan Blunck <jblunck@infradead.org>
>> Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
>> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
>
> There are a lot of strcmp in this patch.

Are you sure that you are referring to this patch? There is a single
strcmp added here in the find_vdev() helper.

> Maybe it should be abstracted in a "match" function.
> It would allow bringing new vdev rules in future.

Technically that is possible. If I remember correctly we agreed that
matching based on the alias is scheduled for removal in a future
release. Therefore I believe it is better to keep this in the virtual
bus layer implementation instead of moving it down to the PMDs by
introducing a driver specific "match" function.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v4 03/10] eal: move virtual device probing into a bus
  2017-03-13 17:44       ` Thomas Monjalon
@ 2017-03-27  7:46         ` Jan Blunck
  0 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-27  7:46 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, David Marchand, Shreyansh Jain, Ferruh Yigit

On Mon, Mar 13, 2017 at 6:44 PM, Thomas Monjalon
<thomas.monjalon@6wind.com> wrote:
> 2017-03-06 11:56, Jan Blunck:
>> +static int
>> +vdev_scan(void)
>> +{
>> +     /* for virtual devices we don't need to scan anything */
>> +     return 0;
>> +}
>
> The vdev_scan could save the devargs.
> The vdev args are the equivalent of PCI BDF.

In a later patch ("eal: make virtual bus use rte_vdev_device") the
vdev_scan() is creating the list of devices based on the devargs.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* Re: [PATCH v4 00/10] Rework vdev probing to use rte_bus infrastructure
  2017-03-13 17:55       ` Thomas Monjalon
@ 2017-03-27  7:47         ` Jan Blunck
  0 siblings, 0 replies; 91+ messages in thread
From: Jan Blunck @ 2017-03-27  7:47 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, David Marchand, Shreyansh Jain, Ferruh Yigit

On Mon, Mar 13, 2017 at 6:55 PM, Thomas Monjalon
<thomas.monjalon@6wind.com> wrote:
> 2017-03-06 11:56, Jan Blunck:
>> Jan Blunck (10):
>>   eal: probe legacy PCI devices before other bus devices
>>   eal: probe new virtual bus after other bus devices
>>   eal: move virtual device probing into a bus
>>   eal: remove unused rte_eal_dev_init()
>>   eal: Refactor vdev driver probe/remove
>>   eal: add struct rte_vdev_device
>>   eal: add virtual device name helper function
>>   eal: add virtual device arguments helper function
>>   eal: make virtual bus use rte_vdev_device
>>   eal: make virtual driver probe and remove take rte_vdev_device
>>
>>  drivers/crypto/null/null_crypto_pmd.c           |  18 +-
>>  drivers/net/af_packet/rte_eth_af_packet.c       |  11 +-
>>  drivers/net/bonding/rte_eth_bond_pmd.c          |  13 +-
>>  drivers/net/mpipe/mpipe_tilegx.c                |  10 +-
>>  drivers/net/null/rte_eth_null.c                 |  13 +-
>>  drivers/net/pcap/rte_eth_pcap.c                 |  12 +-
>>  drivers/net/ring/rte_eth_ring.c                 |   9 +-
>>  drivers/net/tap/rte_eth_tap.c                   |  10 +-
>>  drivers/net/vhost/rte_eth_vhost.c               |  10 +-
>>  drivers/net/virtio/virtio_user_ethdev.c         |  18 +-
>>  drivers/net/xenvirt/rte_eth_xenvirt.c           |   9 +-
>>  lib/librte_eal/bsdapp/eal/eal.c                 |   9 +-
>>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 -
>>  lib/librte_eal/common/eal_common_bus.c          |  16 +-
>>  lib/librte_eal/common/eal_common_dev.c          |  28 ---
>>  lib/librte_eal/common/eal_common_vdev.c         | 245 +++++++++++++++++++++---
>>  lib/librte_eal/common/include/rte_dev.h         |   5 -
>>  lib/librte_eal/common/include/rte_vdev.h        |  26 ++-
>>  lib/librte_eal/linuxapp/eal/eal.c               |   9 +-
>>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 -
>>  20 files changed, 341 insertions(+), 132 deletions(-)
>
> When it will be merged, it would be nice to move the vdev bus files
> to drivers/bus/vdev/.

Correct. I'll send a follow up which is moving the code to the new path.

^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH v5 00/12] Rework vdev probing to use rte_bus infrastructure
  2017-03-06 10:56     ` [PATCH v4 " Jan Blunck
  2017-03-13 17:55       ` Thomas Monjalon
@ 2017-04-11 15:44       ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 01/12] eal: probe new virtual bus after other bus devices Gaetan Rivet
                           ` (12 more replies)
  1 sibling, 13 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

I have rebased the work done by Jan to introduce the virtual device
subsystem using the new rte_bus API.
I also fixed a few outstanding compilation issues, related to PMDs introduced
during this release.
Additionally, a few virtual devices had not been ported to use the new
rte_vdev_device that had been introduced in previous versions.

This patchset depends on:
http://dpdk.org/dev/patchwork/patch/20416/
http://dpdk.org/dev/patchwork/patch/20417/

Changes since version 4:
 * Fix compilation issues for several virtual devices

Gaetan Rivet (3):
  net/kni: use generic vdev for probe and remove
  crypto: use generic vdev for probe and remove
  event: use generic vdev for probe and remove

Jan Blunck (9):
  eal: probe new virtual bus after other bus devices
  eal: move virtual device probing into a bus
  eal: remove unused rte_eal_dev_init()
  eal: Refactor vdev driver probe/remove
  eal: add struct rte_vdev_device
  eal: add virtual device name helper function
  eal: add virtual device arguments helper function
  eal: make virtual bus use rte_vdev_device
  eal: make virtual driver probe and remove take rte_vdev_device

 drivers/crypto/aesni_gcm/aesni_gcm_pmd.c        |  20 +-
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c      |  21 +-
 drivers/crypto/armv8/rte_armv8_pmd.c            |  21 +-
 drivers/crypto/kasumi/rte_kasumi_pmd.c          |  22 +-
 drivers/crypto/null/null_crypto_pmd.c           |  18 +-
 drivers/crypto/openssl/rte_openssl_pmd.c        |  22 +-
 drivers/crypto/scheduler/scheduler_pmd.c        |  17 +-
 drivers/crypto/snow3g/rte_snow3g_pmd.c          |  22 +-
 drivers/crypto/zuc/rte_zuc_pmd.c                |  22 +-
 drivers/event/octeontx/ssovf_evdev.c            |  11 +-
 drivers/event/skeleton/skeleton_eventdev.c      |  10 +-
 drivers/event/sw/sw_evdev.c                     |  11 +-
 drivers/net/af_packet/rte_eth_af_packet.c       |  11 +-
 drivers/net/bonding/rte_eth_bond_pmd.c          |  13 +-
 drivers/net/kni/rte_eth_kni.c                   |  12 +-
 drivers/net/null/rte_eth_null.c                 |  13 +-
 drivers/net/pcap/rte_eth_pcap.c                 |  12 +-
 drivers/net/ring/rte_eth_ring.c                 |   9 +-
 drivers/net/tap/rte_eth_tap.c                   |  10 +-
 drivers/net/vhost/rte_eth_vhost.c               |  10 +-
 drivers/net/virtio/virtio_user_ethdev.c         |  18 +-
 drivers/net/xenvirt/rte_eth_xenvirt.c           |   9 +-
 lib/librte_eal/bsdapp/eal/eal.c                 |   3 -
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   1 -
 lib/librte_eal/common/eal_common_bus.c          |  16 +-
 lib/librte_eal/common/eal_common_dev.c          |  29 ---
 lib/librte_eal/common/eal_common_vdev.c         | 262 +++++++++++++++++++++---
 lib/librte_eal/common/include/rte_dev.h         |   5 -
 lib/librte_eal/common/include/rte_vdev.h        |  26 ++-
 lib/librte_eal/linuxapp/eal/eal.c               |   3 -
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   1 -
 31 files changed, 492 insertions(+), 188 deletions(-)

-- 
2.1.4

^ permalink raw reply	[flat|nested] 91+ messages in thread

* [PATCH v5 01/12] eal: probe new virtual bus after other bus devices
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 02/12] eal: move virtual device probing into a bus Gaetan Rivet
                           ` (11 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

From: Jan Blunck <jblunck@infradead.org>

Also see commit f4ce209a8ce5 ("eal: postpone vdev initialization").

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/eal_common_bus.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 4638e78..8f9baf8 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -86,9 +86,14 @@ int
 rte_bus_probe(void)
 {
 	int ret;
-	struct rte_bus *bus;
+	struct rte_bus *bus, *vbus = NULL;
 
 	TAILQ_FOREACH(bus, &rte_bus_list, next) {
+		if (!strcmp(bus->name, "virtual")) {
+			vbus = bus;
+			continue;
+		}
+
 		ret = bus->probe();
 		if (ret) {
 			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
@@ -97,6 +102,15 @@ rte_bus_probe(void)
 		}
 	}
 
+	if (vbus) {
+		ret = vbus->probe();
+		if (ret) {
+			RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n",
+				vbus->name);
+			return ret;
+		}
+	}
+
 	return 0;
 }
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 02/12] eal: move virtual device probing into a bus
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 01/12] eal: probe new virtual bus after other bus devices Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 03/12] eal: remove unused rte_eal_dev_init() Gaetan Rivet
                           ` (10 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

From: Jan Blunck <jblunck@infradead.org>

This is a refactoring of the virtual device probing which moves into into
a proper bus structure.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_dev.c  | 25 +-------------
 lib/librte_eal/common/eal_common_vdev.c | 61 +++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 24 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index d7d1f3d..522aad3 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -81,30 +81,7 @@ void rte_eal_device_remove(struct rte_device *dev)
 int
 rte_eal_dev_init(void)
 {
-	struct rte_devargs *devargs;
-	int ret = 0;
-
-	/*
-	 * Note that the dev_driver_list is populated here
-	 * from calls made to rte_eal_driver_register from constructor functions
-	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
-	 */
-
-	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
-
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
-			continue;
-
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-					devargs->args)) {
-			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-					devargs->virt.drv_name);
-			ret = -1;
-		}
-	}
-
-	return ret;
+	return 0;
 }
 
 int rte_eal_dev_attach(const char *name, const char *devargs)
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 7d6e54f..a94c4c6 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -37,16 +37,23 @@
 #include <stdint.h>
 #include <sys/queue.h>
 
+#include <rte_eal.h>
+#include <rte_bus.h>
 #include <rte_vdev.h>
 #include <rte_common.h>
+#include <rte_devargs.h>
 
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
 
+static void rte_vdev_bus_register(void);
+
 /* register a driver */
 void
 rte_eal_vdrv_register(struct rte_vdev_driver *driver)
 {
+	rte_vdev_bus_register();
+
 	TAILQ_INSERT_TAIL(&vdev_driver_list, driver, next);
 	rte_eal_driver_register(&driver->driver);
 }
@@ -122,3 +129,57 @@ rte_eal_vdev_uninit(const char *name)
 	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
 	return -EINVAL;
 }
+
+static int
+vdev_scan(void)
+{
+	/* for virtual devices we don't need to scan anything */
+	return 0;
+}
+
+static int
+vdev_probe(void)
+{
+	struct rte_devargs *devargs;
+
+	/*
+	 * Note that the dev_driver_list is populated here
+	 * from calls made to rte_eal_driver_register from constructor functions
+	 * embedded into PMD modules via the RTE_PMD_REGISTER_VDEV macro
+	 */
+
+	/* call the init function for each virtual device */
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		if (rte_eal_vdev_init(devargs->virt.drv_name,
+				      devargs->args)) {
+			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
+				devargs->virt.drv_name);
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+static struct rte_bus rte_vdev_bus = {
+	.scan = vdev_scan,
+	.probe = vdev_probe,
+};
+
+RTE_INIT(rte_vdev_bus_register);
+
+static void rte_vdev_bus_register(void)
+{
+	static int registered;
+
+	if (registered)
+		return;
+
+	registered = 1;
+	rte_vdev_bus.name = RTE_STR(virtual);
+	rte_bus_register(&rte_vdev_bus);
+}
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 03/12] eal: remove unused rte_eal_dev_init()
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 01/12] eal: probe new virtual bus after other bus devices Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 02/12] eal: move virtual device probing into a bus Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 04/12] eal: Refactor vdev driver probe/remove Gaetan Rivet
                           ` (9 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

From: Jan Blunck <jblunck@infradead.org>

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal.c                 | 3 ---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   | 1 -
 lib/librte_eal/common/eal_common_dev.c          | 6 ------
 lib/librte_eal/common/include/rte_dev.h         | 5 -----
 lib/librte_eal/linuxapp/eal/eal.c               | 3 ---
 lib/librte_eal/linuxapp/eal/rte_eal_version.map | 1 -
 6 files changed, 19 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 7321ac6..41aa0b5 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -660,9 +660,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	if (rte_eal_dev_init() < 0)
-		rte_eal_init_alert("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index ca12d89..1bb3c9e 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -20,7 +20,6 @@ DPDK_2.0 {
 	rte_dump_tailq;
 	rte_eal_alarm_cancel;
 	rte_eal_alarm_set;
-	rte_eal_dev_init;
 	rte_eal_devargs_add;
 	rte_eal_devargs_dump;
 	rte_eal_devargs_type_count;
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 522aad3..01e37c4 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -78,12 +78,6 @@ void rte_eal_device_remove(struct rte_device *dev)
 	TAILQ_REMOVE(&dev_device_list, dev, next);
 }
 
-int
-rte_eal_dev_init(void)
-{
-	return 0;
-}
-
 int rte_eal_dev_attach(const char *name, const char *devargs)
 {
 	int ret = 1;
diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h
index b17791f..4251099 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -171,11 +171,6 @@ void rte_eal_driver_register(struct rte_driver *driver);
 void rte_eal_driver_unregister(struct rte_driver *driver);
 
 /**
- * Initalize all the registered drivers in this process
- */
-int rte_eal_dev_init(void);
-
-/**
  * Initialize a driver specified by name.
  *
  * @param name
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 7cf33d6..a869ee3 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -939,9 +939,6 @@ rte_eal_init(int argc, char **argv)
 		return -1;
 	}
 
-	if (rte_eal_dev_init() < 0)
-		rte_eal_init_alert("Cannot init pmd devices\n");
-
 	rte_eal_mcfg_complete();
 
 	return fctret;
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 94da1e7..dbc419b 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -20,7 +20,6 @@ DPDK_2.0 {
 	rte_dump_tailq;
 	rte_eal_alarm_cancel;
 	rte_eal_alarm_set;
-	rte_eal_dev_init;
 	rte_eal_devargs_add;
 	rte_eal_devargs_dump;
 	rte_eal_devargs_type_count;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 04/12] eal: Refactor vdev driver probe/remove
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (2 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 03/12] eal: remove unused rte_eal_dev_init() Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 05/12] eal: add struct rte_vdev_device Gaetan Rivet
                           ` (8 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

From: Jan Blunck <jblunck@infradead.org>

This is a preparation for the introduction of the struct rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 44 ++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index a94c4c6..c255073 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -66,14 +66,11 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 	TAILQ_REMOVE(&vdev_driver_list, driver, next);
 }
 
-int
-rte_eal_vdev_init(const char *name, const char *args)
+static int
+vdev_probe_all_drivers(const char *name, const char *args)
 {
 	struct rte_vdev_driver *driver;
 
-	if (name == NULL)
-		return -EINVAL;
-
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -94,18 +91,29 @@ rte_eal_vdev_init(const char *name, const char *args)
 			return driver->probe(name, args);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
 }
 
 int
-rte_eal_vdev_uninit(const char *name)
+rte_eal_vdev_init(const char *name, const char *args)
 {
-	struct rte_vdev_driver *driver;
+	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
+	ret = vdev_probe_all_drivers(name, args);
+	if (ret  > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
+}
+
+static int
+vdev_remove_driver(const char *name)
+{
+	struct rte_vdev_driver *driver;
+
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
 		 * search a driver prefix in virtual device name.
@@ -126,8 +134,22 @@ rte_eal_vdev_uninit(const char *name)
 			return driver->remove(name);
 	}
 
-	RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
-	return -EINVAL;
+	return 1;
+}
+
+int
+rte_eal_vdev_uninit(const char *name)
+{
+	int ret;
+
+	if (name == NULL)
+		return -EINVAL;
+
+	ret = vdev_remove_driver(name);
+	if (ret > 0)
+		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+
+	return ret;
 }
 
 static int
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 05/12] eal: add struct rte_vdev_device
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (3 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 04/12] eal: Refactor vdev driver probe/remove Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 06/12] eal: add virtual device name helper function Gaetan Rivet
                           ` (7 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

From: Jan Blunck <jblunck@infradead.org>

This adds the rte_vdev_device structure which embeds a generic rte_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_vdev.c  | 5 +++++
 lib/librte_eal/common/include/rte_vdev.h | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index c255073..e3a75fd 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -43,6 +43,11 @@
 #include <rte_common.h>
 #include <rte_devargs.h>
 
+/** Double linked list of virtual device drivers. */
+TAILQ_HEAD(vdev_device_list, rte_vdev_device);
+
+static struct vdev_device_list vdev_device_list =
+	TAILQ_HEAD_INITIALIZER(vdev_device_list);
 struct vdev_driver_list vdev_driver_list =
 	TAILQ_HEAD_INITIALIZER(vdev_driver_list);
 
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 784e837..8f98372 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -40,6 +40,11 @@ extern "C" {
 #include <sys/queue.h>
 #include <rte_dev.h>
 
+struct rte_vdev_device {
+	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
+	struct rte_device device;               /**< Inherit core device */
+};
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 06/12] eal: add virtual device name helper function
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (4 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 05/12] eal: add struct rte_vdev_device Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 07/12] eal: add virtual device arguments " Gaetan Rivet
                           ` (6 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

From: Jan Blunck <jblunck@infradead.org>

This adds the rte_vdev_device_name() helper function to retrieve the
rte_vdev_device name which makes moving the name of the low-level
device into struct rte_device easier in the future.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/include/rte_vdev.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 8f98372..abdefab 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -39,12 +39,21 @@ extern "C" {
 
 #include <sys/queue.h>
 #include <rte_dev.h>
+#include <rte_devargs.h>
 
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
 };
 
+static inline const char *
+rte_vdev_device_name(const struct rte_vdev_device *dev)
+{
+	if (dev && dev->device.devargs)
+		return dev->device.devargs->virt.drv_name;
+	return NULL;
+}
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 07/12] eal: add virtual device arguments helper function
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (5 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 06/12] eal: add virtual device name helper function Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 08/12] eal: make virtual bus use rte_vdev_device Gaetan Rivet
                           ` (5 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

From: Jan Blunck <jblunck@infradead.org>

This adds the rte_vdev_device_args() helper function to prepare for
changing the virtual drivers probe() functions take a rte_vdev_device
pointer instead of the name+args strings.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 lib/librte_eal/common/include/rte_vdev.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index abdefab..81f6beb 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -54,6 +54,14 @@ rte_vdev_device_name(const struct rte_vdev_device *dev)
 	return NULL;
 }
 
+static inline const char *
+rte_vdev_device_args(const struct rte_vdev_device *dev)
+{
+	if (dev && dev->device.devargs)
+		return dev->device.devargs->args;
+	return "";
+}
+
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 08/12] eal: make virtual bus use rte_vdev_device
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (6 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 07/12] eal: add virtual device arguments " Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 09/12] eal: make virtual driver probe and remove take rte_vdev_device Gaetan Rivet
                           ` (4 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

From: Jan Blunck <jblunck@infradead.org>

This allows the virtual bus to be rescanned and probed by tracking the
creation of rte_vdev_device.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
Tested-by: Ferruh Yigit <ferruh.yigit@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 195 +++++++++++++++++++++++++-------
 1 file changed, 155 insertions(+), 40 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index e3a75fd..70da608 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -42,6 +42,7 @@
 #include <rte_vdev.h>
 #include <rte_common.h>
 #include <rte_devargs.h>
+#include <rte_memory.h>
 
 /** Double linked list of virtual device drivers. */
 TAILQ_HEAD(vdev_device_list, rte_vdev_device);
@@ -72,9 +73,12 @@ rte_eal_vdrv_unregister(struct rte_vdev_driver *driver)
 }
 
 static int
-vdev_probe_all_drivers(const char *name, const char *args)
+vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
+	const char *args = rte_vdev_device_args(dev);
 	struct rte_vdev_driver *driver;
+	int ret;
 
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		/*
@@ -84,90 +88,202 @@ vdev_probe_all_drivers(const char *name, const char *args)
 		 * So use strncmp to compare.
 		 */
 		if (!strncmp(driver->driver.name, name,
-			    strlen(driver->driver.name)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.name))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	/* Give new names precedence over aliases. */
 	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
 		if (driver->driver.alias &&
 		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->probe(name, args);
+			    strlen(driver->driver.alias))) {
+			dev->device.driver = &driver->driver;
+			ret = driver->probe(name, args);
+			if (ret)
+				dev->device.driver = NULL;
+			return ret;
+		}
 	}
 
 	return 1;
 }
 
+static struct rte_vdev_device *
+find_vdev(const char *name)
+{
+	struct rte_vdev_device *dev;
+
+	if (!name)
+		return NULL;
+
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
+		const char *devname = rte_vdev_device_name(dev);
+		if (!strncmp(devname, name, strlen(name)))
+			return dev;
+	}
+
+	return NULL;
+}
+
+static struct rte_devargs *
+alloc_devargs(const char *name, const char *args)
+{
+	struct rte_devargs *devargs;
+	int ret;
+
+	devargs = calloc(1, sizeof(*devargs));
+	if (!devargs)
+		return NULL;
+
+	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	if (args)
+		devargs->args = strdup(args);
+
+	ret = snprintf(devargs->virt.drv_name,
+			       sizeof(devargs->virt.drv_name), "%s", name);
+	if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name)) {
+		free(devargs->args);
+		free(devargs);
+		return NULL;
+	}
+
+	return devargs;
+}
+
 int
 rte_eal_vdev_init(const char *name, const char *args)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_probe_all_drivers(name, args);
-	if (ret  > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (dev)
+		return -EEXIST;
+
+	devargs = alloc_devargs(name, args);
+	if (!devargs)
+		return -ENOMEM;
+
+	dev = calloc(1, sizeof(*dev));
+	if (!dev) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+
+	dev->device.devargs = devargs;
+	dev->device.numa_node = SOCKET_ID_ANY;
+
+	ret = vdev_probe_all_drivers(dev);
+	if (ret) {
+		if (ret > 0)
+			RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+		goto fail;
+	}
+
+	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
+
+	rte_eal_device_insert(&dev->device);
+	TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	return 0;
 
+fail:
+	free(devargs->args);
+	free(devargs);
+	free(dev);
 	return ret;
 }
 
 static int
-vdev_remove_driver(const char *name)
+vdev_remove_driver(struct rte_vdev_device *dev)
 {
-	struct rte_vdev_driver *driver;
+	const char *name = rte_vdev_device_name(dev);
+	const struct rte_vdev_driver *driver;
 
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		/*
-		 * search a driver prefix in virtual device name.
-		 * For example, if the driver is pcap PMD, driver->name
-		 * will be "net_pcap", but "name" will be "net_pcapN".
-		 * So use strncmp to compare.
-		 */
-		if (!strncmp(driver->driver.name, name,
-			     strlen(driver->driver.name)))
-			return driver->remove(name);
-	}
-
-	/* Give new names precedence over aliases. */
-	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
-		if (driver->driver.alias &&
-		    !strncmp(driver->driver.alias, name,
-			    strlen(driver->driver.alias)))
-			return driver->remove(name);
+	if (!dev->device.driver) {
+		RTE_LOG(DEBUG, EAL, "no driver attach to device %s\n", name);
+		return 1;
 	}
 
-	return 1;
+	driver = container_of(dev->device.driver, const struct rte_vdev_driver,
+		driver);
+	return driver->remove(name);
 }
 
 int
 rte_eal_vdev_uninit(const char *name)
 {
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
 	int ret;
 
 	if (name == NULL)
 		return -EINVAL;
 
-	ret = vdev_remove_driver(name);
-	if (ret > 0)
-		RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
+	dev = find_vdev(name);
+	if (!dev)
+		return -ENOENT;
 
-	return ret;
+	devargs = dev->device.devargs;
+
+	ret = vdev_remove_driver(dev);
+	if (ret)
+		return ret;
+
+	TAILQ_REMOVE(&vdev_device_list, dev, next);
+	rte_eal_device_remove(&dev->device);
+
+	TAILQ_REMOVE(&devargs_list, devargs, next);
+
+	free(devargs->args);
+	free(devargs);
+	free(dev);
+	return 0;
 }
 
 static int
 vdev_scan(void)
 {
-	/* for virtual devices we don't need to scan anything */
+	struct rte_vdev_device *dev;
+	struct rte_devargs *devargs;
+
+	/* for virtual devices we scan the devargs_list populated via cmdline */
+
+	TAILQ_FOREACH(devargs, &devargs_list, next) {
+
+		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+			continue;
+
+		dev = find_vdev(devargs->virt.drv_name);
+		if (dev)
+			continue;
+
+		dev = calloc(1, sizeof(*dev));
+		if (!dev)
+			return -1;
+
+		dev->device.devargs = devargs;
+		dev->device.numa_node = SOCKET_ID_ANY;
+
+		rte_eal_device_insert(&dev->device);
+		TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+	}
+
 	return 0;
 }
 
 static int
 vdev_probe(void)
 {
-	struct rte_devargs *devargs;
+	struct rte_vdev_device *dev;
 
 	/*
 	 * Note that the dev_driver_list is populated here
@@ -176,15 +292,14 @@ vdev_probe(void)
 	 */
 
 	/* call the init function for each virtual device */
-	TAILQ_FOREACH(devargs, &devargs_list, next) {
+	TAILQ_FOREACH(dev, &vdev_device_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (dev->device.driver)
 			continue;
 
-		if (rte_eal_vdev_init(devargs->virt.drv_name,
-				      devargs->args)) {
+		if (vdev_probe_all_drivers(dev)) {
 			RTE_LOG(ERR, EAL, "failed to initialize %s device\n",
-				devargs->virt.drv_name);
+				rte_vdev_device_name(dev));
 			return -1;
 		}
 	}
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 09/12] eal: make virtual driver probe and remove take rte_vdev_device
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (7 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 08/12] eal: make virtual bus use rte_vdev_device Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 10/12] net/kni: use generic vdev for probe and remove Gaetan Rivet
                           ` (3 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

From: Jan Blunck <jblunck@infradead.org>

This is a preparation to embed the generic rte_device into the rte_eth_dev
also for virtual devices.

Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
 drivers/crypto/null/null_crypto_pmd.c     | 18 ++++++++++++------
 drivers/net/af_packet/rte_eth_af_packet.c | 11 ++++++-----
 drivers/net/bonding/rte_eth_bond_pmd.c    | 13 +++++++++----
 drivers/net/null/rte_eth_null.c           | 13 ++++++++-----
 drivers/net/pcap/rte_eth_pcap.c           | 12 +++++++-----
 drivers/net/ring/rte_eth_ring.c           |  9 +++++++--
 drivers/net/tap/rte_eth_tap.c             | 10 +++++++---
 drivers/net/vhost/rte_eth_vhost.c         | 10 +++++++---
 drivers/net/virtio/virtio_user_ethdev.c   | 18 +++++++-----------
 drivers/net/xenvirt/rte_eth_xenvirt.c     |  9 +++++----
 lib/librte_eal/common/eal_common_vdev.c   |  7 +++----
 lib/librte_eal/common/include/rte_vdev.h  |  4 ++--
 12 files changed, 80 insertions(+), 54 deletions(-)

diff --git a/drivers/crypto/null/null_crypto_pmd.c b/drivers/crypto/null/null_crypto_pmd.c
index f68ec8d..a44c61a 100644
--- a/drivers/crypto/null/null_crypto_pmd.c
+++ b/drivers/crypto/null/null_crypto_pmd.c
@@ -218,8 +218,7 @@ cryptodev_null_create(struct rte_crypto_vdev_init_params *init_params)
 
 /** Initialise null crypto device */
 static int
-cryptodev_null_probe(const char *name,
-		const char *input_args)
+cryptodev_null_probe(struct rte_vdev_device *dev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -228,10 +227,11 @@ cryptodev_null_probe(const char *name,
 		{0}
 	};
 
-	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
+	rte_cryptodev_parse_vdev_init_params(&init_params,
+		rte_vdev_device_args(dev));
 
-	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
-			init_params.socket_id);
+	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n",
+		rte_vdev_device_name(dev), init_params.socket_id);
 	if (init_params.name[0] != '\0')
 		RTE_LOG(INFO, PMD, "  User defined name = %s\n",
 			init_params.name);
@@ -256,9 +256,15 @@ cryptodev_null_remove(const char *name)
 	return 0;
 }
 
+static int
+cryptodev_null_remove_dev(struct rte_vdev_device *dev)
+{
+	return cryptodev_null_remove(rte_vdev_device_name(dev));
+}
+
 static struct rte_vdev_driver cryptodev_null_pmd_drv = {
 	.probe = cryptodev_null_probe,
-	.remove = cryptodev_null_remove
+	.remove = cryptodev_null_remove_dev,
 };
 
 RTE_PMD_REGISTER_VDEV(CRYPTODEV_NAME_NULL_PMD, cryptodev_null_pmd_drv);
diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c
index 2f87553..77536e8 100644
--- a/drivers/net/af_packet/rte_eth_af_packet.c
+++ b/drivers/net/af_packet/rte_eth_af_packet.c
@@ -923,8 +923,9 @@ rte_eth_from_packet(const char *name,
 }
 
 static int
-rte_pmd_af_packet_probe(const char *name, const char *params)
+rte_pmd_af_packet_probe(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
 	unsigned numa_node;
 	int ret = 0;
 	struct rte_kvargs *kvlist;
@@ -934,7 +935,7 @@ rte_pmd_af_packet_probe(const char *name, const char *params)
 
 	numa_node = rte_socket_id();
 
-	kvlist = rte_kvargs_parse(params, valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
 	if (kvlist == NULL) {
 		ret = -1;
 		goto exit;
@@ -961,7 +962,7 @@ rte_pmd_af_packet_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_af_packet_remove(const char *name)
+rte_pmd_af_packet_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 	struct pmd_internals *internals;
@@ -970,11 +971,11 @@ rte_pmd_af_packet_remove(const char *name)
 	RTE_LOG(INFO, PMD, "Closing AF_PACKET ethdev on numa socket %u\n",
 			rte_socket_id());
 
-	if (name == NULL)
+	if (dev == NULL)
 		return -1;
 
 	/* find the ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (eth_dev == NULL)
 		return -1;
 
diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c
index 77d3bee..340d793 100644
--- a/drivers/net/bonding/rte_eth_bond_pmd.c
+++ b/drivers/net/bonding/rte_eth_bond_pmd.c
@@ -2240,16 +2240,19 @@ const struct eth_dev_ops default_dev_ops = {
 };
 
 static int
-bond_probe(const char *name, const char *params)
+bond_probe(struct rte_vdev_device *dev)
 {
+	const char *name;
 	struct bond_dev_private *internals;
 	struct rte_kvargs *kvlist;
 	uint8_t bonding_mode, socket_id;
 	int  arg_count, port_id;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, EAL, "Initializing pmd_bond for %s\n", name);
 
-	kvlist = rte_kvargs_parse(params, pmd_bond_init_valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev),
+		pmd_bond_init_valid_arguments);
 	if (kvlist == NULL)
 		return -1;
 
@@ -2307,13 +2310,15 @@ bond_probe(const char *name, const char *params)
 }
 
 static int
-bond_remove(const char *name)
+bond_remove(struct rte_vdev_device *dev)
 {
+	const char *name;
 	int  ret;
 
-	if (name == NULL)
+	if (!dev)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, EAL, "Uninitializing pmd_bond for %s\n", name);
 
 	/* free link bonding eth device */
diff --git a/drivers/net/null/rte_eth_null.c b/drivers/net/null/rte_eth_null.c
index 7e14da0..a7b57bc 100644
--- a/drivers/net/null/rte_eth_null.c
+++ b/drivers/net/null/rte_eth_null.c
@@ -606,17 +606,20 @@ get_packet_copy_arg(const char *key __rte_unused,
 }
 
 static int
-rte_pmd_null_probe(const char *name, const char *params)
+rte_pmd_null_probe(struct rte_vdev_device *dev)
 {
+	const char *name, *params;
 	unsigned numa_node;
 	unsigned packet_size = default_packet_size;
 	unsigned packet_copy = default_packet_copy;
 	struct rte_kvargs *kvlist = NULL;
 	int ret;
 
-	if (name == NULL)
+	if (!dev)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(dev);
+	params = rte_vdev_device_args(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_null for %s\n", name);
 
 	numa_node = rte_socket_id();
@@ -658,18 +661,18 @@ rte_pmd_null_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_null_remove(const char *name)
+rte_pmd_null_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 
-	if (name == NULL)
+	if (!dev)
 		return -EINVAL;
 
 	RTE_LOG(INFO, PMD, "Closing null ethdev on numa socket %u\n",
 			rte_socket_id());
 
 	/* find the ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (eth_dev == NULL)
 		return -1;
 
diff --git a/drivers/net/pcap/rte_eth_pcap.c b/drivers/net/pcap/rte_eth_pcap.c
index 075e3be..05cbd47 100644
--- a/drivers/net/pcap/rte_eth_pcap.c
+++ b/drivers/net/pcap/rte_eth_pcap.c
@@ -936,8 +936,9 @@ eth_from_pcaps(const char *name, struct pmd_devargs *rx_queues,
 }
 
 static int
-pmd_pcap_probe(const char *name, const char *params)
+pmd_pcap_probe(struct rte_vdev_device *dev)
 {
+	const char *name;
 	unsigned int is_rx_pcap = 0, is_tx_pcap = 0;
 	struct rte_kvargs *kvlist;
 	struct pmd_devargs pcaps = {0};
@@ -945,13 +946,14 @@ pmd_pcap_probe(const char *name, const char *params)
 	int single_iface = 0;
 	int ret;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_pcap for %s\n", name);
 
 	gettimeofday(&start_time, NULL);
 	start_cycles = rte_get_timer_cycles();
 	hz = rte_get_timer_hz();
 
-	kvlist = rte_kvargs_parse(params, valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
 	if (kvlist == NULL)
 		return -1;
 
@@ -1035,18 +1037,18 @@ pmd_pcap_probe(const char *name, const char *params)
 }
 
 static int
-pmd_pcap_remove(const char *name)
+pmd_pcap_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 
 	RTE_LOG(INFO, PMD, "Closing pcap ethdev on numa socket %u\n",
 			rte_socket_id());
 
-	if (name == NULL)
+	if (!dev)
 		return -1;
 
 	/* reserve an ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (eth_dev == NULL)
 		return -1;
 
diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c
index 77ef3a1..4bae895 100644
--- a/drivers/net/ring/rte_eth_ring.c
+++ b/drivers/net/ring/rte_eth_ring.c
@@ -502,12 +502,16 @@ static int parse_kvlist (const char *key __rte_unused, const char *value, void *
 }
 
 static int
-rte_pmd_ring_probe(const char *name, const char *params)
+rte_pmd_ring_probe(struct rte_vdev_device *dev)
 {
+	const char *name, *params;
 	struct rte_kvargs *kvlist = NULL;
 	int ret = 0;
 	struct node_action_list *info = NULL;
 
+	name = rte_vdev_device_name(dev);
+	params = rte_vdev_device_args(dev);
+
 	RTE_LOG(INFO, PMD, "Initializing pmd_ring for %s\n", name);
 
 	if (params == NULL || params[0] == '\0') {
@@ -577,8 +581,9 @@ rte_pmd_ring_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_ring_remove(const char *name)
+rte_pmd_ring_remove(struct rte_vdev_device *dev)
 {
+	const char *name = rte_vdev_device_name(dev);
 	struct rte_eth_dev *eth_dev = NULL;
 	struct pmd_internals *internals = NULL;
 	struct ring_queue *r = NULL;
diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 347a807..698e14b 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -1288,14 +1288,18 @@ set_remote_iface(const char *key __rte_unused,
 /* Open a TAP interface device.
  */
 static int
-rte_pmd_tap_probe(const char *name, const char *params)
+rte_pmd_tap_probe(struct rte_vdev_device *dev)
 {
+	const char *name, *params;
 	int ret;
 	struct rte_kvargs *kvlist = NULL;
 	int speed;
 	char tap_name[RTE_ETH_NAME_MAX_LEN];
 	char remote_iface[RTE_ETH_NAME_MAX_LEN];
 
+	name = rte_vdev_device_name(dev);
+	params = rte_vdev_device_args(dev);
+
 	speed = ETH_SPEED_NUM_10G;
 	snprintf(tap_name, sizeof(tap_name), "%s%d",
 		 DEFAULT_TAP_NAME, tap_unit++);
@@ -1355,7 +1359,7 @@ rte_pmd_tap_probe(const char *name, const char *params)
 /* detach a TAP device.
  */
 static int
-rte_pmd_tap_remove(const char *name)
+rte_pmd_tap_remove(struct rte_vdev_device *dev)
 {
 	struct rte_eth_dev *eth_dev = NULL;
 	struct pmd_internals *internals;
@@ -1365,7 +1369,7 @@ rte_pmd_tap_remove(const char *name)
 		rte_socket_id());
 
 	/* find the ethdev entry */
-	eth_dev = rte_eth_dev_allocated(name);
+	eth_dev = rte_eth_dev_allocated(rte_vdev_device_name(dev));
 	if (!eth_dev)
 		return 0;
 
diff --git a/drivers/net/vhost/rte_eth_vhost.c b/drivers/net/vhost/rte_eth_vhost.c
index 41ce5fc..cdd8c31 100644
--- a/drivers/net/vhost/rte_eth_vhost.c
+++ b/drivers/net/vhost/rte_eth_vhost.c
@@ -1132,8 +1132,9 @@ open_int(const char *key __rte_unused, const char *value, void *extra_args)
 }
 
 static int
-rte_pmd_vhost_probe(const char *name, const char *params)
+rte_pmd_vhost_probe(struct rte_vdev_device *dev)
 {
+	const char *name;
 	struct rte_kvargs *kvlist = NULL;
 	int ret = 0;
 	char *iface_name;
@@ -1142,9 +1143,10 @@ rte_pmd_vhost_probe(const char *name, const char *params)
 	int client_mode = 0;
 	int dequeue_zero_copy = 0;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, PMD, "Initializing pmd_vhost for %s\n", name);
 
-	kvlist = rte_kvargs_parse(params, valid_arguments);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_arguments);
 	if (kvlist == NULL)
 		return -1;
 
@@ -1195,11 +1197,13 @@ rte_pmd_vhost_probe(const char *name, const char *params)
 }
 
 static int
-rte_pmd_vhost_remove(const char *name)
+rte_pmd_vhost_remove(struct rte_vdev_device *dev)
 {
+	const char *name;
 	struct rte_eth_dev *eth_dev = NULL;
 	unsigned int i;
 
+	name = rte_vdev_device_name(dev);
 	RTE_LOG(INFO, PMD, "Un-Initializing pmd_vhost for %s\n", name);
 
 	/* find an ethdev entry */
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
index 35717f7..46276ee 100644
--- a/drivers/net/virtio/virtio_user_ethdev.c
+++ b/drivers/net/virtio/virtio_user_ethdev.c
@@ -402,7 +402,7 @@ virtio_user_eth_dev_free(struct rte_eth_dev *eth_dev)
  * Returns 0 on success.
  */
 static int
-virtio_user_pmd_probe(const char *name, const char *params)
+virtio_user_pmd_probe(struct rte_vdev_device *dev)
 {
 	struct rte_kvargs *kvlist = NULL;
 	struct rte_eth_dev *eth_dev;
@@ -415,13 +415,7 @@ virtio_user_pmd_probe(const char *name, const char *params)
 	char *mac_addr = NULL;
 	int ret = -1;
 
-	if (!params || params[0] == '\0') {
-		PMD_INIT_LOG(ERR, "arg %s is mandatory for virtio_user",
-			  VIRTIO_USER_ARG_QUEUE_SIZE);
-		goto end;
-	}
-
-	kvlist = rte_kvargs_parse(params, valid_args);
+	kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_args);
 	if (!kvlist) {
 		PMD_INIT_LOG(ERR, "error when parsing param");
 		goto end;
@@ -506,7 +500,7 @@ virtio_user_pmd_probe(const char *name, const char *params)
 		goto end;
 	}
 
-	eth_dev = virtio_user_eth_dev_alloc(name);
+	eth_dev = virtio_user_eth_dev_alloc(rte_vdev_device_name(dev));
 	if (!eth_dev) {
 		PMD_INIT_LOG(ERR, "virtio_user fails to alloc device");
 		goto end;
@@ -542,15 +536,17 @@ virtio_user_pmd_probe(const char *name, const char *params)
 
 /** Called by rte_eth_dev_detach() */
 static int
-virtio_user_pmd_remove(const char *name)
+virtio_user_pmd_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
 	struct rte_eth_dev *eth_dev;
 	struct virtio_hw *hw;
 	struct virtio_user_dev *dev;
 
-	if (!name)
+	if (!vdev)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(vdev);
 	PMD_DRV_LOG(INFO, "Un-Initializing %s", name);
 	eth_dev = rte_eth_dev_allocated(name);
 	if (!eth_dev)
diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c b/drivers/net/xenvirt/rte_eth_xenvirt.c
index 19bc09a..6ec8c08 100644
--- a/drivers/net/xenvirt/rte_eth_xenvirt.c
+++ b/drivers/net/xenvirt/rte_eth_xenvirt.c
@@ -726,7 +726,7 @@ eth_dev_xenvirt_free(const char *name, const unsigned numa_node)
 
 /*TODO: Support multiple process model */
 static int
-rte_pmd_xenvirt_probe(const char *name, const char *params)
+rte_pmd_xenvirt_probe(struct rte_vdev_device *dev)
 {
 	if (virtio_idx == 0) {
 		if (xenstore_init() != 0) {
@@ -738,14 +738,15 @@ rte_pmd_xenvirt_probe(const char *name, const char *params)
 			return -1;
 		}
 	}
-	eth_dev_xenvirt_create(name, params, rte_socket_id(), DEV_CREATE);
+	eth_dev_xenvirt_create(rte_vdev_device_name(dev),
+		rte_vdev_device_args(dev), rte_socket_id(), DEV_CREATE);
 	return 0;
 }
 
 static int
-rte_pmd_xenvirt_remove(const char *name)
+rte_pmd_xenvirt_remove(struct rte_vdev_device *dev)
 {
-	eth_dev_xenvirt_free(name, rte_socket_id());
+	eth_dev_xenvirt_free(rte_vdev_device_name(dev), rte_socket_id());
 
 	if (virtio_idx == 0) {
 		if (xenstore_uninit() != 0)
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 70da608..22fe2ca 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -76,7 +76,6 @@ static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
 	const char *name = rte_vdev_device_name(dev);
-	const char *args = rte_vdev_device_args(dev);
 	struct rte_vdev_driver *driver;
 	int ret;
 
@@ -90,7 +89,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 		if (!strncmp(driver->driver.name, name,
 			    strlen(driver->driver.name))) {
 			dev->device.driver = &driver->driver;
-			ret = driver->probe(name, args);
+			ret = driver->probe(dev);
 			if (ret)
 				dev->device.driver = NULL;
 			return ret;
@@ -103,7 +102,7 @@ vdev_probe_all_drivers(struct rte_vdev_device *dev)
 		    !strncmp(driver->driver.alias, name,
 			    strlen(driver->driver.alias))) {
 			dev->device.driver = &driver->driver;
-			ret = driver->probe(name, args);
+			ret = driver->probe(dev);
 			if (ret)
 				dev->device.driver = NULL;
 			return ret;
@@ -215,7 +214,7 @@ vdev_remove_driver(struct rte_vdev_device *dev)
 
 	driver = container_of(dev->device.driver, const struct rte_vdev_driver,
 		driver);
-	return driver->remove(name);
+	return driver->remove(dev);
 }
 
 int
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 81f6beb..8db2c00 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -68,12 +68,12 @@ TAILQ_HEAD(vdev_driver_list, rte_vdev_driver);
 /**
  * Probe function called for each virtual device driver once.
  */
-typedef int (rte_vdev_probe_t)(const char *name, const char *args);
+typedef int (rte_vdev_probe_t)(struct rte_vdev_device *dev);
 
 /**
  * Remove function called for each virtual device driver once.
  */
-typedef int (rte_vdev_remove_t)(const char *name);
+typedef int (rte_vdev_remove_t)(struct rte_vdev_device *dev);
 
 /**
  * A virtual device driver abstraction.
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 10/12] net/kni: use generic vdev for probe and remove
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (8 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 09/12] eal: make virtual driver probe and remove take rte_vdev_device Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 11/12] crypto: " Gaetan Rivet
                           ` (2 subsequent siblings)
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 drivers/net/kni/rte_eth_kni.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/net/kni/rte_eth_kni.c b/drivers/net/kni/rte_eth_kni.c
index 59205e7..e3ce572 100644
--- a/drivers/net/kni/rte_eth_kni.c
+++ b/drivers/net/kni/rte_eth_kni.c
@@ -393,7 +393,7 @@ eth_kni_create(const char *name, struct eth_kni_args *args,
 
 	eth_dev->data = data;
 	eth_dev->dev_ops = &eth_kni_ops;
-	eth_dev->driver = NULL;
+	eth_dev->device->driver = NULL;
 
 	data->dev_flags = RTE_ETH_DEV_DETACHABLE;
 	data->kdrv = RTE_KDRV_NONE;
@@ -442,12 +442,16 @@ eth_kni_kvargs_process(struct eth_kni_args *args, const char *params)
 }
 
 static int
-eth_kni_probe(const char *name, const char *params)
+eth_kni_probe(struct rte_vdev_device *vdev)
 {
 	struct rte_eth_dev *eth_dev;
 	struct eth_kni_args args;
+	const char *name;
+	const char *params;
 	int ret;
 
+	name = rte_vdev_device_name(vdev);
+	params = rte_vdev_device_args(vdev);
 	RTE_LOG(INFO, PMD, "Initializing eth_kni for %s\n", name);
 
 	ret = eth_kni_kvargs_process(&args, params);
@@ -475,11 +479,13 @@ eth_kni_probe(const char *name, const char *params)
 }
 
 static int
-eth_kni_remove(const char *name)
+eth_kni_remove(struct rte_vdev_device *vdev)
 {
 	struct rte_eth_dev *eth_dev;
 	struct pmd_internals *internals;
+	const char *name;
 
+	name = rte_vdev_device_name(vdev);
 	RTE_LOG(INFO, PMD, "Un-Initializing eth_kni for %s\n", name);
 
 	/* find the ethdev entry */
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 11/12] crypto: use generic vdev for probe and remove
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (9 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 10/12] net/kni: use generic vdev for probe and remove Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-11 15:44         ` [PATCH v5 12/12] event: " Gaetan Rivet
  2017-04-14 12:21         ` [PATCH v5 00/12] Rework vdev probing to use rte_bus infrastructure Thomas Monjalon
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 drivers/crypto/aesni_gcm/aesni_gcm_pmd.c   | 20 ++++++++++++++------
 drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c | 21 ++++++++++++++-------
 drivers/crypto/armv8/rte_armv8_pmd.c       | 21 ++++++++++++++-------
 drivers/crypto/kasumi/rte_kasumi_pmd.c     | 22 +++++++++++++++-------
 drivers/crypto/openssl/rte_openssl_pmd.c   | 22 +++++++++++++++-------
 drivers/crypto/scheduler/scheduler_pmd.c   | 17 +++++++++++------
 drivers/crypto/snow3g/rte_snow3g_pmd.c     | 22 +++++++++++++++-------
 drivers/crypto/zuc/rte_zuc_pmd.c           | 22 +++++++++++++++-------
 8 files changed, 113 insertions(+), 54 deletions(-)

diff --git a/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c b/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
index ceec765..1705896 100644
--- a/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
+++ b/drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
@@ -429,10 +429,11 @@ aesni_gcm_pmd_enqueue_burst(void *queue_pair,
 	return nb_enqueued;
 }
 
-static int aesni_gcm_remove(const char *name);
+static int aesni_gcm_remove(struct rte_vdev_device *vdev);
 
 static int
-aesni_gcm_create(struct rte_crypto_vdev_init_params *init_params)
+aesni_gcm_create(struct rte_vdev_device *vdev,
+		 struct rte_crypto_vdev_init_params *init_params)
 {
 	struct rte_cryptodev *dev;
 	struct aesni_gcm_private *internals;
@@ -483,12 +484,12 @@ aesni_gcm_create(struct rte_crypto_vdev_init_params *init_params)
 init_error:
 	GCM_LOG_ERR("driver %s: create failed", init_params->name);
 
-	aesni_gcm_remove(init_params->name);
+	aesni_gcm_remove(vdev);
 	return -EFAULT;
 }
 
 static int
-aesni_gcm_probe(const char *name, const char *input_args)
+aesni_gcm_probe(struct rte_vdev_device *vdev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -496,7 +497,11 @@ aesni_gcm_probe(const char *name, const char *input_args)
 		rte_socket_id(),
 		{0}
 	};
+	const char *name;
+	const char *input_args;
 
+	name = rte_vdev_device_name(vdev);
+	input_args = rte_vdev_device_args(vdev);
 	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
 	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
@@ -509,12 +514,15 @@ aesni_gcm_probe(const char *name, const char *input_args)
 	RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
 			init_params.max_nb_sessions);
 
-	return aesni_gcm_create(&init_params);
+	return aesni_gcm_create(vdev, &init_params);
 }
 
 static int
-aesni_gcm_remove(const char *name)
+aesni_gcm_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	if (name == NULL)
 		return -EINVAL;
 
diff --git a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
index be15d22..37b22ec 100644
--- a/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
+++ b/drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c
@@ -669,10 +669,11 @@ aesni_mb_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
 	return processed_jobs;
 }
 
-static int cryptodev_aesni_mb_remove(const char *name);
+static int cryptodev_aesni_mb_remove(struct rte_vdev_device *vdev);
 
 static int
-cryptodev_aesni_mb_create(struct rte_crypto_vdev_init_params *init_params)
+cryptodev_aesni_mb_create(struct rte_vdev_device *vdev,
+			  struct rte_crypto_vdev_init_params *init_params)
 {
 	struct rte_cryptodev *dev;
 	struct aesni_mb_private *internals;
@@ -750,13 +751,12 @@ cryptodev_aesni_mb_create(struct rte_crypto_vdev_init_params *init_params)
 	MB_LOG_ERR("driver %s: cryptodev_aesni_create failed",
 			init_params->name);
 
-	cryptodev_aesni_mb_remove(init_params->name);
+	cryptodev_aesni_mb_remove(vdev);
 	return -EFAULT;
 }
 
 static int
-cryptodev_aesni_mb_probe(const char *name,
-		const char *input_args)
+cryptodev_aesni_mb_probe(struct rte_vdev_device *vdev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -764,7 +764,11 @@ cryptodev_aesni_mb_probe(const char *name,
 		rte_socket_id(),
 		""
 	};
+	const char *name;
+	const char *input_args;
 
+	name = rte_vdev_device_name(vdev);
+	input_args = rte_vdev_device_args(vdev);
 	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
 	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
@@ -777,12 +781,15 @@ cryptodev_aesni_mb_probe(const char *name,
 	RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
 			init_params.max_nb_sessions);
 
-	return cryptodev_aesni_mb_create(&init_params);
+	return cryptodev_aesni_mb_create(vdev, &init_params);
 }
 
 static int
-cryptodev_aesni_mb_remove(const char *name)
+cryptodev_aesni_mb_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	if (name == NULL)
 		return -EINVAL;
 
diff --git a/drivers/crypto/armv8/rte_armv8_pmd.c b/drivers/crypto/armv8/rte_armv8_pmd.c
index 6376e9e..bf56bc6 100644
--- a/drivers/crypto/armv8/rte_armv8_pmd.c
+++ b/drivers/crypto/armv8/rte_armv8_pmd.c
@@ -44,7 +44,7 @@
 
 #include "rte_armv8_pmd_private.h"
 
-static int cryptodev_armv8_crypto_uninit(const char *name);
+static int cryptodev_armv8_crypto_uninit(struct rte_vdev_device *vdev);
 
 /**
  * Pointers to the supported combined mode crypto functions are stored
@@ -773,7 +773,8 @@ armv8_crypto_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
 
 /** Create ARMv8 crypto device */
 static int
-cryptodev_armv8_crypto_create(struct rte_crypto_vdev_init_params *init_params)
+cryptodev_armv8_crypto_create(struct rte_vdev_device *vdev,
+			      struct rte_crypto_vdev_init_params *init_params)
 {
 	struct rte_cryptodev *dev;
 	struct armv8_crypto_private *internals;
@@ -845,14 +846,13 @@ cryptodev_armv8_crypto_create(struct rte_crypto_vdev_init_params *init_params)
 		"driver %s: cryptodev_armv8_crypto_create failed",
 		init_params->name);
 
-	cryptodev_armv8_crypto_uninit(init_params->name);
+	cryptodev_armv8_crypto_uninit(vdev);
 	return -EFAULT;
 }
 
 /** Initialise ARMv8 crypto device */
 static int
-cryptodev_armv8_crypto_init(const char *name,
-		const char *input_args)
+cryptodev_armv8_crypto_init(struct rte_vdev_device *vdev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -860,7 +860,11 @@ cryptodev_armv8_crypto_init(const char *name,
 		rte_socket_id(),
 		{0}
 	};
+	const char *name;
+	const char *input_args;
 
+	name = rte_vdev_device_name(vdev);
+	input_args = rte_vdev_device_args(vdev);
 	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
 	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
@@ -874,13 +878,16 @@ cryptodev_armv8_crypto_init(const char *name,
 	RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
 			init_params.max_nb_sessions);
 
-	return cryptodev_armv8_crypto_create(&init_params);
+	return cryptodev_armv8_crypto_create(vdev, &init_params);
 }
 
 /** Uninitialise ARMv8 crypto device */
 static int
-cryptodev_armv8_crypto_uninit(const char *name)
+cryptodev_armv8_crypto_uninit(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	if (name == NULL)
 		return -EINVAL;
 
diff --git a/drivers/crypto/kasumi/rte_kasumi_pmd.c b/drivers/crypto/kasumi/rte_kasumi_pmd.c
index 55bdb29..42fdd33 100644
--- a/drivers/crypto/kasumi/rte_kasumi_pmd.c
+++ b/drivers/crypto/kasumi/rte_kasumi_pmd.c
@@ -548,10 +548,11 @@ kasumi_pmd_dequeue_burst(void *queue_pair,
 	return nb_dequeued;
 }
 
-static int cryptodev_kasumi_remove(const char *name);
+static int cryptodev_kasumi_remove(struct rte_vdev_device *vdev);
 
 static int
-cryptodev_kasumi_create(struct rte_crypto_vdev_init_params *init_params)
+cryptodev_kasumi_create(struct rte_vdev_device *vdev,
+			struct rte_crypto_vdev_init_params *init_params)
 {
 	struct rte_cryptodev *dev;
 	struct kasumi_private *internals;
@@ -606,13 +607,12 @@ cryptodev_kasumi_create(struct rte_crypto_vdev_init_params *init_params)
 	KASUMI_LOG_ERR("driver %s: cryptodev_kasumi_create failed",
 			init_params->name);
 
-	cryptodev_kasumi_remove(init_params->name);
+	cryptodev_kasumi_remove(vdev);
 	return -EFAULT;
 }
 
 static int
-cryptodev_kasumi_probe(const char *name,
-		const char *input_args)
+cryptodev_kasumi_probe(struct rte_vdev_device *vdev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -620,6 +620,11 @@ cryptodev_kasumi_probe(const char *name,
 		rte_socket_id(),
 		{0}
 	};
+	const char *name;
+	const char *input_args;
+
+	name = rte_vdev_device_name(vdev);
+	input_args = rte_vdev_device_args(vdev);
 
 	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
@@ -633,12 +638,15 @@ cryptodev_kasumi_probe(const char *name,
 	RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
 			init_params.max_nb_sessions);
 
-	return cryptodev_kasumi_create(&init_params);
+	return cryptodev_kasumi_create(vdev, &init_params);
 }
 
 static int
-cryptodev_kasumi_remove(const char *name)
+cryptodev_kasumi_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	if (name == NULL)
 		return -EINVAL;
 
diff --git a/drivers/crypto/openssl/rte_openssl_pmd.c b/drivers/crypto/openssl/rte_openssl_pmd.c
index 5046eac..f3c8f83 100644
--- a/drivers/crypto/openssl/rte_openssl_pmd.c
+++ b/drivers/crypto/openssl/rte_openssl_pmd.c
@@ -44,7 +44,7 @@
 
 #define DES_BLOCK_SIZE 8
 
-static int cryptodev_openssl_remove(const char *name);
+static int cryptodev_openssl_remove(struct rte_vdev_device *vdev);
 
 /*----------------------------------------------------------------------------*/
 
@@ -1264,7 +1264,8 @@ openssl_pmd_dequeue_burst(void *queue_pair, struct rte_crypto_op **ops,
 
 /** Create OPENSSL crypto device */
 static int
-cryptodev_openssl_create(struct rte_crypto_vdev_init_params *init_params)
+cryptodev_openssl_create(struct rte_vdev_device *vdev,
+			 struct rte_crypto_vdev_init_params *init_params)
 {
 	struct rte_cryptodev *dev;
 	struct openssl_private *internals;
@@ -1312,14 +1313,13 @@ cryptodev_openssl_create(struct rte_crypto_vdev_init_params *init_params)
 	OPENSSL_LOG_ERR("driver %s: cryptodev_openssl_create failed",
 			init_params->name);
 
-	cryptodev_openssl_remove(init_params->name);
+	cryptodev_openssl_remove(vdev);
 	return -EFAULT;
 }
 
 /** Initialise OPENSSL crypto device */
 static int
-cryptodev_openssl_probe(const char *name,
-		const char *input_args)
+cryptodev_openssl_probe(struct rte_vdev_device *vdev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -1327,6 +1327,11 @@ cryptodev_openssl_probe(const char *name,
 		rte_socket_id(),
 		{0}
 	};
+	const char *name;
+	const char *input_args;
+
+	name = rte_vdev_device_name(vdev);
+	input_args = rte_vdev_device_args(vdev);
 
 	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
@@ -1340,13 +1345,16 @@ cryptodev_openssl_probe(const char *name,
 	RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
 			init_params.max_nb_sessions);
 
-	return cryptodev_openssl_create(&init_params);
+	return cryptodev_openssl_create(vdev, &init_params);
 }
 
 /** Uninitialise OPENSSL crypto device */
 static int
-cryptodev_openssl_remove(const char *name)
+cryptodev_openssl_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	if (name == NULL)
 		return -EINVAL;
 
diff --git a/drivers/crypto/scheduler/scheduler_pmd.c b/drivers/crypto/scheduler/scheduler_pmd.c
index b189fbd..7d9e376 100644
--- a/drivers/crypto/scheduler/scheduler_pmd.c
+++ b/drivers/crypto/scheduler/scheduler_pmd.c
@@ -193,14 +193,16 @@ cryptodev_scheduler_create(const char *name,
 }
 
 static int
-cryptodev_scheduler_remove(const char *name)
+cryptodev_scheduler_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
 	struct rte_cryptodev *dev;
 	struct scheduler_ctx *sched_ctx;
 
-	if (name == NULL)
+	if (vdev == NULL)
 		return -EINVAL;
 
+	name = rte_vdev_device_name(vdev);
 	dev = rte_cryptodev_pmd_get_named_dev(name);
 	if (dev == NULL)
 		return -EINVAL;
@@ -413,7 +415,7 @@ scheduler_parse_init_params(struct scheduler_init_params *params,
 }
 
 static int
-cryptodev_scheduler_probe(const char *name, const char *input_args)
+cryptodev_scheduler_probe(struct rte_vdev_device *vdev)
 {
 	struct scheduler_init_params init_params = {
 		.def_p = {
@@ -428,9 +430,11 @@ cryptodev_scheduler_probe(const char *name, const char *input_args)
 		.enable_ordering = 0
 	};
 
-	scheduler_parse_init_params(&init_params, input_args);
+	scheduler_parse_init_params(&init_params,
+				    rte_vdev_device_args(vdev));
 
-	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n", name,
+	RTE_LOG(INFO, PMD, "Initialising %s on NUMA node %d\n",
+			rte_vdev_device_name(vdev),
 			init_params.def_p.socket_id);
 	RTE_LOG(INFO, PMD, "  Max number of queue pairs = %d\n",
 			init_params.def_p.max_nb_queue_pairs);
@@ -440,7 +444,8 @@ cryptodev_scheduler_probe(const char *name, const char *input_args)
 		RTE_LOG(INFO, PMD, "  User defined name = %s\n",
 			init_params.def_p.name);
 
-	return cryptodev_scheduler_create(name, &init_params);
+	return cryptodev_scheduler_create(rte_vdev_device_name(vdev),
+					  &init_params);
 }
 
 static struct rte_vdev_driver cryptodev_scheduler_pmd_drv = {
diff --git a/drivers/crypto/snow3g/rte_snow3g_pmd.c b/drivers/crypto/snow3g/rte_snow3g_pmd.c
index 1042b31..a31eaa8 100644
--- a/drivers/crypto/snow3g/rte_snow3g_pmd.c
+++ b/drivers/crypto/snow3g/rte_snow3g_pmd.c
@@ -539,10 +539,11 @@ snow3g_pmd_dequeue_burst(void *queue_pair,
 	return nb_dequeued;
 }
 
-static int cryptodev_snow3g_remove(const char *name);
+static int cryptodev_snow3g_remove(struct rte_vdev_device *vdev);
 
 static int
-cryptodev_snow3g_create(struct rte_crypto_vdev_init_params *init_params)
+cryptodev_snow3g_create(struct rte_vdev_device *vdev,
+			struct rte_crypto_vdev_init_params *init_params)
 {
 	struct rte_cryptodev *dev;
 	struct snow3g_private *internals;
@@ -595,13 +596,12 @@ cryptodev_snow3g_create(struct rte_crypto_vdev_init_params *init_params)
 	SNOW3G_LOG_ERR("driver %s: cryptodev_snow3g_create failed",
 			init_params->name);
 
-	cryptodev_snow3g_remove(init_params->name);
+	cryptodev_snow3g_remove(vdev);
 	return -EFAULT;
 }
 
 static int
-cryptodev_snow3g_probe(const char *name,
-		const char *input_args)
+cryptodev_snow3g_probe(struct rte_vdev_device *vdev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -609,6 +609,11 @@ cryptodev_snow3g_probe(const char *name,
 		rte_socket_id(),
 		{0}
 	};
+	const char *name;
+	const char *input_args;
+
+	name = rte_vdev_device_name(vdev);
+	input_args = rte_vdev_device_args(vdev);
 
 	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
@@ -622,12 +627,15 @@ cryptodev_snow3g_probe(const char *name,
 	RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
 			init_params.max_nb_sessions);
 
-	return cryptodev_snow3g_create(&init_params);
+	return cryptodev_snow3g_create(vdev, &init_params);
 }
 
 static int
-cryptodev_snow3g_remove(const char *name)
+cryptodev_snow3g_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	if (name == NULL)
 		return -EINVAL;
 
diff --git a/drivers/crypto/zuc/rte_zuc_pmd.c b/drivers/crypto/zuc/rte_zuc_pmd.c
index 06ff503..5eec933 100644
--- a/drivers/crypto/zuc/rte_zuc_pmd.c
+++ b/drivers/crypto/zuc/rte_zuc_pmd.c
@@ -439,10 +439,11 @@ zuc_pmd_dequeue_burst(void *queue_pair,
 	return nb_dequeued;
 }
 
-static int cryptodev_zuc_remove(const char *name);
+static int cryptodev_zuc_remove(struct rte_vdev_device *vdev);
 
 static int
-cryptodev_zuc_create(struct rte_crypto_vdev_init_params *init_params)
+cryptodev_zuc_create(struct rte_vdev_device *vdev,
+		     struct rte_crypto_vdev_init_params *init_params)
 {
 	struct rte_cryptodev *dev;
 	struct zuc_private *internals;
@@ -495,13 +496,12 @@ cryptodev_zuc_create(struct rte_crypto_vdev_init_params *init_params)
 	ZUC_LOG_ERR("driver %s: cryptodev_zuc_create failed",
 			init_params->name);
 
-	cryptodev_zuc_remove(init_params->name);
+	cryptodev_zuc_remove(vdev);
 	return -EFAULT;
 }
 
 static int
-cryptodev_zuc_probe(const char *name,
-		const char *input_args)
+cryptodev_zuc_probe(struct rte_vdev_device *vdev)
 {
 	struct rte_crypto_vdev_init_params init_params = {
 		RTE_CRYPTODEV_VDEV_DEFAULT_MAX_NB_QUEUE_PAIRS,
@@ -509,6 +509,11 @@ cryptodev_zuc_probe(const char *name,
 		rte_socket_id(),
 		{0}
 	};
+	const char *name;
+	const char *input_args;
+
+	name = rte_vdev_device_name(vdev);
+	input_args = rte_vdev_device_args(vdev);
 
 	rte_cryptodev_parse_vdev_init_params(&init_params, input_args);
 
@@ -522,12 +527,15 @@ cryptodev_zuc_probe(const char *name,
 	RTE_LOG(INFO, PMD, "  Max number of sessions = %d\n",
 			init_params.max_nb_sessions);
 
-	return cryptodev_zuc_create(&init_params);
+	return cryptodev_zuc_create(vdev, &init_params);
 }
 
 static int
-cryptodev_zuc_remove(const char *name)
+cryptodev_zuc_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	if (name == NULL)
 		return -EINVAL;
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* [PATCH v5 12/12] event: use generic vdev for probe and remove
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (10 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 11/12] crypto: " Gaetan Rivet
@ 2017-04-11 15:44         ` Gaetan Rivet
  2017-04-14 12:21         ` [PATCH v5 00/12] Rework vdev probing to use rte_bus infrastructure Thomas Monjalon
  12 siblings, 0 replies; 91+ messages in thread
From: Gaetan Rivet @ 2017-04-11 15:44 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 drivers/event/octeontx/ssovf_evdev.c       | 11 +++++++----
 drivers/event/skeleton/skeleton_eventdev.c | 10 ++++++++--
 drivers/event/sw/sw_evdev.c                | 11 +++++++++--
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/event/octeontx/ssovf_evdev.c b/drivers/event/octeontx/ssovf_evdev.c
index 6479c80..c80a443 100644
--- a/drivers/event/octeontx/ssovf_evdev.c
+++ b/drivers/event/octeontx/ssovf_evdev.c
@@ -488,17 +488,17 @@ static const struct rte_eventdev_ops ssovf_ops = {
 };
 
 static int
-ssovf_vdev_probe(const char *name, const char *params)
+ssovf_vdev_probe(struct rte_vdev_device *vdev)
 {
 	struct octeontx_ssovf_info oinfo;
 	struct ssovf_mbox_dev_info info;
 	struct ssovf_evdev *edev;
 	struct rte_eventdev *eventdev;
 	static int ssovf_init_once;
+	const char *name;
 	int ret;
 
-	RTE_SET_USED(params);
-
+	name = rte_vdev_device_name(vdev);
 	/* More than one instance is not supported */
 	if (ssovf_init_once) {
 		ssovf_log_err("Request to create >1 %s instance", name);
@@ -563,8 +563,11 @@ ssovf_vdev_probe(const char *name, const char *params)
 }
 
 static int
-ssovf_vdev_remove(const char *name)
+ssovf_vdev_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	ssovf_log_info("Closing %s", name);
 	return rte_event_pmd_vdev_uninit(name);
 }
diff --git a/drivers/event/skeleton/skeleton_eventdev.c b/drivers/event/skeleton/skeleton_eventdev.c
index d2da7d8..800bd76 100644
--- a/drivers/event/skeleton/skeleton_eventdev.c
+++ b/drivers/event/skeleton/skeleton_eventdev.c
@@ -468,16 +468,22 @@ skeleton_eventdev_create(const char *name, int socket_id)
 }
 
 static int
-skeleton_eventdev_probe(const char *name, __rte_unused const char *input_args)
+skeleton_eventdev_probe(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	RTE_LOG(INFO, PMD, "Initializing %s on NUMA node %d\n", name,
 			rte_socket_id());
 	return skeleton_eventdev_create(name, rte_socket_id());
 }
 
 static int
-skeleton_eventdev_remove(const char *name)
+skeleton_eventdev_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	PMD_DRV_LOG(INFO, "Closing %s on NUMA node %d", name, rte_socket_id());
 
 	return rte_event_pmd_vdev_uninit(name);
diff --git a/drivers/event/sw/sw_evdev.c b/drivers/event/sw/sw_evdev.c
index 0caf8ba..a31aaa6 100644
--- a/drivers/event/sw/sw_evdev.c
+++ b/drivers/event/sw/sw_evdev.c
@@ -696,7 +696,7 @@ set_credit_quanta(const char *key __rte_unused, const char *value, void *opaque)
 }
 
 static int
-sw_probe(const char *name, const char *params)
+sw_probe(struct rte_vdev_device *vdev)
 {
 	static const struct rte_eventdev_ops evdev_sw_ops = {
 			.dev_configure = sw_dev_configure,
@@ -727,12 +727,16 @@ sw_probe(const char *name, const char *params)
 		CREDIT_QUANTA_ARG,
 		NULL
 	};
+	const char *name;
+	const char *params;
 	struct rte_eventdev *dev;
 	struct sw_evdev *sw;
 	int socket_id = rte_socket_id();
 	int sched_quanta  = SW_DEFAULT_SCHED_QUANTA;
 	int credit_quanta = SW_DEFAULT_CREDIT_QUANTA;
 
+	name = rte_vdev_device_name(vdev);
+	params = rte_vdev_device_args(vdev);
 	if (params != NULL && params[0] != '\0') {
 		struct rte_kvargs *kvlist = rte_kvargs_parse(params, args);
 
@@ -806,8 +810,11 @@ sw_probe(const char *name, const char *params)
 }
 
 static int
-sw_remove(const char *name)
+sw_remove(struct rte_vdev_device *vdev)
 {
+	const char *name;
+
+	name = rte_vdev_device_name(vdev);
 	if (name == NULL)
 		return -EINVAL;
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 91+ messages in thread

* Re: [PATCH v5 00/12] Rework vdev probing to use rte_bus infrastructure
  2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
                           ` (11 preceding siblings ...)
  2017-04-11 15:44         ` [PATCH v5 12/12] event: " Gaetan Rivet
@ 2017-04-14 12:21         ` Thomas Monjalon
  12 siblings, 0 replies; 91+ messages in thread
From: Thomas Monjalon @ 2017-04-14 12:21 UTC (permalink / raw)
  To: Gaetan Rivet, Jan Blunck; +Cc: dev

2017-04-11 17:44, Gaetan Rivet:
> I have rebased the work done by Jan to introduce the virtual device
> subsystem using the new rte_bus API.
> I also fixed a few outstanding compilation issues, related to PMDs introduced
> during this release.
> Additionally, a few virtual devices had not been ported to use the new
> rte_vdev_device that had been introduced in previous versions.
> 
> This patchset depends on:
> http://dpdk.org/dev/patchwork/patch/20416/
> http://dpdk.org/dev/patchwork/patch/20417/
> 
> Changes since version 4:
>  * Fix compilation issues for several virtual devices
> 
> Gaetan Rivet (3):
>   net/kni: use generic vdev for probe and remove
>   crypto: use generic vdev for probe and remove
>   event: use generic vdev for probe and remove
> 
> Jan Blunck (9):
>   eal: probe new virtual bus after other bus devices
>   eal: move virtual device probing into a bus
>   eal: remove unused rte_eal_dev_init()
>   eal: Refactor vdev driver probe/remove
>   eal: add struct rte_vdev_device
>   eal: add virtual device name helper function
>   eal: add virtual device arguments helper function
>   eal: make virtual bus use rte_vdev_device
>   eal: make virtual driver probe and remove take rte_vdev_device

The 3 additional patches from Gaetan are squashed with the EAL change
to fix compilation of every drivers.

Applied, thanks

The vdev bus still needs to be registered with RTE_REGISTER_BUS.

^ permalink raw reply	[flat|nested] 91+ messages in thread

end of thread, other threads:[~2017-04-14 12:21 UTC | newest]

Thread overview: 91+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-15 10:02 [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Jan Blunck
2017-02-15 10:02 ` [PATCH 1/7] eal: use different constructor priorities for initcalls Jan Blunck
2017-02-15 14:37   ` Shreyansh Jain
2017-02-15 15:05     ` Jan Blunck
2017-02-16  5:59       ` Shreyansh Jain
2017-02-15 10:02 ` [PATCH 2/7] eal: probe legacy PCI devices before other bus devices Jan Blunck
2017-02-15 14:03   ` Shreyansh Jain
2017-02-15 10:02 ` [PATCH 3/7] eal: move virtual device probing into a bus Jan Blunck
2017-02-15 14:11   ` Shreyansh Jain
2017-02-15 14:13     ` Jan Blunck
2017-02-15 14:20       ` Shreyansh Jain
2017-02-15 14:15     ` Shreyansh Jain
2017-02-15 14:22       ` Wiles, Keith
2017-02-15 14:27         ` Shreyansh Jain
2017-02-15 17:25           ` Jerin Jacob
2017-02-15 18:09             ` Wiles, Keith
2017-02-15 20:06               ` Jan Blunck
2017-02-15 21:56                 ` Wiles, Keith
2017-02-15 17:06         ` Jan Blunck
2017-02-15 17:10           ` Wiles, Keith
2017-02-15 17:22             ` Wiles, Keith
2017-02-15 10:02 ` [PATCH 4/7] eal: remove unused rte_eal_dev_init() Jan Blunck
2017-02-15 17:11   ` Ferruh Yigit
2017-02-15 10:02 ` [PATCH 5/7] eal: Refactor vdev driver probe/remove Jan Blunck
2017-02-15 10:02 ` [PATCH 6/7] eal: add struct rte_vdev_device Jan Blunck
2017-02-15 17:11   ` Ferruh Yigit
2017-02-16 15:55     ` Jan Blunck
2017-02-15 10:02 ` [PATCH 7/7] eal: make virtual bus use rte_vdev_device Jan Blunck
2017-02-15 17:11   ` Ferruh Yigit
2017-02-15 17:11 ` [PATCH 0/7] Rework vdev probing to use rte_bus infrastructure Ferruh Yigit
2017-02-20 14:17 ` [PATCH v2 0/8] " Jan Blunck
2017-02-21  6:44   ` Shreyansh Jain
2017-02-25 10:28   ` [PATCH v3 00/10] " Jan Blunck
2017-02-27 13:09     ` Jan Blunck
2017-02-28  8:48       ` Shreyansh Jain
2017-02-28  9:19         ` Jan Blunck
2017-02-28  9:28           ` Shreyansh Jain
2017-03-06 10:56     ` [PATCH v4 " Jan Blunck
2017-03-13 17:55       ` Thomas Monjalon
2017-03-27  7:47         ` Jan Blunck
2017-04-11 15:44       ` [PATCH v5 00/12] " Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 01/12] eal: probe new virtual bus after other bus devices Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 02/12] eal: move virtual device probing into a bus Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 03/12] eal: remove unused rte_eal_dev_init() Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 04/12] eal: Refactor vdev driver probe/remove Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 05/12] eal: add struct rte_vdev_device Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 06/12] eal: add virtual device name helper function Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 07/12] eal: add virtual device arguments " Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 08/12] eal: make virtual bus use rte_vdev_device Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 09/12] eal: make virtual driver probe and remove take rte_vdev_device Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 10/12] net/kni: use generic vdev for probe and remove Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 11/12] crypto: " Gaetan Rivet
2017-04-11 15:44         ` [PATCH v5 12/12] event: " Gaetan Rivet
2017-04-14 12:21         ` [PATCH v5 00/12] Rework vdev probing to use rte_bus infrastructure Thomas Monjalon
2017-03-06 10:56     ` [PATCH v4 01/10] eal: probe legacy PCI devices before other bus devices Jan Blunck
2017-03-06 10:56     ` [PATCH v4 02/10] eal: probe new virtual bus after " Jan Blunck
2017-03-13 17:42       ` Thomas Monjalon
2017-03-06 10:56     ` [PATCH v4 03/10] eal: move virtual device probing into a bus Jan Blunck
2017-03-13 17:44       ` Thomas Monjalon
2017-03-27  7:46         ` Jan Blunck
2017-03-06 10:56     ` [PATCH v4 04/10] eal: remove unused rte_eal_dev_init() Jan Blunck
2017-03-06 10:56     ` [PATCH v4 05/10] eal: Refactor vdev driver probe/remove Jan Blunck
2017-03-06 10:56     ` [PATCH v4 06/10] eal: add struct rte_vdev_device Jan Blunck
2017-03-06 10:56     ` [PATCH v4 07/10] eal: add virtual device name helper function Jan Blunck
2017-03-06 10:56     ` [PATCH v4 08/10] eal: add virtual device arguments " Jan Blunck
2017-03-06 10:56     ` [PATCH v4 09/10] eal: make virtual bus use rte_vdev_device Jan Blunck
2017-03-13 17:51       ` Thomas Monjalon
2017-03-27  7:43         ` Jan Blunck
2017-03-06 10:56     ` [PATCH v4 10/10] eal: make virtual driver probe and remove take rte_vdev_device Jan Blunck
2017-02-25 10:28   ` [PATCH v3 01/10] eal: probe legacy PCI devices before other bus devices Jan Blunck
2017-02-25 10:28   ` [PATCH v3 02/10] eal: probe new virtual bus after " Jan Blunck
2017-02-27  8:59     ` Shreyansh Jain
2017-02-27  9:09       ` Jan Blunck
2017-02-25 10:28   ` [PATCH v3 03/10] eal: move virtual device probing into a bus Jan Blunck
2017-02-25 10:28   ` [PATCH v3 04/10] eal: remove unused rte_eal_dev_init() Jan Blunck
2017-02-25 10:28   ` [PATCH v3 05/10] eal: Refactor vdev driver probe/remove Jan Blunck
2017-02-25 10:28   ` [PATCH v3 06/10] eal: add struct rte_vdev_device Jan Blunck
2017-02-25 10:28   ` [PATCH v3 07/10] eal: add virtual device name helper function Jan Blunck
2017-02-25 10:28   ` [PATCH v3 08/10] eal: add virtual device arguments " Jan Blunck
2017-02-25 10:28   ` [PATCH v3 09/10] eal: make virtual bus use rte_vdev_device Jan Blunck
2017-02-25 10:28   ` [PATCH v3 10/10] eal: make virtual driver probe and remove take rte_vdev_device Jan Blunck
2017-02-20 14:17 ` [PATCH v2 1/8] eal: use different constructor priorities for initcalls Jan Blunck
2017-02-21 12:30   ` Ferruh Yigit
2017-02-20 14:17 ` [PATCH v2 2/8] eal: probe legacy PCI devices before other bus devices Jan Blunck
2017-02-20 14:17 ` [PATCH v2 3/8] eal: move virtual device probing into a bus Jan Blunck
2017-02-20 14:17 ` [PATCH v2 4/8] eal: remove unused rte_eal_dev_init() Jan Blunck
2017-02-20 14:17 ` [PATCH v2 5/8] eal: Refactor vdev driver probe/remove Jan Blunck
2017-02-20 14:17 ` [PATCH v2 6/8] eal: add struct rte_vdev_device Jan Blunck
2017-02-20 14:17 ` [PATCH v2 7/8] eal: add virtual device name helper function Jan Blunck
2017-02-21 12:25   ` Ferruh Yigit
2017-02-20 14:17 ` [PATCH v2 8/8] eal: make virtual bus use rte_vdev_device Jan Blunck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.