From mboxrd@z Thu Jan 1 00:00:00 1970 From: Shreyansh Jain Subject: [PATCH v3 07/12] eal: enable probe from bus infrastructure Date: Fri, 16 Dec 2016 18:40:48 +0530 Message-ID: <1481893853-31790-8-git-send-email-shreyansh.jain@nxp.com> References: <1481636232-2300-1-git-send-email-shreyansh.jain@nxp.com> <1481893853-31790-1-git-send-email-shreyansh.jain@nxp.com> Mime-Version: 1.0 Content-Type: text/plain Cc: , , , Shreyansh Jain To: , Return-path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0065.outbound.protection.outlook.com [104.47.41.65]) by dpdk.org (Postfix) with ESMTP id A3B5258EC for ; Fri, 16 Dec 2016 14:09:13 +0100 (CET) In-Reply-To: <1481893853-31790-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" The model is: rte_eal_init `--> calls rte_eal_bus_probe() This iterates over all the drivers and devices and matches them. For matched bus specific device-driver and calls: `-> rte_driver->probe() for all matched device/drivers (rte_bus->match() successful) This would be responsible for devargs related checks, eventually calling: `-> rte_xxx_driver->probe() which does all the work from eth_dev allocation to init. (Currently, eth_dev init is done by eth_driver->eth_dev_init, which would be removed soon) Signed-off-by: Shreyansh Jain --- lib/librte_eal/common/eal_common_bus.c | 51 +++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index 5fbfdcc..0dfa800 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -196,11 +196,60 @@ rte_eal_bus_scan(void) return 0; } +static int +perform_probe(struct rte_bus *bus __rte_unused, struct rte_driver *driver, + struct rte_device *device) +{ + int ret; + + if (!driver->probe) { + RTE_LOG(ERR, EAL, "Driver (%s) doesn't support probe.\n", + driver->name); + /* This is not an error - just a badly implemented PMD */ + return 0; + } + + ret = driver->probe(driver, device); + if (ret < 0) + /* One of the probes failed */ + RTE_LOG(ERR, EAL, "Probe failed for (%s).\n", driver->name); + + /* In either case, ret <0 (error), ret > 0 (not supported) and ret = 0 + * success, return ret + */ + return ret; +} + /* Match driver<->device and call driver->probe() */ int rte_eal_bus_probe(void) { - /* Until driver->probe is available, this is dummy implementation */ + int ret; + struct rte_bus *bus; + struct rte_device *device; + struct rte_driver *driver; + + /* For each bus registered with EAL */ + TAILQ_FOREACH(bus, &rte_bus_list, next) { + TAILQ_FOREACH(device, &bus->device_list, next) { + TAILQ_FOREACH(driver, &bus->driver_list, next) { + ret = bus->match(driver, device); + if (!ret) { + ret = perform_probe(bus, driver, + device); + if (ret < 0) + return ret; + + device->driver = driver; + /* ret == 0 is success; ret >0 implies + * driver doesn't support the device. + * in either case, continue + */ + } + } + } + } + return 0; } -- 2.7.4