From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shreyansh Jain Subject: [PATCH v5 08/12] eal/pci: generalize args of PCI scan/match towards RTE device/driver Date: Mon, 26 Dec 2016 18:54:01 +0530 Message-ID: <1482758645-23057-9-git-send-email-shreyansh.jain@nxp.com> References: <1482756644-13726-1-git-send-email-shreyansh.jain@nxp.com> <1482758645-23057-1-git-send-email-shreyansh.jain@nxp.com> Mime-Version: 1.0 Content-Type: text/plain Cc: , , Shreyansh Jain To: Return-path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0068.outbound.protection.outlook.com [104.47.32.68]) by dpdk.org (Postfix) with ESMTP id 95DECF91C for ; Mon, 26 Dec 2016 14:21:32 +0100 (CET) In-Reply-To: <1482758645-23057-1-git-send-email-shreyansh.jain@nxp.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- app/test/test_pci.c | 2 +- lib/librte_eal/bsdapp/eal/eal_pci.c | 4 ++-- lib/librte_eal/common/eal_common_pci.c | 28 +++++++++++++++++++++------- lib/librte_eal/common/include/rte_pci.h | 16 +++++++++------- lib/librte_eal/linuxapp/eal/eal_pci.c | 4 ++-- 5 files changed, 35 insertions(+), 19 deletions(-) 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 3a5c315..56b506e 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -352,7 +352,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; @@ -667,7 +667,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 f466448..b7be6aa 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(struct rte_pci_driver *pci_drv, - struct rte_pci_device *pci_dev) +rte_eal_pci_match(struct rte_driver *drv, + struct rte_device *dev) { int match = 1; 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 */ @@ -201,11 +206,15 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev) { int ret; + struct rte_driver *driver; + struct rte_device *device; struct rte_pci_addr *loc; if ((dr == NULL) || (dev == NULL)) return -EINVAL; + driver = &dr->driver; + device = &dev->device; loc = &dev->addr; RTE_LOG(INFO, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n", @@ -222,11 +231,11 @@ 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(dr, dev); + ret = rte_eal_pci_match(driver, device); if (ret) { /* Match of device and driver failed */ RTE_LOG(DEBUG, EAL, "Driver (%s) doesn't match the device\n", - dr->driver.name); + driver->name); return 1; } @@ -263,12 +272,17 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr, struct rte_pci_device *dev) { int ret; + struct rte_driver *driver = NULL; + struct rte_device *device; struct rte_pci_addr *loc; if ((dr == NULL) || (dev == NULL)) return -EINVAL; - ret = rte_eal_pci_match(dr, dev); + driver = &(dr->driver); + device = &(dev->device); + + ret = rte_eal_pci_match(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 34ff3d1..e5e58dd 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -367,25 +367,27 @@ 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(struct rte_pci_driver *pci_drv, - struct rte_pci_device *pci_dev); +rte_eal_pci_match(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 4350134..7e092d2 100644 --- a/lib/librte_eal/linuxapp/eal/eal_pci.c +++ b/lib/librte_eal/linuxapp/eal/eal_pci.c @@ -446,7 +446,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; @@ -724,7 +724,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; } -- 2.7.4