All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/9] rte_bus parse API
@ 2017-05-24 15:12 Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 1/9] bus: fix bus name registration Gaetan Rivet
                   ` (10 more replies)
  0 siblings, 11 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Following the evolutions announced in [1], here is the first part of
the rte_devargs rework planned for 17.08. The rationale has been partially
explained in [2].

This first part covers the introduction of the necessary facilities in
rte_bus to allow for generic device parsing. This API is implemented for
the virtual and PCI buses. Additionally, this rte_bus evolution is being
used within rte_devargs to characterize a device type by its bus.
This work is the first of two parts to reduce the dependency of the EAL
upon specific bus implementations.

Two public functions are added to rte_bus to help bus recognition:

- rte_bus_from_name
- rte_bus_from_dev

These functions are made public because the bus handle within devargs
becomes the generic device type. Recognizing device types is useful for
buses and PMDs alike.
The modified rte_devargs parsing allows declaring on the EAL command line
explicit buses to handle a device. The format is as follow:

  --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
  -w PCI:00:02.0 -w 00:03.0

This explicit bus designation is optional; no evolution is currently
forced on users to migrate to this new format. The separating character is
arbitrary and can be any character illegal within a bus name.
Subsequently, what is allowed within a bus name has been formally
defined and is now enforced.

[1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
[2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html

This patchset depends on:

bus: attach / detach API
http://dpdk.org/ml/archives/dev/2017-May/066330.html
http://dpdk.org/dev/patchwork/patch/24489/

Gaetan Rivet (9):
  bus: fix bus name registration
  bus: verify bus name on registration
  bus: introduce parsing functionality
  vdev: implement parse bus operation
  pci: implement parse bus operation
  bus: add helper to find bus from a name
  bus: add helper to find a bus from a device name
  vdev: expose bus name
  devargs: parse bus info

 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
 lib/librte_eal/common/eal_common_bus.c          | 47 +++++++++++++++++
 lib/librte_eal/common/eal_common_devargs.c      | 17 +++++-
 lib/librte_eal/common/eal_common_pci.c          | 19 +++++++
 lib/librte_eal/common/eal_common_vdev.c         | 70 ++++++++++++++-----------
 lib/librte_eal/common/eal_private.h             | 16 ++++++
 lib/librte_eal/common/include/rte_bus.h         | 49 ++++++++++++++++-
 lib/librte_eal/common/include/rte_devargs.h     |  3 ++
 lib/librte_eal/common/include/rte_vdev.h        |  2 +
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
 10 files changed, 205 insertions(+), 34 deletions(-)

-- 
2.1.4

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

* [PATCH 1/9] bus: fix bus name registration
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
@ 2017-05-24 15:12 ` Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 2/9] bus: verify bus name on registration Gaetan Rivet
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand, stable

The default bus registration function should not result in buses registering
with double quotes within their names.

Fixes: a97725791eec ("bus: introduce bus abstraction")
Cc: stable@dpdk.org

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 201b0ff..3893ad6 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -222,7 +222,7 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 #define RTE_REGISTER_BUS(nm, bus) \
 static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
 {\
-	(bus).name = RTE_STR(nm);\
+	(bus).name = nm;\
 	rte_bus_register(&bus); \
 }
 
-- 
2.1.4

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

* [PATCH 2/9] bus: verify bus name on registration
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 1/9] bus: fix bus name registration Gaetan Rivet
@ 2017-05-24 15:12 ` Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 3/9] bus: introduce parsing functionality Gaetan Rivet
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Verify that a bus name is legal.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_bus.c | 13 +++++++++++++
 lib/librte_eal/common/eal_private.h    | 16 ++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index b41ea86..8ef859a 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -47,6 +47,8 @@ rte_bus_register(struct rte_bus *bus)
 {
 	RTE_VERIFY(bus);
 	RTE_VERIFY(bus->name && strlen(bus->name));
+	/* Its whole name should be comprised only of valid characters */
+	RTE_VERIFY(rte_bus_name_valid(bus->name) == strlen(bus->name));
 	/* A bus should mandatorily have the scan implemented */
 	RTE_VERIFY(bus->scan);
 	RTE_VERIFY(bus->probe);
@@ -210,3 +212,14 @@ rte_bus_find_device(const struct rte_device *start,
 
 	return dev;
 }
+
+/* Validate a bus name. */
+size_t
+rte_bus_name_valid(const char *name)
+{
+	size_t i = 0;
+
+	while (isalnum(name[i]) || name[i] == '_')
+		i++;
+	return i;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 6cacce0..6d2206a 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -338,4 +338,20 @@ int rte_eal_hugepage_attach(void);
  */
 bool rte_eal_using_phys_addrs(void);
 
+/*
+ * Validate a bus name.
+ *
+ * Counts the number of valid characters in a given name,
+ * starting from the beginning.
+ * A legal bus name is defined by the pattern:
+ *   [:alnum:_]+
+ *
+ * @param name
+ *	bus name
+ *
+ * @return
+ *	number of valid characters in name.
+ */
+size_t rte_bus_name_valid(const char *name);
+
 #endif /* _EAL_PRIVATE_H_ */
-- 
2.1.4

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

* [PATCH 3/9] bus: introduce parsing functionality
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 1/9] bus: fix bus name registration Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 2/9] bus: verify bus name on registration Gaetan Rivet
@ 2017-05-24 15:12 ` Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 4/9] vdev: implement parse bus operation Gaetan Rivet
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

This operation can be used either to validate that a device
representation can be understood by a bus, as well as store the resulting
specialized device representation in any format determined by the bus.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 3893ad6..00fc6d2 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -103,6 +103,26 @@ typedef int (*rte_bus_attach_t)(struct rte_device *dev);
 typedef int (*rte_bus_detach_t)(struct rte_device *dev);
 
 /**
+ * Bus specific parsing function.
+ * Validates the syntax used in the textual representation of a device,
+ * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
+ * device representation to ``addr``.
+ *
+ * @param[in] name
+ *	device textual description
+ *
+ * @param[out] addr
+ *	device information location address, into which parsed info
+ *	should be written. If NULL, nothing should be written, which
+ *	is not an error.
+ *
+ * @return
+ *	0 if parsing was successful.
+ *	!0 for any error.
+ */
+typedef int (*rte_bus_parse_t)(const char *name, void *addr);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -113,6 +133,7 @@ struct rte_bus {
 	rte_bus_find_device_t find_device; /**< Find device on bus */
 	rte_bus_attach_t attach;     /**< Probe single device for drivers */
 	rte_bus_detach_t detach;     /**< Remove single device from driver */
+	rte_bus_parse_t parse;       /**< Parse a device name */
 };
 
 /**
-- 
2.1.4

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

* [PATCH 4/9] vdev: implement parse bus operation
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
                   ` (2 preceding siblings ...)
  2017-05-24 15:12 ` [PATCH 3/9] bus: introduce parsing functionality Gaetan Rivet
@ 2017-05-24 15:12 ` Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 5/9] pci: " Gaetan Rivet
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 62 ++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 2095b01..9c9a1de 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -102,6 +102,31 @@ 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;
+
+	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
+		if (!strncmp(driver->driver.name, name,
+			     strlen(driver->driver.name)))
+			goto ret;
+		if (driver->driver.alias &&
+		    !strncmp(driver->driver.alias, name,
+			     strlen(driver->driver.alias)))
+			goto ret;
+	}
+	driver = NULL;
+ret:
+	if (addr != NULL)
+		*out = driver;
+	return !driver;
+}
+
 static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
@@ -116,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;
-		}
-	}
-
-	/* 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;
-		}
+	if (vdev_parse(name, &driver)) {
+		ret = -1;
+		goto out;
 	}
-
+	dev->device.driver = &driver->driver;
+	ret = driver->probe(dev);
+	if (ret)
+		dev->device.driver = NULL;
 out:
 	free(drv_name);
 	return ret;
@@ -368,6 +371,7 @@ static struct rte_bus rte_vdev_bus = {
 	.find_device = vdev_find_device,
 	/* .attach = NULL, see comment on vdev_detach */
 	.detach = vdev_detach,
+	.parse = vdev_parse,
 };
 
 RTE_INIT(rte_vdev_bus_register);
-- 
2.1.4

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

* [PATCH 5/9] pci: implement parse bus operation
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
                   ` (3 preceding siblings ...)
  2017-05-24 15:12 ` [PATCH 4/9] vdev: implement parse bus operation Gaetan Rivet
@ 2017-05-24 15:12 ` Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 6/9] bus: add helper to find bus from a name Gaetan Rivet
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_pci.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 8428006..0f171ec 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -474,6 +474,24 @@ rte_pci_dump(FILE *f)
 	}
 }
 
+/*
+ * Parse a device entry
+ * typeof(addr): (struct rte_pci_addr *)
+ */
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	int parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr)
+		*out = pci_addr;
+	return parse;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -530,6 +548,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
-- 
2.1.4

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

* [PATCH 6/9] bus: add helper to find bus from a name
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
                   ` (4 preceding siblings ...)
  2017-05-24 15:12 ` [PATCH 5/9] pci: " Gaetan Rivet
@ 2017-05-24 15:12 ` Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 +++++++
 lib/librte_eal/common/eal_common_bus.c          | 19 +++++++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
 4 files changed, 47 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 150b0f7..3517d74 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -197,3 +197,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 8ef859a..7977190 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -223,3 +223,22 @@ rte_bus_name_valid(const char *name)
 		i++;
 	return i;
 }
+
+static int
+bus_cmp_name(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+	size_t i = 0;
+
+	i = rte_bus_name_valid(name);
+	return (!strncmp(bus->name, name, i));
+}
+
+/* find a bus by its name */
+struct rte_bus *
+rte_bus_from_name(const char *str)
+{
+	if (rte_bus_name_valid(str) == 0)
+		return NULL;
+	return rte_bus_find(bus_cmp_name, str);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 00fc6d2..5b87ac4 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -236,6 +236,20 @@ rte_bus_find_device(const struct rte_device *start,
  */
 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 
+/*
+ * Find a bus handle by its name.
+ * Compares the name of each bus up until any invalid character
+ * in the matched pattern.
+ *
+ * @param str
+ *	A null terminated character string.
+ *
+ * @return
+ *	A pointer to a bus if found.
+ *	NULL if no bus matches.
+ */
+struct rte_bus *rte_bus_from_name(const char *str);
+
 /**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index e0a056d..6607acc 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -201,3 +201,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
-- 
2.1.4

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

* [PATCH 7/9] bus: add helper to find a bus from a device name
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
                   ` (5 preceding siblings ...)
  2017-05-24 15:12 ` [PATCH 6/9] bus: add helper to find bus from a name Gaetan Rivet
@ 2017-05-24 15:12 ` Gaetan Rivet
  2017-06-07 17:28   ` Jan Blunck
  2017-05-24 15:12 ` [PATCH 8/9] vdev: expose bus name Gaetan Rivet
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Find which bus should be able to parse this device name into an internal
device representation.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 4 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 3517d74..04fa882 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -202,5 +202,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 7977190..08fff60 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
 		return NULL;
 	return rte_bus_find(bus_cmp_name, str);
 }
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return (bus->parse && !bus->parse(name, NULL));
+}
+
+/* find a bus capable of parsing a device description */
+struct rte_bus *
+rte_bus_from_dev(const char *str)
+{
+	return rte_bus_find(bus_can_parse, str);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 5b87ac4..0b48e66 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -251,6 +251,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 struct rte_bus *rte_bus_from_name(const char *str);
 
 /**
+ * Find a bus capable of identifying a device.
+ *
+ * @param str
+ *   A device identifier (PCI address, virtual PMD name, ...).
+ *
+ * @return
+ *   A valid bus structure if found.
+ *   NULL if no bus is able to parse this device.
+ */
+struct rte_bus *rte_bus_from_dev(const char *str);
+
+/**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
  */
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 6607acc..a5127d6 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -206,5 +206,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
-- 
2.1.4

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

* [PATCH 8/9] vdev: expose bus name
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
                   ` (6 preceding siblings ...)
  2017-05-24 15:12 ` [PATCH 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-05-24 15:12 ` Gaetan Rivet
  2017-05-24 15:12 ` [PATCH 9/9] devargs: parse bus info Gaetan Rivet
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c  | 2 +-
 lib/librte_eal/common/include/rte_vdev.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 9c9a1de..5580295 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -384,6 +384,6 @@ static void rte_vdev_bus_register(void)
 		return;
 
 	registered = 1;
-	rte_vdev_bus.name = RTE_STR(virtual);
+	rte_vdev_bus.name = VIRTUAL_BUS_NAME;
 	rte_bus_register(&rte_vdev_bus);
 }
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index e6b678e..2d02c68 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -41,6 +41,8 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_devargs.h>
 
+#define VIRTUAL_BUS_NAME "virtual"
+
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
-- 
2.1.4

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

* [PATCH 9/9] devargs: parse bus info
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
                   ` (7 preceding siblings ...)
  2017-05-24 15:12 ` [PATCH 8/9] vdev: expose bus name Gaetan Rivet
@ 2017-05-24 15:12 ` Gaetan Rivet
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
  2017-06-07 17:22 ` [PATCH 0/9] " Jan Blunck
  10 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 15:12 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_devargs.c  | 17 ++++++++++++++++-
 lib/librte_eal/common/eal_common_vdev.c     |  6 ++++--
 lib/librte_eal/common/include/rte_devargs.h |  3 +++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index ffa8ad9..8bb72a2 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -83,7 +83,10 @@ int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
+	const char *dev = devargs_str;
+	struct rte_bus *bus;
 	char *buf = NULL;
+	size_t i;
 	int ret;
 
 	/* use malloc instead of rte_malloc as it's called early at init */
@@ -94,7 +97,19 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	memset(devargs, 0, sizeof(*devargs));
 	devargs->type = devtype;
 
-	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
+	bus = rte_bus_from_name(dev);
+	if (bus) {
+		i = rte_bus_name_valid(dev);
+		dev += i + 1;
+	} else {
+		bus = rte_bus_from_dev(dev);
+		if (!bus) {
+			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
+			goto fail;
+		}
+	}
+	devargs->bus = bus;
+	if (rte_eal_parse_devargs_str(dev, &buf, &devargs->args))
 		goto fail;
 
 	switch (devargs->type) {
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 5580295..539835a 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -182,6 +182,7 @@ alloc_devargs(const char *name, const char *args)
 		return NULL;
 
 	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	devargs->bus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	if (args)
 		devargs->args = strdup(args);
 
@@ -294,12 +295,13 @@ vdev_scan(void)
 {
 	struct rte_vdev_device *dev;
 	struct rte_devargs *devargs;
+	struct rte_bus *vbus;
 
 	/* for virtual devices we scan the devargs_list populated via cmdline */
-
+	vbus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (devargs->bus != vbus)
 			continue;
 
 		dev = find_vdev(devargs->virt.drv_name);
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 88120a1..1f50a24 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -51,6 +51,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#include <rte_bus.h>
 
 /**
  * Type of generic device
@@ -89,6 +90,8 @@ struct rte_devargs {
 			char drv_name[32];
 		} virt;
 	};
+	/** Bus handle for the device. */
+	struct rte_bus *bus;
 	/** Arguments string as given by user or "" for no argument. */
 	char *args;
 };
-- 
2.1.4

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

* [PATCH v2 0/9] rte_bus parse API
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
                   ` (8 preceding siblings ...)
  2017-05-24 15:12 ` [PATCH 9/9] devargs: parse bus info Gaetan Rivet
@ 2017-05-24 16:15 ` Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 1/9] bus: fix bus name registration Gaetan Rivet
                     ` (9 more replies)
  2017-06-07 17:22 ` [PATCH 0/9] " Jan Blunck
  10 siblings, 10 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Following the evolutions announced in [1], here is the first part of
the rte_devargs rework planned for 17.08. The rationale has been partially
explained in [2].

This first part covers the introduction of the necessary facilities in
rte_bus to allow for generic device parsing. This API is implemented for
the virtual and PCI buses. Additionally, this rte_bus evolution is being
used within rte_devargs to characterize a device type by its bus.
This work is the first of two parts to reduce the dependency of the EAL
upon specific bus implementations.

Two public functions are added to rte_bus to help bus recognition:

- rte_bus_from_name
- rte_bus_from_dev

These functions are made public because the bus handle within devargs
becomes the generic device type. Recognizing device types is useful for
buses and PMDs alike.
The modified rte_devargs parsing allows declaring on the EAL command line
explicit buses to handle a device. The format is as follow:

  --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
  -w PCI:00:02.0 -w 00:03.0

This explicit bus designation is optional; no evolution is currently
forced on users to migrate to this new format. The separating character is
arbitrary and can be any character illegal within a bus name.
Subsequently, what is allowed within a bus name has been formally
defined and is now enforced.

[1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
[2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html

This patchset depends on:

bus: attach / detach API
http://dpdk.org/ml/archives/dev/2017-May/066330.html
http://dpdk.org/dev/patchwork/patch/24489/

v1 -> v2:

  * fix PCI parse implementation

Gaetan Rivet (9):
  bus: fix bus name registration
  bus: verify bus name on registration
  bus: introduce parsing functionality
  vdev: implement parse bus operation
  pci: implement parse bus operation
  bus: add helper to find bus from a name
  bus: add helper to find a bus from a device name
  vdev: expose bus name
  devargs: parse bus info

 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
 lib/librte_eal/common/eal_common_bus.c          | 47 +++++++++++++++++
 lib/librte_eal/common/eal_common_devargs.c      | 17 +++++-
 lib/librte_eal/common/eal_common_pci.c          | 19 +++++++
 lib/librte_eal/common/eal_common_vdev.c         | 70 ++++++++++++++-----------
 lib/librte_eal/common/eal_private.h             | 16 ++++++
 lib/librte_eal/common/include/rte_bus.h         | 49 ++++++++++++++++-
 lib/librte_eal/common/include/rte_devargs.h     |  3 ++
 lib/librte_eal/common/include/rte_vdev.h        |  2 +
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
 10 files changed, 205 insertions(+), 34 deletions(-)

-- 
2.1.4

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

* [PATCH v2 1/9] bus: fix bus name registration
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
@ 2017-05-24 16:15   ` Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 2/9] bus: verify bus name on registration Gaetan Rivet
                     ` (8 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet, stable

The default bus registration function should not result in buses registering
with double quotes within their names.

Fixes: a97725791eec ("bus: introduce bus abstraction")
Cc: stable@dpdk.org

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 201b0ff..3893ad6 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -222,7 +222,7 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 #define RTE_REGISTER_BUS(nm, bus) \
 static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
 {\
-	(bus).name = RTE_STR(nm);\
+	(bus).name = nm;\
 	rte_bus_register(&bus); \
 }
 
-- 
2.1.4

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

* [PATCH v2 2/9] bus: verify bus name on registration
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 1/9] bus: fix bus name registration Gaetan Rivet
@ 2017-05-24 16:15   ` Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 3/9] bus: introduce parsing functionality Gaetan Rivet
                     ` (7 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Verify that a bus name is legal.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_bus.c | 13 +++++++++++++
 lib/librte_eal/common/eal_private.h    | 16 ++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index b41ea86..8ef859a 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -47,6 +47,8 @@ rte_bus_register(struct rte_bus *bus)
 {
 	RTE_VERIFY(bus);
 	RTE_VERIFY(bus->name && strlen(bus->name));
+	/* Its whole name should be comprised only of valid characters */
+	RTE_VERIFY(rte_bus_name_valid(bus->name) == strlen(bus->name));
 	/* A bus should mandatorily have the scan implemented */
 	RTE_VERIFY(bus->scan);
 	RTE_VERIFY(bus->probe);
@@ -210,3 +212,14 @@ rte_bus_find_device(const struct rte_device *start,
 
 	return dev;
 }
+
+/* Validate a bus name. */
+size_t
+rte_bus_name_valid(const char *name)
+{
+	size_t i = 0;
+
+	while (isalnum(name[i]) || name[i] == '_')
+		i++;
+	return i;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 6cacce0..6d2206a 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -338,4 +338,20 @@ int rte_eal_hugepage_attach(void);
  */
 bool rte_eal_using_phys_addrs(void);
 
+/*
+ * Validate a bus name.
+ *
+ * Counts the number of valid characters in a given name,
+ * starting from the beginning.
+ * A legal bus name is defined by the pattern:
+ *   [:alnum:_]+
+ *
+ * @param name
+ *	bus name
+ *
+ * @return
+ *	number of valid characters in name.
+ */
+size_t rte_bus_name_valid(const char *name);
+
 #endif /* _EAL_PRIVATE_H_ */
-- 
2.1.4

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

* [PATCH v2 3/9] bus: introduce parsing functionality
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 1/9] bus: fix bus name registration Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 2/9] bus: verify bus name on registration Gaetan Rivet
@ 2017-05-24 16:15   ` Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 4/9] vdev: implement parse bus operation Gaetan Rivet
                     ` (6 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

This operation can be used either to validate that a device
representation can be understood by a bus, as well as store the resulting
specialized device representation in any format determined by the bus.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 3893ad6..00fc6d2 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -103,6 +103,26 @@ typedef int (*rte_bus_attach_t)(struct rte_device *dev);
 typedef int (*rte_bus_detach_t)(struct rte_device *dev);
 
 /**
+ * Bus specific parsing function.
+ * Validates the syntax used in the textual representation of a device,
+ * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
+ * device representation to ``addr``.
+ *
+ * @param[in] name
+ *	device textual description
+ *
+ * @param[out] addr
+ *	device information location address, into which parsed info
+ *	should be written. If NULL, nothing should be written, which
+ *	is not an error.
+ *
+ * @return
+ *	0 if parsing was successful.
+ *	!0 for any error.
+ */
+typedef int (*rte_bus_parse_t)(const char *name, void *addr);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -113,6 +133,7 @@ struct rte_bus {
 	rte_bus_find_device_t find_device; /**< Find device on bus */
 	rte_bus_attach_t attach;     /**< Probe single device for drivers */
 	rte_bus_detach_t detach;     /**< Remove single device from driver */
+	rte_bus_parse_t parse;       /**< Parse a device name */
 };
 
 /**
-- 
2.1.4

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

* [PATCH v2 4/9] vdev: implement parse bus operation
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
                     ` (2 preceding siblings ...)
  2017-05-24 16:15   ` [PATCH v2 3/9] bus: introduce parsing functionality Gaetan Rivet
@ 2017-05-24 16:15   ` Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 5/9] pci: " Gaetan Rivet
                     ` (5 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 62 ++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 2095b01..9c9a1de 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -102,6 +102,31 @@ 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;
+
+	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
+		if (!strncmp(driver->driver.name, name,
+			     strlen(driver->driver.name)))
+			goto ret;
+		if (driver->driver.alias &&
+		    !strncmp(driver->driver.alias, name,
+			     strlen(driver->driver.alias)))
+			goto ret;
+	}
+	driver = NULL;
+ret:
+	if (addr != NULL)
+		*out = driver;
+	return !driver;
+}
+
 static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
@@ -116,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;
-		}
-	}
-
-	/* 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;
-		}
+	if (vdev_parse(name, &driver)) {
+		ret = -1;
+		goto out;
 	}
-
+	dev->device.driver = &driver->driver;
+	ret = driver->probe(dev);
+	if (ret)
+		dev->device.driver = NULL;
 out:
 	free(drv_name);
 	return ret;
@@ -368,6 +371,7 @@ static struct rte_bus rte_vdev_bus = {
 	.find_device = vdev_find_device,
 	/* .attach = NULL, see comment on vdev_detach */
 	.detach = vdev_detach,
+	.parse = vdev_parse,
 };
 
 RTE_INIT(rte_vdev_bus_register);
-- 
2.1.4

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

* [PATCH v2 5/9] pci: implement parse bus operation
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
                     ` (3 preceding siblings ...)
  2017-05-24 16:15   ` [PATCH v2 4/9] vdev: implement parse bus operation Gaetan Rivet
@ 2017-05-24 16:15   ` Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 6/9] bus: add helper to find bus from a name Gaetan Rivet
                     ` (4 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_pci.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 8428006..44cfa3c 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -474,6 +474,24 @@ rte_pci_dump(FILE *f)
 	}
 }
 
+/*
+ * Parse a device entry
+ * typeof(addr): (struct rte_pci_addr *)
+ */
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	int parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr)
+		*out = pci_addr;
+	return !parse;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -530,6 +548,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
-- 
2.1.4

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

* [PATCH v2 6/9] bus: add helper to find bus from a name
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
                     ` (4 preceding siblings ...)
  2017-05-24 16:15   ` [PATCH v2 5/9] pci: " Gaetan Rivet
@ 2017-05-24 16:15   ` Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
                     ` (3 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 +++++++
 lib/librte_eal/common/eal_common_bus.c          | 19 +++++++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
 4 files changed, 47 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 150b0f7..3517d74 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -197,3 +197,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 8ef859a..7977190 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -223,3 +223,22 @@ rte_bus_name_valid(const char *name)
 		i++;
 	return i;
 }
+
+static int
+bus_cmp_name(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+	size_t i = 0;
+
+	i = rte_bus_name_valid(name);
+	return (!strncmp(bus->name, name, i));
+}
+
+/* find a bus by its name */
+struct rte_bus *
+rte_bus_from_name(const char *str)
+{
+	if (rte_bus_name_valid(str) == 0)
+		return NULL;
+	return rte_bus_find(bus_cmp_name, str);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 00fc6d2..5b87ac4 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -236,6 +236,20 @@ rte_bus_find_device(const struct rte_device *start,
  */
 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 
+/*
+ * Find a bus handle by its name.
+ * Compares the name of each bus up until any invalid character
+ * in the matched pattern.
+ *
+ * @param str
+ *	A null terminated character string.
+ *
+ * @return
+ *	A pointer to a bus if found.
+ *	NULL if no bus matches.
+ */
+struct rte_bus *rte_bus_from_name(const char *str);
+
 /**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index e0a056d..6607acc 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -201,3 +201,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
-- 
2.1.4

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

* [PATCH v2 7/9] bus: add helper to find a bus from a device name
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
                     ` (5 preceding siblings ...)
  2017-05-24 16:15   ` [PATCH v2 6/9] bus: add helper to find bus from a name Gaetan Rivet
@ 2017-05-24 16:15   ` Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 8/9] vdev: expose bus name Gaetan Rivet
                     ` (2 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Find which bus should be able to parse this device name into an internal
device representation.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 4 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 3517d74..04fa882 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -202,5 +202,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 7977190..08fff60 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
 		return NULL;
 	return rte_bus_find(bus_cmp_name, str);
 }
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return (bus->parse && !bus->parse(name, NULL));
+}
+
+/* find a bus capable of parsing a device description */
+struct rte_bus *
+rte_bus_from_dev(const char *str)
+{
+	return rte_bus_find(bus_can_parse, str);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 5b87ac4..0b48e66 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -251,6 +251,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 struct rte_bus *rte_bus_from_name(const char *str);
 
 /**
+ * Find a bus capable of identifying a device.
+ *
+ * @param str
+ *   A device identifier (PCI address, virtual PMD name, ...).
+ *
+ * @return
+ *   A valid bus structure if found.
+ *   NULL if no bus is able to parse this device.
+ */
+struct rte_bus *rte_bus_from_dev(const char *str);
+
+/**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
  */
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 6607acc..a5127d6 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -206,5 +206,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
-- 
2.1.4

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

* [PATCH v2 8/9] vdev: expose bus name
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
                     ` (6 preceding siblings ...)
  2017-05-24 16:15   ` [PATCH v2 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-05-24 16:15   ` Gaetan Rivet
  2017-05-24 16:15   ` [PATCH v2 9/9] devargs: parse bus info Gaetan Rivet
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c  | 2 +-
 lib/librte_eal/common/include/rte_vdev.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 9c9a1de..5580295 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -384,6 +384,6 @@ static void rte_vdev_bus_register(void)
 		return;
 
 	registered = 1;
-	rte_vdev_bus.name = RTE_STR(virtual);
+	rte_vdev_bus.name = VIRTUAL_BUS_NAME;
 	rte_bus_register(&rte_vdev_bus);
 }
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index e6b678e..2d02c68 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -41,6 +41,8 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_devargs.h>
 
+#define VIRTUAL_BUS_NAME "virtual"
+
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
-- 
2.1.4

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

* [PATCH v2 9/9] devargs: parse bus info
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
                     ` (7 preceding siblings ...)
  2017-05-24 16:15   ` [PATCH v2 8/9] vdev: expose bus name Gaetan Rivet
@ 2017-05-24 16:15   ` Gaetan Rivet
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-05-24 16:15 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_devargs.c  | 17 ++++++++++++++++-
 lib/librte_eal/common/eal_common_vdev.c     |  6 ++++--
 lib/librte_eal/common/include/rte_devargs.h |  3 +++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index ffa8ad9..8bb72a2 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -83,7 +83,10 @@ int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
+	const char *dev = devargs_str;
+	struct rte_bus *bus;
 	char *buf = NULL;
+	size_t i;
 	int ret;
 
 	/* use malloc instead of rte_malloc as it's called early at init */
@@ -94,7 +97,19 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	memset(devargs, 0, sizeof(*devargs));
 	devargs->type = devtype;
 
