bus: add probing
authorShreyansh Jain <shreyansh.jain@nxp.com>
Wed, 18 Jan 2017 14:05:22 +0000 (19:35 +0530)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Thu, 19 Jan 2017 03:58:17 +0000 (04:58 +0100)
Bus implementations can implement a probe handler to match the devices
scanned against the drivers registered.

Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
lib/librte_eal/bsdapp/eal/eal.c
lib/librte_eal/bsdapp/eal/rte_eal_version.map
lib/librte_eal/common/eal_common_bus.c
lib/librte_eal/common/include/rte_bus.h
lib/librte_eal/linuxapp/eal/eal.c
lib/librte_eal/linuxapp/eal/rte_eal_version.map

index be5d295..534aeea 100644 (file)
@@ -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");
index 931afeb..2cf1ac8 100644 (file)
@@ -179,6 +179,7 @@ DPDK_17.02 {
        global:
 
        rte_bus_dump;
+       rte_bus_probe;
        rte_bus_register;
        rte_bus_scan;
        rte_bus_unregister;
index ef10390..4638e78 100644 (file)
@@ -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)
index b01930a..7c36969 100644 (file)
@@ -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.
  *
index 1d2a16a..bf6b818 100644 (file)
@@ -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");
index c238381..3c68ff5 100644 (file)
@@ -183,6 +183,7 @@ DPDK_17.02 {
        global:
 
        rte_bus_dump;
+       rte_bus_probe;
        rte_bus_register;
        rte_bus_scan;
        rte_bus_unregister;