[PATCH 005/109] drm/amd/ras: Parse error type of MCE and encode CPER

Alex Deucher <[email protected]>
Newsgroups org.freedesktop.lists.amd-gfx
Message-ID <[email protected]>
From: YiPeng Chai <[email protected]>

Introduce MCE type ras log event.
Parse error type of MCE and encode to corresponding CPER.

Signed-off-by: Xiang Liu <[email protected]>
Signed-off-by: YiPeng Chai <[email protected]>
Reviewed-by: Hawking Zhang <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
---
 drivers/gpu/drm/amd/ras/core/log_ring.h |  1 +
 drivers/gpu/drm/amd/ras/core/ras_cper.c | 28 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/drivers/gpu/drm/amd/ras/core/log_ring.h b/drivers/gpu/drm/amd/ras/core/log_ring.h
index a1ef2f24130c0..13973add0e5cb 100644
--- a/drivers/gpu/drm/amd/ras/core/log_ring.h
+++ b/drivers/gpu/drm/amd/ras/core/log_ring.h
@@ -37,6 +37,7 @@ enum ras_log_event {
 	RAS_LOG_EVENT_POISON_CREATION,
 	RAS_LOG_EVENT_POISON_CONSUMPTION,
 	RAS_LOG_EVENT_RMA,
+	RAS_LOG_EVENT_MCE,
 	RAS_LOG_EVENT_COUNT_MAX,
 };
 
diff --git a/drivers/gpu/drm/amd/ras/core/ras_cper.c b/drivers/gpu/drm/amd/ras/core/ras_cper.c
index dd95e6891bcf2..fb37c7cc29142 100644
--- a/drivers/gpu/drm/amd/ras/core/ras_cper.c
+++ b/drivers/gpu/drm/amd/ras/core/ras_cper.c
@@ -270,6 +270,26 @@ static enum ras_cper_type cper_ras_log_event_to_cper_type(enum ras_log_event eve
 	}
 }
 
+static enum ras_log_event cper_mce_parse_err_type(struct ras_core_context *ras_core,
+						  struct aca_bank_reg *bank)
+{
+	struct aca_bank_ecc bank_err = {0};
+
+	if (ras_aca_parse_bank(ras_core, bank, &bank_err))
+		return RAS_LOG_EVENT_NONE;
+
+	if (bank_err.ue_count)
+		return RAS_LOG_EVENT_UE;
+
+	if (bank_err.ce_count)
+		return RAS_LOG_EVENT_CE;
+
+	if (bank_err.de_count)
+		return RAS_LOG_EVENT_DE;
+
+	return RAS_LOG_EVENT_NONE;
+}
+
 int ras_cper_generate_cper(struct ras_core_context *ras_core,
 		struct ras_log_info *trace_list, uint32_t count,
 		uint8_t *buf, uint32_t buf_len, uint32_t *real_data_len)
@@ -279,6 +299,14 @@ int ras_cper_generate_cper(struct ras_core_context *ras_core,
 	int record_size, saved_size = 0;
 	struct cper_section_hdr *hdr;
 
+	if (trace_list[0].event == RAS_LOG_EVENT_MCE) {
+		struct aca_bank_reg bank = { 0 };
+
+		/* MCE is encoded as 1 record each */
+		memcpy(&bank.regs, &trace_list[0].aca_reg.regs, sizeof(bank.regs));
+		trace_list[0].event = cper_mce_parse_err_type(ras_core, &bank);
+	}
+
 	/* All the batch traces share the same event */
 	record_size = cper_get_record_size(
 			cper_ras_log_event_to_cper_type(trace_list[0].event), count);
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.