2 * Copyright 2021 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.h"
25 #include "amdgpu_umc.h"
28 #include "umc/umc_6_7_0_offset.h"
29 #include "umc/umc_6_7_0_sh_mask.h"
32 umc_v6_7_channel_idx_tbl_second[UMC_V6_7_UMC_INSTANCE_NUM][UMC_V6_7_CHANNEL_INSTANCE_NUM] = {
33 {28, 20, 24, 16, 12, 4, 8, 0},
34 {6, 30, 2, 26, 22, 14, 18, 10},
35 {19, 11, 15, 7, 3, 27, 31, 23},
36 {9, 1, 5, 29, 25, 17, 21, 13}
39 umc_v6_7_channel_idx_tbl_first[UMC_V6_7_UMC_INSTANCE_NUM][UMC_V6_7_CHANNEL_INSTANCE_NUM] = {
40 {19, 11, 15, 7, 3, 27, 31, 23},
41 {9, 1, 5, 29, 25, 17, 21, 13},
42 {28, 20, 24, 16, 12, 4, 8, 0},
43 {6, 30, 2, 26, 22, 14, 18, 10},
46 static inline uint32_t get_umc_v6_7_reg_offset(struct amdgpu_device *adev,
50 uint32_t index = umc_inst * adev->umc.channel_inst_num + ch_inst;
52 /* adjust umc and channel index offset,
53 * the register address is not linear on each umc instace */
57 return adev->umc.channel_offs * ch_inst + UMC_V6_7_INST_DIST * umc_inst;
60 static inline uint32_t get_umc_v6_7_channel_index(struct amdgpu_device *adev,
64 return adev->umc.channel_idx_tbl[umc_inst * adev->umc.channel_inst_num + ch_inst];
67 static void umc_v6_7_query_error_status_helper(struct amdgpu_device *adev,
68 uint64_t mc_umc_status, uint32_t umc_reg_offset)
73 if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Deferred) == 1)
74 dev_info(adev->dev, "Deferred error, no user action is needed.\n");
77 dev_info(adev->dev, "MCA STATUS 0x%llx, umc_reg_offset 0x%x\n", mc_umc_status, umc_reg_offset);
79 /* print IPID registers value */
81 SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_IPIDT0);
82 reg_value = RREG64_PCIE((mc_umc_addr + umc_reg_offset) * 4);
84 dev_info(adev->dev, "MCA IPID 0x%llx, umc_reg_offset 0x%x\n", reg_value, umc_reg_offset);
86 /* print SYND registers value */
88 SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_SYNDT0);
89 reg_value = RREG64_PCIE((mc_umc_addr + umc_reg_offset) * 4);
91 dev_info(adev->dev, "MCA SYND 0x%llx, umc_reg_offset 0x%x\n", reg_value, umc_reg_offset);
93 /* print MISC0 registers value */
95 SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_MISC0T0);
96 reg_value = RREG64_PCIE((mc_umc_addr + umc_reg_offset) * 4);
98 dev_info(adev->dev, "MCA MISC0 0x%llx, umc_reg_offset 0x%x\n", reg_value, umc_reg_offset);
101 static void umc_v6_7_ecc_info_query_correctable_error_count(struct amdgpu_device *adev,
102 uint32_t umc_inst, uint32_t ch_inst,
103 unsigned long *error_count)
105 uint64_t mc_umc_status;
106 uint32_t eccinfo_table_idx;
107 uint32_t umc_reg_offset;
108 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
110 umc_reg_offset = get_umc_v6_7_reg_offset(adev,
113 eccinfo_table_idx = umc_inst * adev->umc.channel_inst_num + ch_inst;
114 /* check for SRAM correctable error
115 MCUMC_STATUS is a 64 bit register */
116 mc_umc_status = ras->umc_ecc.ecc[eccinfo_table_idx].mca_umc_status;
117 if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1 &&
118 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, CECC) == 1) {
121 umc_v6_7_query_error_status_helper(adev, mc_umc_status, umc_reg_offset);
125 static void umc_v6_7_ecc_info_querry_uncorrectable_error_count(struct amdgpu_device *adev,
126 uint32_t umc_inst, uint32_t ch_inst,
127 unsigned long *error_count)
129 uint64_t mc_umc_status;
130 uint32_t eccinfo_table_idx;
131 uint32_t umc_reg_offset;
132 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
134 umc_reg_offset = get_umc_v6_7_reg_offset(adev,
137 eccinfo_table_idx = umc_inst * adev->umc.channel_inst_num + ch_inst;
138 /* check the MCUMC_STATUS */
139 mc_umc_status = ras->umc_ecc.ecc[eccinfo_table_idx].mca_umc_status;
140 if ((REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1) &&
141 (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Deferred) == 1 ||
142 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC) == 1 ||
143 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, PCC) == 1 ||
144 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UC) == 1 ||
145 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, TCC) == 1)) {
148 umc_v6_7_query_error_status_helper(adev, mc_umc_status, umc_reg_offset);
152 static void umc_v6_7_ecc_info_query_ras_error_count(struct amdgpu_device *adev,
153 void *ras_error_status)
155 struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;
157 uint32_t umc_inst = 0;
158 uint32_t ch_inst = 0;
160 /*TODO: driver needs to toggle DF Cstate to ensure
161 * safe access of UMC registers. Will add the protection */
162 LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
163 umc_v6_7_ecc_info_query_correctable_error_count(adev,
165 &(err_data->ce_count));
166 umc_v6_7_ecc_info_querry_uncorrectable_error_count(adev,
168 &(err_data->ue_count));
172 static void umc_v6_7_ecc_info_query_error_address(struct amdgpu_device *adev,
173 struct ras_err_data *err_data,
177 uint64_t mc_umc_status, err_addr, soc_pa, retired_page, column;
178 uint32_t channel_index;
179 uint32_t eccinfo_table_idx;
180 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
182 eccinfo_table_idx = umc_inst * adev->umc.channel_inst_num + ch_inst;
184 adev->umc.channel_idx_tbl[umc_inst * adev->umc.channel_inst_num + ch_inst];
186 mc_umc_status = ras->umc_ecc.ecc[eccinfo_table_idx].mca_umc_status;
188 if (mc_umc_status == 0)
191 if (!err_data->err_addr)
194 /* calculate error address if ue/ce error is detected */
195 if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1 &&
196 (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC) == 1 ||
197 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, CECC) == 1)) {
199 err_addr = ras->umc_ecc.ecc[eccinfo_table_idx].mca_umc_addr;
200 err_addr = REG_GET_FIELD(err_addr, MCA_UMC_UMC0_MCUMC_ADDRT0, ErrorAddr);
202 /* translate umc channel address to soc pa, 3 parts are included */
203 soc_pa = ADDR_OF_8KB_BLOCK(err_addr) |
204 ADDR_OF_256B_BLOCK(channel_index) |
205 OFFSET_IN_256B_BLOCK(err_addr);
207 /* The umc channel bits are not original values, they are hashed */
208 SET_CHANNEL_HASH(channel_index, soc_pa);
210 /* clear [C4 C3 C2] in soc physical address */
211 soc_pa &= ~(0x7ULL << UMC_V6_7_PA_C2_BIT);
213 /* we only save ue error information currently, ce is skipped */
214 if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC)
216 /* loop for all possibilities of [C4 C3 C2] */
217 for (column = 0; column < UMC_V6_7_NA_MAP_PA_NUM; column++) {
218 retired_page = soc_pa | (column << UMC_V6_7_PA_C2_BIT);
219 dev_info(adev->dev, "Error Address(PA): 0x%llx\n", retired_page);
220 amdgpu_umc_fill_error_record(err_data, err_addr,
221 retired_page, channel_index, umc_inst);
224 retired_page ^= (0x1ULL << UMC_V6_7_PA_R14_BIT);
225 dev_info(adev->dev, "Error Address(PA): 0x%llx\n", retired_page);
226 amdgpu_umc_fill_error_record(err_data, err_addr,
227 retired_page, channel_index, umc_inst);
233 static void umc_v6_7_ecc_info_query_ras_error_address(struct amdgpu_device *adev,
234 void *ras_error_status)
236 struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;
238 uint32_t umc_inst = 0;
239 uint32_t ch_inst = 0;
241 /*TODO: driver needs to toggle DF Cstate to ensure
242 * safe access of UMC resgisters. Will add the protection
243 * when firmware interface is ready */
244 LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
245 umc_v6_7_ecc_info_query_error_address(adev,
252 static void umc_v6_7_query_correctable_error_count(struct amdgpu_device *adev,
253 uint32_t umc_reg_offset,
254 unsigned long *error_count)
256 uint32_t ecc_err_cnt_sel, ecc_err_cnt_sel_addr;
257 uint32_t ecc_err_cnt, ecc_err_cnt_addr;
258 uint64_t mc_umc_status;
259 uint32_t mc_umc_status_addr;
261 /* UMC 6_1_1 registers */
262 ecc_err_cnt_sel_addr =
263 SOC15_REG_OFFSET(UMC, 0, regUMCCH0_0_EccErrCntSel);
265 SOC15_REG_OFFSET(UMC, 0, regUMCCH0_0_EccErrCnt);
267 SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_STATUST0);
269 /* select the lower chip and check the error count */
270 ecc_err_cnt_sel = RREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4);
271 ecc_err_cnt_sel = REG_SET_FIELD(ecc_err_cnt_sel, UMCCH0_0_EccErrCntSel,
273 WREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4, ecc_err_cnt_sel);
275 ecc_err_cnt = RREG32_PCIE((ecc_err_cnt_addr + umc_reg_offset) * 4);
277 (REG_GET_FIELD(ecc_err_cnt, UMCCH0_0_EccErrCnt, EccErrCnt) -
278 UMC_V6_7_CE_CNT_INIT);
280 /* select the higher chip and check the err counter */
281 ecc_err_cnt_sel = REG_SET_FIELD(ecc_err_cnt_sel, UMCCH0_0_EccErrCntSel,
283 WREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4, ecc_err_cnt_sel);
285 ecc_err_cnt = RREG32_PCIE((ecc_err_cnt_addr + umc_reg_offset) * 4);
287 (REG_GET_FIELD(ecc_err_cnt, UMCCH0_0_EccErrCnt, EccErrCnt) -
288 UMC_V6_7_CE_CNT_INIT);
290 /* check for SRAM correctable error
291 MCUMC_STATUS is a 64 bit register */
292 mc_umc_status = RREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4);
293 if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1 &&
294 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, CECC) == 1) {
297 umc_v6_7_query_error_status_helper(adev, mc_umc_status, umc_reg_offset);
301 static void umc_v6_7_querry_uncorrectable_error_count(struct amdgpu_device *adev,
302 uint32_t umc_reg_offset,
303 unsigned long *error_count)
305 uint64_t mc_umc_status;
306 uint32_t mc_umc_status_addr;
309 SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_STATUST0);
311 /* check the MCUMC_STATUS */
312 mc_umc_status = RREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4);
313 if ((REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1) &&
314 (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Deferred) == 1 ||
315 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC) == 1 ||
316 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, PCC) == 1 ||
317 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UC) == 1 ||
318 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, TCC) == 1)) {
321 umc_v6_7_query_error_status_helper(adev, mc_umc_status, umc_reg_offset);
325 static void umc_v6_7_reset_error_count_per_channel(struct amdgpu_device *adev,
326 uint32_t umc_reg_offset)
328 uint32_t ecc_err_cnt_addr;
329 uint32_t ecc_err_cnt_sel, ecc_err_cnt_sel_addr;
331 ecc_err_cnt_sel_addr =
332 SOC15_REG_OFFSET(UMC, 0,
333 regUMCCH0_0_EccErrCntSel);
335 SOC15_REG_OFFSET(UMC, 0,
336 regUMCCH0_0_EccErrCnt);
338 /* select the lower chip */
339 ecc_err_cnt_sel = RREG32_PCIE((ecc_err_cnt_sel_addr +
340 umc_reg_offset) * 4);
341 ecc_err_cnt_sel = REG_SET_FIELD(ecc_err_cnt_sel,
342 UMCCH0_0_EccErrCntSel,
344 WREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4,
347 /* clear lower chip error count */
348 WREG32_PCIE((ecc_err_cnt_addr + umc_reg_offset) * 4,
349 UMC_V6_7_CE_CNT_INIT);
351 /* select the higher chip */
352 ecc_err_cnt_sel = RREG32_PCIE((ecc_err_cnt_sel_addr +
353 umc_reg_offset) * 4);
354 ecc_err_cnt_sel = REG_SET_FIELD(ecc_err_cnt_sel,
355 UMCCH0_0_EccErrCntSel,
357 WREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4,
360 /* clear higher chip error count */
361 WREG32_PCIE((ecc_err_cnt_addr + umc_reg_offset) * 4,
362 UMC_V6_7_CE_CNT_INIT);
365 static void umc_v6_7_reset_error_count(struct amdgpu_device *adev)
367 uint32_t umc_inst = 0;
368 uint32_t ch_inst = 0;
369 uint32_t umc_reg_offset = 0;
371 LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
372 umc_reg_offset = get_umc_v6_7_reg_offset(adev,
376 umc_v6_7_reset_error_count_per_channel(adev,
381 static void umc_v6_7_query_ras_error_count(struct amdgpu_device *adev,
382 void *ras_error_status)
384 struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;
386 uint32_t umc_inst = 0;
387 uint32_t ch_inst = 0;
388 uint32_t umc_reg_offset = 0;
390 /*TODO: driver needs to toggle DF Cstate to ensure
391 * safe access of UMC registers. Will add the protection */
392 LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
393 umc_reg_offset = get_umc_v6_7_reg_offset(adev,
396 umc_v6_7_query_correctable_error_count(adev,
398 &(err_data->ce_count));
399 umc_v6_7_querry_uncorrectable_error_count(adev,
401 &(err_data->ue_count));
404 umc_v6_7_reset_error_count(adev);
407 static void umc_v6_7_query_error_address(struct amdgpu_device *adev,
408 struct ras_err_data *err_data,
409 uint32_t umc_reg_offset,
413 uint32_t mc_umc_status_addr;
414 uint32_t channel_index;
415 uint64_t mc_umc_status, mc_umc_addrt0;
416 uint64_t err_addr, soc_pa, retired_page, column;
419 SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_STATUST0);
421 SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_ADDRT0);
423 mc_umc_status = RREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4);
425 if (mc_umc_status == 0)
428 if (!err_data->err_addr) {
429 /* clear umc status */
430 WREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4, 0x0ULL);
435 adev->umc.channel_idx_tbl[umc_inst * adev->umc.channel_inst_num + ch_inst];
437 /* calculate error address if ue/ce error is detected */
438 if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1 &&
439 (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC) == 1 ||
440 REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, CECC) == 1)) {
442 err_addr = RREG64_PCIE((mc_umc_addrt0 + umc_reg_offset) * 4);
443 err_addr = REG_GET_FIELD(err_addr, MCA_UMC_UMC0_MCUMC_ADDRT0, ErrorAddr);
445 /* translate umc channel address to soc pa, 3 parts are included */
446 soc_pa = ADDR_OF_8KB_BLOCK(err_addr) |
447 ADDR_OF_256B_BLOCK(channel_index) |
448 OFFSET_IN_256B_BLOCK(err_addr);
450 /* The umc channel bits are not original values, they are hashed */
451 SET_CHANNEL_HASH(channel_index, soc_pa);
453 /* clear [C4 C3 C2] in soc physical address */
454 soc_pa &= ~(0x7ULL << UMC_V6_7_PA_C2_BIT);
456 /* we only save ue error information currently, ce is skipped */
457 if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC)
459 /* loop for all possibilities of [C4 C3 C2] */
460 for (column = 0; column < UMC_V6_7_NA_MAP_PA_NUM; column++) {
461 retired_page = soc_pa | (column << UMC_V6_7_PA_C2_BIT);
462 dev_info(adev->dev, "Error Address(PA): 0x%llx\n", retired_page);
463 amdgpu_umc_fill_error_record(err_data, err_addr,
464 retired_page, channel_index, umc_inst);
467 retired_page ^= (0x1ULL << UMC_V6_7_PA_R14_BIT);
468 dev_info(adev->dev, "Error Address(PA): 0x%llx\n", retired_page);
469 amdgpu_umc_fill_error_record(err_data, err_addr,
470 retired_page, channel_index, umc_inst);
475 /* clear umc status */
476 WREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4, 0x0ULL);
479 static void umc_v6_7_query_ras_error_address(struct amdgpu_device *adev,
480 void *ras_error_status)
482 struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;
484 uint32_t umc_inst = 0;
485 uint32_t ch_inst = 0;
486 uint32_t umc_reg_offset = 0;
488 /*TODO: driver needs to toggle DF Cstate to ensure
489 * safe access of UMC resgisters. Will add the protection
490 * when firmware interface is ready */
491 LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
492 umc_reg_offset = get_umc_v6_7_reg_offset(adev,
495 umc_v6_7_query_error_address(adev,
503 static uint32_t umc_v6_7_query_ras_poison_mode_per_channel(
504 struct amdgpu_device *adev,
505 uint32_t umc_reg_offset)
507 uint32_t ecc_ctrl_addr, ecc_ctrl;
510 SOC15_REG_OFFSET(UMC, 0, regUMCCH0_0_EccCtrl);
511 ecc_ctrl = RREG32_PCIE((ecc_ctrl_addr +
512 umc_reg_offset) * 4);
514 return REG_GET_FIELD(ecc_ctrl, UMCCH0_0_EccCtrl, UCFatalEn);
517 static bool umc_v6_7_query_ras_poison_mode(struct amdgpu_device *adev)
519 uint32_t umc_reg_offset = 0;
521 /* Enabling fatal error in umc instance0 channel0 will be
522 * considered as fatal error mode
524 umc_reg_offset = get_umc_v6_7_reg_offset(adev, 0, 0);
525 return !umc_v6_7_query_ras_poison_mode_per_channel(adev, umc_reg_offset);
528 const struct amdgpu_ras_block_hw_ops umc_v6_7_ras_hw_ops = {
529 .query_ras_error_count = umc_v6_7_query_ras_error_count,
530 .query_ras_error_address = umc_v6_7_query_ras_error_address,
533 struct amdgpu_umc_ras umc_v6_7_ras = {
535 .hw_ops = &umc_v6_7_ras_hw_ops,
537 .query_ras_poison_mode = umc_v6_7_query_ras_poison_mode,
538 .ecc_info_query_ras_error_count = umc_v6_7_ecc_info_query_ras_error_count,
539 .ecc_info_query_ras_error_address = umc_v6_7_ecc_info_query_ras_error_address,