[PATCH i-g-t 1/5] lib/xe_sriov_debugfs: add helper for opening attributes

Kamil Konieczny kamil.konieczny at linux.intel.com
Thu Oct 31 10:28:25 UTC 2024


Hi Marcin,
On 2024-10-30 at 20:36:25 +0100, Marcin Bernatowicz wrote:
> From: Lukasz Laguna <lukasz.laguna at intel.com>
> 
> Helper allows to open SR-IOV debugfs attributes corresponding to
> specified PF device, VF number and GT number.
> 
> Signed-off-by: Lukasz Laguna <lukasz.laguna at intel.com>
> 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: 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/meson.build           |  1 +
>  lib/xe/xe_sriov_debugfs.c | 69 +++++++++++++++++++++++++++++++++++++++
>  lib/xe/xe_sriov_debugfs.h | 14 ++++++++
>  3 files changed, 84 insertions(+)
>  create mode 100644 lib/xe/xe_sriov_debugfs.c
>  create mode 100644 lib/xe/xe_sriov_debugfs.h
> 
> diff --git a/lib/meson.build b/lib/meson.build
> index c3556a921..3d5d68b75 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -116,6 +116,7 @@ lib_sources = [
>  	'xe/xe_mmio.c',
>  	'xe/xe_query.c',
>  	'xe/xe_spin.c',
> +	'xe/xe_sriov_debugfs.c',
>  	'xe/xe_util.c',
>  ]
>  
> diff --git a/lib/xe/xe_sriov_debugfs.c b/lib/xe/xe_sriov_debugfs.c
> new file mode 100644
> index 000000000..dc6ef9da3
> --- /dev/null
> +++ b/lib/xe/xe_sriov_debugfs.c
> @@ -0,0 +1,69 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright(c) 2024 Intel Corporation. All rights reserved.
> + */
> +
> +#include <dirent.h>
> +#include <fcntl.h>
> +
> +#include "drmtest.h"
> +#include "igt_debugfs.h"
> +#include "igt_sriov_device.h"
> +#include "xe/xe_sriov_debugfs.h"
> +#include "xe/xe_query.h"
> +
> +#define SRIOV_DEBUGFS_PATH_MAX 96
> +
> +static char *xe_sriov_pf_debugfs_path(int pf, unsigned int vf_num, unsigned int gt_num, char *path,
> +				      int pathlen)
> +{
> +	char sriov_path[SRIOV_DEBUGFS_PATH_MAX];
> +
> +	if (!igt_debugfs_path(pf, path, pathlen))
> +		return NULL;
> +
> +	if (vf_num)
> +		snprintf(sriov_path, SRIOV_DEBUGFS_PATH_MAX, "/gt%u/vf%u/", gt_num, vf_num);
> +	else
> +		snprintf(sriov_path, SRIOV_DEBUGFS_PATH_MAX, "/gt%u/pf/", gt_num);
> +
> +	strncat(path, sriov_path, pathlen - strlen(path));
> +
> +	if (access(path, F_OK))
> +		return NULL;
> +
> +	return path;
> +}
> +
> +/**
> + * xe_sriov_pf_debugfs_attr_open:
> + * @pf: PF device file descriptor
> + * @vf_num: VF number (1-based) or 0 for PF
> + * @gt_num: GT number
> + * @attr: debugfs attribute name
> + * @mode: mode bits as used by open()
> + *
> + * Opens SR-IOV debugfs attribute @attr for given PF device @pf, VF number @vf_num on GT @gt_num.
> + *
> + * Returns:
> + * File descriptor or -1 on failure.
> + */
> +int xe_sriov_pf_debugfs_attr_open(int pf, unsigned int vf_num, unsigned int gt_num,
> +				  const char *attr, int mode)
> +{
> +	char path[PATH_MAX];
> +	int debugfs;
> +
> +	igt_assert(igt_sriov_is_pf(pf) && is_xe_device(pf));
> +	igt_assert(gt_num < xe_number_gt(pf));
> +
> +	if (!xe_sriov_pf_debugfs_path(pf, vf_num, gt_num, path, sizeof(path)))
> +		return -1;
> +
> +	strncat(path, attr, sizeof(path) - strlen(path));
> +
> +	debugfs = open(path, mode);
> +	igt_debug_on(debugfs < 0);
> +
> +	return debugfs;
> +}
> diff --git a/lib/xe/xe_sriov_debugfs.h b/lib/xe/xe_sriov_debugfs.h
> new file mode 100644
> index 000000000..e859ff5b2
> --- /dev/null
> +++ b/lib/xe/xe_sriov_debugfs.h
> @@ -0,0 +1,14 @@
> +/* SPDX-License-Identifier: MIT */
> +/*
> + * Copyright(c) 2024 Intel Corporation. All rights reserved.
> + */
> +
> +#ifndef __XE_SRIOV_DEBUGFS_H__
> +#define __XE_SRIOV_DEBUGFS_H__
> +
> +#include <stdint.h>

You do not need this include here, please remove it.

Regards,
Kamil

> +
> +int xe_sriov_pf_debugfs_attr_open(int pf, unsigned int vf_num, unsigned int gt_num,
> +				  const char *attr, int mode);
> +
> +#endif /* __XE_SRIOV_DEBUGFS_H__ */
> -- 
> 2.31.1
> 


More information about the igt-dev mailing list