All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gaetan Rivet <gaetan.rivet@6wind.com>
To: dev@dpdk.org
Cc: Jan Blunck <jblunck@infradead.org>
Subject: [PATCH v5 08/12] eal: make virtual bus use rte_vdev_device
Date: Tue, 11 Apr 2017 17:44:12 +0200	[thread overview]
Message-ID: <8bbc807c13ee98855d90317f23fff3fdeda853bc.1491925092.git.gaetan.rivet@6wind.com> (raw)
In-Reply-To: <cover.1491925092.git.gaetan.rivet@6wind.com>
In-Reply-To: <cover.1491925092.git.gaetan.rivet@6wind.com>

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

  parent reply	other threads:[~2017-04-11 15:44 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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         ` Gaetan Rivet [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8bbc807c13ee98855d90317f23fff3fdeda853bc.1491925092.git.gaetan.rivet@6wind.com \
    --to=gaetan.rivet@6wind.com \
    --cc=dev@dpdk.org \
    --cc=jblunck@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.