umc_v6_7.c 19.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright 2021 Advanced Micro Devices, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 */
#include "umc_v6_7.h"
#include "amdgpu_ras.h"
25
#include "amdgpu_umc.h"
26 27
#include "amdgpu.h"

28 29 30
#include "umc/umc_6_7_0_offset.h"
#include "umc/umc_6_7_0_sh_mask.h"

31 32
const uint32_t
	umc_v6_7_channel_idx_tbl_second[UMC_V6_7_UMC_INSTANCE_NUM][UMC_V6_7_CHANNEL_INSTANCE_NUM] = {
33 34 35 36
		{28, 20, 24, 16, 12, 4, 8, 0},
		{6, 30, 2, 26, 22, 14, 18, 10},
		{19, 11, 15, 7, 3, 27, 31, 23},
		{9, 1, 5, 29, 25, 17, 21, 13}
37 38 39
};
const uint32_t
	umc_v6_7_channel_idx_tbl_first[UMC_V6_7_UMC_INSTANCE_NUM][UMC_V6_7_CHANNEL_INSTANCE_NUM] = {
40 41 42 43
		{19, 11, 15, 7,	3, 27, 31, 23},
		{9, 1, 5, 29, 25, 17, 21, 13},
		{28, 20, 24, 16, 12, 4, 8, 0},
		{6, 30, 2, 26, 22, 14, 18, 10},
44 45
};

46 47 48 49
static inline uint32_t get_umc_v6_7_reg_offset(struct amdgpu_device *adev,
					      uint32_t umc_inst,
					      uint32_t ch_inst)
{
50 51 52 53 54 55 56
	uint32_t index = umc_inst * adev->umc.channel_inst_num + ch_inst;

	/* adjust umc and channel index offset,
	 * the register address is not linear on each umc instace */
	umc_inst = index / 4;
	ch_inst = index % 4;

57 58 59
	return adev->umc.channel_offs * ch_inst + UMC_V6_7_INST_DIST * umc_inst;
}

60 61 62 63 64 65 66
static inline uint32_t get_umc_v6_7_channel_index(struct amdgpu_device *adev,
					      uint32_t umc_inst,
					      uint32_t ch_inst)
{
	return adev->umc.channel_idx_tbl[umc_inst * adev->umc.channel_inst_num + ch_inst];
}

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
static void umc_v6_7_query_error_status_helper(struct amdgpu_device *adev,
						  uint64_t mc_umc_status, uint32_t umc_reg_offset)
{
	uint32_t mc_umc_addr;
	uint64_t reg_value;

	if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Deferred) == 1)
		dev_info(adev->dev, "Deferred error, no user action is needed.\n");

	if (mc_umc_status)
		dev_info(adev->dev, "MCA STATUS 0x%llx, umc_reg_offset 0x%x\n", mc_umc_status, umc_reg_offset);

	/* print IPID registers value */
	mc_umc_addr =
		SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_IPIDT0);
	reg_value = RREG64_PCIE((mc_umc_addr + umc_reg_offset) * 4);
	if (reg_value)
		dev_info(adev->dev, "MCA IPID 0x%llx, umc_reg_offset 0x%x\n", reg_value, umc_reg_offset);

	/* print SYND registers value */
	mc_umc_addr =
		SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_SYNDT0);
	reg_value = RREG64_PCIE((mc_umc_addr + umc_reg_offset) * 4);
	if (reg_value)
		dev_info(adev->dev, "MCA SYND 0x%llx, umc_reg_offset 0x%x\n", reg_value, umc_reg_offset);

	/* print MISC0 registers value */
	mc_umc_addr =
		SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_MISC0T0);
	reg_value = RREG64_PCIE((mc_umc_addr + umc_reg_offset) * 4);
	if (reg_value)
		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 104 105
						   unsigned long *error_count)
{
	uint64_t mc_umc_status;
106
	uint32_t eccinfo_table_idx;
107
	uint32_t umc_reg_offset;
108 109
	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);

110 111 112
	umc_reg_offset = get_umc_v6_7_reg_offset(adev,
						umc_inst, ch_inst);

113
	eccinfo_table_idx = umc_inst * adev->umc.channel_inst_num + ch_inst;