-	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
+	bus = rte_bus_from_name(dev);
+	if (bus) {
+		i = rte_bus_name_valid(dev);
+		dev += i + 1;
+	} else {
+		bus = rte_bus_from_dev(dev);
+		if (!bus) {
+			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
+			goto fail;
+		}
+	}
+	devargs->bus = bus;
+	if (rte_eal_parse_devargs_str(dev, &buf, &devargs->args))
 		goto fail;
 
 	switch (devargs->type) {
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 5580295..539835a 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -182,6 +182,7 @@ alloc_devargs(const char *name, const char *args)
 		return NULL;
 
 	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	devargs->bus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	if (args)
 		devargs->args = strdup(args);
 
@@ -294,12 +295,13 @@ vdev_scan(void)
 {
 	struct rte_vdev_device *dev;
 	struct rte_devargs *devargs;
+	struct rte_bus *vbus;
 
 	/* for virtual devices we scan the devargs_list populated via cmdline */
-
+	vbus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (devargs->bus != vbus)
 			continue;
 
 		dev = find_vdev(devargs->virt.drv_name);
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 88120a1..1f50a24 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -51,6 +51,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#include <rte_bus.h>
 
 /**
  * Type of generic device
@@ -89,6 +90,8 @@ struct rte_devargs {
 			char drv_name[32];
 		} virt;
 	};
+	/** Bus handle for the device. */
+	struct rte_bus *bus;
 	/** Arguments string as given by user or "" for no argument. */
 	char *args;
 };
-- 
2.1.4

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

* [PATCH v3 0/9] rte_bus parse API
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
                     ` (8 preceding siblings ...)
  2017-05-24 16:15   ` [PATCH v2 9/9] devargs: parse bus info Gaetan Rivet
@ 2017-06-01 10:08   ` Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 1/9] bus: fix bus name registration Gaetan Rivet
                       ` (9 more replies)
  9 siblings, 10 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Following the evolutions announced in [1], here is the first part of
the rte_devargs rework planned for 17.08. The rationale has been partially
explained in [2].

This first part covers the introduction of the necessary facilities in
rte_bus to allow for generic device parsing. This API is implemented for
the virtual and PCI buses. Additionally, this rte_bus evolution is being
used within rte_devargs to characterize a device type by its bus.
This work is the first of two parts to reduce the dependency of the EAL
upon specific bus implementations.

Two public functions are added to rte_bus to help bus recognition:

- rte_bus_from_name
- rte_bus_from_dev

These functions are made public because the bus handle within devargs
becomes the generic device type. Recognizing device types is useful for
buses and PMDs alike.
The modified rte_devargs parsing allows declaring on the EAL command line
explicit buses to handle a device. The format is as follow:

  --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
  -w PCI:00:02.0 -w 00:03.0

This explicit bus designation is optional; no evolution is currently
forced on users to migrate to this new format. The separating character is
arbitrary and can be any character illegal within a bus name.
Subsequently, what is allowed within a bus name has been formally
defined and is now enforced.

[1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
[2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html

This patchset depends on:

bus: attach / detach API
http://dpdk.org/ml/archives/dev/2017-May/066330.html
http://dpdk.org/dev/patchwork/patch/24489/

v1 -> v2:

  * fix PCI parse implementation

v2 --> v3

  * Rebase the series on the new plug / unplug API

Gaetan Rivet (9):
  bus: fix bus name registration
  bus: verify bus name on registration
  bus: introduce parsing functionality
  vdev: implement parse bus operation
  pci: implement parse bus operation
  bus: add helper to find bus from a name
  bus: add helper to find a bus from a device name
  vdev: expose bus name
  devargs: parse bus info

 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
 lib/librte_eal/common/eal_common_bus.c          | 47 +++++++++++++++++
 lib/librte_eal/common/eal_common_devargs.c      | 17 +++++-
 lib/librte_eal/common/eal_common_pci.c          | 19 +++++++
 lib/librte_eal/common/eal_common_vdev.c         | 70 ++++++++++++++-----------
 lib/librte_eal/common/eal_private.h             | 16 ++++++
 lib/librte_eal/common/include/rte_bus.h         | 49 ++++++++++++++++-
 lib/librte_eal/common/include/rte_devargs.h     |  3 ++
 lib/librte_eal/common/include/rte_vdev.h        |  2 +
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
 10 files changed, 205 insertions(+), 34 deletions(-)

-- 
2.1.4

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

* [PATCH v3 1/9] bus: fix bus name registration
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
@ 2017-06-01 10:08     ` Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 2/9] bus: verify bus name on registration Gaetan Rivet
                       ` (8 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet, stable

The default bus registration function should not result in buses registering
with double quotes within their names.

Fixes: a97725791eec ("bus: introduce bus abstraction")
Cc: stable@dpdk.org

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 3c59fc2..3bc4e1c 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -234,7 +234,7 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 #define RTE_REGISTER_BUS(nm, bus) \
 static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
 {\
-	(bus).name = RTE_STR(nm);\
+	(bus).name = nm;\
 	rte_bus_register(&bus); \
 }
 
-- 
2.1.4

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

* [PATCH v3 2/9] bus: verify bus name on registration
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 1/9] bus: fix bus name registration Gaetan Rivet
@ 2017-06-01 10:08     ` Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 3/9] bus: introduce parsing functionality Gaetan Rivet
                       ` (7 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Verify that a bus name is legal.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_bus.c | 13 +++++++++++++
 lib/librte_eal/common/eal_private.h    | 16 ++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 4063897..bc3c6c6 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -47,6 +47,8 @@ rte_bus_register(struct rte_bus *bus)
 {
 	RTE_VERIFY(bus);
 	RTE_VERIFY(bus->name && strlen(bus->name));
+	/* Its whole name should be comprised only of valid characters */
+	RTE_VERIFY(rte_bus_name_valid(bus->name) == strlen(bus->name));
 	/* A bus should mandatorily have the scan implemented */
 	RTE_VERIFY(bus->scan);
 	RTE_VERIFY(bus->probe);
@@ -210,3 +212,14 @@ rte_bus_find_device(const struct rte_device *start,
 	}
 	return dev;
 }
+
+/* Validate a bus name. */
+size_t
+rte_bus_name_valid(const char *name)
+{
+	size_t i = 0;
+
+	while (isalnum(name[i]) || name[i] == '_')
+		i++;
+	return i;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 6cacce0..6d2206a 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -338,4 +338,20 @@ int rte_eal_hugepage_attach(void);
  */
 bool rte_eal_using_phys_addrs(void);
 
+/*
+ * Validate a bus name.
+ *
+ * Counts the number of valid characters in a given name,
+ * starting from the beginning.
+ * A legal bus name is defined by the pattern:
+ *   [:alnum:_]+
+ *
+ * @param name
+ *	bus name
+ *
+ * @return
+ *	number of valid characters in name.
+ */
+size_t rte_bus_name_valid(const char *name);
+
 #endif /* _EAL_PRIVATE_H_ */
-- 
2.1.4

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

* [PATCH v3 3/9] bus: introduce parsing functionality
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 1/9] bus: fix bus name registration Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 2/9] bus: verify bus name on registration Gaetan Rivet
@ 2017-06-01 10:08     ` Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 4/9] vdev: implement parse bus operation Gaetan Rivet
                       ` (6 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

This operation can be used either to validate that a device
representation can be understood by a bus, as well as store the resulting
specialized device representation in any format determined by the bus.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 3bc4e1c..7e73d62 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -106,6 +106,26 @@ typedef int (*rte_bus_plug_t)(struct rte_devargs *da);
 typedef int (*rte_bus_unplug_t)(struct rte_devargs *da);
 
 /**
+ * Bus specific parsing function.
+ * Validates the syntax used in the textual representation of a device,
+ * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
+ * device representation to ``addr``.
+ *
+ * @param[in] name
+ *	device textual description
+ *
+ * @param[out] addr
+ *	device information location address, into which parsed info
+ *	should be written. If NULL, nothing should be written, which
+ *	is not an error.
+ *
+ * @return
+ *	0 if parsing was successful.
+ *	!0 for any error.
+ */
+typedef int (*rte_bus_parse_t)(const char *name, void *addr);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -116,6 +136,7 @@ struct rte_bus {
 	rte_bus_find_device_t find_device; /**< Find device on bus */
 	rte_bus_plug_t plug;         /**< Probe single device for drivers */
 	rte_bus_unplug_t unplug;     /**< Remove single device from driver */
+	rte_bus_parse_t parse;       /**< Parse a device name */
 };
 
 /**
-- 
2.1.4

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

* [PATCH v3 4/9] vdev: implement parse bus operation
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
                       ` (2 preceding siblings ...)
  2017-06-01 10:08     ` [PATCH v3 3/9] bus: introduce parsing functionality Gaetan Rivet
@ 2017-06-01 10:08     ` Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 5/9] pci: " Gaetan Rivet
                       ` (5 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 62 ++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 29 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 67c6fff..131e0c2 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -102,6 +102,31 @@ 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;
+
+	TAILQ_FOREACH(driver, &vdev_driver_list, next) {
+		if (!strncmp(driver->driver.name, name,
+			     strlen(driver->driver.name)))
+			goto ret;
+		if (driver->driver.alias &&
+		    !strncmp(driver->driver.alias, name,
+			     strlen(driver->driver.alias)))
+			goto ret;
+	}
+	driver = NULL;
+ret:
+	if (addr != NULL)
+		*out = driver;
+	return !driver;
+}
+
 static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
@@ -116,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;
-		}
-	}
-
-	/* 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;
-		}
+	if (vdev_parse(name, &driver)) {
+		ret = -1;
+		goto out;
 	}
-
+	dev->device.driver = &driver->driver;
+	ret = driver->probe(dev);
+	if (ret)
+		dev->device.driver = NULL;
 out:
 	free(drv_name);
 	return ret;
@@ -368,6 +371,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);
-- 
2.1.4

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

* [PATCH v3 5/9] pci: implement parse bus operation
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
                       ` (3 preceding siblings ...)
  2017-06-01 10:08     ` [PATCH v3 4/9] vdev: implement parse bus operation Gaetan Rivet
@ 2017-06-01 10:08     ` Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 6/9] bus: add helper to find bus from a name Gaetan Rivet
                       ` (4 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_pci.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 2ab1d65..c698cf8 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -474,6 +474,24 @@ rte_pci_dump(FILE *f)
 	}
 }
 
+/*
+ * Parse a device entry
+ * typeof(addr): (struct rte_pci_addr *)
+ */
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	int parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr)
+		*out = pci_addr;
+	return !parse;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -529,6 +547,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
-- 
2.1.4

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

* [PATCH v3 6/9] bus: add helper to find bus from a name
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
                       ` (4 preceding siblings ...)
  2017-06-01 10:08     ` [PATCH v3 5/9] pci: " Gaetan Rivet
@ 2017-06-01 10:08     ` Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
                       ` (3 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 +++++++
 lib/librte_eal/common/eal_common_bus.c          | 19 +++++++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
 4 files changed, 47 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 150b0f7..3517d74 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -197,3 +197,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index bc3c6c6..063fcea 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -223,3 +223,22 @@ rte_bus_name_valid(const char *name)
 		i++;
 	return i;
 }
+
+static int
+bus_cmp_name(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+	size_t i = 0;
+
+	i = rte_bus_name_valid(name);
+	return (!strncmp(bus->name, name, i));
+}
+
+/* find a bus by its name */
+struct rte_bus *
+rte_bus_from_name(const char *str)
+{
+	if (rte_bus_name_valid(str) == 0)
+		return NULL;
+	return rte_bus_find(bus_cmp_name, str);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 7e73d62..0eacd88 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -248,6 +248,20 @@ rte_bus_find_device(const struct rte_device *start,
  */
 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 
+/*
+ * Find a bus handle by its name.
+ * Compares the name of each bus up until any invalid character
+ * in the matched pattern.
+ *
+ * @param str
+ *	A null terminated character string.
+ *
+ * @return
+ *	A pointer to a bus if found.
+ *	NULL if no bus matches.
+ */
+struct rte_bus *rte_bus_from_name(const char *str);
+
 /**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index e0a056d..6607acc 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -201,3 +201,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
-- 
2.1.4

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

* [PATCH v3 7/9] bus: add helper to find a bus from a device name
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
                       ` (5 preceding siblings ...)
  2017-06-01 10:08     ` [PATCH v3 6/9] bus: add helper to find bus from a name Gaetan Rivet
@ 2017-06-01 10:08     ` Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 8/9] vdev: expose bus name Gaetan Rivet
                       ` (2 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Find which bus should be able to parse this device name into an internal
device representation.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 4 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 3517d74..04fa882 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -202,5 +202,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 063fcea..e9e4e1b 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
 		return NULL;
 	return rte_bus_find(bus_cmp_name, str);
 }
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return (bus->parse && !bus->parse(name, NULL));
+}
+
+/* find a bus capable of parsing a device description */
+struct rte_bus *
+rte_bus_from_dev(const char *str)
+{
+	return rte_bus_find(bus_can_parse, str);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 0eacd88..4489d1d 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -263,6 +263,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 struct rte_bus *rte_bus_from_name(const char *str);
 
 /**
+ * Find a bus capable of identifying a device.
+ *
+ * @param str
+ *   A device identifier (PCI address, virtual PMD name, ...).
+ *
+ * @return
+ *   A valid bus structure if found.
+ *   NULL if no bus is able to parse this device.
+ */
+struct rte_bus *rte_bus_from_dev(const char *str);
+
+/**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
  */
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 6607acc..a5127d6 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -206,5 +206,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
-- 
2.1.4

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

* [PATCH v3 8/9] vdev: expose bus name
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
                       ` (6 preceding siblings ...)
  2017-06-01 10:08     ` [PATCH v3 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-06-01 10:08     ` Gaetan Rivet
  2017-06-01 10:08     ` [PATCH v3 9/9] devargs: parse bus info Gaetan Rivet
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c  | 2 +-
 lib/librte_eal/common/include/rte_vdev.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 131e0c2..452f60f 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -384,6 +384,6 @@ static void rte_vdev_bus_register(void)
 		return;
 
 	registered = 1;
-	rte_vdev_bus.name = RTE_STR(virtual);
+	rte_vdev_bus.name = VIRTUAL_BUS_NAME;
 	rte_bus_register(&rte_vdev_bus);
 }
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index e6b678e..2d02c68 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -41,6 +41,8 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_devargs.h>
 
+#define VIRTUAL_BUS_NAME "virtual"
+
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
-- 
2.1.4

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

* [PATCH v3 9/9] devargs: parse bus info
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
                       ` (7 preceding siblings ...)
  2017-06-01 10:08     ` [PATCH v3 8/9] vdev: expose bus name Gaetan Rivet
@ 2017-06-01 10:08     ` Gaetan Rivet
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-01 10:08 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_devargs.c  | 17 ++++++++++++++++-
 lib/librte_eal/common/eal_common_vdev.c     |  6 ++++--
 lib/librte_eal/common/include/rte_devargs.h |  3 +++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index ffa8ad9..8bb72a2 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -83,7 +83,10 @@ int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
+	const char *dev = devargs_str;
+	struct rte_bus *bus;
 	char *buf = NULL;
+	size_t i;
 	int ret;
 
 	/* use malloc instead of rte_malloc as it's called early at init */
@@ -94,7 +97,19 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	memset(devargs, 0, sizeof(*devargs));
 	devargs->type = devtype;
 
-	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
+	bus = rte_bus_from_name(dev);
+	if (bus) {
+		i = rte_bus_name_valid(dev);
+		dev += i + 1;
+	} else {
+		bus = rte_bus_from_dev(dev);
+		if (!bus) {
+			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
+			goto fail;
+		}
+	}
+	devargs->bus = bus;
+	if (rte_eal_parse_devargs_str(dev, &buf, &devargs->args))
 		goto fail;
 
 	switch (devargs->type) {
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 452f60f..ea58706 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -182,6 +182,7 @@ alloc_devargs(const char *name, const char *args)
 		return NULL;
 
 	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	devargs->bus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	if (args)
 		devargs->args = strdup(args);
 
@@ -294,12 +295,13 @@ vdev_scan(void)
 {
 	struct rte_vdev_device *dev;
 	struct rte_devargs *devargs;
+	struct rte_bus *vbus;
 
 	/* for virtual devices we scan the devargs_list populated via cmdline */
-
+	vbus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (devargs->bus != vbus)
 			continue;
 
 		dev = find_vdev(devargs->virt.drv_name);
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 88120a1..1f50a24 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -51,6 +51,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#include <rte_bus.h>
 
 /**
  * Type of generic device
@@ -89,6 +90,8 @@ struct rte_devargs {
 			char drv_name[32];
 		} virt;
 	};
+	/** Bus handle for the device. */
+	struct rte_bus *bus;
 	/** Arguments string as given by user or "" for no argument. */
 	char *args;
 };
-- 
2.1.4

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

* Re: [PATCH 0/9] rte_bus parse API
  2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
                   ` (9 preceding siblings ...)
  2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
@ 2017-06-07 17:22 ` Jan Blunck
  2017-06-07 19:55   ` Gaëtan Rivet
  10 siblings, 1 reply; 123+ messages in thread
From: Jan Blunck @ 2017-06-07 17:22 UTC (permalink / raw)
  To: Gaetan Rivet
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> Following the evolutions announced in [1], here is the first part of
> the rte_devargs rework planned for 17.08. The rationale has been partially
> explained in [2].
>
> This first part covers the introduction of the necessary facilities in
> rte_bus to allow for generic device parsing. This API is implemented for
> the virtual and PCI buses. Additionally, this rte_bus evolution is being
> used within rte_devargs to characterize a device type by its bus.
> This work is the first of two parts to reduce the dependency of the EAL
> upon specific bus implementations.
>
> Two public functions are added to rte_bus to help bus recognition:
>
> - rte_bus_from_name
> - rte_bus_from_dev
>
> These functions are made public because the bus handle within devargs
> becomes the generic device type. Recognizing device types is useful for
> buses and PMDs alike.
> The modified rte_devargs parsing allows declaring on the EAL command line
> explicit buses to handle a device. The format is as follow:
>
>   --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
>   -w PCI:00:02.0 -w 00:03.0
>

I don't see the point of doing this. The --vdev parameter implicitly
defines the bus by its name (--vdev aka virtual device).

Why don't you add a commandline "--dev" parameter that supports a
"bus=" devarg? You would need to clarify what that means for other
busses than the virtual one. Is the bus switched into whitelist mode
by that?


> This explicit bus designation is optional; no evolution is currently
> forced on users to migrate to this new format. The separating character is
> arbitrary and can be any character illegal within a bus name.
> Subsequently, what is allowed within a bus name has been formally
> defined and is now enforced.
>
> [1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
> [2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html
>
> This patchset depends on:
>
> bus: attach / detach API
> http://dpdk.org/ml/archives/dev/2017-May/066330.html
> http://dpdk.org/dev/patchwork/patch/24489/
>
> Gaetan Rivet (9):
>   bus: fix bus name registration
>   bus: verify bus name on registration
>   bus: introduce parsing functionality
>   vdev: implement parse bus operation
>   pci: implement parse bus operation
>   bus: add helper to find bus from a name
>   bus: add helper to find a bus from a device name
>   vdev: expose bus name
>   devargs: parse bus info
>
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
>  lib/librte_eal/common/eal_common_bus.c          | 47 +++++++++++++++++
>  lib/librte_eal/common/eal_common_devargs.c      | 17 +++++-
>  lib/librte_eal/common/eal_common_pci.c          | 19 +++++++
>  lib/librte_eal/common/eal_common_vdev.c         | 70 ++++++++++++++-----------
>  lib/librte_eal/common/eal_private.h             | 16 ++++++
>  lib/librte_eal/common/include/rte_bus.h         | 49 ++++++++++++++++-
>  lib/librte_eal/common/include/rte_devargs.h     |  3 ++
>  lib/librte_eal/common/include/rte_vdev.h        |  2 +
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
>  10 files changed, 205 insertions(+), 34 deletions(-)
>
> --
> 2.1.4
>

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

* Re: [PATCH 7/9] bus: add helper to find a bus from a device name
  2017-05-24 15:12 ` [PATCH 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-06-07 17:28   ` Jan Blunck
  2017-06-07 20:03     ` Gaëtan Rivet
  0 siblings, 1 reply; 123+ messages in thread
From: Jan Blunck @ 2017-06-07 17:28 UTC (permalink / raw)
  To: Gaetan Rivet
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> Find which bus should be able to parse this device name into an internal
> device representation.
>

No, please don't add this. One should know to what bus a device
belongs to before plugging it. Artificially encoding the parent bus
into the device name is not the right thing to do. Please keep those
things separate.

> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
>  lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
>  lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
>  4 files changed, 29 insertions(+)
>
> diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> index 3517d74..04fa882 100644
> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> @@ -202,5 +202,6 @@ DPDK_17.08 {
>         global:
>
>         rte_bus_from_name;
> +       rte_bus_from_dev;
>
>  } DPDK_17.05;
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> index 7977190..08fff60 100644
> --- a/lib/librte_eal/common/eal_common_bus.c
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
>                 return NULL;
>         return rte_bus_find(bus_cmp_name, str);
>  }
> +
> +static int
> +bus_can_parse(const struct rte_bus *bus, const void *_name)
> +{
> +       const char *name = _name;
> +
> +       return (bus->parse && !bus->parse(name, NULL));
> +}
> +
> +/* find a bus capable of parsing a device description */
> +struct rte_bus *
> +rte_bus_from_dev(const char *str)
> +{
> +       return rte_bus_find(bus_can_parse, str);
> +}
> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> index 5b87ac4..0b48e66 100644
> --- a/lib/librte_eal/common/include/rte_bus.h
> +++ b/lib/librte_eal/common/include/rte_bus.h
> @@ -251,6 +251,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
>  struct rte_bus *rte_bus_from_name(const char *str);
>
>  /**
> + * Find a bus capable of identifying a device.
> + *
> + * @param str
> + *   A device identifier (PCI address, virtual PMD name, ...).
> + *
> + * @return
> + *   A valid bus structure if found.
> + *   NULL if no bus is able to parse this device.
> + */
> +struct rte_bus *rte_bus_from_dev(const char *str);
> +
> +/**
>   * Helper for Bus registration.
>   * The constructor has higher priority than PMD constructors.
>   */
> diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> index 6607acc..a5127d6 100644
> --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> @@ -206,5 +206,6 @@ DPDK_17.08 {
>         global:
>
>         rte_bus_from_name;
> +       rte_bus_from_dev;
>
>  } DPDK_17.05;
> --
> 2.1.4
>

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

* Re: [PATCH 0/9] rte_bus parse API
  2017-06-07 17:22 ` [PATCH 0/9] " Jan Blunck
@ 2017-06-07 19:55   ` Gaëtan Rivet
  2017-06-08 11:38     ` Jan Blunck
  0 siblings, 1 reply; 123+ messages in thread
From: Gaëtan Rivet @ 2017-06-07 19:55 UTC (permalink / raw)
  To: Jan Blunck
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Wed, Jun 07, 2017 at 07:22:05PM +0200, Jan Blunck wrote:
> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> > Following the evolutions announced in [1], here is the first part of
> > the rte_devargs rework planned for 17.08. The rationale has been partially
> > explained in [2].
> >
> > This first part covers the introduction of the necessary facilities in
> > rte_bus to allow for generic device parsing. This API is implemented for
> > the virtual and PCI buses. Additionally, this rte_bus evolution is being
> > used within rte_devargs to characterize a device type by its bus.
> > This work is the first of two parts to reduce the dependency of the EAL
> > upon specific bus implementations.
> >
> > Two public functions are added to rte_bus to help bus recognition:
> >
> > - rte_bus_from_name
> > - rte_bus_from_dev
> >
> > These functions are made public because the bus handle within devargs
> > becomes the generic device type. Recognizing device types is useful for
> > buses and PMDs alike.
> > The modified rte_devargs parsing allows declaring on the EAL command line
> > explicit buses to handle a device. The format is as follow:
> >
> >   --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
> >   -w PCI:00:02.0 -w 00:03.0
> >
> 
> I don't see the point of doing this. The --vdev parameter implicitly
> defines the bus by its name (--vdev aka virtual device).
> 
> Why don't you add a commandline "--dev" parameter that supports a
> "bus=" devarg? You would need to clarify what that means for other
> busses than the virtual one. Is the bus switched into whitelist mode
> by that?
> 
> 

We cannot keep the current -w, -b and --vdev parameter. Those are
processed by the EAL, and use specifics from the virtual and PCI buses.

The rte_devargs rework has been to make the same functionality generic
to all rte_bus. As seen quickly in [2], rte_devargs has two functions:

* Validating a device declaration
* Keeping the relevant device info until it has been processed.

Both functionalities have been genericized. This results in all parameters
being able to be used with all types of devices. This is inherent to the
EAL becoming bus-agnostic.

Now, it is absolutely possible to rename for example -w as --dev, as it
is the expected behavior from users. This however should be discussed by
the community, last time I talked about the possibility of switching the
default of the PCI bus to whitelist mode the community wasn't all that
enthused by the prospect.

Finally, I do not like the idea of a special devarg just for declaring
explicitly buses for devices. The bus is not a device modifier, nor is
it a driver parameter. The bus is a way to define the location of the
device on the system. Adding a special "bus=" devargs means having some
preprocessing done on devargs upon rte_devargs allocation. This was
already abused by the bonding PMD with the driver= parameter. I do not
support this and did not want to repeat it. Passing down the device args
is a simple process and we should keep it as simple as possible.

I know you do not like having the bus as part of the device name.
As a compromise, I made the current system flexible and allowed the legacy
device definition to be kept.

However with a purely generic process, it is necessary to at least offer
the possibility to the user to explicitly use a bus, as nothing prevents
conflicting device names from existing.

> > [2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html

> > This explicit bus designation is optional; no evolution is currently
> > forced on users to migrate to this new format. The separating character is
> > arbitrary and can be any character illegal within a bus name.
> > Subsequently, what is allowed within a bus name has been formally
> > defined and is now enforced.
> >
> > [1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
> > [2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html
> >
> > This patchset depends on:
> >
> > bus: attach / detach API
> > http://dpdk.org/ml/archives/dev/2017-May/066330.html
> > http://dpdk.org/dev/patchwork/patch/24489/
> >
> > Gaetan Rivet (9):
> >   bus: fix bus name registration
> >   bus: verify bus name on registration
> >   bus: introduce parsing functionality
> >   vdev: implement parse bus operation
> >   pci: implement parse bus operation
> >   bus: add helper to find bus from a name
> >   bus: add helper to find a bus from a device name
> >   vdev: expose bus name
> >   devargs: parse bus info
> >
> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
> >  lib/librte_eal/common/eal_common_bus.c          | 47 +++++++++++++++++
> >  lib/librte_eal/common/eal_common_devargs.c      | 17 +++++-
> >  lib/librte_eal/common/eal_common_pci.c          | 19 +++++++
> >  lib/librte_eal/common/eal_common_vdev.c         | 70 ++++++++++++++-----------
> >  lib/librte_eal/common/eal_private.h             | 16 ++++++
> >  lib/librte_eal/common/include/rte_bus.h         | 49 ++++++++++++++++-
> >  lib/librte_eal/common/include/rte_devargs.h     |  3 ++
> >  lib/librte_eal/common/include/rte_vdev.h        |  2 +
> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
> >  10 files changed, 205 insertions(+), 34 deletions(-)
> >
> > --
> > 2.1.4
> >

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH 7/9] bus: add helper to find a bus from a device name
  2017-06-07 17:28   ` Jan Blunck
@ 2017-06-07 20:03     ` Gaëtan Rivet
  2017-06-08 10:45       ` Jan Blunck
  0 siblings, 1 reply; 123+ messages in thread
From: Gaëtan Rivet @ 2017-06-07 20:03 UTC (permalink / raw)
  To: Jan Blunck
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Wed, Jun 07, 2017 at 07:28:07PM +0200, Jan Blunck wrote:
> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> > Find which bus should be able to parse this device name into an internal
> > device representation.
> >
> 
> No, please don't add this. One should know to what bus a device
> belongs to before plugging it. Artificially encoding the parent bus
> into the device name is not the right thing to do. Please keep those
> things separate.
> 

The EAL has no way to know this currently. As you noted, it has to know
onto which bus a device belongs before plugging it.

> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > ---
> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
> >  lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
> >  lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
> >  4 files changed, 29 insertions(+)
> >
> > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> > index 3517d74..04fa882 100644
> > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> > @@ -202,5 +202,6 @@ DPDK_17.08 {
> >         global:
> >
> >         rte_bus_from_name;
> > +       rte_bus_from_dev;
> >
> >  } DPDK_17.05;
> > diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> > index 7977190..08fff60 100644
> > --- a/lib/librte_eal/common/eal_common_bus.c
> > +++ b/lib/librte_eal/common/eal_common_bus.c
> > @@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
> >                 return NULL;
> >         return rte_bus_find(bus_cmp_name, str);
> >  }
> > +
> > +static int
> > +bus_can_parse(const struct rte_bus *bus, const void *_name)
> > +{
> > +       const char *name = _name;
> > +
> > +       return (bus->parse && !bus->parse(name, NULL));
> > +}
> > +
> > +/* find a bus capable of parsing a device description */
> > +struct rte_bus *
> > +rte_bus_from_dev(const char *str)
> > +{
> > +       return rte_bus_find(bus_can_parse, str);
> > +}
> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> > index 5b87ac4..0b48e66 100644
> > --- a/lib/librte_eal/common/include/rte_bus.h
> > +++ b/lib/librte_eal/common/include/rte_bus.h
> > @@ -251,6 +251,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
> >  struct rte_bus *rte_bus_from_name(const char *str);
> >
> >  /**
> > + * Find a bus capable of identifying a device.
> > + *
> > + * @param str
> > + *   A device identifier (PCI address, virtual PMD name, ...).
> > + *
> > + * @return
> > + *   A valid bus structure if found.
> > + *   NULL if no bus is able to parse this device.
> > + */
> > +struct rte_bus *rte_bus_from_dev(const char *str);
> > +
> > +/**
> >   * Helper for Bus registration.
> >   * The constructor has higher priority than PMD constructors.
> >   */
> > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> > index 6607acc..a5127d6 100644
> > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> > @@ -206,5 +206,6 @@ DPDK_17.08 {
> >         global:
> >
> >         rte_bus_from_name;
> > +       rte_bus_from_dev;
> >
> >  } DPDK_17.05;
> > --
> > 2.1.4
> >

-- 
Gaëtan Rivet
6WIND

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

* [PATCH v4 0/9] rte_bus parse API
  2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
                       ` (8 preceding siblings ...)
  2017-06-01 10:08     ` [PATCH v3 9/9] devargs: parse bus info Gaetan Rivet
@ 2017-06-07 23:56     ` Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 1/9] bus: fix bus name registration Gaetan Rivet
                         ` (9 more replies)
  9 siblings, 10 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Following the evolutions announced in [1], here is the first part of
the rte_devargs rework planned for 17.08. The rationale has been partially
explained in [2].

This first part covers the introduction of the necessary facilities in
rte_bus to allow for generic device parsing. This API is implemented for
the virtual and PCI buses. Additionally, this rte_bus evolution is being
used within rte_devargs to characterize a device type by its bus.
This work is the first of two parts to reduce the dependency of the EAL
upon specific bus implementations.

Two public functions are added to rte_bus to help bus recognition:

- rte_bus_from_name
- rte_bus_from_dev

These functions are made public because the bus handle within devargs
becomes the generic device type. Recognizing device types is useful for
buses and PMDs alike.
The modified rte_devargs parsing allows declaring on the EAL command line
explicit buses to handle a device. The format is as follow:

  --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
  -w PCI:00:02.0 -w 00:03.0

This explicit bus designation is optional; no evolution is currently
forced on users to migrate to this new format. The separating character is
arbitrary and can be any character illegal within a bus name.
Subsequently, what is allowed within a bus name has been formally
defined and is now enforced.

[1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
[2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html

This patchset depends on:

bus: attach / detach API
http://dpdk.org/ml/archives/dev/2017-May/066330.html
http://dpdk.org/dev/patchwork/patch/24489/

v1 -> v2:

  * fix PCI parse implementation

v2 --> v3:

  * Rebase the series on the new plug / unplug API

v3 --> v4:

  * Several bug fixes, commit log rewrite.
  * Follow the changes to the plug / unplug API.

Gaetan Rivet (9):
  bus: fix bus name registration
  bus: verify bus name on registration
  bus: introduce parsing functionality
  vdev: implement parse bus operation
  pci: implement parse bus operation
  bus: add helper to find a bus from a bus name
  bus: add helper to find a bus from a device name
  vdev: expose bus name
  devargs: parse bus info

 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
 lib/librte_eal/common/eal_common_bus.c          | 47 +++++++++++++++++
 lib/librte_eal/common/eal_common_devargs.c      | 17 ++++++-
 lib/librte_eal/common/eal_common_pci.c          | 19 +++++++
 lib/librte_eal/common/eal_common_vdev.c         | 68 +++++++++++++------------
 lib/librte_eal/common/eal_private.h             | 16 ++++++
 lib/librte_eal/common/include/rte_bus.h         | 49 +++++++++++++++++-
 lib/librte_eal/common/include/rte_devargs.h     |  3 ++
 lib/librte_eal/common/include/rte_vdev.h        |  2 +
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
 10 files changed, 203 insertions(+), 34 deletions(-)

-- 
2.1.4

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

* [PATCH v4 1/9] bus: fix bus name registration
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
@ 2017-06-07 23:56       ` Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 2/9] bus: verify bus name on registration Gaetan Rivet
                         ` (8 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet, stable

The default bus registration function should not result in buses
registering with double quotes within their names.

Fixes: a97725791eec ("bus: introduce bus abstraction")
Cc: stable@dpdk.org

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index cb44e46..7264e3f 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -247,7 +247,7 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 #define RTE_REGISTER_BUS(nm, bus) \
 static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
 {\
-	(bus).name = RTE_STR(nm);\
+	(bus).name = nm;\
 	rte_bus_register(&bus); \
 }
 
-- 
2.1.4

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

* [PATCH v4 2/9] bus: verify bus name on registration
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 1/9] bus: fix bus name registration Gaetan Rivet
@ 2017-06-07 23:56       ` Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 3/9] bus: introduce parsing functionality Gaetan Rivet
                         ` (7 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Verify that a bus name is legal.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_bus.c | 13 +++++++++++++
 lib/librte_eal/common/eal_private.h    | 16 ++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 381a0b6..d9d8f62 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -47,6 +47,8 @@ rte_bus_register(struct rte_bus *bus)
 {
 	RTE_VERIFY(bus);
 	RTE_VERIFY(bus->name && strlen(bus->name));
+	/* Its whole name should be comprised only of valid characters */
+	RTE_VERIFY(rte_bus_name_valid(bus->name) == strlen(bus->name));
 	/* A bus should mandatorily have the scan implemented */
 	RTE_VERIFY(bus->scan);
 	RTE_VERIFY(bus->probe);
@@ -207,3 +209,14 @@ rte_bus_find_device(const struct rte_device *start,
 	}
 	return dev;
 }
+
+/* Validate a bus name. */
+size_t
+rte_bus_name_valid(const char *name)
+{
+	size_t i = 0;
+
+	while (isalnum(name[i]) || name[i] == '_')
+		i++;
+	return i;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 6cacce0..6d2206a 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -338,4 +338,20 @@ int rte_eal_hugepage_attach(void);
  */
 bool rte_eal_using_phys_addrs(void);
 
+/*
+ * Validate a bus name.
+ *
+ * Counts the number of valid characters in a given name,
+ * starting from the beginning.
+ * A legal bus name is defined by the pattern:
+ *   [:alnum:_]+
+ *
+ * @param name
+ *	bus name
+ *
+ * @return
+ *	number of valid characters in name.
+ */
+size_t rte_bus_name_valid(const char *name);
+
 #endif /* _EAL_PRIVATE_H_ */
-- 
2.1.4

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

* [PATCH v4 3/9] bus: introduce parsing functionality
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 1/9] bus: fix bus name registration Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 2/9] bus: verify bus name on registration Gaetan Rivet
@ 2017-06-07 23:56       ` Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 4/9] vdev: implement parse bus operation Gaetan Rivet
                         ` (6 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

This operation can be used either to validate that a device
representation can be understood by a bus, as well as store the resulting
specialized device representation in any format determined by the bus.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 7264e3f..9b50451 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -117,6 +117,26 @@ typedef struct rte_device * (*rte_bus_plug_t)(struct rte_devargs *da);
 typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
 
 /**
+ * Bus specific parsing function.
+ * Validates the syntax used in the textual representation of a device,
+ * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
+ * device representation to ``addr``.
+ *
+ * @param[in] name
+ *	device textual description
+ *
+ * @param[out] addr
+ *	device information location address, into which parsed info
+ *	should be written. If NULL, nothing should be written, which
+ *	is not an error.
+ *
+ * @return
+ *	0 if parsing was successful.
+ *	!0 for any error.
+ */
+typedef int (*rte_bus_parse_t)(const char *name, void *addr);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -127,6 +147,7 @@ struct rte_bus {
 	rte_bus_find_device_t find_device; /**< Find device on bus */
 	rte_bus_plug_t plug;         /**< Probe single device for drivers */
 	rte_bus_unplug_t unplug;     /**< Remove single device from driver */
+	rte_bus_parse_t parse;       /**< Parse a device name */
 };
 
 /**
-- 
2.1.4

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

* [PATCH v4 4/9] vdev: implement parse bus operation
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
                         ` (2 preceding siblings ...)
  2017-06-07 23:56       ` [PATCH v4 3/9] bus: introduce parsing functionality Gaetan Rivet
@ 2017-06-07 23:56       ` Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 5/9] pci: " Gaetan Rivet
                         ` (5 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

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;
+}
+
 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);
-- 
2.1.4

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

* [PATCH v4 5/9] pci: implement parse bus operation
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
                         ` (3 preceding siblings ...)
  2017-06-07 23:56       ` [PATCH v4 4/9] vdev: implement parse bus operation Gaetan Rivet
@ 2017-06-07 23:56       ` Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 6/9] bus: add helper to find a bus from a bus name Gaetan Rivet
                         ` (4 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_pci.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 5a8478c..3075eee 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -445,6 +445,24 @@ rte_pci_dump(FILE *f)
 	}
 }
 
+/*
+ * Parse a device entry
+ * typeof(addr): (struct rte_pci_addr *)
+ */
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	int parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr)
+		*out = pci_addr;
+	return !parse;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -500,6 +518,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
-- 
2.1.4

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

* [PATCH v4 6/9] bus: add helper to find a bus from a bus name
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
                         ` (4 preceding siblings ...)
  2017-06-07 23:56       ` [PATCH v4 5/9] pci: " Gaetan Rivet
@ 2017-06-07 23:56       ` Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
                         ` (3 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 +++++++
 lib/librte_eal/common/eal_common_bus.c          | 19 +++++++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
 4 files changed, 47 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 150b0f7..3517d74 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -197,3 +197,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index d9d8f62..2b41ba2 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -220,3 +220,22 @@ rte_bus_name_valid(const char *name)
 		i++;
 	return i;
 }
+
+static int
+bus_cmp_name(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+	size_t i = 0;
+
+	i = rte_bus_name_valid(name);
+	return strncmp(bus->name, name, i);
+}
+
+/* find a bus by its name */
+struct rte_bus *
+rte_bus_from_name(const char *str)
+{
+	if (rte_bus_name_valid(str) == 0)
+		return NULL;
+	return rte_bus_find(bus_cmp_name, str);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 9b50451..b236893 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -261,6 +261,20 @@ rte_bus_find_device(const struct rte_device *start,
  */
 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 
+/*
+ * Find a bus handle by its name.
+ * Compares the name of each bus up until any invalid character
+ * in the matched pattern.
+ *
+ * @param str
+ *	A null terminated character string.
+ *
+ * @return
+ *	A pointer to a bus if found.
+ *	NULL if no bus matches.
+ */
+struct rte_bus *rte_bus_from_name(const char *str);
+
 /**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index e0a056d..6607acc 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -201,3 +201,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
-- 
2.1.4

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

* [PATCH v4 7/9] bus: add helper to find a bus from a device name
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
                         ` (5 preceding siblings ...)
  2017-06-07 23:56       ` [PATCH v4 6/9] bus: add helper to find a bus from a bus name Gaetan Rivet
@ 2017-06-07 23:56       ` Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 8/9] vdev: expose bus name Gaetan Rivet
                         ` (2 subsequent siblings)
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Find which bus should be able to parse this device name into an internal
device representation.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 4 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 3517d74..04fa882 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -202,5 +202,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 2b41ba2..bad1bd9 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -239,3 +239,18 @@ rte_bus_from_name(const char *str)
 		return NULL;
 	return rte_bus_find(bus_cmp_name, str);
 }
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return !(bus->parse && bus->parse(name, NULL) == 0);
+}
+
+/* find a bus capable of parsing a device description */
+struct rte_bus *
+rte_bus_from_dev(const char *str)
+{
+	return rte_bus_find(bus_can_parse, str);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index b236893..4bed780 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -276,6 +276,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 struct rte_bus *rte_bus_from_name(const char *str);
 
 /**
+ * Find a bus capable of identifying a device.
+ *
+ * @param str
+ *   A device identifier (PCI address, virtual PMD name, ...).
+ *
+ * @return
+ *   A valid bus handle if found.
+ *   NULL if no bus is able to parse this device.
+ */
+struct rte_bus *rte_bus_from_dev(const char *str);
+
+/**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
  */
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 6607acc..a5127d6 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -206,5 +206,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
-- 
2.1.4

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

* [PATCH v4 8/9] vdev: expose bus name
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
                         ` (6 preceding siblings ...)
  2017-06-07 23:56       ` [PATCH v4 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-06-07 23:56       ` Gaetan Rivet
  2017-06-07 23:56       ` [PATCH v4 9/9] devargs: parse bus info Gaetan Rivet
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c  | 2 +-
 lib/librte_eal/common/include/rte_vdev.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 8dd4c88..221146e 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -404,6 +404,6 @@ static void rte_vdev_bus_register(void)
 		return;
 
 	registered = 1;
-	rte_vdev_bus.name = RTE_STR(virtual);
+	rte_vdev_bus.name = VIRTUAL_BUS_NAME;
 	rte_bus_register(&rte_vdev_bus);
 }
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index e6b678e..2d02c68 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -41,6 +41,8 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_devargs.h>
 
+#define VIRTUAL_BUS_NAME "virtual"
+
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
-- 
2.1.4

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

* [PATCH v4 9/9] devargs: parse bus info
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
                         ` (7 preceding siblings ...)
  2017-06-07 23:56       ` [PATCH v4 8/9] vdev: expose bus name Gaetan Rivet
@ 2017-06-07 23:56       ` Gaetan Rivet
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
  9 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-07 23:56 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_devargs.c  | 17 ++++++++++++++++-
 lib/librte_eal/common/eal_common_vdev.c     |  6 ++++--
 lib/librte_eal/common/include/rte_devargs.h |  3 +++
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index ffa8ad9..8bb72a2 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -83,7 +83,10 @@ int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
+	const char *dev = devargs_str;
+	struct rte_bus *bus;
 	char *buf = NULL;
+	size_t i;
 	int ret;
 
 	/* use malloc instead of rte_malloc as it's called early at init */
@@ -94,7 +97,19 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	memset(devargs, 0, sizeof(*devargs));
 	devargs->type = devtype;
 
-	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
+	bus = rte_bus_from_name(dev);
+	if (bus) {
+		i = rte_bus_name_valid(dev);
+		dev += i + 1;
+	} else {
+		bus = rte_bus_from_dev(dev);
+		if (!bus) {
+			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
+			goto fail;
+		}
+	}
+	devargs->bus = bus;
+	if (rte_eal_parse_devargs_str(dev, &buf, &devargs->args))
 		goto fail;
 
 	switch (devargs->type) {
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 221146e..7cc3c6c 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -182,6 +182,7 @@ alloc_devargs(const char *name, const char *args)
 		return NULL;
 
 	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	devargs->bus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	if (args)
 		devargs->args = strdup(args);
 
@@ -294,12 +295,13 @@ vdev_scan(void)
 {
 	struct rte_vdev_device *dev;
 	struct rte_devargs *devargs;
+	struct rte_bus *vbus;
 
 	/* for virtual devices we scan the devargs_list populated via cmdline */
-
+	vbus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (devargs->bus != vbus)
 			continue;
 
 		dev = find_vdev(devargs->virt.drv_name);
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 88120a1..1f50a24 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -51,6 +51,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#include <rte_bus.h>
 
 /**
  * Type of generic device
@@ -89,6 +90,8 @@ struct rte_devargs {
 			char drv_name[32];
 		} virt;
 	};
+	/** Bus handle for the device. */
+	struct rte_bus *bus;
 	/** Arguments string as given by user or "" for no argument. */
 	char *args;
 };
-- 
2.1.4

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

* Re: [PATCH 7/9] bus: add helper to find a bus from a device name
  2017-06-07 20:03     ` Gaëtan Rivet
@ 2017-06-08 10:45       ` Jan Blunck
  2017-06-08 11:36         ` Gaëtan Rivet
  0 siblings, 1 reply; 123+ messages in thread
From: Jan Blunck @ 2017-06-08 10:45 UTC (permalink / raw)
  To: Gaëtan Rivet
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Wed, Jun 7, 2017 at 10:03 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> On Wed, Jun 07, 2017 at 07:28:07PM +0200, Jan Blunck wrote:
>> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
>> > Find which bus should be able to parse this device name into an internal
>> > device representation.
>> >
>>
>> No, please don't add this. One should know to what bus a device
>> belongs to before plugging it. Artificially encoding the parent bus
>> into the device name is not the right thing to do. Please keep those
>> things separate.
>>
>

When plugging a device the users know about:
- bus name
- device name

Its not the case that the users invent the device names out of thin
air. The EAL shouldn't codify what the users of the EAL already know
about.


> The EAL has no way to know this currently. As you noted, it has to know
> onto which bus a device belongs before plugging it.
>
>> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
>> > ---
>> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
>> >  lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
>> >  lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
>> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
>> >  4 files changed, 29 insertions(+)
>> >
>> > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> > index 3517d74..04fa882 100644
>> > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> > @@ -202,5 +202,6 @@ DPDK_17.08 {
>> >         global:
>> >
>> >         rte_bus_from_name;
>> > +       rte_bus_from_dev;
>> >
>> >  } DPDK_17.05;
>> > diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
>> > index 7977190..08fff60 100644
>> > --- a/lib/librte_eal/common/eal_common_bus.c
>> > +++ b/lib/librte_eal/common/eal_common_bus.c
>> > @@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
>> >                 return NULL;
>> >         return rte_bus_find(bus_cmp_name, str);
>> >  }
>> > +
>> > +static int
>> > +bus_can_parse(const struct rte_bus *bus, const void *_name)
>> > +{
>> > +       const char *name = _name;
>> > +
>> > +       return (bus->parse && !bus->parse(name, NULL));
>> > +}
>> > +
>> > +/* find a bus capable of parsing a device description */
>> > +struct rte_bus *
>> > +rte_bus_from_dev(const char *str)
>> > +{
>> > +       return rte_bus_find(bus_can_parse, str);
>> > +}
>> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
>> > index 5b87ac4..0b48e66 100644
>> > --- a/lib/librte_eal/common/include/rte_bus.h
>> > +++ b/lib/librte_eal/common/include/rte_bus.h
>> > @@ -251,6 +251,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
>> >  struct rte_bus *rte_bus_from_name(const char *str);
>> >
>> >  /**
>> > + * Find a bus capable of identifying a device.
>> > + *
>> > + * @param str
>> > + *   A device identifier (PCI address, virtual PMD name, ...).
>> > + *
>> > + * @return
>> > + *   A valid bus structure if found.
>> > + *   NULL if no bus is able to parse this device.
>> > + */
>> > +struct rte_bus *rte_bus_from_dev(const char *str);
>> > +
>> > +/**
>> >   * Helper for Bus registration.
>> >   * The constructor has higher priority than PMD constructors.
>> >   */
>> > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
>> > index 6607acc..a5127d6 100644
>> > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
>> > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
>> > @@ -206,5 +206,6 @@ DPDK_17.08 {
>> >         global:
>> >
>> >         rte_bus_from_name;
>> > +       rte_bus_from_dev;
>> >
>> >  } DPDK_17.05;
>> > --
>> > 2.1.4
>> >
>
> --
> Gaėtan Rivet
> 6WIND

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

* Re: [PATCH 7/9] bus: add helper to find a bus from a device name
  2017-06-08 10:45       ` Jan Blunck
@ 2017-06-08 11:36         ` Gaëtan Rivet
  2017-06-08 11:40           ` Jan Blunck
  0 siblings, 1 reply; 123+ messages in thread
From: Gaëtan Rivet @ 2017-06-08 11:36 UTC (permalink / raw)
  To: Jan Blunck
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Thu, Jun 08, 2017 at 12:45:17PM +0200, Jan Blunck wrote:
> On Wed, Jun 7, 2017 at 10:03 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> > On Wed, Jun 07, 2017 at 07:28:07PM +0200, Jan Blunck wrote:
> >> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> >> > Find which bus should be able to parse this device name into an internal
> >> > device representation.
> >> >
> >>
> >> No, please don't add this. One should know to what bus a device
> >> belongs to before plugging it. Artificially encoding the parent bus
> >> into the device name is not the right thing to do. Please keep those
> >> things separate.
> >>
> >
> 
> When plugging a device the users know about:
> - bus name
> - device name
> 
> Its not the case that the users invent the device names out of thin
> air. The EAL shouldn't codify what the users of the EAL already know
> about.
> 
> 

Yes, but in that case the user is forced to explicitly name the bus used
for a device.

I think it might be sufficient to have this as a private function to the
EAL, as it is currently only used within the rte_devargs parsing.
Applications could use this helper to recognize a bus from a device
name, but this is contrived.

> > The EAL has no way to know this currently. As you noted, it has to know
> > onto which bus a device belongs before plugging it.
> >
> >> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> >> > ---
> >> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
> >> >  lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
> >> >  lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
> >> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
> >> >  4 files changed, 29 insertions(+)
> >> >
> >> > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> >> > index 3517d74..04fa882 100644
> >> > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> >> > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> >> > @@ -202,5 +202,6 @@ DPDK_17.08 {
> >> >         global:
> >> >
> >> >         rte_bus_from_name;
> >> > +       rte_bus_from_dev;
> >> >
> >> >  } DPDK_17.05;
> >> > diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> >> > index 7977190..08fff60 100644
> >> > --- a/lib/librte_eal/common/eal_common_bus.c
> >> > +++ b/lib/librte_eal/common/eal_common_bus.c
> >> > @@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
> >> >                 return NULL;
> >> >         return rte_bus_find(bus_cmp_name, str);
> >> >  }
> >> > +
> >> > +static int
> >> > +bus_can_parse(const struct rte_bus *bus, const void *_name)
> >> > +{
> >> > +       const char *name = _name;
> >> > +
> >> > +       return (bus->parse && !bus->parse(name, NULL));
> >> > +}
> >> > +
> >> > +/* find a bus capable of parsing a device description */
> >> > +struct rte_bus *
> >> > +rte_bus_from_dev(const char *str)
> >> > +{
> >> > +       return rte_bus_find(bus_can_parse, str);
> >> > +}
> >> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> >> > index 5b87ac4..0b48e66 100644
> >> > --- a/lib/librte_eal/common/include/rte_bus.h
> >> > +++ b/lib/librte_eal/common/include/rte_bus.h
> >> > @@ -251,6 +251,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
> >> >  struct rte_bus *rte_bus_from_name(const char *str);
> >> >
> >> >  /**
> >> > + * Find a bus capable of identifying a device.
> >> > + *
> >> > + * @param str
> >> > + *   A device identifier (PCI address, virtual PMD name, ...).
> >> > + *
> >> > + * @return
> >> > + *   A valid bus structure if found.
> >> > + *   NULL if no bus is able to parse this device.
> >> > + */
> >> > +struct rte_bus *rte_bus_from_dev(const char *str);
> >> > +
> >> > +/**
> >> >   * Helper for Bus registration.
> >> >   * The constructor has higher priority than PMD constructors.
> >> >   */
> >> > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> >> > index 6607acc..a5127d6 100644
> >> > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> >> > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> >> > @@ -206,5 +206,6 @@ DPDK_17.08 {
> >> >         global:
> >> >
> >> >         rte_bus_from_name;
> >> > +       rte_bus_from_dev;
> >> >
> >> >  } DPDK_17.05;
> >> > --
> >> > 2.1.4
> >> >
> >
> > --
> > Gaėtan Rivet
> > 6WIND

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH 0/9] rte_bus parse API
  2017-06-07 19:55   ` Gaëtan Rivet
@ 2017-06-08 11:38     ` Jan Blunck
  2017-06-08 13:04       ` Gaëtan Rivet
  0 siblings, 1 reply; 123+ messages in thread
From: Jan Blunck @ 2017-06-08 11:38 UTC (permalink / raw)
  To: Gaëtan Rivet
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Wed, Jun 7, 2017 at 9:55 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> On Wed, Jun 07, 2017 at 07:22:05PM +0200, Jan Blunck wrote:
>> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
>> > Following the evolutions announced in [1], here is the first part of
>> > the rte_devargs rework planned for 17.08. The rationale has been partially
>> > explained in [2].
>> >
>> > This first part covers the introduction of the necessary facilities in
>> > rte_bus to allow for generic device parsing. This API is implemented for
>> > the virtual and PCI buses. Additionally, this rte_bus evolution is being
>> > used within rte_devargs to characterize a device type by its bus.
>> > This work is the first of two parts to reduce the dependency of the EAL
>> > upon specific bus implementations.
>> >
>> > Two public functions are added to rte_bus to help bus recognition:
>> >
>> > - rte_bus_from_name
>> > - rte_bus_from_dev
>> >
>> > These functions are made public because the bus handle within devargs
>> > becomes the generic device type. Recognizing device types is useful for
>> > buses and PMDs alike.
>> > The modified rte_devargs parsing allows declaring on the EAL command line
>> > explicit buses to handle a device. The format is as follow:
>> >
>> >   --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
>> >   -w PCI:00:02.0 -w 00:03.0
>> >
>>
>> I don't see the point of doing this. The --vdev parameter implicitly
>> defines the bus by its name (--vdev aka virtual device).
>>
>> Why don't you add a commandline "--dev" parameter that supports a
>> "bus=" devarg? You would need to clarify what that means for other
>> busses than the virtual one. Is the bus switched into whitelist mode
>> by that?
>>
>>
>
> We cannot keep the current -w, -b and --vdev parameter. Those are
> processed by the EAL, and use specifics from the virtual and PCI buses.
>
> The rte_devargs rework has been to make the same functionality generic
> to all rte_bus. As seen quickly in [2], rte_devargs has two functions:
>
> * Validating a device declaration
> * Keeping the relevant device info until it has been processed.
>

I don't agree with the validation step. This is highly
device/driver/bus specific and I don't believe that just because you
have created a rte_devargs it is a guarantee that the device is valid.
Besides that it makes statically embedding rte_devargs into other
structures impossible. As I see it rte_devargs is a key-value list
with some keys that are generic. This would make application
development much easier.


> Both functionalities have been genericized. This results in all parameters
> being able to be used with all types of devices. This is inherent to the
> EAL becoming bus-agnostic.
>
> Now, it is absolutely possible to rename for example -w as --dev, as it
> is the expected behavior from users. This however should be discussed by
> the community, last time I talked about the possibility of switching the
> default of the PCI bus to whitelist mode the community wasn't all that
> enthused by the prospect.
>
> Finally, I do not like the idea of a special devarg just for declaring
> explicitly buses for devices. The bus is not a device modifier, nor is
> it a driver parameter. The bus is a way to define the location of the
> device on the system. Adding a special "bus=" devargs means having some
> preprocessing done on devargs upon rte_devargs allocation. This was
> already abused by the bonding PMD with the driver= parameter. I do not
> support this and did not want to repeat it. Passing down the device args
> is a simple process and we should keep it as simple as possible.
>
> I know you do not like having the bus as part of the device name.
> As a compromise, I made the current system flexible and allowed the legacy
> device definition to be kept.
>
> However with a purely generic process, it is necessary to at least offer
> the possibility to the user to explicitly use a bus, as nothing prevents
> conflicting device names from existing.
>
>> > [2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html
>
>> > This explicit bus designation is optional; no evolution is currently
>> > forced on users to migrate to this new format. The separating character is
>> > arbitrary and can be any character illegal within a bus name.
>> > Subsequently, what is allowed within a bus name has been formally
>> > defined and is now enforced.
>> >
>> > [1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
>> > [2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html
>> >
>> > This patchset depends on:
>> >
>> > bus: attach / detach API
>> > http://dpdk.org/ml/archives/dev/2017-May/066330.html
>> > http://dpdk.org/dev/patchwork/patch/24489/
>> >
>> > Gaetan Rivet (9):
>> >   bus: fix bus name registration
>> >   bus: verify bus name on registration
>> >   bus: introduce parsing functionality
>> >   vdev: implement parse bus operation
>> >   pci: implement parse bus operation
>> >   bus: add helper to find bus from a name
>> >   bus: add helper to find a bus from a device name
>> >   vdev: expose bus name
>> >   devargs: parse bus info
>> >
>> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
>> >  lib/librte_eal/common/eal_common_bus.c          | 47 +++++++++++++++++
>> >  lib/librte_eal/common/eal_common_devargs.c      | 17 +++++-
>> >  lib/librte_eal/common/eal_common_pci.c          | 19 +++++++
>> >  lib/librte_eal/common/eal_common_vdev.c         | 70 ++++++++++++++-----------
>> >  lib/librte_eal/common/eal_private.h             | 16 ++++++
>> >  lib/librte_eal/common/include/rte_bus.h         | 49 ++++++++++++++++-
>> >  lib/librte_eal/common/include/rte_devargs.h     |  3 ++
>> >  lib/librte_eal/common/include/rte_vdev.h        |  2 +
>> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
>> >  10 files changed, 205 insertions(+), 34 deletions(-)
>> >
>> > --
>> > 2.1.4
>> >
>
> --
> Gaėtan Rivet
> 6WIND

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

* Re: [PATCH 7/9] bus: add helper to find a bus from a device name
  2017-06-08 11:36         ` Gaëtan Rivet
@ 2017-06-08 11:40           ` Jan Blunck
  2017-06-08 12:51             ` Gaëtan Rivet
  0 siblings, 1 reply; 123+ messages in thread
From: Jan Blunck @ 2017-06-08 11:40 UTC (permalink / raw)
  To: Gaëtan Rivet
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Thu, Jun 8, 2017 at 1:36 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> On Thu, Jun 08, 2017 at 12:45:17PM +0200, Jan Blunck wrote:
>> On Wed, Jun 7, 2017 at 10:03 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
>> > On Wed, Jun 07, 2017 at 07:28:07PM +0200, Jan Blunck wrote:
>> >> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
>> >> > Find which bus should be able to parse this device name into an internal
>> >> > device representation.
>> >> >
>> >>
>> >> No, please don't add this. One should know to what bus a device
>> >> belongs to before plugging it. Artificially encoding the parent bus
>> >> into the device name is not the right thing to do. Please keep those
>> >> things separate.
>> >>
>> >
>>
>> When plugging a device the users know about:
>> - bus name
>> - device name
>>
>> Its not the case that the users invent the device names out of thin
>> air. The EAL shouldn't codify what the users of the EAL already know
>> about.
>>
>>
>
> Yes, but in that case the user is forced to explicitly name the bus used
> for a device.
>
> I think it might be sufficient to have this as a private function to the
> EAL, as it is currently only used within the rte_devargs parsing.
> Applications could use this helper to recognize a bus from a device
> name, but this is contrived.
>

Just remove it. Putting the knowledge of what bus a device name could
be for into code has failed before (e.g. biosdevname etc.). If the
application doesn't know what bus the device is living on we have a
different problem.

>> > The EAL has no way to know this currently. As you noted, it has to know
>> > onto which bus a device belongs before plugging it.
>> >
>> >> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
>> >> > ---
>> >> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
>> >> >  lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
>> >> >  lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
>> >> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
>> >> >  4 files changed, 29 insertions(+)
>> >> >
>> >> > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> >> > index 3517d74..04fa882 100644
>> >> > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> >> > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
>> >> > @@ -202,5 +202,6 @@ DPDK_17.08 {
>> >> >         global:
>> >> >
>> >> >         rte_bus_from_name;
>> >> > +       rte_bus_from_dev;
>> >> >
>> >> >  } DPDK_17.05;
>> >> > diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
>> >> > index 7977190..08fff60 100644
>> >> > --- a/lib/librte_eal/common/eal_common_bus.c
>> >> > +++ b/lib/librte_eal/common/eal_common_bus.c
>> >> > @@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
>> >> >                 return NULL;
>> >> >         return rte_bus_find(bus_cmp_name, str);
>> >> >  }
>> >> > +
>> >> > +static int
>> >> > +bus_can_parse(const struct rte_bus *bus, const void *_name)
>> >> > +{
>> >> > +       const char *name = _name;
>> >> > +
>> >> > +       return (bus->parse && !bus->parse(name, NULL));
>> >> > +}
>> >> > +
>> >> > +/* find a bus capable of parsing a device description */
>> >> > +struct rte_bus *
>> >> > +rte_bus_from_dev(const char *str)
>> >> > +{
>> >> > +       return rte_bus_find(bus_can_parse, str);
>> >> > +}
>> >> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
>> >> > index 5b87ac4..0b48e66 100644
>> >> > --- a/lib/librte_eal/common/include/rte_bus.h
>> >> > +++ b/lib/librte_eal/common/include/rte_bus.h
>> >> > @@ -251,6 +251,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
>> >> >  struct rte_bus *rte_bus_from_name(const char *str);
>> >> >
>> >> >  /**
>> >> > + * Find a bus capable of identifying a device.
>> >> > + *
>> >> > + * @param str
>> >> > + *   A device identifier (PCI address, virtual PMD name, ...).
>> >> > + *
>> >> > + * @return
>> >> > + *   A valid bus structure if found.
>> >> > + *   NULL if no bus is able to parse this device.
>> >> > + */
>> >> > +struct rte_bus *rte_bus_from_dev(const char *str);
>> >> > +
>> >> > +/**
>> >> >   * Helper for Bus registration.
>> >> >   * The constructor has higher priority than PMD constructors.
>> >> >   */
>> >> > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
>> >> > index 6607acc..a5127d6 100644
>> >> > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
>> >> > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
>> >> > @@ -206,5 +206,6 @@ DPDK_17.08 {
>> >> >         global:
>> >> >
>> >> >         rte_bus_from_name;
>> >> > +       rte_bus_from_dev;
>> >> >
>> >> >  } DPDK_17.05;
>> >> > --
>> >> > 2.1.4
>> >> >
>> >
>> > --
>> > Gaėtan Rivet
>> > 6WIND
>
> --
> Gaëtan Rivet
> 6WIND

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

* Re: [PATCH 7/9] bus: add helper to find a bus from a device name
  2017-06-08 11:40           ` Jan Blunck
@ 2017-06-08 12:51             ` Gaëtan Rivet
  2017-06-10  8:50               ` Jan Blunck
  0 siblings, 1 reply; 123+ messages in thread
From: Gaëtan Rivet @ 2017-06-08 12:51 UTC (permalink / raw)
  To: Jan Blunck
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Thu, Jun 08, 2017 at 01:40:46PM +0200, Jan Blunck wrote:
> On Thu, Jun 8, 2017 at 1:36 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> > On Thu, Jun 08, 2017 at 12:45:17PM +0200, Jan Blunck wrote:
> >> On Wed, Jun 7, 2017 at 10:03 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> >> > On Wed, Jun 07, 2017 at 07:28:07PM +0200, Jan Blunck wrote:
> >> >> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> >> >> > Find which bus should be able to parse this device name into an internal
> >> >> > device representation.
> >> >> >
> >> >>
> >> >> No, please don't add this. One should know to what bus a device
> >> >> belongs to before plugging it. Artificially encoding the parent bus
> >> >> into the device name is not the right thing to do. Please keep those
> >> >> things separate.
> >> >>
> >> >
> >>
> >> When plugging a device the users know about:
> >> - bus name
> >> - device name
> >>
> >> Its not the case that the users invent the device names out of thin
> >> air. The EAL shouldn't codify what the users of the EAL already know
> >> about.
> >>
> >>
> >
> > Yes, but in that case the user is forced to explicitly name the bus used
> > for a device.
> >
> > I think it might be sufficient to have this as a private function to the
> > EAL, as it is currently only used within the rte_devargs parsing.
> > Applications could use this helper to recognize a bus from a device
> > name, but this is contrived.
> >
> 
> Just remove it. Putting the knowledge of what bus a device name could
> be for into code has failed before (e.g. biosdevname etc.). If the
> application doesn't know what bus the device is living on we have a
> different problem.
> 

This means that devices will be declared as follows:

  -w PCI:00:02.0 -w virtual:net_ring0

Without a way to keep the legacy behavior.
Do you agree with it?

> >> > The EAL has no way to know this currently. As you noted, it has to know
> >> > onto which bus a device belongs before plugging it.
> >> >
> >> >> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> >> >> > ---
> >> >> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
> >> >> >  lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
> >> >> >  lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
> >> >> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
> >> >> >  4 files changed, 29 insertions(+)
> >> >> >
> >> >> > diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> >> >> > index 3517d74..04fa882 100644
> >> >> > --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> >> >> > +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> >> >> > @@ -202,5 +202,6 @@ DPDK_17.08 {
> >> >> >         global:
> >> >> >
> >> >> >         rte_bus_from_name;
> >> >> > +       rte_bus_from_dev;
> >> >> >
> >> >> >  } DPDK_17.05;
> >> >> > diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> >> >> > index 7977190..08fff60 100644
> >> >> > --- a/lib/librte_eal/common/eal_common_bus.c
> >> >> > +++ b/lib/librte_eal/common/eal_common_bus.c
> >> >> > @@ -242,3 +242,18 @@ rte_bus_from_name(const char *str)
> >> >> >                 return NULL;
> >> >> >         return rte_bus_find(bus_cmp_name, str);
> >> >> >  }
> >> >> > +
> >> >> > +static int
> >> >> > +bus_can_parse(const struct rte_bus *bus, const void *_name)
> >> >> > +{
> >> >> > +       const char *name = _name;
> >> >> > +
> >> >> > +       return (bus->parse && !bus->parse(name, NULL));
> >> >> > +}
> >> >> > +
> >> >> > +/* find a bus capable of parsing a device description */
> >> >> > +struct rte_bus *
> >> >> > +rte_bus_from_dev(const char *str)
> >> >> > +{
> >> >> > +       return rte_bus_find(bus_can_parse, str);
> >> >> > +}
> >> >> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> >> >> > index 5b87ac4..0b48e66 100644
> >> >> > --- a/lib/librte_eal/common/include/rte_bus.h
> >> >> > +++ b/lib/librte_eal/common/include/rte_bus.h
> >> >> > @@ -251,6 +251,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
> >> >> >  struct rte_bus *rte_bus_from_name(const char *str);
> >> >> >
> >> >> >  /**
> >> >> > + * Find a bus capable of identifying a device.
> >> >> > + *
> >> >> > + * @param str
> >> >> > + *   A device identifier (PCI address, virtual PMD name, ...).
> >> >> > + *
> >> >> > + * @return
> >> >> > + *   A valid bus structure if found.
> >> >> > + *   NULL if no bus is able to parse this device.
> >> >> > + */
> >> >> > +struct rte_bus *rte_bus_from_dev(const char *str);
> >> >> > +
> >> >> > +/**
> >> >> >   * Helper for Bus registration.
> >> >> >   * The constructor has higher priority than PMD constructors.
> >> >> >   */
> >> >> > diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> >> >> > index 6607acc..a5127d6 100644
> >> >> > --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> >> >> > +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> >> >> > @@ -206,5 +206,6 @@ DPDK_17.08 {
> >> >> >         global:
> >> >> >
> >> >> >         rte_bus_from_name;
> >> >> > +       rte_bus_from_dev;
> >> >> >
> >> >> >  } DPDK_17.05;
> >> >> > --
> >> >> > 2.1.4
> >> >> >
> >> >
> >> > --
> >> > Gaėtan Rivet
> >> > 6WIND
> >
> > --
> > Gaëtan Rivet
> > 6WIND

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH 0/9] rte_bus parse API
  2017-06-08 11:38     ` Jan Blunck
@ 2017-06-08 13:04       ` Gaëtan Rivet
  0 siblings, 0 replies; 123+ messages in thread
From: Gaëtan Rivet @ 2017-06-08 13:04 UTC (permalink / raw)
  To: Jan Blunck
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Thu, Jun 08, 2017 at 01:38:12PM +0200, Jan Blunck wrote:
> On Wed, Jun 7, 2017 at 9:55 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> > On Wed, Jun 07, 2017 at 07:22:05PM +0200, Jan Blunck wrote:
> >> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> >> > Following the evolutions announced in [1], here is the first part of
> >> > the rte_devargs rework planned for 17.08. The rationale has been partially
> >> > explained in [2].
> >> >
> >> > This first part covers the introduction of the necessary facilities in
> >> > rte_bus to allow for generic device parsing. This API is implemented for
> >> > the virtual and PCI buses. Additionally, this rte_bus evolution is being
> >> > used within rte_devargs to characterize a device type by its bus.
> >> > This work is the first of two parts to reduce the dependency of the EAL
> >> > upon specific bus implementations.
> >> >
> >> > Two public functions are added to rte_bus to help bus recognition:
> >> >
> >> > - rte_bus_from_name
> >> > - rte_bus_from_dev
> >> >
> >> > These functions are made public because the bus handle within devargs
> >> > becomes the generic device type. Recognizing device types is useful for
> >> > buses and PMDs alike.
> >> > The modified rte_devargs parsing allows declaring on the EAL command line
> >> > explicit buses to handle a device. The format is as follow:
> >> >
> >> >   --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
> >> >   -w PCI:00:02.0 -w 00:03.0
> >> >
> >>
> >> I don't see the point of doing this. The --vdev parameter implicitly
> >> defines the bus by its name (--vdev aka virtual device).
> >>
> >> Why don't you add a commandline "--dev" parameter that supports a
> >> "bus=" devarg? You would need to clarify what that means for other
> >> busses than the virtual one. Is the bus switched into whitelist mode
> >> by that?
> >>
> >>
> >
> > We cannot keep the current -w, -b and --vdev parameter. Those are
> > processed by the EAL, and use specifics from the virtual and PCI buses.
> >
> > The rte_devargs rework has been to make the same functionality generic
> > to all rte_bus. As seen quickly in [2], rte_devargs has two functions:
> >
> > * Validating a device declaration
> > * Keeping the relevant device info until it has been processed.
> >
> 
> I don't agree with the validation step. This is highly
> device/driver/bus specific and I don't believe that just because you
> have created a rte_devargs it is a guarantee that the device is valid.

It is the current API. If an rte_devargs is added to the global list,
then it means that the embedded information has been validated. I
kept the same behavior but made it generic in the new version.

> Besides that it makes statically embedding rte_devargs into other
> structures impossible.

Why? In the failsafe PMD, I statically embed an rte_devargs to avoid
having to insert one in the global device list to remove it afterward.
What limitation to this do you see? I think I misunderstand what you
mean.

> As I see it rte_devargs is a key-value list
> with some keys that are generic. This would make application
> development much easier.
> 
> 

The previously encoded information was:

- Scan policy / bus (in the type field)
- Device designation (PCI location / virtual driver)
- kvargs

Beside the kvargs, none were generic, so I made them so. I
divided the type field into two separate elements as it was conflating
two concepts.

I do not understand how much simpler we can make this. The fields have
not changed, nor has the information itself. Everything has however
been genericized, which is necessary.

> > Both functionalities have been genericized. This results in all parameters
> > being able to be used with all types of devices. This is inherent to the
> > EAL becoming bus-agnostic.
> >
> > Now, it is absolutely possible to rename for example -w as --dev, as it
> > is the expected behavior from users. This however should be discussed by
> > the community, last time I talked about the possibility of switching the
> > default of the PCI bus to whitelist mode the community wasn't all that
> > enthused by the prospect.
> >
> > Finally, I do not like the idea of a special devarg just for declaring
> > explicitly buses for devices. The bus is not a device modifier, nor is
> > it a driver parameter. The bus is a way to define the location of the
> > device on the system. Adding a special "bus=" devargs means having some
> > preprocessing done on devargs upon rte_devargs allocation. This was
> > already abused by the bonding PMD with the driver= parameter. I do not
> > support this and did not want to repeat it. Passing down the device args
> > is a simple process and we should keep it as simple as possible.
> >
> > I know you do not like having the bus as part of the device name.
> > As a compromise, I made the current system flexible and allowed the legacy
> > device definition to be kept.
> >
> > However with a purely generic process, it is necessary to at least offer
> > the possibility to the user to explicitly use a bus, as nothing prevents
> > conflicting device names from existing.
> >
> >> > [2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html
> >
> >> > This explicit bus designation is optional; no evolution is currently
> >> > forced on users to migrate to this new format. The separating character is
> >> > arbitrary and can be any character illegal within a bus name.
> >> > Subsequently, what is allowed within a bus name has been formally
> >> > defined and is now enforced.
> >> >
> >> > [1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
> >> > [2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html
> >> >
> >> > This patchset depends on:
> >> >
> >> > bus: attach / detach API
> >> > http://dpdk.org/ml/archives/dev/2017-May/066330.html
> >> > http://dpdk.org/dev/patchwork/patch/24489/
> >> >
> >> > Gaetan Rivet (9):
> >> >   bus: fix bus name registration
> >> >   bus: verify bus name on registration
> >> >   bus: introduce parsing functionality
> >> >   vdev: implement parse bus operation
> >> >   pci: implement parse bus operation
> >> >   bus: add helper to find bus from a name
> >> >   bus: add helper to find a bus from a device name
> >> >   vdev: expose bus name
> >> >   devargs: parse bus info
> >> >
> >> >  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
> >> >  lib/librte_eal/common/eal_common_bus.c          | 47 +++++++++++++++++
> >> >  lib/librte_eal/common/eal_common_devargs.c      | 17 +++++-
> >> >  lib/librte_eal/common/eal_common_pci.c          | 19 +++++++
> >> >  lib/librte_eal/common/eal_common_vdev.c         | 70 ++++++++++++++-----------
> >> >  lib/librte_eal/common/eal_private.h             | 16 ++++++
> >> >  lib/librte_eal/common/include/rte_bus.h         | 49 ++++++++++++++++-
> >> >  lib/librte_eal/common/include/rte_devargs.h     |  3 ++
> >> >  lib/librte_eal/common/include/rte_vdev.h        |  2 +
> >> >  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
> >> >  10 files changed, 205 insertions(+), 34 deletions(-)
> >> >
> >> > --
> >> > 2.1.4
> >> >
> >
> > --
> > Gaėtan Rivet
> > 6WIND

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH 7/9] bus: add helper to find a bus from a device name
  2017-06-08 12:51             ` Gaëtan Rivet
@ 2017-06-10  8:50               ` Jan Blunck
  2017-06-12 14:21                 ` Gaëtan Rivet
  0 siblings, 1 reply; 123+ messages in thread
From: Jan Blunck @ 2017-06-10  8:50 UTC (permalink / raw)
  To: Gaëtan Rivet
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Thu, Jun 8, 2017 at 2:51 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> On Thu, Jun 08, 2017 at 01:40:46PM +0200, Jan Blunck wrote:
>> On Thu, Jun 8, 2017 at 1:36 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
>> > On Thu, Jun 08, 2017 at 12:45:17PM +0200, Jan Blunck wrote:
>> >> On Wed, Jun 7, 2017 at 10:03 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
>> >> > On Wed, Jun 07, 2017 at 07:28:07PM +0200, Jan Blunck wrote:
>> >> >> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
>> >> >> > Find which bus should be able to parse this device name into an internal
>> >> >> > device representation.
>> >> >> >
>> >> >>
>> >> >> No, please don't add this. One should know to what bus a device
>> >> >> belongs to before plugging it. Artificially encoding the parent bus
>> >> >> into the device name is not the right thing to do. Please keep those
>> >> >> things separate.
>> >> >>
>> >> >
>> >>
>> >> When plugging a device the users know about:
>> >> - bus name
>> >> - device name
>> >>
>> >> Its not the case that the users invent the device names out of thin
>> >> air. The EAL shouldn't codify what the users of the EAL already know
>> >> about.
>> >>
>> >>
>> >
>> > Yes, but in that case the user is forced to explicitly name the bus used
>> > for a device.
>> >
>> > I think it might be sufficient to have this as a private function to the
>> > EAL, as it is currently only used within the rte_devargs parsing.
>> > Applications could use this helper to recognize a bus from a device
>> > name, but this is contrived.
>> >
>>
>> Just remove it. Putting the knowledge of what bus a device name could
>> be for into code has failed before (e.g. biosdevname etc.). If the
>> application doesn't know what bus the device is living on we have a
>> different problem.
>>
>
> This means that devices will be declared as follows:
>
>   -w PCI:00:02.0 -w virtual:net_ring0
>
> Without a way to keep the legacy behavior.
> Do you agree with it?
>

This adds ':' as another character not usable in identifiers for buses.

I wouldn't touch the meaning of -w at all and instead use it as an alias for

--dev 00:02.0,bus=pci  --bus pci,whitelist

This would clearly separate the device arguments from the bus arguments.

What do you think? Does this make sense?

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

* Re: [PATCH 7/9] bus: add helper to find a bus from a device name
  2017-06-10  8:50               ` Jan Blunck
@ 2017-06-12 14:21                 ` Gaëtan Rivet
  0 siblings, 0 replies; 123+ messages in thread
From: Gaëtan Rivet @ 2017-06-12 14:21 UTC (permalink / raw)
  To: Jan Blunck
  Cc: dev, Stephen Hemminger, Maxime Coquelin, Jerin Jacob, David Marchand

On Sat, Jun 10, 2017 at 10:50:12AM +0200, Jan Blunck wrote:
> On Thu, Jun 8, 2017 at 2:51 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> > On Thu, Jun 08, 2017 at 01:40:46PM +0200, Jan Blunck wrote:
> >> On Thu, Jun 8, 2017 at 1:36 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> >> > On Thu, Jun 08, 2017 at 12:45:17PM +0200, Jan Blunck wrote:
> >> >> On Wed, Jun 7, 2017 at 10:03 PM, Gaëtan Rivet <gaetan.rivet@6wind.com> wrote:
> >> >> > On Wed, Jun 07, 2017 at 07:28:07PM +0200, Jan Blunck wrote:
> >> >> >> On Wed, May 24, 2017 at 5:12 PM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> >> >> >> > Find which bus should be able to parse this device name into an internal
> >> >> >> > device representation.
> >> >> >> >
> >> >> >>
> >> >> >> No, please don't add this. One should know to what bus a device
> >> >> >> belongs to before plugging it. Artificially encoding the parent bus
> >> >> >> into the device name is not the right thing to do. Please keep those
> >> >> >> things separate.
> >> >> >>
> >> >> >
> >> >>
> >> >> When plugging a device the users know about:
> >> >> - bus name
> >> >> - device name
> >> >>
> >> >> Its not the case that the users invent the device names out of thin
> >> >> air. The EAL shouldn't codify what the users of the EAL already know
> >> >> about.
> >> >>
> >> >>
> >> >
> >> > Yes, but in that case the user is forced to explicitly name the bus used
> >> > for a device.
> >> >
> >> > I think it might be sufficient to have this as a private function to the
> >> > EAL, as it is currently only used within the rte_devargs parsing.
> >> > Applications could use this helper to recognize a bus from a device
> >> > name, but this is contrived.
> >> >
> >>
> >> Just remove it. Putting the knowledge of what bus a device name could
> >> be for into code has failed before (e.g. biosdevname etc.). If the
> >> application doesn't know what bus the device is living on we have a
> >> different problem.
> >>
> >
> > This means that devices will be declared as follows:
> >
> >   -w PCI:00:02.0 -w virtual:net_ring0
> >
> > Without a way to keep the legacy behavior.
> > Do you agree with it?
> >
> 
> This adds ':' as another character not usable in identifiers for buses.
> 

I understand your issue with this.
However, we are not forced to define a separating character that would thus
be forbidden within bus names.

We can strncmp() the name of the device, limited to strlen(bus->name).
If no bus name could be read this way, then we are sure to have a device
name (if we want to keep backward compability) or to throw an error if
we want to force defining the bus explicitly.

My current approach has been to define what is allowed within a bus name
and to limit the name comparison to the valid characters.
This allowed to use any illegal character as separator, but I think it
was a mistake. This is not a good, stable API for the future and does
not give clear rules to bus writers as to what is, or will be allowed
within a bus name.

But the strncmp approach allows the use of any separating character,
legal or illegal within a bus name. Additionally, it's then possible not
to add a magic devargs that must be parsed prior to device probing.

This last point is important I think. I am strongly opposed to having
parsing done upon the devargs, and to have any special logic added to
the rte_devargs constructor. As you saw with the driver= special
parameter, this led you to either add rte_kvargs as a dependency or roll
out your own parser. This was an undocumented hack for the bonding PMD test,
and personally I do not support this kind of addition to the public
rte_bus API.

> I wouldn't touch the meaning of -w at all and instead use it as an alias for
> 
> --dev 00:02.0,bus=pci  --bus pci,whitelist
> 

I agree that we should add a --bus parameter or similar to offer bus
configuration.

I think that in the end, -w, -b and --vdev should disappear to only
leave a common --dev parameter, capable of handling all devices.

It may be possible to have a special rule for -w, -b for some time, that
would either prepend "PCI:" or append ",bus=PCI" to any device
definition, but this is hacky as it relies on PCI_BUS_NAME without
being able to include its definition.

But considering the possibility to declare a device without explicitly
naming its bus: if we go in this direction, then we already have a
public API that can be leveraged for this. The implementation is
simple and can be made private to the EAL if exposing it is a problem.
Additionally it does not inject implicit bus dependencies within the
EAL.

> This would clearly separate the device arguments from the bus arguments.
> 
> What do you think? Does this make sense?

-- 
Gaëtan Rivet
6WIND

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

* [PATCH v5 0/7] rte_bus parse API
  2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
                         ` (8 preceding siblings ...)
  2017-06-07 23:56       ` [PATCH v4 9/9] devargs: parse bus info Gaetan Rivet
@ 2017-06-20 23:30       ` Gaetan Rivet
  2017-06-20 23:30         ` [PATCH v5 1/7] bus: fix bus name registration Gaetan Rivet
                           ` (8 more replies)
  9 siblings, 9 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-20 23:30 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, David Marchand

Following the evolutions announced in [1], here is the first part of
the rte_devargs rework planned for 17.08. The rationale has been partially
explained in [2].

This first part covers the introduction of the necessary facilities in
rte_bus to allow for generic device parsing. This API is implemented for
the virtual and PCI buses. Additionally, this rte_bus evolution is being
used within rte_devargs to characterize a device type by its bus.
This work is the first of two parts to reduce the dependency of the EAL
upon specific bus implementations.

Two public functions are added to rte_bus to help bus recognition:

- rte_bus_from_name
- rte_bus_from_dev

These functions are made public because the bus handle within devargs
becomes the generic device type. Recognizing device types is useful for
buses and PMDs alike.
The modified rte_devargs parsing allows declaring on the EAL command line
explicit buses to handle a device. The format is as follow:

  --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
  -w PCI:00:02.0 -w 00:03.0

This explicit bus designation is optional; no evolution is currently
forced on users to migrate to this new format. The separating character is
arbitrary and can be any character illegal within a bus name.
Subsequently, what is allowed within a bus name has been formally
defined and is now enforced.

[1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
[2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html

This patchset depends on:

bus: attach / detach API
http://dpdk.org/ml/archives/dev/2017-May/066330.html
http://dpdk.org/dev/patchwork/patch/24489/

v1 -> v2:

  * fix PCI parse implementation

v2 --> v3:

  * Rebase the series on the new plug / unplug API

v3 --> v4:

  * Several bug fixes, commit log rewrite.
  * Follow the changes to the plug / unplug API.

v5:

  * Do not verify bus name on bus registration.
    Actually, a legal bus name is not defined anymore.
    The bus/device separator in a device declaration can be anything,
    as long as it is a single character.
    The behavior is otherwise unchanged.

Gaetan Rivet (7):
  bus: fix bus name registration
  bus: introduce parsing functionality
  vdev: implement parse bus operation
  pci: implement parse bus operation
  bus: add helper to find a bus from a device name
  vdev: expose bus name
  devargs: parse bus info

 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++
 lib/librte_eal/common/eal_common_bus.c          | 31 +++++++++++
 lib/librte_eal/common/eal_common_devargs.c      | 15 +++++-
 lib/librte_eal/common/eal_common_pci.c          | 19 +++++++
 lib/librte_eal/common/eal_common_vdev.c         | 68 +++++++++++++------------
 lib/librte_eal/common/include/rte_bus.h         | 49 +++++++++++++++++-
 lib/librte_eal/common/include/rte_devargs.h     |  3 ++
 lib/librte_eal/common/include/rte_vdev.h        |  2 +
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++
 9 files changed, 169 insertions(+), 34 deletions(-)

-- 
2.1.4

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

* [PATCH v5 1/7] bus: fix bus name registration
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
@ 2017-06-20 23:30         ` Gaetan Rivet
  2017-06-27 15:53           ` Bruce Richardson
  2017-06-27 19:19           ` Jan Blunck
  2017-06-20 23:30         ` [PATCH v5 2/7] bus: introduce parsing functionality Gaetan Rivet
                           ` (7 subsequent siblings)
  8 siblings, 2 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-20 23:30 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet, stable

The default bus registration function should not result in buses
registering with double quotes within their names.

Fixes: a97725791eec ("bus: introduce bus abstraction")
Cc: stable@dpdk.org

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index fcc2442..b220299 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -254,7 +254,7 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 #define RTE_REGISTER_BUS(nm, bus) \
 static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
 {\
-	(bus).name = RTE_STR(nm);\
+	(bus).name = nm;\
 	rte_bus_register(&bus); \
 }
 
-- 
2.1.4

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

* [PATCH v5 2/7] bus: introduce parsing functionality
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
  2017-06-20 23:30         ` [PATCH v5 1/7] bus: fix bus name registration Gaetan Rivet
@ 2017-06-20 23:30         ` Gaetan Rivet
  2017-06-27 15:54           ` Bruce Richardson
  2017-06-27 19:26           ` Jan Blunck
  2017-06-20 23:30         ` [PATCH v5 3/7] vdev: implement parse bus operation Gaetan Rivet
                           ` (6 subsequent siblings)
  8 siblings, 2 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-20 23:30 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

This operation can be used either to validate that a device
representation can be understood by a bus, as well as store the resulting
specialized device representation in any format determined by the bus.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index b220299..05503ea 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -117,6 +117,26 @@ typedef struct rte_device * (*rte_bus_plug_t)(struct rte_devargs *da);
 typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
 
 /**
+ * Bus specific parsing function.
+ * Validates the syntax used in the textual representation of a device,
+ * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
+ * device representation to ``addr``.
+ *
+ * @param[in] name
+ *	device textual description
+ *
+ * @param[out] addr
+ *	device information location address, into which parsed info
+ *	should be written. If NULL, nothing should be written, which
+ *	is not an error.
+ *
+ * @return
+ *	0 if parsing was successful.
+ *	!0 for any error.
+ */
+typedef int (*rte_bus_parse_t)(const char *name, void *addr);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -127,6 +147,7 @@ struct rte_bus {
 	rte_bus_find_device_t find_device; /**< Find device on bus */
 	rte_bus_plug_t plug;         /**< Probe single device for drivers */
 	rte_bus_unplug_t unplug;     /**< Remove single device from driver */
+	rte_bus_parse_t parse;       /**< Parse a device name */
 };
 
 /**
-- 
2.1.4

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

* [PATCH v5 3/7] vdev: implement parse bus operation
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
  2017-06-20 23:30         ` [PATCH v5 1/7] bus: fix bus name registration Gaetan Rivet
  2017-06-20 23:30         ` [PATCH v5 2/7] bus: introduce parsing functionality Gaetan Rivet
@ 2017-06-20 23:30         ` Gaetan Rivet
  2017-06-27 15:59           ` Bruce Richardson
  2017-06-20 23:30         ` [PATCH v5 4/7] pci: " Gaetan Rivet
                           ` (5 subsequent siblings)
  8 siblings, 1 reply; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-20 23:30 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

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;
+}
+
 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);
-- 
2.1.4

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

* [PATCH v5 4/7] pci: implement parse bus operation
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
                           ` (2 preceding siblings ...)
  2017-06-20 23:30         ` [PATCH v5 3/7] vdev: implement parse bus operation Gaetan Rivet
@ 2017-06-20 23:30         ` Gaetan Rivet
  2017-06-27 16:18           ` Bruce Richardson
  2017-06-20 23:30         ` [PATCH v5 5/7] bus: add helper to find a bus from a device name Gaetan Rivet
                           ` (4 subsequent siblings)
  8 siblings, 1 reply; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-20 23:30 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 +++++++
 lib/librte_eal/common/eal_common_bus.c          | 16 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 19 +++++++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
 5 files changed, 63 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 150b0f7..3517d74 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -197,3 +197,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index b6bf57e..e69ce38 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -215,3 +215,19 @@ rte_bus_find_device(const struct rte_device *start,
 	}
 	return dev;
 }
+
+static int
+bus_cmp_name(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return strncmp(bus->name, name,
+		       strlen(bus->name));
+}
+
+/* find a bus by its name */
+struct rte_bus *
+rte_bus_from_name(const char *str)
+{
+	return rte_bus_find(bus_cmp_name, str, NULL);
+}
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 00d48d9..0f3ecdb 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -450,6 +450,24 @@ rte_pci_dump(FILE *f)
 	}
 }
 
