Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: Lukasz Laguna <lukasz.laguna@intel.com>, igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 1/8] lib/igt_sriov_device: add core SR-IOV helpers
Date: Mon, 6 Nov 2023 23:07:06 +0100	[thread overview]
Message-ID: <5304b828-d2f1-4bda-a4b1-3be8129f4ce1@intel.com> (raw)
In-Reply-To: <20231106195947.14640-2-lukasz.laguna@intel.com>



On 06.11.2023 20:59, Lukasz Laguna wrote:
> From: Katarzyna Dec <katarzyna.dec@intel.com>
> 
> Create lib for core SR-IOV helpers that allow to manage SR-IOV devices.
> 
> Signed-off-by: Katarzyna Dec <katarzyna.dec@intel.com>
> Reviewed-by: Lukasz Laguna <lukasz.laguna@intel.com>
> Signed-off-by: Lukasz Laguna <lukasz.laguna@intel.com>
> Reviewed-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
> ---
>  lib/igt_sriov_device.c | 174 +++++++++++++++++++++++++++++++++++++++++
>  lib/igt_sriov_device.h |  20 +++++
>  lib/meson.build        |   1 +
>  3 files changed, 195 insertions(+)
>  create mode 100644 lib/igt_sriov_device.c
>  create mode 100644 lib/igt_sriov_device.h
> 
> diff --git a/lib/igt_sriov_device.c b/lib/igt_sriov_device.c
> new file mode 100644
> index 000000000..7d53c2045
> --- /dev/null
> +++ b/lib/igt_sriov_device.c
> @@ -0,0 +1,174 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright(c) 2023 Intel Corporation. All rights reserved.
> + */
> +
> +#include "igt_core.h"
> +#include "igt_sriov_device.h"
> +#include "igt_sysfs.h"
> +
> +/**
> + * igt_sriov_is_pf:

nit: short function description missing, not required anymore?

> + * @device: device file descriptor
> + *
> + * Check if device is PF by checking existence of sriov_totalvfs file
> + * and non-zero value read from that file.

just to clarify/be precise, do you want to check here "device"
capability or "driver" capability ?

IIRC the PCI subsystem will set these attributes on the "PF device" even
if attached "PF driver" does not provide required hook to enable VFs
(and this is main purpose of being a "PF", no?)

> + *
> + * Returns:
> + * True if device is PF, false otherwise.
> + */
> +bool igt_sriov_is_pf(int device)
> +{
> +	int sysfs;
> +	bool ret;
> +	uint32_t totalvfs;

nit: we shouldn't specify width if not needed, maybe plain unsigned int
will just work ? shame that there are no __igt_sysfs_get_uint()

> +
> +	sysfs = igt_sysfs_open(device);
> +	igt_assert_fd(sysfs);
> +
> +	ret = __igt_sysfs_get_u32(sysfs, "device/sriov_totalvfs", &totalvfs);
> +	close(sysfs);
> +
> +	if (!ret)
> +		return false;
> +
> +	return totalvfs > 0;
> +}
> +
> +static uint32_t __pf_attr_get_u32(int pf, const char *attr)
> +{
> +	int sysfs;
> +	uint32_t value;
> +
> +	igt_assert(igt_sriov_is_pf(pf));
> +
> +	sysfs = igt_sysfs_open(pf);
> +	igt_assert_fd(sysfs);
> +
> +	value = igt_sysfs_get_u32(sysfs, attr);
> +	close(sysfs);
> +
> +	return value;
> +}
> +
> +static bool __pf_attr_set_u32(int pf, const char *attr, uint32_t value)
> +{
> +	int sysfs;
> +	bool ret;
> +
> +	igt_assert(igt_sriov_is_pf(pf));
> +
> +	sysfs = igt_sysfs_open(pf);
> +	igt_assert_fd(sysfs);
> +
> +	ret = __igt_sysfs_set_u32(sysfs, attr, value);
> +	close(sysfs);
> +
> +	return ret;
> +}
> +
> +/**
> + * igt_sriov_get_totalvfs:
> + * @pf: PF device file descriptor
> + *
> + * Get maximum number of VFs that can be enabled.
> + *
> + * Returns:
> + * Maximum number of VFs that could be associated with given PF.
> + */
> +unsigned int igt_sriov_get_total_vfs(int pf)
> +{
> +	return __pf_attr_get_u32(pf, "device/sriov_totalvfs");
> +}
> +
> +/**
> + * igt_sriov_get_numvfs:
> + * @pf: PF device file descriptor
> + *
> + * Get number of enabled VFs.
> + *
> + * Returns:
> + * Number of VFs enabled by given PF.
> + */
> +unsigned int igt_sriov_get_enabled_vfs(int pf)
> +{
> +	return __pf_attr_get_u32(pf, "device/sriov_numvfs");
> +}
> +
> +/**
> + * igt_sriov_enable_vfs:

Helper for VFs enabling

> + * @pf: PF device file descriptor
> + * @num_vfs: Number of virtual functions to be enabled
> + *
> + * Helper for VFs enabling.

"This will try to enable VFs by writing @num_vfs to ...

> + *
> + * Returns:
> + * True on success and false on failure.
> + */
> +bool igt_sriov_enable_vfs(int pf, unsigned int num_vfs)
> +{
> +	igt_assert(num_vfs > 0);
> +	igt_debug("Enabling %u VFs\n", num_vfs);
> +	return __pf_attr_set_u32(pf, "device/sriov_numvfs", num_vfs);
> +}
> +
> +/**
> + * igt_sriov_disable_vfs:

Helper for VFs disabling

> + * @pf: PF device file descriptor
> + *
> + * Set 0 in sriov_numvfs file to disable VFs.

"This will try to disable already enabled VFs by writing 0 to ...

> + *
> + * Returns:
> + * True on success and false on failure.
> + */
> +bool igt_sriov_disable_vfs(int pf)
> +{
> +	igt_debug("Disabling %u VFs\n", igt_sriov_get_enabled_vfs(pf));

this will trigger unnecessary "read" operation just for debug purposes,
while in log you should already see "Enabling N VFs", so we know the N.

> +	return __pf_attr_set_u32(pf, "device/sriov_numvfs", 0);
> +}
> +
> +/**
> + * igt_sriov_is_driver_autoprobe_enabled:
> + * @pf: PF device file descriptor
> + *
> + * Get current driver autoprobe setting.

hmm, this is SRIOV driver autoprobe (or VF driver autoprobe for
short/clarity)

> + *
> + * Returns:
> + * True if autoprobe is enabled, false otherwise.
> + */
> +bool igt_sriov_is_driver_autoprobe_enabled(int pf)
> +{
> +	return __pf_attr_get_u32(pf, "device/sriov_drivers_autoprobe");
> +}
> +
> +/**
> + * igt_sriov_enable_driver_autoprobe:
> + * @pf: PF device file descriptor
> + *
> + * Set driver autoprobe to true.
> + *
> + * During VFs enabling driver will be bound to VFs.

"If successful, then kernel will automatically bind VFs to a compatible
driver immediately after they are enabled.

> + *
> + * Return:
> + * True if setting driver autoprobe succeed, otherwise false.
> + */
> +bool igt_sriov_enable_driver_autoprobe(int pf)
> +{
> +	return __pf_attr_set_u32(pf,  "device/sriov_drivers_autoprobe", true);
> +}
> +
> +/**
> + * igt_sriov_disable_driver_autoprobe:
> + * @pf: PF device file descriptor
> + *
> + * Set driver autoprobe to false.
> + *
> + * During VFs enabling driver won't be bound to VFs.
> + *
> + * Return:
> + * True if setting driver autoprobe succeed, otherwise false.
> + */
> +bool igt_sriov_disable_driver_autoprobe(int pf)
> +{
> +	return __pf_attr_set_u32(pf,  "device/sriov_drivers_autoprobe", false);
> +}
> diff --git a/lib/igt_sriov_device.h b/lib/igt_sriov_device.h
> new file mode 100644
> index 000000000..f2c5c44fa
> --- /dev/null
> +++ b/lib/igt_sriov_device.h
> @@ -0,0 +1,20 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright(c) 2023 Intel Corporation. All rights reserved.
> + */
> +
> +#ifndef __IGT_SRIOV_DEVICE_H__
> +#define __IGT_SRIOV_DEVICE_H__
> +
> +#include <stdint.h>
> +
> +bool igt_sriov_is_pf(int device);
> +unsigned int igt_sriov_get_total_vfs(int pf);
> +unsigned int igt_sriov_get_enabled_vfs(int pf);
> +bool igt_sriov_enable_vfs(int pf, unsigned int num_vfs);
> +bool igt_sriov_disable_vfs(int pf);
> +bool igt_sriov_is_driver_autoprobe_enabled(int pf);
> +bool igt_sriov_enable_driver_autoprobe(int pf);
> +bool igt_sriov_disable_driver_autoprobe(int pf);

nit: I'm wondering if there is any pattern to have:

a) void function that has igt_assert() inside
b) bool function that has no igt_assert() inside

then for writing scenario you just use a) without need to check
and use b) only when doing lower level testing and use dedicated checks

> +
> +#endif /* __IGT_SRIOV_DEVICE_H__ */
> diff --git a/lib/meson.build b/lib/meson.build
> index a7bccafc3..083baa68a 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -38,6 +38,7 @@ lib_sources = [
>  	'igt_primes.c',
>  	'igt_pci.c',
>  	'igt_rand.c',
> +	'igt_sriov_device.c',
>  	'igt_stats.c',
>  	'igt_syncobj.c',
>  	'igt_sysfs.c',

  reply	other threads:[~2023-11-06 22:07 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-06 19:59 [igt-dev] [PATCH i-g-t 0/8] Initial SR-IOV validation Lukasz Laguna
2023-11-06 19:59 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_sriov_device: add core SR-IOV helpers Lukasz Laguna
2023-11-06 22:07   ` Michal Wajdeczko [this message]
2023-11-09  6:55     ` Laguna, Lukasz
2023-11-10 19:22       ` Michal Wajdeczko
2023-11-17 14:34         ` Laguna, Lukasz
2023-11-20 14:26         ` Laguna, Lukasz
2023-11-06 19:59 ` [igt-dev] [PATCH i-g-t 2/8] lib/igt_sriov_device: add helper for opening VF device Lukasz Laguna
2023-11-06 19:59 ` [igt-dev] [PATCH i-g-t 3/8] lib/igt_sriov_device: add helper for checking if VF DRM driver is probed Lukasz Laguna
2023-11-06 19:59 ` [igt-dev] [PATCH i-g-t 4/8] lib/igt_sriov_device: add helpers for operations in different VFs scenarios Lukasz Laguna
2023-11-06 22:13   ` Michal Wajdeczko
2023-11-09  6:58     ` Laguna, Lukasz
2023-11-06 19:59 ` [igt-dev] [PATCH i-g-t 5/8] tests/sriov_basic: add basic tests for enabling SR-IOV VFs Lukasz Laguna
2023-11-06 22:46   ` Michal Wajdeczko
2023-11-09  7:04     ` Laguna, Lukasz
2023-11-10 19:37       ` Michal Wajdeczko
2023-11-20 14:29         ` Laguna, Lukasz
2023-11-06 19:59 ` [igt-dev] [PATCH i-g-t 6/8] lib/igt_sriov_device: add helpers for VF DRM driver bind and unbind Lukasz Laguna
2023-11-06 19:59 ` [igt-dev] [PATCH i-g-t 7/8] tests/sriov_basic: validate driver binding to VFs Lukasz Laguna
2023-11-06 22:59   ` Michal Wajdeczko
2023-11-09  7:06     ` Laguna, Lukasz
2023-11-10 19:44       ` Michal Wajdeczko
2023-11-20 14:31         ` Laguna, Lukasz
2023-11-06 19:59 ` [igt-dev] [PATCH i-g-t 8/8] tests/sriov_basic: add more tests for VF driver binding Lukasz Laguna
2023-11-06 20:55 ` [igt-dev] ✓ CI.xeBAT: success for Initial SR-IOV validation Patchwork
2023-11-06 21:00 ` [igt-dev] ✓ Fi.CI.BAT: " Patchwork
2023-11-07  6:03 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2023-11-09  6:51 [igt-dev] [PATCH i-g-t 0/8] " Lukasz Laguna
2023-11-09  6:51 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_sriov_device: add core SR-IOV helpers Lukasz Laguna
2023-11-09 11:57   ` Kamil Konieczny
2023-11-20 14:21     ` Laguna, Lukasz
2023-11-20 14:14 [igt-dev] [PATCH i-g-t 0/8] Initial SR-IOV validation Lukasz Laguna
2023-11-20 14:14 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_sriov_device: add core SR-IOV helpers Lukasz Laguna
2023-11-24  8:52 [igt-dev] [PATCH i-g-t 0/8] Initial SR-IOV validation Lukasz Laguna
2023-11-24  8:52 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_sriov_device: add core SR-IOV helpers Lukasz Laguna
2023-11-30 12:48 [igt-dev] [PATCH i-g-t 0/8] Initial SR-IOV validation Lukasz Laguna
2023-11-30 12:48 ` [igt-dev] [PATCH i-g-t 1/8] lib/igt_sriov_device: add core SR-IOV helpers Lukasz Laguna
2023-12-01 15:21   ` Kamil Konieczny

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=5304b828-d2f1-4bda-a4b1-3be8129f4ce1@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=lukasz.laguna@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox