krishnanadh / rpms / rasdaemon

Forked from rpms/rasdaemon a year ago
Clone
9fadc0
commit 738bafafdcb2e8b0ced32fff31b13754d571090b
9fadc0
Author: Jason Tian <jason@os.amperecomputing.com>
9fadc0
Date:   Fri May 28 11:35:43 2021 +0800
9fadc0
9fadc0
    Add error handling for Ampere-specific errors.
9fadc0
    
9fadc0
    Save Ampere-specific errors' decode into sqlite3 data
9fadc0
    base and log PCIe segment, bus/device/function number
9fadc0
    into BMC SEL.
9fadc0
    
9fadc0
    Signed-off-by: Jason Tian <jason@os.amperecomputing.com>
9fadc0
    Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
9fadc0
9fadc0
diff --git a/non-standard-ampere.c b/non-standard-ampere.c
9fadc0
index 8cceb26..05b5252 100644
9fadc0
--- a/non-standard-ampere.c
9fadc0
+++ b/non-standard-ampere.c
9fadc0
@@ -216,6 +216,13 @@ static const char * const err_bert_sub_type[] = {
9fadc0
 	"PMPRO Fatal",
9fadc0
 };
9fadc0
 
9fadc0
+static char *sqlite3_table_list[] = {
9fadc0
+	"amp_payload0_event_tab",
9fadc0
+	"amp_payload1_event_tab",
9fadc0
+	"amp_payload2_event_tab",
9fadc0
+	"amp_payload3_event_tab",
9fadc0
+};
9fadc0
+
9fadc0
 struct amp_ras_type_info {
9fadc0
 	int id;
9fadc0
 	const char *name;
9fadc0
@@ -352,6 +359,359 @@ static const char *oem_subtype_name(const struct amp_ras_type_info *info,
9fadc0
 	return "unknown";
9fadc0
 }
9fadc0
 
9fadc0
+#ifdef HAVE_SQLITE3
9fadc0
+/*key pair definition for ampere specific error payload type 0*/
9fadc0
+static const struct db_fields amp_payload0_event_fields[] = {
9fadc0
+	{ .name = "id",			.type = "INTEGER PRIMARY KEY" },
9fadc0
+	{ .name = "timestamp",          .type = "TEXT" },
9fadc0
+	{ .name = "type",		.type = "TEXT" },
9fadc0
+	{ .name = "subtype",		.type = "TEXT" },
9fadc0
+	{ .name = "instance",		.type = "INTEGER" },
9fadc0
+	{ .name = "socket_num",		.type = "INTEGER" },
9fadc0
+	{ .name = "status_reg",		.type = "INTEGER" },
9fadc0
+	{ .name = "addr_reg",		.type = "INTEGER" },
9fadc0
+	{ .name = "misc0",		.type = "INTEGER" },
9fadc0
+	{ .name = "misc1",		.type = "INTEGER" },
9fadc0
+	{ .name = "misc2",		.type = "INTEGER" },
9fadc0
+	{ .name = "misc3",		.type = "INTEGER" },
9fadc0
+};
9fadc0
+
9fadc0
+static const struct db_table_descriptor amp_payload0_event_tab = {
9fadc0
+	.name = "amp_payload0_event",
9fadc0
+	.fields = amp_payload0_event_fields,
9fadc0
+	.num_fields = ARRAY_SIZE(amp_payload0_event_fields),
9fadc0
+};
9fadc0
+
9fadc0
+/*key pair definition for ampere specific error payload type 1*/
9fadc0
+static const struct db_fields amp_payload1_event_fields[] = {
9fadc0
+	{ .name = "id",			.type = "INTEGER PRIMARY KEY" },
9fadc0
+	{ .name = "timestamp",          .type = "TEXT" },
9fadc0
+	{ .name = "type",		.type = "TEXT" },
9fadc0
+	{ .name = "subtype",		.type = "TEXT" },
9fadc0
+	{ .name = "instance",		.type = "INTEGER" },
9fadc0
+	{ .name = "socket_num",		.type = "INTEGER" },
9fadc0
+	{ .name = "uncore_err_status",	.type = "INTEGER" },
9fadc0
+	{ .name = "uncore_err_mask",	.type = "INTEGER" },
9fadc0
+	{ .name = "uncore_err_sev",	.type = "INTEGER" },
9fadc0
+	{ .name = "core_err_status",	.type = "INTEGER" },
9fadc0
+	{ .name = "core_err_mask",	.type = "INTEGER" },
9fadc0
+	{ .name = "root_err_cmd",	.type = "INTEGER" },
9fadc0
+	{ .name = "root_err_status",	.type = "INTEGER" },
9fadc0
+	{ .name = "src_id",		.type = "INTEGER" },
9fadc0
+	{ .name = "reserved1",		.type = "INTEGER" },
9fadc0
+	{ .name = "reserverd2",		.type = "INTEGER" },
9fadc0
+};
9fadc0
+
9fadc0
+static const struct db_table_descriptor amp_payload1_event_tab = {
9fadc0
+	.name = "amp_payload1_event",
9fadc0
+	.fields = amp_payload1_event_fields,
9fadc0
+	.num_fields = ARRAY_SIZE(amp_payload1_event_fields),
9fadc0
+};
9fadc0
+
9fadc0
+/*key pair definition for ampere specific error payload type 2*/
9fadc0
+static const struct db_fields amp_payload2_event_fields[] = {
9fadc0
+	{ .name = "id",                 .type = "INTEGER PRIMARY KEY" },
9fadc0
+	{ .name = "timestamp",          .type = "TEXT" },
9fadc0
+	{ .name = "type",		.type = "TEXT" },
9fadc0
+	{ .name = "subtype",		.type = "TEXT" },
9fadc0
+	{ .name = "instance",		.type = "INTEGER" },
9fadc0
+	{ .name = "socket_num",		.type = "INTEGER" },
9fadc0
+	{ .name = "ce_report_reg",	.type = "INTEGER" },
9fadc0
+	{ .name = "ce_location",	.type = "INTEGER" },
9fadc0
+	{ .name = "ce_addr",		.type = "INTEGER" },
9fadc0
+	{ .name = "ue_report_reg",	.type = "INTEGER" },
9fadc0
+	{ .name = "ue_location",	.type = "INTEGER" },
9fadc0
+	{ .name = "ue_addr",		.type = "INTEGER" },
9fadc0
+	{ .name = "reserved1",		.type = "INTEGER" },
9fadc0
+	{ .name = "reserved2",		.type = "INTEGER" },
9fadc0
+	{ .name = "reserved2",		.type = "INTEGER" },
9fadc0
+};
9fadc0
+
9fadc0
+static const struct db_table_descriptor amp_payload2_event_tab = {
9fadc0
+	.name = "amp_payload2_event",
9fadc0
+	.fields = amp_payload2_event_fields,
9fadc0
+	.num_fields = ARRAY_SIZE(amp_payload2_event_fields),
9fadc0
+};
9fadc0
+
9fadc0
+/*key pair definition for ampere specific error payload type 3*/
9fadc0
+static const struct db_fields amp_payload3_event_fields[] = {
9fadc0
+	{ .name = "id",                 .type = "INTEGER PRIMARY KEY" },
9fadc0
+	{ .name = "timestamp",          .type = "TEXT" },
9fadc0
+	{ .name = "type",		.type = "TEXT" },
9fadc0
+	{ .name = "subtype",		.type = "TEXT" },
9fadc0
+	{ .name = "instance",		.type = "INTEGER" },
9fadc0
+	{ .name = "socket_num",		.type = "INTEGER" },
9fadc0
+	{ .name = "fw_spec_data0",	.type = "INTEGER" },
9fadc0
+	{ .name = "fw_spec_data1",	.type = "INTEGER" },
9fadc0
+	{ .name = "fw_spec_data2",	.type = "INTEGER" },
9fadc0
+	{ .name = "fw_spec_data3",	.type = "INTEGER" },
9fadc0
+	{ .name = "fw_spec_data4",	.type = "INTEGER" },
9fadc0
+	{ .name = "fw_spec_data5",	.type = "INTEGER" },
9fadc0
+};
9fadc0
+
9fadc0
+static const struct db_table_descriptor amp_payload3_event_tab = {
9fadc0
+	.name = "amp_payload3_event",
9fadc0
+	.fields = amp_payload3_event_fields,
9fadc0
+	.num_fields = ARRAY_SIZE(amp_payload3_event_fields),
9fadc0
+};
9fadc0
+
9fadc0
+/*Save data with different type into sqlite3 db*/
9fadc0
+static void record_amp_data(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+			    enum amp_oem_data_type data_type,
9fadc0
+			    int id, int64_t data, const char *text)
9fadc0
+{
9fadc0
+	switch (data_type) {
9fadc0
+	case AMP_OEM_DATA_TYPE_INT:
9fadc0
+		sqlite3_bind_int(ev_decoder->stmt_dec_record, id, data);
9fadc0
+		break;
9fadc0
+	case AMP_OEM_DATA_TYPE_INT64:
9fadc0
+		sqlite3_bind_int64(ev_decoder->stmt_dec_record, id, data);
9fadc0
+		break;
9fadc0
+	case AMP_OEM_DATA_TYPE_TEXT:
9fadc0
+		sqlite3_bind_text(ev_decoder->stmt_dec_record, id,
9fadc0
+				  text, -1, NULL);
9fadc0
+		break;
9fadc0
+	default:
9fadc0
+		break;
9fadc0
+	}
9fadc0
+}
9fadc0
+
9fadc0
+static int store_amp_err_data(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+				const char *name)
9fadc0
+{
9fadc0
+	int rc;
9fadc0
+
9fadc0
+	rc = sqlite3_step(ev_decoder->stmt_dec_record);
9fadc0
+	if (rc != SQLITE_OK && rc != SQLITE_DONE)
9fadc0
+		log(TERM, LOG_ERR,
9fadc0
+		    "Failed to do %s step on sqlite: error = %d\n", name, rc);
9fadc0
+
9fadc0
+	rc = sqlite3_reset(ev_decoder->stmt_dec_record);
9fadc0
+	if (rc != SQLITE_OK && rc != SQLITE_DONE)
9fadc0
+		log(TERM, LOG_ERR,
9fadc0
+		    "Failed to reset %s on sqlite: error = %d\n", name, rc);
9fadc0
+
9fadc0
+	rc = sqlite3_clear_bindings(ev_decoder->stmt_dec_record);
9fadc0
+	if (rc != SQLITE_OK && rc != SQLITE_DONE)
9fadc0
+		log(TERM, LOG_ERR,
9fadc0
+		    "Failed to clear bindings %s on sqlite: error = %d\n",
9fadc0
+		    name, rc);
9fadc0
+
9fadc0
+	return rc;
9fadc0
+}
9fadc0
+
9fadc0
+/*save all Ampere Specific Error Payload type 0 to sqlite3 database*/
9fadc0
+static void record_amp_payload0_err(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+				const char *type_str, const char *subtype_str,
9fadc0
+				const struct amp_payload0_type_sec *err)
9fadc0
+{
9fadc0
+	if (ev_decoder != NULL) {
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+			AMP_PAYLOAD0_FIELD_TYPE, 0, type_str);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+			AMP_PAYLOAD0_FIELD_SUB_TYPE, 0, subtype_str);
9fadc0
+
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD0_FIELD_INS, INSTANCE(err->instance), NULL);
9fadc0
+
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD0_FIELD_SOCKET_NUM,
9fadc0
+			SOCKET_NUM(err->instance), NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD0_FIELD_STATUS_REG, err->err_status, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD0_FIELD_ADDR_REG,
9fadc0
+			err->err_addr, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD0_FIELD_MISC0,
9fadc0
+			err->err_misc_0, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD0_FIELD_MISC1,
9fadc0
+			err->err_misc_1, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD0_FIELD_MISC2,
9fadc0
+			err->err_misc_2, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD0_FIELD_MISC3,
9fadc0
+			err->err_misc_3, NULL);
9fadc0
+		store_amp_err_data(ev_decoder, "amp_payload0_event_tab");
9fadc0
+	}
9fadc0
+}
9fadc0
+
9fadc0
+/*save all Ampere Specific Error Payload type 1 to sqlite3 database*/
9fadc0
+static void record_amp_payload1_err(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+				const char *type_str, const char *subtype_str,
9fadc0
+				const struct amp_payload1_type_sec *err)
9fadc0
+{
9fadc0
+	if (ev_decoder != NULL) {
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+				AMP_PAYLOAD1_FIELD_TYPE, 0, type_str);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+				AMP_PAYLOAD1_FIELD_SUB_TYPE, 0, subtype_str);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_INS,
9fadc0
+				INSTANCE(err->instance), NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_SOCKET_NUM,
9fadc0
+				SOCKET_NUM(err->instance), NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_UNCORE_ERR_STATUS,
9fadc0
+				err->uncore_status, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_UNCORE_ERR_MASK,
9fadc0
+				err->uncore_mask, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_UNCORE_ERR_SEV,
9fadc0
+				err->uncore_sev, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_CORE_ERR_STATUS,
9fadc0
+				err->core_status, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_CORE_ERR_MASK,
9fadc0
+				err->core_mask, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_ROOT_ERR_CMD,
9fadc0
+				err->root_err_cmd, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_ROOT_ERR_STATUS,
9fadc0
+				err->root_status, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_SRC_ID,
9fadc0
+				err->src_id, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+				AMP_PAYLOAD1_FIELD_RESERVED1,
9fadc0
+				err->reserved1, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+				AMP_PAYLOAD1_FIELD_RESERVED2,
9fadc0
+				err->reserved2, NULL);
9fadc0
+		store_amp_err_data(ev_decoder, "amp_payload1_event_tab");
9fadc0
+	}
9fadc0
+}
9fadc0
+
9fadc0
+/*save all Ampere Specific Error Payload type 2 to sqlite3 database*/
9fadc0
+static void record_amp_payload2_err(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+				const char *type_str, const char *subtype_str,
9fadc0
+				const struct amp_payload2_type_sec *err)
9fadc0
+{
9fadc0
+	if (ev_decoder != NULL) {
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+			AMP_PAYLOAD2_FIELD_TYPE, 0, type_str);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+			AMP_PAYLOAD2_FIELD_SUB_TYPE, 0, subtype_str);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD2_FIELD_INS, INSTANCE(err->instance), NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD2_FIELD_SOCKET_NUM,
9fadc0
+			SOCKET_NUM(err->instance), NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD2_FIELD_CE_REPORT_REG,
9fadc0
+			err->ce_register, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD2_FIELD_CE_LOACATION,
9fadc0
+			err->ce_location, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD2_FIELD_CE_ADDR,
9fadc0
+			err->ce_addr, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD2_FIELD_UE_REPORT_REG,
9fadc0
+			err->ue_register, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD2_FIELD_UE_LOCATION,
9fadc0
+			err->ue_location, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD2_FIELD_UE_ADDR,
9fadc0
+			err->ue_addr, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD2_FIELD_RESERVED1,
9fadc0
+			err->reserved1, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD2_FIELD_RESERVED2,
9fadc0
+			err->reserved2, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD2_FIELD_RESERVED3,
9fadc0
+			err->reserved3, NULL);
9fadc0
+		store_amp_err_data(ev_decoder, "amp_payload2_event_tab");
9fadc0
+	}
9fadc0
+}
9fadc0
+
9fadc0
+/*save all Ampere Specific Error Payload type 3 to sqlite3 database*/
9fadc0
+static void record_amp_payload3_err(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+				const char *type_str, const char *subtype_str,
9fadc0
+				const struct amp_payload3_type_sec *err)
9fadc0
+{
9fadc0
+	if (ev_decoder != NULL) {
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+			AMP_PAYLOAD3_FIELD_TYPE, 0, type_str);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+			AMP_PAYLOAD3_FIELD_SUB_TYPE, 0, subtype_str);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD3_FIELD_INS, INSTANCE(err->instance), NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD3_FIELD_SOCKET_NUM,
9fadc0
+			SOCKET_NUM(err->instance), NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT,
9fadc0
+			AMP_PAYLOAD3_FIELD_FW_SPEC_DATA0,
9fadc0
+			err->fw_speci_data0, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD3_FIELD_FW_SPEC_DATA1,
9fadc0
+			err->fw_speci_data1, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD3_FIELD_FW_SPEC_DATA2,
9fadc0
+			err->fw_speci_data2, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD3_FIELD_FW_SPEC_DATA3,
9fadc0
+			err->fw_speci_data3, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD3_FIELD_FW_SPEC_DATA4,
9fadc0
+			err->fw_speci_data4, NULL);
9fadc0
+		record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_INT64,
9fadc0
+			AMP_PAYLOAD3_FIELD_FW_SPEC_DATA5,
9fadc0
+			err->fw_speci_data5, NULL);
9fadc0
+		store_amp_err_data(ev_decoder, "amp_payload3_event_tab");
9fadc0
+	}
9fadc0
+}
9fadc0
+
9fadc0
+#else
9fadc0
+static void record_amp_data(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+			    enum amp_oem_data_type data_type,
9fadc0
+			    int id, int64_t data, const char *text)
9fadc0
+{
9fadc0
+	return 0;
9fadc0
+}
9fadc0
+
9fadc0
+static void record_amp_payload0_err(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+				const char *type_str, const char *subtype_str,
9fadc0
+				const struct amp_payload0_type_sec *err)
9fadc0
+{
9fadc0
+	return 0;
9fadc0
+}
9fadc0
+
9fadc0
+static void record_amp_payload1_err(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+				const char *type_str, const char *subtype_str,
9fadc0
+				const struct amp_payload1_type_sec *err)
9fadc0
+{
9fadc0
+	return 0;
9fadc0
+}
9fadc0
+
9fadc0
+static void record_amp_payload2_err(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+				const char *type_str, const char *subtype_str,
9fadc0
+				const struct amp_payload2_type_sec *err)
9fadc0
+{
9fadc0
+	return 0;
9fadc0
+}
9fadc0
+
9fadc0
+static void record_amp_payload3_err(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
+				const char *type_str, const char *subtype_str,
9fadc0
+				const struct amp_payload3_type_sec *err)
9fadc0
+{
9fadc0
+	return 0;
9fadc0
+}
9fadc0
+
9fadc0
+static int store_amp_err_data(struct ras_ns_ev_decoder *ev_decoder, char *name)
9fadc0
+{
9fadc0
+	return 0;
9fadc0
+}
9fadc0
+#endif
9fadc0
 
