diff mbox

[dpdk-dev,10/13] eal/pci: generalize args of PCI scan/match towards RTE device/driver

Message ID 1480846288-2517-11-git-send-email-shreyansh.jain@nxp.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show

Checks

Context Check Description
checkpatch/checkpatch success coding style OK

Commit Message

Shreyansh Jain Dec. 4, 2016, 10:11 a.m. UTC
PCI scan and match now work on rte_device/rte_driver rather than PCI
specific objects. These functions can now be plugged to the generic
bus callbacks for scanning and matching devices/drivers.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
 app/test/test_pci.c                     |  2 +-
 lib/librte_eal/bsdapp/eal/eal_pci.c     |  4 ++--
 lib/librte_eal/common/eal_common_pci.c  | 17 +++++++++++------
 lib/librte_eal/common/include/rte_pci.h | 17 ++++++++++-------
 lib/librte_eal/linuxapp/eal/eal_pci.c   |  4 ++--
 5 files changed, 26 insertions(+), 18 deletions(-)
diff mbox

Patch

diff --git a/app/test/test_pci.c b/app/test/test_pci.c
index cda186d..f9b84db 100644
--- a/app/test/test_pci.c
+++ b/app/test/test_pci.c
@@ -180,7 +180,7 @@  test_pci_setup(void)
 		TAILQ_INSERT_TAIL(&real_pci_device_list, dev, next);
 	}
 
-	ret = rte_eal_pci_scan();
+	ret = rte_eal_pci_scan(NULL);
 	TEST_ASSERT_SUCCESS(ret, "failed to scan PCI bus");
 	rte_eal_pci_dump(stdout);
 
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8b3ed88..10b234e 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -361,7 +361,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(void)
+rte_eal_pci_scan(struct rte_bus *bus __rte_unused)
 {
 	int fd;
 	unsigned dev_count = 0;
@@ -676,7 +676,7 @@  rte_eal_pci_init(void)
 	if (internal_config.no_pci)
 		return 0;
 
-	if (rte_eal_pci_scan() < 0) {
+	if (rte_eal_pci_scan(NULL) < 0) {
 		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
 		return -1;
 	}
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 793ac59..ba84ccb 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -153,17 +153,22 @@  pci_unmap_resource(void *requested_addr, size_t size)
 }
 
 int
-rte_eal_pci_match_default(struct rte_pci_driver *pci_drv,
-			  struct rte_pci_device *pci_dev)
+rte_eal_pci_match_default(struct rte_driver *drv,
+			  struct rte_device *dev)
 {
 	int match = 0;
 	const struct rte_pci_id *id_table;
+	struct rte_pci_driver *pci_drv;
+	struct rte_pci_device *pci_dev;
 
-	if (!pci_drv || !pci_dev || !pci_drv->id_table) {
-		RTE_LOG(DEBUG, EAL, "Invalid PCI Driver object\n");
+	if (!drv || !dev) {
+		RTE_LOG(DEBUG, EAL, "Invalid Device/Driver\n");
 		return -1;
 	}
 
+	pci_drv = container_of(drv, struct rte_pci_driver, driver);
+	pci_dev = container_of(dev, struct rte_pci_device, device);
+
 	for (id_table = pci_drv->id_table; id_table->vendor_id != 0;
 	     id_table++) {
 		/* check if device's identifiers match the driver's ones */
@@ -226,7 +231,7 @@  rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
 	}
 
 	/* The device is not blacklisted; Check if driver supports it */
-	ret = rte_eal_pci_match_default(dr, dev);
+	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",
@@ -282,7 +287,7 @@  rte_eal_pci_detach_dev(struct rte_pci_driver *dr,
 	driver = &(dr->driver);
 	device = &(dev->device);
 
-	ret = rte_eal_pci_match_default(dr, dev);
+	ret = rte_eal_pci_match_default(driver, device);
 	if (ret) {
 		/* Device and driver don't match */
 		return 1;
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index eb9ef7d..2a5f766 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -363,25 +363,28 @@  rte_eal_compare_pci_addr(const struct rte_pci_addr *addr,
  * Scan the content of the PCI bus, and the devices in the devices
  * list
  *
+ * @param bus
+ *	Reference to the PCI bus
+ *
  * @return
  *  0 on success, negative on error
  */
-int rte_eal_pci_scan(void);
+int rte_eal_pci_scan(struct rte_bus *bus);
 
 /**
  * Match the PCI Driver and Device using the ID Table
  *
- * @param pci_drv
- *	PCI driver from which ID table would be extracted
- * @param pci_dev
- *	PCI device to match against the driver
+ * @param drv
+ *	driver from which ID table would be extracted
+ * @param dev
+ *	device to match against the driver
  * @return
  *	0 for successful match
  *	!0 for unsuccessful match
  */
 int
-rte_eal_pci_match_default(struct rte_pci_driver *pci_drv,
-			  struct rte_pci_device *pci_dev);
+rte_eal_pci_match_default(struct rte_driver *drv,
+			  struct rte_device *dev);
 
 /**
  * Probe the PCI bus for registered drivers.
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 876ba38..bafb7fb 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -485,7 +485,7 @@  parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain,
  * list
  */
 int
-rte_eal_pci_scan(void)
+rte_eal_pci_scan(struct rte_bus *bus_p __rte_unused)
 {
 	struct dirent *e;
 	DIR *dir;
@@ -763,7 +763,7 @@  rte_eal_pci_init(void)
 	if (internal_config.no_pci)
 		return 0;
 
-	if (rte_eal_pci_scan() < 0) {
+	if (rte_eal_pci_scan(NULL) < 0) {
 		RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
 		return -1;
 	}