[dpdk-dev] [PATCH v1 13/18] bus/pci: implement device iteration and comparison

Gaetan Rivet gaetan.rivet at 6wind.com
Thu Mar 15 18:49:43 CET 2018


Signed-off-by: Gaetan Rivet <gaetan.rivet at 6wind.com>
---
 drivers/bus/pci/Makefile     |  2 +-
 drivers/bus/pci/pci_common.c | 54 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/pci/Makefile b/drivers/bus/pci/Makefile
index f3df1c4ce..73498dc77 100644
--- a/drivers/bus/pci/Makefile
+++ b/drivers/bus/pci/Makefile
@@ -50,7 +50,7 @@ CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common
 CFLAGS += -I$(RTE_SDK)/lib/librte_eal/$(SYSTEM)app/eal
 
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
-LDLIBS += -lrte_ethdev -lrte_pci
+LDLIBS += -lrte_ethdev -lrte_pci -lrte_kvargs
 
 include $(RTE_SDK)/drivers/bus/pci/$(SYSTEM)/Makefile
 SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) := $(addprefix $(SYSTEM)/,$(SRCS))
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 2c45f8151..482c96df2 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -13,6 +13,7 @@
 
 #include <rte_errno.h>
 #include <rte_interrupts.h>
+#include <rte_kvargs.h>
 #include <rte_log.h>
 #include <rte_bus.h>
 #include <rte_pci.h>
@@ -497,6 +498,58 @@ pci_unplug(struct rte_device *dev)
 	return ret;
 }
 
+static int
+pci_dev_match(const struct rte_device *dev,
+	      const void *_kvlist)
+{
+	const struct rte_kvargs *kvlist = _kvlist;
+
+	(void) dev;
+	(void) kvlist;
+	return 0;
+}
+
+static struct rte_device *
+pci_dev_iterate(struct rte_dev_iterator *it)
+{
+	struct rte_device *dev = it->device;
+	struct rte_kvargs *kvargs = NULL;
+	char *str = NULL;
+
+	if (it->busstr != NULL) {
+		char *slash;
+
+		str = strdup(it->busstr);
+		if (str == NULL) {
+			RTE_LOG(ERR, EAL, "could not allocate string copy\n");
+			rte_errno = ENOMEM;
+			return NULL;
+		}
+		slash = strchr(str, '/');
+		slash = slash ? slash : strchr(str, '\0');
+		if (slash == NULL) {
+			RTE_LOG(ERR, EAL, "malformed string\n");
+			rte_errno = EINVAL;
+			goto free_str;
+		}
+		slash[0] = '\0';
+		kvargs = rte_kvargs_parse(str, NULL);
+		if (kvargs == NULL) {
+			RTE_LOG(ERR, EAL, "cannot parse argument list\n");
+			rte_errno = EINVAL;
+			goto free_str;
+		}
+	}
+	dev = pci_find_device(dev, pci_dev_match, kvargs);
+	it->device = dev;
+free_str:
+	if (it->busstr != NULL) {
+		free(str);
+		rte_kvargs_free(kvargs);
+	}
+	return dev;
+}
+
 struct rte_pci_bus rte_pci_bus = {
 	.bus = {
 		.scan = rte_pci_scan,
@@ -506,6 +559,7 @@ struct rte_pci_bus rte_pci_bus = {
 		.unplug = pci_unplug,
 		.parse = pci_parse,
 		.get_iommu_class = rte_pci_get_iommu_class,
+		.dev_iterate = pci_dev_iterate,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
-- 
2.11.0



More information about the dev mailing list