[v5,3/9] dmadev: add device iterator

Message ID 20210917135429.90562-4-bruce.richardson@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series add test suite for DMA drivers |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Bruce Richardson Sept. 17, 2021, 1:54 p.m. UTC
Add a function and wrapper macro to iterate over all dma devices.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/dmadev/rte_dmadev.c | 13 +++++++++++++
 lib/dmadev/rte_dmadev.h | 18 ++++++++++++++++++
 lib/dmadev/version.map  |  1 +
 3 files changed, 32 insertions(+)

--
2.30.2
  

Comments

fengchengwen Sept. 22, 2021, 8:46 a.m. UTC | #1
On 2021/9/17 21:54, Bruce Richardson wrote:
> Add a function and wrapper macro to iterate over all dma devices.
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  lib/dmadev/rte_dmadev.c | 13 +++++++++++++
>  lib/dmadev/rte_dmadev.h | 18 ++++++++++++++++++
>  lib/dmadev/version.map  |  1 +
>  3 files changed, 32 insertions(+)
> 
> diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
> index ed342e0d32..ba189f3539 100644
> --- a/lib/dmadev/rte_dmadev.c
> +++ b/lib/dmadev/rte_dmadev.c
> @@ -55,6 +55,19 @@ rte_dma_dev_max(size_t dev_max)
>  	return 0;
>  }
> 
> +uint16_t
> +rte_dma_next_dev(uint16_t start_dev_id)
> +{
> +	uint16_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 UINT16_MAX;
> +}

Now dev_id is int16_t, so the input parameter should be int16_t and return -1 when non next. e.g.

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 be4bb18ee6..d262b8ed8d 100644
> --- a/lib/dmadev/rte_dmadev.h
> +++ b/lib/dmadev/rte_dmadev.h
> @@ -219,6 +219,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
> +uint16_t rte_dma_next_dev(uint16_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); \
> +	     (uint16_t)p < UINT16_MAX; \
> +	     p = rte_dma_next_dev(p + 1))

#define RTE_DMA_FOREACH_DEV(p) \
	for (p = rte_dma_next_dev(0); \
	     p != -1; \
	     p = rte_dma_next_dev(p + 1))

> +
> +
>  /** DMA device support memory-to-memory transfer.
>   *
>   * @see struct rte_dma_info::dev_capa
> diff --git a/lib/dmadev/version.map b/lib/dmadev/version.map
> index 66420c4ede..0ab570a1be 100644
> --- a/lib/dmadev/version.map
> +++ b/lib/dmadev/version.map
> @@ -15,6 +15,7 @@ EXPERIMENTAL {
>  	rte_dma_get_dev_id;
>  	rte_dma_info_get;
>  	rte_dma_is_valid;
> +	rte_dma_next_dev;
>  	rte_dma_start;
>  	rte_dma_stats_get;
>  	rte_dma_stats_reset;
> --
> 2.30.2
> 
> .
>
  

Patch

diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
index ed342e0d32..ba189f3539 100644
--- a/lib/dmadev/rte_dmadev.c
+++ b/lib/dmadev/rte_dmadev.c
@@ -55,6 +55,19 @@  rte_dma_dev_max(size_t dev_max)
 	return 0;
 }

+uint16_t
+rte_dma_next_dev(uint16_t start_dev_id)
+{
+	uint16_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 UINT16_MAX;
+}
+
 static int
 dma_check_name(const char *name)
 {
diff --git a/lib/dmadev/rte_dmadev.h b/lib/dmadev/rte_dmadev.h
index be4bb18ee6..d262b8ed8d 100644
--- a/lib/dmadev/rte_dmadev.h
+++ b/lib/dmadev/rte_dmadev.h
@@ -219,6 +219,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
+uint16_t rte_dma_next_dev(uint16_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); \
+	     (uint16_t)p < UINT16_MAX; \
+	     p = rte_dma_next_dev(p + 1))
+
+
 /** DMA device support memory-to-memory transfer.
  *
  * @see struct rte_dma_info::dev_capa
diff --git a/lib/dmadev/version.map b/lib/dmadev/version.map
index 66420c4ede..0ab570a1be 100644
--- a/lib/dmadev/version.map
+++ b/lib/dmadev/version.map
@@ -15,6 +15,7 @@  EXPERIMENTAL {
 	rte_dma_get_dev_id;
 	rte_dma_info_get;
 	rte_dma_is_valid;
+	rte_dma_next_dev;
 	rte_dma_start;
 	rte_dma_stats_get;
 	rte_dma_stats_reset;