bus/dpaa: delay fman device list to bus probe

The fman device list need to be accessed across processes.
The hw device structures should be allocated with rte_calloc
instead of calloc. The rte_calloc is not available at the
time of bus scan, so better prepare the device list at probe.

Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
This commit is contained in:
Hemant Agrawal 2019-03-26 12:01:46 +00:00 committed by Thomas Monjalon
parent e1797f4b44
commit 4762b3d419
5 changed files with 60 additions and 43 deletions

View File

@ -12,6 +12,7 @@
/* This header declares the driver interface we implement */
#include <fman.h>
#include <of.h>
#include <rte_malloc.h>
#include <rte_dpaa_logs.h>
#include <rte_string_fns.h>
@ -177,7 +178,7 @@ fman_if_init(const struct device_node *dpa_node)
mprop = "fsl,fman-mac";
/* Allocate an object for this network interface */
__if = malloc(sizeof(*__if));
__if = rte_malloc(NULL, sizeof(*__if), RTE_CACHE_LINE_SIZE);
if (!__if) {
FMAN_ERR(-ENOMEM, "malloc(%zu)\n", sizeof(*__if));
goto err;
@ -433,7 +434,7 @@ fman_if_init(const struct device_node *dpa_node)
uint64_t bpool_host[6] = {0};
const char *pname;
/* Allocate an object for the pool */
bpool = malloc(sizeof(*bpool));
bpool = rte_malloc(NULL, sizeof(*bpool), RTE_CACHE_LINE_SIZE);
if (!bpool) {
FMAN_ERR(-ENOMEM, "malloc(%zu)\n", sizeof(*bpool));
goto err;
@ -443,7 +444,7 @@ fman_if_init(const struct device_node *dpa_node)
if (!pool_node) {
FMAN_ERR(-ENXIO, "%s: bad fsl,bman-buffer-pools\n",
dname);
free(bpool);
rte_free(bpool);
goto err;
}
pname = pool_node->full_name;
@ -451,7 +452,7 @@ fman_if_init(const struct device_node *dpa_node)
prop = of_get_property(pool_node, "fsl,bpid", &proplen);
if (!prop) {
FMAN_ERR(-EINVAL, "%s: no fsl,bpid\n", pname);
free(bpool);
rte_free(bpool);
goto err;
}
assert(proplen == sizeof(*prop));
@ -574,7 +575,7 @@ fman_finish(void)
-errno, strerror(errno));
printf("Tearing down %s\n", __if->node_path);
list_del(&__if->__if.node);
free(__if);
rte_free(__if);
}
close(fman_ccsr_map_fd);

View File

@ -114,7 +114,7 @@ netcfg_acquire(void)
size = sizeof(*netcfg) +
(num_ports * sizeof(struct fm_eth_port_cfg));
netcfg = calloc(1, size);
netcfg = rte_calloc(NULL, 1, size, 0);
if (unlikely(netcfg == NULL)) {
DPAA_BUS_LOG(ERR, "Unable to allocat mem for netcfg");
goto error;
@ -141,7 +141,7 @@ netcfg_acquire(void)
error:
if (netcfg) {
free(netcfg);
rte_free(netcfg);
netcfg = NULL;
}
@ -151,7 +151,7 @@ netcfg_acquire(void)
void
netcfg_release(struct netcfg_info *cfg_ptr)
{
free(cfg_ptr);
rte_free(cfg_ptr);
/* Close socket for shared interfaces */
if (skfd >= 0) {
close(skfd);

View File

@ -442,40 +442,8 @@ rte_dpaa_bus_scan(void)
RTE_LOG(DEBUG, EAL, "DPAA Bus not present. Skipping.\n");
return 0;
}
/* Load the device-tree driver */
ret = of_init();
if (ret) {
DPAA_BUS_LOG(ERR, "of_init failed with ret: %d", ret);
return -1;
}
/* Get the interface configurations from device-tree */
dpaa_netcfg = netcfg_acquire();
if (!dpaa_netcfg) {
DPAA_BUS_LOG(ERR, "netcfg_acquire failed");
return -EINVAL;
}
RTE_LOG(NOTICE, EAL, "DPAA Bus Detected\n");
if (!dpaa_netcfg->num_ethports) {
DPAA_BUS_LOG(INFO, "no network interfaces available");
/* This is not an error */
return 0;
}
#ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
dump_netcfg(dpaa_netcfg);
#endif
DPAA_BUS_LOG(DEBUG, "Number of ethernet devices = %d",
dpaa_netcfg->num_ethports);
ret = dpaa_create_device_list();
if (ret) {
DPAA_BUS_LOG(ERR, "Unable to create device list. (%d)", ret);
return ret;
}
/* detected DPAA devices */
rte_dpaa_bus.detected = 1;
/* create the key, supplying a function that'll be invoked
* when a portal affined thread will be deleted.
@ -533,6 +501,47 @@ rte_dpaa_device_match(struct rte_dpaa_driver *drv,
return -1;
}
static int
rte_dpaa_bus_dev_build(void)
{
int ret;
/* Load the device-tree driver */
ret = of_init();
if (ret) {
DPAA_BUS_LOG(ERR, "of_init failed with ret: %d", ret);
return -1;
}
/* Get the interface configurations from device-tree */
dpaa_netcfg = netcfg_acquire();
if (!dpaa_netcfg) {
DPAA_BUS_LOG(ERR, "netcfg_acquire failed");
return -EINVAL;
}
RTE_LOG(NOTICE, EAL, "DPAA Bus Detected\n");
if (!dpaa_netcfg->num_ethports) {
DPAA_BUS_LOG(INFO, "no network interfaces available");
/* This is not an error */
return 0;
}
#ifdef RTE_LIBRTE_DPAA_DEBUG_DRIVER
dump_netcfg(dpaa_netcfg);
#endif
DPAA_BUS_LOG(DEBUG, "Number of ethernet devices = %d",
dpaa_netcfg->num_ethports);
ret = dpaa_create_device_list();
if (ret) {
DPAA_BUS_LOG(ERR, "Unable to create device list. (%d)", ret);
return ret;
}
return 0;
}
static int
rte_dpaa_bus_probe(void)
{
@ -544,6 +553,12 @@ rte_dpaa_bus_probe(void)
int probe_all = rte_dpaa_bus.bus.conf.scan_mode != RTE_BUS_SCAN_WHITELIST;
/* If DPAA bus is not present nothing needs to be done */
if (!rte_dpaa_bus.detected)
return 0;
rte_dpaa_bus_dev_build();
/* If no device present on DPAA bus nothing needs to be done */
if (TAILQ_EMPTY(&rte_dpaa_bus.device_list))
return 0;

View File

@ -54,6 +54,7 @@ struct rte_dpaa_bus {
struct rte_dpaa_device_list device_list;
struct rte_dpaa_driver_list driver_list;
int device_count;
int detected;
};
struct dpaa_device_id {

View File

@ -1354,7 +1354,7 @@ dpaa_dev_init(struct rte_eth_dev *eth_dev)
/* reset bpool list, initialize bpool dynamically */
list_for_each_entry_safe(bp, tmp_bp, &cfg->fman_if->bpool_list, node) {
list_del(&bp->node);
free(bp);
rte_free(bp);
}
/* Populate ethdev structure */