DPDK patches and discussions
 help / color / mirror / Atom feed
From: Shreyansh Jain <shreyansh.jain@nxp.com>
To: <dev@dpdk.org>
Cc: <thomas.monjalon@6wind.com>, <david.marchand@6wind.com>,
	Shreyansh Jain <shreyansh.jain@nxp.com>
Subject: [dpdk-dev] [PATCH 12/13] eal: enable PCI bus
Date: Sun, 4 Dec 2016 15:41:27 +0530	[thread overview]
Message-ID: <1480846288-2517-13-git-send-email-shreyansh.jain@nxp.com> (raw)
In-Reply-To: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com>

Register a PCI bus with Scan/match and probe callbacks. Necessary changes
in EAL layer for enabling bus interfaces. PCI devices and drivers now
reside within the Bus object.

Removing PCI init and probe from rte_eal_init now that bus performs these
functions.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal.c         |   7 --
 lib/librte_eal/bsdapp/eal/eal_pci.c     |  42 +++++++---
 lib/librte_eal/common/eal_common_bus.c  |   5 +-
 lib/librte_eal/common/eal_common_pci.c  | 137 ++++++++++++++++++++++++++------
 lib/librte_eal/common/eal_private.h     |   4 +-
 lib/librte_eal/common/include/rte_bus.h |   5 ++
 lib/librte_eal/common/include/rte_pci.h |   3 +
 lib/librte_eal/linuxapp/eal/eal.c       |   7 --
 lib/librte_eal/linuxapp/eal/eal_pci.c   |  43 +++++++---
 9 files changed, 189 insertions(+), 64 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
index 30afc6b..79d82d4 100644
--- a/lib/librte_eal/bsdapp/eal/eal.c
+++ b/lib/librte_eal/bsdapp/eal/eal.c
@@ -562,9 +562,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_timer_init() < 0)
 		rte_panic("Cannot init HPET or TSC timers\n");
 
-	if (rte_eal_pci_init() < 0)
-		rte_panic("Cannot init PCI\n");
-
 	eal_check_mem_on_local_socket();
 
 	if (eal_plugins_init() < 0)
@@ -616,10 +613,6 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe & Initialize PCI devices */
-	if (rte_eal_pci_probe())
-		rte_panic("Cannot probe PCI\n");
-
 	if (rte_eal_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 10b234e..ab04408 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -58,6 +58,7 @@
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_common.h>
 #include <rte_launch.h>
@@ -249,7 +250,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
 }
 
 static int
-pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
+pci_scan_one(struct rte_bus *bus, int dev_pci_fd, struct pci_conf *conf)
 {
 	struct rte_pci_device *dev;
 	struct pci_bar_io bar;
@@ -322,19 +323,23 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 	}
 
 	/* device is valid, add in list (sorted) */
