From: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: "Marcin Bernatowicz" <marcin.bernatowicz@linux.intel.com>,
"Adam Miszczak" <adam.miszczak@linux.intel.com>,
"Jakub Kolakowski" <jakub1.kolakowski@intel.com>,
"Lukasz Laguna" <lukasz.laguna@intel.com>,
"Michał Wajdeczko" <michal.wajdeczko@intel.com>,
"Michał Winiarski" <michal.winiarski@intel.com>,
"Narasimha C V" <narasimha.c.v@intel.com>,
"Piotr Piórkowski" <piotr.piorkowski@intel.com>,
"Satyanarayana K V P" <satyanarayana.k.v.p@intel.com>,
"Tomasz Lis" <tomasz.lis@intel.com>
Subject: [PATCH i-g-t 1/6] lib/igt_sriov_device: add helper for opening SR-IOV device sysfs
Date: Wed, 9 Oct 2024 13:30:13 +0200 [thread overview]
Message-ID: <20241009113018.741371-2-marcin.bernatowicz@linux.intel.com> (raw)
In-Reply-To: <20241009113018.741371-1-marcin.bernatowicz@linux.intel.com>
Helper allows to open sysfs directory corresponding to SR-IOV device.
Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Cc: Adam Miszczak <adam.miszczak@linux.intel.com>
Cc: Jakub Kolakowski <jakub1.kolakowski@intel.com>
Cc: Lukasz Laguna <lukasz.laguna@intel.com>
Cc: Michał Wajdeczko <michal.wajdeczko@intel.com>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: Narasimha C V <narasimha.c.v@intel.com>
Cc: Piotr Piórkowski <piotr.piorkowski@intel.com>
Cc: Satyanarayana K V P <satyanarayana.k.v.p@intel.com>
Cc: Tomasz Lis <tomasz.lis@intel.com>
---
lib/igt_sriov_device.c | 32 ++++++++++++++++++++++++++++++++
lib/igt_sriov_device.h | 1 +
2 files changed, 33 insertions(+)
diff --git a/lib/igt_sriov_device.c b/lib/igt_sriov_device.c
index 7c3814bf2..d20c74823 100644
--- a/lib/igt_sriov_device.c
+++ b/lib/igt_sriov_device.c
@@ -5,6 +5,7 @@
#include <dirent.h>
#include <errno.h>
+#include <fcntl.h>
#include <limits.h>
#include <pciaccess.h>
@@ -381,3 +382,34 @@ void igt_sriov_unbind_vf_drm_driver(int pf, unsigned int vf_num)
{
igt_assert(__igt_sriov_bind_vf_drm_driver(pf, vf_num, false));
}
+
+/**
+ * igt_sriov_device_sysfs_open:
+ * @pf: PF device file descriptor
+ * @vf_num: VF number (1-based to identify single VF) or 0 for PF
+ *
+ * Open the sysfs directory corresponding to SR-IOV device.
+ *
+ * Returns:
+ * The SR-IOV device sysfs directory fd, -1 on failure.
+ */
+int igt_sriov_device_sysfs_open(int pf, unsigned int vf_num)
+{
+ char path[PATH_MAX];
+ int sysfs, fd;
+
+ sysfs = igt_sysfs_open(pf);
+ if (sysfs < 0)
+ return -1;
+
+ if (!vf_num)
+ snprintf(path, sizeof(path), "device");
+ else
+ /* vf_num is 1-based, but virtfn is 0-based */
+ snprintf(path, sizeof(path), "device/virtfn%u", vf_num - 1);
+
+ fd = openat(sysfs, path, O_DIRECTORY | O_RDONLY);
+ close(sysfs);
+
+ return fd;
+}
diff --git a/lib/igt_sriov_device.h b/lib/igt_sriov_device.h
index 20ffc515f..dc95a4c78 100644
--- a/lib/igt_sriov_device.h
+++ b/lib/igt_sriov_device.h
@@ -30,6 +30,7 @@ int igt_sriov_open_vf_drm_device(int pf, unsigned int vf_num);
bool igt_sriov_is_vf_drm_driver_probed(int pf, unsigned int vf_num);
void igt_sriov_bind_vf_drm_driver(int pf, unsigned int vf_num);
void igt_sriov_unbind_vf_drm_driver(int pf, unsigned int vf_num);
+int igt_sriov_device_sysfs_open(int pf, unsigned int vf_num);
/**
* for_each_sriov_vf - Helper for running code on each VF
--
2.31.1
next prev parent reply other threads:[~2024-10-09 11:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 11:30 [PATCH i-g-t 0/6] Introduce xe_sriov_flr test Marcin Bernatowicz
2024-10-09 11:30 ` Marcin Bernatowicz [this message]
2024-10-14 13:34 ` [PATCH i-g-t 1/6] lib/igt_sriov_device: add helper for opening SR-IOV device sysfs Adam Miszczak
2024-10-09 11:30 ` [PATCH i-g-t 2/6] lib/igt_sriov_device: add helper for resetting SR-IOV device Marcin Bernatowicz
2024-10-14 13:37 ` Adam Miszczak
2024-10-09 11:30 ` [PATCH i-g-t 3/6] tests/intel/xe_sriov_flr: Add skeleton for clear and isolation tests Marcin Bernatowicz
2024-10-18 6:58 ` Laguna, Lukasz
2024-10-09 11:30 ` [PATCH i-g-t 4/6] tests/intel/xe_sriov_flr: Implement clear-ggtt subcheck Marcin Bernatowicz
2024-10-18 7:06 ` Laguna, Lukasz
2024-10-09 11:30 ` [PATCH i-g-t 5/6] tests/intel/xe_sriov_flr: Implement clear-lmem subcheck Marcin Bernatowicz
2024-10-18 7:17 ` Laguna, Lukasz
2024-10-09 11:30 ` [PATCH i-g-t 6/6] tests/intel/xe_sriov_flr: Implement clear-scratch-regs and clear-media-scratch-regs subchecks Marcin Bernatowicz
2024-10-10 0:04 ` ✓ CI.xeBAT: success for Introduce xe_sriov_flr test Patchwork
2024-10-10 0:13 ` ✓ Fi.CI.BAT: " Patchwork
2024-10-10 14:13 ` ✗ CI.xeFULL: failure " Patchwork
2024-10-11 6:35 ` ✗ Fi.CI.IGT: " 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=20241009113018.741371-2-marcin.bernatowicz@linux.intel.com \
--to=marcin.bernatowicz@linux.intel.com \
--cc=adam.miszczak@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=jakub1.kolakowski@intel.com \
--cc=lukasz.laguna@intel.com \
--cc=michal.wajdeczko@intel.com \
--cc=michal.winiarski@intel.com \
--cc=narasimha.c.v@intel.com \
--cc=piotr.piorkowski@intel.com \
--cc=satyanarayana.k.v.p@intel.com \
--cc=tomasz.lis@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