2 * Copyright 2019 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include "amdgpu_ras_eeprom.h"
26 #include "amdgpu_ras.h"
27 #include <linux/bits.h>
29 #include "amdgpu_eeprom.h"
30 #include "amdgpu_atomfirmware.h"
31 #include <linux/debugfs.h>
32 #include <linux/uaccess.h>
34 #include "amdgpu_reset.h"
36 /* These are memory addresses as would be seen by one or more EEPROM
37 * chips strung on the I2C bus, usually by manipulating pins 1-3 of a
38 * set of EEPROM devices. They form a continuous memory space.
40 * The I2C device address includes the device type identifier, 1010b,
41 * which is a reserved value and indicates that this is an I2C EEPROM
42 * device. It also includes the top 3 bits of the 19 bit EEPROM memory
43 * address, namely bits 18, 17, and 16. This makes up the 7 bit
44 * address sent on the I2C bus with bit 0 being the direction bit,
45 * which is not represented here, and sent by the hardware directly.
48 * 50h = 1010000b => device type identifier 1010b, bits 18:16 = 000b, address 0.
49 * 54h = 1010100b => --"--, bits 18:16 = 100b, address 40000h.
50 * 56h = 1010110b => --"--, bits 18:16 = 110b, address 60000h.
51 * Depending on the size of the I2C EEPROM device(s), bits 18:16 may
52 * address memory in a device or a device on the I2C bus, depending on
53 * the status of pins 1-3. See top of amdgpu_eeprom.c.
55 * The RAS table lives either at address 0 or address 40000h of EEPROM.
57 #define EEPROM_I2C_MADDR_0 0x0
58 #define EEPROM_I2C_MADDR_4 0x40000
61 * The 2 macros below represent the actual size in bytes that
62 * those entities occupy in the EEPROM memory.
63 * RAS_TABLE_RECORD_SIZE is different than sizeof(eeprom_table_record) which
64 * uses uint64 to store 6b fields such as retired_page.
66 #define RAS_TABLE_HEADER_SIZE 20
67 #define RAS_TABLE_RECORD_SIZE 24
69 /* Table hdr is 'AMDR' */
70 #define RAS_TABLE_HDR_VAL 0x414d4452
72 /* Bad GPU tag ‘BADG’ */
73 #define RAS_TABLE_HDR_BAD 0x42414447
76 * EEPROM Table structure v1
77 * ---------------------------------
79 * | EEPROM TABLE HEADER |
80 * | ( size 20 Bytes ) |
82 * ---------------------------------
84 * | BAD PAGE RECORD AREA |
86 * ---------------------------------
89 /* Assume 2-Mbit size EEPROM and take up the whole space. */
90 #define RAS_TBL_SIZE_BYTES (256 * 1024)
91 #define RAS_TABLE_START 0
92 #define RAS_HDR_START RAS_TABLE_START
93 #define RAS_RECORD_START (RAS_HDR_START + RAS_TABLE_HEADER_SIZE)
94 #define RAS_MAX_RECORD_COUNT ((RAS_TBL_SIZE_BYTES - RAS_TABLE_HEADER_SIZE) \
95 / RAS_TABLE_RECORD_SIZE)
98 * EEPROM Table structrue v2.1
99 * ---------------------------------
101 * | EEPROM TABLE HEADER |
102 * | ( size 20 Bytes ) |
104 * ---------------------------------
106 * | EEPROM TABLE RAS INFO |
107 * | (available info size 4 Bytes) |
108 * | ( reserved size 252 Bytes ) |
110 * ---------------------------------
112 * | BAD PAGE RECORD AREA |
114 * ---------------------------------
117 /* EEPROM Table V2_1 */
118 #define RAS_TABLE_V2_1_INFO_SIZE 256
119 #define RAS_TABLE_V2_1_INFO_START RAS_TABLE_HEADER_SIZE
120 #define RAS_RECORD_START_V2_1 (RAS_HDR_START + RAS_TABLE_HEADER_SIZE + \
121 RAS_TABLE_V2_1_INFO_SIZE)
122 #define RAS_MAX_RECORD_COUNT_V2_1 ((RAS_TBL_SIZE_BYTES - RAS_TABLE_HEADER_SIZE - \
123 RAS_TABLE_V2_1_INFO_SIZE) \
124 / RAS_TABLE_RECORD_SIZE)
126 /* Given a zero-based index of an EEPROM RAS record, yields the EEPROM
127 * offset off of RAS_TABLE_START. That is, this is something you can
128 * add to control->i2c_address, and then tell I2C layer to read
129 * from/write to there. _N is the so called absolute index,
130 * because it starts right after the table header.
132 #define RAS_INDEX_TO_OFFSET(_C, _N) ((_C)->ras_record_offset + \
133 (_N) * RAS_TABLE_RECORD_SIZE)
135 #define RAS_OFFSET_TO_INDEX(_C, _O) (((_O) - \
136 (_C)->ras_record_offset) / RAS_TABLE_RECORD_SIZE)
138 /* Given a 0-based relative record index, 0, 1, 2, ..., etc., off
139 * of "fri", return the absolute record index off of the end of
142 #define RAS_RI_TO_AI(_C, _I) (((_I) + (_C)->ras_fri) % \
143 (_C)->ras_max_record_count)
145 #define RAS_NUM_RECS(_tbl_hdr) (((_tbl_hdr)->tbl_size - \
146 RAS_TABLE_HEADER_SIZE) / RAS_TABLE_RECORD_SIZE)
148 #define RAS_NUM_RECS_V2_1(_tbl_hdr) (((_tbl_hdr)->tbl_size - \
149 RAS_TABLE_HEADER_SIZE - \
150 RAS_TABLE_V2_1_INFO_SIZE) / RAS_TABLE_RECORD_SIZE)
152 #define to_amdgpu_device(x) ((container_of(x, struct amdgpu_ras, eeprom_control))->adev)
154 static bool __is_ras_eeprom_supported(struct amdgpu_device *adev)
156 switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
157 case IP_VERSION(11, 0, 2): /* VEGA20 and ARCTURUS */
158 case IP_VERSION(11, 0, 7): /* Sienna cichlid */
159 case IP_VERSION(13, 0, 0):
160 case IP_VERSION(13, 0, 2): /* Aldebaran */
161 case IP_VERSION(13, 0, 10):
163 case IP_VERSION(13, 0, 6):
164 case IP_VERSION(13, 0, 14):
165 return (adev->gmc.is_app_apu) ? false : true;
171 static bool __get_eeprom_i2c_addr(struct amdgpu_device *adev,
172 struct amdgpu_ras_eeprom_control *control)
174 struct atom_context *atom_ctx = adev->mode_info.atom_context;
180 if (amdgpu_atomfirmware_ras_rom_addr(adev, &i2c_addr)) {
181 /* The address given by VBIOS is an 8-bit, wire-format
182 * address, i.e. the most significant byte.
184 * Normalize it to a 19-bit EEPROM address. Remove the
185 * device type identifier and make it a 7-bit address;
186 * then make it a 19-bit EEPROM address. See top of
189 i2c_addr = (i2c_addr & 0x0F) >> 1;
190 control->i2c_address = ((u32) i2c_addr) << 16;
195 switch (amdgpu_ip_version(adev, MP1_HWIP, 0)) {
196 case IP_VERSION(11, 0, 2):
197 /* VEGA20 and ARCTURUS */
198 if (adev->asic_type == CHIP_VEGA20)
199 control->i2c_address = EEPROM_I2C_MADDR_0;
200 else if (strnstr(atom_ctx->vbios_pn,
202 sizeof(atom_ctx->vbios_pn)))
203 control->i2c_address = EEPROM_I2C_MADDR_0;
205 control->i2c_address = EEPROM_I2C_MADDR_4;
207 case IP_VERSION(11, 0, 7):
208 control->i2c_address = EEPROM_I2C_MADDR_0;
210 case IP_VERSION(13, 0, 2):
211 if (strnstr(atom_ctx->vbios_pn, "D673",
212 sizeof(atom_ctx->vbios_pn)))
213 control->i2c_address = EEPROM_I2C_MADDR_4;
215 control->i2c_address = EEPROM_I2C_MADDR_0;
217 case IP_VERSION(13, 0, 0):
218 if (strnstr(atom_ctx->vbios_pn, "D707",
219 sizeof(atom_ctx->vbios_pn)))
220 control->i2c_address = EEPROM_I2C_MADDR_0;
222 control->i2c_address = EEPROM_I2C_MADDR_4;
224 case IP_VERSION(13, 0, 6):
225 case IP_VERSION(13, 0, 10):
226 case IP_VERSION(13, 0, 14):
227 control->i2c_address = EEPROM_I2C_MADDR_4;
235 __encode_table_header_to_buf(struct amdgpu_ras_eeprom_table_header *hdr,
238 u32 *pp = (uint32_t *)buf;
240 pp[0] = cpu_to_le32(hdr->header);
241 pp[1] = cpu_to_le32(hdr->version);
242 pp[2] = cpu_to_le32(hdr->first_rec_offset);
243 pp[3] = cpu_to_le32(hdr->tbl_size);
244 pp[4] = cpu_to_le32(hdr->checksum);
248 __decode_table_header_from_buf(struct amdgpu_ras_eeprom_table_header *hdr,
251 u32 *pp = (uint32_t *)buf;
253 hdr->header = le32_to_cpu(pp[0]);
254 hdr->version = le32_to_cpu(pp[1]);
255 hdr->first_rec_offset = le32_to_cpu(pp[2]);
256 hdr->tbl_size = le32_to_cpu(pp[3]);
257 hdr->checksum = le32_to_cpu(pp[4]);
260 static int __write_table_header(struct amdgpu_ras_eeprom_control *control)
262 u8 buf[RAS_TABLE_HEADER_SIZE];
263 struct amdgpu_device *adev = to_amdgpu_device(control);
266 memset(buf, 0, sizeof(buf));
267 __encode_table_header_to_buf(&control->tbl_hdr, buf);
269 /* i2c may be unstable in gpu reset */
270 down_read(&adev->reset_domain->sem);
271 res = amdgpu_eeprom_write(adev->pm.ras_eeprom_i2c_bus,
272 control->i2c_address +
273 control->ras_header_offset,
274 buf, RAS_TABLE_HEADER_SIZE);
275 up_read(&adev->reset_domain->sem);
278 DRM_ERROR("Failed to write EEPROM table header:%d", res);
279 } else if (res < RAS_TABLE_HEADER_SIZE) {
280 DRM_ERROR("Short write:%d out of %d\n",
281 res, RAS_TABLE_HEADER_SIZE);
291 __encode_table_ras_info_to_buf(struct amdgpu_ras_eeprom_table_ras_info *rai,
294 u32 *pp = (uint32_t *)buf;
297 tmp = ((uint32_t)(rai->rma_status) & 0xFF) |
298 (((uint32_t)(rai->health_percent) << 8) & 0xFF00) |
299 (((uint32_t)(rai->ecc_page_threshold) << 16) & 0xFFFF0000);
300 pp[0] = cpu_to_le32(tmp);
304 __decode_table_ras_info_from_buf(struct amdgpu_ras_eeprom_table_ras_info *rai,
307 u32 *pp = (uint32_t *)buf;
310 tmp = le32_to_cpu(pp[0]);
311 rai->rma_status = tmp & 0xFF;
312 rai->health_percent = (tmp >> 8) & 0xFF;
313 rai->ecc_page_threshold = (tmp >> 16) & 0xFFFF;
316 static int __write_table_ras_info(struct amdgpu_ras_eeprom_control *control)
318 struct amdgpu_device *adev = to_amdgpu_device(control);
322 buf = kzalloc(RAS_TABLE_V2_1_INFO_SIZE, GFP_KERNEL);
324 DRM_ERROR("Failed to alloc buf to write table ras info\n");
328 __encode_table_ras_info_to_buf(&control->tbl_rai, buf);
330 /* i2c may be unstable in gpu reset */
331 down_read(&adev->reset_domain->sem);
332 res = amdgpu_eeprom_write(adev->pm.ras_eeprom_i2c_bus,
333 control->i2c_address +
334 control->ras_info_offset,
335 buf, RAS_TABLE_V2_1_INFO_SIZE);
336 up_read(&adev->reset_domain->sem);
339 DRM_ERROR("Failed to write EEPROM table ras info:%d", res);
340 } else if (res < RAS_TABLE_V2_1_INFO_SIZE) {
341 DRM_ERROR("Short write:%d out of %d\n",
342 res, RAS_TABLE_V2_1_INFO_SIZE);
353 static u8 __calc_hdr_byte_sum(const struct amdgpu_ras_eeprom_control *control)
359 /* Header checksum, skip checksum field in the calculation */
360 sz = sizeof(control->tbl_hdr) - sizeof(control->tbl_hdr.checksum);
361 pp = (u8 *) &control->tbl_hdr;
363 for (ii = 0; ii < sz; ii++, pp++)
369 static u8 __calc_ras_info_byte_sum(const struct amdgpu_ras_eeprom_control *control)
375 sz = sizeof(control->tbl_rai);
376 pp = (u8 *) &control->tbl_rai;
378 for (ii = 0; ii < sz; ii++, pp++)
384 static int amdgpu_ras_eeprom_correct_header_tag(
385 struct amdgpu_ras_eeprom_control *control,
388 struct amdgpu_ras_eeprom_table_header *hdr = &control->tbl_hdr;
393 csum = -hdr->checksum;
395 hh = (void *) &hdr->header;
396 csum -= (hh[0] + hh[1] + hh[2] + hh[3]);
397 hh = (void *) &header;
398 csum += hh[0] + hh[1] + hh[2] + hh[3];
400 mutex_lock(&control->ras_tbl_mutex);
401 hdr->header = header;
402 hdr->checksum = csum;
403 res = __write_table_header(control);
404 mutex_unlock(&control->ras_tbl_mutex);
409 static void amdgpu_ras_set_eeprom_table_version(struct amdgpu_ras_eeprom_control *control)
411 struct amdgpu_device *adev = to_amdgpu_device(control);
412 struct amdgpu_ras_eeprom_table_header *hdr = &control->tbl_hdr;
414 switch (amdgpu_ip_version(adev, UMC_HWIP, 0)) {
415 case IP_VERSION(8, 10, 0):
416 case IP_VERSION(12, 0, 0):
417 hdr->version = RAS_TABLE_VER_V2_1;
420 hdr->version = RAS_TABLE_VER_V1;
426 * amdgpu_ras_eeprom_reset_table -- Reset the RAS EEPROM table
427 * @control: pointer to control structure
429 * Reset the contents of the header of the RAS EEPROM table.
430 * Return 0 on success, -errno on error.
432 int amdgpu_ras_eeprom_reset_table(struct amdgpu_ras_eeprom_control *control)
434 struct amdgpu_device *adev = to_amdgpu_device(control);
435 struct amdgpu_ras_eeprom_table_header *hdr = &control->tbl_hdr;
436 struct amdgpu_ras_eeprom_table_ras_info *rai = &control->tbl_rai;
437 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
441 mutex_lock(&control->ras_tbl_mutex);
443 hdr->header = RAS_TABLE_HDR_VAL;
444 amdgpu_ras_set_eeprom_table_version(control);
446 if (hdr->version == RAS_TABLE_VER_V2_1) {
447 hdr->first_rec_offset = RAS_RECORD_START_V2_1;
448 hdr->tbl_size = RAS_TABLE_HEADER_SIZE +
449 RAS_TABLE_V2_1_INFO_SIZE;
450 rai->rma_status = GPU_HEALTH_USABLE;
452 * GPU health represented as a percentage.
453 * 0 means worst health, 100 means fully health.
455 rai->health_percent = 100;
456 /* ecc_page_threshold = 0 means disable bad page retirement */
457 rai->ecc_page_threshold = con->bad_page_cnt_threshold;
459 hdr->first_rec_offset = RAS_RECORD_START;
460 hdr->tbl_size = RAS_TABLE_HEADER_SIZE;
463 csum = __calc_hdr_byte_sum(control);
464 if (hdr->version == RAS_TABLE_VER_V2_1)
465 csum += __calc_ras_info_byte_sum(control);
467 hdr->checksum = csum;
468 res = __write_table_header(control);
469 if (!res && hdr->version > RAS_TABLE_VER_V1)
470 res = __write_table_ras_info(control);
472 control->ras_num_recs = 0;
473 control->ras_num_bad_pages = 0;
474 control->ras_fri = 0;
476 amdgpu_dpm_send_hbm_bad_pages_num(adev, control->ras_num_bad_pages);
478 control->bad_channel_bitmap = 0;
479 amdgpu_dpm_send_hbm_bad_channel_flag(adev, control->bad_channel_bitmap);
480 con->update_channel_flag = false;
482 amdgpu_ras_debugfs_set_ret_size(control);
484 mutex_unlock(&control->ras_tbl_mutex);
490 __encode_table_record_to_buf(struct amdgpu_ras_eeprom_control *control,
491 struct eeprom_table_record *record,
497 /* Next are all record fields according to EEPROM page spec in LE foramt */
498 buf[i++] = record->err_type;
500 buf[i++] = record->bank;
502 tmp = cpu_to_le64(record->ts);
503 memcpy(buf + i, &tmp, 8);
506 tmp = cpu_to_le64((record->offset & 0xffffffffffff));
507 memcpy(buf + i, &tmp, 6);
510 buf[i++] = record->mem_channel;
511 buf[i++] = record->mcumc_id;
513 tmp = cpu_to_le64((record->retired_page & 0xffffffffffff));
514 memcpy(buf + i, &tmp, 6);
518 __decode_table_record_from_buf(struct amdgpu_ras_eeprom_control *control,
519 struct eeprom_table_record *record,
525 /* Next are all record fields according to EEPROM page spec in LE foramt */
526 record->err_type = buf[i++];
528 record->bank = buf[i++];
530 memcpy(&tmp, buf + i, 8);
531 record->ts = le64_to_cpu(tmp);
534 memcpy(&tmp, buf + i, 6);
535 record->offset = (le64_to_cpu(tmp) & 0xffffffffffff);
538 record->mem_channel = buf[i++];
539 record->mcumc_id = buf[i++];
541 memcpy(&tmp, buf + i, 6);
542 record->retired_page = (le64_to_cpu(tmp) & 0xffffffffffff);
545 bool amdgpu_ras_eeprom_check_err_threshold(struct amdgpu_device *adev)
547 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
549 if (!__is_ras_eeprom_supported(adev) ||
550 !amdgpu_bad_page_threshold)
553 /* skip check eeprom table for VEGA20 Gaming */
557 if (!(con->features & BIT(AMDGPU_RAS_BLOCK__UMC)))
560 if (con->eeprom_control.tbl_hdr.header == RAS_TABLE_HDR_BAD) {
561 if (amdgpu_bad_page_threshold == -1) {
562 dev_warn(adev->dev, "RAS records:%d exceed threshold:%d",
563 con->eeprom_control.ras_num_bad_pages, con->bad_page_cnt_threshold);
565 "But GPU can be operated due to bad_page_threshold = -1.\n");
568 dev_warn(adev->dev, "This GPU is in BAD status.");
569 dev_warn(adev->dev, "Please retire it or set a larger "
570 "threshold value when reloading driver.\n");
579 * __amdgpu_ras_eeprom_write -- write indexed from buffer to EEPROM
580 * @control: pointer to control structure
581 * @buf: pointer to buffer containing data to write
582 * @fri: start writing at this index
583 * @num: number of records to write
585 * The caller must hold the table mutex in @control.
586 * Return 0 on success, -errno otherwise.
588 static int __amdgpu_ras_eeprom_write(struct amdgpu_ras_eeprom_control *control,
589 u8 *buf, const u32 fri, const u32 num)
591 struct amdgpu_device *adev = to_amdgpu_device(control);
595 /* i2c may be unstable in gpu reset */
596 down_read(&adev->reset_domain->sem);
597 buf_size = num * RAS_TABLE_RECORD_SIZE;
598 res = amdgpu_eeprom_write(adev->pm.ras_eeprom_i2c_bus,
599 control->i2c_address +
600 RAS_INDEX_TO_OFFSET(control, fri),
602 up_read(&adev->reset_domain->sem);
604 DRM_ERROR("Writing %d EEPROM table records error:%d",
606 } else if (res < buf_size) {
607 /* Short write, return error.
609 DRM_ERROR("Wrote %d records out of %d",
610 res / RAS_TABLE_RECORD_SIZE, num);
620 amdgpu_ras_eeprom_append_table(struct amdgpu_ras_eeprom_control *control,
621 struct eeprom_table_record *record,
624 struct amdgpu_ras *con = amdgpu_ras_get_context(to_amdgpu_device(control));
625 struct amdgpu_device *adev = to_amdgpu_device(control);
630 buf = kcalloc(num, RAS_TABLE_RECORD_SIZE, GFP_KERNEL);
634 /* Encode all of them in one go.
637 for (i = 0; i < num; i++, pp += RAS_TABLE_RECORD_SIZE) {
638 __encode_table_record_to_buf(control, &record[i], pp);
640 /* update bad channel bitmap */
641 if ((record[i].mem_channel < BITS_PER_TYPE(control->bad_channel_bitmap)) &&
642 !(control->bad_channel_bitmap & (1 << record[i].mem_channel))) {
643 control->bad_channel_bitmap |= 1 << record[i].mem_channel;
644 con->update_channel_flag = true;
648 /* a, first record index to write into.
649 * b, last record index to write into.
650 * a = first index to read (fri) + number of records in the table,
652 * Let N = control->ras_max_num_record_count, then we have,
653 * case 0: 0 <= a <= b < N,
654 * just append @num records starting at a;
655 * case 1: 0 <= a < N <= b,
656 * append (N - a) records starting at a, and
657 * append the remainder, b % N + 1, starting at 0.
658 * case 2: 0 <= fri < N <= a <= b, then modulo N we get two subcases,
659 * case 2a: 0 <= a <= b < N
660 * append num records starting at a; and fix fri if b overwrote it,
661 * and since a <= b, if b overwrote it then a must've also,
662 * and if b didn't overwrite it, then a didn't also.
663 * case 2b: 0 <= b < a < N
664 * write num records starting at a, which wraps around 0=N
665 * and overwrite fri unconditionally. Now from case 2a,
666 * this means that b eclipsed fri to overwrite it and wrap
667 * around 0 again, i.e. b = 2N+r pre modulo N, so we unconditionally
668 * set fri = b + 1 (mod N).
669 * Now, since fri is updated in every case, except the trivial case 0,
670 * the number of records present in the table after writing, is,
671 * num_recs - 1 = b - fri (mod N), and we take the positive value,
672 * by adding an arbitrary multiple of N before taking the modulo N
675 a = control->ras_fri + control->ras_num_recs;
677 if (b < control->ras_max_record_count) {
678 res = __amdgpu_ras_eeprom_write(control, buf, a, num);
679 } else if (a < control->ras_max_record_count) {
682 g0 = control->ras_max_record_count - a;
683 g1 = b % control->ras_max_record_count + 1;
684 res = __amdgpu_ras_eeprom_write(control, buf, a, g0);
687 res = __amdgpu_ras_eeprom_write(control,
688 buf + g0 * RAS_TABLE_RECORD_SIZE,
692 if (g1 > control->ras_fri)
693 control->ras_fri = g1 % control->ras_max_record_count;
695 a %= control->ras_max_record_count;
696 b %= control->ras_max_record_count;
699 /* Note that, b - a + 1 = num. */
700 res = __amdgpu_ras_eeprom_write(control, buf, a, num);
703 if (b >= control->ras_fri)
704 control->ras_fri = (b + 1) % control->ras_max_record_count;
708 /* b < a, which means, we write from
709 * a to the end of the table, and from
710 * the start of the table to b.
712 g0 = control->ras_max_record_count - a;
714 res = __amdgpu_ras_eeprom_write(control, buf, a, g0);
717 res = __amdgpu_ras_eeprom_write(control,
718 buf + g0 * RAS_TABLE_RECORD_SIZE,
722 control->ras_fri = g1 % control->ras_max_record_count;
725 control->ras_num_recs = 1 + (control->ras_max_record_count + b
727 % control->ras_max_record_count;
729 if (control->rec_type == AMDGPU_RAS_EEPROM_REC_PA)
730 control->ras_num_bad_pages = control->ras_num_recs;
732 control->ras_num_bad_pages =
733 control->ras_num_recs * adev->umc.retire_unit;
740 amdgpu_ras_eeprom_update_header(struct amdgpu_ras_eeprom_control *control)
742 struct amdgpu_device *adev = to_amdgpu_device(control);
743 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
748 /* Modify the header if it exceeds.
750 if (amdgpu_bad_page_threshold != 0 &&
751 control->ras_num_bad_pages >= ras->bad_page_cnt_threshold) {
753 "Saved bad pages %d reaches threshold value %d\n",
754 control->ras_num_bad_pages, ras->bad_page_cnt_threshold);
755 control->tbl_hdr.header = RAS_TABLE_HDR_BAD;
756 if (control->tbl_hdr.version == RAS_TABLE_VER_V2_1) {
757 control->tbl_rai.rma_status = GPU_RETIRED__ECC_REACH_THRESHOLD;
758 control->tbl_rai.health_percent = 0;
761 if (amdgpu_bad_page_threshold != -1)
764 /* ignore the -ENOTSUPP return value */
765 amdgpu_dpm_send_rma_reason(adev);
768 if (control->tbl_hdr.version == RAS_TABLE_VER_V2_1)
769 control->tbl_hdr.tbl_size = RAS_TABLE_HEADER_SIZE +
770 RAS_TABLE_V2_1_INFO_SIZE +
771 control->ras_num_recs * RAS_TABLE_RECORD_SIZE;
773 control->tbl_hdr.tbl_size = RAS_TABLE_HEADER_SIZE +
774 control->ras_num_recs * RAS_TABLE_RECORD_SIZE;
775 control->tbl_hdr.checksum = 0;
777 buf_size = control->ras_num_recs * RAS_TABLE_RECORD_SIZE;
778 buf = kcalloc(control->ras_num_recs, RAS_TABLE_RECORD_SIZE, GFP_KERNEL);
780 DRM_ERROR("allocating memory for table of size %d bytes failed\n",
781 control->tbl_hdr.tbl_size);
786 down_read(&adev->reset_domain->sem);
787 res = amdgpu_eeprom_read(adev->pm.ras_eeprom_i2c_bus,
788 control->i2c_address +
789 control->ras_record_offset,
791 up_read(&adev->reset_domain->sem);
793 DRM_ERROR("EEPROM failed reading records:%d\n",
796 } else if (res < buf_size) {
797 DRM_ERROR("EEPROM read %d out of %d bytes\n",
804 * bad page records have been stored in eeprom,
805 * now calculate gpu health percent
807 if (amdgpu_bad_page_threshold != 0 &&
808 control->tbl_hdr.version == RAS_TABLE_VER_V2_1 &&
809 control->ras_num_bad_pages < ras->bad_page_cnt_threshold)
810 control->tbl_rai.health_percent = ((ras->bad_page_cnt_threshold -
811 control->ras_num_bad_pages) * 100) /
812 ras->bad_page_cnt_threshold;
814 /* Recalc the checksum.
817 for (pp = buf; pp < buf + buf_size; pp++)
820 csum += __calc_hdr_byte_sum(control);
821 if (control->tbl_hdr.version == RAS_TABLE_VER_V2_1)
822 csum += __calc_ras_info_byte_sum(control);
823 /* avoid sign extension when assigning to "checksum" */
825 control->tbl_hdr.checksum = csum;
826 res = __write_table_header(control);
827 if (!res && control->tbl_hdr.version > RAS_TABLE_VER_V1)
828 res = __write_table_ras_info(control);
835 * amdgpu_ras_eeprom_append -- append records to the EEPROM RAS table
836 * @control: pointer to control structure
837 * @record: array of records to append
838 * @num: number of records in @record array
840 * Append @num records to the table, calculate the checksum and write
841 * the table back to EEPROM. The maximum number of records that
842 * can be appended is between 1 and control->ras_max_record_count,
843 * regardless of how many records are already stored in the table.
845 * Return 0 on success or if EEPROM is not supported, -errno on error.
847 int amdgpu_ras_eeprom_append(struct amdgpu_ras_eeprom_control *control,
848 struct eeprom_table_record *record,
851 struct amdgpu_device *adev = to_amdgpu_device(control);
854 if (!__is_ras_eeprom_supported(adev))
858 DRM_ERROR("will not append 0 records\n");
860 } else if (num > control->ras_max_record_count) {
861 DRM_ERROR("cannot append %d records than the size of table %d\n",
862 num, control->ras_max_record_count);
866 /* set the new channel index flag */
867 for (i = 0; i < num; i++)
868 record[i].retired_page |= UMC_CHANNEL_IDX_V2;
870 mutex_lock(&control->ras_tbl_mutex);
872 res = amdgpu_ras_eeprom_append_table(control, record, num);
874 res = amdgpu_ras_eeprom_update_header(control);
876 amdgpu_ras_debugfs_set_ret_size(control);
878 mutex_unlock(&control->ras_tbl_mutex);
880 /* clear channel index flag, the flag is only saved on eeprom */
881 for (i = 0; i < num; i++)
882 record[i].retired_page &= ~UMC_CHANNEL_IDX_V2;
888 * __amdgpu_ras_eeprom_read -- read indexed from EEPROM into buffer
889 * @control: pointer to control structure
890 * @buf: pointer to buffer to read into
891 * @fri: first record index, start reading at this index, absolute index
892 * @num: number of records to read
894 * The caller must hold the table mutex in @control.
895 * Return 0 on success, -errno otherwise.
897 static int __amdgpu_ras_eeprom_read(struct amdgpu_ras_eeprom_control *control,
898 u8 *buf, const u32 fri, const u32 num)
900 struct amdgpu_device *adev = to_amdgpu_device(control);
904 /* i2c may be unstable in gpu reset */
905 down_read(&adev->reset_domain->sem);
906 buf_size = num * RAS_TABLE_RECORD_SIZE;
907 res = amdgpu_eeprom_read(adev->pm.ras_eeprom_i2c_bus,
908 control->i2c_address +
909 RAS_INDEX_TO_OFFSET(control, fri),
911 up_read(&adev->reset_domain->sem);
913 DRM_ERROR("Reading %d EEPROM table records error:%d",
915 } else if (res < buf_size) {
916 /* Short read, return error.
918 DRM_ERROR("Read %d records out of %d",
919 res / RAS_TABLE_RECORD_SIZE, num);
929 * amdgpu_ras_eeprom_read -- read EEPROM
930 * @control: pointer to control structure
931 * @record: array of records to read into
932 * @num: number of records in @record
934 * Reads num records from the RAS table in EEPROM and
935 * writes the data into @record array.
937 * Returns 0 on success, -errno on error.
939 int amdgpu_ras_eeprom_read(struct amdgpu_ras_eeprom_control *control,
940 struct eeprom_table_record *record,
943 struct amdgpu_device *adev = to_amdgpu_device(control);
944 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
949 if (!__is_ras_eeprom_supported(adev))
953 DRM_ERROR("will not read 0 records\n");
955 } else if (num > control->ras_num_recs) {
956 DRM_ERROR("too many records to read:%d available:%d\n",
957 num, control->ras_num_recs);
961 buf = kcalloc(num, RAS_TABLE_RECORD_SIZE, GFP_KERNEL);
965 /* Determine how many records to read, from the first record
966 * index, fri, to the end of the table, and from the beginning
967 * of the table, such that the total number of records is
968 * @num, and we handle wrap around when fri > 0 and
969 * fri + num > RAS_MAX_RECORD_COUNT.
971 * First we compute the index of the last element
972 * which would be fetched from each region,
973 * g0 is in [fri, fri + num - 1], and
974 * g1 is in [0, RAS_MAX_RECORD_COUNT - 1].
975 * Then, if g0 < RAS_MAX_RECORD_COUNT, the index of
976 * the last element to fetch, we set g0 to _the number_
977 * of elements to fetch, @num, since we know that the last
978 * indexed to be fetched does not exceed the table.
980 * If, however, g0 >= RAS_MAX_RECORD_COUNT, then
981 * we set g0 to the number of elements to read
982 * until the end of the table, and g1 to the number of
983 * elements to read from the beginning of the table.
985 g0 = control->ras_fri + num - 1;
986 g1 = g0 % control->ras_max_record_count;
987 if (g0 < control->ras_max_record_count) {
991 g0 = control->ras_max_record_count - control->ras_fri;
995 mutex_lock(&control->ras_tbl_mutex);
996 res = __amdgpu_ras_eeprom_read(control, buf, control->ras_fri, g0);
1000 res = __amdgpu_ras_eeprom_read(control,
1001 buf + g0 * RAS_TABLE_RECORD_SIZE,
1009 /* Read up everything? Then transform.
1012 for (i = 0; i < num; i++, pp += RAS_TABLE_RECORD_SIZE) {
1013 __decode_table_record_from_buf(control, &record[i], pp);
1015 /* update bad channel bitmap */
1016 if ((record[i].mem_channel < BITS_PER_TYPE(control->bad_channel_bitmap)) &&
1017 !(control->bad_channel_bitmap & (1 << record[i].mem_channel))) {
1018 control->bad_channel_bitmap |= 1 << record[i].mem_channel;
1019 con->update_channel_flag = true;
1024 mutex_unlock(&control->ras_tbl_mutex);
1029 uint32_t amdgpu_ras_eeprom_max_record_count(struct amdgpu_ras_eeprom_control *control)
1031 /* get available eeprom table version first before eeprom table init */
1032 amdgpu_ras_set_eeprom_table_version(control);
1034 if (control->tbl_hdr.version == RAS_TABLE_VER_V2_1)
1035 return RAS_MAX_RECORD_COUNT_V2_1;
1037 return RAS_MAX_RECORD_COUNT;
1041 amdgpu_ras_debugfs_eeprom_size_read(struct file *f, char __user *buf,
1042 size_t size, loff_t *pos)
1044 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
1045 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
1046 struct amdgpu_ras_eeprom_control *control = ras ? &ras->eeprom_control : NULL;
1053 if (!ras || !control) {
1054 res = snprintf(data, sizeof(data), "Not supported\n");
1056 res = snprintf(data, sizeof(data), "%d bytes or %d records\n",
1057 RAS_TBL_SIZE_BYTES, control->ras_max_record_count);
1064 res = min_t(size_t, res, size);
1066 if (copy_to_user(buf, &data[*pos], res))
1074 const struct file_operations amdgpu_ras_debugfs_eeprom_size_ops = {
1075 .owner = THIS_MODULE,
1076 .read = amdgpu_ras_debugfs_eeprom_size_read,
1078 .llseek = default_llseek,
1081 static const char *tbl_hdr_str = " Signature Version FirstOffs Size Checksum\n";
1082 static const char *tbl_hdr_fmt = "0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n";
1083 #define tbl_hdr_fmt_size (5 * (2+8) + 4 + 1)
1084 static const char *rec_hdr_str = "Index Offset ErrType Bank/CU TimeStamp Offs/Addr MemChl MCUMCID RetiredPage\n";
1085 static const char *rec_hdr_fmt = "%5d 0x%05X %7s 0x%02X 0x%016llX 0x%012llX 0x%02X 0x%02X 0x%012llX\n";
1086 #define rec_hdr_fmt_size (5 + 1 + 7 + 1 + 7 + 1 + 7 + 1 + 18 + 1 + 14 + 1 + 6 + 1 + 7 + 1 + 14 + 1)
1088 static const char *record_err_type_str[AMDGPU_RAS_EEPROM_ERR_COUNT] = {
1094 static loff_t amdgpu_ras_debugfs_table_size(struct amdgpu_ras_eeprom_control *control)
1096 return strlen(tbl_hdr_str) + tbl_hdr_fmt_size +
1097 strlen(rec_hdr_str) + rec_hdr_fmt_size * control->ras_num_recs;
1100 void amdgpu_ras_debugfs_set_ret_size(struct amdgpu_ras_eeprom_control *control)
1102 struct amdgpu_ras *ras = container_of(control, struct amdgpu_ras,
1104 struct dentry *de = ras->de_ras_eeprom_table;
1107 d_inode(de)->i_size = amdgpu_ras_debugfs_table_size(control);
1110 static ssize_t amdgpu_ras_debugfs_table_read(struct file *f, char __user *buf,
1111 size_t size, loff_t *pos)
1113 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
1114 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
1115 struct amdgpu_ras_eeprom_control *control = &ras->eeprom_control;
1116 const size_t orig_size = size;
1120 mutex_lock(&control->ras_tbl_mutex);
1122 /* We want *pos - data_len > 0, which means there's
1123 * bytes to be printed from data.
1125 data_len = strlen(tbl_hdr_str);
1126 if (*pos < data_len) {
1128 data_len = min_t(size_t, data_len, size);
1129 if (copy_to_user(buf, &tbl_hdr_str[*pos], data_len))
1136 data_len = strlen(tbl_hdr_str) + tbl_hdr_fmt_size;
1137 if (*pos < data_len && size > 0) {
1138 u8 data[tbl_hdr_fmt_size + 1];
1141 snprintf(data, sizeof(data), tbl_hdr_fmt,
1142 control->tbl_hdr.header,
1143 control->tbl_hdr.version,
1144 control->tbl_hdr.first_rec_offset,
1145 control->tbl_hdr.tbl_size,
1146 control->tbl_hdr.checksum);
1149 data_len = min_t(size_t, data_len, size);
1150 lpos = *pos - strlen(tbl_hdr_str);
1151 if (copy_to_user(buf, &data[lpos], data_len))
1158 data_len = strlen(tbl_hdr_str) + tbl_hdr_fmt_size + strlen(rec_hdr_str);
1159 if (*pos < data_len && size > 0) {
1163 data_len = min_t(size_t, data_len, size);
1164 lpos = *pos - strlen(tbl_hdr_str) - tbl_hdr_fmt_size;
1165 if (copy_to_user(buf, &rec_hdr_str[lpos], data_len))
1172 data_len = amdgpu_ras_debugfs_table_size(control);
1173 if (*pos < data_len && size > 0) {
1174 u8 dare[RAS_TABLE_RECORD_SIZE];
1175 u8 data[rec_hdr_fmt_size + 1];
1176 struct eeprom_table_record record;
1179 /* Find the starting record index
1181 s = *pos - strlen(tbl_hdr_str) - tbl_hdr_fmt_size -
1182 strlen(rec_hdr_str);
1183 s = s / rec_hdr_fmt_size;
1184 r = *pos - strlen(tbl_hdr_str) - tbl_hdr_fmt_size -
1185 strlen(rec_hdr_str);
1186 r = r % rec_hdr_fmt_size;
1188 for ( ; size > 0 && s < control->ras_num_recs; s++) {
1189 u32 ai = RAS_RI_TO_AI(control, s);
1190 /* Read a single record
1192 res = __amdgpu_ras_eeprom_read(control, dare, ai, 1);
1195 __decode_table_record_from_buf(control, &record, dare);
1196 snprintf(data, sizeof(data), rec_hdr_fmt,
1198 RAS_INDEX_TO_OFFSET(control, ai),
1199 record_err_type_str[record.err_type],
1205 record.retired_page);
1207 data_len = min_t(size_t, rec_hdr_fmt_size - r, size);
1208 if (copy_to_user(buf, &data[r], data_len)) {
1220 mutex_unlock(&control->ras_tbl_mutex);
1221 return res < 0 ? res : orig_size - size;
1225 amdgpu_ras_debugfs_eeprom_table_read(struct file *f, char __user *buf,
1226 size_t size, loff_t *pos)
1228 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
1229 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
1230 struct amdgpu_ras_eeprom_control *control = ras ? &ras->eeprom_control : NULL;
1237 if (!ras || !control) {
1238 res = snprintf(data, sizeof(data), "Not supported\n");
1243 res = min_t(size_t, res, size);
1245 if (copy_to_user(buf, &data[*pos], res))
1252 return amdgpu_ras_debugfs_table_read(f, buf, size, pos);
1256 const struct file_operations amdgpu_ras_debugfs_eeprom_table_ops = {
1257 .owner = THIS_MODULE,
1258 .read = amdgpu_ras_debugfs_eeprom_table_read,
1260 .llseek = default_llseek,
1264 * __verify_ras_table_checksum -- verify the RAS EEPROM table checksum
1265 * @control: pointer to control structure
1267 * Check the checksum of the stored in EEPROM RAS table.
1269 * Return 0 if the checksum is correct,
1270 * positive if it is not correct, and
1271 * -errno on I/O error.
1273 static int __verify_ras_table_checksum(struct amdgpu_ras_eeprom_control *control)
1275 struct amdgpu_device *adev = to_amdgpu_device(control);
1279 if (control->tbl_hdr.version == RAS_TABLE_VER_V2_1)
1280 buf_size = RAS_TABLE_HEADER_SIZE +
1281 RAS_TABLE_V2_1_INFO_SIZE +
1282 control->ras_num_recs * RAS_TABLE_RECORD_SIZE;
1284 buf_size = RAS_TABLE_HEADER_SIZE +
1285 control->ras_num_recs * RAS_TABLE_RECORD_SIZE;
1287 buf = kzalloc(buf_size, GFP_KERNEL);
1289 DRM_ERROR("Out of memory checking RAS table checksum.\n");
1293 res = amdgpu_eeprom_read(adev->pm.ras_eeprom_i2c_bus,
1294 control->i2c_address +
1295 control->ras_header_offset,
1297 if (res < buf_size) {
1298 DRM_ERROR("Partial read for checksum, res:%d\n", res);
1299 /* On partial reads, return -EIO.
1307 for (pp = buf; pp < buf + buf_size; pp++)
1311 return res < 0 ? res : csum;
1314 static int __read_table_ras_info(struct amdgpu_ras_eeprom_control *control)
1316 struct amdgpu_ras_eeprom_table_ras_info *rai = &control->tbl_rai;
1317 struct amdgpu_device *adev = to_amdgpu_device(control);
1321 buf = kzalloc(RAS_TABLE_V2_1_INFO_SIZE, GFP_KERNEL);
1323 DRM_ERROR("Failed to alloc buf to read EEPROM table ras info\n");
1328 * EEPROM table V2_1 supports ras info,
1329 * read EEPROM table ras info
1331 res = amdgpu_eeprom_read(adev->pm.ras_eeprom_i2c_bus,
1332 control->i2c_address + control->ras_info_offset,
1333 buf, RAS_TABLE_V2_1_INFO_SIZE);
1334 if (res < RAS_TABLE_V2_1_INFO_SIZE) {
1335 DRM_ERROR("Failed to read EEPROM table ras info, res:%d", res);
1336 res = res >= 0 ? -EIO : res;
1340 __decode_table_ras_info_from_buf(rai, buf);
1344 return res == RAS_TABLE_V2_1_INFO_SIZE ? 0 : res;
1347 int amdgpu_ras_eeprom_init(struct amdgpu_ras_eeprom_control *control)
1349 struct amdgpu_device *adev = to_amdgpu_device(control);
1350 unsigned char buf[RAS_TABLE_HEADER_SIZE] = { 0 };
1351 struct amdgpu_ras_eeprom_table_header *hdr = &control->tbl_hdr;
1352 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
1355 ras->is_rma = false;
1357 if (!__is_ras_eeprom_supported(adev))
1360 /* Verify i2c adapter is initialized */
1361 if (!adev->pm.ras_eeprom_i2c_bus || !adev->pm.ras_eeprom_i2c_bus->algo)
1364 if (!__get_eeprom_i2c_addr(adev, control))
1367 control->ras_header_offset = RAS_HDR_START;
1368 control->ras_info_offset = RAS_TABLE_V2_1_INFO_START;
1369 mutex_init(&control->ras_tbl_mutex);
1371 /* Read the table header from EEPROM address */
1372 res = amdgpu_eeprom_read(adev->pm.ras_eeprom_i2c_bus,
1373 control->i2c_address + control->ras_header_offset,
1374 buf, RAS_TABLE_HEADER_SIZE);
1375 if (res < RAS_TABLE_HEADER_SIZE) {
1376 DRM_ERROR("Failed to read EEPROM table header, res:%d", res);
1377 return res >= 0 ? -EIO : res;
1380 __decode_table_header_from_buf(hdr, buf);
1382 if (hdr->version == RAS_TABLE_VER_V2_1) {
1383 control->ras_num_recs = RAS_NUM_RECS_V2_1(hdr);
1384 control->ras_record_offset = RAS_RECORD_START_V2_1;
1385 control->ras_max_record_count = RAS_MAX_RECORD_COUNT_V2_1;
1387 control->ras_num_recs = RAS_NUM_RECS(hdr);
1388 control->ras_record_offset = RAS_RECORD_START;
1389 control->ras_max_record_count = RAS_MAX_RECORD_COUNT;
1391 control->ras_fri = RAS_OFFSET_TO_INDEX(control, hdr->first_rec_offset);
1396 int amdgpu_ras_eeprom_check(struct amdgpu_ras_eeprom_control *control)
1398 struct amdgpu_device *adev = to_amdgpu_device(control);
1399 struct amdgpu_ras_eeprom_table_header *hdr = &control->tbl_hdr;
1400 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
1403 if (!__is_ras_eeprom_supported(adev))
1406 /* Verify i2c adapter is initialized */
1407 if (!adev->pm.ras_eeprom_i2c_bus || !adev->pm.ras_eeprom_i2c_bus->algo)
1410 if (!__get_eeprom_i2c_addr(adev, control))
1413 if (control->rec_type == AMDGPU_RAS_EEPROM_REC_PA)
1414 control->ras_num_bad_pages = control->ras_num_recs;
1416 control->ras_num_bad_pages =
1417 control->ras_num_recs * adev->umc.retire_unit;
1419 if (hdr->header == RAS_TABLE_HDR_VAL) {
1420 DRM_DEBUG_DRIVER("Found existing EEPROM table with %d records",
1421 control->ras_num_bad_pages);
1423 if (hdr->version == RAS_TABLE_VER_V2_1) {
1424 res = __read_table_ras_info(control);
1429 res = __verify_ras_table_checksum(control);
1431 DRM_ERROR("RAS table incorrect checksum or error:%d\n",
1434 /* Warn if we are at 90% of the threshold or above
1436 if (10 * control->ras_num_bad_pages >= 9 * ras->bad_page_cnt_threshold)
1437 dev_warn(adev->dev, "RAS records:%u exceeds 90%% of threshold:%d",
1438 control->ras_num_bad_pages,
1439 ras->bad_page_cnt_threshold);
1440 } else if (hdr->header == RAS_TABLE_HDR_BAD &&
1441 amdgpu_bad_page_threshold != 0) {
1442 if (hdr->version == RAS_TABLE_VER_V2_1) {
1443 res = __read_table_ras_info(control);
1448 res = __verify_ras_table_checksum(control);
1450 dev_err(adev->dev, "RAS Table incorrect checksum or error:%d\n",
1454 if (ras->bad_page_cnt_threshold > control->ras_num_bad_pages) {
1455 /* This means that, the threshold was increased since
1456 * the last time the system was booted, and now,
1457 * ras->bad_page_cnt_threshold - control->num_recs > 0,
1458 * so that at least one more record can be saved,
1459 * before the page count threshold is reached.
1462 "records:%d threshold:%d, resetting "
1463 "RAS table header signature",
1464 control->ras_num_bad_pages,
1465 ras->bad_page_cnt_threshold);
1466 res = amdgpu_ras_eeprom_correct_header_tag(control,
1469 dev_err(adev->dev, "RAS records:%d exceed threshold:%d",
1470 control->ras_num_bad_pages, ras->bad_page_cnt_threshold);
1471 if (amdgpu_bad_page_threshold == -1) {
1472 dev_warn(adev->dev, "GPU will be initialized due to bad_page_threshold = -1.");
1477 "RAS records:%d exceed threshold:%d, "
1478 "GPU will not be initialized. Replace this GPU or increase the threshold",
1479 control->ras_num_bad_pages, ras->bad_page_cnt_threshold);
1483 DRM_INFO("Creating a new EEPROM table");
1485 res = amdgpu_ras_eeprom_reset_table(control);
1488 return res < 0 ? res : 0;