]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
rasdaemon: Add support for creating the vendor error tables at startup
authorShiju Jose <shiju.jose@huawei.com>
Wed, 31 May 2023 15:24:36 +0000 (16:24 +0100)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Mon, 23 Oct 2023 08:52:12 +0000 (10:52 +0200)
1. Support for create/open the vendor error tables at rasdaemon startup.
2. Make changes in the HiSilicon error handling code for the same.

Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
non-standard-hisi_hip08.c
non-standard-hisilicon.c
ras-events.c
ras-non-standard-handler.c
ras-non-standard-handler.h

index 61f12eb1c18f4b078c88d34272a6cf653d743b76..08998125de58353b78840aa5b8cbb04e9a9b560a 100644 (file)
@@ -654,6 +654,20 @@ static void decode_oem_type1_err_regs(struct ras_ns_ev_decoder *ev_decoder,
        step_vendor_data_tab(ev_decoder, "hip08_oem_type1_event_tab");
 }
 
+static int add_hip08_oem_type1_table(struct ras_events *ras, struct ras_ns_ev_decoder *ev_decoder)
+{
+#ifdef HAVE_SQLITE3
+       if (ras->record_events && !ev_decoder->stmt_dec_record) {
+               if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
+                                           &hip08_oem_type1_event_tab) != SQLITE_OK) {
+                       log(TERM, LOG_WARNING, "Failed to create sql hip08_oem_type1_event_tab\n");
+                       return -1;
+               }
+       }
+#endif
+       return 0;
+}
+
 /* error data decoding functions */
 static int decode_hip08_oem_type1_error(struct ras_events *ras,
                                        struct ras_ns_ev_decoder *ev_decoder,
@@ -669,17 +683,6 @@ static int decode_hip08_oem_type1_error(struct ras_events *ras,
                return -1;
        }
 
-#ifdef HAVE_SQLITE3
-       if (ras->record_events && !ev_decoder->stmt_dec_record) {
-               if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
-                                           &hip08_oem_type1_event_tab)
-                       != SQLITE_OK) {
-                       trace_seq_printf(s,
-                                       "create sql hip08_oem_type1_event_tab fail\n");
-                       return -1;
-               }
-       }
-#endif
        record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT,
                           HIP08_OEM_TYPE1_FIELD_TIMESTAMP,
                           0, event->timestamp);
@@ -827,6 +830,20 @@ static void decode_oem_type2_err_regs(struct ras_ns_ev_decoder *ev_decoder,
        step_vendor_data_tab(ev_decoder, "hip08_oem_type2_event_tab");
 }
 
+static int add_hip08_oem_type2_table(struct ras_events *ras, struct ras_ns_ev_decoder *ev_decoder)
+{
+#ifdef HAVE_SQLITE3
+       if (ras->record_events && !ev_decoder->stmt_dec_record) {
+               if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
+                                           &hip08_oem_type2_event_tab) != SQLITE_OK) {
+                       log(TERM, LOG_WARNING, "Failed to create sql hip08_oem_type2_event_tab\n");
+                       return -1;
+               }
+       }
+#endif
+       return 0;
+}
+
 static int decode_hip08_oem_type2_error(struct ras_events *ras,
                                        struct ras_ns_ev_decoder *ev_decoder,
                                        struct trace_seq *s,
@@ -841,16 +858,6 @@ static int decode_hip08_oem_type2_error(struct ras_events *ras,
                return -1;
        }
 
-#ifdef HAVE_SQLITE3
-       if (ras->record_events && !ev_decoder->stmt_dec_record) {
-               if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
-                       &hip08_oem_type2_event_tab) != SQLITE_OK) {
-                       trace_seq_printf(s,
-                               "create sql hip08_oem_type2_event_tab fail\n");
-                       return -1;
-               }
-       }
-#endif
        record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT,
                           HIP08_OEM_TYPE2_FIELD_TIMESTAMP,
                           0, event->timestamp);
@@ -977,6 +984,20 @@ static void decode_pcie_local_err_regs(struct ras_ns_ev_decoder *ev_decoder,
        step_vendor_data_tab(ev_decoder, "hip08_pcie_local_event_tab");
 }
 
+static int add_hip08_pcie_local_table(struct ras_events *ras, struct ras_ns_ev_decoder *ev_decoder)
+{
+#ifdef HAVE_SQLITE3
+       if (ras->record_events && !ev_decoder->stmt_dec_record) {
+               if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
+                                           &hip08_pcie_local_event_tab) != SQLITE_OK) {
+                       log(TERM, LOG_WARNING, "Failed to create sql hip08_pcie_local_event_tab\n");
+                       return -1;
+               }
+       }
+#endif
+       return 0;
+}
+
 static int decode_hip08_pcie_local_error(struct ras_events *ras,
                                         struct ras_ns_ev_decoder *ev_decoder,
                                         struct trace_seq *s,
@@ -991,16 +1012,6 @@ static int decode_hip08_pcie_local_error(struct ras_events *ras,
                return -1;
        }
 
-#ifdef HAVE_SQLITE3
-       if (ras->record_events && !ev_decoder->stmt_dec_record) {
-               if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
-                               &hip08_pcie_local_event_tab) != SQLITE_OK) {
-                       trace_seq_printf(s,
-                               "create sql hip08_pcie_local_event_tab fail\n");
-                       return -1;
-               }
-       }
-#endif
        record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT,
                           HIP08_PCIE_LOCAL_FIELD_TIMESTAMP,
                           0, event->timestamp);