114 115
	/* check for SRAM correctable error
	  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) {
119
		*error_count += 1;
120 121

		umc_v6_7_query_error_status_helper(adev, mc_umc_status, umc_reg_offset);
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

		if (ras->umc_ecc.record_ce_addr_supported)	{
			uint64_t err_addr, soc_pa;
			uint32_t channel_index =
				adev->umc.channel_idx_tbl[umc_inst * adev->umc.channel_inst_num + ch_inst];

			err_addr = ras->umc_ecc.ecc[eccinfo_table_idx].mca_ceumc_addr;
			err_addr = REG_GET_FIELD(err_addr, MCA_UMC_UMC0_MCUMC_ADDRT0, ErrorAddr);
			/* translate umc channel address to soc pa, 3 parts are included */
			soc_pa = ADDR_OF_8KB_BLOCK(err_addr) |
					ADDR_OF_256B_BLOCK(channel_index) |
					OFFSET_IN_256B_BLOCK(err_addr);

			/* The umc channel bits are not original values, they are hashed */
			SET_CHANNEL_HASH(channel_index, soc_pa);

			dev_info(adev->dev, "Error Address(PA): 0x%llx\n", soc_pa);
		}
140
	}
141 142 143
}

static void umc_v6_7_ecc_info_querry_uncorrectable_error_count(struct amdgpu_device *adev,
144
							  uint32_t umc_inst, uint32_t ch_inst,
145 146 147
						      unsigned long *error_count)
{
	uint64_t mc_umc_status;
148
	uint32_t eccinfo_table_idx;
S
Stanley.Yang 已提交
149
	uint32_t umc_reg_offset;
150 151
	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);

S
Stanley.Yang 已提交
152 153 154
	umc_reg_offset = get_umc_v6_7_reg_offset(adev,
						umc_inst, ch_inst);

155
	eccinfo_table_idx = umc_inst * adev->umc.channel_inst_num + ch_inst;
156
	/* check the MCUMC_STATUS */
157
	mc_umc_status = ras->umc_ecc.ecc[eccinfo_table_idx].mca_umc_status;
158 159 160 161 162
	if ((REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1) &&
	    (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Deferred) == 1 ||
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC) == 1 ||
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, PCC) == 1 ||
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UC) == 1 ||
S
Stanley.Yang 已提交
163
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, TCC) == 1)) {
164
		*error_count += 1;
S
Stanley.Yang 已提交
165

166
		umc_v6_7_query_error_status_helper(adev, mc_umc_status, umc_reg_offset);
S
Stanley.Yang 已提交
167
	}
168 169 170 171 172 173 174 175 176 177 178 179 180 181
}

static void umc_v6_7_ecc_info_query_ras_error_count(struct amdgpu_device *adev,
					   void *ras_error_status)
{
	struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;

	uint32_t umc_inst        = 0;
	uint32_t ch_inst         = 0;

	/*TODO: driver needs to toggle DF Cstate to ensure
	 * safe access of UMC registers. Will add the protection */
	LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
		umc_v6_7_ecc_info_query_correctable_error_count(adev,
182
						      umc_inst, ch_inst,
183 184
						      &(err_data->ce_count));
		umc_v6_7_ecc_info_querry_uncorrectable_error_count(adev,
185
						      umc_inst, ch_inst,
186 187 188 189 190 191 192 193 194
							  &(err_data->ue_count));
	}
}

static void umc_v6_7_ecc_info_query_error_address(struct amdgpu_device *adev,
					 struct ras_err_data *err_data,
					 uint32_t ch_inst,
					 uint32_t umc_inst)
{
195
	uint64_t mc_umc_status, err_addr, soc_pa, retired_page, column;
196
	uint32_t channel_index;
197
	uint32_t eccinfo_table_idx;
198 199
	struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);

200
	eccinfo_table_idx = umc_inst * adev->umc.channel_inst_num + ch_inst;
201 202 203
	channel_index =
		adev->umc.channel_idx_tbl[umc_inst * adev->umc.channel_inst_num + ch_inst];

204
	mc_umc_status = ras->umc_ecc.ecc[eccinfo_table_idx].mca_umc_status;
