xref: /linux/drivers/gpu/drm/amd/amdgpu/umc_v12_0.c (revision be239684b18e1cdcafcf8c7face4a2f562c745ad)
1 /*
2  * Copyright 2023 Advanced Micro Devices, Inc.
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  *
22  */
23 #include "umc_v12_0.h"
24 #include "amdgpu_ras.h"
25 #include "amdgpu_umc.h"
26 #include "amdgpu.h"
27 #include "umc/umc_12_0_0_offset.h"
28 #include "umc/umc_12_0_0_sh_mask.h"
29 #include "mp/mp_13_0_6_sh_mask.h"
30 
31 const uint32_t
32 	umc_v12_0_channel_idx_tbl[]
33 			[UMC_V12_0_UMC_INSTANCE_NUM]
34 			[UMC_V12_0_CHANNEL_INSTANCE_NUM] = {
35 		{{3,   7,   11,  15,  2,   6,   10,  14},  {1,   5,   9,   13,  0,   4,   8,   12},
36 		 {19,  23,  27,  31,  18,  22,  26,  30},  {17,  21,  25,  29,  16,  20,  24,  28}},
37 		{{47,  43,  39,  35,  46,  42,  38,  34},  {45,  41,  37,  33,  44,  40,  36,  32},
38 		 {63,  59,  55,  51,  62,  58,  54,  50},  {61,  57,  53,  49,  60,  56,  52,  48}},
39 		{{79,  75,  71,  67,  78,  74,  70,  66},  {77,  73,  69,  65,  76,  72,  68,  64},
40 		 {95,  91,  87,  83,  94,  90,  86,  82},  {93,  89,  85,  81,  92,  88,  84,  80}},
41 		{{99,  103, 107, 111, 98,  102, 106, 110}, {97,  101, 105, 109, 96,  100, 104, 108},
42 		 {115, 119, 123, 127, 114, 118, 122, 126}, {113, 117, 121, 125, 112, 116, 120, 124}}
43 	};
44 
45 /* mapping of MCA error address to normalized address */
46 static const uint32_t umc_v12_0_ma2na_mapping[] = {
47 	0,  5,  6,  8,  9,  14, 12, 13,
48 	10, 11, 15, 16, 17, 18, 19, 20,
49 	21, 22, 23, 24, 25, 26, 27, 28,
50 	24, 7,  29, 30,
51 };
52 
53 static inline uint64_t get_umc_v12_0_reg_offset(struct amdgpu_device *adev,
54 					    uint32_t node_inst,
55 					    uint32_t umc_inst,
56 					    uint32_t ch_inst)
57 {
58 	uint32_t index = umc_inst * adev->umc.channel_inst_num + ch_inst;
59 	uint64_t cross_node_offset = (node_inst == 0) ? 0 : UMC_V12_0_CROSS_NODE_OFFSET;
60 
61 	umc_inst = index / 4;
62 	ch_inst = index % 4;
63 
64 	return adev->umc.channel_offs * ch_inst + UMC_V12_0_INST_DIST * umc_inst +
65 		UMC_V12_0_NODE_DIST * node_inst + cross_node_offset;
66 }
67 
68 static int umc_v12_0_reset_error_count_per_channel(struct amdgpu_device *adev,
69 					uint32_t node_inst, uint32_t umc_inst,
70 					uint32_t ch_inst, void *data)
71 {
72 	uint64_t odecc_err_cnt_addr;
73 	uint64_t umc_reg_offset =
74 		get_umc_v12_0_reg_offset(adev, node_inst, umc_inst, ch_inst);
75 
76 	odecc_err_cnt_addr =
77 		SOC15_REG_OFFSET(UMC, 0, regUMCCH0_OdEccErrCnt);
78 
79 	/* clear error count */
80 	WREG32_PCIE_EXT((odecc_err_cnt_addr + umc_reg_offset) * 4,
81 			UMC_V12_0_CE_CNT_INIT);
82 
83 	return 0;
84 }
85 
86 static void umc_v12_0_reset_error_count(struct amdgpu_device *adev)
87 {
88 	amdgpu_umc_loop_channels(adev,
89 		umc_v12_0_reset_error_count_per_channel, NULL);
90 }
91 
92 bool umc_v12_0_is_deferred_error(struct amdgpu_device *adev, uint64_t mc_umc_status)
93 {
94 	dev_info(adev->dev,
95 		"MCA_UMC_STATUS(0x%llx): Val:%llu, Poison:%llu, Deferred:%llu, PCC:%llu, UC:%llu, TCC:%llu\n",
96 		mc_umc_status,
97 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val),
98 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Poison),
99 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Deferred),
100 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, PCC),
101 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UC),
102 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, TCC)
103 	);
104 
105 	return (amdgpu_ras_is_poison_mode_supported(adev) &&
106 		(REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1) &&
107 		(REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Deferred) == 1));
108 }
109 
110 bool umc_v12_0_is_uncorrectable_error(struct amdgpu_device *adev, uint64_t mc_umc_status)
111 {
112 	if (umc_v12_0_is_deferred_error(adev, mc_umc_status))
113 		return false;
114 
115 	return ((REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1) &&
116 		(REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, PCC) == 1 ||
117 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UC) == 1 ||
118 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, TCC) == 1));
119 }
120 
121 bool umc_v12_0_is_correctable_error(struct amdgpu_device *adev, uint64_t mc_umc_status)
122 {
123 	if (umc_v12_0_is_deferred_error(adev, mc_umc_status))
124 		return false;
125 
126 	return (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1 &&
127 		(REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, CECC) == 1 ||
128 		(REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC) == 1 &&
129 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UC) == 0) ||
130 		/* Identify data parity error in replay mode */
131 		((REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, ErrorCodeExt) == 0x5 ||
132 		REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, ErrorCodeExt) == 0xb) &&
133 		!(umc_v12_0_is_uncorrectable_error(adev, mc_umc_status)))));
134 }
135 
136 static void umc_v12_0_query_error_count_per_type(struct amdgpu_device *adev,
137 						   uint64_t umc_reg_offset,
138 						   unsigned long *error_count,
139 						   check_error_type_func error_type_func)
140 {
141 	uint64_t mc_umc_status;
142 	uint64_t mc_umc_status_addr;
143 
144 	mc_umc_status_addr =
145 		SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_STATUST0);
146 
147 	/* Check MCUMC_STATUS */
148 	mc_umc_status =
149 		RREG64_PCIE_EXT((mc_umc_status_addr + umc_reg_offset) * 4);
150 
151 	if (error_type_func(adev, mc_umc_status))
152 		*error_count += 1;
153 }
154 
155 static int umc_v12_0_query_error_count(struct amdgpu_device *adev,
156 					uint32_t node_inst, uint32_t umc_inst,
157 					uint32_t ch_inst, void *data)
158 {
159 	struct ras_err_data *err_data = (struct ras_err_data *)data;
160 	unsigned long ue_count = 0, ce_count = 0, de_count = 0;
161 
162 	/* NOTE: node_inst is converted by adev->umc.active_mask and the range is [0-3],
163 	 * which can be used as die ID directly */
164 	struct amdgpu_smuio_mcm_config_info mcm_info = {
165 		.socket_id = adev->smuio.funcs->get_socket_id(adev),
166 		.die_id = node_inst,
167 	};
168 
169 	uint64_t umc_reg_offset =
170 		get_umc_v12_0_reg_offset(adev, node_inst, umc_inst, ch_inst);
171 
172 	umc_v12_0_query_error_count_per_type(adev, umc_reg_offset,
173 					    &ce_count, umc_v12_0_is_correctable_error);
174 	umc_v12_0_query_error_count_per_type(adev, umc_reg_offset,
175 					    &ue_count, umc_v12_0_is_uncorrectable_error);
176 	umc_v12_0_query_error_count_per_type(adev, umc_reg_offset,
177 					    &de_count, umc_v12_0_is_deferred_error);
178 
179 	amdgpu_ras_error_statistic_ue_count(err_data, &mcm_info, NULL, ue_count);
180 	amdgpu_ras_error_statistic_ce_count(err_data, &mcm_info, NULL, ce_count);
181 	amdgpu_ras_error_statistic_de_count(err_data, &mcm_info, NULL, de_count);
182 
183 	return 0;
184 }
185 
186 static void umc_v12_0_query_ras_error_count(struct amdgpu_device *adev,
187 					   void *ras_error_status)
188 {
189 	amdgpu_umc_loop_channels(adev,
190 		umc_v12_0_query_error_count, ras_error_status);
191 
192 	umc_v12_0_reset_error_count(adev);
193 }
194 
195 static bool umc_v12_0_bit_wise_xor(uint32_t val)
196 {
197 	bool result = 0;
198 	int i;
199 
200 	for (i = 0; i < 32; i++)
201 		result = result ^ ((val >> i) & 0x1);
202 
203 	return result;
204 }
205 
206 static void umc_v12_0_mca_addr_to_pa(struct amdgpu_device *adev,
207 					uint64_t err_addr, uint32_t ch_inst, uint32_t umc_inst,
208 					uint32_t node_inst,
209 					struct ta_ras_query_address_output *addr_out)
210 {
211 	uint32_t channel_index, i;
212 	uint64_t na, soc_pa;
213 	uint32_t bank_hash0, bank_hash1, bank_hash2, bank_hash3, col, row;
214 	uint32_t bank0, bank1, bank2, bank3, bank;
215 
216 	bank_hash0 = (err_addr >> UMC_V12_0_MCA_B0_BIT) & 0x1ULL;
217 	bank_hash1 = (err_addr >> UMC_V12_0_MCA_B1_BIT) & 0x1ULL;
218 	bank_hash2 = (err_addr >> UMC_V12_0_MCA_B2_BIT) & 0x1ULL;
219 	bank_hash3 = (err_addr >> UMC_V12_0_MCA_B3_BIT) & 0x1ULL;
220 	col = (err_addr >> 1) & 0x1fULL;
221 	row = (err_addr >> 10) & 0x3fffULL;
222 
223 	/* apply bank hash algorithm */
224 	bank0 =
225 		bank_hash0 ^ (UMC_V12_0_XOR_EN0 &
226 		(umc_v12_0_bit_wise_xor(col & UMC_V12_0_COL_XOR0) ^
227 		(umc_v12_0_bit_wise_xor(row & UMC_V12_0_ROW_XOR0))));
228 	bank1 =
229 		bank_hash1 ^ (UMC_V12_0_XOR_EN1 &
230 		(umc_v12_0_bit_wise_xor(col & UMC_V12_0_COL_XOR1) ^
231 		(umc_v12_0_bit_wise_xor(row & UMC_V12_0_ROW_XOR1))));
232 	bank2 =
233 		bank_hash2 ^ (UMC_V12_0_XOR_EN2 &
234 		(umc_v12_0_bit_wise_xor(col & UMC_V12_0_COL_XOR2) ^
235 		(umc_v12_0_bit_wise_xor(row & UMC_V12_0_ROW_XOR2))));
236 	bank3 =
237 		bank_hash3 ^ (UMC_V12_0_XOR_EN3 &
238 		(umc_v12_0_bit_wise_xor(col & UMC_V12_0_COL_XOR3) ^
239 		(umc_v12_0_bit_wise_xor(row & UMC_V12_0_ROW_XOR3))));
240 
241 	bank = bank0 | (bank1 << 1) | (bank2 << 2) | (bank3 << 3);
242 	err_addr &= ~0x3c0ULL;
243 	err_addr |= (bank << UMC_V12_0_MCA_B0_BIT);
244 
245 	na = 0x0;
246 	/* convert mca error address to normalized address */
247 	for (i = 1; i < ARRAY_SIZE(umc_v12_0_ma2na_mapping); i++)
248 		na |= ((err_addr >> i) & 0x1ULL) << umc_v12_0_ma2na_mapping[i];
249 
250 	channel_index =
251 		adev->umc.channel_idx_tbl[node_inst * adev->umc.umc_inst_num *
252 			adev->umc.channel_inst_num +
253 			umc_inst * adev->umc.channel_inst_num +
254 			ch_inst];
255 	/* translate umc channel address to soc pa, 3 parts are included */
256 	soc_pa = ADDR_OF_32KB_BLOCK(na) |
257 		ADDR_OF_256B_BLOCK(channel_index) |
258 		OFFSET_IN_256B_BLOCK(na);
259 
260 	/* the umc channel bits are not original values, they are hashed */
261 	UMC_V12_0_SET_CHANNEL_HASH(channel_index, soc_pa);
262 
263 	addr_out->pa.pa = soc_pa;
264 	addr_out->pa.bank = bank;
265 	addr_out->pa.channel_idx = channel_index;
266 }
267 
268 static void umc_v12_0_convert_error_address(struct amdgpu_device *adev,
269 					struct ras_err_data *err_data,
270 					struct ta_ras_query_address_input *addr_in)
271 {
272 	uint32_t col, row, row_xor, bank, channel_index;
273 	uint64_t soc_pa, retired_page, column, err_addr;
274 	struct ta_ras_query_address_output addr_out;
275 
276 	err_addr = addr_in->ma.err_addr;
277 	addr_in->addr_type = TA_RAS_MCA_TO_PA;
278 	if (psp_ras_query_address(&adev->psp, addr_in, &addr_out))
279 		/* fallback to old path if fail to get pa from psp */
280 		umc_v12_0_mca_addr_to_pa(adev, err_addr, addr_in->ma.ch_inst,
281 				addr_in->ma.umc_inst, addr_in->ma.node_inst, &addr_out);
282 
283 	soc_pa = addr_out.pa.pa;
284 	bank = addr_out.pa.bank;
285 	channel_index = addr_out.pa.channel_idx;
286 
287 	col = (err_addr >> 1) & 0x1fULL;
288 	row = (err_addr >> 10) & 0x3fffULL;
289 	row_xor = row ^ (0x1ULL << 13);
290 	/* clear [C3 C2] in soc physical address */
291 	soc_pa &= ~(0x3ULL << UMC_V12_0_PA_C2_BIT);
292 	/* clear [C4] in soc physical address */
293 	soc_pa &= ~(0x1ULL << UMC_V12_0_PA_C4_BIT);
294 
295 	/* loop for all possibilities of [C4 C3 C2] */
296 	for (column = 0; column < UMC_V12_0_NA_MAP_PA_NUM; column++) {
297 		retired_page = soc_pa | ((column & 0x3) << UMC_V12_0_PA_C2_BIT);
298 		retired_page |= (((column & 0x4) >> 2) << UMC_V12_0_PA_C4_BIT);
299 		/* include column bit 0 and 1 */
300 		col &= 0x3;
301 		col |= (column << 2);
302 		dev_info(adev->dev,
303 			"Error Address(PA):0x%-10llx Row:0x%-4x Col:0x%-2x Bank:0x%x Channel:0x%x\n",
304 			retired_page, row, col, bank, channel_index);
305 		amdgpu_umc_fill_error_record(err_data, err_addr,
306 			retired_page, channel_index, addr_in->ma.umc_inst);
307 
308 		/* shift R13 bit */
309 		retired_page ^= (0x1ULL << UMC_V12_0_PA_R13_BIT);
310 		dev_info(adev->dev,
311 			"Error Address(PA):0x%-10llx Row:0x%-4x Col:0x%-2x Bank:0x%x Channel:0x%x\n",
312 			retired_page, row_xor, col, bank, channel_index);
313 		amdgpu_umc_fill_error_record(err_data, err_addr,
314 			retired_page, channel_index, addr_in->ma.umc_inst);
315 	}
316 }
317 
318 static int umc_v12_0_query_error_address(struct amdgpu_device *adev,
319 					uint32_t node_inst, uint32_t umc_inst,
320 					uint32_t ch_inst, void *data)
321 {
322 	struct ras_err_data *err_data = (struct ras_err_data *)data;
323 	struct ta_ras_query_address_input addr_in;
324 	uint64_t mc_umc_status_addr;
325 	uint64_t mc_umc_status, err_addr;
326 	uint64_t mc_umc_addrt0;
327 	uint64_t umc_reg_offset =
328 		get_umc_v12_0_reg_offset(adev, node_inst, umc_inst, ch_inst);
329 
330 	mc_umc_status_addr =
331 		SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_STATUST0);
332 
333 	mc_umc_status = RREG64_PCIE_EXT((mc_umc_status_addr + umc_reg_offset) * 4);
334 
335 	if (mc_umc_status == 0)
336 		return 0;
337 
338 	if (!err_data->err_addr) {
339 		/* clear umc status */
340 		WREG64_PCIE_EXT((mc_umc_status_addr + umc_reg_offset) * 4, 0x0ULL);
341 
342 		return 0;
343 	}
344 
345 	/* calculate error address if ue error is detected */
346 	if (umc_v12_0_is_uncorrectable_error(adev, mc_umc_status) ||
347 	    umc_v12_0_is_deferred_error(adev, mc_umc_status)) {
348 		mc_umc_addrt0 =
349 			SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_ADDRT0);
350 
351 		err_addr = RREG64_PCIE_EXT((mc_umc_addrt0 + umc_reg_offset) * 4);
352 
353 		err_addr = REG_GET_FIELD(err_addr, MCA_UMC_UMC0_MCUMC_ADDRT0, ErrorAddr);
354 
355 		if (!adev->aid_mask &&
356 		    adev->smuio.funcs &&
357 		    adev->smuio.funcs->get_socket_id)
358 			addr_in.ma.socket_id = adev->smuio.funcs->get_socket_id(adev);
359 		else
360 			addr_in.ma.socket_id = 0;
361 
362 		addr_in.ma.err_addr = err_addr;
363 		addr_in.ma.ch_inst = ch_inst;
364 		addr_in.ma.umc_inst = umc_inst;
365 		addr_in.ma.node_inst = node_inst;
366 
367 		umc_v12_0_convert_error_address(adev, err_data, &addr_in);
368 	}
369 
370 	/* clear umc status */
371 	WREG64_PCIE_EXT((mc_umc_status_addr + umc_reg_offset) * 4, 0x0ULL);
372 
373 	return 0;
374 }
375 
376 static void umc_v12_0_query_ras_error_address(struct amdgpu_device *adev,
377 					     void *ras_error_status)
378 {
379 	amdgpu_umc_loop_channels(adev,
380 		umc_v12_0_query_error_address, ras_error_status);
381 }
382 
383 static int umc_v12_0_err_cnt_init_per_channel(struct amdgpu_device *adev,
384 					uint32_t node_inst, uint32_t umc_inst,
385 					uint32_t ch_inst, void *data)
386 {
387 	uint32_t odecc_cnt_sel;
388 	uint64_t odecc_cnt_sel_addr, odecc_err_cnt_addr;
389 	uint64_t umc_reg_offset =
390 		get_umc_v12_0_reg_offset(adev, node_inst, umc_inst, ch_inst);
391 
392 	odecc_cnt_sel_addr =
393 		SOC15_REG_OFFSET(UMC, 0, regUMCCH0_OdEccCntSel);
394 	odecc_err_cnt_addr =
395 		SOC15_REG_OFFSET(UMC, 0, regUMCCH0_OdEccErrCnt);
396 
397 	odecc_cnt_sel = RREG32_PCIE_EXT((odecc_cnt_sel_addr + umc_reg_offset) * 4);
398 
399 	/* set ce error interrupt type to APIC based interrupt */
400 	odecc_cnt_sel = REG_SET_FIELD(odecc_cnt_sel, UMCCH0_OdEccCntSel,
401 					OdEccErrInt, 0x1);
402 	WREG32_PCIE_EXT((odecc_cnt_sel_addr + umc_reg_offset) * 4, odecc_cnt_sel);
403 
404 	/* set error count to initial value */
405 	WREG32_PCIE_EXT((odecc_err_cnt_addr + umc_reg_offset) * 4, UMC_V12_0_CE_CNT_INIT);
406 
407 	return 0;
408 }
409 
410 static void umc_v12_0_ecc_info_query_ras_error_count(struct amdgpu_device *adev,
411 					void *ras_error_status)
412 {
413 	struct ras_query_context qctx;
414 
415 	memset(&qctx, 0, sizeof(qctx));
416 	qctx.event_id = amdgpu_ras_acquire_event_id(adev, amdgpu_ras_intr_triggered() ?
417 						    RAS_EVENT_TYPE_ISR : RAS_EVENT_TYPE_INVALID);
418 
419 	amdgpu_mca_smu_log_ras_error(adev,
420 		AMDGPU_RAS_BLOCK__UMC, AMDGPU_MCA_ERROR_TYPE_CE, ras_error_status, &qctx);
421 	amdgpu_mca_smu_log_ras_error(adev,
422 		AMDGPU_RAS_BLOCK__UMC, AMDGPU_MCA_ERROR_TYPE_UE, ras_error_status, &qctx);
423 }
424 
425 static void umc_v12_0_ecc_info_query_ras_error_address(struct amdgpu_device *adev,
426 					void *ras_error_status)
427 {
428 	struct ras_err_node *err_node;
429 	uint64_t mc_umc_status;
430 	struct ras_err_info *err_info;
431 	struct ras_err_addr *mca_err_addr, *tmp;
432 	struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;
433 	struct ta_ras_query_address_input addr_in;
434 
435 	for_each_ras_error(err_node, err_data) {
436 		err_info = &err_node->err_info;
437 		if (list_empty(&err_info->err_addr_list))
438 			continue;
439 
440 		addr_in.ma.node_inst = err_info->mcm_info.die_id;
441 		addr_in.ma.socket_id = err_info->mcm_info.socket_id;
442 
443 		list_for_each_entry_safe(mca_err_addr, tmp, &err_info->err_addr_list, node) {
444 			mc_umc_status = mca_err_addr->err_status;
445 			if (mc_umc_status &&
446 				(umc_v12_0_is_uncorrectable_error(adev, mc_umc_status) ||
447 				 umc_v12_0_is_deferred_error(adev, mc_umc_status))) {
448 				uint64_t mca_addr, err_addr, mca_ipid;
449 				uint32_t InstanceIdLo;
450 
451 				mca_addr = mca_err_addr->err_addr;
452 				mca_ipid = mca_err_addr->err_ipid;
453 
454 				err_addr = REG_GET_FIELD(mca_addr,
455 							MCA_UMC_UMC0_MCUMC_ADDRT0, ErrorAddr);
456 				InstanceIdLo = REG_GET_FIELD(mca_ipid, MCMP1_IPIDT0, InstanceIdLo);
457 
458 				addr_in.ma.err_addr = err_addr;
459 				addr_in.ma.ch_inst = MCA_IPID_LO_2_UMC_CH(InstanceIdLo);
460 				addr_in.ma.umc_inst = MCA_IPID_LO_2_UMC_INST(InstanceIdLo);
461 
462 				dev_info(adev->dev, "UMC:IPID:0x%llx, aid:%d, inst:%d, ch:%d, err_addr:0x%llx\n",
463 					mca_ipid,
464 					err_info->mcm_info.die_id,
465 					MCA_IPID_LO_2_UMC_INST(InstanceIdLo),
466 					MCA_IPID_LO_2_UMC_CH(InstanceIdLo),
467 					err_addr);
468 
469 				umc_v12_0_convert_error_address(adev,
470 					err_data, &addr_in);
471 			}
472 
473 			/* Delete error address node from list and free memory */
474 			amdgpu_ras_del_mca_err_addr(err_info, mca_err_addr);
475 		}
476 	}
477 }
478 
479 static bool umc_v12_0_check_ecc_err_status(struct amdgpu_device *adev,
480 			enum amdgpu_mca_error_type type, void *ras_error_status)
481 {
482 	uint64_t mc_umc_status = *(uint64_t *)ras_error_status;
483 
484 	switch (type) {
485 	case AMDGPU_MCA_ERROR_TYPE_UE:
486 		return umc_v12_0_is_uncorrectable_error(adev, mc_umc_status);
487 	case AMDGPU_MCA_ERROR_TYPE_CE:
488 		return umc_v12_0_is_correctable_error(adev, mc_umc_status);
489 	case AMDGPU_MCA_ERROR_TYPE_DE:
490 		return umc_v12_0_is_deferred_error(adev, mc_umc_status);
491 	default:
492 		return false;
493 	}
494 
495 	return false;
496 }
497 
498 static void umc_v12_0_err_cnt_init(struct amdgpu_device *adev)
499 {
500 	amdgpu_umc_loop_channels(adev,
501 		umc_v12_0_err_cnt_init_per_channel, NULL);
502 }
503 
504 static bool umc_v12_0_query_ras_poison_mode(struct amdgpu_device *adev)
505 {
506 	/*
507 	 * Force return true, because regUMCCH0_EccCtrl
508 	 * is not accessible from host side
509 	 */
510 	return true;
511 }
512 
513 const struct amdgpu_ras_block_hw_ops umc_v12_0_ras_hw_ops = {
514 	.query_ras_error_count = umc_v12_0_query_ras_error_count,
515 	.query_ras_error_address = umc_v12_0_query_ras_error_address,
516 };
517 
518 static int umc_v12_0_aca_bank_parser(struct aca_handle *handle, struct aca_bank *bank,
519 				     enum aca_smu_type type, void *data)
520 {
521 	struct amdgpu_device *adev = handle->adev;
522 	struct aca_bank_info info;
523 	enum aca_error_type err_type;
524 	u64 status, count;
525 	u32 ext_error_code;
526 	int ret;
527 
528 	status = bank->regs[ACA_REG_IDX_STATUS];
529 	if (umc_v12_0_is_deferred_error(adev, status))
530 		err_type = ACA_ERROR_TYPE_DEFERRED;
531 	else if (umc_v12_0_is_uncorrectable_error(adev, status))
532 		err_type = ACA_ERROR_TYPE_UE;
533 	else if (umc_v12_0_is_correctable_error(adev, status))
534 		err_type = ACA_ERROR_TYPE_CE;
535 	else
536 		return 0;
537 
538 	ret = aca_bank_info_decode(bank, &info);
539 	if (ret)
540 		return ret;
541 
542 	ext_error_code = ACA_REG__STATUS__ERRORCODEEXT(status);
543 	count = ext_error_code == 0 ?
544 		ACA_REG__MISC0__ERRCNT(bank->regs[ACA_REG_IDX_MISC0]) : 1ULL;
545 
546 	return aca_error_cache_log_bank_error(handle, &info, err_type, count);
547 }
548 
549 static const struct aca_bank_ops umc_v12_0_aca_bank_ops = {
550 	.aca_bank_parser = umc_v12_0_aca_bank_parser,
551 };
552 
553 const struct aca_info umc_v12_0_aca_info = {
554 	.hwip = ACA_HWIP_TYPE_UMC,
555 	.mask = ACA_ERROR_UE_MASK | ACA_ERROR_CE_MASK | ACA_ERROR_DEFERRED_MASK,
556 	.bank_ops = &umc_v12_0_aca_bank_ops,
557 };
558 
559 static int umc_v12_0_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *ras_block)
560 {
561 	int ret;
562 
563 	ret = amdgpu_umc_ras_late_init(adev, ras_block);
564 	if (ret)
565 		return ret;
566 
567 	ret = amdgpu_ras_bind_aca(adev, AMDGPU_RAS_BLOCK__UMC,
568 				  &umc_v12_0_aca_info, NULL);
569 	if (ret)
570 		return ret;
571 
572 	return 0;
573 }
574 
575 struct amdgpu_umc_ras umc_v12_0_ras = {
576 	.ras_block = {
577 		.hw_ops = &umc_v12_0_ras_hw_ops,
578 		.ras_late_init = umc_v12_0_ras_late_init,
579 	},
580 	.err_cnt_init = umc_v12_0_err_cnt_init,
581 	.query_ras_poison_mode = umc_v12_0_query_ras_poison_mode,
582 	.ecc_info_query_ras_error_count = umc_v12_0_ecc_info_query_ras_error_count,
583 	.ecc_info_query_ras_error_address = umc_v12_0_ecc_info_query_ras_error_address,
584 	.check_ecc_err_status = umc_v12_0_check_ecc_err_status,
585 };
586 
587