Function to allocate and free a Nic device are added here. The DPDK PMD drivers make use of a shared mem area (dev->data), which is kept here, but some question remains to be answered about its usage (dpdk hash of inspiration: 9702b2b53f250aa50973e6d86abce45b4a919eda)
Signed-off-by: Christophe Milard <christophe.mil...@linaro.org> --- platform/linux-generic/include/odp/nic.h | 1 + platform/linux-generic/odp_nic.c | 72 ++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/platform/linux-generic/include/odp/nic.h b/platform/linux-generic/include/odp/nic.h index 7688bee..3b2c950 100644 --- a/platform/linux-generic/include/odp/nic.h +++ b/platform/linux-generic/include/odp/nic.h @@ -22,6 +22,7 @@ extern "C" { #include <odp/shared_memory.h> #include <odp/plat/nic_types.h> #include <odp/pci.h> +#include <odp/shared_memory.h> /** @ingroup odp_nic * @{ diff --git a/platform/linux-generic/odp_nic.c b/platform/linux-generic/odp_nic.c index 8a4cd43..5faf642 100644 --- a/platform/linux-generic/odp_nic.c +++ b/platform/linux-generic/odp_nic.c @@ -210,3 +210,75 @@ void odp_nic_driver_register(odp_nic_driver_t *drv) else ODP_ERR("Maximum number of drivers exceeded... "); } + +odp_nic_dev_t *odp_nic_dev_alloc(const char *unique_id, int private_sz, + int nb_rxqueues, int nb_txqueues, + odp_pktio_t pktio) +{ + odp_shm_t shm; + odp_nic_dev_t *dev; + + char name[ODP_SHM_NAME_LEN]; + + dev = malloc(sizeof(odp_nic_dev_t)); + + /* allocate memory for data (global to the NIC): */ + /* FIXME: this is a shared mem data struct in DPDK: don't + * fully understand why at this stage as it contains pointers + * ...needs review... */ + snprintf(name, sizeof(name), "ETH_dev_data:%s", unique_id); + shm = odp_shm_lookup(name); + if (shm == ODP_SHM_INVALID) { + shm = odp_shm_reserve(name, + sizeof(odp_nic_dev_data_t), + ODP_CACHE_LINE_SIZE, 0); + } + dev->data = odp_shm_addr(shm); + if (!dev->data) + goto out1; + + dev->data_shm = shm; + + /* 1 port per ethernet device, matching the pktio entry index: */ + dev->data->port_id = _odp_typeval(pktio); + + /* allocate memory for driver private data: */ + dev->data->dev_private = malloc(private_sz); + if (!dev->data->dev_private) + goto out2; + + /* allocate memory for the rx queues: */ + dev->data->rx_queues = malloc(sizeof(dev->data->rx_queues[0]) * + nb_rxqueues); + if (!dev->data->rx_queues) + goto out3; + + /* allocate memory for the tx queues: */ + dev->data->tx_queues = malloc(sizeof(dev->data->tx_queues[0]) + * nb_txqueues); + if (!dev->data->tx_queues) + goto out4; + + dev->data->nb_rx_queues = nb_rxqueues; + dev->data->nb_tx_queues = nb_txqueues; + + return dev; + +out4: + free(dev->data->rx_queues); +out3: + free(dev->data->dev_private); +out2: + if (odp_shm_free(shm) < 0) + ODP_ERR("Shm free failed for ETH_dev_data"); +out1: return NULL; +} + +void odp_nic_dev_free(odp_nic_dev_t *nic_dev) +{ + free(nic_dev->data->tx_queues); + free(nic_dev->data->rx_queues); + free(nic_dev->data->dev_private); + odp_shm_free(nic_dev->data_shm); + free(nic_dev); +} -- 2.1.4 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp