[PATCH i-g-t v1 1/4] lib/xe/xe_sriov_provisioning: Add helper to read VF's configuration data

K V P, Satyanarayana satyanarayana.k.v.p at intel.com
Fri Jan 24 10:46:31 UTC 2025


> -----Original Message-----
> From: Laguna, Lukasz <lukasz.laguna at intel.com>
> Sent: Friday, January 24, 2025 1:41 PM
> To: igt-dev at lists.freedesktop.org
> Cc: marcin.bernatowicz at linux.intel.com; Laguna, Lukasz
> <lukasz.laguna at intel.com>; K V P, Satyanarayana
> <satyanarayana.k.v.p at intel.com>; Wajdeczko, Michal
> <Michal.Wajdeczko at intel.com>; adam.miszczak at linux.intel.com; Kolakowski,
> Jakub1 <jakub1.kolakowski at intel.com>
> Subject: [PATCH i-g-t v1 1/4] lib/xe/xe_sriov_provisioning: Add helper to read
> VF's configuration data
> 
> Add helper allowing to read configuration data that VF queried from GuC
> during probe.
> 
> Signed-off-by: Lukasz Laguna <lukasz.laguna at intel.com>
> ---
Reviewed-by: Satyanarayana K V P <satyanarayana.k.v.p at intel.com>
>  lib/xe/xe_sriov_provisioning.c | 80
> ++++++++++++++++++++++++++++++++++
>  lib/xe/xe_sriov_provisioning.h |  5 +++
>  2 files changed, 85 insertions(+)
> 
> diff --git a/lib/xe/xe_sriov_provisioning.c b/lib/xe/xe_sriov_provisioning.c
> index 22035ffd8..5ba348131 100644
> --- a/lib/xe/xe_sriov_provisioning.c
> +++ b/lib/xe/xe_sriov_provisioning.c
> @@ -4,8 +4,10 @@
>   */
> 
>  #include <errno.h>
> +#include <fcntl.h>
> 
>  #include "igt_core.h"
> +#include "igt_debugfs.h"
>  #include "intel_chipset.h"
>  #include "linux_scaffold.h"
>  #include "xe/xe_mmio.h"
> @@ -296,3 +298,81 @@ bool xe_sriov_is_shared_res_provisionable(int pf,
> enum xe_sriov_shared_res res,
> 
>  	return true;
>  }
> +
> +/**
> + * __xe_sriov_vf_get_shared_res_selfconfig - Read VF's configuration data.
> + * @vf: VF device file descriptor
> + * @res: Shared resource type (see enum xe_sriov_shared_res)
> + * @gt_num: GT number
> + * @value: Pointer to store the read value
> + *
> + * Reads the specified shared resource @res from selfconfig of given VF
> device
> + * @vf on GT @gt_num.
> + *
> + * Return: 0 on success, negative error code on failure.
> + */
> +int __xe_sriov_vf_get_shared_res_selfconfig(int vf, enum
> xe_sriov_shared_res res,
> +					    unsigned int gt_num, uint64_t
> *value)
> +{
> +	FILE *file;
> +	size_t n = 0;
> +	char *line = NULL;
> +	int fd, ret = 0;
> +
> +	fd = igt_debugfs_gt_open(vf, gt_num, "vf/self_config", O_RDONLY);
> +	if (fd < 0)
> +		return fd;
> +	file = fdopen(fd, "r");
> +	if (!file) {
> +		close(fd);
> +		return -errno;
> +	}
> +
> +	while (getline(&line, &n, file) >= 0) {
> +		switch (res) {
> +		case XE_SRIOV_SHARED_RES_CONTEXTS:
> +			ret = sscanf(line, "GuC contexts: %lu", value);
> +			break;
> +		case XE_SRIOV_SHARED_RES_DOORBELLS:
> +			ret = sscanf(line, "GuC doorbells: %lu", value);
> +			break;
> +		case XE_SRIOV_SHARED_RES_GGTT:
> +			ret = sscanf(line, "GGTT size: %lu", value);
> +			break;
> +		case XE_SRIOV_SHARED_RES_LMEM:
> +			ret = sscanf(line, "LMEM size: %lu", value);
> +			break;
> +		}
> +
> +		if (ret > 0)
> +			break;
> +	}
> +
> +	free(line);
> +	fclose(file);
> +	close(fd);
> +
> +	return ret ? 0 : -1;
> +}
> +/**
> + * xe_sriov_vf_get_shared_res_selfconfig - Read VF's configuration data.
> + * @pf: PF device file descriptor
> + * @res: Shared resource type (see enum xe_sriov_shared_res)
> + * @gt_num: GT number
> + *
> + * A throwing version of __xe_sriov_vf_get_shared_res_selfconfig().
> + * Instead of returning an error code, it returns the quota value and asserts
> + * in case of an error.
> + *
> + * Return: The quota for the given shared resource.
> + *         Asserts in case of failure.
> + */
> +uint64_t xe_sriov_vf_get_shared_res_selfconfig(int vf, enum
> xe_sriov_shared_res res,
> +					       unsigned int gt_num)
> +{
> +	uint64_t value;
> +
> +	igt_fail_on(__xe_sriov_vf_get_shared_res_selfconfig(vf, res, gt_num,
> &value));
> +
> +	return value;
> +}
> diff --git a/lib/xe/xe_sriov_provisioning.h b/lib/xe/xe_sriov_provisioning.h
> index b4300ec2e..1a05c2c59 100644
> --- a/lib/xe/xe_sriov_provisioning.h
> +++ b/lib/xe/xe_sriov_provisioning.h
> @@ -90,4 +90,9 @@ void xe_sriov_pf_set_shared_res_attr(int pf, enum
> xe_sriov_shared_res res,
>  				     unsigned int vf_num, unsigned int gt_num,
>  				     uint64_t value);
> 
> +int __xe_sriov_vf_get_shared_res_selfconfig(int vf, enum
> xe_sriov_shared_res res,
> +					    unsigned int gt_num, uint64_t
> *value);
> +uint64_t xe_sriov_vf_get_shared_res_selfconfig(int vf, enum
> xe_sriov_shared_res res,
> +					       unsigned int gt_num);
> +
>  #endif /* __XE_SRIOV_PROVISIONING_H__ */
> --
> 2.40.0



More information about the igt-dev mailing list