[PATCH i-g-t v2 3/4] lib/igt_sriov_device: Add helper to iterate over VFs in specified range

Bernatowicz, Marcin marcin.bernatowicz at linux.intel.com
Tue Feb 11 11:23:04 UTC 2025



On 2/7/2025 10:40 AM, Lukasz Laguna wrote:
> Helper allows to iterate over VFs within the specified range.
> 
> Signed-off-by: Lukasz Laguna <lukasz.laguna at intel.com>
> ---
>   lib/igt_sriov_device.h | 18 ++++++++++++++++++
>   1 file changed, 18 insertions(+)
> 
> diff --git a/lib/igt_sriov_device.h b/lib/igt_sriov_device.h
> index de25a7d98..c12a8cf6c 100644
> --- a/lib/igt_sriov_device.h
> +++ b/lib/igt_sriov_device.h
> @@ -86,6 +86,24 @@ igt_sriov_random_vf_in_range(int pf_fd, unsigned int start, unsigned int end)
>   	     ++__vf_num)
>   #define for_each_sriov_num_vfs for_each_sriov_vf
>   
> +/**
> + * for_each_sriov_vf_in_range - Iterate over VFs in a specified range
> + * @__pf_fd: PF device file descriptor
> + * @__start: Starting VF number in the range
> + * @__end: Ending VF number in the range
> + * @__vf_num: Variable to store the random VF number
> + *
> + * For loop that iterates over VFs associated with given PF @__pf_fd,
> + * within the specified range [__start, __end]. The loop runs only if
> + * the range is valid.
> + */
> +#define for_each_sriov_vf_in_range(__pf_fd, __start, __end, __vf_num) \
> +	for (unsigned int __vf_num = __start & \
> +		__is_valid_range(__start, __end, igt_sriov_get_total_vfs(__pf_fd)); \
> +	     __vf_num && __vf_num <= __end; \
> +	     ++__vf_num)
> +#define for_each_sriov_num_vfs_in_range for_each_sriov_vf_in_range
> +

Something is wrong, is the bitwise operator expected ?
Is this going to work:
  for_each_sriov_vf_in_range(pf_fd, 2, 7, vf) ?

Maybe

#define for_each_sriov_vf_in_range(__pf_fd, __start, __end, __vf_num) \
     for (unsigned int __vf_num = ((__is_valid_range((__start), (__end),
                                    igt_sriov_get_total_vfs(__pf_fd))) ?
                                      (__start) : 0); \
          __vf_num && __vf_num <= (__end); ++__vf_num)

--
marcin

>   /**
>    * for_random_sriov_vf_in_range - Iterate over a random VF in a specified range
>    * @__pf_fd: PF device file descriptor



More information about the igt-dev mailing list