diff mbox series

[v2,4/5] devargs: parse name from global device syntax

Message ID 1610983002-7630-5-git-send-email-xuemingl@nvidia.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers show
Series eal: enable global device syntax | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Xueming Li Jan. 18, 2021, 3:16 p.m. UTC
To use Global Device Syntax as devarg, name is required for device
management.

This patch adds global device syntax name resolving by using same
strategy as function rte_eth_iterator_init(), parses from "addr" bus
parameter for PCI bus, from "name" bus parameter for vdev bus.
Example:
 -a bus=pci,addr=83:00.0/class=eth/driver=mlx5,...
    name: 03:00.0
 -a bus=vdev,name=pcap0/class=eth/driver=pcap,...
    name:pcap0

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
---
 lib/librte_eal/common/eal_common_devargs.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index 9c7a7de30e..27af4cc0e3 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -57,6 +57,7 @@  rte_devargs_layers_parse(struct rte_devargs *devargs,
 	struct rte_class *cls = NULL;
 	struct rte_bus *bus = NULL;
 	const char *s = devstr;
+	const char *name = NULL;
 	size_t nblayer;
 	size_t i = 0;
 	int ret = 0;
@@ -116,6 +117,8 @@  rte_devargs_layers_parse(struct rte_devargs *devargs,
 		if (layers[i].kvlist == NULL)
 			continue;
 		kv = &layers[i].kvlist->pairs[0];
+		if (!kv->key)
+			continue;
 		if (strcmp(kv->key, "bus") == 0) {
 			bus = rte_bus_find_by_name(kv->value);
 			if (bus == NULL) {
@@ -146,6 +149,16 @@  rte_devargs_layers_parse(struct rte_devargs *devargs,
 	devargs->cls = cls;
 	devargs->src = devstr;
 
+	/* Parse device name. */
+	if (bus) {
+		if (strcmp(bus->name, "vdev") == 0)
+			name = rte_kvargs_get(layers[0].kvlist, "name");
+		else if (strcmp(bus->name, "pci") == 0)
+			name = rte_kvargs_get(layers[0].kvlist, "addr");
+		if (name != NULL)
+			strncpy(devargs->name, name, sizeof(devargs->name) - 1);
+	}
+
 	/* If we own the data, clean up a bit
 	 * the several layers string, to ease
 	 * their parsing afterward.