[PATCH v2 i-g-t 2/6] lib/igt_sriov_device: add helper for resetting SR-IOV device

Marcin Bernatowicz marcin.bernatowicz at linux.intel.com
Mon Oct 21 20:07:33 UTC 2024


Reset is initiated by writing 1 to device's sysfs reset attribute.

Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz at linux.intel.com>
Reviewed-by: Adam Miszczak <adam.miszczak 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/igt_sriov_device.c | 51 ++++++++++++++++++++++++++++++++++++++++++
 lib/igt_sriov_device.h |  2 ++
 2 files changed, 53 insertions(+)

diff --git a/lib/igt_sriov_device.c b/lib/igt_sriov_device.c
index d20c74823..2b83cd43c 100644
--- a/lib/igt_sriov_device.c
+++ b/lib/igt_sriov_device.c
@@ -413,3 +413,54 @@ int igt_sriov_device_sysfs_open(int pf, unsigned int vf_num)
 
 	return fd;
 }
+
+/**
+ * igt_sriov_device_reset_exists:
+ * @pf: PF device file descriptor
+ * @vf_num: VF number (1-based to identify single VF) or 0 for PF
+ *
+ * Check if reset attribute exists for a given SR-IOV device.
+ *
+ * Returns:
+ * True if reset attribute exists, false otherwise.
+ */
+bool igt_sriov_device_reset_exists(int pf, unsigned int vf_num)
+{
+	int sysfs;
+	bool reset_exists;
+
+	sysfs = igt_sriov_device_sysfs_open(pf, vf_num);
+	if (sysfs < 0)
+		return false;
+
+	reset_exists = igt_sysfs_has_attr(sysfs, "reset");
+	close(sysfs);
+
+	return reset_exists;
+}
+
+/**
+ * igt_sriov_device_reset:
+ * @pf: PF device file descriptor
+ * @vf_num: VF number (1-based to identify single VF) or 0 for PF
+ *
+ * Trigger FLR on a given VF.
+ *
+ * Returns:
+ * True on success, false on failure.
+ */
+bool igt_sriov_device_reset(int pf, unsigned int vf_num)
+{
+	int sysfs;
+	bool ret;
+
+	sysfs = igt_sriov_device_sysfs_open(pf, vf_num);
+	if (sysfs < 0)
+		return false;
+
+	igt_debug("Initiating FLR on VF%d\n", vf_num);
+	ret = igt_sysfs_set(sysfs, "reset", "1");
+	close(sysfs);
+
+	return ret;
+}
diff --git a/lib/igt_sriov_device.h b/lib/igt_sriov_device.h
index dc95a4c78..4b63ceb22 100644
--- a/lib/igt_sriov_device.h
+++ b/lib/igt_sriov_device.h
@@ -31,6 +31,8 @@ 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);
+bool igt_sriov_device_reset_exists(int pf, unsigned int vf_num);
+bool igt_sriov_device_reset(int pf, unsigned int vf_num);
 
 /**
  * for_each_sriov_vf - Helper for running code on each VF
-- 
2.31.1



More information about the igt-dev mailing list