+/*
+ * Parse a device entry
+ * typeof(addr): (struct rte_pci_addr *)
+ */
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	int parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr)
+		*out = pci_addr;
+	return !parse;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -505,6 +523,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 05503ea..da8b8a1 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -268,6 +268,20 @@ rte_bus_find_device(const struct rte_device *start,
  */
 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 
+/*
+ * Find a bus handle by its name.
+ * Compares the name of each bus up until any invalid character
+ * in the matched pattern.
+ *
+ * @param str
+ *	A null terminated character string.
+ *
+ * @return
+ *	A pointer to a bus if found.
+ *	NULL if no bus matches.
+ */
+struct rte_bus *rte_bus_from_name(const char *str);
+
 /**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index e0a056d..6607acc 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -201,3 +201,10 @@ DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
-- 
2.1.4

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

* [PATCH v5 5/7] bus: add helper to find a bus from a device name
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
                           ` (3 preceding siblings ...)
  2017-06-20 23:30         ` [PATCH v5 4/7] pci: " Gaetan Rivet
@ 2017-06-20 23:30         ` Gaetan Rivet
  2017-06-27 16:26           ` Bruce Richardson
  2017-06-27 18:55           ` Jan Blunck
  2017-06-20 23:30         ` [PATCH v5 6/7] vdev: expose bus name Gaetan Rivet
                           ` (3 subsequent siblings)
  8 siblings, 2 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-20 23:30 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Find which bus should be able to parse this device name into an internal
device representation.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
 lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
 4 files changed, 29 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 3517d74..04fa882 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -202,5 +202,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index e69ce38..e9fbc03 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -231,3 +231,18 @@ rte_bus_from_name(const char *str)
 {
 	return rte_bus_find(bus_cmp_name, str, NULL);
 }
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return !(bus->parse && bus->parse(name, NULL) == 0);
+}
+
+/* find a bus capable of parsing a device description */
+struct rte_bus *
+rte_bus_from_dev(const char *str)
+{
+	return rte_bus_find(bus_can_parse, str, NULL);
+}
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index da8b8a1..61d9e6e 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -283,6 +283,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 struct rte_bus *rte_bus_from_name(const char *str);
 
 /**
+ * Find a bus capable of identifying a device.
+ *
+ * @param str
+ *   A device identifier (PCI address, virtual PMD name, ...).
+ *
+ * @return
+ *   A valid bus handle if found.
+ *   NULL if no bus is able to parse this device.
+ */
+struct rte_bus *rte_bus_from_dev(const char *str);
+
+/**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
  */
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 6607acc..a5127d6 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -206,5 +206,6 @@ DPDK_17.08 {
 	global:
 
 	rte_bus_from_name;
+	rte_bus_from_dev;
 
 } DPDK_17.05;
-- 
2.1.4

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

* [PATCH v5 6/7] vdev: expose bus name
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
                           ` (4 preceding siblings ...)
  2017-06-20 23:30         ` [PATCH v5 5/7] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-06-20 23:30         ` Gaetan Rivet
  2017-06-20 23:30         ` [PATCH v5 7/7] devargs: parse bus info Gaetan Rivet
                           ` (2 subsequent siblings)
  8 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-20 23:30 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c  | 2 +-
 lib/librte_eal/common/include/rte_vdev.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 8dd4c88..221146e 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -404,6 +404,6 @@ static void rte_vdev_bus_register(void)
 		return;
 
 	registered = 1;
-	rte_vdev_bus.name = RTE_STR(virtual);
+	rte_vdev_bus.name = VIRTUAL_BUS_NAME;
 	rte_bus_register(&rte_vdev_bus);
 }
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index e6b678e..2d02c68 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -41,6 +41,8 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_devargs.h>
 
+#define VIRTUAL_BUS_NAME "virtual"
+
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
-- 
2.1.4

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

* [PATCH v5 7/7] devargs: parse bus info
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
                           ` (5 preceding siblings ...)
  2017-06-20 23:30         ` [PATCH v5 6/7] vdev: expose bus name Gaetan Rivet
@ 2017-06-20 23:30         ` Gaetan Rivet
  2017-06-27 16:01         ` [PATCH v5 0/7] rte_bus parse API Bruce Richardson
  2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
  8 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-06-20 23:30 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_devargs.c  | 15 ++++++++++++++-
 lib/librte_eal/common/eal_common_vdev.c     |  6 ++++--
 lib/librte_eal/common/include/rte_devargs.h |  3 +++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index ffa8ad9..d5f297d 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -83,6 +83,8 @@ int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
+	const char *dev = devargs_str;
+	struct rte_bus *bus;
 	char *buf = NULL;
 	int ret;
 
@@ -94,7 +96,18 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	memset(devargs, 0, sizeof(*devargs));
 	devargs->type = devtype;
 
-	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
+	bus = rte_bus_from_name(dev);
+	if (bus) {
+		dev += strlen(bus->name) + 1;
+	} else {
+		bus = rte_bus_from_dev(dev);
+		if (!bus) {
+			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
+			goto fail;
+		}
+	}
+	devargs->bus = bus;
+	if (rte_eal_parse_devargs_str(dev, &buf, &devargs->args))
 		goto fail;
 
 	switch (devargs->type) {
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 221146e..7cc3c6c 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -182,6 +182,7 @@ alloc_devargs(const char *name, const char *args)
 		return NULL;
 
 	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	devargs->bus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	if (args)
 		devargs->args = strdup(args);
 
@@ -294,12 +295,13 @@ vdev_scan(void)
 {
 	struct rte_vdev_device *dev;
 	struct rte_devargs *devargs;
+	struct rte_bus *vbus;
 
 	/* for virtual devices we scan the devargs_list populated via cmdline */
-
+	vbus = rte_bus_from_name(VIRTUAL_BUS_NAME);
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (devargs->bus != vbus)
 			continue;
 
 		dev = find_vdev(devargs->virt.drv_name);
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 88120a1..1f50a24 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -51,6 +51,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#include <rte_bus.h>
 
 /**
  * Type of generic device
@@ -89,6 +90,8 @@ struct rte_devargs {
 			char drv_name[32];
 		} virt;
 	};
+	/** Bus handle for the device. */
+	struct rte_bus *bus;
 	/** Arguments string as given by user or "" for no argument. */
 	char *args;
 };
-- 
2.1.4

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

* Re: [PATCH v5 1/7] bus: fix bus name registration
  2017-06-20 23:30         ` [PATCH v5 1/7] bus: fix bus name registration Gaetan Rivet
@ 2017-06-27 15:53           ` Bruce Richardson
  2017-06-27 19:19           ` Jan Blunck
  1 sibling, 0 replies; 123+ messages in thread
From: Bruce Richardson @ 2017-06-27 15:53 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev, stable

On Wed, Jun 21, 2017 at 01:30:30AM +0200, Gaetan Rivet wrote:
> The default bus registration function should not result in buses
> registering with double quotes within their names.
> 
> Fixes: a97725791eec ("bus: introduce bus abstraction")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>

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

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

* Re: [PATCH v5 2/7] bus: introduce parsing functionality
  2017-06-20 23:30         ` [PATCH v5 2/7] bus: introduce parsing functionality Gaetan Rivet
@ 2017-06-27 15:54           ` Bruce Richardson
  2017-06-27 19:26           ` Jan Blunck
  1 sibling, 0 replies; 123+ messages in thread
From: Bruce Richardson @ 2017-06-27 15:54 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

On Wed, Jun 21, 2017 at 01:30:31AM +0200, Gaetan Rivet wrote:
> This operation can be used either to validate that a device
> representation can be understood by a bus, as well as store the resulting
> specialized device representation in any format determined by the bus.
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>

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

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

* Re: [PATCH v5 3/7] vdev: implement parse bus operation
  2017-06-20 23:30         ` [PATCH v5 3/7] vdev: implement parse bus operation Gaetan Rivet
@ 2017-06-27 15:59           ` Bruce Richardson
  0 siblings, 0 replies; 123+ messages in thread
From: Bruce Richardson @ 2017-06-27 15:59 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

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>

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

* Re: [PATCH v5 0/7] rte_bus parse API
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
                           ` (6 preceding siblings ...)
  2017-06-20 23:30         ` [PATCH v5 7/7] devargs: parse bus info Gaetan Rivet
@ 2017-06-27 16:01         ` Bruce Richardson
  2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
  8 siblings, 0 replies; 123+ messages in thread
From: Bruce Richardson @ 2017-06-27 16:01 UTC (permalink / raw)
  To: Gaetan Rivet
  Cc: dev, Jan Blunck, Stephen Hemminger, Maxime Coquelin, Jerin Jacob,
	David Marchand

On Wed, Jun 21, 2017 at 01:30:29AM +0200, Gaetan Rivet wrote:
> Following the evolutions announced in [1], here is the first part of
> the rte_devargs rework planned for 17.08. The rationale has been partially
> explained in [2].
> 
> This first part covers the introduction of the necessary facilities in
> rte_bus to allow for generic device parsing. This API is implemented for
> the virtual and PCI buses. Additionally, this rte_bus evolution is being
> used within rte_devargs to characterize a device type by its bus.
> This work is the first of two parts to reduce the dependency of the EAL
> upon specific bus implementations.
> 
> Two public functions are added to rte_bus to help bus recognition:
> 
> - rte_bus_from_name
> - rte_bus_from_dev
> 
> These functions are made public because the bus handle within devargs
> becomes the generic device type. Recognizing device types is useful for
> buses and PMDs alike.
> The modified rte_devargs parsing allows declaring on the EAL command line
> explicit buses to handle a device. The format is as follow:
> 
>   --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
>   -w PCI:00:02.0 -w 00:03.0
> 
> This explicit bus designation is optional; no evolution is currently
> forced on users to migrate to this new format. The separating character is
> arbitrary and can be any character illegal within a bus name.
> Subsequently, what is allowed within a bus name has been formally
> defined and is now enforced.
> 
> [1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
> [2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html
> 
> This patchset depends on:
> 
> bus: attach / detach API
> http://dpdk.org/ml/archives/dev/2017-May/066330.html
> http://dpdk.org/dev/patchwork/patch/24489/
> 
Just to note there are some errors on apply with this set after applying
the latest version of the dependent patches. Nothing that's hard to fix,
mind - this set just needs a new version after the attach/detach API set
is applied.

/Bruce

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

* Re: [PATCH v5 4/7] pci: implement parse bus operation
  2017-06-20 23:30         ` [PATCH v5 4/7] pci: " Gaetan Rivet
@ 2017-06-27 16:18           ` Bruce Richardson
  0 siblings, 0 replies; 123+ messages in thread
From: Bruce Richardson @ 2017-06-27 16:18 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

On Wed, Jun 21, 2017 at 01:30:33AM +0200, Gaetan Rivet wrote:
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 +++++++
>  lib/librte_eal/common/eal_common_bus.c          | 16 ++++++++++++++++
>  lib/librte_eal/common/eal_common_pci.c          | 19 +++++++++++++++++++
>  lib/librte_eal/common/include/rte_bus.h         | 14 ++++++++++++++
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
>  5 files changed, 63 insertions(+)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> index 150b0f7..3517d74 100644
> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> @@ -197,3 +197,10 @@ DPDK_17.05 {
>  	vfio_get_group_no;
>  
>  } DPDK_17.02;
> +
> +DPDK_17.08 {
> +	global:
> +
> +	rte_bus_from_name;
> +
> +} DPDK_17.05;
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> index b6bf57e..e69ce38 100644
> --- a/lib/librte_eal/common/eal_common_bus.c
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -215,3 +215,19 @@ rte_bus_find_device(const struct rte_device *start,
>  	}
>  	return dev;
>  }
> +
> +static int
> +bus_cmp_name(const struct rte_bus *bus, const void *_name)
> +{
> +	const char *name = _name;
> +
> +	return strncmp(bus->name, name,
> +		       strlen(bus->name));
> +}
> +
> +/* find a bus by its name */
> +struct rte_bus *
> +rte_bus_from_name(const char *str)
> +{
> +	return rte_bus_find(bus_cmp_name, str, NULL);
> +}

I think the rte_bus_from_name changes should go in a separate patch, as
they are not part of the PCI changes.

Content-wise, it looks good though, so keep my ack on both patches if
split.

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

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

* Re: [PATCH v5 5/7] bus: add helper to find a bus from a device name
  2017-06-20 23:30         ` [PATCH v5 5/7] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-06-27 16:26           ` Bruce Richardson
  2017-06-27 18:55           ` Jan Blunck
  1 sibling, 0 replies; 123+ messages in thread
From: Bruce Richardson @ 2017-06-27 16:26 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

On Wed, Jun 21, 2017 at 01:30:34AM +0200, Gaetan Rivet wrote:
> Find which bus should be able to parse this device name into an internal
> device representation.
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>

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

* Re: [PATCH v5 5/7] bus: add helper to find a bus from a device name
  2017-06-20 23:30         ` [PATCH v5 5/7] bus: add helper to find a bus from a device name Gaetan Rivet
  2017-06-27 16:26           ` Bruce Richardson
@ 2017-06-27 18:55           ` Jan Blunck
  2017-06-28 17:03             ` Thomas Monjalon
  1 sibling, 1 reply; 123+ messages in thread
From: Jan Blunck @ 2017-06-27 18:55 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> Find which bus should be able to parse this device name into an internal
> device representation.
>
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  1 +
>  lib/librte_eal/common/eal_common_bus.c          | 15 +++++++++++++++
>  lib/librte_eal/common/include/rte_bus.h         | 12 ++++++++++++
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  1 +
>  4 files changed, 29 insertions(+)
>
> diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> index 3517d74..04fa882 100644
> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> @@ -202,5 +202,6 @@ DPDK_17.08 {
>         global:
>
>         rte_bus_from_name;
> +       rte_bus_from_dev;
>
>  } DPDK_17.05;
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> index e69ce38..e9fbc03 100644
> --- a/lib/librte_eal/common/eal_common_bus.c
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -231,3 +231,18 @@ rte_bus_from_name(const char *str)
>  {
>         return rte_bus_find(bus_cmp_name, str, NULL);
>  }
> +
> +static int
> +bus_can_parse(const struct rte_bus *bus, const void *_name)
> +{
> +       const char *name = _name;
> +
> +       return !(bus->parse && bus->parse(name, NULL) == 0);
> +}
> +
> +/* find a bus capable of parsing a device description */
> +struct rte_bus *
> +rte_bus_from_dev(const char *str)
> +{
> +       return rte_bus_find(bus_can_parse, str, NULL);
> +}
> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> index da8b8a1..61d9e6e 100644
> --- a/lib/librte_eal/common/include/rte_bus.h
> +++ b/lib/librte_eal/common/include/rte_bus.h
> @@ -283,6 +283,18 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
>  struct rte_bus *rte_bus_from_name(const char *str);
>
>  /**
> + * Find a bus capable of identifying a device.
> + *
> + * @param str
> + *   A device identifier (PCI address, virtual PMD name, ...).
> + *
> + * @return
> + *   A valid bus handle if found.
> + *   NULL if no bus is able to parse this device.
> + */
> +struct rte_bus *rte_bus_from_dev(const char *str);

I still don't agree with this. The bus name should be passed
explicitly by the user of the API.

NAK.


> +
> +/**
>   * Helper for Bus registration.
>   * The constructor has higher priority than PMD constructors.
>   */
> diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> index 6607acc..a5127d6 100644
> --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
> @@ -206,5 +206,6 @@ DPDK_17.08 {
>         global:
>
>         rte_bus_from_name;
> +       rte_bus_from_dev;
>
>  } DPDK_17.05;
> --
> 2.1.4
>

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

* Re: [PATCH v5 1/7] bus: fix bus name registration
  2017-06-20 23:30         ` [PATCH v5 1/7] bus: fix bus name registration Gaetan Rivet
  2017-06-27 15:53           ` Bruce Richardson
@ 2017-06-27 19:19           ` Jan Blunck
  2017-07-04  1:05             ` Gaëtan Rivet
  1 sibling, 1 reply; 123+ messages in thread
From: Jan Blunck @ 2017-06-27 19:19 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev, stable

On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> The default bus registration function should not result in buses
> registering with double quotes within their names.
>

This is breaking expectations with users. All other registration macro
pass the names through the stringification. The problem is that you
pass in the name as a string already ("PCI" instead of PCI).


> Fixes: a97725791eec ("bus: introduce bus abstraction")
> Cc: stable@dpdk.org
>
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/common/include/rte_bus.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> index fcc2442..b220299 100644
> --- a/lib/librte_eal/common/include/rte_bus.h
> +++ b/lib/librte_eal/common/include/rte_bus.h
> @@ -254,7 +254,7 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
>  #define RTE_REGISTER_BUS(nm, bus) \
>  static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
>  {\
> -       (bus).name = RTE_STR(nm);\
> +       (bus).name = nm;\
>         rte_bus_register(&bus); \
>  }
>
> --
> 2.1.4
>

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

* Re: [PATCH v5 2/7] bus: introduce parsing functionality
  2017-06-20 23:30         ` [PATCH v5 2/7] bus: introduce parsing functionality Gaetan Rivet
  2017-06-27 15:54           ` Bruce Richardson
@ 2017-06-27 19:26           ` Jan Blunck
  2017-07-04  1:35             ` Gaëtan Rivet
  1 sibling, 1 reply; 123+ messages in thread
From: Jan Blunck @ 2017-06-27 19:26 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> This operation can be used either to validate that a device
> representation can be understood by a bus, as well as store the resulting
> specialized device representation in any format determined by the bus.
>

Again, I don't think this makes sense to have. Also there is no user
for this as far as I can see. The bus specific device representation
should come from the scan function instead of this.


> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> index b220299..05503ea 100644
> --- a/lib/librte_eal/common/include/rte_bus.h
> +++ b/lib/librte_eal/common/include/rte_bus.h
> @@ -117,6 +117,26 @@ typedef struct rte_device * (*rte_bus_plug_t)(struct rte_devargs *da);
>  typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
>
>  /**
> + * Bus specific parsing function.
> + * Validates the syntax used in the textual representation of a device,
> + * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
> + * device representation to ``addr``.
> + *
> + * @param[in] name
> + *     device textual description
> + *
> + * @param[out] addr
> + *     device information location address, into which parsed info
> + *     should be written. If NULL, nothing should be written, which
> + *     is not an error.
> + *
> + * @return
> + *     0 if parsing was successful.
> + *     !0 for any error.
> + */
> +typedef int (*rte_bus_parse_t)(const char *name, void *addr);
> +
> +/**
>   * A structure describing a generic bus.
>   */
>  struct rte_bus {
> @@ -127,6 +147,7 @@ struct rte_bus {
>         rte_bus_find_device_t find_device; /**< Find device on bus */
>         rte_bus_plug_t plug;         /**< Probe single device for drivers */
>         rte_bus_unplug_t unplug;     /**< Remove single device from driver */
> +       rte_bus_parse_t parse;       /**< Parse a device name */
>  };
>
>  /**
> --
> 2.1.4
>

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

* Re: [PATCH v5 5/7] bus: add helper to find a bus from a device name
  2017-06-27 18:55           ` Jan Blunck
@ 2017-06-28 17:03             ` Thomas Monjalon
  2017-06-29  7:56               ` Jan Blunck
  0 siblings, 1 reply; 123+ messages in thread
From: Thomas Monjalon @ 2017-06-28 17:03 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, Gaetan Rivet

27/06/2017 20:55, Jan Blunck:
> On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> >  /**
> > + * Find a bus capable of identifying a device.
> > + *
> > + * @param str
> > + *   A device identifier (PCI address, virtual PMD name, ...).
> > + *
> > + * @return
> > + *   A valid bus handle if found.
> > + *   NULL if no bus is able to parse this device.
> > + */
> > +struct rte_bus *rte_bus_from_dev(const char *str);
> 
> I still don't agree with this. The bus name should be passed
> explicitly by the user of the API.
> 
> NAK.

Please explain why you think the bus name should be explicit.
If the bus is ambiguous, it can be explicited by the user.

I see some good benefits in being tolerant with the bus/device
representation. It provides a smooth transition to the bus model.

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

* Re: [PATCH v5 5/7] bus: add helper to find a bus from a device name
  2017-06-28 17:03             ` Thomas Monjalon
@ 2017-06-29  7:56               ` Jan Blunck
  2017-06-29  8:21                 ` Thomas Monjalon
  2017-06-29 10:23                 ` Gaëtan Rivet
  0 siblings, 2 replies; 123+ messages in thread
From: Jan Blunck @ 2017-06-29  7:56 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Gaetan Rivet

On Wed, Jun 28, 2017 at 7:03 PM, Thomas Monjalon <thomas@monjalon.net> wrote:
> 27/06/2017 20:55, Jan Blunck:
>> On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
>> >  /**
>> > + * Find a bus capable of identifying a device.
>> > + *
>> > + * @param str
>> > + *   A device identifier (PCI address, virtual PMD name, ...).
>> > + *
>> > + * @return
>> > + *   A valid bus handle if found.
>> > + *   NULL if no bus is able to parse this device.
>> > + */
>> > +struct rte_bus *rte_bus_from_dev(const char *str);
>>
>> I still don't agree with this. The bus name should be passed
>> explicitly by the user of the API.
>>
>> NAK.
>
> Please explain why you think the bus name should be explicit.
> If the bus is ambiguous, it can be explicited by the user.
>
> I see some good benefits in being tolerant with the bus/device
> representation. It provides a smooth transition to the bus model.
>

We build libraries. The applications we build with the help of those
libraries get notified by the OS about device events. Those devices
are chields of their parent bus. At the time the event is fired the OS
already knows about:

- the bus name (parent)
- the device name (child)
- additional event parameters (environment)

Blame me that I probably spent too much time with Kay Sievers and
GregKH to understand that device naming is easy to get wrong. Just
look at the hyperv device names and how they switched to the UUID
scheme. I don't think that hyperv is the only bus that uses UUID as
device identification. We should not codify a policy of how to deduce
a bus name from a given device name if that is knowledge that is
already present externally. Otherwise I fear this part of the EAL will
be subject to constant churn.

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

* Re: [PATCH v5 5/7] bus: add helper to find a bus from a device name
  2017-06-29  7:56               ` Jan Blunck
@ 2017-06-29  8:21                 ` Thomas Monjalon
  2017-06-29 10:23                 ` Gaëtan Rivet
  1 sibling, 0 replies; 123+ messages in thread
From: Thomas Monjalon @ 2017-06-29  8:21 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, Gaetan Rivet

29/06/2017 09:56, Jan Blunck:
> On Wed, Jun 28, 2017 at 7:03 PM, Thomas Monjalon <thomas@monjalon.net> wrote:
> > 27/06/2017 20:55, Jan Blunck:
> >> On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> >> >  /**
> >> > + * Find a bus capable of identifying a device.
> >> > + *
> >> > + * @param str
> >> > + *   A device identifier (PCI address, virtual PMD name, ...).
> >> > + *
> >> > + * @return
> >> > + *   A valid bus handle if found.
> >> > + *   NULL if no bus is able to parse this device.
> >> > + */
> >> > +struct rte_bus *rte_bus_from_dev(const char *str);
> >>
> >> I still don't agree with this. The bus name should be passed
> >> explicitly by the user of the API.
> >>
> >> NAK.
> >
> > Please explain why you think the bus name should be explicit.
> > If the bus is ambiguous, it can be explicited by the user.
> >
> > I see some good benefits in being tolerant with the bus/device
> > representation. It provides a smooth transition to the bus model.
> >
> 
> We build libraries. The applications we build with the help of those
> libraries get notified by the OS about device events. Those devices
> are chields of their parent bus. At the time the event is fired the OS
> already knows about:
> 
> - the bus name (parent)
> - the device name (child)
> - additional event parameters (environment)
> 
> Blame me that I probably spent too much time with Kay Sievers and
> GregKH to understand that device naming is easy to get wrong. Just
> look at the hyperv device names and how they switched to the UUID
> scheme. I don't think that hyperv is the only bus that uses UUID as
> device identification. We should not codify a policy of how to deduce
> a bus name from a given device name if that is knowledge that is
> already present externally. Otherwise I fear this part of the EAL will
> be subject to constant churn.

OK I understand your point that it is a weak identification.
It is as weak as what we have currently.
It works at least when we have only PCI and VDEV.
However it does not prevent to use a strong identification with
bus and parent names.
I see rte_bus_from_dev() as a helper to transition to the new strong
identification model. So we could remove it in few releases.
Does it make sense?

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

* Re: [PATCH v5 5/7] bus: add helper to find a bus from a device name
  2017-06-29  7:56               ` Jan Blunck
  2017-06-29  8:21                 ` Thomas Monjalon
@ 2017-06-29 10:23                 ` Gaëtan Rivet
  2017-06-29 10:30                   ` Richardson, Bruce
  1 sibling, 1 reply; 123+ messages in thread
From: Gaëtan Rivet @ 2017-06-29 10:23 UTC (permalink / raw)
  To: Jan Blunck; +Cc: Thomas Monjalon, dev

On Thu, Jun 29, 2017 at 09:56:30AM +0200, Jan Blunck wrote:
> On Wed, Jun 28, 2017 at 7:03 PM, Thomas Monjalon <thomas@monjalon.net> wrote:
> > 27/06/2017 20:55, Jan Blunck:
> >> On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> >> >  /**
> >> > + * Find a bus capable of identifying a device.
> >> > + *
> >> > + * @param str
> >> > + *   A device identifier (PCI address, virtual PMD name, ...).
> >> > + *
> >> > + * @return
> >> > + *   A valid bus handle if found.
> >> > + *   NULL if no bus is able to parse this device.
> >> > + */
> >> > +struct rte_bus *rte_bus_from_dev(const char *str);
> >>
> >> I still don't agree with this. The bus name should be passed
> >> explicitly by the user of the API.
> >>
> >> NAK.
> >
> > Please explain why you think the bus name should be explicit.
> > If the bus is ambiguous, it can be explicited by the user.
> >
> > I see some good benefits in being tolerant with the bus/device
> > representation. It provides a smooth transition to the bus model.
> >
> 
> We build libraries. The applications we build with the help of those
> libraries get notified by the OS about device events. Those devices
> are chields of their parent bus. At the time the event is fired the OS
> already knows about:
> 
> - the bus name (parent)
> - the device name (child)
> - additional event parameters (environment)
> 
> Blame me that I probably spent too much time with Kay Sievers and
> GregKH to understand that device naming is easy to get wrong. Just
> look at the hyperv device names and how they switched to the UUID
> scheme. I don't think that hyperv is the only bus that uses UUID as
> device identification. We should not codify a policy of how to deduce
> a bus name from a given device name if that is knowledge that is
> already present externally. Otherwise I fear this part of the EAL will
> be subject to constant churn.

I agree in the context of device events.
But this development concerns all device identification scheme, not only
in the context of hotplug where we can retrieve events giving proper
info. It is parsing user input as well (command line or configuration).

In this user-centric device specification, the issue is that the current
model expect the user to provide the bus implicitly by using the right
parameter (--vdev, -w). This identification *cannot* stay, as those are
parsed within the EAL and specifics are getting out.

What is left is thus a choice: either

* We let the current scheme work for a time, while the EAL is being cleaned
  out, during which we need some crutch to emulate the current behavior

* We force all users to migrate to the new format straight away with a
  full identification scheme.

I planned for both eventuality in my deprecation notice, by warning that
device parameters and definition might change this version. However,
while I thought that it was possible it would happen, I think it is best
to provide as much stability as possible while we work out the EAL
internals.

This API is only there because I choose to keep backward compatibility.
A compromise might be to make it private to the EAL (I proposed it
before but no one really responded so I haven't acted on it). This would
help the future transition to the fully-qualified-device-identifier that
we will have to require from our users.

I'd like to hear from other DPDK devs as I think that surprising users
is not something that should be done lightly. I understand your concern
and am not opposed to address it.

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH v5 5/7] bus: add helper to find a bus from a device name
  2017-06-29 10:23                 ` Gaëtan Rivet
@ 2017-06-29 10:30                   ` Richardson, Bruce
  0 siblings, 0 replies; 123+ messages in thread
From: Richardson, Bruce @ 2017-06-29 10:30 UTC (permalink / raw)
  To: Gaëtan Rivet, Jan Blunck; +Cc: Thomas Monjalon, dev



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Gaëtan Rivet
> Sent: Thursday, June 29, 2017 11:24 AM
> To: Jan Blunck <jblunck@infradead.org>
> Cc: Thomas Monjalon <thomas@monjalon.net>; dev <dev@dpdk.org>
> Subject: Re: [dpdk-dev] [PATCH v5 5/7] bus: add helper to find a bus from
> a device name
> 
> On Thu, Jun 29, 2017 at 09:56:30AM +0200, Jan Blunck wrote:
> > On Wed, Jun 28, 2017 at 7:03 PM, Thomas Monjalon <thomas@monjalon.net>
> wrote:
> > > 27/06/2017 20:55, Jan Blunck:
> > >> On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet
> <gaetan.rivet@6wind.com> wrote:
> > >> >  /**
> > >> > + * Find a bus capable of identifying a device.
> > >> > + *
> > >> > + * @param str
> > >> > + *   A device identifier (PCI address, virtual PMD name, ...).
> > >> > + *
> > >> > + * @return
> > >> > + *   A valid bus handle if found.
> > >> > + *   NULL if no bus is able to parse this device.
> > >> > + */
> > >> > +struct rte_bus *rte_bus_from_dev(const char *str);
> > >>
> > >> I still don't agree with this. The bus name should be passed
> > >> explicitly by the user of the API.
> > >>
> > >> NAK.
> > >
> > > Please explain why you think the bus name should be explicit.
> > > If the bus is ambiguous, it can be explicited by the user.
> > >
> > > I see some good benefits in being tolerant with the bus/device
> > > representation. It provides a smooth transition to the bus model.
> > >
> >
> > We build libraries. The applications we build with the help of those
> > libraries get notified by the OS about device events. Those devices
> > are chields of their parent bus. At the time the event is fired the OS
> > already knows about:
> >
> > - the bus name (parent)
> > - the device name (child)
> > - additional event parameters (environment)
> >
> > Blame me that I probably spent too much time with Kay Sievers and
> > GregKH to understand that device naming is easy to get wrong. Just
> > look at the hyperv device names and how they switched to the UUID
> > scheme. I don't think that hyperv is the only bus that uses UUID as
> > device identification. We should not codify a policy of how to deduce
> > a bus name from a given device name if that is knowledge that is
> > already present externally. Otherwise I fear this part of the EAL will
> > be subject to constant churn.
> 
> I agree in the context of device events.
> But this development concerns all device identification scheme, not only
> in the context of hotplug where we can retrieve events giving proper info.
> It is parsing user input as well (command line or configuration).
> 
> In this user-centric device specification, the issue is that the current
> model expect the user to provide the bus implicitly by using the right
> parameter (--vdev, -w). This identification *cannot* stay, as those are
> parsed within the EAL and specifics are getting out.
> 
> What is left is thus a choice: either
> 
> * We let the current scheme work for a time, while the EAL is being
> cleaned
>   out, during which we need some crutch to emulate the current behavior
> 
> * We force all users to migrate to the new format straight away with a
>   full identification scheme.
> 
> I planned for both eventuality in my deprecation notice, by warning that
> device parameters and definition might change this version. However, while
> I thought that it was possible it would happen, I think it is best to
> provide as much stability as possible while we work out the EAL internals.
> 
> This API is only there because I choose to keep backward compatibility.
> A compromise might be to make it private to the EAL (I proposed it before
> but no one really responded so I haven't acted on it). This would help the
> future transition to the fully-qualified-device-identifier that we will
> have to require from our users.
> 
> I'd like to hear from other DPDK devs as I think that surprising users is
> not something that should be done lightly. I understand your concern and
> am not opposed to address it.
> 

I'm all in favour of stability and backward compatibility, so I don't like the option of forcing users to change just now - especially as the whole picture is not yet complete. Once we are sure we have a fully settled new scheme, then we can being to deprecate the old.

/Bruce

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

* [PATCH v6 0/6] rte_bus parse API
  2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
                           ` (7 preceding siblings ...)
  2017-06-27 16:01         ` [PATCH v5 0/7] rte_bus parse API Bruce Richardson
@ 2017-07-04  0:58         ` Gaetan Rivet
  2017-07-04  0:58           ` [PATCH v6 1/6] bus: fix bus name registration Gaetan Rivet
                             ` (6 more replies)
  8 siblings, 7 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04  0:58 UTC (permalink / raw)
  To: dev
  Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Maxime Coquelin,
	Jerin Jacob, Bruce Richardson, David Marchand

Following the evolutions announced in [1], here is the first part of
the rte_devargs rework planned for 17.08. The rationale has been partially
explained in [2].

This first part covers the introduction of the necessary facilities in
rte_bus to allow for generic device parsing. This API is implemented for
the virtual and PCI buses. Additionally, this rte_bus evolution is being
used within rte_devargs to characterize a device type by its bus.
This work is the first of two parts to reduce the dependency of the EAL
upon specific bus implementations.

The modified rte_devargs parsing allows declaring on the EAL command line
explicit buses to handle a device. The format is as follow:

  --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
  -w PCI:00:02.0 -w 00:03.0

This explicit bus designation is optional; no evolution is currently
forced on users to migrate to this new format. The separating character is
arbitrary.

[1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
[2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html

This patchset depends on:

bus attach/detach API and hotplug rework
http://dpdk.org/ml/archives/dev/2017-June/069643.html
http://dpdk.org/dev/patchwork/patch/26135/

v1 -> v2:

  * fix PCI parse implementation

v2 --> v3:

  * Rebase the series on the new plug / unplug API

v3 --> v4:

  * Several bug fixes, commit log rewrite.
  * Follow the changes to the plug / unplug API.

v5:

  * Do not verify bus name on bus registration.
    Actually, a legal bus name is not defined anymore.
    The bus/device separator in a device declaration can be anything,
    as long as it is a single character.
    The behavior is otherwise unchanged.

v6:

  * Rebase upon new hotplug patchset version.
  * Rename rte_bus_from_dev as rte_bus_find_by_device_name.
    This function is now private to the EAL.
  * Remove rte_bus_from_name, as it has been integrated as
    rte_bus_find_by_name by Jan Blunck.
  * Reduce parsing ambiguity in rte_devargs.

Gaetan Rivet (6):
  bus: fix bus name registration
  bus: introduce parsing functionality
  vdev: implement parse bus operation
  pci: implement parse bus operation
  bus: add helper to find a bus from a device name
  devargs: parse bus info

 lib/librte_eal/common/eal_common_bus.c      | 15 +++++++
 lib/librte_eal/common/eal_common_devargs.c  | 42 +++++++++++++++----
 lib/librte_eal/common/eal_common_pci.c      | 15 +++++++
 lib/librte_eal/common/eal_common_vdev.c     | 64 +++++++++++++++--------------
 lib/librte_eal/common/eal_private.h         | 12 ++++++
 lib/librte_eal/common/include/rte_bus.h     | 23 ++++++++++-
 lib/librte_eal/common/include/rte_devargs.h |  3 ++
 7 files changed, 135 insertions(+), 39 deletions(-)

-- 
2.1.4

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

* [PATCH v6 1/6] bus: fix bus name registration
  2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
@ 2017-07-04  0:58           ` Gaetan Rivet
  2017-07-04 21:43             ` [PATCH] bus: fix driver registration Thomas Monjalon
  2017-07-04  0:58           ` [PATCH v6 2/6] bus: introduce parsing functionality Gaetan Rivet
                             ` (5 subsequent siblings)
  6 siblings, 1 reply; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04  0:58 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet, stable

The default bus registration function should not result in buses
registering with double quotes within their names.

Fixes: a97725791eec ("bus: introduce bus abstraction")
Cc: stable@dpdk.org

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 34ea9d5..c1c8fa5 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -258,7 +258,7 @@ struct rte_bus *rte_bus_find_by_name(const char *busname);
 #define RTE_REGISTER_BUS(nm, bus) \
 static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
 {\
-	(bus).name = RTE_STR(nm);\
+	(bus).name = nm;\
 	rte_bus_register(&bus); \
 }
 
-- 
2.1.4

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

* [PATCH v6 2/6] bus: introduce parsing functionality
  2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
  2017-07-04  0:58           ` [PATCH v6 1/6] bus: fix bus name registration Gaetan Rivet
@ 2017-07-04  0:58           ` Gaetan Rivet
  2017-07-04  0:58           ` [PATCH v6 3/6] vdev: implement parse bus operation Gaetan Rivet
                             ` (4 subsequent siblings)
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04  0:58 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

This operation can be used either to validate that a device
representation can be understood by a bus, as well as store the resulting
specialized device representation in any format determined by the bus.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index c1c8fa5..31995c7 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -138,6 +138,26 @@ typedef int (*rte_bus_plug_t)(struct rte_device *dev,
 typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
 
 /**
+ * Bus specific parsing function.
+ * Validates the syntax used in the textual representation of a device,
+ * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
+ * device representation to ``addr``.
+ *
+ * @param[in] name
+ *	device textual description
+ *
+ * @param[out] addr
+ *	device information location address, into which parsed info
+ *	should be written. If NULL, nothing should be written, which
+ *	is not an error.
+ *
+ * @return
+ *	0 if parsing was successful.
+ *	!0 for any error.
+ */
+typedef int (*rte_bus_parse_t)(const char *name, void *addr);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -148,6 +168,7 @@ struct rte_bus {
 	rte_bus_find_device_t find_device; /**< Find a device on the bus */
 	rte_bus_plug_t plug;         /**< Probe single device for drivers */
 	rte_bus_unplug_t unplug;     /**< Remove single device from driver */
+	rte_bus_parse_t parse;       /**< Parse a device name */
 };
 
 /**
-- 
2.1.4

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

* [PATCH v6 3/6] vdev: implement parse bus operation
  2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
  2017-07-04  0:58           ` [PATCH v6 1/6] bus: fix bus name registration Gaetan Rivet
  2017-07-04  0:58           ` [PATCH v6 2/6] bus: introduce parsing functionality Gaetan Rivet
@ 2017-07-04  0:58           ` Gaetan Rivet
  2017-07-04  0:58           ` [PATCH v6 4/6] pci: " Gaetan Rivet
                             ` (3 subsequent siblings)
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04  0:58 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 58 ++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index baf3c5b..75a7b93 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -102,6 +102,27 @@ static char *parse_driver_arg(const char *args)
 }
 
 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)) == 0)
+			break;
+		if (driver->driver.alias &&
+		    strncmp(driver->driver.alias, name,
+			    strlen(driver->driver.alias)) == 0)
+			break;
+	}
+	if (driver != NULL &&
+	    addr != NULL)
+		*out = driver;
+	return driver == NULL;
+}
+
+static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
 	const char *name;
@@ -115,36 +136,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;
-		}
-	}
-
-	/* 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;
-		}
+	if (vdev_parse(name, &driver)) {
+		ret = -1;
+		goto out;
 	}
-
+	dev->device.driver = &driver->driver;
+	ret = driver->probe(dev);
+	if (ret)
+		dev->device.driver = NULL;
 out:
 	free(drv_name);
 	return ret;
@@ -372,6 +371,7 @@ static struct rte_bus rte_vdev_bus = {
 	.find_device = vdev_find_device,
 	/* .plug = NULL, see comment on vdev_unplug */
 	.unplug = vdev_unplug,
+	.parse = vdev_parse,
 };
 
 RTE_REGISTER_BUS(VIRTUAL_BUS_NAME, rte_vdev_bus);
-- 
2.1.4

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

* [PATCH v6 4/6] pci: implement parse bus operation
  2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
                             ` (2 preceding siblings ...)
  2017-07-04  0:58           ` [PATCH v6 3/6] vdev: implement parse bus operation Gaetan Rivet
@ 2017-07-04  0:58           ` Gaetan Rivet
  2017-07-04  0:58           ` [PATCH v6 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
                             ` (2 subsequent siblings)
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04  0:58 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_pci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 5ee100e..9549e92 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -448,6 +448,20 @@ rte_pci_dump(FILE *f)
 	}
 }
 
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	bool parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr != NULL)
+		*out = pci_addr;
+	return parse == false;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -544,6 +558,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.find_device = pci_find_device,
 		.plug = pci_plug,
 		.unplug = pci_unplug,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
-- 
2.1.4

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

* [PATCH v6 5/6] bus: add helper to find a bus from a device name
  2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
                             ` (3 preceding siblings ...)
  2017-07-04  0:58           ` [PATCH v6 4/6] pci: " Gaetan Rivet
@ 2017-07-04  0:58           ` Gaetan Rivet
  2017-07-04 12:28             ` Gaëtan Rivet
  2017-07-04  0:58           ` [PATCH v6 6/6] devargs: parse bus info Gaetan Rivet
  2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
  6 siblings, 1 reply; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04  0:58 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Find which bus should be able to parse this device name into an internal
device representation.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_bus.c | 15 +++++++++++++++
 lib/librte_eal/common/eal_private.h    | 12 ++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 87b0c6e..b143f21 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -204,3 +204,18 @@ rte_bus_find_by_name(const char *busname)
 {
 	return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
 }
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return !(bus->parse && bus->parse(name, NULL) == 0);
+}
+
+/* find a bus capable of parsing a device description */
+struct rte_bus *
+rte_bus_find_by_device_name(const char *str)
+{
+	return rte_bus_find(NULL, bus_can_parse, str);
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 6cacce0..0836339 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void);
  */
 bool rte_eal_using_phys_addrs(void);
 
+/**
+ * Find a bus capable of identifying a device.
+ *
+ * @param str
+ *   A device identifier (PCI address, virtual PMD name, ...).
+ *
+ * @return
+ *   A valid bus handle if found.
+ *   NULL if no bus is able to parse this device.
+ */
+struct rte_bus *rte_bus_find_by_device_name(const char *str);
+
 #endif /* _EAL_PRIVATE_H_ */
-- 
2.1.4

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

* [PATCH v6 6/6] devargs: parse bus info
  2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
                             ` (4 preceding siblings ...)
  2017-07-04  0:58           ` [PATCH v6 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-07-04  0:58           ` Gaetan Rivet
  2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04  0:58 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_devargs.c  | 42 ++++++++++++++++++++++++-----
 lib/librte_eal/common/eal_common_vdev.c     |  6 +++--
 lib/librte_eal/common/include/rte_devargs.h |  3 +++
 3 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index ffa8ad9..102bd8d 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -78,12 +78,23 @@ rte_eal_parse_devargs_str(const char *devargs_str,
 	return 0;
 }
 
+static int
+bus_name_cmp(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return strncmp(bus->name, name,
+		       strlen(bus->name));
+}
+
 /* store a whitelist parameter for later parsing */
 int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
-	char *buf = NULL;
+	struct rte_bus *bus = NULL;
+	char *dev = NULL;
+	const char *devname;
 	int ret;
 
 	/* use malloc instead of rte_malloc as it's called early at init */
@@ -94,34 +105,51 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	memset(devargs, 0, sizeof(*devargs));
 	devargs->type = devtype;
 
-	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
+	if (rte_eal_parse_devargs_str(devargs_str, &dev, &devargs->args))
 		goto fail;
+	devname = dev;
+	do {
+		bus = rte_bus_find(bus, bus_name_cmp, dev);
+		if (bus == NULL)
+			break;
+		devname = dev + strlen(bus->name) + 1;
+		if (rte_bus_find_by_device_name(devname) == bus)
+			break;
+		devname = dev;
+	} while (1);
+	if (bus == NULL) {
+		bus = rte_bus_find_by_device_name(devname);
+		if (bus == NULL) {
+			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
+			goto fail;
+		}
+	}
+	devargs->bus = bus;
 
 	switch (devargs->type) {
 	case RTE_DEVTYPE_WHITELISTED_PCI:
 	case RTE_DEVTYPE_BLACKLISTED_PCI:
 		/* try to parse pci identifier */
-		if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
-		    eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0)
+		if (bus->parse(devname, &devargs->pci.addr) != 0)
 			goto fail;
 
 		break;
 	case RTE_DEVTYPE_VIRTUAL:
 		/* save driver name */
 		ret = snprintf(devargs->virt.drv_name,
-			       sizeof(devargs->virt.drv_name), "%s", buf);
+			       sizeof(devargs->virt.drv_name), "%s", devname);
 		if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name))
 			goto fail;
 
 		break;
 	}
 
-	free(buf);
+	free(dev);
 	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
 	return 0;
 
 fail:
-	free(buf);
+	free(dev);
 	if (devargs) {
 		free(devargs->args);
 		free(devargs);
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 75a7b93..79ec528 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -177,6 +177,7 @@ alloc_devargs(const char *name, const char *args)
 		return NULL;
 
 	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	devargs->bus = rte_bus_find_by_name(VIRTUAL_BUS_NAME);
 	if (args)
 		devargs->args = strdup(args);
 
@@ -289,12 +290,13 @@ vdev_scan(void)
 {
 	struct rte_vdev_device *dev;
 	struct rte_devargs *devargs;
+	struct rte_bus *vbus;
 
 	/* for virtual devices we scan the devargs_list populated via cmdline */
-
+	vbus = rte_bus_find_by_name(VIRTUAL_BUS_NAME);
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (devargs->bus != vbus)
 			continue;
 
 		dev = find_vdev(devargs->virt.drv_name);
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 88120a1..1f50a24 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -51,6 +51,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#include <rte_bus.h>
 
 /**
  * Type of generic device
@@ -89,6 +90,8 @@ struct rte_devargs {
 			char drv_name[32];
 		} virt;
 	};
+	/** Bus handle for the device. */
+	struct rte_bus *bus;
 	/** Arguments string as given by user or "" for no argument. */
 	char *args;
 };
-- 
2.1.4

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

* Re: [PATCH v5 1/7] bus: fix bus name registration
  2017-06-27 19:19           ` Jan Blunck
@ 2017-07-04  1:05             ` Gaëtan Rivet
  0 siblings, 0 replies; 123+ messages in thread
From: Gaëtan Rivet @ 2017-07-04  1:05 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev, stable

On Tue, Jun 27, 2017 at 09:19:14PM +0200, Jan Blunck wrote:
> On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> > The default bus registration function should not result in buses
> > registering with double quotes within their names.
> >
> 
> This is breaking expectations with users. All other registration macro
> pass the names through the stringification. The problem is that you
> pass in the name as a string already ("PCI" instead of PCI).
> 
> 

I agree that it does not behave as expected.
However, all buses are currently using it this way, and this
cannot be fixed if maintainers keep using public define's
for their bus name.

> > Fixes: a97725791eec ("bus: introduce bus abstraction")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > ---
> >  lib/librte_eal/common/include/rte_bus.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> > index fcc2442..b220299 100644
> > --- a/lib/librte_eal/common/include/rte_bus.h
> > +++ b/lib/librte_eal/common/include/rte_bus.h
> > @@ -254,7 +254,7 @@ struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
> >  #define RTE_REGISTER_BUS(nm, bus) \
> >  static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
> >  {\
> > -       (bus).name = RTE_STR(nm);\
> > +       (bus).name = nm;\
> >         rte_bus_register(&bus); \
> >  }
> >
> > --
> > 2.1.4
> >

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH v5 2/7] bus: introduce parsing functionality
  2017-06-27 19:26           ` Jan Blunck
@ 2017-07-04  1:35             ` Gaëtan Rivet
  0 siblings, 0 replies; 123+ messages in thread
From: Gaëtan Rivet @ 2017-07-04  1:35 UTC (permalink / raw)
  To: Jan Blunck; +Cc: dev

On Tue, Jun 27, 2017 at 09:26:20PM +0200, Jan Blunck wrote:
> On Wed, Jun 21, 2017 at 1:30 AM, Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> > This operation can be used either to validate that a device
> > representation can be understood by a bus, as well as store the resulting
> > specialized device representation in any format determined by the bus.
> >
> 
> Again, I don't think this makes sense to have. Also there is no user
> for this as far as I can see. The bus specific device representation
> should come from the scan function instead of this.
> 
> 

I think it makes sense that scanning would store this representation
yes. The issue is that it requires another rte_bus_scan API evolution,
which is beyond this patchset.

Keep in mind that I was bound when writing this to follow the existing
API. I agree that some cleanup could come up in the EAL, but it cannot
all happen at once. These first steps (generic devargs / vdev & PCI move
to drivers/bus) serve to trim the EAL before these changes.

> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > ---
> >  lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
> >  1 file changed, 21 insertions(+)
> >
> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> > index b220299..05503ea 100644
> > --- a/lib/librte_eal/common/include/rte_bus.h
> > +++ b/lib/librte_eal/common/include/rte_bus.h
> > @@ -117,6 +117,26 @@ typedef struct rte_device * (*rte_bus_plug_t)(struct rte_devargs *da);
> >  typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
> >
> >  /**
> > + * Bus specific parsing function.
> > + * Validates the syntax used in the textual representation of a device,
> > + * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
> > + * device representation to ``addr``.
> > + *
> > + * @param[in] name
> > + *     device textual description
> > + *
> > + * @param[out] addr
> > + *     device information location address, into which parsed info
> > + *     should be written. If NULL, nothing should be written, which
> > + *     is not an error.
> > + *
> > + * @return
> > + *     0 if parsing was successful.
> > + *     !0 for any error.
> > + */
> > +typedef int (*rte_bus_parse_t)(const char *name, void *addr);
> > +
> > +/**
> >   * A structure describing a generic bus.
> >   */
> >  struct rte_bus {
> > @@ -127,6 +147,7 @@ struct rte_bus {
> >         rte_bus_find_device_t find_device; /**< Find device on bus */
> >         rte_bus_plug_t plug;         /**< Probe single device for drivers */
> >         rte_bus_unplug_t unplug;     /**< Remove single device from driver */
> > +       rte_bus_parse_t parse;       /**< Parse a device name */
> >  };
> >
> >  /**
> > --
> > 2.1.4
> >

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH v6 5/6] bus: add helper to find a bus from a device name
  2017-07-04  0:58           ` [PATCH v6 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-07-04 12:28             ` Gaëtan Rivet
  0 siblings, 0 replies; 123+ messages in thread
From: Gaëtan Rivet @ 2017-07-04 12:28 UTC (permalink / raw)
  To: dev; +Cc: Jan Blunck, Stephen Hemminger, Bruce Richardson, Gowrishankar

I made this API private, however we can see the bonding PMD could use
this kind of facility:

http://dpdk.org/ml/archives/dev/2017-July/070087.html

I know the failsafe could leverage this, as well as another bus idea I
threw together a few weeks ago[1].

So maybe I should make it public? This can always be fixed
past-integration though, and I'd prefer being able to go forward on the
PCI move.

[1]: http://dpdk.org/ml/archives/dev/2017-June/067546.html

On Tue, Jul 04, 2017 at 02:58:32AM +0200, Gaetan Rivet wrote:
> Find which bus should be able to parse this device name into an internal
> device representation.
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/common/eal_common_bus.c | 15 +++++++++++++++
>  lib/librte_eal/common/eal_private.h    | 12 ++++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> index 87b0c6e..b143f21 100644
> --- a/lib/librte_eal/common/eal_common_bus.c
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -204,3 +204,18 @@ rte_bus_find_by_name(const char *busname)
>  {
>  	return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
>  }
> +
> +static int
> +bus_can_parse(const struct rte_bus *bus, const void *_name)
> +{
> +	const char *name = _name;
> +
> +	return !(bus->parse && bus->parse(name, NULL) == 0);
> +}
> +
> +/* find a bus capable of parsing a device description */
> +struct rte_bus *
> +rte_bus_find_by_device_name(const char *str)
> +{
> +	return rte_bus_find(NULL, bus_can_parse, str);
> +}
> diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
> index 6cacce0..0836339 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void);
>   */
>  bool rte_eal_using_phys_addrs(void);
>  
> +/**
> + * Find a bus capable of identifying a device.
> + *
> + * @param str
> + *   A device identifier (PCI address, virtual PMD name, ...).
> + *
> + * @return
> + *   A valid bus handle if found.
> + *   NULL if no bus is able to parse this device.
> + */
> +struct rte_bus *rte_bus_find_by_device_name(const char *str);
> +
>  #endif /* _EAL_PRIVATE_H_ */
> -- 
> 2.1.4
> 

-- 
Gaëtan Rivet
6WIND

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

* [PATCH] bus: fix driver registration
  2017-07-04  0:58           ` [PATCH v6 1/6] bus: fix bus name registration Gaetan Rivet
@ 2017-07-04 21:43             ` Thomas Monjalon
  2017-07-05  5:47               ` Shreyansh Jain
  0 siblings, 1 reply; 123+ messages in thread
From: Thomas Monjalon @ 2017-07-04 21:43 UTC (permalink / raw)
  To: gaetan.rivet; +Cc: dev

The bus name was stored with embedded double quotes.
Indeed the bus name is given with a string in a macro,
which is not used elsewhere.
These macros are useless because the buses are drivers,
so they must not have any API for the application writer.
The registration can be done with a hardcoded value without quotes.

There is another (small) benefit of not using macros for driver names:
it is to have a meaningful constructor function name.
For instance, it was businitfn_PCI_BUS_NAME instead of businitfn_pci.

The bus registration macro is also changed to use
the new RTE_INIT_PRIO macro, similar to RTE_INIT used for other drivers.
The priority is the highest (101) in order to be sure that the bus driver
is registered before its device drivers.

Fixes: 0fd1a0eaae19 ("pci: add bus driver")
Fixes: fea892e35f21 ("bus/vdev: use standard bus registration")
Fixes: 7e7df6d0a41d ("bus/fslmc: introduce fsl-mc bus driver")

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
This patch is a proposal to replace the patch
"bus: fix bus name registration" in the series "rte_bus parse API".
---
 drivers/bus/fslmc/fslmc_bus.c            | 2 +-
 drivers/bus/fslmc/rte_fslmc.h            | 3 ---
 lib/librte_eal/common/eal_common_pci.c   | 2 +-
 lib/librte_eal/common/eal_common_vdev.c  | 2 +-
 lib/librte_eal/common/include/rte_bus.h  | 3 ++-
 lib/librte_eal/common/include/rte_eal.h  | 3 +++
 lib/librte_eal/common/include/rte_pci.h  | 3 ---
 lib/librte_eal/common/include/rte_vdev.h | 2 --
 8 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 1e3bbeeb0..f9e22111d 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -161,4 +161,4 @@ struct rte_fslmc_bus rte_fslmc_bus = {
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.driver_list),
 };
 
-RTE_REGISTER_BUS(FSLMC_BUS_NAME, rte_fslmc_bus.bus);
+RTE_REGISTER_BUS(fslmc, rte_fslmc_bus.bus);
diff --git a/drivers/bus/fslmc/rte_fslmc.h b/drivers/bus/fslmc/rte_fslmc.h
index 040ab9588..8f3527815 100644
--- a/drivers/bus/fslmc/rte_fslmc.h
+++ b/drivers/bus/fslmc/rte_fslmc.h
@@ -56,9 +56,6 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_bus.h>
 
-/** Name of FSLMC Bus */
-#define FSLMC_BUS_NAME "FSLMC"
-
 struct rte_dpaa2_driver;
 
 /* DPAA2 Device and Driver lists for FSLMC bus */
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 5ee100e67..2c99049a1 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -549,4 +549,4 @@ struct rte_pci_bus rte_pci_bus = {
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
 };
 
-RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus);
+RTE_REGISTER_BUS(pci, rte_pci_bus.bus);
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index baf3c5bfa..3bad0c463 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -374,4 +374,4 @@ static struct rte_bus rte_vdev_bus = {
 	.unplug = vdev_unplug,
 };
 
-RTE_REGISTER_BUS(VIRTUAL_BUS_NAME, rte_vdev_bus);
+RTE_REGISTER_BUS(vdev, rte_vdev_bus);
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 2f1c911f7..773b0d7af 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -256,7 +256,8 @@ struct rte_bus *rte_bus_find_by_name(const char *busname);
  * The constructor has higher priority than PMD constructors.
  */
 #define RTE_REGISTER_BUS(nm, bus) \
-static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
+RTE_INIT_PRIO(businitfn_ ##nm, 101); \
+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 abf020bf9..6b7c5ca92 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -286,6 +286,9 @@ static inline int rte_gettid(void)
 #define RTE_INIT(func) \
 static void __attribute__((constructor, used)) func(void)
 
+#define RTE_INIT_PRIO(func, prio) \
+static void __attribute__((constructor(prio), used)) func(void)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 0284a6208..7863f9457 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -77,9 +77,6 @@ const char *pci_get_sysfs_path(void);
 /** Maximum number of PCI resources. */
 #define PCI_MAX_RESOURCE 6
 
-/** Name of PCI Bus */
-#define PCI_BUS_NAME "PCI"
-
 /* Forward declarations */
 struct rte_pci_device;
 struct rte_pci_driver;
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 2d02c68d7..e6b678ea3 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -41,8 +41,6 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_devargs.h>
 
-#define VIRTUAL_BUS_NAME "virtual"
-
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
-- 
2.13.1

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

* [PATCH v7 0/6] rte_bus parse API
  2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
                             ` (5 preceding siblings ...)
  2017-07-04  0:58           ` [PATCH v6 6/6] devargs: parse bus info Gaetan Rivet
@ 2017-07-04 23:55           ` Gaetan Rivet
  2017-07-04 23:55             ` [PATCH v7 1/6] bus: fix driver registration Gaetan Rivet
                               ` (6 more replies)
  6 siblings, 7 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04 23:55 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Bruce Richardson

Following the evolutions announced in [1], here is the first part of
the rte_devargs rework planned for 17.08. The rationale has been partially
explained in [2].

This first part covers the introduction of the necessary facilities in
rte_bus to allow for generic device parsing. This API is implemented for
the virtual and PCI buses. Additionally, this rte_bus evolution is being
used within rte_devargs to characterize a device type by its bus.
This work is the first of two parts to reduce the dependency of the EAL
upon specific bus implementations.

The modified rte_devargs parsing allows declaring on the EAL command line
explicit buses to handle a device. The format is as follow:

  --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
  -w PCI:00:02.0 -w 00:03.0

This explicit bus designation is optional; no evolution is currently
forced on users to migrate to this new format. The separating character is
arbitrary.

[1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
[2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html

This patchset depends on:

bus attach/detach API and hotplug rework
http://dpdk.org/ml/archives/dev/2017-June/069643.html
http://dpdk.org/dev/patchwork/patch/26135/

v1 -> v2:

  * fix PCI parse implementation

v2 --> v3:

  * Rebase the series on the new plug / unplug API

v3 --> v4:

  * Several bug fixes, commit log rewrite.
  * Follow the changes to the plug / unplug API.

v5:

  * Do not verify bus name on bus registration.
    Actually, a legal bus name is not defined anymore.
    The bus/device separator in a device declaration can be anything,
    as long as it is a single character.
    The behavior is otherwise unchanged.

v6:

  * Rebase upon new hotplug patchset version.
  * Rename rte_bus_from_dev as rte_bus_find_by_device_name.
    This function is now private to the EAL.
  * Remove rte_bus_from_name, as it has been integrated as
    rte_bus_find_by_name by Jan Blunck.
  * Reduce parsing ambiguity in rte_devargs.

v7:

  * Use Thomas' bus registration fix.
  * Improve rte_bus_find_by_device_name, by making
    more resistant to shaky bus parse implementation.

Gaetan Rivet (5):
  bus: introduce parsing functionality
  vdev: implement parse bus operation
  pci: implement parse bus operation
  bus: add helper to find a bus from a device name
  devargs: parse bus info

Thomas Monjalon (1):
  bus: fix driver registration

 drivers/bus/fslmc/fslmc_bus.c               |  2 +-
 drivers/bus/fslmc/rte_fslmc.h               |  3 --
 lib/librte_eal/common/eal_common_bus.c      | 21 +++++++++
 lib/librte_eal/common/eal_common_devargs.c  | 42 +++++++++++++++---
 lib/librte_eal/common/eal_common_pci.c      | 17 +++++++-
 lib/librte_eal/common/eal_common_vdev.c     | 66 +++++++++++++++--------------
 lib/librte_eal/common/eal_private.h         | 12 ++++++
 lib/librte_eal/common/include/rte_bus.h     | 24 ++++++++++-
 lib/librte_eal/common/include/rte_devargs.h |  3 ++
 lib/librte_eal/common/include/rte_eal.h     |  3 ++
 lib/librte_eal/common/include/rte_pci.h     |  3 --
 lib/librte_eal/common/include/rte_vdev.h    |  2 -
 12 files changed, 148 insertions(+), 50 deletions(-)

-- 
2.1.4

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

* [PATCH v7 1/6] bus: fix driver registration
  2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
@ 2017-07-04 23:55             ` Gaetan Rivet
  2017-07-05 13:03               ` Shreyansh Jain
  2017-07-06  6:05               ` santosh
  2017-07-04 23:55             ` [PATCH v7 2/6] bus: introduce parsing functionality Gaetan Rivet
                               ` (5 subsequent siblings)
  6 siblings, 2 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04 23:55 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon

From: Thomas Monjalon <thomas@monjalon.net>

The bus name was stored with embedded double quotes.
Indeed the bus name is given with a string in a macro,
which is not used elsewhere.
These macros are useless because the buses are drivers,
so they must not have any API for the application writer.
The registration can be done with a hardcoded value without quotes.

There is another (small) benefit of not using macros for driver names:
it is to have a meaningful constructor function name.
For instance, it was businitfn_PCI_BUS_NAME instead of businitfn_pci.

The bus registration macro is also changed to use
the new RTE_INIT_PRIO macro, similar to RTE_INIT used for other drivers.
The priority is the highest (101) in order to be sure that the bus driver
is registered before its device drivers.

Fixes: 0fd1a0eaae19 ("pci: add bus driver")
Fixes: fea892e35f21 ("bus/vdev: use standard bus registration")
Fixes: 7e7df6d0a41d ("bus/fslmc: introduce fsl-mc bus driver")

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 drivers/bus/fslmc/fslmc_bus.c            | 2 +-
 drivers/bus/fslmc/rte_fslmc.h            | 3 ---
 lib/librte_eal/common/eal_common_pci.c   | 2 +-
 lib/librte_eal/common/eal_common_vdev.c  | 2 +-
 lib/librte_eal/common/include/rte_bus.h  | 3 ++-
 lib/librte_eal/common/include/rte_eal.h  | 3 +++
 lib/librte_eal/common/include/rte_pci.h  | 3 ---
 lib/librte_eal/common/include/rte_vdev.h | 2 --
 8 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 1e3bbee..f9e2211 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -161,4 +161,4 @@ struct rte_fslmc_bus rte_fslmc_bus = {
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.driver_list),
 };
 
-RTE_REGISTER_BUS(FSLMC_BUS_NAME, rte_fslmc_bus.bus);
+RTE_REGISTER_BUS(fslmc, rte_fslmc_bus.bus);
diff --git a/drivers/bus/fslmc/rte_fslmc.h b/drivers/bus/fslmc/rte_fslmc.h
index 040ab95..8f35278 100644
--- a/drivers/bus/fslmc/rte_fslmc.h
+++ b/drivers/bus/fslmc/rte_fslmc.h
@@ -56,9 +56,6 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_bus.h>
 
-/** Name of FSLMC Bus */
-#define FSLMC_BUS_NAME "FSLMC"
-
 struct rte_dpaa2_driver;
 
 /* DPAA2 Device and Driver lists for FSLMC bus */
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 5ee100e..2c99049 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -549,4 +549,4 @@ struct rte_pci_bus rte_pci_bus = {
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
 };
 
-RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus);
+RTE_REGISTER_BUS(pci, rte_pci_bus.bus);
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index baf3c5b..3bad0c4 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -374,4 +374,4 @@ static struct rte_bus rte_vdev_bus = {
 	.unplug = vdev_unplug,
 };
 
-RTE_REGISTER_BUS(VIRTUAL_BUS_NAME, rte_vdev_bus);
+RTE_REGISTER_BUS(vdev, rte_vdev_bus);
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 2f1c911..773b0d7 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -256,7 +256,8 @@ struct rte_bus *rte_bus_find_by_name(const char *busname);
  * The constructor has higher priority than PMD constructors.
  */
 #define RTE_REGISTER_BUS(nm, bus) \
-static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
+RTE_INIT_PRIO(businitfn_ ##nm, 101); \
+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 abf020b..6b7c5ca 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -286,6 +286,9 @@ static inline int rte_gettid(void)
 #define RTE_INIT(func) \
 static void __attribute__((constructor, used)) func(void)
 
+#define RTE_INIT_PRIO(func, prio) \
+static void __attribute__((constructor(prio), used)) func(void)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 0284a62..7863f94 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -77,9 +77,6 @@ const char *pci_get_sysfs_path(void);
 /** Maximum number of PCI resources. */
 #define PCI_MAX_RESOURCE 6
 
-/** Name of PCI Bus */
-#define PCI_BUS_NAME "PCI"
-
 /* Forward declarations */
 struct rte_pci_device;
 struct rte_pci_driver;
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 2d02c68..e6b678e 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -41,8 +41,6 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_devargs.h>
 
-#define VIRTUAL_BUS_NAME "virtual"
-
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
-- 
2.1.4

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

* [PATCH v7 2/6] bus: introduce parsing functionality
  2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
  2017-07-04 23:55             ` [PATCH v7 1/6] bus: fix driver registration Gaetan Rivet
@ 2017-07-04 23:55             ` Gaetan Rivet
  2017-07-05 13:04               ` Shreyansh Jain
  2017-07-06  9:19               ` santosh
  2017-07-04 23:55             ` [PATCH v7 3/6] vdev: implement parse bus operation Gaetan Rivet
                               ` (4 subsequent siblings)
  6 siblings, 2 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04 23:55 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

This operation can be used either to validate that a device
representation can be understood by a bus, as well as store the resulting
specialized device representation in any format determined by the bus.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 773b0d7..aebf57e 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -138,6 +138,26 @@ typedef int (*rte_bus_plug_t)(struct rte_device *dev,
 typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
 
 /**
+ * Bus specific parsing function.
+ * Validates the syntax used in the textual representation of a device,
+ * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
+ * device representation to ``addr``.
+ *
+ * @param[in] name
+ *	device textual description
+ *
+ * @param[out] addr
+ *	device information location address, into which parsed info
+ *	should be written. If NULL, nothing should be written, which
+ *	is not an error.
+ *
+ * @return
+ *	0 if parsing was successful.
+ *	!0 for any error.
+ */
+typedef int (*rte_bus_parse_t)(const char *name, void *addr);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -148,6 +168,7 @@ struct rte_bus {
 	rte_bus_find_device_t find_device; /**< Find a device on the bus */
 	rte_bus_plug_t plug;         /**< Probe single device for drivers */
 	rte_bus_unplug_t unplug;     /**< Remove single device from driver */
+	rte_bus_parse_t parse;       /**< Parse a device name */
 };
 
 /**
-- 
2.1.4

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

* [PATCH v7 3/6] vdev: implement parse bus operation
  2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
  2017-07-04 23:55             ` [PATCH v7 1/6] bus: fix driver registration Gaetan Rivet
  2017-07-04 23:55             ` [PATCH v7 2/6] bus: introduce parsing functionality Gaetan Rivet
@ 2017-07-04 23:55             ` Gaetan Rivet
  2017-07-05 13:16               ` Shreyansh Jain
  2017-07-06  9:35               ` santosh
  2017-07-04 23:55             ` [PATCH v7 4/6] pci: " Gaetan Rivet
                               ` (3 subsequent siblings)
  6 siblings, 2 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04 23:55 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 58 ++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 3bad0c4..6ecd1b5 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -102,6 +102,27 @@ static char *parse_driver_arg(const char *args)
 }
 
 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)) == 0)
+			break;
+		if (driver->driver.alias &&
+		    strncmp(driver->driver.alias, name,
+			    strlen(driver->driver.alias)) == 0)
+			break;
+	}
+	if (driver != NULL &&
+	    addr != NULL)
+		*out = driver;
+	return driver == NULL;
+}
+
+static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
 	const char *name;
@@ -115,36 +136,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;
-		}
-	}
-
-	/* 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;
-		}
+	if (vdev_parse(name, &driver)) {
+		ret = -1;
+		goto out;
 	}
-
+	dev->device.driver = &driver->driver;
+	ret = driver->probe(dev);
+	if (ret)
+		dev->device.driver = NULL;
 out:
 	free(drv_name);
 	return ret;
@@ -372,6 +371,7 @@ static struct rte_bus rte_vdev_bus = {
 	.find_device = vdev_find_device,
 	/* .plug = NULL, see comment on vdev_unplug */
 	.unplug = vdev_unplug,
+	.parse = vdev_parse,
 };
 
 RTE_REGISTER_BUS(vdev, rte_vdev_bus);
-- 
2.1.4

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

* [PATCH v7 4/6] pci: implement parse bus operation
  2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
                               ` (2 preceding siblings ...)
  2017-07-04 23:55             ` [PATCH v7 3/6] vdev: implement parse bus operation Gaetan Rivet
@ 2017-07-04 23:55             ` Gaetan Rivet
  2017-07-04 23:55             ` [PATCH v7 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
                               ` (2 subsequent siblings)
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04 23:55 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_pci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 2c99049..d7e2fb4 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -448,6 +448,20 @@ rte_pci_dump(FILE *f)
 	}
 }
 
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	bool parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr != NULL)
+		*out = pci_addr;
+	return parse == false;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -544,6 +558,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.find_device = pci_find_device,
 		.plug = pci_plug,
 		.unplug = pci_unplug,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
-- 
2.1.4

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

* [PATCH v7 5/6] bus: add helper to find a bus from a device name
  2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
                               ` (3 preceding siblings ...)
  2017-07-04 23:55             ` [PATCH v7 4/6] pci: " Gaetan Rivet
@ 2017-07-04 23:55             ` Gaetan Rivet
  2017-07-05 13:35               ` Shreyansh Jain
  2017-07-04 23:55             ` [PATCH v7 6/6] devargs: parse bus info Gaetan Rivet
  2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
  6 siblings, 1 reply; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04 23:55 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Find which bus should be able to parse this device name into an internal
device representation.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_bus.c | 21 +++++++++++++++++++++
 lib/librte_eal/common/eal_private.h    | 12 ++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 87b0c6e..34fcfa1 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -204,3 +204,24 @@ rte_bus_find_by_name(const char *busname)
 {
 	return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
 }
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return !(bus->parse && bus->parse(name, NULL) == 0);
+}
+
+struct rte_bus *
+rte_bus_find_by_device_name(const char *str)
+{
+	char name[32];
+	char *c;
+
+	snprintf(name, sizeof(name), "%s", str);
+	c = strchr(name, ',');
+	if (c != NULL)
+		c[0] = '\0';
+	return rte_bus_find(NULL, bus_can_parse, name);
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 6cacce0..0836339 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void);
  */
 bool rte_eal_using_phys_addrs(void);
 
+/**
+ * Find a bus capable of identifying a device.
+ *
+ * @param str
+ *   A device identifier (PCI address, virtual PMD name, ...).
+ *
+ * @return
+ *   A valid bus handle if found.
+ *   NULL if no bus is able to parse this device.
+ */
+struct rte_bus *rte_bus_find_by_device_name(const char *str);
+
 #endif /* _EAL_PRIVATE_H_ */
-- 
2.1.4

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

* [PATCH v7 6/6] devargs: parse bus info
  2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
                               ` (4 preceding siblings ...)
  2017-07-04 23:55             ` [PATCH v7 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-07-04 23:55             ` Gaetan Rivet
  2017-07-05 18:03               ` Stephen Hemminger
  2017-07-06  9:07               ` Shreyansh Jain
  2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
  6 siblings, 2 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-04 23:55 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/common/eal_common_devargs.c  | 42 ++++++++++++++++++++++++-----
 lib/librte_eal/common/eal_common_vdev.c     |  6 +++--
 lib/librte_eal/common/include/rte_devargs.h |  3 +++
 3 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index ffa8ad9..102bd8d 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -78,12 +78,23 @@ rte_eal_parse_devargs_str(const char *devargs_str,
 	return 0;
 }
 
+static int
+bus_name_cmp(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return strncmp(bus->name, name,
+		       strlen(bus->name));
+}
+
 /* store a whitelist parameter for later parsing */
 int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
-	char *buf = NULL;
+	struct rte_bus *bus = NULL;
+	char *dev = NULL;
+	const char *devname;
 	int ret;
 
 	/* use malloc instead of rte_malloc as it's called early at init */
@@ -94,34 +105,51 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	memset(devargs, 0, sizeof(*devargs));
 	devargs->type = devtype;
 
-	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
+	if (rte_eal_parse_devargs_str(devargs_str, &dev, &devargs->args))
 		goto fail;
+	devname = dev;
+	do {
+		bus = rte_bus_find(bus, bus_name_cmp, dev);
+		if (bus == NULL)
+			break;
+		devname = dev + strlen(bus->name) + 1;
+		if (rte_bus_find_by_device_name(devname) == bus)
+			break;
+		devname = dev;
+	} while (1);
+	if (bus == NULL) {
+		bus = rte_bus_find_by_device_name(devname);
+		if (bus == NULL) {
+			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
+			goto fail;
+		}
+	}
+	devargs->bus = bus;
 
 	switch (devargs->type) {
 	case RTE_DEVTYPE_WHITELISTED_PCI:
 	case RTE_DEVTYPE_BLACKLISTED_PCI:
 		/* try to parse pci identifier */
-		if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
-		    eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0)
+		if (bus->parse(devname, &devargs->pci.addr) != 0)
 			goto fail;
 
 		break;
 	case RTE_DEVTYPE_VIRTUAL:
 		/* save driver name */
 		ret = snprintf(devargs->virt.drv_name,
-			       sizeof(devargs->virt.drv_name), "%s", buf);
+			       sizeof(devargs->virt.drv_name), "%s", devname);
 		if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name))
 			goto fail;
 
 		break;
 	}
 
-	free(buf);
+	free(dev);
 	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
 	return 0;
 
 fail:
-	free(buf);
+	free(dev);
 	if (devargs) {
 		free(devargs->args);
 		free(devargs);
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 6ecd1b5..8fd1ef7 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -177,6 +177,7 @@ alloc_devargs(const char *name, const char *args)
 		return NULL;
 
 	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	devargs->bus = rte_bus_find_by_name("vdev");
 	if (args)
 		devargs->args = strdup(args);
 
@@ -289,12 +290,13 @@ vdev_scan(void)
 {
 	struct rte_vdev_device *dev;
 	struct rte_devargs *devargs;
+	struct rte_bus *vbus;
 
 	/* for virtual devices we scan the devargs_list populated via cmdline */
-
+	vbus = rte_bus_find_by_name("vdev");
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (devargs->bus != vbus)
 			continue;
 
 		dev = find_vdev(devargs->virt.drv_name);
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index 88120a1..1f50a24 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -51,6 +51,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#include <rte_bus.h>
 
 /**
  * Type of generic device
@@ -89,6 +90,8 @@ struct rte_devargs {
 			char drv_name[32];
 		} virt;
 	};
+	/** Bus handle for the device. */
+	struct rte_bus *bus;
 	/** Arguments string as given by user or "" for no argument. */
 	char *args;
 };
-- 
2.1.4

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

* Re: [PATCH] bus: fix driver registration
  2017-07-04 21:43             ` [PATCH] bus: fix driver registration Thomas Monjalon
@ 2017-07-05  5:47               ` Shreyansh Jain
  2017-07-05  6:01                 ` Shreyansh Jain
  0 siblings, 1 reply; 123+ messages in thread
From: Shreyansh Jain @ 2017-07-05  5:47 UTC (permalink / raw)
  To: Thomas Monjalon, gaetan.rivet; +Cc: dev

On Wednesday 05 July 2017 03:13 AM, Thomas Monjalon wrote:
> The bus name was stored with embedded double quotes.
> Indeed the bus name is given with a string in a macro,
> which is not used elsewhere.
> These macros are useless because the buses are drivers,
> so they must not have any API for the application writer.
> The registration can be done with a hardcoded value without quotes.
> 
> There is another (small) benefit of not using macros for driver names:
> it is to have a meaningful constructor function name.
> For instance, it was businitfn_PCI_BUS_NAME instead of businitfn_pci.
> 
> The bus registration macro is also changed to use
> the new RTE_INIT_PRIO macro, similar to RTE_INIT used for other drivers.
> The priority is the highest (101) in order to be sure that the bus driver
> is registered before its device drivers.
> 
> Fixes: 0fd1a0eaae19 ("pci: add bus driver")
> Fixes: fea892e35f21 ("bus/vdev: use standard bus registration")
> Fixes: 7e7df6d0a41d ("bus/fslmc: introduce fsl-mc bus driver")
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---
> This patch is a proposal to replace the patch
> "bus: fix bus name registration" in the series "rte_bus parse API".
> ---
>  drivers/bus/fslmc/fslmc_bus.c            | 2 +-
>  drivers/bus/fslmc/rte_fslmc.h            | 3 ---
>  lib/librte_eal/common/eal_common_pci.c   | 2 +-
>  lib/librte_eal/common/eal_common_vdev.c  | 2 +-
>  lib/librte_eal/common/include/rte_bus.h  | 3 ++-
>  lib/librte_eal/common/include/rte_eal.h  | 3 +++
>  lib/librte_eal/common/include/rte_pci.h  | 3 ---
>  lib/librte_eal/common/include/rte_vdev.h | 2 --
>  8 files changed, 8 insertions(+), 12 deletions(-)
> 
For DPAA2 as well as generic change:

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

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

* Re: [PATCH] bus: fix driver registration
  2017-07-05  5:47               ` Shreyansh Jain
@ 2017-07-05  6:01                 ` Shreyansh Jain
  0 siblings, 0 replies; 123+ messages in thread
From: Shreyansh Jain @ 2017-07-05  6:01 UTC (permalink / raw)
  To: Thomas Monjalon, gaetan.rivet, Bruce Richardson; +Cc: dev

On Wednesday 05 July 2017 11:17 AM, Shreyansh Jain wrote:
> On Wednesday 05 July 2017 03:13 AM, Thomas Monjalon wrote:
>> The bus name was stored with embedded double quotes.
>> Indeed the bus name is given with a string in a macro,
>> which is not used elsewhere.
>> These macros are useless because the buses are drivers,
>> so they must not have any API for the application writer.
>> The registration can be done with a hardcoded value without quotes.
>>
>> There is another (small) benefit of not using macros for driver names:
>> it is to have a meaningful constructor function name.
>> For instance, it was businitfn_PCI_BUS_NAME instead of businitfn_pci.
>>
>> The bus registration macro is also changed to use
>> the new RTE_INIT_PRIO macro, similar to RTE_INIT used for other drivers.
>> The priority is the highest (101) in order to be sure that the bus driver
>> is registered before its device drivers.
>>
>> Fixes: 0fd1a0eaae19 ("pci: add bus driver")
>> Fixes: fea892e35f21 ("bus/vdev: use standard bus registration")
>> Fixes: 7e7df6d0a41d ("bus/fslmc: introduce fsl-mc bus driver")
>>
>> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
>> ---
>> This patch is a proposal to replace the patch
>> "bus: fix bus name registration" in the series "rte_bus parse API".
>> ---
>>  drivers/bus/fslmc/fslmc_bus.c            | 2 +-
>>  drivers/bus/fslmc/rte_fslmc.h            | 3 ---
>>  lib/librte_eal/common/eal_common_pci.c   | 2 +-
>>  lib/librte_eal/common/eal_common_vdev.c  | 2 +-
>>  lib/librte_eal/common/include/rte_bus.h  | 3 ++-
>>  lib/librte_eal/common/include/rte_eal.h  | 3 +++
>>  lib/librte_eal/common/include/rte_pci.h  | 3 ---
>>  lib/librte_eal/common/include/rte_vdev.h | 2 --
>>  8 files changed, 8 insertions(+), 12 deletions(-)
>>
> For DPAA2 as well as generic change:
> 
> Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
> 

I just noticed that Bruce has already Acked the patch which is super-seeded by this. I didn't mean to conflict here.

I don't have a reservation to either of these - but, I like this patch as it does away with priority as well as need for drivers to define an internal name strings. Thus, my ACK to this.

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

* Re: [PATCH v7 1/6] bus: fix driver registration
  2017-07-04 23:55             ` [PATCH v7 1/6] bus: fix driver registration Gaetan Rivet
@ 2017-07-05 13:03               ` Shreyansh Jain
  2017-07-06  6:05               ` santosh
  1 sibling, 0 replies; 123+ messages in thread
From: Shreyansh Jain @ 2017-07-05 13:03 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev, Thomas Monjalon

On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
> From: Thomas Monjalon <thomas@monjalon.net>
> 
> The bus name was stored with embedded double quotes.
> Indeed the bus name is given with a string in a macro,
> which is not used elsewhere.
> These macros are useless because the buses are drivers,
> so they must not have any API for the application writer.
> The registration can be done with a hardcoded value without quotes.
> 
> There is another (small) benefit of not using macros for driver names:
> it is to have a meaningful constructor function name.
> For instance, it was businitfn_PCI_BUS_NAME instead of businitfn_pci.
> 
> The bus registration macro is also changed to use
> the new RTE_INIT_PRIO macro, similar to RTE_INIT used for other drivers.
> The priority is the highest (101) in order to be sure that the bus driver
> is registered before its device drivers.
> 
> Fixes: 0fd1a0eaae19 ("pci: add bus driver")
> Fixes: fea892e35f21 ("bus/vdev: use standard bus registration")
> Fixes: 7e7df6d0a41d ("bus/fslmc: introduce fsl-mc bus driver")
> 
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---

Though I had already acked it in v6,
(from DPAA2 (bus/fslmc) perspective, as well as generically):

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

-
Shreyansh

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

* Re: [PATCH v7 2/6] bus: introduce parsing functionality
  2017-07-04 23:55             ` [PATCH v7 2/6] bus: introduce parsing functionality Gaetan Rivet
@ 2017-07-05 13:04               ` Shreyansh Jain
  2017-07-06  9:19               ` santosh
  1 sibling, 0 replies; 123+ messages in thread
From: Shreyansh Jain @ 2017-07-05 13:04 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
> This operation can be used either to validate that a device
> representation can be understood by a bus, as well as store the resulting
> specialized device representation in any format determined by the bus.
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---

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

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

* Re: [PATCH v7 3/6] vdev: implement parse bus operation
  2017-07-04 23:55             ` [PATCH v7 3/6] vdev: implement parse bus operation Gaetan Rivet
@ 2017-07-05 13:16               ` Shreyansh Jain
  2017-07-06  9:35               ` santosh
  1 sibling, 0 replies; 123+ messages in thread
From: Shreyansh Jain @ 2017-07-05 13:16 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---

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

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

* Re: [PATCH v7 5/6] bus: add helper to find a bus from a device name
  2017-07-04 23:55             ` [PATCH v7 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-07-05 13:35               ` Shreyansh Jain
  2017-07-05 13:45                 ` Gaëtan Rivet
  0 siblings, 1 reply; 123+ messages in thread
From: Shreyansh Jain @ 2017-07-05 13:35 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

Hello Gaetan,

Some comments inline:

On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
> Find which bus should be able to parse this device name into an internal
> device representation.
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>   lib/librte_eal/common/eal_common_bus.c | 21 +++++++++++++++++++++
>   lib/librte_eal/common/eal_private.h    | 12 ++++++++++++
>   2 files changed, 33 insertions(+)
> 
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> index 87b0c6e..34fcfa1 100644
> --- a/lib/librte_eal/common/eal_common_bus.c
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -204,3 +204,24 @@ rte_bus_find_by_name(const char *busname)
>   {
>   	return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
>   }
> +
> +static int
> +bus_can_parse(const struct rte_bus *bus, const void *_name)
> +{
> +	const char *name = _name;
> +
> +	return !(bus->parse && bus->parse(name, NULL) == 0);
> +}
> +
> +struct rte_bus *
> +rte_bus_find_by_device_name(const char *str)
> +{
> +	char name[32];

It is possible to use a constant here? Basically, I am not sure why '32' 
has been chosen - or maybe, it might remind a reader in future the 
reason for this value.

Just to clarify: is there any documented limit on bus name? Until this 
point, the name (and length) of bus was responsibility of bus driver 
implementation. eal_common_bus.c doesn't codify any limit - so, this may 
have to be advertised, even if just within the code.

> +	char *c;
> +
> +	snprintf(name, sizeof(name), "%s", str);
> +	c = strchr(name, ',');

I saw a lot of discussion on the naming assumptions/presumptions. 
Though, I am not sure I have an understood conclusion from that.
So, this might be incorrect/ill-informed:

Is it assumed that ',' is not present in device name?

Do you think it would be better if this is documented that ',' in a 
device name is reserved (as per devargs)? (or, is this already known?)

For example, in case of DPAA2 devices, I didn't consider this as a case 
while generating names while scanning the bus (though, I didn't have a 
',' in the name). But, if a well known fact, bus drivers can normalize 
their device names before creating device names.

> +	if (c != NULL)
> +		c[0] = '\0';
> +	return rte_bus_find(NULL, bus_can_parse, name);
> +}
> diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
> index 6cacce0..0836339 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void);
>    */
>   bool rte_eal_using_phys_addrs(void);
>   
> +/**
> + * Find a bus capable of identifying a device.
> + *
> + * @param str
> + *   A device identifier (PCI address, virtual PMD name, ...).
> + *
> + * @return
> + *   A valid bus handle if found.
> + *   NULL if no bus is able to parse this device.
> + */
> +struct rte_bus *rte_bus_find_by_device_name(const char *str);
> +
>   #endif /* _EAL_PRIVATE_H_ */
> 

(Apologies for commenting so late in series - feel free to ignore if 
this disrupts your cycle or sounds out-of-context.)

-
Shreyansh

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

* Re: [PATCH v7 5/6] bus: add helper to find a bus from a device name
  2017-07-05 13:35               ` Shreyansh Jain
@ 2017-07-05 13:45                 ` Gaëtan Rivet
  2017-07-05 14:12                   ` Shreyansh Jain
  2017-07-06 10:10                   ` Thomas Monjalon
  0 siblings, 2 replies; 123+ messages in thread
From: Gaëtan Rivet @ 2017-07-05 13:45 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: dev

Hi Shreyansh,

On Wed, Jul 05, 2017 at 07:05:40PM +0530, Shreyansh Jain wrote:
> Hello Gaetan,
> 
> Some comments inline:
> 
> On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
> >Find which bus should be able to parse this device name into an internal
> >device representation.
> >
> >Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> >---
> >  lib/librte_eal/common/eal_common_bus.c | 21 +++++++++++++++++++++
> >  lib/librte_eal/common/eal_private.h    | 12 ++++++++++++
> >  2 files changed, 33 insertions(+)
> >
> >diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> >index 87b0c6e..34fcfa1 100644
> >--- a/lib/librte_eal/common/eal_common_bus.c
> >+++ b/lib/librte_eal/common/eal_common_bus.c
> >@@ -204,3 +204,24 @@ rte_bus_find_by_name(const char *busname)
> >  {
> >  	return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
> >  }
> >+
> >+static int
> >+bus_can_parse(const struct rte_bus *bus, const void *_name)
> >+{
> >+	const char *name = _name;
> >+
> >+	return !(bus->parse && bus->parse(name, NULL) == 0);
> >+}
> >+
> >+struct rte_bus *
> >+rte_bus_find_by_device_name(const char *str)
> >+{
> >+	char name[32];
> 
> It is possible to use a constant here? Basically, I am not sure why '32' has
> been chosen - or maybe, it might remind a reader in future the reason for
> this value.
> 
> Just to clarify: is there any documented limit on bus name? Until this
> point, the name (and length) of bus was responsibility of bus driver
> implementation. eal_common_bus.c doesn't codify any limit - so, this may
> have to be advertised, even if just within the code.
> 

I agree that this is not clear. First thing however: this is a limit on
the device name length, not bus.

This problem is fixed in [1], as a single common device name location is
defined. The problem is that it is in another patchset (even if both are
closely linked and were only separated to ease integration).

This limit was currently taken from the arbitrary limit of device in
name in the original rte_devargs for virtual devices. I think it could
be exported as a define by rte_dev.h, used there and reused in [1] to
define the new rte_devargs structure.

Would that be ok with you?

[1]: http://dpdk.org/ml/archives/dev/2017-July/070225.html

> >+	char *c;
> >+
> >+	snprintf(name, sizeof(name), "%s", str);
> >+	c = strchr(name, ',');
> 
> I saw a lot of discussion on the naming assumptions/presumptions. Though, I
> am not sure I have an understood conclusion from that.
> So, this might be incorrect/ill-informed:
> 
> Is it assumed that ',' is not present in device name?
> 
> Do you think it would be better if this is documented that ',' in a device
> name is reserved (as per devargs)? (or, is this already known?)
> 
> For example, in case of DPAA2 devices, I didn't consider this as a case
> while generating names while scanning the bus (though, I didn't have a ','
> in the name). But, if a well known fact, bus drivers can normalize their
> device names before creating device names.
> 

For this release cycle the discussion was mostly about forbidding (or
not forbidding) characters in bus names. This character is one
limitation previously defined for device names, to separate the device
name from its kvargs.

I am thus following the current rte_devargs API.
Not sure if that's documented. There are examples in doc, but maybe this
device name limitation is not explicitly said.

> >+	if (c != NULL)
> >+		c[0] = '\0';
> >+	return rte_bus_find(NULL, bus_can_parse, name);
> >+}
> >diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
> >index 6cacce0..0836339 100644
> >--- a/lib/librte_eal/common/eal_private.h
> >+++ b/lib/librte_eal/common/eal_private.h
> >@@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void);
> >   */
> >  bool rte_eal_using_phys_addrs(void);
> >+/**
> >+ * Find a bus capable of identifying a device.
> >+ *
> >+ * @param str
> >+ *   A device identifier (PCI address, virtual PMD name, ...).
> >+ *
> >+ * @return
> >+ *   A valid bus handle if found.
> >+ *   NULL if no bus is able to parse this device.
> >+ */
> >+struct rte_bus *rte_bus_find_by_device_name(const char *str);
> >+
> >  #endif /* _EAL_PRIVATE_H_ */
> >
> 
> (Apologies for commenting so late in series - feel free to ignore if this
> disrupts your cycle or sounds out-of-context.)
> 

No problem, thanks for reviewing so quickly this patchset.

> -
> Shreyansh

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH v7 5/6] bus: add helper to find a bus from a device name
  2017-07-05 13:45                 ` Gaëtan Rivet
@ 2017-07-05 14:12                   ` Shreyansh Jain
  2017-07-06 10:10                   ` Thomas Monjalon
  1 sibling, 0 replies; 123+ messages in thread
From: Shreyansh Jain @ 2017-07-05 14:12 UTC (permalink / raw)
  To: Gaëtan Rivet; +Cc: dev

On Wednesday 05 July 2017 07:15 PM, Gaëtan Rivet wrote:
> Hi Shreyansh,
> 
> On Wed, Jul 05, 2017 at 07:05:40PM +0530, Shreyansh Jain wrote:
>> Hello Gaetan,
>>
>> Some comments inline:
>>
>> On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
>>> Find which bus should be able to parse this device name into an internal
>>> device representation.
>>>
>>> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
>>> ---
>>>   lib/librte_eal/common/eal_common_bus.c | 21 +++++++++++++++++++++
>>>   lib/librte_eal/common/eal_private.h    | 12 ++++++++++++
>>>   2 files changed, 33 insertions(+)
>>>
>>> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
>>> index 87b0c6e..34fcfa1 100644
>>> --- a/lib/librte_eal/common/eal_common_bus.c
>>> +++ b/lib/librte_eal/common/eal_common_bus.c
>>> @@ -204,3 +204,24 @@ rte_bus_find_by_name(const char *busname)
>>>   {
>>>   	return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
>>>   }
>>> +
>>> +static int
>>> +bus_can_parse(const struct rte_bus *bus, const void *_name)
>>> +{
>>> +	const char *name = _name;
>>> +
>>> +	return !(bus->parse && bus->parse(name, NULL) == 0);
>>> +}
>>> +
>>> +struct rte_bus *
>>> +rte_bus_find_by_device_name(const char *str)
>>> +{
>>> +	char name[32];
>>
>> It is possible to use a constant here? Basically, I am not sure why '32' has
>> been chosen - or maybe, it might remind a reader in future the reason for
>> this value.
>>
>> Just to clarify: is there any documented limit on bus name? Until this
>> point, the name (and length) of bus was responsibility of bus driver
>> implementation. eal_common_bus.c doesn't codify any limit - so, this may
>> have to be advertised, even if just within the code.
>>
> 
> I agree that this is not clear. First thing however: this is a limit on
> the device name length, not bus.

Ah, yes, I see that now. I mixed up.

> 
> This problem is fixed in [1], as a single common device name location is
> defined. The problem is that it is in another patchset (even if both are
> closely linked and were only separated to ease integration).

Ok. I hadn't yet gone through it yet - so, didn't notice.
I will look through that as well.
But, if this is already taken care of in that series, consider my 
comment resolved.

> 
> This limit was currently taken from the arbitrary limit of device in
> name in the original rte_devargs for virtual devices. I think it could
> be exported as a define by rte_dev.h, used there and reused in [1] to
> define the new rte_devargs structure.
> 
> Would that be ok with you?

For the purpose of this patch, this is OK.
I will read through that patch series and comment if there is something 
I have comments on. Thanks for highlighting.

> 
> [1]: http://dpdk.org/ml/archives/dev/2017-July/070225.html
> 
>>> +	char *c;
>>> +
>>> +	snprintf(name, sizeof(name), "%s", str);
>>> +	c = strchr(name, ',');
>>
>> I saw a lot of discussion on the naming assumptions/presumptions. Though, I
>> am not sure I have an understood conclusion from that.
>> So, this might be incorrect/ill-informed:
>>
>> Is it assumed that ',' is not present in device name?
>>
>> Do you think it would be better if this is documented that ',' in a device
>> name is reserved (as per devargs)? (or, is this already known?)
>>
>> For example, in case of DPAA2 devices, I didn't consider this as a case
>> while generating names while scanning the bus (though, I didn't have a ','
>> in the name). But, if a well known fact, bus drivers can normalize their
>> device names before creating device names.
>>
> 
> For this release cycle the discussion was mostly about forbidding (or
> not forbidding) characters in bus names. This character is one
> limitation previously defined for device names, to separate the device
> name from its kvargs.
> 
> I am thus following the current rte_devargs API.
> Not sure if that's documented. There are examples in doc, but maybe this
> device name limitation is not explicitly said.

I agree. There doesn't seem to be much devargs related documentation 
anyways. (is there?)

If someone uses a ',' name (ignorantly), they would get a failure from 
this function because of partial name match.

But its worth documenting - now that EAL (Bus scan) allows device an 
arbitrary naming (no more just PCI and VDEV).
(I will try to write something and push as patch - that is, if I have 
enough understanding of devargs subsystem.)

> 
>>> +	if (c != NULL)
>>> +		c[0] = '\0';
>>> +	return rte_bus_find(NULL, bus_can_parse, name);
>>> +}
>>> diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
>>> index 6cacce0..0836339 100644
>>> --- a/lib/librte_eal/common/eal_private.h
>>> +++ b/lib/librte_eal/common/eal_private.h
>>> @@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void);
>>>    */
>>>   bool rte_eal_using_phys_addrs(void);
>>> +/**
>>> + * Find a bus capable of identifying a device.
>>> + *
>>> + * @param str
>>> + *   A device identifier (PCI address, virtual PMD name, ...).
>>> + *
>>> + * @return
>>> + *   A valid bus handle if found.
>>> + *   NULL if no bus is able to parse this device.
>>> + */
>>> +struct rte_bus *rte_bus_find_by_device_name(const char *str);
>>> +
>>>   #endif /* _EAL_PRIVATE_H_ */
>>>
>>
>> (Apologies for commenting so late in series - feel free to ignore if this
>> disrupts your cycle or sounds out-of-context.)
>>
> 
> No problem, thanks for reviewing so quickly this patchset.
> 
>> -
>> Shreyansh
> 
Other than the 'device name length issue', which would be revisited in 
other patch series:

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

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

* Re: [PATCH v7 6/6] devargs: parse bus info
  2017-07-04 23:55             ` [PATCH v7 6/6] devargs: parse bus info Gaetan Rivet
@ 2017-07-05 18:03               ` Stephen Hemminger
  2017-07-06  9:07               ` Shreyansh Jain
  1 sibling, 0 replies; 123+ messages in thread
From: Stephen Hemminger @ 2017-07-05 18:03 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

On Wed,  5 Jul 2017 01:55:23 +0200
Gaetan Rivet <gaetan.rivet@6wind.com> wrote:

>  	case RTE_DEVTYPE_WHITELISTED_PCI:
>  	case RTE_DEVTYPE_BLACKLISTED_PCI:
>  		/* try to parse pci identifier */
> -		if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
> -		    eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0)
> +		if (bus->parse(devname, &devargs->pci.addr) != 0)
>  			goto fail;

Shouldn't these go under bus args for PCI?
It would be good to get all the bus specific args out of generic code.

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

* Re: [PATCH v7 1/6] bus: fix driver registration
  2017-07-04 23:55             ` [PATCH v7 1/6] bus: fix driver registration Gaetan Rivet
  2017-07-05 13:03               ` Shreyansh Jain
@ 2017-07-06  6:05               ` santosh
  1 sibling, 0 replies; 123+ messages in thread
From: santosh @ 2017-07-06  6:05 UTC (permalink / raw)
  To: dev

On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:

> From: Thomas Monjalon <thomas@monjalon.net>
>
> The bus name was stored with embedded double quotes.
> Indeed the bus name is given with a string in a macro,
> which is not used elsewhere.
> These macros are useless because the buses are drivers,
> so they must not have any API for the application writer.
> The registration can be done with a hardcoded value without quotes.
>
> There is another (small) benefit of not using macros for driver names:
> it is to have a meaningful constructor function name.
> For instance, it was businitfn_PCI_BUS_NAME instead of businitfn_pci.
>
> The bus registration macro is also changed to use
> the new RTE_INIT_PRIO macro, similar to RTE_INIT used for other drivers.
> The priority is the highest (101) in order to be sure that the bus driver
> is registered before its device drivers.
>
> Fixes: 0fd1a0eaae19 ("pci: add bus driver")
> Fixes: fea892e35f21 ("bus/vdev: use standard bus registration")
> Fixes: 7e7df6d0a41d ("bus/fslmc: introduce fsl-mc bus driver")
>
> Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
> ---

LGTM, Reviewed-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>

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

* Re: [PATCH v7 6/6] devargs: parse bus info
  2017-07-04 23:55             ` [PATCH v7 6/6] devargs: parse bus info Gaetan Rivet
  2017-07-05 18:03               ` Stephen Hemminger
@ 2017-07-06  9:07               ` Shreyansh Jain
  2017-07-06 10:00                 ` Gaëtan Rivet
  1 sibling, 1 reply; 123+ messages in thread
From: Shreyansh Jain @ 2017-07-06  9:07 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

Hello Gaetan,

On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>   lib/librte_eal/common/eal_common_devargs.c  | 42 ++++++++++++++++++++++++-----
>   lib/librte_eal/common/eal_common_vdev.c     |  6 +++--
>   lib/librte_eal/common/include/rte_devargs.h |  3 +++
>   3 files changed, 42 insertions(+), 9 deletions(-)
> 
> diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
> index ffa8ad9..102bd8d 100644
> --- a/lib/librte_eal/common/eal_common_devargs.c
> +++ b/lib/librte_eal/common/eal_common_devargs.c
> @@ -78,12 +78,23 @@ rte_eal_parse_devargs_str(const char *devargs_str,
>   	return 0;
>   }
>   
> +static int
> +bus_name_cmp(const struct rte_bus *bus, const void *_name)
> +{
> +	const char *name = _name;
> +
> +	return strncmp(bus->name, name,
> +		       strlen(bus->name));

Trivial: Any specific reason why this is split across multiple lines 
even though it is less than 80 chars in total?

> +}
> +
>   /* store a whitelist parameter for later parsing */
>   int
>   rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>   {
>   	struct rte_devargs *devargs = NULL;
> -	char *buf = NULL;
> +	struct rte_bus *bus = NULL;
> +	char *dev = NULL;
> +	const char *devname;
>   	int ret;
>   
>   	/* use malloc instead of rte_malloc as it's called early at init */
> @@ -94,34 +105,51 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>   	memset(devargs, 0, sizeof(*devargs));
>   	devargs->type = devtype;
>   
> -	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
> +	if (rte_eal_parse_devargs_str(devargs_str, &dev, &devargs->args))

A very basic (and possibly incorrect) question:

here, for example "'net_pcap0,rx_pcap=input.pcap,tx_pcap=output.pcap'" 
was passed to application, which would mean;

dev = "net_pcap0" (name of the device)
devargs = "rx_pcap=input.pcap,tx_pcap=output.pcap"

>   		goto fail;
> +	devname = dev;
> +	do {
> +		bus = rte_bus_find(bus, bus_name_cmp, dev);
> +		if (bus == NULL)
> +			break;
> +		devname = dev + strlen(bus->name) + 1;

Assuming "vdev" bus:
                       "net_pcap0"
                             |
devname points here --------' (4+1) chars from start of "net_pcap0".
Is that the expectation?

Probably I am missing something here (maybe the input already has a bus 
name.)

Or, if this is not the case, then we will have to change the test 
application (test_devargs.c) which passes such strings to 
"rte_eal_devargs_add".

> +		if (rte_bus_find_by_device_name(devname) == bus)

Obviously, if my assumption is correct, this fails. Or, maybe I am 
completely off the mark.

> +			break;
> +		devname = dev;
> +	} while (1);
> +	if (bus == NULL) {
> +		bus = rte_bus_find_by_device_name(devname);
> +		if (bus == NULL) {
> +			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
> +			goto fail;
> +		}
> +	}
> +	devargs->bus = bus;
   >   	switch (devargs->type) {
>   	case RTE_DEVTYPE_WHITELISTED_PCI:
>   	case RTE_DEVTYPE_BLACKLISTED_PCI:
>   		/* try to parse pci identifier */
> -		if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
> -		    eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0)
> +		if (bus->parse(devname, &devargs->pci.addr) != 0)
>   			goto fail;
>   
>   		break;
>   	case RTE_DEVTYPE_VIRTUAL:
>   		/* save driver name */
>   		ret = snprintf(devargs->virt.drv_name,
> -			       sizeof(devargs->virt.drv_name), "%s", buf);
> +			       sizeof(devargs->virt.drv_name), "%s", devname);
>   		if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name))
>   			goto fail;
>   
>   		break;
>   	}

I think all this will change in the devargs series.

>   
> -	free(buf);
> +	free(dev);
>   	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
>   	return 0;
>   
>   fail:
> -	free(buf);
> +	free(dev);
>   	if (devargs) {
>   		free(devargs->args);
>   		free(devargs);
> diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
> index 6ecd1b5..8fd1ef7 100644
> --- a/lib/librte_eal/common/eal_common_vdev.c
> +++ b/lib/librte_eal/common/eal_common_vdev.c
> @@ -177,6 +177,7 @@ alloc_devargs(const char *name, const char *args)
>   		return NULL;
>   
>   	devargs->type = RTE_DEVTYPE_VIRTUAL;
> +	devargs->bus = rte_bus_find_by_name("vdev");
>   	if (args)
>   		devargs->args = strdup(args);
>   
> @@ -289,12 +290,13 @@ vdev_scan(void)
>   {
>   	struct rte_vdev_device *dev;
>   	struct rte_devargs *devargs;
> +	struct rte_bus *vbus;
>   
>   	/* for virtual devices we scan the devargs_list populated via cmdline */
> -
> +	vbus = rte_bus_find_by_name("vdev");
>   	TAILQ_FOREACH(devargs, &devargs_list, next) {
>   
> -		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
> +		if (devargs->bus != vbus)
>   			continue;
>   
>   		dev = find_vdev(devargs->virt.drv_name);
> diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
> index 88120a1..1f50a24 100644
> --- a/lib/librte_eal/common/include/rte_devargs.h
> +++ b/lib/librte_eal/common/include/rte_devargs.h
> @@ -51,6 +51,7 @@ extern "C" {
>   #include <stdio.h>
>   #include <sys/queue.h>
>   #include <rte_pci.h>
> +#include <rte_bus.h>
>   
>   /**
>    * Type of generic device
> @@ -89,6 +90,8 @@ struct rte_devargs {
>   			char drv_name[32];
>   		} virt;
>   	};
> +	/** Bus handle for the device. */
> +	struct rte_bus *bus;
>   	/** Arguments string as given by user or "" for no argument. */
>   	char *args;
>   };
> 
-
Shreyansh

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

* Re: [PATCH v7 2/6] bus: introduce parsing functionality
  2017-07-04 23:55             ` [PATCH v7 2/6] bus: introduce parsing functionality Gaetan Rivet
  2017-07-05 13:04               ` Shreyansh Jain
@ 2017-07-06  9:19               ` santosh
  2017-07-06 12:30                 ` Gaëtan Rivet
  1 sibling, 1 reply; 123+ messages in thread
From: santosh @ 2017-07-06  9:19 UTC (permalink / raw)
  To: Gaetan Rivet, dev

Hi Gaetan,

On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:

> This operation can be used either to validate that a device
> representation can be understood by a bus, as well as store the resulting
> specialized device representation in any format determined by the bus.
>
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
>
> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> index 773b0d7..aebf57e 100644
> --- a/lib/librte_eal/common/include/rte_bus.h
> +++ b/lib/librte_eal/common/include/rte_bus.h
> @@ -138,6 +138,26 @@ typedef int (*rte_bus_plug_t)(struct rte_device *dev,
>  typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
>  
>  /**
> + * Bus specific parsing function.
> + * Validates the syntax used in the textual representation of a device,
> + * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
> + * device representation to ``addr``.
> + *
> + * @param[in] name
> + *	device textual description
> + *
> + * @param[out] addr
> + *	device information location address, into which parsed info
> + *	should be written. If NULL, nothing should be written, which
> + *	is not an error.
> + *

r / is not a error/ is valid?

> + * @return
> + *	0 if parsing was successful.
> + *	!0 for any error.
> + */
> +typedef int (*rte_bus_parse_t)(const char *name, void *addr);
> +

_parse handler in _common_vdev or common_pci file return boolean value 
i.e..0 for success and 1 for error, right? if so then
!0 for any error would be like '1' for error case.. make sense?

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

* Re: [PATCH v7 3/6] vdev: implement parse bus operation
  2017-07-04 23:55             ` [PATCH v7 3/6] vdev: implement parse bus operation Gaetan Rivet
  2017-07-05 13:16               ` Shreyansh Jain
@ 2017-07-06  9:35               ` santosh
  1 sibling, 0 replies; 123+ messages in thread
From: santosh @ 2017-07-06  9:35 UTC (permalink / raw)
  To: Gaetan Rivet, dev

On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:

> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---

LGTM, Reviewed-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>

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

* Re: [PATCH v7 6/6] devargs: parse bus info
  2017-07-06  9:07               ` Shreyansh Jain
@ 2017-07-06 10:00                 ` Gaëtan Rivet
  2017-07-06 13:17                   ` Shreyansh Jain
  0 siblings, 1 reply; 123+ messages in thread
From: Gaëtan Rivet @ 2017-07-06 10:00 UTC (permalink / raw)
  To: Shreyansh Jain; +Cc: dev

On Thu, Jul 06, 2017 at 02:37:16PM +0530, Shreyansh Jain wrote:
> Hello Gaetan,
> 
> On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
> >Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> >---
> >  lib/librte_eal/common/eal_common_devargs.c  | 42 ++++++++++++++++++++++++-----
> >  lib/librte_eal/common/eal_common_vdev.c     |  6 +++--
> >  lib/librte_eal/common/include/rte_devargs.h |  3 +++
> >  3 files changed, 42 insertions(+), 9 deletions(-)
> >
> >diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
> >index ffa8ad9..102bd8d 100644
> >--- a/lib/librte_eal/common/eal_common_devargs.c
> >+++ b/lib/librte_eal/common/eal_common_devargs.c
> >@@ -78,12 +78,23 @@ rte_eal_parse_devargs_str(const char *devargs_str,
> >  	return 0;
> >  }
> >+static int
> >+bus_name_cmp(const struct rte_bus *bus, const void *_name)
> >+{
> >+	const char *name = _name;
> >+
> >+	return strncmp(bus->name, name,
> >+		       strlen(bus->name));
> 
> Trivial: Any specific reason why this is split across multiple lines even
> though it is less than 80 chars in total?
> 

Not really, it's only a matter of taste.
If is mostly to hightlight that we are limiting the comparison to
bus->name length, by putting it on its own line.

> >+}
> >+
> >  /* store a whitelist parameter for later parsing */
> >  int
> >  rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
> >  {
> >  	struct rte_devargs *devargs = NULL;
> >-	char *buf = NULL;
> >+	struct rte_bus *bus = NULL;
> >+	char *dev = NULL;
> >+	const char *devname;
> >  	int ret;
> >  	/* use malloc instead of rte_malloc as it's called early at init */
> >@@ -94,34 +105,51 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
> >  	memset(devargs, 0, sizeof(*devargs));
> >  	devargs->type = devtype;
> >-	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
> >+	if (rte_eal_parse_devargs_str(devargs_str, &dev, &devargs->args))
> 
> A very basic (and possibly incorrect) question:
> 
> here, for example "'net_pcap0,rx_pcap=input.pcap,tx_pcap=output.pcap'" was
> passed to application, which would mean;
> 
> dev = "net_pcap0" (name of the device)
> devargs = "rx_pcap=input.pcap,tx_pcap=output.pcap"
> 
> >  		goto fail;
> >+	devname = dev;
> >+	do {
> >+		bus = rte_bus_find(bus, bus_name_cmp, dev);
> >+		if (bus == NULL)
> >+			break;
> >+		devname = dev + strlen(bus->name) + 1;
> 
> Assuming "vdev" bus:
>                       "net_pcap0"
>                             |
> devname points here --------' (4+1) chars from start of "net_pcap0".
> Is that the expectation?
> 

Yes :)
Well, actually, almost. The lines

> >+		bus = rte_bus_find(bus, bus_name_cmp, dev);
> >+		if (bus == NULL)
> >+			break;

Mean that at this point, we would already have broken out of the loop.
But to continue with your example, assuming that we have a bus that
is named "net_p":

> Probably I am missing something here (maybe the input already has a bus
> name.)
> 
> Or, if this is not the case, then we will have to change the test
> application (test_devargs.c) which passes such strings to
> "rte_eal_devargs_add".
> 
> >+		if (rte_bus_find_by_device_name(devname) == bus)
> 
> Obviously, if my assumption is correct, this fails. Or, maybe I am
> completely off the mark.
> 

It should not be necessary to update the tests (yet).
This bit of code tries to recognize bus names at the start of the
declaration. However, some device names might be ambiguous and start
like bus names for any reason. Device names have no specification beside
not having commas within, bus names have no specification at all.

Thus, we first try here to recognize a bus name within dev, but we do
not stop here. We also verify afterward that the resulting device would
be correct, and that its bus handler is actually the same as the bus we
first recognized.

In your example, the line


> >+        if (rte_bus_find_by_device_name(devname) == bus)

Fails, as the device is incorrect and rte_bus_find_by_device_name
returns NULL as no bus is able to handle a device named

> "cap0,rx_pcap=input.pcap,tx_pcap=output.pcap"

Considering this, we should break from this loop with no recognized bus.
As such, we enter afterward in the branch:

> >+			break;
> >+		devname = dev;

Note here that devname is set back to the start of dev.

> >+	} while (1);
> >+	if (bus == NULL) {
> >+		bus = rte_bus_find_by_device_name(devname);

Which will try to recognize a bus from the device name ("net_pcap0"),
which should succeed in recognizing vdev.

It is a little contrived, but I wanted this parsing to both be flexible
and perform as many checks as possible.

I am developing a new bus that have a high probability of name conflicts
with other device names, so I am extra careful on this side.

> >+		if (bus == NULL) {
> >+			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
> >+			goto fail;
> >+		}
> >+	}
> >+	devargs->bus = bus;
>   >   	switch (devargs->type) {
> >  	case RTE_DEVTYPE_WHITELISTED_PCI:
> >  	case RTE_DEVTYPE_BLACKLISTED_PCI:
> >  		/* try to parse pci identifier */
> >-		if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
> >-		    eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0)
> >+		if (bus->parse(devname, &devargs->pci.addr) != 0)
> >  			goto fail;
> >  		break;
> >  	case RTE_DEVTYPE_VIRTUAL:
> >  		/* save driver name */
> >  		ret = snprintf(devargs->virt.drv_name,
> >-			       sizeof(devargs->virt.drv_name), "%s", buf);
> >+			       sizeof(devargs->virt.drv_name), "%s", devname);
> >  		if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name))
> >  			goto fail;
> >  		break;
> >  	}
> 
> I think all this will change in the devargs series.
> 

Indeed :)

> >-	free(buf);
> >+	free(dev);
> >  	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
> >  	return 0;
> >  fail:
> >-	free(buf);
> >+	free(dev);
> >  	if (devargs) {
> >  		free(devargs->args);
> >  		free(devargs);
> >diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
> >index 6ecd1b5..8fd1ef7 100644
> >--- a/lib/librte_eal/common/eal_common_vdev.c
> >+++ b/lib/librte_eal/common/eal_common_vdev.c
> >@@ -177,6 +177,7 @@ alloc_devargs(const char *name, const char *args)
> >  		return NULL;
> >  	devargs->type = RTE_DEVTYPE_VIRTUAL;
> >+	devargs->bus = rte_bus_find_by_name("vdev");
> >  	if (args)
> >  		devargs->args = strdup(args);
> >@@ -289,12 +290,13 @@ vdev_scan(void)
> >  {
> >  	struct rte_vdev_device *dev;
> >  	struct rte_devargs *devargs;
> >+	struct rte_bus *vbus;
> >  	/* for virtual devices we scan the devargs_list populated via cmdline */
> >-
> >+	vbus = rte_bus_find_by_name("vdev");
> >  	TAILQ_FOREACH(devargs, &devargs_list, next) {
> >-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
> >+		if (devargs->bus != vbus)
> >  			continue;
> >  		dev = find_vdev(devargs->virt.drv_name);
> >diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
> >index 88120a1..1f50a24 100644
> >--- a/lib/librte_eal/common/include/rte_devargs.h
> >+++ b/lib/librte_eal/common/include/rte_devargs.h
> >@@ -51,6 +51,7 @@ extern "C" {
> >  #include <stdio.h>
> >  #include <sys/queue.h>
> >  #include <rte_pci.h>
> >+#include <rte_bus.h>
> >  /**
> >   * Type of generic device
> >@@ -89,6 +90,8 @@ struct rte_devargs {
> >  			char drv_name[32];
> >  		} virt;
> >  	};
> >+	/** Bus handle for the device. */
> >+	struct rte_bus *bus;
> >  	/** Arguments string as given by user or "" for no argument. */
> >  	char *args;
> >  };
> >
> -
> Shreyansh

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH v7 5/6] bus: add helper to find a bus from a device name
  2017-07-05 13:45                 ` Gaëtan Rivet
  2017-07-05 14:12                   ` Shreyansh Jain
@ 2017-07-06 10:10                   ` Thomas Monjalon
  2017-07-06 11:37                     ` Gaëtan Rivet
  1 sibling, 1 reply; 123+ messages in thread
From: Thomas Monjalon @ 2017-07-06 10:10 UTC (permalink / raw)
  To: Gaëtan Rivet, Shreyansh Jain; +Cc: dev

05/07/2017 15:45, Gaëtan Rivet:
> On Wed, Jul 05, 2017 at 07:05:40PM +0530, Shreyansh Jain wrote:
> > >+struct rte_bus *
> > >+rte_bus_find_by_device_name(const char *str)
> > >+{
> > >+	char name[32];
> > 
> > It is possible to use a constant here? Basically, I am not sure why '32' has
> > been chosen - or maybe, it might remind a reader in future the reason for
> > this value.
> > 
> > Just to clarify: is there any documented limit on bus name? Until this
> > point, the name (and length) of bus was responsibility of bus driver
> > implementation. eal_common_bus.c doesn't codify any limit - so, this may
> > have to be advertised, even if just within the code.
> 
> I agree that this is not clear. First thing however: this is a limit on
> the device name length, not bus.
> 
> This problem is fixed in [1], as a single common device name location is
> defined. The problem is that it is in another patchset (even if both are
> closely linked and were only separated to ease integration).
> 
> This limit was currently taken from the arbitrary limit of device in
> name in the original rte_devargs for virtual devices. I think it could
> be exported as a define by rte_dev.h, used there and reused in [1] to
> define the new rte_devargs structure.

Please check this patch which was integrated yesterday:
	http://dpdk.org/commit/48d8675c9cf
Now you can use RTE_DEV_NAME_MAX_LEN instead of hardcoded 32.

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

* Re: [PATCH v7 5/6] bus: add helper to find a bus from a device name
  2017-07-06 10:10                   ` Thomas Monjalon
@ 2017-07-06 11:37                     ` Gaëtan Rivet
  0 siblings, 0 replies; 123+ messages in thread
From: Gaëtan Rivet @ 2017-07-06 11:37 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: Shreyansh Jain, dev

On Thu, Jul 06, 2017 at 12:10:10PM +0200, Thomas Monjalon wrote:
> 05/07/2017 15:45, Gaëtan Rivet:
> > On Wed, Jul 05, 2017 at 07:05:40PM +0530, Shreyansh Jain wrote:
> > > >+struct rte_bus *
> > > >+rte_bus_find_by_device_name(const char *str)
> > > >+{
> > > >+	char name[32];
> > > 
> > > It is possible to use a constant here? Basically, I am not sure why '32' has
> > > been chosen - or maybe, it might remind a reader in future the reason for
> > > this value.
> > > 
> > > Just to clarify: is there any documented limit on bus name? Until this
> > > point, the name (and length) of bus was responsibility of bus driver
> > > implementation. eal_common_bus.c doesn't codify any limit - so, this may
> > > have to be advertised, even if just within the code.
> > 
> > I agree that this is not clear. First thing however: this is a limit on
> > the device name length, not bus.
> > 
> > This problem is fixed in [1], as a single common device name location is
> > defined. The problem is that it is in another patchset (even if both are
> > closely linked and were only separated to ease integration).
> > 
> > This limit was currently taken from the arbitrary limit of device in
> > name in the original rte_devargs for virtual devices. I think it could
> > be exported as a define by rte_dev.h, used there and reused in [1] to
> > define the new rte_devargs structure.
> 
> Please check this patch which was integrated yesterday:
> 	http://dpdk.org/commit/48d8675c9cf
> Now you can use RTE_DEV_NAME_MAX_LEN instead of hardcoded 32.
> 

Yes I just saw that while rebasing, it's exactly what I needed. It will
be in the next version.

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH v7 2/6] bus: introduce parsing functionality
  2017-07-06  9:19               ` santosh
@ 2017-07-06 12:30                 ` Gaëtan Rivet
  2017-07-06 13:12                   ` santosh
  0 siblings, 1 reply; 123+ messages in thread
From: Gaëtan Rivet @ 2017-07-06 12:30 UTC (permalink / raw)
  To: santosh; +Cc: dev

On Thu, Jul 06, 2017 at 02:49:41PM +0530, santosh wrote:
> Hi Gaetan,
> 
> On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
> 
> > This operation can be used either to validate that a device
> > representation can be understood by a bus, as well as store the resulting
> > specialized device representation in any format determined by the bus.
> >
> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > ---
> >  lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
> >  1 file changed, 21 insertions(+)
> >
> > diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> > index 773b0d7..aebf57e 100644
> > --- a/lib/librte_eal/common/include/rte_bus.h
> > +++ b/lib/librte_eal/common/include/rte_bus.h
> > @@ -138,6 +138,26 @@ typedef int (*rte_bus_plug_t)(struct rte_device *dev,
> >  typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
> >  
> >  /**
> > + * Bus specific parsing function.
> > + * Validates the syntax used in the textual representation of a device,
> > + * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
> > + * device representation to ``addr``.
> > + *
> > + * @param[in] name
> > + *	device textual description
> > + *
> > + * @param[out] addr
> > + *	device information location address, into which parsed info
> > + *	should be written. If NULL, nothing should be written, which
> > + *	is not an error.
> > + *
> 
> r / is not a error/ is valid?
> 

I'm partial to "is not an error" here, but it doesn't matter that much
and I can change it if you prefer.

> > + * @return
> > + *	0 if parsing was successful.
> > + *	!0 for any error.
> > + */
> > +typedef int (*rte_bus_parse_t)(const char *name, void *addr);
> > +
> 
> _parse handler in _common_vdev or common_pci file return boolean value 
> i.e..0 for success and 1 for error, right? if so then
> !0 for any error would be like '1' for error case.. make sense?
> 

I thought of that yes, and actually your suggestion was the first
version I used.

Ultimately however, this function is not only saying "can parse": it is
not merely a test of being able to process the input, but also the
process itself. The test value is then a byproduct.

As such, I decided to settle on the standard "0 means nothing of note
happened, carry on".

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH v7 2/6] bus: introduce parsing functionality
  2017-07-06 12:30                 ` Gaëtan Rivet
@ 2017-07-06 13:12                   ` santosh
  2017-07-06 13:30                     ` Gaëtan Rivet
  0 siblings, 1 reply; 123+ messages in thread
From: santosh @ 2017-07-06 13:12 UTC (permalink / raw)
  To: Gaëtan Rivet; +Cc: dev

On Thursday 06 July 2017 06:00 PM, Gaëtan Rivet wrote:

> On Thu, Jul 06, 2017 at 02:49:41PM +0530, santosh wrote:
>> Hi Gaetan,
>>
>> On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
>>
>>> This operation can be used either to validate that a device
>>> representation can be understood by a bus, as well as store the resulting
>>> specialized device representation in any format determined by the bus.
>>>
>>> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
>>> ---
>>>  lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
>>>  1 file changed, 21 insertions(+)
>>>
>>> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
>>> index 773b0d7..aebf57e 100644
>>> --- a/lib/librte_eal/common/include/rte_bus.h
>>> +++ b/lib/librte_eal/common/include/rte_bus.h
>>> @@ -138,6 +138,26 @@ typedef int (*rte_bus_plug_t)(struct rte_device *dev,
>>>  typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
>>>  
>>>  /**
>>> + * Bus specific parsing function.
>>> + * Validates the syntax used in the textual representation of a device,
>>> + * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
>>> + * device representation to ``addr``.
>>> + *
>>> + * @param[in] name
>>> + *	device textual description
>>> + *
>>> + * @param[out] addr
>>> + *	device information location address, into which parsed info
>>> + *	should be written. If NULL, nothing should be written, which
>>> + *	is not an error.
>>> + *
>> r / is not a error/ is valid?
>>
> I'm partial to "is not an error" here, but it doesn't matter that much
> and I can change it if you prefer.
>
>>> + * @return
>>> + *	0 if parsing was successful.
>>> + *	!0 for any error.
>>> + */
>>> +typedef int (*rte_bus_parse_t)(const char *name, void *addr);
>>> +
>> _parse handler in _common_vdev or common_pci file return boolean value 
>> i.e..0 for success and 1 for error, right? if so then
>> !0 for any error would be like '1' for error case.. make sense?
>>
> I thought of that yes, and actually your suggestion was the first
> version I used.
>
> Ultimately however, this function is not only saying "can parse": it is
> not merely a test of being able to process the input, but also the
> process itself. The test value is then a byproduct.
>
> As such, I decided to settle on the standard "0 means nothing of note
> happened, carry on".

I'm not aware of past work history, catching up with stuff so no
strong opinion but In my opinion: if we're sure about return values then better
mention them explicitly.

Thanks.

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

* Re: [PATCH v7 6/6] devargs: parse bus info
  2017-07-06 10:00                 ` Gaëtan Rivet
@ 2017-07-06 13:17                   ` Shreyansh Jain
  0 siblings, 0 replies; 123+ messages in thread
From: Shreyansh Jain @ 2017-07-06 13:17 UTC (permalink / raw)
  To: Gaëtan Rivet; +Cc: dev

Hello Gaetan,

On Thursday 06 July 2017 03:30 PM, Gaëtan Rivet wrote:
> On Thu, Jul 06, 2017 at 02:37:16PM +0530, Shreyansh Jain wrote:
>> Hello Gaetan,
>>
>> On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
>>> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
>>> ---
>>>   lib/librte_eal/common/eal_common_devargs.c  | 42 ++++++++++++++++++++++++-----
>>>   lib/librte_eal/common/eal_common_vdev.c     |  6 +++--
>>>   lib/librte_eal/common/include/rte_devargs.h |  3 +++
>>>   3 files changed, 42 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
>>> index ffa8ad9..102bd8d 100644
>>> --- a/lib/librte_eal/common/eal_common_devargs.c
>>> +++ b/lib/librte_eal/common/eal_common_devargs.c
>>> @@ -78,12 +78,23 @@ rte_eal_parse_devargs_str(const char *devargs_str,
>>>   	return 0;
>>>   }
>>> +static int
>>> +bus_name_cmp(const struct rte_bus *bus, const void *_name)
>>> +{
>>> +	const char *name = _name;
>>> +
>>> +	return strncmp(bus->name, name,
>>> +		       strlen(bus->name));
>>
>> Trivial: Any specific reason why this is split across multiple lines even
>> though it is less than 80 chars in total?
>>
> 
> Not really, it's only a matter of taste.
> If is mostly to hightlight that we are limiting the comparison to
> bus->name length, by putting it on its own line.

Ok. I am ok with this.

> 
>>> +}
>>> +
>>>   /* store a whitelist parameter for later parsing */
>>>   int
>>>   rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>>>   {
>>>   	struct rte_devargs *devargs = NULL;
>>> -	char *buf = NULL;
>>> +	struct rte_bus *bus = NULL;
>>> +	char *dev = NULL;
>>> +	const char *devname;
>>>   	int ret;
>>>   	/* use malloc instead of rte_malloc as it's called early at init */
>>> @@ -94,34 +105,51 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
>>>   	memset(devargs, 0, sizeof(*devargs));
>>>   	devargs->type = devtype;
>>> -	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
>>> +	if (rte_eal_parse_devargs_str(devargs_str, &dev, &devargs->args))
>>
>> A very basic (and possibly incorrect) question:
>>
>> here, for example "'net_pcap0,rx_pcap=input.pcap,tx_pcap=output.pcap'" was
>> passed to application, which would mean;
>>
>> dev = "net_pcap0" (name of the device)
>> devargs = "rx_pcap=input.pcap,tx_pcap=output.pcap"
>>
>>>   		goto fail;
>>> +	devname = dev;
>>> +	do {
>>> +		bus = rte_bus_find(bus, bus_name_cmp, dev);
>>> +		if (bus == NULL)
>>> +			break;
>>> +		devname = dev + strlen(bus->name) + 1;
>>
>> Assuming "vdev" bus:
>>                        "net_pcap0"
>>                              |
>> devname points here --------' (4+1) chars from start of "net_pcap0".
>> Is that the expectation?
>>
> 
> Yes :)
> Well, actually, almost. The lines
> 
>>> +		bus = rte_bus_find(bus, bus_name_cmp, dev);
>>> +		if (bus == NULL)
>>> +			break;
> 
> Mean that at this point, we would already have broken out of the loop.
> But to continue with your example, assuming that we have a bus that
> is named "net_p":
> 
>> Probably I am missing something here (maybe the input already has a bus
>> name.)
>>
>> Or, if this is not the case, then we will have to change the test
>> application (test_devargs.c) which passes such strings to
>> "rte_eal_devargs_add".
>>
>>> +		if (rte_bus_find_by_device_name(devname) == bus)
>>
>> Obviously, if my assumption is correct, this fails. Or, maybe I am
>> completely off the mark.
>>
> 
> It should not be necessary to update the tests (yet).
> This bit of code tries to recognize bus names at the start of the
> declaration. However, some device names might be ambiguous and start
> like bus names for any reason. Device names have no specification beside
> not having commas within, bus names have no specification at all.
> 
> Thus, we first try here to recognize a bus name within dev, but we do
> not stop here. We also verify afterward that the resulting device would
> be correct, and that its bus handler is actually the same as the bus we
> first recognized.
> 
> In your example, the line
> 
> 
>>> +        if (rte_bus_find_by_device_name(devname) == bus)
> 
> Fails, as the device is incorrect and rte_bus_find_by_device_name
> returns NULL as no bus is able to handle a device named
> 
>> "cap0,rx_pcap=input.pcap,tx_pcap=output.pcap"
> 
> Considering this, we should break from this loop with no recognized bus.
> As such, we enter afterward in the branch:
> 
>>> +			break;
>>> +		devname = dev;
> 
> Note here that devname is set back to the start of dev.
> 
>>> +	} while (1);
>>> +	if (bus == NULL) {
>>> +		bus = rte_bus_find_by_device_name(devname);
> 
> Which will try to recognize a bus from the device name ("net_pcap0"),
> which should succeed in recognizing vdev.
> 
> It is a little contrived, but I wanted this parsing to both be flexible
> and perform as many checks as possible.
> 
> I am developing a new bus that have a high probability of name conflicts
> with other device names, so I am extra careful on this side.

Ok. I completely missed this logic.
Thanks.

> 
>>> +		if (bus == NULL) {
>>> +			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
>>> +			goto fail;
>>> +		}
>>> +	}
>>> +	devargs->bus = bus;
>>    >   	switch (devargs->type) {
>>>   	case RTE_DEVTYPE_WHITELISTED_PCI:
>>>   	case RTE_DEVTYPE_BLACKLISTED_PCI:
>>>   		/* try to parse pci identifier */
>>> -		if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
>>> -		    eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0)
>>> +		if (bus->parse(devname, &devargs->pci.addr) != 0)
>>>   			goto fail;
>>>   		break;
>>>   	case RTE_DEVTYPE_VIRTUAL:
>>>   		/* save driver name */
>>>   		ret = snprintf(devargs->virt.drv_name,
>>> -			       sizeof(devargs->virt.drv_name), "%s", buf);
>>> +			       sizeof(devargs->virt.drv_name), "%s", devname);
>>>   		if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name))
>>>   			goto fail;
>>>   		break;
>>>   	}
>>
>> I think all this will change in the devargs series.
>>
> 
> Indeed :)
> 
>>> -	free(buf);
>>> +	free(dev);
>>>   	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
>>>   	return 0;
>>>   fail:
>>> -	free(buf);
>>> +	free(dev);
>>>   	if (devargs) {
>>>   		free(devargs->args);
>>>   		free(devargs);
>>> diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
>>> index 6ecd1b5..8fd1ef7 100644
>>> --- a/lib/librte_eal/common/eal_common_vdev.c
>>> +++ b/lib/librte_eal/common/eal_common_vdev.c
>>> @@ -177,6 +177,7 @@ alloc_devargs(const char *name, const char *args)
>>>   		return NULL;
>>>   	devargs->type = RTE_DEVTYPE_VIRTUAL;
>>> +	devargs->bus = rte_bus_find_by_name("vdev");
>>>   	if (args)
>>>   		devargs->args = strdup(args);
>>> @@ -289,12 +290,13 @@ vdev_scan(void)
>>>   {
>>>   	struct rte_vdev_device *dev;
>>>   	struct rte_devargs *devargs;
>>> +	struct rte_bus *vbus;
>>>   	/* for virtual devices we scan the devargs_list populated via cmdline */
>>> -
>>> +	vbus = rte_bus_find_by_name("vdev");
>>>   	TAILQ_FOREACH(devargs, &devargs_list, next) {
>>> -		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
>>> +		if (devargs->bus != vbus)
>>>   			continue;
>>>   		dev = find_vdev(devargs->virt.drv_name);
>>> diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
>>> index 88120a1..1f50a24 100644
>>> --- a/lib/librte_eal/common/include/rte_devargs.h
>>> +++ b/lib/librte_eal/common/include/rte_devargs.h
>>> @@ -51,6 +51,7 @@ extern "C" {
>>>   #include <stdio.h>
>>>   #include <sys/queue.h>
>>>   #include <rte_pci.h>
>>> +#include <rte_bus.h>
>>>   /**
>>>    * Type of generic device
>>> @@ -89,6 +90,8 @@ struct rte_devargs {
>>>   			char drv_name[32];
>>>   		} virt;
>>>   	};
>>> +	/** Bus handle for the device. */
>>> +	struct rte_bus *bus;
>>>   	/** Arguments string as given by user or "" for no argument. */
>>>   	char *args;
>>>   };
>>>
>> -
>> Shreyansh
> 

And, for this patch as well:

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

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

* Re: [PATCH v7 2/6] bus: introduce parsing functionality
  2017-07-06 13:12                   ` santosh
@ 2017-07-06 13:30                     ` Gaëtan Rivet
  0 siblings, 0 replies; 123+ messages in thread
From: Gaëtan Rivet @ 2017-07-06 13:30 UTC (permalink / raw)
  To: santosh; +Cc: dev

On Thu, Jul 06, 2017 at 06:42:23PM +0530, santosh wrote:
> On Thursday 06 July 2017 06:00 PM, Gaëtan Rivet wrote:
> 
> > On Thu, Jul 06, 2017 at 02:49:41PM +0530, santosh wrote:
> >> Hi Gaetan,
> >>
> >> On Wednesday 05 July 2017 05:25 AM, Gaetan Rivet wrote:
> >>
> >>> This operation can be used either to validate that a device
> >>> representation can be understood by a bus, as well as store the resulting
> >>> specialized device representation in any format determined by the bus.
> >>>
> >>> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> >>> ---
> >>>  lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
> >>>  1 file changed, 21 insertions(+)
> >>>
> >>> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> >>> index 773b0d7..aebf57e 100644
> >>> --- a/lib/librte_eal/common/include/rte_bus.h
> >>> +++ b/lib/librte_eal/common/include/rte_bus.h
> >>> @@ -138,6 +138,26 @@ typedef int (*rte_bus_plug_t)(struct rte_device *dev,
> >>>  typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
> >>>  
> >>>  /**
> >>> + * Bus specific parsing function.
> >>> + * Validates the syntax used in the textual representation of a device,
> >>> + * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
> >>> + * device representation to ``addr``.
> >>> + *
> >>> + * @param[in] name
> >>> + *	device textual description
> >>> + *
> >>> + * @param[out] addr
> >>> + *	device information location address, into which parsed info
> >>> + *	should be written. If NULL, nothing should be written, which
> >>> + *	is not an error.
> >>> + *
> >> r / is not a error/ is valid?
> >>
> > I'm partial to "is not an error" here, but it doesn't matter that much
> > and I can change it if you prefer.
> >
> >>> + * @return
> >>> + *	0 if parsing was successful.
> >>> + *	!0 for any error.
> >>> + */
> >>> +typedef int (*rte_bus_parse_t)(const char *name, void *addr);
> >>> +
> >> _parse handler in _common_vdev or common_pci file return boolean value 
> >> i.e..0 for success and 1 for error, right? if so then
> >> !0 for any error would be like '1' for error case.. make sense?
> >>
> > I thought of that yes, and actually your suggestion was the first
> > version I used.
> >
> > Ultimately however, this function is not only saying "can parse": it is
> > not merely a test of being able to process the input, but also the
> > process itself. The test value is then a byproduct.
> >
> > As such, I decided to settle on the standard "0 means nothing of note
> > happened, carry on".
> 
> I'm not aware of past work history, catching up with stuff so no
> strong opinion but In my opinion: if we're sure about return values then better
> mention them explicitly.
> 

That's the way it has been implemented in vdev and pci, but other buses
might want to use internal helpers in their version, that might return
something else than 1 on error.

As such, I think it's better to push the weakest specification
sufficient to match our needs and not force unnecessary hoops on
developers downstream.

> Thanks.
> 
> 

-- 
Gaëtan Rivet
6WIND

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

* [PATCH v8 0/6] rte_bus parse API
  2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
                               ` (5 preceding siblings ...)
  2017-07-04 23:55             ` [PATCH v7 6/6] devargs: parse bus info Gaetan Rivet
@ 2017-07-07  0:03             ` Gaetan Rivet
  2017-07-07  0:03               ` [PATCH v8 1/6] bus: fix driver registration Gaetan Rivet
                                 ` (6 more replies)
  6 siblings, 7 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-07  0:03 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet, Jan Blunck, Stephen Hemminger, Bruce Richardson

Following the evolutions announced in [1], here is the first part of
the rte_devargs rework planned for 17.08. The rationale has been partially
explained in [2].

This first part covers the introduction of the necessary facilities in
rte_bus to allow for generic device parsing. This API is implemented for
the virtual and PCI buses. Additionally, this rte_bus evolution is being
used within rte_devargs to characterize a device type by its bus.
This work is the first of two parts to reduce the dependency of the EAL
upon specific bus implementations.

The modified rte_devargs parsing allows declaring on the EAL command line
explicit buses to handle a device. The format is as follow:

  --vdev="virtual:net_ring0" --vdev="net_tap0,iface=tap0"
  -w PCI:00:02.0 -w 00:03.0

This explicit bus designation is optional; no evolution is currently
forced on users to migrate to this new format. The separating character is
arbitrary.

[1]: http://dpdk.org/ml/archives/dev/2017-May/065634.html
[2]: http://dpdk.org/ml/archives/dev/2017-May/065670.html

This patchset depends on:

bus attach/detach API and hotplug rework
http://dpdk.org/ml/archives/dev/2017-June/069643.html
http://dpdk.org/dev/patchwork/patch/26135/

v1 -> v2:

  * fix PCI parse implementation

v2 --> v3:

  * Rebase the series on the new plug / unplug API

v3 --> v4:

  * Several bug fixes, commit log rewrite.
  * Follow the changes to the plug / unplug API.

v5:

  * Do not verify bus name on bus registration.
    Actually, a legal bus name is not defined anymore.
    The bus/device separator in a device declaration can be anything,
    as long as it is a single character.
    The behavior is otherwise unchanged.

v6:

  * Rebase upon new hotplug patchset version.
  * Rename rte_bus_from_dev as rte_bus_find_by_device_name.
    This function is now private to the EAL.
  * Remove rte_bus_from_name, as it has been integrated as
    rte_bus_find_by_name by Jan Blunck.
  * Reduce parsing ambiguity in rte_devargs.

v7:

  * Use Thomas' bus registration fix.
  * Improve rte_bus_find_by_device_name, by making
    more resistant to shaky bus parse implementation.

v8:

  * Fix a few incorrect bus name references.
  * Add a few acks.
  * Clarify the standing of the bus parse API in its
    introductory commit log.

Gaetan Rivet (5):
  bus: introduce parsing functionality
  vdev: implement parse bus operation
  pci: implement parse bus operation
  bus: add helper to find a bus from a device name
  devargs: parse bus info

Thomas Monjalon (1):
  bus: fix driver registration

 drivers/bus/fslmc/fslmc_bus.c               |  2 +-
 drivers/bus/fslmc/rte_fslmc.h               |  3 --
 lib/librte_eal/common/eal_common_bus.c      | 23 +++++++++-
 lib/librte_eal/common/eal_common_dev.c      |  2 +-
 lib/librte_eal/common/eal_common_devargs.c  | 42 +++++++++++++++---
 lib/librte_eal/common/eal_common_pci.c      | 17 +++++++-
 lib/librte_eal/common/eal_common_vdev.c     | 66 +++++++++++++++--------------
 lib/librte_eal/common/eal_private.h         | 12 ++++++
 lib/librte_eal/common/include/rte_bus.h     | 24 ++++++++++-
 lib/librte_eal/common/include/rte_devargs.h |  3 ++
 lib/librte_eal/common/include/rte_eal.h     |  3 ++
 lib/librte_eal/common/include/rte_pci.h     |  3 --
 lib/librte_eal/common/include/rte_vdev.h    |  2 -
 13 files changed, 150 insertions(+), 52 deletions(-)

-- 
2.1.4

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

* [PATCH v8 1/6] bus: fix driver registration
  2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
@ 2017-07-07  0:03               ` Gaetan Rivet
  2017-07-07  0:03               ` [PATCH v8 2/6] bus: introduce parsing functionality Gaetan Rivet
                                 ` (5 subsequent siblings)
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-07  0:03 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon

From: Thomas Monjalon <thomas@monjalon.net>

The bus name was stored with embedded double quotes.
Indeed the bus name is given with a string in a macro,
which is not used elsewhere.
These macros are useless because the buses are drivers,
so they must not have any API for the application writer.
The registration can be done with a hardcoded value without quotes.

There is another (small) benefit of not using macros for driver names:
it is to have a meaningful constructor function name.
For instance, it was businitfn_PCI_BUS_NAME instead of businitfn_pci.

The bus registration macro is also changed to use
the new RTE_INIT_PRIO macro, similar to RTE_INIT used for other drivers.
The priority is the highest (101) in order to be sure that the bus driver
is registered before its device drivers.

Fixes: 0fd1a0eaae19 ("pci: add bus driver")
Fixes: fea892e35f21 ("bus/vdev: use standard bus registration")
Fixes: 7e7df6d0a41d ("bus/fslmc: introduce fsl-mc bus driver")

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Reviewed-by: Santosh Shukla <santosh.shukla@caviumnetworks.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 drivers/bus/fslmc/fslmc_bus.c            | 2 +-
 drivers/bus/fslmc/rte_fslmc.h            | 3 ---
 lib/librte_eal/common/eal_common_bus.c   | 2 +-
 lib/librte_eal/common/eal_common_dev.c   | 2 +-
 lib/librte_eal/common/eal_common_pci.c   | 2 +-
 lib/librte_eal/common/eal_common_vdev.c  | 2 +-
 lib/librte_eal/common/include/rte_bus.h  | 3 ++-
 lib/librte_eal/common/include/rte_eal.h  | 3 +++
 lib/librte_eal/common/include/rte_pci.h  | 3 ---
 lib/librte_eal/common/include/rte_vdev.h | 2 --
 10 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 1e3bbee..f9e2211 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -161,4 +161,4 @@ struct rte_fslmc_bus rte_fslmc_bus = {
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.driver_list),
 };
 
-RTE_REGISTER_BUS(FSLMC_BUS_NAME, rte_fslmc_bus.bus);
+RTE_REGISTER_BUS(fslmc, rte_fslmc_bus.bus);
diff --git a/drivers/bus/fslmc/rte_fslmc.h b/drivers/bus/fslmc/rte_fslmc.h
index 040ab95..8f35278 100644
--- a/drivers/bus/fslmc/rte_fslmc.h
+++ b/drivers/bus/fslmc/rte_fslmc.h
@@ -56,9 +56,6 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_bus.h>
 
-/** Name of FSLMC Bus */
-#define FSLMC_BUS_NAME "FSLMC"
-
 struct rte_dpaa2_driver;
 
 /* DPAA2 Device and Driver lists for FSLMC bus */
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 87b0c6e..fd59b7c 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -92,7 +92,7 @@ rte_bus_probe(void)
 	struct rte_bus *bus, *vbus = NULL;
 
 	TAILQ_FOREACH(bus, &rte_bus_list, next) {
-		if (!strcmp(bus->name, "virtual")) {
+		if (!strcmp(bus->name, "vdev")) {
 			vbus = bus;
 			continue;
 		}
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 4ee52fd..32e12b5 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -74,7 +74,7 @@ int rte_eal_dev_attach(const char *name, const char *devargs)
 		return -EINVAL;
 	}
 
-	ret = rte_eal_hotplug_add("PCI", name, devargs);
+	ret = rte_eal_hotplug_add("pci", name, devargs);
 	if (ret && ret != -EINVAL)
 		return ret;
 
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 5ee100e..2c99049 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -549,4 +549,4 @@ struct rte_pci_bus rte_pci_bus = {
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
 };
 
-RTE_REGISTER_BUS(PCI_BUS_NAME, rte_pci_bus.bus);
+RTE_REGISTER_BUS(pci, rte_pci_bus.bus);
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index baf3c5b..3bad0c4 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -374,4 +374,4 @@ static struct rte_bus rte_vdev_bus = {
 	.unplug = vdev_unplug,
 };
 
-RTE_REGISTER_BUS(VIRTUAL_BUS_NAME, rte_vdev_bus);
+RTE_REGISTER_BUS(vdev, rte_vdev_bus);
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 2f1c911..773b0d7 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -256,7 +256,8 @@ struct rte_bus *rte_bus_find_by_name(const char *busname);
  * The constructor has higher priority than PMD constructors.
  */
 #define RTE_REGISTER_BUS(nm, bus) \
-static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
+RTE_INIT_PRIO(businitfn_ ##nm, 101); \
+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 abf020b..6b7c5ca 100644
--- a/lib/librte_eal/common/include/rte_eal.h
+++ b/lib/librte_eal/common/include/rte_eal.h
@@ -286,6 +286,9 @@ static inline int rte_gettid(void)
 #define RTE_INIT(func) \
 static void __attribute__((constructor, used)) func(void)
 
+#define RTE_INIT_PRIO(func, prio) \
+static void __attribute__((constructor(prio), used)) func(void)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index e416714..406d918 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -77,9 +77,6 @@ const char *pci_get_sysfs_path(void);
 /** Maximum number of PCI resources. */
 #define PCI_MAX_RESOURCE 6
 
-/** Name of PCI Bus */
-#define PCI_BUS_NAME "PCI"
-
 /* Forward declarations */
 struct rte_pci_device;
 struct rte_pci_driver;
diff --git a/lib/librte_eal/common/include/rte_vdev.h b/lib/librte_eal/common/include/rte_vdev.h
index 2d02c68..e6b678e 100644
--- a/lib/librte_eal/common/include/rte_vdev.h
+++ b/lib/librte_eal/common/include/rte_vdev.h
@@ -41,8 +41,6 @@ extern "C" {
 #include <rte_dev.h>
 #include <rte_devargs.h>
 
-#define VIRTUAL_BUS_NAME "virtual"
-
 struct rte_vdev_device {
 	TAILQ_ENTRY(rte_vdev_device) next;      /**< Next attached vdev */
 	struct rte_device device;               /**< Inherit core device */
-- 
2.1.4

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

* [PATCH v8 2/6] bus: introduce parsing functionality
  2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
  2017-07-07  0:03               ` [PATCH v8 1/6] bus: fix driver registration Gaetan Rivet
@ 2017-07-07  0:03               ` Gaetan Rivet
  2017-07-07  0:03               ` [PATCH v8 3/6] vdev: implement parse bus operation Gaetan Rivet
                                 ` (4 subsequent siblings)
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-07  0:03 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

This operation can be used either to validate that a device
representation can be understood by a bus, as well as store the resulting
specialized device representation in any format determined by the bus.

Implementing this function allows EAL initialization routines to infer
which bus should handle a device. This is used as a way to respect
backward compatibility.

This API will disappear once this compatibility is not enforced anymore.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/include/rte_bus.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 773b0d7..aebf57e 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -138,6 +138,26 @@ typedef int (*rte_bus_plug_t)(struct rte_device *dev,
 typedef int (*rte_bus_unplug_t)(struct rte_device *dev);
 
 /**
+ * Bus specific parsing function.
+ * Validates the syntax used in the textual representation of a device,
+ * If the syntax is valid and ``addr`` is not NULL, writes the bus-specific
+ * device representation to ``addr``.
+ *
+ * @param[in] name
+ *	device textual description
+ *
+ * @param[out] addr
+ *	device information location address, into which parsed info
+ *	should be written. If NULL, nothing should be written, which
+ *	is not an error.
+ *
+ * @return
+ *	0 if parsing was successful.
+ *	!0 for any error.
+ */
+typedef int (*rte_bus_parse_t)(const char *name, void *addr);
+
+/**
  * A structure describing a generic bus.
  */
 struct rte_bus {
@@ -148,6 +168,7 @@ struct rte_bus {
 	rte_bus_find_device_t find_device; /**< Find a device on the bus */
 	rte_bus_plug_t plug;         /**< Probe single device for drivers */
 	rte_bus_unplug_t unplug;     /**< Remove single device from driver */
+	rte_bus_parse_t parse;       /**< Parse a device name */
 };
 
 /**
-- 
2.1.4

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

* [PATCH v8 3/6] vdev: implement parse bus operation
  2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
  2017-07-07  0:03               ` [PATCH v8 1/6] bus: fix driver registration Gaetan Rivet
  2017-07-07  0:03               ` [PATCH v8 2/6] bus: introduce parsing functionality Gaetan Rivet
@ 2017-07-07  0:03               ` Gaetan Rivet
  2017-07-07  0:03               ` [PATCH v8 4/6] pci: " Gaetan Rivet
                                 ` (3 subsequent siblings)
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-07  0:03 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_eal/common/eal_common_vdev.c | 58 ++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 29 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 3bad0c4..6ecd1b5 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -102,6 +102,27 @@ static char *parse_driver_arg(const char *args)
 }
 
 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)) == 0)
