xref: /linux/drivers/gpu/drm/amd/amdgpu/amdgpu_fru_eeprom.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1bd607166SKent Russell /*
2bd607166SKent Russell  * Copyright 2019 Advanced Micro Devices, Inc.
3bd607166SKent Russell  *
4bd607166SKent Russell  * Permission is hereby granted, free of charge, to any person obtaining a
5bd607166SKent Russell  * copy of this software and associated documentation files (the "Software"),
6bd607166SKent Russell  * to deal in the Software without restriction, including without limitation
7bd607166SKent Russell  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bd607166SKent Russell  * and/or sell copies of the Software, and to permit persons to whom the
9bd607166SKent Russell  * Software is furnished to do so, subject to the following conditions:
10bd607166SKent Russell  *
11bd607166SKent Russell  * The above copyright notice and this permission notice shall be included in
12bd607166SKent Russell  * all copies or substantial portions of the Software.
13bd607166SKent Russell  *
14bd607166SKent Russell  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15bd607166SKent Russell  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16bd607166SKent Russell  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17bd607166SKent Russell  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18bd607166SKent Russell  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19bd607166SKent Russell  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20bd607166SKent Russell  * OTHER DEALINGS IN THE SOFTWARE.
21bd607166SKent Russell  *
22bd607166SKent Russell  */
231ea2b260SKent Russell #include <linux/pci.h>
241ea2b260SKent Russell 
25bd607166SKent Russell #include "amdgpu.h"
26bd607166SKent Russell #include "amdgpu_i2c.h"
27bd607166SKent Russell #include "smu_v11_0_i2c.h"
28bd607166SKent Russell #include "atom.h"
29d43f7ff6SAlex Deucher #include "amdgpu_fru_eeprom.h"
3025e5c09fSAlex Deucher #include "amdgpu_eeprom.h"
31bd607166SKent Russell 
32afbe5d1eSLuben Tuikov #define FRU_EEPROM_MADDR_6      0x60000
33afbe5d1eSLuben Tuikov #define FRU_EEPROM_MADDR_8      0x80000
34bd607166SKent Russell 
is_fru_eeprom_supported(struct amdgpu_device * adev,u32 * fru_addr)35afbe5d1eSLuben Tuikov static bool is_fru_eeprom_supported(struct amdgpu_device *adev, u32 *fru_addr)
36fabe01d7SJohn Clements {
37f94582e4SKent Russell 	/* Only server cards have the FRU EEPROM
38f94582e4SKent Russell 	 * TODO: See if we can figure this out dynamically instead of
39f94582e4SKent Russell 	 * having to parse VBIOS versions.
401ea2b260SKent Russell 	 */
41f94582e4SKent Russell 	struct atom_context *atom_ctx = adev->mode_info.atom_context;
42f94582e4SKent Russell 
43901abf36Sshaoyunl 	/* The i2c access is blocked on VF
44901abf36Sshaoyunl 	 * TODO: Need other way to get the info
45a8558fceSLijo Lazar 	 * Also, FRU not valid for APU devices.
46901abf36Sshaoyunl 	 */
47a8558fceSLijo Lazar 	if (amdgpu_sriov_vf(adev) || (adev->flags & AMD_IS_APU))
48901abf36Sshaoyunl 		return false;
49901abf36Sshaoyunl 
50afbe5d1eSLuben Tuikov 	/* The default I2C EEPROM address of the FRU.
51afbe5d1eSLuben Tuikov 	 */
52afbe5d1eSLuben Tuikov 	if (fru_addr)
53afbe5d1eSLuben Tuikov 		*fru_addr = FRU_EEPROM_MADDR_8;
54afbe5d1eSLuben Tuikov 
553ed89339SLuben Tuikov 	/* VBIOS is of the format ###-DXXXYYYY-##. For SKU identification,
56f94582e4SKent Russell 	 * we can use just the "DXXX" portion. If there were more models, we
57f94582e4SKent Russell 	 * could convert the 3 characters to a hex integer and use a switch
58f94582e4SKent Russell 	 * for ease/speed/readability. For now, 2 string comparisons are
59f94582e4SKent Russell 	 * reasonable and not too expensive
60f94582e4SKent Russell 	 */
61be2e8acaSYang Wang 	switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
62be2e8acaSYang Wang 	case IP_VERSION(11, 0, 2):
63f94582e4SKent Russell 		switch (adev->asic_type) {
64f94582e4SKent Russell 		case CHIP_VEGA20:
65f94582e4SKent Russell 			/* D161 and D163 are the VG20 server SKUs */
66adf64e21SMario Limonciello 			if (strnstr(atom_ctx->vbios_pn, "D161",
67adf64e21SMario Limonciello 				    sizeof(atom_ctx->vbios_pn)) ||
68adf64e21SMario Limonciello 			    strnstr(atom_ctx->vbios_pn, "D163",
69adf64e21SMario Limonciello 				    sizeof(atom_ctx->vbios_pn))) {
7028afcb0aSLuben Tuikov 				if (fru_addr)
71afbe5d1eSLuben Tuikov 					*fru_addr = FRU_EEPROM_MADDR_6;
721ea2b260SKent Russell 				return true;
73afbe5d1eSLuben Tuikov 			} else {
74fabe01d7SJohn Clements 				return false;
75afbe5d1eSLuben Tuikov 			}
76be2e8acaSYang Wang 		case CHIP_ARCTURUS:
77be2e8acaSYang Wang 		default:
78be2e8acaSYang Wang 			return false;
79be2e8acaSYang Wang 		}
80be2e8acaSYang Wang 	case IP_VERSION(11, 0, 7):
81adf64e21SMario Limonciello 		if (strnstr(atom_ctx->vbios_pn, "D603",
82adf64e21SMario Limonciello 			    sizeof(atom_ctx->vbios_pn))) {
83adf64e21SMario Limonciello 			if (strnstr(atom_ctx->vbios_pn, "D603GLXE",
84adf64e21SMario Limonciello 				    sizeof(atom_ctx->vbios_pn))) {
853ed89339SLuben Tuikov 				return false;
86ce83aa7bSSrinivasan Shanmugam 			}
87ce83aa7bSSrinivasan Shanmugam 
8828afcb0aSLuben Tuikov 			if (fru_addr)
89afbe5d1eSLuben Tuikov 				*fru_addr = FRU_EEPROM_MADDR_6;
90c8fea927SGuchun Chen 			return true;
91ce83aa7bSSrinivasan Shanmugam 
92c8fea927SGuchun Chen 		} else {
93c8fea927SGuchun Chen 			return false;
94c8fea927SGuchun Chen 		}
95be2e8acaSYang Wang 	case IP_VERSION(13, 0, 2):
96be2e8acaSYang Wang 		/* All Aldebaran SKUs have an FRU */
97be2e8acaSYang Wang 		if (!strnstr(atom_ctx->vbios_pn, "D673",
98be2e8acaSYang Wang 			     sizeof(atom_ctx->vbios_pn)))
99be2e8acaSYang Wang 			if (fru_addr)
100be2e8acaSYang Wang 				*fru_addr = FRU_EEPROM_MADDR_6;
101be2e8acaSYang Wang 		return true;
102be2e8acaSYang Wang 	case IP_VERSION(13, 0, 6):
103*a6bcffa5SHawking Zhang 	case IP_VERSION(13, 0, 14):
104be2e8acaSYang Wang 			if (fru_addr)
105be2e8acaSYang Wang 				*fru_addr = FRU_EEPROM_MADDR_8;
106be2e8acaSYang Wang 			return true;
107f94582e4SKent Russell 	default:
108f94582e4SKent Russell 		return false;
109f94582e4SKent Russell 	}
110fabe01d7SJohn Clements }
111fabe01d7SJohn Clements 
amdgpu_fru_get_product_info(struct amdgpu_device * adev)112bd607166SKent Russell int amdgpu_fru_get_product_info(struct amdgpu_device *adev)
113bd607166SKent Russell {
1148a2b5139SLijo Lazar 	struct amdgpu_fru_info *fru_info;
1150dbf2c56SLuben Tuikov 	unsigned char buf[8], *pia;
1160dbf2c56SLuben Tuikov 	u32 addr, fru_addr;
117ccdfbfecSLuben Tuikov 	int size, len;
1180dbf2c56SLuben Tuikov 	u8 csum;
119bd607166SKent Russell 
120afbe5d1eSLuben Tuikov 	if (!is_fru_eeprom_supported(adev, &fru_addr))
121fabe01d7SJohn Clements 		return 0;
122fabe01d7SJohn Clements 
1238a2b5139SLijo Lazar 	if (!adev->fru_info) {
1248a2b5139SLijo Lazar 		adev->fru_info = kzalloc(sizeof(*adev->fru_info), GFP_KERNEL);
1258a2b5139SLijo Lazar 		if (!adev->fru_info)
1268a2b5139SLijo Lazar 			return -ENOMEM;
1278a2b5139SLijo Lazar 	}
1288a2b5139SLijo Lazar 
1298a2b5139SLijo Lazar 	fru_info = adev->fru_info;
1308a2b5139SLijo Lazar 	/* For Arcturus-and-later, default value of serial_number is unique_id
1318a2b5139SLijo Lazar 	 * so convert it to a 16-digit HEX string for convenience and
1328a2b5139SLijo Lazar 	 * backwards-compatibility.
1338a2b5139SLijo Lazar 	 */
1348a2b5139SLijo Lazar 	sprintf(fru_info->serial, "%llx", adev->unique_id);
1358a2b5139SLijo Lazar 
136bd607166SKent Russell 	/* If algo exists, it means that the i2c_adapter's initialized */
1372f60dd50SLuben Tuikov 	if (!adev->pm.fru_eeprom_i2c_bus || !adev->pm.fru_eeprom_i2c_bus->algo) {
138bd607166SKent Russell 		DRM_WARN("Cannot access FRU, EEPROM accessor not initialized");
13902b865f8SJiansong Chen 		return -ENODEV;
140bd607166SKent Russell 	}
141bd607166SKent Russell 
1420dbf2c56SLuben Tuikov 	/* Read the IPMI Common header */
1430dbf2c56SLuben Tuikov 	len = amdgpu_eeprom_read(adev->pm.fru_eeprom_i2c_bus, fru_addr, buf,
1440dbf2c56SLuben Tuikov 				 sizeof(buf));
1450dbf2c56SLuben Tuikov 	if (len != 8) {
1460dbf2c56SLuben Tuikov 		DRM_ERROR("Couldn't read the IPMI Common Header: %d", len);
1470dbf2c56SLuben Tuikov 		return len < 0 ? len : -EIO;
1480dbf2c56SLuben Tuikov 	}
1490dbf2c56SLuben Tuikov 
1500dbf2c56SLuben Tuikov 	if (buf[0] != 1) {
1510dbf2c56SLuben Tuikov 		DRM_ERROR("Bad IPMI Common Header version: 0x%02x", buf[0]);
1520dbf2c56SLuben Tuikov 		return -EIO;
1530dbf2c56SLuben Tuikov 	}
1540dbf2c56SLuben Tuikov 
1550dbf2c56SLuben Tuikov 	for (csum = 0; len > 0; len--)
1560dbf2c56SLuben Tuikov 		csum += buf[len - 1];
1570dbf2c56SLuben Tuikov 	if (csum) {
1580dbf2c56SLuben Tuikov 		DRM_ERROR("Bad IPMI Common Header checksum: 0x%02x", csum);
1590dbf2c56SLuben Tuikov 		return -EIO;
1600dbf2c56SLuben Tuikov 	}
1610dbf2c56SLuben Tuikov 
1620dbf2c56SLuben Tuikov 	/* Get the offset to the Product Info Area (PIA). */
1630dbf2c56SLuben Tuikov 	addr = buf[4] * 8;
1640dbf2c56SLuben Tuikov 	if (!addr)
1650dbf2c56SLuben Tuikov 		return 0;
1660dbf2c56SLuben Tuikov 
1670dbf2c56SLuben Tuikov 	/* Get the absolute address to the PIA. */
1680dbf2c56SLuben Tuikov 	addr += fru_addr;
1690dbf2c56SLuben Tuikov 
1700dbf2c56SLuben Tuikov 	/* Read the header of the PIA. */
1710dbf2c56SLuben Tuikov 	len = amdgpu_eeprom_read(adev->pm.fru_eeprom_i2c_bus, addr, buf, 3);
1720dbf2c56SLuben Tuikov 	if (len != 3) {
1730dbf2c56SLuben Tuikov 		DRM_ERROR("Couldn't read the Product Info Area header: %d", len);
1740dbf2c56SLuben Tuikov 		return len < 0 ? len : -EIO;
1750dbf2c56SLuben Tuikov 	}
1760dbf2c56SLuben Tuikov 
1770dbf2c56SLuben Tuikov 	if (buf[0] != 1) {
1780dbf2c56SLuben Tuikov 		DRM_ERROR("Bad IPMI Product Info Area version: 0x%02x", buf[0]);
1790dbf2c56SLuben Tuikov 		return -EIO;
1800dbf2c56SLuben Tuikov 	}
1810dbf2c56SLuben Tuikov 
1820dbf2c56SLuben Tuikov 	size = buf[1] * 8;
1830dbf2c56SLuben Tuikov 	pia = kzalloc(size, GFP_KERNEL);
1840dbf2c56SLuben Tuikov 	if (!pia)
1850dbf2c56SLuben Tuikov 		return -ENOMEM;
1860dbf2c56SLuben Tuikov 
1870dbf2c56SLuben Tuikov 	/* Read the whole PIA. */
1880dbf2c56SLuben Tuikov 	len = amdgpu_eeprom_read(adev->pm.fru_eeprom_i2c_bus, addr, pia, size);
1890dbf2c56SLuben Tuikov 	if (len != size) {
1900dbf2c56SLuben Tuikov 		kfree(pia);
1910dbf2c56SLuben Tuikov 		DRM_ERROR("Couldn't read the Product Info Area: %d", len);
1920dbf2c56SLuben Tuikov 		return len < 0 ? len : -EIO;
1930dbf2c56SLuben Tuikov 	}
1940dbf2c56SLuben Tuikov 
1950dbf2c56SLuben Tuikov 	for (csum = 0; size > 0; size--)
1960dbf2c56SLuben Tuikov 		csum += pia[size - 1];
1970dbf2c56SLuben Tuikov 	if (csum) {
1980dbf2c56SLuben Tuikov 		DRM_ERROR("Bad Product Info Area checksum: 0x%02x", csum);
1999ed630c5SLuben Tuikov 		kfree(pia);
2000dbf2c56SLuben Tuikov 		return -EIO;
2010dbf2c56SLuben Tuikov 	}
2020dbf2c56SLuben Tuikov 
2030dbf2c56SLuben Tuikov 	/* Now extract useful information from the PIA.
2040dbf2c56SLuben Tuikov 	 *
205ac6b1f27SLijo Lazar 	 * Read Manufacturer Name field whose length is [3].
206bd607166SKent Russell 	 */
207ac6b1f27SLijo Lazar 	addr = 3;
208ac6b1f27SLijo Lazar 	if (addr + 1 >= len)
209ac6b1f27SLijo Lazar 		goto Out;
210ac6b1f27SLijo Lazar 	memcpy(fru_info->manufacturer_name, pia + addr + 1,
211ac6b1f27SLijo Lazar 	       min_t(size_t, sizeof(fru_info->manufacturer_name),
212ac6b1f27SLijo Lazar 		     pia[addr] & 0x3F));
213ac6b1f27SLijo Lazar 	fru_info->manufacturer_name[sizeof(fru_info->manufacturer_name) - 1] =
214ac6b1f27SLijo Lazar 		'\0';
215ac6b1f27SLijo Lazar 
216ac6b1f27SLijo Lazar 	/* Read Product Name field. */
217ac6b1f27SLijo Lazar 	addr += 1 + (pia[addr] & 0x3F);
2180dbf2c56SLuben Tuikov 	if (addr + 1 >= len)
2190dbf2c56SLuben Tuikov 		goto Out;
2208a2b5139SLijo Lazar 	memcpy(fru_info->product_name, pia + addr + 1,
2218a2b5139SLijo Lazar 	       min_t(size_t, sizeof(fru_info->product_name), pia[addr] & 0x3F));
2228a2b5139SLijo Lazar 	fru_info->product_name[sizeof(fru_info->product_name) - 1] = '\0';
223bd607166SKent Russell 
2240dbf2c56SLuben Tuikov 	/* Go to the Product Part/Model Number field. */
2250dbf2c56SLuben Tuikov 	addr += 1 + (pia[addr] & 0x3F);
2260dbf2c56SLuben Tuikov 	if (addr + 1 >= len)
2270dbf2c56SLuben Tuikov 		goto Out;
2288a2b5139SLijo Lazar 	memcpy(fru_info->product_number, pia + addr + 1,
2298a2b5139SLijo Lazar 	       min_t(size_t, sizeof(fru_info->product_number),
2300dbf2c56SLuben Tuikov 		     pia[addr] & 0x3F));
2318a2b5139SLijo Lazar 	fru_info->product_number[sizeof(fru_info->product_number) - 1] = '\0';
232bd607166SKent Russell 
2330dbf2c56SLuben Tuikov 	/* Go to the Product Version field. */
2340dbf2c56SLuben Tuikov 	addr += 1 + (pia[addr] & 0x3F);
235bd607166SKent Russell 
2360dbf2c56SLuben Tuikov 	/* Go to the Product Serial Number field. */
2370dbf2c56SLuben Tuikov 	addr += 1 + (pia[addr] & 0x3F);
2380dbf2c56SLuben Tuikov 	if (addr + 1 >= len)
2390dbf2c56SLuben Tuikov 		goto Out;
2408a2b5139SLijo Lazar 	memcpy(fru_info->serial, pia + addr + 1,
2418a2b5139SLijo Lazar 	       min_t(size_t, sizeof(fru_info->serial), pia[addr] & 0x3F));
2428a2b5139SLijo Lazar 	fru_info->serial[sizeof(fru_info->serial) - 1] = '\0';
243ac6b1f27SLijo Lazar 
244ac6b1f27SLijo Lazar 	/* Asset Tag field */
245ac6b1f27SLijo Lazar 	addr += 1 + (pia[addr] & 0x3F);
246ac6b1f27SLijo Lazar 
247ac6b1f27SLijo Lazar 	/* FRU File Id field. This could be 'null'. */
248ac6b1f27SLijo Lazar 	addr += 1 + (pia[addr] & 0x3F);
249ac6b1f27SLijo Lazar 	if ((addr + 1 >= len) || !(pia[addr] & 0x3F))
250ac6b1f27SLijo Lazar 		goto Out;
251ac6b1f27SLijo Lazar 	memcpy(fru_info->fru_id, pia + addr + 1,
252ac6b1f27SLijo Lazar 	       min_t(size_t, sizeof(fru_info->fru_id), pia[addr] & 0x3F));
253ac6b1f27SLijo Lazar 	fru_info->fru_id[sizeof(fru_info->fru_id) - 1] = '\0';
254ac6b1f27SLijo Lazar 
2550dbf2c56SLuben Tuikov Out:
2560dbf2c56SLuben Tuikov 	kfree(pia);
257bd607166SKent Russell 	return 0;
258bd607166SKent Russell }
2597957ec80SLijo Lazar 
2607957ec80SLijo Lazar /**
2617957ec80SLijo Lazar  * DOC: product_name
2627957ec80SLijo Lazar  *
2637957ec80SLijo Lazar  * The amdgpu driver provides a sysfs API for reporting the product name
2647957ec80SLijo Lazar  * for the device
2657957ec80SLijo Lazar  * The file product_name is used for this and returns the product name
2667957ec80SLijo Lazar  * as returned from the FRU.
2677957ec80SLijo Lazar  * NOTE: This is only available for certain server cards
2687957ec80SLijo Lazar  */
2697957ec80SLijo Lazar 
amdgpu_fru_product_name_show(struct device * dev,struct device_attribute * attr,char * buf)2707957ec80SLijo Lazar static ssize_t amdgpu_fru_product_name_show(struct device *dev,
2717957ec80SLijo Lazar 					    struct device_attribute *attr,
2727957ec80SLijo Lazar 					    char *buf)
2737957ec80SLijo Lazar {
2747957ec80SLijo Lazar 	struct drm_device *ddev = dev_get_drvdata(dev);
2757957ec80SLijo Lazar 	struct amdgpu_device *adev = drm_to_adev(ddev);
2767957ec80SLijo Lazar 
2778a2b5139SLijo Lazar 	return sysfs_emit(buf, "%s\n", adev->fru_info->product_name);
2787957ec80SLijo Lazar }
2797957ec80SLijo Lazar 
2807957ec80SLijo Lazar static DEVICE_ATTR(product_name, 0444, amdgpu_fru_product_name_show, NULL);
2817957ec80SLijo Lazar 
2827957ec80SLijo Lazar /**
2837957ec80SLijo Lazar  * DOC: product_number
2847957ec80SLijo Lazar  *
2857957ec80SLijo Lazar  * The amdgpu driver provides a sysfs API for reporting the part number
2867957ec80SLijo Lazar  * for the device
2877957ec80SLijo Lazar  * The file product_number is used for this and returns the part number
2887957ec80SLijo Lazar  * as returned from the FRU.
2897957ec80SLijo Lazar  * NOTE: This is only available for certain server cards
2907957ec80SLijo Lazar  */
2917957ec80SLijo Lazar 
amdgpu_fru_product_number_show(struct device * dev,struct device_attribute * attr,char * buf)2927957ec80SLijo Lazar static ssize_t amdgpu_fru_product_number_show(struct device *dev,
2937957ec80SLijo Lazar 					      struct device_attribute *attr,
2947957ec80SLijo Lazar 					      char *buf)
2957957ec80SLijo Lazar {
2967957ec80SLijo Lazar 	struct drm_device *ddev = dev_get_drvdata(dev);
2977957ec80SLijo Lazar 	struct amdgpu_device *adev = drm_to_adev(ddev);
2987957ec80SLijo Lazar 
2998a2b5139SLijo Lazar 	return sysfs_emit(buf, "%s\n", adev->fru_info->product_number);
3007957ec80SLijo Lazar }
3017957ec80SLijo Lazar 
3027957ec80SLijo Lazar static DEVICE_ATTR(product_number, 0444, amdgpu_fru_product_number_show, NULL);
3037957ec80SLijo Lazar 
3047957ec80SLijo Lazar /**
3057957ec80SLijo Lazar  * DOC: serial_number
3067957ec80SLijo Lazar  *
3077957ec80SLijo Lazar  * The amdgpu driver provides a sysfs API for reporting the serial number
3087957ec80SLijo Lazar  * for the device
3097957ec80SLijo Lazar  * The file serial_number is used for this and returns the serial number
3107957ec80SLijo Lazar  * as returned from the FRU.
3117957ec80SLijo Lazar  * NOTE: This is only available for certain server cards
3127957ec80SLijo Lazar  */
3137957ec80SLijo Lazar 
amdgpu_fru_serial_number_show(struct device * dev,struct device_attribute * attr,char * buf)3147957ec80SLijo Lazar static ssize_t amdgpu_fru_serial_number_show(struct device *dev,
3157957ec80SLijo Lazar 					     struct device_attribute *attr,
3167957ec80SLijo Lazar 					     char *buf)
3177957ec80SLijo Lazar {
3187957ec80SLijo Lazar 	struct drm_device *ddev = dev_get_drvdata(dev);
3197957ec80SLijo Lazar 	struct amdgpu_device *adev = drm_to_adev(ddev);
3207957ec80SLijo Lazar 
3218a2b5139SLijo Lazar 	return sysfs_emit(buf, "%s\n", adev->fru_info->serial);
3227957ec80SLijo Lazar }
3237957ec80SLijo Lazar 
3247957ec80SLijo Lazar static DEVICE_ATTR(serial_number, 0444, amdgpu_fru_serial_number_show, NULL);
3257957ec80SLijo Lazar 
326b3e73b5aSLijo Lazar /**
327b3e73b5aSLijo Lazar  * DOC: fru_id
328b3e73b5aSLijo Lazar  *
329b3e73b5aSLijo Lazar  * The amdgpu driver provides a sysfs API for reporting FRU File Id
330b3e73b5aSLijo Lazar  * for the device.
331b3e73b5aSLijo Lazar  * The file fru_id is used for this and returns the File Id value
332b3e73b5aSLijo Lazar  * as returned from the FRU.
333b3e73b5aSLijo Lazar  * NOTE: This is only available for certain server cards
334b3e73b5aSLijo Lazar  */
335b3e73b5aSLijo Lazar 
amdgpu_fru_id_show(struct device * dev,struct device_attribute * attr,char * buf)336ac6b1f27SLijo Lazar static ssize_t amdgpu_fru_id_show(struct device *dev,
337ac6b1f27SLijo Lazar 				  struct device_attribute *attr, char *buf)
338ac6b1f27SLijo Lazar {
339ac6b1f27SLijo Lazar 	struct drm_device *ddev = dev_get_drvdata(dev);
340ac6b1f27SLijo Lazar 	struct amdgpu_device *adev = drm_to_adev(ddev);
341ac6b1f27SLijo Lazar 
342ac6b1f27SLijo Lazar 	return sysfs_emit(buf, "%s\n", adev->fru_info->fru_id);
343ac6b1f27SLijo Lazar }
344ac6b1f27SLijo Lazar 
345ac6b1f27SLijo Lazar static DEVICE_ATTR(fru_id, 0444, amdgpu_fru_id_show, NULL);
346ac6b1f27SLijo Lazar 
347b3e73b5aSLijo Lazar /**
348b3e73b5aSLijo Lazar  * DOC: manufacturer
349b3e73b5aSLijo Lazar  *
350b3e73b5aSLijo Lazar  * The amdgpu driver provides a sysfs API for reporting manufacturer name from
351b3e73b5aSLijo Lazar  * FRU information.
352b3e73b5aSLijo Lazar  * The file manufacturer returns the value as returned from the FRU.
353b3e73b5aSLijo Lazar  * NOTE: This is only available for certain server cards
354b3e73b5aSLijo Lazar  */
355b3e73b5aSLijo Lazar 
amdgpu_fru_manufacturer_name_show(struct device * dev,struct device_attribute * attr,char * buf)356ac6b1f27SLijo Lazar static ssize_t amdgpu_fru_manufacturer_name_show(struct device *dev,
357ac6b1f27SLijo Lazar 						 struct device_attribute *attr,
358ac6b1f27SLijo Lazar 						 char *buf)
359ac6b1f27SLijo Lazar {
360ac6b1f27SLijo Lazar 	struct drm_device *ddev = dev_get_drvdata(dev);
361ac6b1f27SLijo Lazar 	struct amdgpu_device *adev = drm_to_adev(ddev);
362ac6b1f27SLijo Lazar 
363ac6b1f27SLijo Lazar 	return sysfs_emit(buf, "%s\n", adev->fru_info->manufacturer_name);
364ac6b1f27SLijo Lazar }
365ac6b1f27SLijo Lazar 
366ac6b1f27SLijo Lazar static DEVICE_ATTR(manufacturer, 0444, amdgpu_fru_manufacturer_name_show, NULL);
367ac6b1f27SLijo Lazar 
3687957ec80SLijo Lazar static const struct attribute *amdgpu_fru_attributes[] = {
3697957ec80SLijo Lazar 	&dev_attr_product_name.attr,
3707957ec80SLijo Lazar 	&dev_attr_product_number.attr,
3717957ec80SLijo Lazar 	&dev_attr_serial_number.attr,
372ac6b1f27SLijo Lazar 	&dev_attr_fru_id.attr,
373ac6b1f27SLijo Lazar 	&dev_attr_manufacturer.attr,
3747957ec80SLijo Lazar 	NULL
3757957ec80SLijo Lazar };
3767957ec80SLijo Lazar 
amdgpu_fru_sysfs_init(struct amdgpu_device * adev)3777957ec80SLijo Lazar int amdgpu_fru_sysfs_init(struct amdgpu_device *adev)
3787957ec80SLijo Lazar {
3798a2b5139SLijo Lazar 	if (!is_fru_eeprom_supported(adev, NULL) || !adev->fru_info)
3807957ec80SLijo Lazar 		return 0;
3817957ec80SLijo Lazar 
3827957ec80SLijo Lazar 	return sysfs_create_files(&adev->dev->kobj, amdgpu_fru_attributes);
3837957ec80SLijo Lazar }
3847957ec80SLijo Lazar 
amdgpu_fru_sysfs_fini(struct amdgpu_device * adev)3857957ec80SLijo Lazar void amdgpu_fru_sysfs_fini(struct amdgpu_device *adev)
3867957ec80SLijo Lazar {
3878a2b5139SLijo Lazar 	if (!is_fru_eeprom_supported(adev, NULL) || !adev->fru_info)
3887957ec80SLijo Lazar 		return;
3897957ec80SLijo Lazar 
3907957ec80SLijo Lazar 	sysfs_remove_files(&adev->dev->kobj, amdgpu_fru_attributes);
3917957ec80SLijo Lazar }
392