From: Jun Yang <[email protected]> Add rte_dpaa2_alloc_dpio_device() and rte_dpaa2_free_dpio_device() to grab and release a DPIO software portal that is not tied to a specific CPU affinity. The allocator reserves a free portal from the DPIO list, sets up the DQRI interrupt when the event driver is built in, and the release helper returns the portal via dpaa2_put_qbman_swp().
This lets consumers that manage their own threading (rather than the per-lcore affine portals) obtain a dedicated portal handle. Signed-off-by: Jun Yang <[email protected]> --- drivers/bus/fslmc/portal/dpaa2_hw_dpio.c | 40 ++++++++++++++++++++++++ drivers/bus/fslmc/portal/dpaa2_hw_dpio.h | 8 +++++ 2 files changed, 48 insertions(+) diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c index 8af8600935..63e1660686 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.c @@ -422,6 +422,46 @@ static void dpaa2_portal_finish(void *arg) pthread_setspecific(dpaa2_portal_key, NULL); } +RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa2_alloc_dpio_device) +struct dpaa2_dpio_dev * +rte_dpaa2_alloc_dpio_device(void) +{ + struct dpaa2_dpio_dev *dpio_dev = NULL; + uint16_t expected = 0; + + /* Get DPIO dev handle from list using index */ + TAILQ_FOREACH(dpio_dev, &dpio_dev_list, next) { + if (dpio_dev && + rte_atomic_compare_exchange_strong_explicit(&dpio_dev->ref_count, + &expected, 1, rte_memory_order_acquire, rte_memory_order_relaxed)) + break; + } + if (!dpio_dev) { + DPAA2_BUS_ERR("No software portal resource left"); + return NULL; + } + + DPAA2_BUS_DEBUG("New Portal %p (%d) affined thread - %u", + dpio_dev, dpio_dev->index, rte_gettid()); + +#ifdef RTE_EVENT_DPAA2 + if (dpaa2_dpio_intr_init(dpio_dev, 1, 0, false)) { + DPAA2_BUS_ERR("Interrupt registration failed for dpio"); + rte_atomic_store_explicit(&dpio_dev->ref_count, 0, + rte_memory_order_release); + return NULL; + } +#endif + + return dpio_dev; +} + +RTE_EXPORT_INTERNAL_SYMBOL(rte_dpaa2_free_dpio_device) +void rte_dpaa2_free_dpio_device(struct dpaa2_dpio_dev *dpio_dev) +{ + dpaa2_put_qbman_swp(dpio_dev); +} + static void dpaa2_close_dpio_device(int object_id) { diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.h b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.h index 0838254437..59a9d11955 100644 --- a/drivers/bus/fslmc/portal/dpaa2_hw_dpio.h +++ b/drivers/bus/fslmc/portal/dpaa2_hw_dpio.h @@ -70,4 +70,12 @@ __rte_internal uint32_t dpaa2_free_eq_descriptors(void); +__rte_internal +struct dpaa2_dpio_dev * +rte_dpaa2_alloc_dpio_device(void); + +__rte_internal +void +rte_dpaa2_free_dpio_device(struct dpaa2_dpio_dev *dpio_dev); + #endif /* _DPAA2_HW_DPIO_H_ */ -- 2.43.0