+			break;
+		if (driver->driver.alias &&
+		    strncmp(driver->driver.alias, name,
+			    strlen(driver->driver.alias)) == 0)
+			break;
+	}
+	if (driver != NULL &&
+	    addr != NULL)
+		*out = driver;
+	return driver == NULL;
+}
+
+static int
 vdev_probe_all_drivers(struct rte_vdev_device *dev)
 {
 	const char *name;
@@ -115,36 +136,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;
-		}
-	}
-
-	/* 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;
-		}
+	if (vdev_parse(name, &driver)) {
+		ret = -1;
+		goto out;
 	}
-
+	dev->device.driver = &driver->driver;
+	ret = driver->probe(dev);
+	if (ret)
+		dev->device.driver = NULL;
 out:
 	free(drv_name);
 	return ret;
@@ -372,6 +371,7 @@ static struct rte_bus rte_vdev_bus = {
 	.find_device = vdev_find_device,
 	/* .plug = NULL, see comment on vdev_unplug */
 	.unplug = vdev_unplug,
+	.parse = vdev_parse,
 };
 
 RTE_REGISTER_BUS(vdev, rte_vdev_bus);
-- 
2.1.4

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

* [PATCH v8 4/6] pci: implement parse bus operation
  2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
                                 ` (2 preceding siblings ...)
  2017-07-07  0:03               ` [PATCH v8 3/6] vdev: implement parse bus operation Gaetan Rivet