205 206 207 208 209 210 211 212 213 214 215 216

	if (mc_umc_status == 0)
		return;

	if (!err_data->err_addr)
		return;

	/* calculate error address if ue/ce error is detected */
	if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1 &&
	    (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC) == 1 ||
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, CECC) == 1)) {

217
		err_addr = ras->umc_ecc.ecc[eccinfo_table_idx].mca_umc_addr;
218 219 220
		err_addr = REG_GET_FIELD(err_addr, MCA_UMC_UMC0_MCUMC_ADDRT0, ErrorAddr);

		/* translate umc channel address to soc pa, 3 parts are included */
221
		soc_pa = ADDR_OF_8KB_BLOCK(err_addr) |
222 223
				ADDR_OF_256B_BLOCK(channel_index) |
				OFFSET_IN_256B_BLOCK(err_addr);
224 225 226 227

		/* The umc channel bits are not original values, they are hashed */
		SET_CHANNEL_HASH(channel_index, soc_pa);

228 229
		/* clear [C4 C3 C2] in soc physical address */
		soc_pa &= ~(0x7ULL << UMC_V6_7_PA_C2_BIT);
230 231 232

		/* we only save ue error information currently, ce is skipped */
		if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC)
233 234 235 236
				== 1) {
			/* loop for all possibilities of [C4 C3 C2] */
			for (column = 0; column < UMC_V6_7_NA_MAP_PA_NUM; column++) {
				retired_page = soc_pa | (column << UMC_V6_7_PA_C2_BIT);
S
Stanley.Yang 已提交
237
				dev_info(adev->dev, "Error Address(PA): 0x%llx\n", retired_page);
238
				amdgpu_umc_fill_error_record(err_data, err_addr,
239
					retired_page, channel_index, umc_inst);
240 241 242

				/* shift R14 bit */
				retired_page ^= (0x1ULL << UMC_V6_7_PA_R14_BIT);
S
Stanley.Yang 已提交
243
				dev_info(adev->dev, "Error Address(PA): 0x%llx\n", retired_page);
244 245 246 247
				amdgpu_umc_fill_error_record(err_data, err_addr,
					retired_page, channel_index, umc_inst);
			}
		}
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
	}
}

static void umc_v6_7_ecc_info_query_ras_error_address(struct amdgpu_device *adev,
					     void *ras_error_status)
{
	struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;

	uint32_t umc_inst        = 0;
	uint32_t ch_inst         = 0;

	/*TODO: driver needs to toggle DF Cstate to ensure
	 * safe access of UMC resgisters. Will add the protection
	 * when firmware interface is ready */
	LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
		umc_v6_7_ecc_info_query_error_address(adev,
					     err_data,
					     ch_inst,
					     umc_inst);
	}
}

