Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: adam.miszczak@linux.intel.com, jakub1.kolakowski@intel.com,
	lukasz.laguna@intel.com, michal.wajdeczko@intel.com,
	michal.winiarski@intel.com, narasimha.c.v@intel.com,
	piotr.piorkowski@intel.com, satyanarayana.k.v.p@intel.com,
	tomasz.lis@intel.com,
	Marcin Bernatowicz <marcin.bernatowicz@linux.intel.com>
Subject: [PATCH v2 i-g-t 1/6] lib/igt_sriov_device: add helper for opening SR-IOV device sysfs
Date: Mon, 21 Oct 2024 22:07:32 +0200	[thread overview]
Message-ID: <20241021200737.941384-2-marcin.bernatowicz@linux.intel.com> (raw)
In-Reply-To: <20241021200737.941384-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>
Reviewed-by: Adam Miszczak <adam.miszczak@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


  reply	other threads:[~2024-10-21 20:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-21 20:07 [PATCH v2 i-g-t 0/6] Introduce xe_sriov_flr test Marcin Bernatowicz
2024-10-21 20:07 ` Marcin Bernatowicz [this message]
2024-10-21 20:07 ` [PATCH v2 i-g-t 2/6] lib/igt_sriov_device: add helper for resetting SR-IOV device Marcin Bernatowicz
2024-10-22 10:10   ` Michal Wajdeczko
2024-10-23 14:23     ` Bernatowicz, Marcin
2024-10-21 20:07 ` [PATCH v2 i-g-t 3/6] tests/intel/xe_sriov_flr: Add skeleton for clear and isolation tests Marcin Bernatowicz
2024-10-21 20:07 ` [PATCH v2 i-g-t 4/6] tests/intel/xe_sriov_flr: Implement clear-ggtt subcheck Marcin Bernatowicz
2024-10-21 20:07 ` [PATCH v2 i-g-t 5/6] tests/intel/xe_sriov_flr: Implement clear-lmem subcheck Marcin Bernatowicz
2024-10-21 20:07 ` [PATCH v2 i-g-t 6/6] tests/intel/xe_sriov_flr: Implement clear-scratch-regs and clear-media-scratch-regs subchecks Marcin Bernatowicz
2024-10-21 21:41 ` ✓ Fi.CI.BAT: success for Introduce xe_sriov_flr test (rev2) Patchwork
2024-10-21 21:51 ` ✓ CI.xeBAT: " Patchwork
2024-10-22  3:56 ` ✗ CI.xeFULL: failure " Patchwork
2024-10-22  5:07 ` ✗ Fi.CI.IGT: " Patchwork
2024-10-28 14:29 ` [PATCH v2 i-g-t 0/6] Introduce xe_sriov_flr test Laguna, Lukasz

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=20241021200737.941384-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