@@ -1015,14 +1026,17 @@ static int decode_hip08_pcie_local_error(struct ras_events *ras,
 static struct ras_ns_ev_decoder hip08_ns_ev_decoder[] = {
        {
                .sec_type = "1f8161e1-55d6-41e6-bd10-7afd1dc5f7c5",
+               .add_table = add_hip08_oem_type1_table,
                .decode = decode_hip08_oem_type1_error,
        },
        {
                .sec_type = "45534ea6-ce23-4115-8535-e07ab3aef91d",
+               .add_table = add_hip08_oem_type2_table,
                .decode = decode_hip08_oem_type2_error,
        },
        {
                .sec_type = "b2889fc9-e7d7-4f9d-a867-af42e98be772",
+               .add_table = add_hip08_pcie_local_table,
                .decode = decode_hip08_pcie_local_error,
        },
 };
index 721821eed59ea49101f84fc948d0533dcb4bb61a..7296d280307370d4ca2255602369bb23a2f6c934 100644 (file)
@@ -341,6 +341,23 @@ static void decode_hisi_common_section_hdr(struct ras_ns_ev_decoder *ev_decoder,
        HISI_SNPRINTF(event->error_msg, "]");
 }
 
+static int add_hisi_common_table(struct ras_events *ras,
+                                struct ras_ns_ev_decoder *ev_decoder)
+{
+#ifdef HAVE_SQLITE3
+       if (ras->record_events &&
+           !ev_decoder->stmt_dec_record) {
+               if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
+                                           &hisi_common_section_tab) != SQLITE_OK) {
+                       log(TERM, LOG_WARNING, "Failed to create sql hisi_common_section_tab\n");
+                       return -1;
+               }
+       }
+#endif
+
+       return 0;
+}
+
 static int decode_hisi_common_section(struct ras_events *ras,
                                      struct ras_ns_ev_decoder *ev_decoder,
                                      struct trace_seq *s,
@@ -350,16 +367,6 @@ static int decode_hisi_common_section(struct ras_events *ras,
                        (struct hisi_common_error_section *)event->error;
        struct hisi_event hevent;
 
-#ifdef HAVE_SQLITE3
-       if (ras->record_events && !ev_decoder->stmt_dec_record) {
-               if (ras_mc_add_vendor_table(ras, &ev_decoder->stmt_dec_record,
-                               &hisi_common_section_tab) != SQLITE_OK) {
-                       trace_seq_printf(s, "create sql hisi_common_section_tab fail\n");
-                       return -1;
-               }
-       }
-#endif
-
        memset(&hevent, 0, sizeof(struct hisi_event));
        trace_seq_printf(s, "\nHisilicon Common Error Section:\n");
        decode_hisi_common_section_hdr(ev_decoder, err, &hevent);
@@ -392,6 +399,7 @@ static int decode_hisi_common_section(struct ras_events *ras,
 static struct ras_ns_ev_decoder hisi_section_ns_ev_decoder[]  = {
        {
                .sec_type = "c8b328a8-9917-4af6-9a13-2e08ab2e7586",
+               .add_table = add_hisi_common_table,
                .decode = decode_hisi_common_section,
        },
 };
index 9eb45b3f8c1f2ec5931ede2b8a3798ceb25eca6d..d0251e027445cf0bec16951a00751e9b757d9c12 100644 (file)
@@ -474,6 +474,10 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata,
        if (pdata[0].ras->record_events) {
                if (ras_mc_event_opendb(pdata[0].cpu, pdata[0].ras))
                        goto error;
+#ifdef HAVE_NON_STANDARD
+               if (ras_ns_add_vendor_tables(pdata[0].ras))
+                       log(TERM, LOG_ERR, "Can't add vendor table\n");
+#endif
        }
 
        do {
@@ -563,8 +567,12 @@ static int read_ras_event_all_cpus(struct pthread_data *pdata,
            "Old kernel detected. Stop listening and fall back to pthread way.\n");
 
 cleanup:
-       if (pdata[0].ras->record_events)
+       if (pdata[0].ras->record_events) {
+#ifdef HAVE_NON_STANDARD
+               ras_ns_finalize_vendor_tables();
+#endif
                ras_mc_event_closedb(pdata[0].cpu, pdata[0].ras);
+       }
 
 error:
        kbuffer_free(kbuf);
@@ -661,6 +669,10 @@ static void *handle_ras_events_cpu(void *priv)
                        free(page);
                        return 0;
                }
+#ifdef HAVE_NON_STANDARD
+               if (ras_ns_add_vendor_tables(pdata->ras))
+                       log(TERM, LOG_ERR, "Can't add vendor table\n");
+#endif
                pthread_mutex_unlock(&pdata->ras->db_lock);
        }
 
@@ -668,6 +680,9 @@ static void *handle_ras_events_cpu(void *priv)
 
        if (pdata->ras->record_events) {
                pthread_mutex_lock(&pdata->ras->db_lock);
+#ifdef HAVE_NON_STANDARD
+               ras_ns_finalize_vendor_tables();
+#endif
                ras_mc_event_closedb(pdata->cpu, pdata->ras);
                pthread_mutex_unlock(&pdata->ras->db_lock);
        }
index b7096da8e9e9d19468a87713f76ff7a0e677f943..cb2504e443a68993daef27da04da3d3c31b2c72d 100644 (file)
@@ -75,6 +75,32 @@ int register_ns_ev_decoder(struct ras_ns_ev_decoder *ns_ev_decoder)
        return 0;
 }
 
+int ras_ns_add_vendor_tables(struct ras_events *ras)
+{
+       struct ras_ns_ev_decoder *ns_ev_decoder;
+       int error = 0;
+
+#ifdef HAVE_SQLITE3
+       if (!ras)
+               return -1;
+
+       ns_ev_decoder = ras_ns_ev_dec_list;
+       while (ns_ev_decoder) {
+               if (ns_ev_decoder->add_table && !ns_ev_decoder->stmt_dec_record) {
+                       error = ns_ev_decoder->add_table(ras, ns_ev_decoder);
+                       if (error)
+                               break;
+               }
+               ns_ev_decoder = ns_ev_decoder->next;
+       }
+
+       if (error)
+               return -1;
+#endif
+
+       return 0;
+}
+
 static int find_ns_ev_decoder(const char *sec_type, struct ras_ns_ev_decoder **p_ns_ev_dec)
 {
        struct ras_ns_ev_decoder *ns_ev_decoder;
@@ -96,7 +122,7 @@ static int find_ns_ev_decoder(const char *sec_type, struct ras_ns_ev_decoder **p
        return 0;
 }
 
-static void unregister_ns_ev_decoder(void)
+void ras_ns_finalize_vendor_tables(void)
 {
 #ifdef HAVE_SQLITE3
        struct ras_ns_ev_decoder *ns_ev_decoder = ras_ns_ev_dec_list;
@@ -108,6 +134,13 @@ static void unregister_ns_ev_decoder(void)
                }
                ns_ev_decoder = ns_ev_decoder->next;
        }
+#endif
+}
+
+static void unregister_ns_ev_decoder(void)
+{
+#ifdef HAVE_SQLITE3
+       ras_ns_finalize_vendor_tables();
 #endif
        ras_ns_ev_dec_list = NULL;
 }
index c360eaf04cab2e40685543975c97d0826c1fa1a3..d19a5649cd80de5fc94d4aa291a525769d8e1d32 100644 (file)
@@ -20,6 +20,7 @@
 struct ras_ns_ev_decoder {
        struct ras_ns_ev_decoder *next;
        const char *sec_type;
+       int (*add_table)(struct ras_events *ras, struct ras_ns_ev_decoder *ev_decoder);
        int (*decode)(struct ras_events *ras, struct ras_ns_ev_decoder *ev_decoder,
                      struct trace_seq *s, struct ras_non_standard_event *event);
 #ifdef HAVE_SQLITE3
@@ -36,6 +37,8 @@ void print_le_hex(struct trace_seq *s, const uint8_t *buf, int index);
 
 #ifdef HAVE_NON_STANDARD
 int register_ns_ev_decoder(struct ras_ns_ev_decoder *ns_ev_decoder);
+int ras_ns_add_vendor_tables(struct ras_events *ras);
+void ras_ns_finalize_vendor_tables(void);
 #else
 static inline int register_ns_ev_decoder(struct ras_ns_ev_decoder *ns_ev_decoder) { return 0; };
 #endif