270 271
static void umc_v6_7_query_correctable_error_count(struct amdgpu_device *adev,
						   uint32_t umc_reg_offset,
272 273 274
						   unsigned long *error_count,
						   uint32_t ch_inst,
						   uint32_t umc_inst)
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
{
	uint32_t ecc_err_cnt_sel, ecc_err_cnt_sel_addr;
	uint32_t ecc_err_cnt, ecc_err_cnt_addr;
	uint64_t mc_umc_status;
	uint32_t mc_umc_status_addr;

	/* UMC 6_1_1 registers */
	ecc_err_cnt_sel_addr =
		SOC15_REG_OFFSET(UMC, 0, regUMCCH0_0_EccErrCntSel);
	ecc_err_cnt_addr =
		SOC15_REG_OFFSET(UMC, 0, regUMCCH0_0_EccErrCnt);
	mc_umc_status_addr =
		SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_STATUST0);

	/* select the lower chip and check the error count */
	ecc_err_cnt_sel = RREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4);
	ecc_err_cnt_sel = REG_SET_FIELD(ecc_err_cnt_sel, UMCCH0_0_EccErrCntSel,
					EccErrCntCsSel, 0);
	WREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4, ecc_err_cnt_sel);

	ecc_err_cnt = RREG32_PCIE((ecc_err_cnt_addr + umc_reg_offset) * 4);
	*error_count +=
		(REG_GET_FIELD(ecc_err_cnt, UMCCH0_0_EccErrCnt, EccErrCnt) -
		 UMC_V6_7_CE_CNT_INIT);

	/* select the higher chip and check the err counter */
	ecc_err_cnt_sel = REG_SET_FIELD(ecc_err_cnt_sel, UMCCH0_0_EccErrCntSel,
					EccErrCntCsSel, 1);
	WREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4, ecc_err_cnt_sel);

	ecc_err_cnt = RREG32_PCIE((ecc_err_cnt_addr + umc_reg_offset) * 4);
	*error_count +=
		(REG_GET_FIELD(ecc_err_cnt, UMCCH0_0_EccErrCnt, EccErrCnt) -
		 UMC_V6_7_CE_CNT_INIT);

	/* check for SRAM correctable error
	  MCUMC_STATUS is a 64 bit register */
	mc_umc_status = RREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4);
	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, CECC) == 1) {
315
		*error_count += 1;
316 317

		umc_v6_7_query_error_status_helper(adev, mc_umc_status, umc_reg_offset);
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342

		{
			uint64_t err_addr, soc_pa;
			uint32_t mc_umc_addrt0;
			uint32_t channel_index;

			mc_umc_addrt0 =
				SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_ADDRT0);

			channel_index =
				adev->umc.channel_idx_tbl[umc_inst * adev->umc.channel_inst_num + ch_inst];

			err_addr = RREG64_PCIE((mc_umc_addrt0 + umc_reg_offset) * 4);
			err_addr = REG_GET_FIELD(err_addr, MCA_UMC_UMC0_MCUMC_ADDRT0, ErrorAddr);

			/* translate umc channel address to soc pa, 3 parts are included */
			soc_pa = ADDR_OF_8KB_BLOCK(err_addr) |
					ADDR_OF_256B_BLOCK(channel_index) |
					OFFSET_IN_256B_BLOCK(err_addr);

			/* The umc channel bits are not original values, they are hashed */
			SET_CHANNEL_HASH(channel_index, soc_pa);

			dev_info(adev->dev, "Error Address(PA): 0x%llx\n", soc_pa);
		}
343
	}
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
}

static void umc_v6_7_querry_uncorrectable_error_count(struct amdgpu_device *adev,
						      uint32_t umc_reg_offset,
						      unsigned long *error_count)
{
	uint64_t mc_umc_status;
	uint32_t mc_umc_status_addr;

	mc_umc_status_addr =
		SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_STATUST0);

	/* check the MCUMC_STATUS */
	mc_umc_status = RREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4);
	if ((REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1) &&
	    (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Deferred) == 1 ||
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC) == 1 ||
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, PCC) == 1 ||
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UC) == 1 ||
S
Stanley.Yang 已提交
363
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, TCC) == 1)) {
364
		*error_count += 1;
S
Stanley.Yang 已提交
365

366
		umc_v6_7_query_error_status_helper(adev, mc_umc_status, umc_reg_offset);
S
Stanley.Yang 已提交
367
	}
368 369
}

370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
static void umc_v6_7_reset_error_count_per_channel(struct amdgpu_device *adev,
						   uint32_t umc_reg_offset)
{
	uint32_t ecc_err_cnt_addr;
	uint32_t ecc_err_cnt_sel, ecc_err_cnt_sel_addr;

	ecc_err_cnt_sel_addr =
		SOC15_REG_OFFSET(UMC, 0,
				regUMCCH0_0_EccErrCntSel);
	ecc_err_cnt_addr =
		SOC15_REG_OFFSET(UMC, 0,
				regUMCCH0_0_EccErrCnt);

	/* select the lower chip */
	ecc_err_cnt_sel = RREG32_PCIE((ecc_err_cnt_sel_addr +
				       umc_reg_offset) * 4);
	ecc_err_cnt_sel = REG_SET_FIELD(ecc_err_cnt_sel,
					UMCCH0_0_EccErrCntSel,
					EccErrCntCsSel, 0);
	WREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4,
			ecc_err_cnt_sel);

	/* clear lower chip error count */
	WREG32_PCIE((ecc_err_cnt_addr + umc_reg_offset) * 4,
			UMC_V6_7_CE_CNT_INIT);

	/* select the higher chip */
	ecc_err_cnt_sel = RREG32_PCIE((ecc_err_cnt_sel_addr +
					umc_reg_offset) * 4);
	ecc_err_cnt_sel = REG_SET_FIELD(ecc_err_cnt_sel,
					UMCCH0_0_EccErrCntSel,
					EccErrCntCsSel, 1);
	WREG32_PCIE((ecc_err_cnt_sel_addr + umc_reg_offset) * 4,
			ecc_err_cnt_sel);

	/* clear higher chip error count */
	WREG32_PCIE((ecc_err_cnt_addr + umc_reg_offset) * 4,
			UMC_V6_7_CE_CNT_INIT);
}

