diff mbox series

[v1,7/7] bus/pci: add new global device syntax support

Message ID 20210108145441.23320-8-xuemingl@nvidia.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series eal: support global syntax | expand

Checks

Context Check Description
ci/iol-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/checkpatch success coding style OK

Commit Message

Xueming(Steven) Li Jan. 8, 2021, 2:54 p.m. UTC
With new global device syntax, this patch tries to get PCI BDF firstly
from bus "addr" argument, fallback to name if not found. Example:

 -w bus=pci,addr=82:00.0/class=eth/driver=mlx5,dv_flow_en=1

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
 drivers/bus/pci/pci_common.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 9b8d769287..f6fc80abe8 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -23,6 +23,7 @@ 
 #include <rte_string_fns.h>
 #include <rte_common.h>
 #include <rte_devargs.h>
+#include <rte_kvargs.h>
 #include <rte_vfio.h>
 
 #include "private.h"
@@ -48,9 +49,20 @@  pci_devargs_lookup(const struct rte_pci_addr *pci_addr)
 {
 	struct rte_devargs *devargs;
 	struct rte_pci_addr addr;
+	struct rte_kvargs *kvlist = NULL;
+	const char *name;
 
 	RTE_EAL_DEVARGS_FOREACH("pci", devargs) {
-		devargs->bus->parse(devargs->name, &addr);
+		name = NULL;
+		if (devargs->bus_str) {
+			kvlist = rte_kvargs_parse(devargs->bus_str, NULL);
+			name = rte_kvargs_get(kvlist, "id");
+		}
+		if (!name)
+			name = devargs->name;
+		devargs->bus->parse(name, &addr);
+		if (kvlist)
+			rte_kvargs_free(kvlist);
 		if (!rte_pci_addr_cmp(pci_addr, &addr))
 			return devargs;
 	}
@@ -71,11 +83,11 @@  pci_name_set(struct rte_pci_device *dev)
 	/* When using a blocklist, only blocked devices will have
 	 * an rte_devargs. Allowed devices won't have one.
 	 */
-	if (devargs != NULL)
+	if (devargs != NULL && strlen(devargs->name))
 		/* If an rte_devargs exists, the generic rte_device uses the
 		 * given name as its name.
 		 */
-		dev->device.name = dev->device.devargs->name;
+		dev->device.name = devargs->name;
 	else
 		/* Otherwise, it uses the internal, canonical form. */
 		dev->device.name = dev->name;