From: Shreyansh Jain Date: Wed, 18 Jan 2017 14:05:22 +0000 (+0530) Subject: bus: add probing X-Git-Tag: spdx-start~4686 X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=commitdiff_plain;h=c3cec1d8070860b3f68f3418b876a511fb99e981 bus: add probing Bus implementations can implement a probe handler to match the devices scanned against the drivers registered. Signed-off-by: Shreyansh Jain Reviewed-by: Ferruh Yigit Signed-off-by: Thomas Monjalon --- diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index be5d295581..534aeeab7a 100644 --- a/lib/librte_eal/bsdapp/eal/eal.c +++ b/lib/librte_eal/bsdapp/eal/eal.c @@ -612,6 +612,10 @@ rte_eal_init(int argc, char **argv) rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER); rte_eal_mp_wait_lcore(); + /* Probe all the buses and devices/drivers on them */ + if (rte_bus_probe()) + rte_panic("Cannot probe devices\n"); + /* Probe & Initialize PCI devices */ if (rte_eal_pci_probe()) rte_panic("Cannot probe PCI\n"); diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map index 931afeba09..2cf1ac8f31 100644 --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map @@ -179,6 +179,7 @@ DPDK_17.02 { global: rte_bus_dump; + rte_bus_probe; rte_bus_register; rte_bus_scan; rte_bus_unregister; diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index ef10390807..4638e78d2e 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -49,6 +49,7 @@ rte_bus_register(struct rte_bus *bus) RTE_VERIFY(bus->name && strlen(bus->name)); /* A bus should mandatorily have the scan implemented */ RTE_VERIFY(bus->scan); + RTE_VERIFY(bus->probe); TAILQ_INSERT_TAIL(&rte_bus_list, bus, next); RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", bus->name); @@ -80,6 +81,25 @@ rte_bus_scan(void) return 0; } +/* Probe all devices of all buses */ +int +rte_bus_probe(void) +{ + int ret; + struct rte_bus *bus; + + TAILQ_FOREACH(bus, &rte_bus_list, next) { + ret = bus->probe(); + if (ret) { + RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n", + bus->name); + return ret; + } + } + + return 0; +} + /* Dump information of a single bus */ static int bus_dump_one(FILE *f, struct rte_bus *bus) diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index b01930af5d..7c36969267 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -69,6 +69,18 @@ TAILQ_HEAD(rte_bus_list, rte_bus); */ typedef int (*rte_bus_scan_t)(void); +/** + * Implementation specific probe function which is responsible for linking + * devices on that bus with applicable drivers. + * + * This is called while iterating over each registered bus. + * + * @return + * 0 for successful probe + * !0 for any error while probing + */ +typedef int (*rte_bus_probe_t)(void); + /** * A structure describing a generic bus. */ @@ -76,6 +88,7 @@ struct rte_bus { TAILQ_ENTRY(rte_bus) next; /**< Next bus object in linked list */ const char *name; /**< Name of the bus */ rte_bus_scan_t scan; /**< Scan for devices attached to bus */ + rte_bus_probe_t probe; /**< Probe devices on bus */ }; /** @@ -105,6 +118,16 @@ void rte_bus_unregister(struct rte_bus *bus); */ int rte_bus_scan(void); +/** + * For each device on the buses, perform a driver 'match' and call the + * driver-specific probe for device initialization. + * + * @return + * 0 for successful match/probe + * !0 otherwise + */ +int rte_bus_probe(void); + /** * Dump information of all the buses registered with EAL. * diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c index 1d2a16a39c..bf6b818c83 100644 --- a/lib/librte_eal/linuxapp/eal/eal.c +++ b/lib/librte_eal/linuxapp/eal/eal.c @@ -884,6 +884,10 @@ rte_eal_init(int argc, char **argv) rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER); rte_eal_mp_wait_lcore(); + /* Probe all the buses and devices/drivers on them */ + if (rte_bus_probe()) + rte_panic("Cannot probe devices\n"); + /* Probe & Initialize PCI devices */ if (rte_eal_pci_probe()) rte_panic("Cannot probe PCI\n"); diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map index c238381b64..3c68ff54d3 100644 --- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map +++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map @@ -183,6 +183,7 @@ DPDK_17.02 { global: rte_bus_dump; + rte_bus_probe; rte_bus_register; rte_bus_scan; rte_bus_unregister;