static void umc_v6_7_reset_error_count(struct amdgpu_device *adev)
{
	uint32_t umc_inst        = 0;
	uint32_t ch_inst         = 0;
	uint32_t umc_reg_offset  = 0;

	LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
		umc_reg_offset = get_umc_v6_7_reg_offset(adev,
							 umc_inst,
							 ch_inst);

		umc_v6_7_reset_error_count_per_channel(adev,
						       umc_reg_offset);
	}
}

static void umc_v6_7_query_ras_error_count(struct amdgpu_device *adev,
					   void *ras_error_status)
{
	struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;

	uint32_t umc_inst        = 0;
	uint32_t ch_inst         = 0;
	uint32_t umc_reg_offset  = 0;

	/*TODO: driver needs to toggle DF Cstate to ensure
	 * safe access of UMC registers. Will add the protection */
	LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
		umc_reg_offset = get_umc_v6_7_reg_offset(adev,
							 umc_inst,
							 ch_inst);
		umc_v6_7_query_correctable_error_count(adev,
						       umc_reg_offset,
443 444
						       &(err_data->ce_count),
						       ch_inst, umc_inst);
445 446 447 448 449 450 451 452
		umc_v6_7_querry_uncorrectable_error_count(adev,
							  umc_reg_offset,
							  &(err_data->ue_count));
	}

	umc_v6_7_reset_error_count(adev);
}

453 454 455 456 457 458 459 460
static void umc_v6_7_query_error_address(struct amdgpu_device *adev,
					 struct ras_err_data *err_data,
					 uint32_t umc_reg_offset,
					 uint32_t ch_inst,
					 uint32_t umc_inst)
{
	uint32_t mc_umc_status_addr;
	uint32_t channel_index;
461 462
	uint64_t mc_umc_status, mc_umc_addrt0;
	uint64_t err_addr, soc_pa, retired_page, column;
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491

	mc_umc_status_addr =
		SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_STATUST0);
	mc_umc_addrt0 =
		SOC15_REG_OFFSET(UMC, 0, regMCA_UMC_UMC0_MCUMC_ADDRT0);

	mc_umc_status = RREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4);

	if (mc_umc_status == 0)
		return;

	if (!err_data->err_addr) {
		/* clear umc status */
		WREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4, 0x0ULL);
		return;
	}

	channel_index =
		adev->umc.channel_idx_tbl[umc_inst * adev->umc.channel_inst_num + ch_inst];

	/* calculate error address if ue/ce error is detected */
	if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, Val) == 1 &&
	    (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC) == 1 ||
	    REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, CECC) == 1)) {

		err_addr = RREG64_PCIE((mc_umc_addrt0 + umc_reg_offset) * 4);
		err_addr = REG_GET_FIELD(err_addr, MCA_UMC_UMC0_MCUMC_ADDRT0, ErrorAddr);

		/* translate umc channel address to soc pa, 3 parts are included */
492
		soc_pa = ADDR_OF_8KB_BLOCK(err_addr) |
493 494
				ADDR_OF_256B_BLOCK(channel_index) |
				OFFSET_IN_256B_BLOCK(err_addr);
495 496 497 498

		/* The umc channel bits are not original values, they are hashed */
		SET_CHANNEL_HASH(channel_index, soc_pa);

499 500
		/* clear [C4 C3 C2] in soc physical address */
		soc_pa &= ~(0x7ULL << UMC_V6_7_PA_C2_BIT);
501 502 503

		/* we only save ue error information currently, ce is skipped */
		if (REG_GET_FIELD(mc_umc_status, MCA_UMC_UMC0_MCUMC_STATUST0, UECC)
504 505 506 507
				== 1) {
			/* loop for all possibilities of [C4 C3 C2] */
			for (column = 0; column < UMC_V6_7_NA_MAP_PA_NUM; column++) {
				retired_page = soc_pa | (column << UMC_V6_7_PA_C2_BIT);
S
Stanley.Yang 已提交
508
				dev_info(adev->dev, "Error Address(PA): 0x%llx\n", retired_page);
509 510 511 512 513
				amdgpu_umc_fill_error_record(err_data, err_addr,
					retired_page, channel_index, umc_inst);

				/* shift R14 bit */
				retired_page ^= (0x1ULL << UMC_V6_7_PA_R14_BIT);
S
Stanley.Yang 已提交
514
				dev_info(adev->dev, "Error Address(PA): 0x%llx\n", retired_page);
515
				amdgpu_umc_fill_error_record(err_data, err_addr,
516
					retired_page, channel_index, umc_inst);
517 518
			}
		}
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
	}

	/* clear umc status */
	WREG64_PCIE((mc_umc_status_addr + umc_reg_offset) * 4, 0x0ULL);
}

