drm/amdgpu: Add more FRU field information
authorLijo Lazar <lijo.lazar@amd.com>
Wed, 4 Oct 2023 13:02:02 +0000 (18:32 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 9 Oct 2023 20:52:17 +0000 (16:52 -0400)
Add support to read Manufacturer Name and FRU File Id fields. Also add
sysfs device attributes for external usage.

Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c
drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.h

index 79ba74dfc5764c7591953c393e08d211e2722ce1..5d627d0e19a431ec32b663b72997f187aa86fda9 100644 (file)
@@ -200,10 +200,19 @@ int amdgpu_fru_get_product_info(struct amdgpu_device *adev)
 
        /* Now extract useful information from the PIA.
         *
-        * Skip the Manufacturer Name at [3] and go directly to
-        * the Product Name field.
+        * Read Manufacturer Name field whose length is [3].
         */
-       addr = 3 + 1 + (pia[3] & 0x3F);
+       addr = 3;
+       if (addr + 1 >= len)
+               goto Out;
+       memcpy(fru_info->manufacturer_name, pia + addr + 1,
+              min_t(size_t, sizeof(fru_info->manufacturer_name),
+                    pia[addr] & 0x3F));
+       fru_info->manufacturer_name[sizeof(fru_info->manufacturer_name) - 1] =
+               '\0';
+
+       /* Read Product Name field. */
+       addr += 1 + (pia[addr] & 0x3F);
        if (addr + 1 >= len)
                goto Out;
        memcpy(fru_info->product_name, pia + addr + 1,
@@ -229,6 +238,18 @@ int amdgpu_fru_get_product_info(struct amdgpu_device *adev)
        memcpy(fru_info->serial, pia + addr + 1,
               min_t(size_t, sizeof(fru_info->serial), pia[addr] & 0x3F));
        fru_info->serial[sizeof(fru_info->serial) - 1] = '\0';
+
+       /* Asset Tag field */
+       addr += 1 + (pia[addr] & 0x3F);
+
+       /* FRU File Id field. This could be 'null'. */
+       addr += 1 + (pia[addr] & 0x3F);
+       if ((addr + 1 >= len) || !(pia[addr] & 0x3F))
+               goto Out;
+       memcpy(fru_info->fru_id, pia + addr + 1,
+              min_t(size_t, sizeof(fru_info->fru_id), pia[addr] & 0x3F));
+       fru_info->fru_id[sizeof(fru_info->fru_id) - 1] = '\0';
+
 Out:
        kfree(pia);
        return 0;
@@ -300,10 +321,35 @@ static ssize_t amdgpu_fru_serial_number_show(struct device *dev,
 
 static DEVICE_ATTR(serial_number, 0444, amdgpu_fru_serial_number_show, NULL);
 
+static ssize_t amdgpu_fru_id_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+       struct drm_device *ddev = dev_get_drvdata(dev);
+       struct amdgpu_device *adev = drm_to_adev(ddev);
+
+       return sysfs_emit(buf, "%s\n", adev->fru_info->fru_id);
+}
+
+static DEVICE_ATTR(fru_id, 0444, amdgpu_fru_id_show, NULL);
+
+static ssize_t amdgpu_fru_manufacturer_name_show(struct device *dev,
+                                                struct device_attribute *attr,
+                                                char *buf)
+{
+       struct drm_device *ddev = dev_get_drvdata(dev);
+       struct amdgpu_device *adev = drm_to_adev(ddev);
+
+       return sysfs_emit(buf, "%s\n", adev->fru_info->manufacturer_name);
+}
+
+static DEVICE_ATTR(manufacturer, 0444, amdgpu_fru_manufacturer_name_show, NULL);
+
 static const struct attribute *amdgpu_fru_attributes[] = {
        &dev_attr_product_name.attr,
        &dev_attr_product_number.attr,
        &dev_attr_serial_number.attr,
+       &dev_attr_fru_id.attr,
+       &dev_attr_manufacturer.attr,
        NULL
 };
 
index c99c74811c78a3af1b315f554f2b80d10f4f7613..bc58dca18035a1f3fbe22aa43594ab74cd34cd38 100644 (file)
@@ -31,6 +31,8 @@ struct amdgpu_fru_info {
        char                            product_number[20];
        char                            product_name[AMDGPU_PRODUCT_NAME_LEN];
        char                            serial[20];
+       char                            manufacturer_name[32];
+       char                            fru_id[32];
 };
 
 int amdgpu_fru_get_product_info(struct amdgpu_device *adev);