-	if (TAILQ_EMPTY(&pci_device_list)) {
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+	if (TAILQ_EMPTY(&bus->device_list)) {
+		rte_eal_bus_add_device(bus, &dev->device);
 	}
 	else {
 		struct rte_pci_device *dev2 = NULL;
+		struct rte_device *r_dev2;
 		int ret;
 
-		TAILQ_FOREACH(dev2, &pci_device_list, next) {
+		TAILQ_FOREACH(r_dev2, &bus->device_list, next) {
+			dev2 = container_of(r_dev2, struct rte_pci_device,
+					    device);
 			ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
 			if (ret > 0)
 				continue;
 			else if (ret < 0) {
-				TAILQ_INSERT_BEFORE(dev2, dev, next);
+				rte_eal_bus_insert_device(bus, &dev2->device,
+							  &dev->device);
 				return 0;
 			} else { /* already registered */
 				dev2->kdrv = dev->kdrv;
@@ -346,7 +351,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 				return 0;
 			}
 		}
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+		rte_eal_bus_add_device(bus, &dev->device);
 	}
 
 	return 0;
@@ -361,7 +366,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
  * list. Call pci_scan_one() for each pci entry found.
  */
 int
-rte_eal_pci_scan(struct rte_bus *bus __rte_unused)
+rte_eal_pci_scan(struct rte_bus *bus)
 {
 	int fd;
 	unsigned dev_count = 0;
@@ -374,6 +379,10 @@ rte_eal_pci_scan(struct rte_bus *bus __rte_unused)
 			.matches = &matches[0],
 	};
 
+	/* for debug purposes, PCI can be disabled */
+	if (internal_config.no_pci)
+		return 0;
+
 	fd = open("/dev/pci", O_RDONLY);
 	if (fd < 0) {
 		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
@@ -389,7 +398,7 @@ rte_eal_pci_scan(struct rte_bus *bus __rte_unused)
 		}
 
 		for (i = 0; i < conf_io.num_matches; i++)
-			if (pci_scan_one(fd, &matches[i]) < 0)
+			if (pci_scan_one(bus, fd, &matches[i]) < 0)
 				goto error;
 
 		dev_count += conf_io.num_matches;
@@ -407,9 +416,9 @@ rte_eal_pci_scan(struct rte_bus *bus __rte_unused)
 }
 
 int
-pci_update_device(const struct rte_pci_addr *addr)
+pci_update_device(struct rte_bus *bus, const struct rte_pci_addr *addr)
 {
-	int fd;
+	int fd = -1;
 	struct pci_conf matches[2];
 	struct pci_match_conf match = {
 		.pc_sel = {
@@ -427,6 +436,9 @@ pci_update_device(const struct rte_pci_addr *addr)
 		.matches = &matches[0],
 	};
 
+	if (!bus)
+		goto error;
+
 	fd = open("/dev/pci", O_RDONLY);
 	if (fd < 0) {
 		RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
@@ -442,7 +454,7 @@ pci_update_device(const struct rte_pci_addr *addr)
 	if (conf_io.num_matches != 1)
 		goto error;
 
-	if (pci_scan_one(fd, &matches[0]) < 0)
+	if (pci_scan_one(bus, fd, &matches[0]) < 0)
 		goto error;
 
 	close(fd);
@@ -682,3 +694,11 @@ rte_eal_pci_init(void)
 	}
 	return 0;
 }
+
+struct rte_bus pci_bus = {
+	.scan = rte_eal_pci_scan,
+	.match = rte_eal_pci_match_default,
+	.probe = rte_eal_pci_probe_default,
+};
+
+RTE_REGISTER_BUS(pci, pci_bus);
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index 469abac..52bf051 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -196,7 +196,7 @@ rte_eal_bus_scan(void)
 }
 
 static int
-perform_probe(struct rte_bus *bus __rte_unused, struct rte_driver *driver,
+perform_probe(struct rte_bus *bus, struct rte_driver *driver,
 	      struct rte_device *device)
 {
 	int ret;
@@ -208,7 +208,7 @@ perform_probe(struct rte_bus *bus __rte_unused, struct rte_driver *driver,
 		return 0;
 	}
 
-	ret = driver->probe(driver, device);
+	ret = bus->probe(driver, device);
 	if (ret < 0)
 		/* One of the probes failed */
 		RTE_LOG(ERR, EAL, "Probe failed for (%s).\n", driver->name);
@@ -234,6 +234,7 @@ rte_eal_bus_probe(void)
 			TAILQ_FOREACH(driver, &bus->driver_list, next) {
 				ret = bus->match(driver, device);
 				if (!ret) {
+					device->driver = driver;
 					ret = perform_probe(bus, driver,
 							    device);
 					if (ret < 0)
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index ba84ccb..4093746 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -71,6 +71,7 @@
 
 #include <rte_interrupts.h>
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_per_lcore.h>
 #include <rte_memory.h>
@@ -230,15 +231,6 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
 		return 1;
 	}
 
-	/* The device is not blacklisted; Check if driver supports it */
-	ret = rte_eal_pci_match_default(driver, device);
-	if (ret) {
-		/* Match of device and driver failed */
-		RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match the device\n",
-			driver->name);
-		return 1;
-	}
-
 	RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
 			dev->id.device_id, dr->driver.name);
 
@@ -322,19 +314,24 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
  * failed, return 1 if no driver is found for this device.
  */
 static int
-pci_probe_all_drivers(struct rte_pci_device *dev)
+pci_probe_all_drivers(struct rte_bus *bus, struct rte_pci_device *dev)
 {
 	struct rte_pci_driver *dr = NULL;
+	struct rte_driver *r_dr = NULL;
 	int rc = 0;
 
 	if (dev == NULL)
 		return -1;
 
+	if (!bus)
+		return -1;
+
 	/* Check if a driver is already loaded */
 	if (dev->driver != NULL)
 		return 0;
 
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
+	TAILQ_FOREACH(r_dr, &bus->driver_list, next) {
+		dr = container_of(r_dr, struct rte_pci_driver, driver);
 		rc = rte_eal_pci_probe_one_driver(dr, dev);
 		if (rc < 0)
 			/* negative value is an error */
@@ -353,15 +350,20 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
  * failed, return 1 if no driver is found for this device.
  */
 static int
-pci_detach_all_drivers(struct rte_pci_device *dev)
+pci_detach_all_drivers(struct rte_bus *bus, struct rte_pci_device *dev)
 {
 	struct rte_pci_driver *dr = NULL;
+	struct rte_driver *r_dr = NULL;
 	int rc = 0;
 
 	if (dev == NULL)
 		return -1;
 
-	TAILQ_FOREACH(dr, &pci_driver_list, next) {
+	if (!bus)
+		return -1;
+
+	TAILQ_FOREACH(r_dr, &bus->driver_list, next) {
+		dr = container_of(r_dr, struct rte_pci_driver, driver);
 		rc = rte_eal_pci_detach_dev(dr, dev);
 		if (rc < 0)
 			/* negative value is an error */
@@ -382,22 +384,31 @@ int
 rte_eal_pci_probe_one(const struct rte_pci_addr *addr)
 {
 	struct rte_pci_device *dev = NULL;
+	struct rte_device *r_dev = NULL;
+	struct rte_bus *bus;
 	int ret = 0;
 
 	if (addr == NULL)
 		return -1;
 
+	bus = rte_eal_get_bus("pci");
+	if (!bus) {
+		RTE_LOG(ERR, EAL, "PCI Bus not registered\n");
+		return -1;
+	}
+
 	/* update current pci device in global list, kernel bindings might have
 	 * changed since last time we looked at it.
 	 */
-	if (pci_update_device(addr) < 0)
+	if (pci_update_device(bus, addr) < 0)
 		goto err_return;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	TAILQ_FOREACH(r_dev, &bus->device_list, next) {
+		dev = container_of(r_dev, struct rte_pci_device, device);
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
-		ret = pci_probe_all_drivers(dev);
+		ret = pci_probe_all_drivers(bus, dev);
 		if (ret)
 			goto err_return;
 		return 0;
@@ -418,20 +429,29 @@ int
 rte_eal_pci_detach(const struct rte_pci_addr *addr)
 {
 	struct rte_pci_device *dev = NULL;
+	struct rte_device *r_dev = NULL;
+	struct rte_bus *bus;
 	int ret = 0;
 
 	if (addr == NULL)
 		return -1;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	bus = rte_eal_get_bus("pci");
+	if (!bus) {
+		RTE_LOG(ERR, EAL, "PCI Bus is not registered\n");
+		return -1;
+	}
+
+	TAILQ_FOREACH(r_dev, &bus->device_list, next) {
+		dev = container_of(r_dev, struct rte_pci_device, device);
 		if (rte_eal_compare_pci_addr(&dev->addr, addr))
 			continue;
 
-		ret = pci_detach_all_drivers(dev);
+		ret = pci_detach_all_drivers(bus, dev);
 		if (ret < 0)
 			goto err_return;
 
-		TAILQ_REMOVE(&pci_device_list, dev, next);
+		rte_eal_bus_remove_device(r_dev);
 		free(dev);
 		return 0;
 	}
@@ -469,10 +489,10 @@ rte_eal_pci_probe(void)
 
 		/* probe all or only whitelisted devices */
 		if (probe_all)
-			ret = pci_probe_all_drivers(dev);
+			ret = pci_probe_all_drivers(NULL, dev);
 		else if (devargs != NULL &&
 			devargs->type == RTE_DEVTYPE_WHITELISTED_PCI)
-			ret = pci_probe_all_drivers(dev);
+			ret = pci_probe_all_drivers(NULL, dev);
 		if (ret < 0)
 			rte_exit(EXIT_FAILURE, "Requested device " PCI_PRI_FMT
 				 " cannot be used\n", dev->addr.domain, dev->addr.bus,
@@ -482,6 +502,44 @@ rte_eal_pci_probe(void)
 	return 0;
 }
 
+int
+rte_eal_pci_probe_default(struct rte_driver *driver, struct rte_device *device)
+{
+	int ret = 0;
+	struct rte_devargs *devargs;
+	struct rte_pci_device *pci_dev;
+	struct rte_pci_driver *pci_drv;
+
+	if (!driver || !device)
+		return -1;
+
+	pci_dev = container_of(device, struct rte_pci_device, device);
+	pci_drv = container_of(driver, struct rte_pci_driver, driver);
+
+	ret = rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI);
+	if (ret != 0) {
+		/* set devargs in PCI structure */
+		devargs = pci_devargs_lookup(pci_dev);
+		if (devargs != NULL &&
+		    devargs->type == RTE_DEVTYPE_WHITELISTED_PCI) {
+			pci_dev->device.devargs = devargs;
+		} else {
+			/* Ignore the device */
+			return 0;
+		}
+	}
+
+	ret = rte_eal_pci_probe_one_driver(pci_drv, pci_dev);
+	if (ret < 0) {
+		RTE_LOG(ERR, EAL, "Requested device " PCI_PRI_FMT
+			" cannot be used\n", pci_dev->addr.domain,
+			pci_dev->addr.bus, pci_dev->addr.devid,
+			pci_dev->addr.function);
+		return ret;
+	}
+	return 0;
+}
+
 /* dump one device */
 static int
 pci_dump_one_device(FILE *f, struct rte_pci_device *dev)
@@ -507,8 +565,17 @@ void
 rte_eal_pci_dump(FILE *f)
 {
 	struct rte_pci_device *dev = NULL;
+	struct rte_device *r_dev = NULL;
+	struct rte_bus *bus;
 
-	TAILQ_FOREACH(dev, &pci_device_list, next) {
+	bus = rte_eal_get_bus("pci");
+	if (!bus) {
+		RTE_LOG(ERR, EAL, "PCI Bus not registered\n");
+		return;
+	}
+
+	TAILQ_FOREACH(r_dev, &bus->device_list, next) {
+		dev = container_of(r_dev, struct rte_pci_device, device);
 		pci_dump_one_device(f, dev);
 	}
 }
@@ -517,14 +584,32 @@ rte_eal_pci_dump(FILE *f)
 void
 rte_eal_pci_register(struct rte_pci_driver *driver)
 {
-	TAILQ_INSERT_TAIL(&pci_driver_list, driver, next);
-	rte_eal_driver_register(&driver->driver);
+	struct rte_bus *bus;
+
+	RTE_VERIFY(driver);
+
+	bus = rte_eal_get_bus("pci");
+	if (!bus) {
+		RTE_LOG(ERR, EAL, "PCI Bus not registered\n");
+		return;
+	}
+
+	rte_eal_bus_add_driver(bus, &driver->driver);
 }
 
 /* unregister a driver */
 void
 rte_eal_pci_unregister(struct rte_pci_driver *driver)
 {
-	rte_eal_driver_unregister(&driver->driver);
-	TAILQ_REMOVE(&pci_driver_list, driver, next);
+	struct rte_bus *bus;
+
+	RTE_VERIFY(driver);
+
+	bus = driver->driver.bus;
+	if (!bus) {
+		RTE_LOG(ERR, EAL, "PCI Bus not registered\n");
+		return;
+	}
+
+	rte_eal_bus_remove_driver(&driver->driver);
 }
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 9e7d8f6..e006d95 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -126,13 +126,15 @@ struct rte_pci_device;
  *
  * This function is private to EAL.
  *
+ * @param bus
+ *	The PCI bus on which device is connected
  * @param addr
  *	The PCI Bus-Device-Function address to look for
  * @return
  *   - 0 on success.
  *   - negative on error.
  */
-int pci_update_device(const struct rte_pci_addr *addr);
+int pci_update_device(struct rte_bus *bus, const struct rte_pci_addr *addr);
 
 /**
  * Unbind kernel driver for this device
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 9bd8650..e8db5b4 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -102,6 +102,10 @@ typedef int (*bus_scan_t)(struct rte_bus *bus);
  */
 typedef int (*bus_match_t)(struct rte_driver *drv, struct rte_device *dev);
 
+/** TODO
+ */
+typedef int (*bus_probe_t)(struct rte_driver *drv, struct rte_device *dev);
+
 struct rte_bus {
 	TAILQ_ENTRY(rte_bus) next;   /**< Next bus object in linked list */
 	struct rte_driver_list driver_list;
@@ -112,6 +116,7 @@ struct rte_bus {
 	bus_scan_t scan;            /**< Scan for devices attached to bus */
 	bus_match_t match;
 	/**< Match device with drivers associated with the bus */
+	bus_probe_t probe;           /**< TODO */
 };
 
 /** @internal
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 2a5f766..c0a0c6a 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -371,6 +371,9 @@ rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
  */
 int rte_eal_pci_scan(struct rte_bus *bus);
 
+int
+rte_eal_pci_probe_default(struct rte_driver *driver, struct rte_device *device);
+
 /**
  * Match the PCI Driver and Device using the ID Table
  *
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 01d0cee..ff92de2 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -803,9 +803,6 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0)
 		rte_panic("Cannot init logs\n");
 
-	if (rte_eal_pci_init() < 0)
-		rte_panic("Cannot init PCI\n");
-
 #ifdef VFIO_PRESENT
 	if (rte_eal_vfio_setup() < 0)
 		rte_panic("Cannot init VFIO\n");
@@ -887,10 +884,6 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
 	rte_eal_mp_wait_lcore();
 
-	/* Probe & Initialize PCI devices */
-	if (rte_eal_pci_probe())
-		rte_panic("Cannot probe PCI\n");
-
 	if (rte_eal_bus_probe())
 		rte_panic("Cannot probe devices\n");
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index cbd25df..de4ed86 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -35,6 +35,7 @@
 #include <dirent.h>
 
 #include <rte_log.h>
+#include <rte_bus.h>
 #include <rte_pci.h>
 #include <rte_eal_memconfig.h>
 #include <rte_malloc.h>
@@ -267,7 +268,8 @@ pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
 
 /* Scan one pci sysfs entry, and fill the devices list from it. */
 static int
-pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
+pci_scan_one(struct rte_bus *bus, const char *dirname,
+	     const struct rte_pci_addr *addr)
 {
 	char filename[PATH_MAX];
 	unsigned long tmp;
@@ -385,20 +387,24 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 		dev->kdrv = RTE_KDRV_NONE;
 
 	/* device is valid, add in list (sorted) */
-	if (TAILQ_EMPTY(&pci_device_list)) {
+	if (TAILQ_EMPTY(&bus->device_list)) {
 		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+		rte_eal_bus_add_device(bus, &dev->device);
 	} else {
 		struct rte_pci_device *dev2;
+		struct rte_device *r_dev2;
 		int ret;
 
-		TAILQ_FOREACH(dev2, &pci_device_list, next) {
+		TAILQ_FOREACH(r_dev2, &bus->device_list, next) {
+			dev2 = container_of(r_dev2, struct rte_pci_device,
+						device);
 			ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
 			if (ret > 0)
 				continue;
 
 			if (ret < 0) {
-				TAILQ_INSERT_BEFORE(dev2, dev, next);
+				rte_eal_bus_insert_device(bus, &dev2->device,
+							  &dev->device);
 				rte_eal_device_insert(&dev->device);
 			} else { /* already registered */
 				dev2->kdrv = dev->kdrv;
@@ -410,14 +416,14 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
 			return 0;
 		}
 		rte_eal_device_insert(&dev->device);
-		TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+		rte_eal_bus_add_device(bus, &dev->device);
 	}
 
 	return 0;
 }
 
 int
-pci_update_device(const struct rte_pci_addr *addr)
+pci_update_device(struct rte_bus *bus, const struct rte_pci_addr *addr)
 {
 	char filename[PATH_MAX];
 
@@ -425,7 +431,7 @@ pci_update_device(const struct rte_pci_addr *addr)
 		 pci_get_sysfs_path(), addr->domain, addr->bus, addr->devid,
 		 addr->function);
 
-	return pci_scan_one(filename, addr);
+	return pci_scan_one(bus, filename, addr);
 }
 
 /*
@@ -479,13 +485,22 @@ parse_pci_addr_format(const char *buf, int bufsize, struct rte_pci_addr *addr)
  * list
  */
 int
-rte_eal_pci_scan(struct rte_bus *bus_p __rte_unused)
+rte_eal_pci_scan(struct rte_bus *bus_p)
 {
 	struct dirent *e;
 	DIR *dir;
 	char dirname[PATH_MAX];
 	struct rte_pci_addr addr;
 
+	if (!bus_p) {
+		RTE_LOG(ERR, EAL, "PCI Bus is not registered\n");
+		return -1;
+	}
+
+	/* for debug purposes, PCI can be disabled */
+	if (internal_config.no_pci)
+		return 0;
+
 	dir = opendir(pci_get_sysfs_path());
 	if (dir == NULL) {
 		RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
@@ -504,7 +519,7 @@ rte_eal_pci_scan(struct rte_bus *bus_p __rte_unused)
 
 		snprintf(dirname, sizeof(dirname), "%s/%s",
 				pci_get_sysfs_path(), e->d_name);
-		if (pci_scan_one(dirname, &addr) < 0)
+		if (pci_scan_one(bus_p, dirname, &addr) < 0)
 			goto error;
 	}
 	closedir(dir);
@@ -765,3 +780,11 @@ rte_eal_pci_init(void)
 
 	return 0;
 }
+
+struct rte_bus pci_bus = {
+	.scan = rte_eal_pci_scan,
+	.match = rte_eal_pci_match_default,
+	.probe = rte_eal_pci_probe_default,
+};
+
+RTE_REGISTER_BUS(pci, pci_bus);
-- 
2.7.4

  parent reply	other threads:[~2016-12-04 10:09 UTC|newest]

Thread overview: 132+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-04 10:11 [dpdk-dev] [PATCH 00/13] Introducing EAL Bus-Device-Driver Model Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 01/13] eal: define container_of macro Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 02/13] eal/bus: introduce bus abstraction Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 03/13] test: add basic bus infrastructure tests Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 04/13] eal/bus: add scan and match support Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 05/13] eal/bus: add support for inserting a device on a bus Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 06/13] eal: integrate bus scan and probe with EAL Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 07/13] pci: replace probe and remove handlers with rte_driver Shreyansh Jain
2016-12-08 17:50   ` Ferruh Yigit
2016-12-09  4:59     ` Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 08/13] eal: enable probe and remove from bus infrastructure Shreyansh Jain
2016-12-06 10:45   ` Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 09/13] pci: split match and probe function Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 10/13] eal/pci: generalize args of PCI scan/match towards RTE device/driver Shreyansh Jain
2016-12-04 10:11 ` [dpdk-dev] [PATCH 11/13] pci: Pass rte_pci_addr to functions instead of separate args Shreyansh Jain
2016-12-04 10:11 ` Shreyansh Jain [this message]
2016-12-04 10:11 ` [dpdk-dev] [PATCH 13/13] eal/pci: remove PCI probe and init calls Shreyansh Jain
2016-12-06 20:52 ` [dpdk-dev] [PATCH 00/13] Introducing EAL Bus-Device-Driver Model David Marchand
2016-12-07  9:55   ` Shreyansh Jain
2016-12-07 12:17     ` David Marchand
2016-12-07 13:10       ` Shreyansh Jain
2016-12-07 13:24         ` Thomas Monjalon
2016-12-08  5:04           ` Shreyansh Jain
2016-12-08  7:21             ` Thomas Monjalon
2016-12-08  7:53               ` Shreyansh Jain
2016-12-12 14:35         ` Jianbo Liu
2016-12-13  6:56           ` Shreyansh Jain
2016-12-13 13:37 ` [dpdk-dev] [PATCH v2 00/12] " Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 01/12] eal: define container_of macro Shreyansh Jain
2016-12-13 22:24     ` Jan Blunck
2016-12-14  5:12       ` Shreyansh Jain
2016-12-16  8:14         ` Jan Blunck
2016-12-16  9:23           ` Adrien Mazarguil
2016-12-16 10:47             ` Jan Blunck
2016-12-16 11:21               ` Adrien Mazarguil
2016-12-16 11:54                 ` Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 02/12] eal/bus: introduce bus abstraction Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 03/12] test: add basic bus infrastructure tests Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 04/12] eal/bus: add scan, match and insert support Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 05/12] eal: integrate bus scan and probe with EAL Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 06/12] eal: add probe and remove support for rte_driver Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 07/12] eal: enable probe from bus infrastructure Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 08/12] pci: split match and probe function Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 09/12] eal/pci: generalize args of PCI scan/match towards RTE device/driver Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 10/12] pci: Pass rte_pci_addr to functions instead of separate args Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 11/12] eal: enable PCI bus Shreyansh Jain
2016-12-13 13:37   ` [dpdk-dev] [PATCH v2 12/12] drivers: update PMDs to use rte_driver probe and remove Shreyansh Jain
2016-12-13 13:52     ` Andrew Rybchenko
2016-12-13 15:07       ` Ferruh Yigit
2016-12-14  5:14         ` Shreyansh Jain
2016-12-14  5:11       ` Shreyansh Jain
2016-12-14  9:49     ` Shreyansh Jain
2016-12-15 21:36       ` Jan Blunck
2016-12-26  9:14         ` Shreyansh Jain
2016-12-16 13:10   ` [dpdk-dev] [PATCH v3 00/12] Introducing EAL Bus-Device-Driver Model Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 01/12] eal: define container_of macro Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 02/12] eal/bus: introduce bus abstraction Shreyansh Jain
2016-12-20 12:37       ` Hemant Agrawal
2016-12-20 13:17       ` Jan Blunck
2016-12-20 13:51         ` Shreyansh Jain
2016-12-20 17:11         ` Stephen Hemminger
2016-12-21  7:11           ` Shreyansh Jain
2016-12-21 15:38           ` Jan Blunck
2016-12-21 23:33             ` Stephen Hemminger
2016-12-22  5:12               ` Shreyansh Jain
2016-12-22  5:52                 ` Shreyansh Jain
2016-12-25 17:39         ` Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 03/12] test: add basic bus infrastructure tests Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 04/12] eal/bus: add scan, match and insert support Shreyansh Jain
2016-12-16 13:25       ` Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 05/12] eal: integrate bus scan and probe with EAL Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 06/12] eal: add probe and remove support for rte_driver Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 07/12] eal: enable probe from bus infrastructure Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 08/12] pci: split match and probe function Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 09/12] eal/pci: generalize args of PCI scan/match towards RTE device/driver Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 10/12] pci: Pass rte_pci_addr to functions instead of separate args Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 11/12] eal: enable PCI bus and PCI test framework Shreyansh Jain
2016-12-16 13:20       ` Shreyansh Jain
2016-12-16 13:10     ` [dpdk-dev] [PATCH v3 12/12] drivers: update PMDs to use rte_driver probe and remove Shreyansh Jain
2016-12-26 12:50     ` [dpdk-dev] [PATCH v4 00/12] Introducing EAL Bus-Device-Driver Model Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 01/12] eal/bus: introduce bus abstraction Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 02/12] test: add basic bus infrastructure tests Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 03/12] eal/bus: add scan, match and insert support Shreyansh Jain
2016-12-26 13:27         ` Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 04/12] eal: integrate bus scan and probe with EAL Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 05/12] eal: add probe and remove support for rte_driver Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 06/12] eal: enable probe from bus infrastructure Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 07/12] pci: split match and probe function Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 08/12] eal/pci: generalize args of PCI scan/match towards RTE device/driver Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 09/12] pci: Pass rte_pci_addr to functions instead of separate args Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 10/12] eal: enable PCI bus and PCI test framework Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 11/12] drivers: update PMDs to use rte_driver probe and remove Shreyansh Jain
2016-12-26 12:50       ` [dpdk-dev] [PATCH v4 12/12] eal/bus: add bus iteration macros Shreyansh Jain
2016-12-26 13:23       ` [dpdk-dev] [PATCH v5 00/12] Introducing EAL Bus-Device-Driver Model Shreyansh Jain
2016-12-26 13:23         ` [dpdk-dev] [PATCH v5 01/12] eal/bus: introduce bus abstraction Shreyansh Jain
2017-01-03 21:52           ` Thomas Monjalon
2017-01-06 10:31             ` Shreyansh Jain
2017-01-06 14:55               ` Thomas Monjalon
2017-01-09  6:24                 ` Shreyansh Jain
2017-01-09 15:22           ` Ferruh Yigit
2017-01-10  4:07             ` Shreyansh Jain
2016-12-26 13:23         ` [dpdk-dev] [PATCH v5 02/12] test: add basic bus infrastructure tests Shreyansh Jain
2016-12-26 13:23         ` [dpdk-dev] [PATCH v5 03/12] eal/bus: add scan, match and insert support Shreyansh Jain
2016-12-26 13:23         ` [dpdk-dev] [PATCH v5 04/12] eal: integrate bus scan and probe with EAL Shreyansh Jain
2017-01-03 21:46           ` Thomas Monjalon
2017-01-06 10:38             ` Shreyansh Jain
2017-01-06 12:00               ` Shreyansh Jain
2017-01-06 13:46                 ` Thomas Monjalon
2017-01-09  6:35                   ` Shreyansh Jain
2017-01-08 12:21           ` Rosen, Rami
2017-01-09  6:34             ` Shreyansh Jain
2016-12-26 13:23         ` [dpdk-dev] [PATCH v5 05/12] eal: add probe and remove support for rte_driver Shreyansh Jain
2017-01-03 22:05           ` Thomas Monjalon
2017-01-06 11:44             ` Shreyansh Jain
2017-01-06 15:26               ` Thomas Monjalon
2017-01-09  6:28                 ` Shreyansh Jain
2016-12-26 13:23         ` [dpdk-dev] [PATCH v5 06/12] eal: enable probe from bus infrastructure Shreyansh Jain
2016-12-26 13:24         ` [dpdk-dev] [PATCH v5 07/12] pci: split match and probe function Shreyansh Jain
2017-01-03 22:08           ` Thomas Monjalon
2016-12-26 13:24         ` [dpdk-dev] [PATCH v5 08/12] eal/pci: generalize args of PCI scan/match towards RTE device/driver Shreyansh Jain
2017-01-03 22:13           ` Thomas Monjalon
2017-01-06 12:03             ` Shreyansh Jain
2016-12-26 13:24         ` [dpdk-dev] [PATCH v5 09/12] pci: Pass rte_pci_addr to functions instead of separate args Shreyansh Jain
2016-12-26 13:24         ` [dpdk-dev] [PATCH v5 10/12] eal: enable PCI bus and PCI test framework Shreyansh Jain
2016-12-26 13:24         ` [dpdk-dev] [PATCH v5 11/12] drivers: update PMDs to use rte_driver probe and remove Shreyansh Jain
2017-01-09 15:19           ` Ferruh Yigit
2017-01-09 16:18             ` Ferruh Yigit
2017-01-10  4:09               ` Shreyansh Jain
2016-12-26 13:24         ` [dpdk-dev] [PATCH v5 12/12] eal/bus: add bus iteration macros Shreyansh Jain
2017-01-03 22:15           ` Thomas Monjalon
2017-01-03 22:22         ` [dpdk-dev] [PATCH v5 00/12] Introducing EAL Bus-Device-Driver Model Thomas Monjalon
2017-01-06  6:27           ` Shreyansh Jain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1480846288-2517-13-git-send-email-shreyansh.jain@nxp.com \
    --to=shreyansh.jain@nxp.com \
    --cc=david.marchand@6wind.com \
    --cc=dev@dpdk.org \
    --cc=thomas.monjalon@6wind.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).