@ 2017-07-07  0:03               ` Gaetan Rivet
  2017-07-07  0:03               ` [PATCH v8 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
                                 ` (2 subsequent siblings)
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-07  0:03 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_eal/common/eal_common_pci.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 2c99049..d7e2fb4 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -448,6 +448,20 @@ rte_pci_dump(FILE *f)
 	}
 }
 
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	bool parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr != NULL)
+		*out = pci_addr;
+	return parse == false;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -544,6 +558,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.find_device = pci_find_device,
 		.plug = pci_plug,
 		.unplug = pci_unplug,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
-- 
2.1.4

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

* [PATCH v8 5/6] bus: add helper to find a bus from a device name
  2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
                                 ` (3 preceding siblings ...)
  2017-07-07  0:03               ` [PATCH v8 4/6] pci: " Gaetan Rivet
@ 2017-07-07  0:03               ` Gaetan Rivet
  2017-07-07  0:03               ` [PATCH v8 6/6] devargs: parse bus info Gaetan Rivet
  2017-07-08 20:30               ` [PATCH v8 0/6] rte_bus parse API Thomas Monjalon
  6 siblings, 0 replies; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-07  0:03 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Find which bus should be able to parse this device name into an internal
device representation.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_eal/common/eal_common_bus.c | 21 +++++++++++++++++++++
 lib/librte_eal/common/eal_private.h    | 12 ++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index fd59b7c..4fc30bb 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -204,3 +204,24 @@ rte_bus_find_by_name(const char *busname)
 {
 	return rte_bus_find(NULL, cmp_bus_name, (const void *)busname);
 }
+
+static int
+bus_can_parse(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return !(bus->parse && bus->parse(name, NULL) == 0);
+}
+
+struct rte_bus *
+rte_bus_find_by_device_name(const char *str)
+{
+	char name[RTE_DEV_NAME_MAX_LEN];
+	char *c;
+
+	snprintf(name, sizeof(name), "%s", str);
+	c = strchr(name, ',');
+	if (c != NULL)
+		c[0] = '\0';
+	return rte_bus_find(NULL, bus_can_parse, name);
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 6cacce0..0836339 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -338,4 +338,16 @@ int rte_eal_hugepage_attach(void);
  */
 bool rte_eal_using_phys_addrs(void);
 
+/**
+ * Find a bus capable of identifying a device.
+ *
+ * @param str
+ *   A device identifier (PCI address, virtual PMD name, ...).
+ *
+ * @return
+ *   A valid bus handle if found.
+ *   NULL if no bus is able to parse this device.
+ */
+struct rte_bus *rte_bus_find_by_device_name(const char *str);
+
 #endif /* _EAL_PRIVATE_H_ */
-- 
2.1.4

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

* [PATCH v8 6/6] devargs: parse bus info
  2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
                                 ` (4 preceding siblings ...)
  2017-07-07  0:03               ` [PATCH v8 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
@ 2017-07-07  0:03               ` Gaetan Rivet
  2017-07-07  0:45                 ` Stephen Hemminger
  2017-07-08 20:30               ` [PATCH v8 0/6] rte_bus parse API Thomas Monjalon
  6 siblings, 1 reply; 123+ messages in thread
From: Gaetan Rivet @ 2017-07-07  0:03 UTC (permalink / raw)
  To: dev; +Cc: Gaetan Rivet

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
Acked-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/common/eal_common_devargs.c  | 42 ++++++++++++++++++++++++-----
 lib/librte_eal/common/eal_common_vdev.c     |  6 +++--
 lib/librte_eal/common/include/rte_devargs.h |  3 +++
 3 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index ffa8ad9..102bd8d 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -78,12 +78,23 @@ rte_eal_parse_devargs_str(const char *devargs_str,
 	return 0;
 }
 
+static int
+bus_name_cmp(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return strncmp(bus->name, name,
+		       strlen(bus->name));
+}
+
 /* store a whitelist parameter for later parsing */
 int
 rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 {
 	struct rte_devargs *devargs = NULL;
-	char *buf = NULL;
+	struct rte_bus *bus = NULL;
+	char *dev = NULL;
+	const char *devname;
 	int ret;
 
 	/* use malloc instead of rte_malloc as it's called early at init */
@@ -94,34 +105,51 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
 	memset(devargs, 0, sizeof(*devargs));
 	devargs->type = devtype;
 
-	if (rte_eal_parse_devargs_str(devargs_str, &buf, &devargs->args))
+	if (rte_eal_parse_devargs_str(devargs_str, &dev, &devargs->args))
 		goto fail;
+	devname = dev;
+	do {
+		bus = rte_bus_find(bus, bus_name_cmp, dev);
+		if (bus == NULL)
+			break;
+		devname = dev + strlen(bus->name) + 1;
+		if (rte_bus_find_by_device_name(devname) == bus)
+			break;
+		devname = dev;
+	} while (1);
+	if (bus == NULL) {
+		bus = rte_bus_find_by_device_name(devname);
+		if (bus == NULL) {
+			fprintf(stderr, "ERROR: failed to parse bus info from device declaration\n");
+			goto fail;
+		}
+	}
+	devargs->bus = bus;
 
 	switch (devargs->type) {
 	case RTE_DEVTYPE_WHITELISTED_PCI:
 	case RTE_DEVTYPE_BLACKLISTED_PCI:
 		/* try to parse pci identifier */
-		if (eal_parse_pci_BDF(buf, &devargs->pci.addr) != 0 &&
-		    eal_parse_pci_DomBDF(buf, &devargs->pci.addr) != 0)
+		if (bus->parse(devname, &devargs->pci.addr) != 0)
 			goto fail;
 
 		break;
 	case RTE_DEVTYPE_VIRTUAL:
 		/* save driver name */
 		ret = snprintf(devargs->virt.drv_name,
-			       sizeof(devargs->virt.drv_name), "%s", buf);
+			       sizeof(devargs->virt.drv_name), "%s", devname);
 		if (ret < 0 || ret >= (int)sizeof(devargs->virt.drv_name))
 			goto fail;
 
 		break;
 	}
 
-	free(buf);
+	free(dev);
 	TAILQ_INSERT_TAIL(&devargs_list, devargs, next);
 	return 0;
 
 fail:
-	free(buf);
+	free(dev);
 	if (devargs) {
 		free(devargs->args);
 		free(devargs);
diff --git a/lib/librte_eal/common/eal_common_vdev.c b/lib/librte_eal/common/eal_common_vdev.c
index 6ecd1b5..8fd1ef7 100644
--- a/lib/librte_eal/common/eal_common_vdev.c
+++ b/lib/librte_eal/common/eal_common_vdev.c
@@ -177,6 +177,7 @@ alloc_devargs(const char *name, const char *args)
 		return NULL;
 
 	devargs->type = RTE_DEVTYPE_VIRTUAL;
+	devargs->bus = rte_bus_find_by_name("vdev");
 	if (args)
 		devargs->args = strdup(args);
 
@@ -289,12 +290,13 @@ vdev_scan(void)
 {
 	struct rte_vdev_device *dev;
 	struct rte_devargs *devargs;
+	struct rte_bus *vbus;
 
 	/* for virtual devices we scan the devargs_list populated via cmdline */
-
+	vbus = rte_bus_find_by_name("vdev");
 	TAILQ_FOREACH(devargs, &devargs_list, next) {
 
-		if (devargs->type != RTE_DEVTYPE_VIRTUAL)
+		if (devargs->bus != vbus)
 			continue;
 
 		dev = find_vdev(devargs->virt.drv_name);
diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h
index b11cbfc..6014853 100644
--- a/lib/librte_eal/common/include/rte_devargs.h
+++ b/lib/librte_eal/common/include/rte_devargs.h
@@ -51,6 +51,7 @@ extern "C" {
 #include <stdio.h>
 #include <sys/queue.h>
 #include <rte_pci.h>
+#include <rte_bus.h>
 
 /**
  * Type of generic device
@@ -89,6 +90,8 @@ struct rte_devargs {
 			char drv_name[RTE_DEV_NAME_MAX_LEN];
 		} virt;
 	};
+	/** Bus handle for the device. */
+	struct rte_bus *bus;
 	/** Arguments string as given by user or "" for no argument. */
 	char *args;
 };
-- 
2.1.4

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

* Re: [PATCH v8 6/6] devargs: parse bus info
  2017-07-07  0:03               ` [PATCH v8 6/6] devargs: parse bus info Gaetan Rivet
@ 2017-07-07  0:45                 ` Stephen Hemminger
  2017-07-07  8:31                   ` Gaëtan Rivet
  0 siblings, 1 reply; 123+ messages in thread
From: Stephen Hemminger @ 2017-07-07  0:45 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev

On Fri,  7 Jul 2017 02:03:12 +0200
Gaetan Rivet <gaetan.rivet@6wind.com> wrote:

> +static int
> +bus_name_cmp(const struct rte_bus *bus, const void *_name)
> +{
> +	const char *name = _name;
> +
> +	return strncmp(bus->name, name,
> +		       strlen(bus->name));

I don't think you need the _name variable hack. C will cast the argument to strncmp

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

* Re: [PATCH v8 6/6] devargs: parse bus info
  2017-07-07  0:45                 ` Stephen Hemminger
@ 2017-07-07  8:31                   ` Gaëtan Rivet
  2017-07-08 20:31                     ` Thomas Monjalon
  0 siblings, 1 reply; 123+ messages in thread
From: Gaëtan Rivet @ 2017-07-07  8:31 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

On Thu, Jul 06, 2017 at 05:45:02PM -0700, Stephen Hemminger wrote:
> On Fri,  7 Jul 2017 02:03:12 +0200
> Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> 
> > +static int
> > +bus_name_cmp(const struct rte_bus *bus, const void *_name)
> > +{
> > +	const char *name = _name;
> > +
> > +	return strncmp(bus->name, name,
> > +		       strlen(bus->name));
> 
> I don't think you need the _name variable hack. C will cast the argument to strncmp

You're right, and it was just habit. Usually I prefer giving a type to a
generic parameter, but in this case it may be too trivial.

-- 
Gaëtan Rivet
6WIND

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

* Re: [PATCH v8 0/6] rte_bus parse API
  2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
                                 ` (5 preceding siblings ...)
  2017-07-07  0:03               ` [PATCH v8 6/6] devargs: parse bus info Gaetan Rivet
@ 2017-07-08 20:30               ` Thomas Monjalon
  6 siblings, 0 replies; 123+ messages in thread
From: Thomas Monjalon @ 2017-07-08 20:30 UTC (permalink / raw)
  To: Gaetan Rivet; +Cc: dev, Jan Blunck, Stephen Hemminger, Bruce Richardson

> Gaetan Rivet (5):
>   bus: introduce parsing functionality
>   vdev: implement parse bus operation
>   pci: implement parse bus operation
>   bus: add helper to find a bus from a device name
>   devargs: parse bus info
> 
> Thomas Monjalon (1):
>   bus: fix driver registration

Series applied with the small change suggested by Stephen, thanks

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

* Re: [PATCH v8 6/6] devargs: parse bus info
  2017-07-07  8:31                   ` Gaëtan Rivet
@ 2017-07-08 20:31                     ` Thomas Monjalon
  0 siblings, 0 replies; 123+ messages in thread
From: Thomas Monjalon @ 2017-07-08 20:31 UTC (permalink / raw)
  To: Gaëtan Rivet, Stephen Hemminger; +Cc: dev

07/07/2017 10:31, Gaëtan Rivet:
> On Thu, Jul 06, 2017 at 05:45:02PM -0700, Stephen Hemminger wrote:
> > On Fri,  7 Jul 2017 02:03:12 +0200
> > Gaetan Rivet <gaetan.rivet@6wind.com> wrote:
> > 
> > > +static int
> > > +bus_name_cmp(const struct rte_bus *bus, const void *_name)
> > > +{
> > > +	const char *name = _name;
> > > +
> > > +	return strncmp(bus->name, name,
> > > +		       strlen(bus->name));
> > 
> > I don't think you need the _name variable hack. C will cast the argument to strncmp
> 
> You're right, and it was just habit. Usually I prefer giving a type to a
> generic parameter, but in this case it may be too trivial.

Simplified when applying.

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

end of thread, other threads:[~2017-07-08 20:31 UTC | newest]

Thread overview: 123+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-24 15:12 [PATCH 0/9] rte_bus parse API Gaetan Rivet
2017-05-24 15:12 ` [PATCH 1/9] bus: fix bus name registration Gaetan Rivet
2017-05-24 15:12 ` [PATCH 2/9] bus: verify bus name on registration Gaetan Rivet
2017-05-24 15:12 ` [PATCH 3/9] bus: introduce parsing functionality Gaetan Rivet
2017-05-24 15:12 ` [PATCH 4/9] vdev: implement parse bus operation Gaetan Rivet
2017-05-24 15:12 ` [PATCH 5/9] pci: " Gaetan Rivet
2017-05-24 15:12 ` [PATCH 6/9] bus: add helper to find bus from a name Gaetan Rivet
2017-05-24 15:12 ` [PATCH 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
2017-06-07 17:28   ` Jan Blunck
2017-06-07 20:03     ` Gaëtan Rivet
2017-06-08 10:45       ` Jan Blunck
2017-06-08 11:36         ` Gaëtan Rivet
2017-06-08 11:40           ` Jan Blunck
2017-06-08 12:51             ` Gaëtan Rivet
2017-06-10  8:50               ` Jan Blunck
2017-06-12 14:21                 ` Gaëtan Rivet
2017-05-24 15:12 ` [PATCH 8/9] vdev: expose bus name Gaetan Rivet
2017-05-24 15:12 ` [PATCH 9/9] devargs: parse bus info Gaetan Rivet
2017-05-24 16:15 ` [PATCH v2 0/9] rte_bus parse API Gaetan Rivet
2017-05-24 16:15   ` [PATCH v2 1/9] bus: fix bus name registration Gaetan Rivet
2017-05-24 16:15   ` [PATCH v2 2/9] bus: verify bus name on registration Gaetan Rivet
2017-05-24 16:15   ` [PATCH v2 3/9] bus: introduce parsing functionality Gaetan Rivet
2017-05-24 16:15   ` [PATCH v2 4/9] vdev: implement parse bus operation Gaetan Rivet
2017-05-24 16:15   ` [PATCH v2 5/9] pci: " Gaetan Rivet
2017-05-24 16:15   ` [PATCH v2 6/9] bus: add helper to find bus from a name Gaetan Rivet
2017-05-24 16:15   ` [PATCH v2 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
2017-05-24 16:15   ` [PATCH v2 8/9] vdev: expose bus name Gaetan Rivet
2017-05-24 16:15   ` [PATCH v2 9/9] devargs: parse bus info Gaetan Rivet
2017-06-01 10:08   ` [PATCH v3 0/9] rte_bus parse API Gaetan Rivet
2017-06-01 10:08     ` [PATCH v3 1/9] bus: fix bus name registration Gaetan Rivet
2017-06-01 10:08     ` [PATCH v3 2/9] bus: verify bus name on registration Gaetan Rivet
2017-06-01 10:08     ` [PATCH v3 3/9] bus: introduce parsing functionality Gaetan Rivet
2017-06-01 10:08     ` [PATCH v3 4/9] vdev: implement parse bus operation Gaetan Rivet
2017-06-01 10:08     ` [PATCH v3 5/9] pci: " Gaetan Rivet
2017-06-01 10:08     ` [PATCH v3 6/9] bus: add helper to find bus from a name Gaetan Rivet
2017-06-01 10:08     ` [PATCH v3 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
2017-06-01 10:08     ` [PATCH v3 8/9] vdev: expose bus name Gaetan Rivet
2017-06-01 10:08     ` [PATCH v3 9/9] devargs: parse bus info Gaetan Rivet
2017-06-07 23:56     ` [PATCH v4 0/9] rte_bus parse API Gaetan Rivet
2017-06-07 23:56       ` [PATCH v4 1/9] bus: fix bus name registration Gaetan Rivet
2017-06-07 23:56       ` [PATCH v4 2/9] bus: verify bus name on registration Gaetan Rivet
2017-06-07 23:56       ` [PATCH v4 3/9] bus: introduce parsing functionality Gaetan Rivet
2017-06-07 23:56       ` [PATCH v4 4/9] vdev: implement parse bus operation Gaetan Rivet
2017-06-07 23:56       ` [PATCH v4 5/9] pci: " Gaetan Rivet
2017-06-07 23:56       ` [PATCH v4 6/9] bus: add helper to find a bus from a bus name Gaetan Rivet
2017-06-07 23:56       ` [PATCH v4 7/9] bus: add helper to find a bus from a device name Gaetan Rivet
2017-06-07 23:56       ` [PATCH v4 8/9] vdev: expose bus name Gaetan Rivet
2017-06-07 23:56       ` [PATCH v4 9/9] devargs: parse bus info Gaetan Rivet
2017-06-20 23:30       ` [PATCH v5 0/7] rte_bus parse API Gaetan Rivet
2017-06-20 23:30         ` [PATCH v5 1/7] bus: fix bus name registration Gaetan Rivet
2017-06-27 15:53           ` Bruce Richardson
2017-06-27 19:19           ` Jan Blunck
2017-07-04  1:05             ` Gaëtan Rivet
2017-06-20 23:30         ` [PATCH v5 2/7] bus: introduce parsing functionality Gaetan Rivet
2017-06-27 15:54           ` Bruce Richardson
2017-06-27 19:26           ` Jan Blunck
2017-07-04  1:35             ` Gaëtan Rivet
2017-06-20 23:30         ` [PATCH v5 3/7] vdev: implement parse bus operation Gaetan Rivet
2017-06-27 15:59           ` Bruce Richardson
2017-06-20 23:30         ` [PATCH v5 4/7] pci: " Gaetan Rivet
2017-06-27 16:18           ` Bruce Richardson
2017-06-20 23:30         ` [PATCH v5 5/7] bus: add helper to find a bus from a device name Gaetan Rivet
2017-06-27 16:26           ` Bruce Richardson
2017-06-27 18:55           ` Jan Blunck
2017-06-28 17:03             ` Thomas Monjalon
2017-06-29  7:56               ` Jan Blunck
2017-06-29  8:21                 ` Thomas Monjalon
2017-06-29 10:23                 ` Gaëtan Rivet
2017-06-29 10:30                   ` Richardson, Bruce
2017-06-20 23:30         ` [PATCH v5 6/7] vdev: expose bus name Gaetan Rivet
2017-06-20 23:30         ` [PATCH v5 7/7] devargs: parse bus info Gaetan Rivet
2017-06-27 16:01         ` [PATCH v5 0/7] rte_bus parse API Bruce Richardson
2017-07-04  0:58         ` [PATCH v6 0/6] " Gaetan Rivet
2017-07-04  0:58           ` [PATCH v6 1/6] bus: fix bus name registration Gaetan Rivet
2017-07-04 21:43             ` [PATCH] bus: fix driver registration Thomas Monjalon
2017-07-05  5:47               ` Shreyansh Jain
2017-07-05  6:01                 ` Shreyansh Jain
2017-07-04  0:58           ` [PATCH v6 2/6] bus: introduce parsing functionality Gaetan Rivet
2017-07-04  0:58           ` [PATCH v6 3/6] vdev: implement parse bus operation Gaetan Rivet
2017-07-04  0:58           ` [PATCH v6 4/6] pci: " Gaetan Rivet
2017-07-04  0:58           ` [PATCH v6 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
2017-07-04 12:28             ` Gaëtan Rivet
2017-07-04  0:58           ` [PATCH v6 6/6] devargs: parse bus info Gaetan Rivet
2017-07-04 23:55           ` [PATCH v7 0/6] rte_bus parse API Gaetan Rivet
2017-07-04 23:55             ` [PATCH v7 1/6] bus: fix driver registration Gaetan Rivet
2017-07-05 13:03               ` Shreyansh Jain
2017-07-06  6:05               ` santosh
2017-07-04 23:55             ` [PATCH v7 2/6] bus: introduce parsing functionality Gaetan Rivet
2017-07-05 13:04               ` Shreyansh Jain
2017-07-06  9:19               ` santosh
2017-07-06 12:30                 ` Gaëtan Rivet
2017-07-06 13:12                   ` santosh
2017-07-06 13:30                     ` Gaëtan Rivet
2017-07-04 23:55             ` [PATCH v7 3/6] vdev: implement parse bus operation Gaetan Rivet
2017-07-05 13:16               ` Shreyansh Jain
2017-07-06  9:35               ` santosh
2017-07-04 23:55             ` [PATCH v7 4/6] pci: " Gaetan Rivet
2017-07-04 23:55             ` [PATCH v7 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
2017-07-05 13:35               ` Shreyansh Jain
2017-07-05 13:45                 ` Gaëtan Rivet
2017-07-05 14:12                   ` Shreyansh Jain
2017-07-06 10:10                   ` Thomas Monjalon
2017-07-06 11:37                     ` Gaëtan Rivet
2017-07-04 23:55             ` [PATCH v7 6/6] devargs: parse bus info Gaetan Rivet
2017-07-05 18:03               ` Stephen Hemminger
2017-07-06  9:07               ` Shreyansh Jain
2017-07-06 10:00                 ` Gaëtan Rivet
2017-07-06 13:17                   ` Shreyansh Jain
2017-07-07  0:03             ` [PATCH v8 0/6] rte_bus parse API Gaetan Rivet
2017-07-07  0:03               ` [PATCH v8 1/6] bus: fix driver registration Gaetan Rivet
2017-07-07  0:03               ` [PATCH v8 2/6] bus: introduce parsing functionality Gaetan Rivet
2017-07-07  0:03               ` [PATCH v8 3/6] vdev: implement parse bus operation Gaetan Rivet
2017-07-07  0:03               ` [PATCH v8 4/6] pci: " Gaetan Rivet
2017-07-07  0:03               ` [PATCH v8 5/6] bus: add helper to find a bus from a device name Gaetan Rivet
2017-07-07  0:03               ` [PATCH v8 6/6] devargs: parse bus info Gaetan Rivet
2017-07-07  0:45                 ` Stephen Hemminger
2017-07-07  8:31                   ` Gaëtan Rivet
2017-07-08 20:31                     ` Thomas Monjalon
2017-07-08 20:30               ` [PATCH v8 0/6] rte_bus parse API Thomas Monjalon
2017-06-07 17:22 ` [PATCH 0/9] " Jan Blunck
2017-06-07 19:55   ` Gaëtan Rivet
2017-06-08 11:38     ` Jan Blunck
2017-06-08 13:04       ` Gaëtan Rivet

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.