From: Bruce Richardson Date: Wed, 13 Oct 2021 15:17:28 +0000 (+0100) Subject: dmadev: add device iterator X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=190f7e84c338beb5cbf086123103cc7e49b05d67;p=dpdk.git dmadev: add device iterator Add a function and wrapper macro to iterate over all DMA devices. Signed-off-by: Bruce Richardson Reviewed-by: Conor Walsh Reviewed-by: Kevin Laatz --- diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c index c737cc6cdc..b6647e6ff8 100644 --- a/lib/dmadev/rte_dmadev.c +++ b/lib/dmadev/rte_dmadev.c @@ -49,6 +49,19 @@ rte_dma_dev_max(size_t dev_max) return 0; } +int16_t +rte_dma_next_dev(int16_t start_dev_id) +{ + int16_t dev_id = start_dev_id; + while (dev_id < dma_devices_max && rte_dma_devices[dev_id].state == RTE_DMA_DEV_UNUSED) + dev_id++; + + if (dev_id < dma_devices_max) + return dev_id; + + return -1; +} + static int dma_check_name(const char *name) { diff --git a/lib/dmadev/rte_dmadev.h b/lib/dmadev/rte_dmadev.h index a0824be20d..bf78748b0c 100644 --- a/lib/dmadev/rte_dmadev.h +++ b/lib/dmadev/rte_dmadev.h @@ -220,6 +220,24 @@ bool rte_dma_is_valid(int16_t dev_id); __rte_experimental uint16_t rte_dma_count_avail(void); +/** + * Iterates over valid dmadev instances. + * + * @param start_dev_id + * The id of the next possible dmadev. + * @return + * Next valid dmadev, UINT16_MAX if there is none. + */ +__rte_experimental +int16_t rte_dma_next_dev(int16_t start_dev_id); + +/** Utility macro to iterate over all available dmadevs */ +#define RTE_DMA_FOREACH_DEV(p) \ + for (p = rte_dma_next_dev(0); \ + p != -1; \ + p = rte_dma_next_dev(p + 1)) + + /**@{@name DMA capability * @see struct rte_dma_info::dev_capa */ diff --git a/lib/dmadev/version.map b/lib/dmadev/version.map index 4bbfdd52f6..ef561acd46 100644 --- a/lib/dmadev/version.map +++ b/lib/dmadev/version.map @@ -15,6 +15,7 @@ EXPERIMENTAL { rte_dma_get_dev_id_by_name; rte_dma_info_get; rte_dma_is_valid; + rte_dma_next_dev; rte_dma_start; rte_dma_stats_get; rte_dma_stats_reset;