Move bus-specific initialization code from probe() to scan() operations for DPAA and FSLMC buses. This separates device discovery and bus setup (scan) from driver matching and probing (probe), preparing for a future generic probe() implementation in EAL.
Both buses now have a clean separation: - scan(): discover devices + initialize bus - probe(): match drivers + call probe_device() Signed-off-by: David Marchand <[email protected]> --- drivers/bus/dpaa/dpaa_bus.c | 76 +++++++++++++++--------------- drivers/bus/fslmc/fslmc_bus.c | 88 +++++++++++++++++------------------ 2 files changed, 80 insertions(+), 84 deletions(-) diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c index b0ed61ba39..43d71cefa4 100644 --- a/drivers/bus/dpaa/dpaa_bus.c +++ b/drivers/bus/dpaa/dpaa_bus.c @@ -569,40 +569,6 @@ dpaa_bus_dev_compare(const char *name1, const char *name2) return strncmp(devname1, devname2, sizeof(devname1)); } -#define DPAA_DEV_PATH1 "/sys/devices/platform/soc/soc:fsl,dpaa" -#define DPAA_DEV_PATH2 "/sys/devices/platform/fsl,dpaa" - -static int -rte_dpaa_bus_scan(void) -{ - int ret; - - BUS_INIT_FUNC_TRACE(); - - if ((access(DPAA_DEV_PATH1, F_OK) != 0) && - (access(DPAA_DEV_PATH2, F_OK) != 0)) { - DPAA_BUS_LOG(DEBUG, "DPAA Bus not present. Skipping."); - return 0; - } - - if (rte_dpaa_bus.detected) - return 0; - - rte_dpaa_bus.detected = 1; - - /* create the key, supplying a function that'll be invoked - * when a portal affined thread will be deleted. - */ - ret = pthread_key_create(&dpaa_portal_key, dpaa_portal_finish); - if (ret) { - DPAA_BUS_LOG(DEBUG, "Unable to create pthread key. (%d)", ret); - dpaa_clean_device_list(); - return ret; - } - - return 0; -} - /* register a dpaa bus based dpaa driver */ RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa_driver_register) void @@ -701,20 +667,43 @@ static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle) return 0; } +#define DPAA_DEV_PATH1 "/sys/devices/platform/soc/soc:fsl,dpaa" +#define DPAA_DEV_PATH2 "/sys/devices/platform/fsl,dpaa" + static int -rte_dpaa_bus_probe(void) +rte_dpaa_bus_scan(void) { - int ret = -1; struct rte_dpaa_device *dev; FILE *svr_file = NULL; uint32_t svr_ver; static int process_once; char *penv; + int ret; + + BUS_INIT_FUNC_TRACE(); + + if ((access(DPAA_DEV_PATH1, F_OK) != 0) && + (access(DPAA_DEV_PATH2, F_OK) != 0)) { + DPAA_BUS_LOG(DEBUG, "DPAA Bus not present. Skipping."); + return 0; + } - /* If DPAA bus is not present nothing needs to be done */ - if (!rte_dpaa_bus.detected) + if (rte_dpaa_bus.detected) return 0; + rte_dpaa_bus.detected = 1; + + /* create the key, supplying a function that'll be invoked + * when a portal affined thread will be deleted. + */ + ret = pthread_key_create(&dpaa_portal_key, dpaa_portal_finish); + if (ret) { + DPAA_BUS_LOG(DEBUG, "Unable to create pthread key. (%d)", ret); + dpaa_clean_device_list(); + return ret; + } + + /* SoC version detection and configuration */ svr_file = fopen(DPAA_SOC_ID_FILE, "r"); if (svr_file) { if (fscanf(svr_file, "svr:%x", &svr_ver) > 0) @@ -786,9 +775,19 @@ rte_dpaa_bus_probe(void) /* And initialize the PA->VA translation table */ dpaax_iova_table_populate(); + dpaa_bus_global_init = 1; + return 0; +} + +static int +rte_dpaa_bus_probe(void) +{ + struct rte_dpaa_device *dev; + /* For each registered driver, and device, call the driver->probe */ RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus.bus) { struct rte_driver *driver = NULL; + int ret; next_driver: driver = rte_bus_find_driver(&rte_dpaa_bus.bus, driver, &dev->device); @@ -801,7 +800,6 @@ rte_dpaa_bus_probe(void) else if (ret > 0) goto next_driver; } - dpaa_bus_global_init = 1; return 0; } diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c index e6db8f5100..156f4e295f 100644 --- a/drivers/bus/fslmc/fslmc_bus.c +++ b/drivers/bus/fslmc/fslmc_bus.c @@ -322,7 +322,6 @@ rte_fslmc_scan(void) } return 0; } - process_once = 1; /* Now we only support single group per process.*/ group_name = getenv("DPRC"); @@ -368,6 +367,48 @@ rte_fslmc_scan(void) /* If debugging is enabled, device list is dumped to log output */ dump_device_list(); + /* Bus initialization - only if devices were found */ + if (!TAILQ_EMPTY(&rte_fslmc_bus.bus.device_list)) { + static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = { + .name = DPAA2_SEQN_DYNFIELD_NAME, + .size = sizeof(dpaa2_seqn_t), + .align = alignof(dpaa2_seqn_t), + }; + + dpaa2_seqn_dynfield_offset = + rte_mbuf_dynfield_register(&dpaa2_seqn_dynfield_desc); + if (dpaa2_seqn_dynfield_offset < 0) { + DPAA2_BUS_ERR("Failed to register mbuf field for dpaa sequence number"); + return 0; + } + + ret = fslmc_vfio_setup_group(); + if (ret) { + DPAA2_BUS_ERR("Unable to setup VFIO %d", ret); + return 0; + } + + /* Map existing segments as well as, in case of hotpluggable memory, + * install callback handler. + */ + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + ret = fslmc_vfio_dmamap(); + if (ret) { + DPAA2_BUS_ERR("Unable to DMA map existing VAs: (%d)", ret); + DPAA2_BUS_ERR("FSLMC VFIO Mapping failed"); + return 0; + } + } + + ret = fslmc_vfio_process_group(); + if (ret) { + DPAA2_BUS_ERR("Unable to setup devices %d", ret); + return 0; + } + } + + process_once = 1; + return 0; scan_fail_cleanup: @@ -408,51 +449,8 @@ rte_fslmc_close(void) static int rte_fslmc_probe(void) { - int ret = 0; - struct rte_dpaa2_device *dev; - - static const struct rte_mbuf_dynfield dpaa2_seqn_dynfield_desc = { - .name = DPAA2_SEQN_DYNFIELD_NAME, - .size = sizeof(dpaa2_seqn_t), - .align = alignof(dpaa2_seqn_t), - }; - - if (TAILQ_EMPTY(&rte_fslmc_bus.bus.device_list)) - return 0; - - dpaa2_seqn_dynfield_offset = - rte_mbuf_dynfield_register(&dpaa2_seqn_dynfield_desc); - if (dpaa2_seqn_dynfield_offset < 0) { - DPAA2_BUS_ERR("Failed to register mbuf field for dpaa sequence number"); - return 0; - } - - ret = fslmc_vfio_setup_group(); - if (ret) { - DPAA2_BUS_ERR("Unable to setup VFIO %d", ret); - return 0; - } - - /* Map existing segments as well as, in case of hotpluggable memory, - * install callback handler. - */ - if (rte_eal_process_type() == RTE_PROC_PRIMARY) { - ret = fslmc_vfio_dmamap(); - if (ret) { - DPAA2_BUS_ERR("Unable to DMA map existing VAs: (%d)", - ret); - /* Not continuing ahead */ - DPAA2_BUS_ERR("FSLMC VFIO Mapping failed"); - return 0; - } - } - - ret = fslmc_vfio_process_group(); - if (ret) { - DPAA2_BUS_ERR("Unable to setup devices %d", ret); - return 0; - } + int ret; RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) { struct rte_driver *driver = NULL; -- 2.53.0