9fadc0
 /*decode ampere specific error payload type 0, the CPU's data is save*/
9fadc0
 /*to sqlite by ras-arm-handler, others are saved by this function.*/
9fadc0
@@ -434,6 +794,7 @@ void decode_amp_payload0_err_regs(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
 		*p = '\0';
9fadc0
 	}
9fadc0
 
9fadc0
+	record_amp_payload0_err(ev_decoder, type_str, subtype_str, err);
9fadc0
 	i = 0;
9fadc0
 	p = NULL;
9fadc0
 	end = NULL;
9fadc0
@@ -517,6 +878,7 @@ static void decode_amp_payload1_err_regs(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
 		*p = '\0';
9fadc0
 	}
9fadc0
 
9fadc0
+	record_amp_payload1_err(ev_decoder, type_str, subtype_str, err);
9fadc0
 	i = 0;
9fadc0
 	p = NULL;
9fadc0
 	end = NULL;
9fadc0
@@ -601,6 +963,7 @@ static void decode_amp_payload2_err_regs(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
 		*p = '\0';
9fadc0
 	}
9fadc0
 
9fadc0
+	record_amp_payload2_err(ev_decoder, type_str, subtype_str, err);
9fadc0
 	i = 0;
9fadc0
 	p = NULL;
9fadc0
 	end = NULL;
