|
29 | 29 |
|
30 | 30 | #define EEPROM_I2C_TARGET_ADDR_ARCTURUS 0xA8 |
31 | 31 | #define EEPROM_I2C_TARGET_ADDR_VEGA20 0xA0 |
| 32 | +#define EEPROM_I2C_PI_ADDR 0xAC |
| 33 | +#define I2C_PRODUCT_INFO_OFFSET 0xC0 |
32 | 34 |
|
33 | 35 | /* |
34 | 36 | * The 2 macros bellow represent the actual size in bytes that |
@@ -79,6 +81,155 @@ static void __decode_table_header_from_buff(struct amdgpu_ras_eeprom_table_heade |
79 | 81 | hdr->checksum = le32_to_cpu(pp[4]); |
80 | 82 | } |
81 | 83 |
|
| 84 | +static int amdgpu_ras_eeprom_get_product_info(struct amdgpu_ras_eeprom_control *control) |
| 85 | +{ |
| 86 | + int ret = 0, i, addrptr = 0, size = 0; |
| 87 | + struct amdgpu_device *adev = to_amdgpu_device(control); |
| 88 | + unsigned char buff[34], sizebuff[3]; |
| 89 | + /* size_msg will be the message to get the size of a field, |
| 90 | + * since it's always 1 for field length |
| 91 | + */ |
| 92 | + struct i2c_msg size_msg = { |
| 93 | + .addr = EEPROM_I2C_PI_ADDR, |
| 94 | + .flags = I2C_M_RD, |
| 95 | + .len = EEPROM_ADDRESS_SIZE + 1, |
| 96 | + .buf = sizebuff, |
| 97 | + }; |
| 98 | + |
| 99 | + /* Add the size obtained above to .len as required */ |
| 100 | + struct i2c_msg msg = { |
| 101 | + .addr = EEPROM_I2C_PI_ADDR, |
| 102 | + .flags = I2C_M_RD, |
| 103 | + .len = EEPROM_ADDRESS_SIZE, |
| 104 | + .buf = buff, |
| 105 | + }; |
| 106 | + |
| 107 | + /* Not supported before VG20 */ |
| 108 | + if (adev->asic_type < CHIP_VEGA20) |
| 109 | + return 0; |
| 110 | + |
| 111 | + /* There's a lot of repetition here. This is due to the FRU having |
| 112 | + * variable-length fields. To get the information, we have to find the |
| 113 | + * size of each field, and then keep reading along and reading along |
| 114 | + * until we get all of the data that we want. We use addrptr to track |
| 115 | + * the address as we go, while we create 2 i2c messages, one to obtain |
| 116 | + * size (since that's always 1-byte, and one to get the data. |
| 117 | + * |
| 118 | + * The size returned by the i2c requires subtraction of 0xC0 since the |
| 119 | + * size apparently always reports as 0xC0+actual size. |
| 120 | + * |
| 121 | + * NOTE: We don't lock the mutex since this data is ummutable |
| 122 | + */ |
| 123 | + |
| 124 | + /* The first fields are all of size 1-byte, from 0-7 are offsets that |
| 125 | + * aren't entirely useful. Bytes 8-e are all 1-byte and refer to the |
| 126 | + * size of the entire struct, and the language field, so just start |
| 127 | + * from 0xf, which is the size of the manufacturer |
| 128 | + */ |
| 129 | + addrptr = 0xf; |
| 130 | + |
| 131 | + /* The i2c message reads the address from the buffer passed in */ |
| 132 | + sizebuff[0] = 0; |
| 133 | + sizebuff[1] = 0xf; |
| 134 | + |
| 135 | + ret = i2c_transfer(&control->eeprom_accessor, &size_msg, 1); |
| 136 | + |
| 137 | + if (ret < 1) { |
| 138 | + DRM_ERROR("Failed to read EEPROM manufacturer size, ret:%d", ret); |
| 139 | + return ret; |
| 140 | + } |
| 141 | + |
| 142 | + size = sizebuff[2] - I2C_PRODUCT_INFO_OFFSET; |
| 143 | + msg.len = EEPROM_ADDRESS_SIZE + size; |
| 144 | + /* Add 1 since address field was 1 byte */ |
| 145 | + addrptr += 1; |
| 146 | + /* Now fill in the actual buffer with the desired address */ |
| 147 | + buff[0] = 0; |
| 148 | + buff[1] = addrptr; |
| 149 | + ret = i2c_transfer(&control->eeprom_accessor, &msg, 1); |
| 150 | + |
| 151 | + if (ret < 1) { |
| 152 | + DRM_ERROR("Failed to read EEPROM product name, ret:%d", ret); |
| 153 | + return ret; |
| 154 | + } |
| 155 | + memcpy(adev->product_name, &buff[2], size); |
| 156 | + adev->product_name[size] = '\0'; |
| 157 | + |
| 158 | + /* Increase the addrptr by the appropriate size */ |
| 159 | + addrptr += size; |
| 160 | + |
| 161 | + /* Get the next field, product name, starting with size */ |
| 162 | + sizebuff[0] = 0; |
| 163 | + sizebuff[1] = addrptr; |
| 164 | + |
| 165 | + ret = i2c_transfer(&control->eeprom_accessor, &size_msg, 1); |
| 166 | + |
| 167 | + if (ret < 1) { |
| 168 | + DRM_ERROR("Failed to read EEPROM product number size, ret:%d", ret); |
| 169 | + return ret; |
| 170 | + } |
| 171 | + |
| 172 | + size = sizebuff[2] - I2C_PRODUCT_INFO_OFFSET; |
| 173 | + msg.len = EEPROM_ADDRESS_SIZE + size; |
| 174 | + /* Add 1 since address field was 1 byte */ |
| 175 | + addrptr += 1; |
| 176 | + buff[0] = 0; |
| 177 | + buff[1] = addrptr; |
| 178 | + |
| 179 | + ret = i2c_transfer(&control->eeprom_accessor, &msg, 1); |
| 180 | + |
| 181 | + if (ret < 1) { |
| 182 | + DRM_ERROR("Failed to read EEPROM product number, ret:%d", ret); |
| 183 | + return ret; |
| 184 | + } |
| 185 | + memcpy(adev->product_number, &buff[2], size); |
| 186 | + adev->product_number[size] = '\0'; |
| 187 | + |
| 188 | + /* Increase the addrptr by the appropriate size */ |
| 189 | + addrptr += size; |
| 190 | + |
| 191 | + /* Skip over the Product Version, it's not very useful */ |
| 192 | + sizebuff[0] = 0; |
| 193 | + sizebuff[1] = addrptr; |
| 194 | + |
| 195 | + ret = i2c_transfer(&control->eeprom_accessor, &size_msg, 1); |
| 196 | + |
| 197 | + if (ret < 1) { |
| 198 | + DRM_ERROR("Failed to read EEPROM product version size, ret:%d", ret); |
| 199 | + return ret; |
| 200 | + } |
| 201 | + size = sizebuff[2] - I2C_PRODUCT_INFO_OFFSET; |
| 202 | + /* Add 1 since address field was 1 byte, plus the size of the version */ |
| 203 | + addrptr += size + 1; |
| 204 | + |
| 205 | + /* Get the last field, serial number */ |
| 206 | + sizebuff[0] = 0; |
| 207 | + sizebuff[1] = addrptr; |
| 208 | + |
| 209 | + ret = i2c_transfer(&control->eeprom_accessor, &size_msg, 1); |
| 210 | + |
| 211 | + if (ret < 1) { |
| 212 | + DRM_ERROR("Failed to read EEPROM serial number size, ret:%d", ret); |
| 213 | + return ret; |
| 214 | + } |
| 215 | + size = sizebuff[2] - I2C_PRODUCT_INFO_OFFSET; |
| 216 | + msg.len = EEPROM_ADDRESS_SIZE + size; |
| 217 | + /* Add 1 since address field was 1 byte */ |
| 218 | + addrptr += 1; |
| 219 | + buff[0] = 0; |
| 220 | + buff[1] = addrptr; |
| 221 | + ret = i2c_transfer(&control->eeprom_accessor, &msg, 1); |
| 222 | + |
| 223 | + if (ret < 1) { |
| 224 | + DRM_ERROR("Failed to read EEPROM serial info, ret:%d", ret); |
| 225 | + return ret; |
| 226 | + } |
| 227 | + memcpy(adev->serial, &buff[2], size); |
| 228 | + adev->serial[size] = '\0'; |
| 229 | + |
| 230 | + return 0; |
| 231 | +} |
| 232 | + |
82 | 233 | static int __update_table_header(struct amdgpu_ras_eeprom_control *control, |
83 | 234 | unsigned char *buff) |
84 | 235 | { |
@@ -260,6 +411,8 @@ int amdgpu_ras_eeprom_init(struct amdgpu_ras_eeprom_control *control) |
260 | 411 | ret = amdgpu_ras_eeprom_reset_table(control); |
261 | 412 | } |
262 | 413 |
|
| 414 | + amdgpu_ras_eeprom_get_product_info(control); |
| 415 | + |
263 | 416 | return ret == 1 ? 0 : -EIO; |
264 | 417 | } |
265 | 418 |
|
|
0 commit comments