All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Bernatowicz, Marcin" <marcin.bernatowicz@linux.intel.com>
To: Lukasz Laguna <lukasz.laguna@intel.com>, igt-dev@lists.freedesktop.org
Cc: marcin.bernatowicz@intel.com, piotr.piorkowski@intel.com
Subject: Re: [PATCH v2 1/3] lib/igt_sriov_device: Add helper to get SR-IOV function name
Date: Tue, 8 Sep 2026 15:16:51 +0200	[thread overview]
Message-ID: <6e21f3b3-894e-4b26-9cde-963418766dc1@linux.intel.com> (raw)
In-Reply-To: <20260907124658.613244-2-lukasz.laguna@intel.com>


On 9/7/2026 2:46 PM, Lukasz Laguna wrote:
> Introduce a helper to format SR-IOV function names. It returns "PF" for
> physical function and "VF%u" for virtual functions.
>
> Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
> ---
>   lib/igt_sriov_device.c | 23 +++++++++++++++++++++++
>   lib/igt_sriov_device.h |  1 +
>   2 files changed, 24 insertions(+)
>
> diff --git a/lib/igt_sriov_device.c b/lib/igt_sriov_device.c
> index 6c9fbdf70..392c80346 100644
> --- a/lib/igt_sriov_device.c
> +++ b/lib/igt_sriov_device.c
> @@ -61,6 +61,29 @@ const char *igt_sriov_func_str(unsigned int vf_num)
>   	return buf;
>   }
>   
> +/**
> + * igt_sriov_function_name - Get SR-IOV function name
> + * @vf_num: VF number (1-based to identify single VF) or 0 for PF
> + * @buf: buffer
> + * @size: size of the buffer
> + *
> + * It formats the function name as "PF" when @vf_num is 0, or as "VF%u"
> + * when @vf_num is greater than 0.
> + *
> + * Return: formatted function name.
> + */
> +const char *igt_sriov_function_name(unsigned int vf_num, char *buf, size_t size)
> +{
> +	int n;
> +
> +	n = vf_num ? snprintf(buf, size, "VF%u", vf_num) :
> +		     snprintf(buf, size, "PF");
> +
> +	igt_assert(n >= 0 && (size_t)n < size);
> +
> +	return buf;
> +}
> +

NIT: We already have igt_sriov_func_str(), although it relies on a 
thread-local buffer.

Would it make sense to factor the formatting into a helper,

with lower- and uppercase wrappers, for example:

static const char *sriov_function_name(unsigned int vf_num, bool uppercase,
                        char *buf, size_t size)
{
     int ret;

     igt_assert(buf && size);

     if (vf_num)
         ret = snprintf(buf, size, uppercase ? "VF%u" : "vf%u", vf_num);
     else
         ret = snprintf(buf, size, "%s", uppercase ? "PF" : "pf");

     igt_assert(ret >= 0 && (size_t)ret < size);

     return buf;
}

const char *igt_sriov_function_name_lower(unsigned int vf_num,
                       char *buf, size_t size)
{
     return sriov_function_name(vf_num, false, buf, size);
}

const char *igt_sriov_function_name_upper(unsigned int vf_num,
                       char *buf, size_t size)
{
     return sriov_function_name(vf_num, true, buf, size);
}

igt_sriov_func_str() could initially remain as a compatibility wrapper

around the lowercase helper, with migrating its callers left for a 
follow-up.

--

marcin

>   static bool __pf_attr_get_u32(int pf, const char *attr, uint32_t *value)
>   {
>   	int sysfs;
> diff --git a/lib/igt_sriov_device.h b/lib/igt_sriov_device.h
> index 4e4ba230a..a969d4172 100644
> --- a/lib/igt_sriov_device.h
> +++ b/lib/igt_sriov_device.h
> @@ -36,6 +36,7 @@ bool igt_sriov_device_reset_exists(int pf, unsigned int vf_num);
>   bool igt_sriov_device_reset(int pf, unsigned int vf_num);
>   bool intel_is_vf_device(int device);
>   const char *igt_sriov_func_str(unsigned int vf_num);
> +const char *igt_sriov_function_name(unsigned int vf_num, char *buf, size_t size);
>   typedef void (*igt_sriov_exit_cleanup_fn)(int pf, int sig, void *user_data);
>   void igt_sriov_install_exit_handler(int pf,
>   				    igt_sriov_exit_cleanup_fn cleanup_fn,

  reply	other threads:[~2026-09-08 13:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07 12:46 [PATCH v2 0/3] tests/intel/xe_sriov_mmio_regs: Add tests to verify registers on VFs Lukasz Laguna
2026-09-07 12:46 ` [PATCH v2 1/3] lib/igt_sriov_device: Add helper to get SR-IOV function name Lukasz Laguna
2026-09-08 13:16   ` Bernatowicz, Marcin [this message]
2026-09-07 12:46 ` [PATCH v2 2/3] tests/intel/xe_sriov_mmio_regs: Add tests to verify registers on VFs Lukasz Laguna
2026-09-10 10:26   ` Bernatowicz, Marcin
2026-09-07 12:46 ` [PATCH v2 3/3] intel-ci: Block igt@xe_sriov_mmio_regs.* Lukasz Laguna
2026-09-10 10:27   ` Bernatowicz, Marcin
2026-09-07 17:15 ` ✓ Xe.CI.BAT: success for tests/intel/xe_sriov_mmio_regs: Add tests to verify registers on VFs (rev2) Patchwork
2026-09-07 17:51 ` ✓ i915.CI.BAT: " Patchwork
2026-09-07 21:01 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-09-08  0:07 ` ✗ i915.CI.Full: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e21f3b3-894e-4b26-9cde-963418766dc1@linux.intel.com \
    --to=marcin.bernatowicz@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=lukasz.laguna@intel.com \
    --cc=marcin.bernatowicz@intel.com \
    --cc=piotr.piorkowski@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.