accel/habanalabs: add parent_device sysfs attribute
authorTomer Tayar <ttayar@habana.ai>
Wed, 3 May 2023 10:19:17 +0000 (13:19 +0300)
committerOded Gabbay <ogabbay@kernel.org>
Tue, 19 Dec 2023 09:09:44 +0000 (11:09 +0200)
The device debugfs directory was modified to be named as the
device-name.
This name is the parent device name, i.e. either the PCI address in case
of an ASIC, or the simulator device name in case of a simulator.

This change makes it more difficult for a user to access the debugfs
directory for a specific accel device, because he can't just use the
accel minor id, but he needs to do more device-dependent operations to
get the device name.

To make it easier to get this name, add a 'parent_device' sysfs
attribute that the user can read using the minor id before accessing
debugfs.

Signed-off-by: Tomer Tayar <ttayar@habana.ai>
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Signed-off-by: Oded Gabbay <ogabbay@kernel.org>
Documentation/ABI/testing/sysfs-driver-habanalabs
drivers/accel/habanalabs/common/habanalabs.h
drivers/accel/habanalabs/common/sysfs.c

index 89fe3b09d4adb02d693866a3910bb42d4feefd92..4244f5af4b54b3ef3fc685ea942593fc99eaebb8 100644 (file)
@@ -155,6 +155,12 @@ KernelVersion:  not yet upstreamed
 Contact:        ogabbay@kernel.org
 Description:    Displays the device's module id
 
+What:           /sys/class/accel/accel<n>/device/parent_device
+Date:           Nov 2023
+KernelVersion:  6.8
+Contact:        ttayar@habana.ai
+Description:    Displays the name of the parent device of the accel device
+
 What:           /sys/class/accel/accel<n>/device/pci_addr
 Date:           Jan 2019
 KernelVersion:  5.1
index dd3fe3ddc00a6257102a845e19364cb4b94624f1..2a900c9941fee698fe225962de6f7e5715b7fee4 100644 (file)
@@ -3521,6 +3521,9 @@ struct hl_device {
        u8                              heartbeat;
 };
 
+/* Retrieve PCI device name in case of a PCI device or dev name in simulator */
+#define HL_DEV_NAME(hdev)      \
+               ((hdev)->pdev ? dev_name(&(hdev)->pdev->dev) : "NA-DEVICE")
 
 /**
  * struct hl_cs_encaps_sig_handle - encapsulated signals handle structure
index c940c5f1d109eb52ccaf5a471be0c62e01ee51b4..8a9f9883215765b0dab610960358156ff87af8ae 100644 (file)
@@ -410,6 +410,13 @@ static ssize_t module_id_show(struct device *dev,
        return sprintf(buf, "%u\n", le32_to_cpu(hdev->asic_prop.cpucp_info.card_location));
 }
 
+static ssize_t parent_device_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct hl_device *hdev = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%s\n", HL_DEV_NAME(hdev));
+}
+
 static DEVICE_ATTR_RO(armcp_kernel_ver);
 static DEVICE_ATTR_RO(armcp_ver);
 static DEVICE_ATTR_RO(cpld_ver);
@@ -430,6 +437,7 @@ static DEVICE_ATTR_RO(uboot_ver);
 static DEVICE_ATTR_RO(fw_os_ver);
 static DEVICE_ATTR_RO(security_enabled);
 static DEVICE_ATTR_RO(module_id);
+static DEVICE_ATTR_RO(parent_device);
 
 static struct bin_attribute bin_attr_eeprom = {
        .attr = {.name = "eeprom", .mode = (0444)},
@@ -456,6 +464,7 @@ static struct attribute *hl_dev_attrs[] = {
        &dev_attr_fw_os_ver.attr,
        &dev_attr_security_enabled.attr,
        &dev_attr_module_id.attr,
+       &dev_attr_parent_device.attr,
        NULL,
 };