Hi Gowrishankar,

This could create a help function in test, just like:

func() {
    RTE_DMA_FOREACH_DEV(i) {
        rte_dma_info_get(i, &dev_info);
        if (strncmp(dev_info->dev_name, xxx)
            ...
    }
}


If some application (not test) should pick some specific device, I suggest
add more general API, e.g.

typedef int (*rte_dma_filter_fn)(struct rte_dma_info *dev_info, void *param);
uint16_t
rte_dma_get_devs_by_filter(rte_dma_filter_fn fn, void *param, uint16_t 
*dev_ids, uint16_t nb_ids) {
    RTE_DMA_FOREACH_DEV(i) {
        rte_dma_info_get(i, &dev_info);
        if (fn(&dev_info, param) == 0) {
            // add to out list
        }
    }
}

So we could filter special name-prefix/capability/multi-vchans

Thanks.

On 2023/8/10 20:21, Gowrishankar Muthukrishnan wrote:
> Add a function to get list of device identifiers for a given driver
> name.
> 
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukri...@marvell.com>
> ---
>  lib/dmadev/rte_dmadev.c | 20 ++++++++++++++++++++
>  lib/dmadev/rte_dmadev.h | 21 +++++++++++++++++++++
>  lib/dmadev/version.map  |  1 +
>  3 files changed, 42 insertions(+)
> 
> diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c
> index 8c095e1f35..f2a106564d 100644
> --- a/lib/dmadev/rte_dmadev.c
> +++ b/lib/dmadev/rte_dmadev.c
> @@ -388,6 +388,26 @@ rte_dma_get_dev_id_by_name(const char *name)
>       return dev->data->dev_id;
>  }
>  
> +uint8_t
> +rte_dma_get_dev_list_by_driver(const char *name, int16_t *devs, uint8_t 
> nb_devs)
> +{
> +     uint8_t i, count = 0;
> +
> +     if (name == NULL)
> +             return count;
> +
> +     for (i = 0; i < dma_devices_max && count < nb_devs; i++) {
> +             if (rte_dma_devices[i].state == RTE_DMA_DEV_UNUSED)
> +                     continue;
> +
> +             if (strncmp(rte_dma_devices[i].device->driver->name,
> +                                     name, strlen(name) + 1) == 0)
> +                     devs[count++] = i;
> +     }
> +
> +     return count;
> +}
> +
>  bool
>  rte_dma_is_valid(int16_t dev_id)
>  {
> diff --git a/lib/dmadev/rte_dmadev.h b/lib/dmadev/rte_dmadev.h
> index e61d71959e..689062a686 100644
> --- a/lib/dmadev/rte_dmadev.h
> +++ b/lib/dmadev/rte_dmadev.h
> @@ -191,6 +191,27 @@ int rte_dma_dev_max(size_t dev_max);
>  __rte_experimental
>  int rte_dma_get_dev_id_by_name(const char *name);
>  
> +/**
> + * @warning
> + * @b EXPERIMENTAL: this API may change without prior notice.
> + *
> + * Get the list of device identifiers for the DMA driver.
> + *
> + * @param name
> + *   DMA driver name.
> + * @param devs
> + *   Output devices identifiers.
> + * @param nb_devs
> + *   Maximal number of devices.
> + *
> + * @return
> + *   Returns number of device identifiers.
> + */
> +__rte_experimental
> +uint8_t rte_dma_get_dev_list_by_driver(const char *name,
> +                                    int16_t *devs,
> +                                    uint8_t nb_devs);
> +
>  /**
>   * @warning
>   * @b EXPERIMENTAL: this API may change without prior notice.
> diff --git a/lib/dmadev/version.map b/lib/dmadev/version.map
> index 7031d6b335..b4d56b41a0 100644
> --- a/lib/dmadev/version.map
> +++ b/lib/dmadev/version.map
> @@ -7,6 +7,7 @@ EXPERIMENTAL {
>       rte_dma_dev_max;
>       rte_dma_dump;
>       rte_dma_get_dev_id_by_name;
> +     rte_dma_get_dev_list_by_driver;
>       rte_dma_info_get;
>       rte_dma_is_valid;
>       rte_dma_next_dev;
> 

Reply via email to