-
Notifications
You must be signed in to change notification settings - Fork 80
/
non-standard-hisilicon.c
410 lines (362 loc) · 11.1 KB
/
non-standard-hisilicon.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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
314
315
316
317
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2020 Hisilicon Limited.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "non-standard-hisilicon.h"
#include "ras-logger.h"
#include "ras-report.h"
#include "types.h"
#define HISI_BUF_LEN 2048
#define HISI_PCIE_INFO_BUF_LEN 256
struct hisi_common_error_section {
uint32_t val_bits;
uint8_t version;
uint8_t soc_id;
uint8_t socket_id;
uint8_t totem_id;
uint8_t nimbus_id;
uint8_t subsystem_id;
uint8_t module_id;
uint8_t submodule_id;
uint8_t core_id;
uint8_t port_id;
uint16_t err_type;
struct {
uint8_t function;
uint8_t device;
uint16_t segment;
uint8_t bus;
uint8_t reserved[3];
} pcie_info;
uint8_t err_severity;
uint8_t reserved[3];
uint32_t reg_array_size;
uint32_t reg_array[];
};
enum {
HISI_COMMON_VALID_SOC_ID,
HISI_COMMON_VALID_SOCKET_ID,
HISI_COMMON_VALID_TOTEM_ID,
HISI_COMMON_VALID_NIMBUS_ID,
HISI_COMMON_VALID_SUBSYSTEM_ID,
HISI_COMMON_VALID_MODULE_ID,
HISI_COMMON_VALID_SUBMODULE_ID,
HISI_COMMON_VALID_CORE_ID,
HISI_COMMON_VALID_PORT_ID,
HISI_COMMON_VALID_ERR_TYPE,
HISI_COMMON_VALID_PCIE_INFO,
HISI_COMMON_VALID_ERR_SEVERITY,
HISI_COMMON_VALID_REG_ARRAY_SIZE,
};
enum {
HISI_COMMON_FIELD_ID,
HISI_COMMON_FIELD_TIMESTAMP,
HISI_COMMON_FIELD_VERSION,
HISI_COMMON_FIELD_SOC_ID,
HISI_COMMON_FIELD_SOCKET_ID,
HISI_COMMON_FIELD_TOTEM_ID,
HISI_COMMON_FIELD_NIMBUS_ID,
HISI_COMMON_FIELD_SUB_SYSTEM_ID,
HISI_COMMON_FIELD_MODULE_ID,
HISI_COMMON_FIELD_SUB_MODULE_ID,
HISI_COMMON_FIELD_CORE_ID,
HISI_COMMON_FIELD_PORT_ID,
HISI_COMMON_FIELD_ERR_TYPE,
HISI_COMMON_FIELD_PCIE_INFO,
HISI_COMMON_FIELD_ERR_SEVERITY,
HISI_COMMON_FIELD_REGS_DUMP,
};
struct hisi_event {
char error_msg[HISI_BUF_LEN];
char pcie_info[HISI_PCIE_INFO_BUF_LEN];
char reg_msg[HISI_BUF_LEN];
};
#ifdef HAVE_SQLITE3
void record_vendor_data(struct ras_ns_ev_decoder *ev_decoder,
enum hisi_oem_data_type data_type,
int id, int64_t data, const char *text)
{
if (!ev_decoder->stmt_dec_record)
return;
switch (data_type) {
case HISI_OEM_DATA_TYPE_INT:
sqlite3_bind_int(ev_decoder->stmt_dec_record, id, data);
break;
case HISI_OEM_DATA_TYPE_INT64:
sqlite3_bind_int64(ev_decoder->stmt_dec_record, id, data);
break;
case HISI_OEM_DATA_TYPE_TEXT:
sqlite3_bind_text(ev_decoder->stmt_dec_record, id, text, -1, NULL);
break;
}
}
int step_vendor_data_tab(struct ras_ns_ev_decoder *ev_decoder, const char *name)
{
int rc;
if (!ev_decoder->stmt_dec_record)
return 0;
rc = sqlite3_step(ev_decoder->stmt_dec_record);
if (rc != SQLITE_OK && rc != SQLITE_DONE)
log(TERM, LOG_ERR,
"Failed to do %s step on sqlite: error = %d\n", name, rc);
rc = sqlite3_reset(ev_decoder->stmt_dec_record);
if (rc != SQLITE_OK && rc != SQLITE_DONE)
log(TERM, LOG_ERR,
"Failed to reset %s on sqlite: error = %d\n", name, rc);
rc = sqlite3_clear_bindings(ev_decoder->stmt_dec_record);
if (rc != SQLITE_OK && rc != SQLITE_DONE)
log(TERM, LOG_ERR,
"Failed to clear bindings %s on sqlite: error = %d\n",
name, rc);
return rc;
}
#else
void record_vendor_data(struct ras_ns_ev_decoder *ev_decoder,
enum hisi_oem_data_type data_type,
int id, int64_t data, const char *text)
{ }
int step_vendor_data_tab(struct ras_ns_ev_decoder *ev_decoder, const char *name)
{
return 0;
}
#endif
#ifdef HAVE_SQLITE3
static const struct db_fields hisi_common_section_fields[] = {
{ .name = "id", .type = "INTEGER PRIMARY KEY" },
{ .name = "timestamp", .type = "TEXT" },
{ .name = "version", .type = "INTEGER" },
{ .name = "soc_id", .type = "INTEGER" },
{ .name = "socket_id", .type = "INTEGER" },
{ .name = "totem_id", .type = "INTEGER" },
{ .name = "nimbus_id", .type = "INTEGER" },
{ .name = "sub_system_id", .type = "INTEGER" },
{ .name = "module_id", .type = "TEXT" },
{ .name = "sub_module_id", .type = "INTEGER" },
{ .name = "core_id", .type = "INTEGER" },
{ .name = "port_id", .type = "INTEGER" },
{ .name = "err_type", .type = "INTEGER" },
{ .name = "pcie_info", .type = "TEXT" },
{ .name = "err_severity", .type = "TEXT" },
{ .name = "regs_dump", .type = "TEXT" },
};
static const struct db_table_descriptor hisi_common_section_tab = {
.name = "hisi_common_section_v2",
.fields = hisi_common_section_fields,
.num_fields = ARRAY_SIZE(hisi_common_section_fields),
};
#endif
static const char * const soc_desc[] = {
"Kunpeng916",
"Kunpeng920",
"Kunpeng930",
};
static const char * const module_name[] = {
"MN",
"PLL",
"SLLC",
"AA",
"SIOE",
"POE",
"CPA",
"DISP",
"GIC",
"ITS",
"AVSBUS",
"CS",
"PPU",
"SMMU",
"PA",
"HLLC",
"DDRC",
"L3TAG",
"L3DATA",
"PCS",
"MATA",
"PCIe Local",
"SAS",
"SATA",
"NIC",
"RoCE",
"USB",
"ZIP",
"HPRE",
"SEC",
"RDE",
"MEE",
"L4D",
"Tsensor",
"ROH",
"BTC",
"HILINK",
"STARS",
"SDMA",
"UC",
"HBMC",
};
static const char * const get_soc_desc(uint8_t soc_id)
{
if (soc_id >= sizeof(soc_desc) / sizeof(char *))
return "unknown";
return soc_desc[soc_id];
}
static void decode_module(struct ras_ns_ev_decoder *ev_decoder,
struct hisi_event *event, uint8_t module_id)
{
if (module_id >= sizeof(module_name) / sizeof(char *)) {
HISI_SNPRINTF(event->error_msg, "module=unknown(id=%hhu) ", module_id);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT,
HISI_COMMON_FIELD_MODULE_ID,
0, "unknown");
} else {
HISI_SNPRINTF(event->error_msg, "module=%s ", module_name[module_id]);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT,
HISI_COMMON_FIELD_MODULE_ID,
0, module_name[module_id]);
}
}
static void decode_hisi_common_section_hdr(struct ras_ns_ev_decoder *ev_decoder,
const struct hisi_common_error_section *err,
struct hisi_event *event)
{
HISI_SNPRINTF(event->error_msg, "[ table_version=%hhu", err->version);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_VERSION,
err->version, NULL);
if (err->val_bits & BIT(HISI_COMMON_VALID_SOC_ID)) {
HISI_SNPRINTF(event->error_msg, "soc=%s", get_soc_desc(err->soc_id));
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_SOC_ID,
err->soc_id, NULL);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_SOCKET_ID)) {
HISI_SNPRINTF(event->error_msg, "socket_id=%hhu", err->socket_id);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_SOCKET_ID,
err->socket_id, NULL);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_TOTEM_ID)) {
HISI_SNPRINTF(event->error_msg, "totem_id=%hhu", err->totem_id);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_TOTEM_ID,
err->totem_id, NULL);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_NIMBUS_ID)) {
HISI_SNPRINTF(event->error_msg, "nimbus_id=%hhu", err->nimbus_id);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_NIMBUS_ID,
err->nimbus_id, NULL);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_SUBSYSTEM_ID)) {
HISI_SNPRINTF(event->error_msg, "subsystem_id=%hhu", err->subsystem_id);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_SUB_SYSTEM_ID,
err->subsystem_id, NULL);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_MODULE_ID))
decode_module(ev_decoder, event, err->module_id);
if (err->val_bits & BIT(HISI_COMMON_VALID_SUBMODULE_ID)) {
HISI_SNPRINTF(event->error_msg, "submodule_id=%hhu", err->submodule_id);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_SUB_MODULE_ID,
err->submodule_id, NULL);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_CORE_ID)) {
HISI_SNPRINTF(event->error_msg, "core_id=%hhu", err->core_id);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_CORE_ID,
err->core_id, NULL);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_PORT_ID)) {
HISI_SNPRINTF(event->error_msg, "port_id=%hhu", err->port_id);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_PORT_ID,
err->port_id, NULL);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_ERR_TYPE)) {
HISI_SNPRINTF(event->error_msg, "err_type=%hu", err->err_type);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_INT,
HISI_COMMON_FIELD_ERR_TYPE,
err->err_type, NULL);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_PCIE_INFO)) {
HISI_SNPRINTF(event->error_msg, "pcie_device_id=%04x:%02x:%02x.%x",
err->pcie_info.segment, err->pcie_info.bus,
err->pcie_info.device, err->pcie_info.function);
HISI_SNPRINTF(event->pcie_info, "%04x:%02x:%02x.%x",
err->pcie_info.segment, err->pcie_info.bus,
err->pcie_info.device, err->pcie_info.function);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT,
HISI_COMMON_FIELD_PCIE_INFO,
0, event->pcie_info);
}
if (err->val_bits & BIT(HISI_COMMON_VALID_ERR_SEVERITY)) {
HISI_SNPRINTF(event->error_msg, "err_severity=%s", err_severity(err->err_severity));
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT,
HISI_COMMON_FIELD_ERR_SEVERITY,
0, err_severity(err->err_severity));
}
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,
struct ras_non_standard_event *event)
{
const struct hisi_common_error_section *err =
(struct hisi_common_error_section *)event->error;
struct hisi_event hevent;
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);
trace_seq_printf(s, "%s\n", hevent.error_msg);
if (err->val_bits & BIT(HISI_COMMON_VALID_REG_ARRAY_SIZE) && err->reg_array_size > 0) {
unsigned int i;
trace_seq_printf(s, "Register Dump:\n");
for (i = 0; i < err->reg_array_size / sizeof(uint32_t); i++) {
trace_seq_printf(s, "reg%02u=0x%08x\n", i,
err->reg_array[i]);
HISI_SNPRINTF(hevent.reg_msg, "reg%02u=0x%08x",
i, err->reg_array[i]);
}
}
if (ras->record_events) {
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT,
HISI_COMMON_FIELD_TIMESTAMP,
0, event->timestamp);
record_vendor_data(ev_decoder, HISI_OEM_DATA_TYPE_TEXT,
HISI_COMMON_FIELD_REGS_DUMP, 0, hevent.reg_msg);
step_vendor_data_tab(ev_decoder, "hisi_common_section_tab");
}
return 0;
}
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,
},
};
static void __attribute__((constructor)) hisi_ns_init(void)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(hisi_section_ns_ev_decoder); i++)
register_ns_ev_decoder(&hisi_section_ns_ev_decoder[i]);
}