9fadc0
@@ -673,6 +1036,7 @@ static void decode_amp_payload3_err_regs(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
 		*p = '\0';
9fadc0
 	}
9fadc0
 
9fadc0
+	record_amp_payload3_err(ev_decoder, type_str, subtype_str, err);
9fadc0
 	i = 0;
9fadc0
 	p = NULL;
9fadc0
 	end = NULL;
9fadc0
@@ -687,6 +1051,38 @@ static int decode_amp_oem_type_error(struct ras_events *ras,
9fadc0
 {
9fadc0
 	int payload_type = PAYLOAD_TYPE(event->error[0]);
9fadc0
 
9fadc0
+#ifdef HAVE_SQLITE3
9fadc0
+	struct db_table_descriptor db_tab;
9fadc0
+	int id = 0;
9fadc0
+
9fadc0
+	if (payload_type == PAYLOAD_TYPE_0) {
9fadc0
+		db_tab = amp_payload0_event_tab;
9fadc0
+		id = AMP_PAYLOAD0_FIELD_TIMESTAMP;
9fadc0
+	} else if (payload_type == PAYLOAD_TYPE_1) {
9fadc0
+		db_tab = amp_payload1_event_tab;
9fadc0
+		id = AMP_PAYLOAD1_FIELD_TIMESTAMP;
9fadc0
+	} else if (payload_type == PAYLOAD_TYPE_2) {
9fadc0
+		db_tab = amp_payload2_event_tab;
9fadc0
+		id = AMP_PAYLOAD2_FIELD_TIMESTAMP;
9fadc0
+	} else if (payload_type == PAYLOAD_TYPE_3) {
9fadc0
+		db_tab = amp_payload3_event_tab;
9fadc0
+		id = AMP_PAYLOAD3_FIELD_TIMESTAMP;
9fadc0
+	} else
9fadc0
+		return -1;
9fadc0
+
9fadc0
+	if (!ev_decoder->stmt_dec_record) {
9fadc0
+		if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
9fadc0
+					    &db_tab) != SQLITE_OK) {
9fadc0
+			trace_seq_printf(s,
9fadc0
+					"create sql %s fail\n",
9fadc0
+					sqlite3_table_list[payload_type]);
9fadc0
+			return -1;
9fadc0
+		}
9fadc0
+	}
9fadc0
+	record_amp_data(ev_decoder, AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+			   id, 0, event->timestamp);
9fadc0
+#endif
9fadc0
+
9fadc0
 	if (payload_type == PAYLOAD_TYPE_0) {
9fadc0
 		const struct amp_payload0_type_sec *err =
9fadc0
 			(struct amp_payload0_type_sec *)event->error;
9fadc0
diff --git a/non-standard-ampere.h b/non-standard-ampere.h
9fadc0
index aacf3a8..f463c53 100644
9fadc0
--- a/non-standard-ampere.h
9fadc0
+++ b/non-standard-ampere.h
9fadc0
@@ -102,6 +102,79 @@ struct amp_payload3_type_sec {
9fadc0
 	uint64_t   fw_speci_data5;
9fadc0
 };
9fadc0
 
9fadc0
+enum amp_oem_data_type {
9fadc0
+	AMP_OEM_DATA_TYPE_INT,
9fadc0
+	AMP_OEM_DATA_TYPE_INT64,
9fadc0
+	AMP_OEM_DATA_TYPE_TEXT,
9fadc0
+};
9fadc0
+
9fadc0
+enum {
9fadc0
+	AMP_PAYLOAD0_FIELD_ID,
9fadc0
+	AMP_PAYLOAD0_FIELD_TIMESTAMP,
9fadc0
+	AMP_PAYLOAD0_FIELD_TYPE,
9fadc0
+	AMP_PAYLOAD0_FIELD_SUB_TYPE,
9fadc0
+	AMP_PAYLOAD0_FIELD_INS,
9fadc0
+	AMP_PAYLOAD0_FIELD_SOCKET_NUM,
9fadc0
+	AMP_PAYLOAD0_FIELD_STATUS_REG,
9fadc0
+	AMP_PAYLOAD0_FIELD_ADDR_REG,
9fadc0
+	AMP_PAYLOAD0_FIELD_MISC0,
9fadc0
+	AMP_PAYLOAD0_FIELD_MISC1,
9fadc0
+	AMP_PAYLOAD0_FIELD_MISC2,
9fadc0
+	AMP_PAYLOAD0_FIELD_MISC3,
9fadc0
+};
9fadc0
+
9fadc0
+enum {
9fadc0
+	AMP_PAYLOAD1_FIELD_ID,
9fadc0
+	AMP_PAYLOAD1_FIELD_TIMESTAMP,
9fadc0
+	AMP_PAYLOAD1_FIELD_TYPE,
9fadc0
+	AMP_PAYLOAD1_FIELD_SUB_TYPE,
9fadc0
+	AMP_PAYLOAD1_FIELD_INS,
9fadc0
+	AMP_PAYLOAD1_FIELD_SOCKET_NUM,
9fadc0
+	AMP_PAYLOAD1_FIELD_UNCORE_ERR_STATUS,
9fadc0
+	AMP_PAYLOAD1_FIELD_UNCORE_ERR_MASK,
9fadc0
+	AMP_PAYLOAD1_FIELD_UNCORE_ERR_SEV,
9fadc0
+	AMP_PAYLOAD1_FIELD_CORE_ERR_STATUS,
9fadc0
+	AMP_PAYLOAD1_FIELD_CORE_ERR_MASK,
9fadc0
+	AMP_PAYLOAD1_FIELD_ROOT_ERR_CMD,
9fadc0
+	AMP_PAYLOAD1_FIELD_ROOT_ERR_STATUS,
9fadc0
+	AMP_PAYLOAD1_FIELD_SRC_ID,
9fadc0
+	AMP_PAYLOAD1_FIELD_RESERVED1,
9fadc0
+	AMP_PAYLOAD1_FIELD_RESERVED2,
9fadc0
+};
9fadc0
+
9fadc0
+enum {
9fadc0
+	AMP_PAYLOAD2_FIELD_ID,
9fadc0
+	AMP_PAYLOAD2_FIELD_TIMESTAMP,
9fadc0
+	AMP_PAYLOAD2_FIELD_TYPE,
9fadc0
+	AMP_PAYLOAD2_FIELD_SUB_TYPE,
9fadc0
+	AMP_PAYLOAD2_FIELD_INS,
9fadc0
+	AMP_PAYLOAD2_FIELD_SOCKET_NUM,
9fadc0
+	AMP_PAYLOAD2_FIELD_CE_REPORT_REG,
9fadc0
+	AMP_PAYLOAD2_FIELD_CE_LOACATION,
9fadc0
+	AMP_PAYLOAD2_FIELD_CE_ADDR,
9fadc0
+	AMP_PAYLOAD2_FIELD_UE_REPORT_REG,
9fadc0
+	AMP_PAYLOAD2_FIELD_UE_LOCATION,
9fadc0
+	AMP_PAYLOAD2_FIELD_UE_ADDR,
9fadc0
+	AMP_PAYLOAD2_FIELD_RESERVED1,
9fadc0
+	AMP_PAYLOAD2_FIELD_RESERVED2,
9fadc0
+	AMP_PAYLOAD2_FIELD_RESERVED3,
9fadc0
+};
9fadc0
+
9fadc0
+enum {
9fadc0
+	AMP_PAYLOAD3_FIELD_ID,
9fadc0
+	AMP_PAYLOAD3_FIELD_TIMESTAMP,
9fadc0
+	AMP_PAYLOAD3_FIELD_TYPE,
9fadc0
+	AMP_PAYLOAD3_FIELD_SUB_TYPE,
9fadc0
+	AMP_PAYLOAD3_FIELD_INS,
9fadc0
+	AMP_PAYLOAD3_FIELD_SOCKET_NUM,
9fadc0
+	AMP_PAYLOAD3_FIELD_FW_SPEC_DATA0,
9fadc0
+	AMP_PAYLOAD3_FIELD_FW_SPEC_DATA1,
9fadc0
+	AMP_PAYLOAD3_FIELD_FW_SPEC_DATA2,
9fadc0
+	AMP_PAYLOAD3_FIELD_FW_SPEC_DATA3,
9fadc0
+	AMP_PAYLOAD3_FIELD_FW_SPEC_DATA4,
9fadc0
+	AMP_PAYLOAD3_FIELD_FW_SPEC_DATA5
9fadc0
+};
9fadc0
+
9fadc0
 void decode_amp_payload0_err_regs(struct ras_ns_ev_decoder *ev_decoder,
9fadc0
 				  struct trace_seq *s,
9fadc0
 				  const struct amp_payload0_type_sec *err);
9fadc0
diff --git a/ras-aer-handler.c b/ras-aer-handler.c
9fadc0
index 8ddd439..6f4cb2b 100644
9fadc0
--- a/ras-aer-handler.c
9fadc0
+++ b/ras-aer-handler.c
9fadc0
@@ -67,6 +67,9 @@ int ras_aer_event_handler(struct trace_seq *s,
9fadc0
 	struct tm *tm;
9fadc0
 	struct ras_aer_event ev;
9fadc0
 	char buf[BUF_LEN];
9fadc0
+	char ipmi_add_sel[105];
9fadc0
+	uint8_t sel_data[5];
9fadc0
+	int seg, bus, dev, fn;
9fadc0
 
9fadc0
 	/*
9fadc0
 	 * Newer kernels (3.10-rc1 or upper) provide an uptime clock.
9fadc0
@@ -129,15 +132,19 @@ int ras_aer_event_handler(struct trace_seq *s,
9fadc0
 	switch (severity_val) {
9fadc0
 	case HW_EVENT_AER_UNCORRECTED_NON_FATAL:
9fadc0
 		ev.error_type = "Uncorrected (Non-Fatal)";
9fadc0
+		sel_data[0] = 0xca;
9fadc0
 		break;
9fadc0
 	case HW_EVENT_AER_UNCORRECTED_FATAL:
9fadc0
 		ev.error_type = "Uncorrected (Fatal)";
9fadc0
+		sel_data[0] = 0xca;
9fadc0
 		break;
9fadc0
 	case HW_EVENT_AER_CORRECTED:
9fadc0
 		ev.error_type = "Corrected";
9fadc0
+		sel_data[0] = 0xbf;
9fadc0
 		break;
9fadc0
 	default:
9fadc0
 		ev.error_type = "Unknown severity";
9fadc0
+		sel_data[0] = 0xbf;
9fadc0
 	}
9fadc0
 	trace_seq_puts(s, ev.error_type);
9fadc0
 
9fadc0
@@ -151,5 +158,29 @@ int ras_aer_event_handler(struct trace_seq *s,
9fadc0
 	ras_report_aer_event(ras, &ev;;
9fadc0
 #endif
9fadc0
 
9fadc0
+#ifdef HAVE_AMP_NS_DECODE
9fadc0
+	/*
9fadc0
+	 * Get PCIe AER error source seg/bus/dev/fn and save it into
9fadc0
+	 * BMC OEM SEL, ipmitool raw 0x0a 0x44 is IPMI command-Add SEL
9fadc0
+	 * entry, please refer IPMI specificaiton chapter 31.6. 0xcd3a
9fadc0
+	 * is manufactuer ID(ampere),byte 12 is sensor num(CE is 0xBF,
9fadc0
+	 * UE is 0xCA), byte 13~14 is segment number, byte 15 is bus
9fadc0
+	 * number, byte 16[7:3] is device number, byte 16[2:0] is
9fadc0
+	 * function number
9fadc0
+	 */
9fadc0
+	sscanf(ev.dev_name, "%x:%x:%x.%x", &seg, &bus, &dev, &fn);
9fadc0
+
9fadc0
+	sel_data[1] = seg & 0xff;
9fadc0
+	sel_data[2] = (seg & 0xff00) >> 8;
9fadc0
+	sel_data[3] = bus;
9fadc0
+	sel_data[4] = (((dev & 0x1f) << 3) | (fn & 0x7));
9fadc0
+
9fadc0
+	sprintf(ipmi_add_sel,
9fadc0
+	  "ipmitool raw 0x0a 0x44 0x00 0x00 0xc0 0x00 0x00 0x00 0x00 0x3a 0xcd 0x00 0xc0 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
9fadc0
+	  sel_data[0], sel_data[1], sel_data[2], sel_data[3], sel_data[4]);
9fadc0
+
9fadc0
+	system(ipmi_add_sel);
9fadc0
+#endif
9fadc0
+
9fadc0
 	return 0;
9fadc0
 }