static void umc_v6_7_query_ras_error_address(struct amdgpu_device *adev,
					     void *ras_error_status)
{
	struct ras_err_data *err_data = (struct ras_err_data *)ras_error_status;

	uint32_t umc_inst        = 0;
	uint32_t ch_inst         = 0;
	uint32_t umc_reg_offset  = 0;

	/*TODO: driver needs to toggle DF Cstate to ensure
	 * safe access of UMC resgisters. Will add the protection
	 * when firmware interface is ready */
	LOOP_UMC_INST_AND_CH(umc_inst, ch_inst) {
		umc_reg_offset = get_umc_v6_7_reg_offset(adev,
							 umc_inst,
							 ch_inst);
		umc_v6_7_query_error_address(adev,
					     err_data,
					     umc_reg_offset,
					     ch_inst,
					     umc_inst);
	}
}

549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
static uint32_t umc_v6_7_query_ras_poison_mode_per_channel(
						struct amdgpu_device *adev,
						uint32_t umc_reg_offset)
{
	uint32_t ecc_ctrl_addr, ecc_ctrl;

	ecc_ctrl_addr =
		SOC15_REG_OFFSET(UMC, 0, regUMCCH0_0_EccCtrl);
	ecc_ctrl = RREG32_PCIE((ecc_ctrl_addr +
					umc_reg_offset) * 4);

	return REG_GET_FIELD(ecc_ctrl, UMCCH0_0_EccCtrl, UCFatalEn);
}

static bool umc_v6_7_query_ras_poison_mode(struct amdgpu_device *adev)
{
	uint32_t umc_reg_offset  = 0;

567 568 569 570 571
	/* Enabling fatal error in umc instance0 channel0 will be
	 * considered as fatal error mode
	 */
	umc_reg_offset = get_umc_v6_7_reg_offset(adev, 0, 0);
	return !umc_v6_7_query_ras_poison_mode_per_channel(adev, umc_reg_offset);
572 573
}

574
const struct amdgpu_ras_block_hw_ops umc_v6_7_ras_hw_ops = {
575
	.query_ras_error_count = umc_v6_7_query_ras_error_count,
576
	.query_ras_error_address = umc_v6_7_query_ras_error_address,
577 578 579 580 581 582
};

struct amdgpu_umc_ras umc_v6_7_ras = {
	.ras_block = {
		.hw_ops = &umc_v6_7_ras_hw_ops,
	},
583
	.query_ras_poison_mode = umc_v6_7_query_ras_poison_mode,
584 585
	.ecc_info_query_ras_error_count = umc_v6_7_ecc_info_query_ras_error_count,
	.ecc_info_query_ras_error_address = umc_v6_7_ecc_info_query_ras_error_address,
586
};