[dpdk-dev,v5,3/7] vdev: implement parse bus operation

Message ID e7f6c4cf58c79ab2bbac440349f645976768dc7f.1497999826.git.gaetan.rivet@6wind.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply patch file failure

Commit Message

Gaëtan Rivet June 20, 2017, 11:30 p.m. UTC
  Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 60 +++++++++++++++++----------------
 1 file changed, 31 insertions(+), 29 deletions(-)
  

Comments

Bruce Richardson June 27, 2017, 3:59 p.m. UTC | #1
On Wed, Jun 21, 2017 at 01:30:32AM +0200, Gaetan Rivet wrote:
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/common/eal_common_vdev.c | 60 +++++++++++++++++----------------
>  1 file changed, 31 insertions(+), 29 deletions(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
> index 22e4640..8dd4c88 100644
> --- a/lib/librte_eal/common/eal_common_vdev.c
> +++ b/lib/librte_eal/common/eal_common_vdev.c
> @@ -104,6 +104,29 @@ static char *parse_driver_arg(const char *args)
>  	return str;
>  }
>  
> +/*
> + * typeof(addr): (struct rte_vdev_driver **)
> + */
> +static int
> +vdev_parse(const char *name, void *addr)
> +{
> +	struct rte_vdev_driver **out = addr;
> +	struct rte_vdev_driver *driver = NULL;
> +
> +	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
> +		if (!strncmp(driver->driver.name, name,
> +			     strlen(driver->driver.name)))
> +			break;
> +		if (driver->driver.alias &&
> +		    !strncmp(driver->driver.alias, name,
> +			     strlen(driver->driver.alias)))
> +			break;
> +	}
> +	if (addr != NULL)
> +		*out = driver;
> +	return !driver;
> +}
> +
Prefer == 0 to use of "!" in return value from strncmp. Otherwise:

Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  

Patch

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 22e4640..8dd4c88 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -104,6 +104,29 @@  static char *parse_driver_arg(const char *args)
 	return str;
 }
 
+/*
+ * typeof(addr): (struct rte_vdev_driver **)
+ */
+static int
+vdev_parse(const char *name, void *addr)
+{
+	struct rte_vdev_driver **out = addr;
+	struct rte_vdev_driver *driver = NULL;
+
+	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
+		if (!strncmp(driver->driver.name, name,
+			     strlen(driver->driver.name)))
+			break;
+		if (driver->driver.alias &&
+		    !strncmp(driver->driver.alias, name,
+			     strlen(driver->driver.alias)))
+			break;
+	}
+	if (addr != NULL)
+		*out = driver;
+	return !driver;
+}
+
 static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
@@ -118,36 +141,14 @@  vdev_probe_all_drivers(struct rte_vdev_device *dev)
 	RTE_LOG(DEBUG, EAL, "Search driver %s to probe device %s\n", name,
 		rte_vdev_device_name(dev));
 
-	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))) {
-			dev->device.driver = &driver->driver;
-			ret = driver->probe(dev);
-			if (ret)
-				dev->device.driver = NULL;
-			goto out;
-		}
+	if (vdev_parse(name, &driver)) {
+		ret = -1;
+		goto out;
 	}
-
-	/* 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))) {
-			dev->device.driver = &driver->driver;
-			ret = driver->probe(dev);
-			if (ret)
-				dev->device.driver = NULL;
-			break;
-		}
-	}
-
+	dev->device.driver = &driver->driver;
+	ret = driver->probe(dev);
+	if (ret)
+		dev->device.driver = NULL;
 out:
 	free(drv_name);
 	return ret;
@@ -390,6 +391,7 @@  static struct rte_bus rte_vdev_bus = {
 	.find_device = vdev_find_device,
 	.plug = vdev_plug,
 	.unplug = vdev_unplug,
+	.parse = vdev_parse,
 };
 
 RTE_INIT(rte_vdev_bus_register);