Skip to content

Commit aa5cea3

Browse files
Tomer Tayarogabbay
authored andcommitted
accel/habanalabs: add parent_device sysfs attribute
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>
1 parent cf0719a commit aa5cea3

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Documentation/ABI/testing/sysfs-driver-habanalabs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ KernelVersion: not yet upstreamed
155155
Contact: ogabbay@kernel.org
156156
Description: Displays the device's module id
157157

158+
What: /sys/class/accel/accel<n>/device/parent_device
159+
Date: Nov 2023
160+
KernelVersion: 6.8
161+
Contact: ttayar@habana.ai
162+
Description: Displays the name of the parent device of the accel device
163+
158164
What: /sys/class/accel/accel<n>/device/pci_addr
159165
Date: Jan 2019
160166
KernelVersion: 5.1

drivers/accel/habanalabs/common/habanalabs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,6 +3521,9 @@ struct hl_device {
35213521
u8 heartbeat;
35223522
};
35233523

3524+
/* Retrieve PCI device name in case of a PCI device or dev name in simulator */
3525+
#define HL_DEV_NAME(hdev) \
3526+
((hdev)->pdev ? dev_name(&(hdev)->pdev->dev) : "NA-DEVICE")
35243527

35253528
/**
35263529
* struct hl_cs_encaps_sig_handle - encapsulated signals handle structure

drivers/accel/habanalabs/common/sysfs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,13 @@ static ssize_t module_id_show(struct device *dev,
410410
return sprintf(buf, "%u\n", le32_to_cpu(hdev->asic_prop.cpucp_info.card_location));
411411
}
412412

413+
static ssize_t parent_device_show(struct device *dev, struct device_attribute *attr, char *buf)
414+
{
415+
struct hl_device *hdev = dev_get_drvdata(dev);
416+
417+
return sprintf(buf, "%s\n", HL_DEV_NAME(hdev));
418+
}
419+
413420
static DEVICE_ATTR_RO(armcp_kernel_ver);
414421
static DEVICE_ATTR_RO(armcp_ver);
415422
static DEVICE_ATTR_RO(cpld_ver);
@@ -430,6 +437,7 @@ static DEVICE_ATTR_RO(uboot_ver);
430437
static DEVICE_ATTR_RO(fw_os_ver);
431438
static DEVICE_ATTR_RO(security_enabled);
432439
static DEVICE_ATTR_RO(module_id);
440+
static DEVICE_ATTR_RO(parent_device);
433441

434442
static struct bin_attribute bin_attr_eeprom = {
435443
.attr = {.name = "eeprom", .mode = (0444)},
@@ -456,6 +464,7 @@ static struct attribute *hl_dev_attrs[] = {
456464
&dev_attr_fw_os_ver.attr,
457465
&dev_attr_security_enabled.attr,
458466
&dev_attr_module_id.attr,
467+
&dev_attr_parent_device.attr,
459468
NULL,
460469
};
461470

0 commit comments

Comments
 (0)