[PATCH i-g-t 1/4] lib/xe/xe_sriov_debugfs: Add debugfs get/set functions for u32, u64, bool

Laguna, Lukasz lukasz.laguna at intel.com
Mon Dec 2 13:03:43 UTC 2024


On 11/27/2024 21:02, Marcin Bernatowicz wrote:
> Add helper functions to get and set SR-IOV debugfs attributes for u32,
> u64, and boolean types.
>
> Functions added:
> - __xe_sriov_pf_debugfs_get_u32
> - __xe_sriov_pf_debugfs_set_u32
> - __xe_sriov_pf_debugfs_get_u64
> - __xe_sriov_pf_debugfs_set_u64
> - __xe_sriov_pf_debugfs_get_boolean
> - __xe_sriov_pf_debugfs_set_boolean
>
> Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz at linux.intel.com>
> Cc: Adam Miszczak <adam.miszczak at linux.intel.com>
> Cc: Jakub Kolakowski <jakub1.kolakowski at intel.com>
> Cc: Lukasz Laguna <lukasz.laguna at intel.com>
> Cc: Michał Wajdeczko <michal.wajdeczko at intel.com>
> Cc: Michał Winiarski <michal.winiarski at intel.com>
> Cc: Narasimha C V <narasimha.c.v at intel.com>
> Cc: Piotr Piórkowski <piotr.piorkowski at intel.com>
> Cc: Satyanarayana K V P <satyanarayana.k.v.p at intel.com>
> Cc: Tomasz Lis <tomasz.lis at intel.com>
> ---
>   lib/xe/xe_sriov_debugfs.c | 194 ++++++++++++++++++++++++++++++++++++++
>   lib/xe/xe_sriov_debugfs.h |  18 ++++
>   2 files changed, 212 insertions(+)
>
> diff --git a/lib/xe/xe_sriov_debugfs.c b/lib/xe/xe_sriov_debugfs.c
> index c87f91492..038912f23 100644
> --- a/lib/xe/xe_sriov_debugfs.c
> +++ b/lib/xe/xe_sriov_debugfs.c
> @@ -9,6 +9,7 @@
>   #include "drmtest.h"
>   #include "igt_debugfs.h"
>   #include "igt_sriov_device.h"
> +#include "igt_sysfs.h"
>   #include "xe/xe_query.h"
>   #include "xe/xe_sriov_debugfs.h"
>   #include "xe/xe_sriov_provisioning.h"
> @@ -204,3 +205,196 @@ cleanup:
>   
>   	return ret;
>   }
> +
> +static int xe_sriov_pf_debugfs_path_open(int pf, unsigned int vf_num,
> +					 unsigned int gt_num)
> +{
> +	char path[PATH_MAX];
> +
> +	if (igt_debug_on_f(!xe_sriov_pf_debugfs_path(pf, vf_num, gt_num, path,
> +						     sizeof(path)),
> +			   "path: %s\n", path))
> +		return -1;
> +
> +	return open(path, O_RDONLY);

O_RDWR?

> +}
> +
> +/**
> + * __xe_sriov_pf_debugfs_get_u32:
> + * @pf: PF device file descriptor
> + * @vf_num: VF number (1-based) or 0 for PF
> + * @gt_num: GT number
> + * @attr: debugfs attribute name
> + * @value: pointer to read value
> + *
> + * Reads SR-IOV debugfs attribute @attr for given PF device @pf,
> + * VF number @vf_num on GT @gt_num.
> + *
> + * Return: 0 on success and negative error on failure.
> + */
> +int __xe_sriov_pf_debugfs_get_u32(int pf, unsigned int vf_num,
> +				  unsigned int gt_num, const char *attr,
> +				  uint32_t *value)
> +{
> +	bool ret;
> +	int dir;
> +
> +	dir = xe_sriov_pf_debugfs_path_open(pf, vf_num, gt_num);
> +	if (igt_debug_on(dir < 0))
> +		return false;

return dir;

> +
> +	ret = __igt_sysfs_get_u32(dir, attr, value);
> +	close(dir);
> +
> +	return ret ? 0 : -1;
> +}
> +
> +/**
> + * __xe_sriov_pf_debugfs_set_u32:
> + * @pf: PF device file descriptor
> + * @vf_num: VF number (1-based) or 0 for PF
> + * @gt_num: GT number
> + * @attr: debugfs attribute name
> + * @value: u32 value to be set
> + *
> + * Writes @value to SR-IOV debugfs attribute @attr for given PF device @pf,
> + * VF number @vf_num on GT @gt_num.
> + *
> + * Return: 0 on success and negative error on failure.
> + */
> +int __xe_sriov_pf_debugfs_set_u32(int pf, unsigned int vf_num,
> +				  unsigned int gt_num, const char *attr,
> +				  uint32_t value)
> +{
> +	bool ret;
> +	int dir;
> +
> +	dir = xe_sriov_pf_debugfs_path_open(pf, vf_num, gt_num);
> +	if (igt_debug_on(dir < 0))
> +		return dir;
> +
> +	ret = __igt_sysfs_set_u32(dir, attr, value);
> +	close(dir);
> +
> +	return ret ? 0 : -1;
> +}
> +
> +/**
> + * __xe_sriov_pf_debugfs_get_u64:
> + * @pf: PF device file descriptor
> + * @vf_num: VF number (1-based) or 0 for PF
> + * @gt_num: GT number
> + * @attr: debugfs attribute name
> + * @value: pointer to read value
> + *
> + * Reads SR-IOV debugfs attribute @attr for given PF device @pf,
> + * VF number @vf_num on GT @gt_num.
> + *
> + * Return: 0 on success and negative error on failure.
> + */
> +int __xe_sriov_pf_debugfs_get_u64(int pf, unsigned int vf_num,
> +				  unsigned int gt_num, const char *attr,
> +				  uint64_t *value)
> +{
> +	bool ret;
> +	int dir;
> +
> +	dir = xe_sriov_pf_debugfs_path_open(pf, vf_num, gt_num);
> +	if (igt_debug_on(dir < 0))
> +		return dir;
> +
> +	ret = __igt_sysfs_get_u64(dir, attr, value);
> +	close(dir);
> +
> +	return ret ? 0 : -1;
> +}
> +
> +/**
> + * __xe_sriov_pf_debugfs_set_u64:
> + * @pf: PF device file descriptor
> + * @vf_num: VF number (1-based) or 0 for PF
> + * @gt_num: GT number
> + * @attr: debugfs attribute name
> + * @value: u64 value to be set
> + *
> + * Writes @value to SR-IOV debugfs attribute @attr for given PF device @pf,
> + * VF number @vf_num on GT @gt_num.
> + *
> + * Return: 0 on success and negative error on failure.
> + */
> +int __xe_sriov_pf_debugfs_set_u64(int pf, unsigned int vf_num,
> +				  unsigned int gt_num, const char *attr,
> +				  uint64_t value)
> +{
> +	bool ret;
> +	int dir;
> +
> +	dir = xe_sriov_pf_debugfs_path_open(pf, vf_num, gt_num);
> +	if (igt_debug_on(dir < 0))
> +		return dir;
> +
> +	ret = __igt_sysfs_set_u64(dir, attr, value);
> +	close(dir);
> +
> +	return ret ? 0 : -1;
> +}
> +
> +/**
> + * __xe_sriov_pf_debugfs_get_boolean:
> + * @pf: PF device file descriptor
> + * @vf_num: VF number (1-based) or 0 for PF
> + * @gt_num: GT number
> + * @attr: debugfs attribute name
> + * @value: pointer to read value
> + *
> + * Reads SR-IOV debugfs attribute @attr for given PF device @pf,
> + * VF number @vf_num on GT @gt_num.
> + *
> + * Return: 0 on success and negative error on failure.
> + */
> +int __xe_sriov_pf_debugfs_get_boolean(int pf, unsigned int vf_num,
> +				      unsigned int gt_num, const char *attr,
> +				      bool *value)
> +{
> +	bool ret;
> +	int dir;
> +
> +	dir = xe_sriov_pf_debugfs_path_open(pf, vf_num, gt_num);
> +	if (igt_debug_on(dir < 0))
> +		return dir;
> +
> +	ret = __igt_sysfs_get_boolean(dir, attr, value);
> +	close(dir);
> +
> +	return ret ? 0 : -1;
> +}
> +
> +/**
> + * __xe_sriov_pf_debugfs_set_boolean:
> + * @pf: PF device file descriptor
> + * @vf_num: VF number (1-based) or 0 for PF
> + * @gt_num: GT number
> + * @attr: debugfs attribute name
> + * @value: u64 value to be set
> + *
> + * Writes @value to SR-IOV debugfs attribute @attr for given PF device @pf,
> + * VF number @vf_num on GT @gt_num.
> + *
> + * Return: 0 on success and negative error on failure.
> + */
> +int __xe_sriov_pf_debugfs_set_boolean(int pf, unsigned int vf_num,
> +				      unsigned int gt_num, const char *attr,
> +				      bool value)
> +{
> +	bool ret;
> +	int dir;
> +
> +	dir = xe_sriov_pf_debugfs_path_open(pf, vf_num, gt_num);
> +	if (igt_debug_on(dir < 0))
> +		return dir;
> +
> +	ret = __igt_sysfs_set_boolean(dir, attr, value);
> +	close(dir);
> +
> +	return ret ? 0 : -1;
> +}
> diff --git a/lib/xe/xe_sriov_debugfs.h b/lib/xe/xe_sriov_debugfs.h
> index 856445e76..2db965f9b 100644
> --- a/lib/xe/xe_sriov_debugfs.h
> +++ b/lib/xe/xe_sriov_debugfs.h
> @@ -16,5 +16,23 @@ int xe_sriov_pf_debugfs_read_provisioned_ranges(int pf_fd, enum xe_sriov_shared_
>   						unsigned int gt_id,
>   						struct xe_sriov_provisioned_range **ranges,
>   						unsigned int *nr_ranges);
> +int __xe_sriov_pf_debugfs_get_u32(int pf, unsigned int vf_num,
> +				  unsigned int gt_num, const char *attr,
> +				  uint32_t *value);
> +int __xe_sriov_pf_debugfs_set_u32(int pf, unsigned int vf_num,
> +				  unsigned int gt_num, const char *attr,
> +				  uint32_t value);
> +int __xe_sriov_pf_debugfs_get_u64(int pf, unsigned int vf_num,
> +				  unsigned int gt_num, const char *attr,
> +				  uint64_t *value);
> +int __xe_sriov_pf_debugfs_set_u64(int pf, unsigned int vf_num,
> +				  unsigned int gt_num, const char *attr,
> +				  uint64_t value);
> +int __xe_sriov_pf_debugfs_get_boolean(int pf, unsigned int vf_num,
> +				      unsigned int gt_num, const char *attr,
> +				      bool *value);
> +int __xe_sriov_pf_debugfs_set_boolean(int pf, unsigned int vf_num,
> +				      unsigned int gt_num, const char *attr,
> +				      bool value);
>   
>   #endif /* __XE_SRIOV_DEBUGFS_H__ */


More information about the igt-dev mailing list