forked from mchehab/rasdaemon
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ras-cxl-handler.c
1183 lines (1015 loc) · 32.6 KB
/
ras-cxl-handler.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
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved.
*/
#include <endian.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <traceevent/kbuffer.h>
#include <unistd.h>
#include "ras-cxl-handler.h"
#include "ras-logger.h"
#include "ras-record.h"
#include "ras-report.h"
#include "types.h"
/* Common Functions */
static void convert_timestamp(unsigned long long ts, char *ts_ptr, uint16_t size)
{
/* CXL Specification 3.0
* Overflow timestamp - The number of unsigned nanoseconds
* that have elapsed since midnight, 01-Jan-1970 UTC
*/
time_t ts_secs = ts / 1000000000ULL;
struct tm *tm;
tm = localtime(&ts_secs);
if (tm)
strftime(ts_ptr, size, "%Y-%m-%d %H:%M:%S %z", tm);
if (!ts || !tm)
strscpy(ts_ptr, "1970-01-01 00:00:00 +0000",
size);
}
static void get_timestamp(struct trace_seq *s, struct tep_record *record,
struct ras_events *ras, char *ts_ptr, uint16_t size)
{
time_t now;
struct tm *tm;
now = record->ts / user_hz + ras->uptime_diff;
tm = localtime(&now);
if (tm)
strftime(ts_ptr, size, "%Y-%m-%d %H:%M:%S %z", tm);
else
strscpy(ts_ptr, "1970-01-01 00:00:00 +0000", size);
}
struct cxl_event_flags {
uint32_t bit;
const char *flag;
};
static int decode_cxl_event_flags(struct trace_seq *s, uint32_t flags,
const struct cxl_event_flags *cxl_ev_flags,
uint8_t num_elems)
{
int i;
for (i = 0; i < num_elems; i++) {
if (flags & cxl_ev_flags[i].bit)
if (trace_seq_printf(s, "\'%s\' ", cxl_ev_flags[i].flag) <= 0)
return -1;
}
return 0;
}
static char *uuid_be(const char *uu)
{
static char uuid[sizeof("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")];
char *p = uuid;
int i;
static const unsigned char be[16] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
for (i = 0; i < 16; i++) {
p += snprintf(p, sizeof(uuid), "%.2x", (unsigned char)uu[be[i]]);
switch (i) {
case 3:
case 5:
case 7:
case 9:
*p++ = '-';
break;
}
}
*p = 0;
return uuid;
}
static const char * const get_cxl_type_str(const char * const *type_array,
uint8_t num_elems, uint8_t type)
{
if (type >= num_elems)
return "Unknown";
return type_array[type];
}
/* Poison List: Payload out flags */
#define CXL_POISON_FLAG_MORE BIT(0)
#define CXL_POISON_FLAG_OVERFLOW BIT(1)
#define CXL_POISON_FLAG_SCANNING BIT(2)
/* CXL poison - source types */
enum cxl_poison_source {
CXL_POISON_SOURCE_UNKNOWN = 0,
CXL_POISON_SOURCE_EXTERNAL = 1,
CXL_POISON_SOURCE_INTERNAL = 2,
CXL_POISON_SOURCE_INJECTED = 3,
CXL_POISON_SOURCE_VENDOR = 7,
};
/* CXL poison - trace types */
enum cxl_poison_trace_type {
CXL_POISON_TRACE_LIST,
CXL_POISON_TRACE_INJECT,
CXL_POISON_TRACE_CLEAR,
};
int ras_cxl_poison_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context)
{
int len;
unsigned long long val;
struct ras_events *ras = context;
struct ras_cxl_poison_event ev;
get_timestamp(s, record, ras, (char *)&ev.timestamp, sizeof(ev.timestamp));
if (trace_seq_printf(s, "%s ", ev.timestamp) <= 0)
return -1;
ev.memdev = tep_get_field_raw(s, event, "memdev",
record, &len, 1);
if (!ev.memdev)
return -1;
if (trace_seq_printf(s, "memdev:%s ", ev.memdev) <= 0)
return -1;
ev.host = tep_get_field_raw(s, event, "host",
record, &len, 1);
if (!ev.host)
return -1;
if (trace_seq_printf(s, "host:%s ", ev.host) <= 0)
return -1;
if (tep_get_field_val(s, event, "serial", record, &val, 1) < 0)
return -1;
ev.serial = val;
if (trace_seq_printf(s, "serial:0x%llx ", (unsigned long long)ev.serial) <= 0)
return -1;
if (tep_get_field_val(s, event, "trace_type", record, &val, 1) < 0)
return -1;
switch (val) {
case CXL_POISON_TRACE_LIST:
ev.trace_type = "List";
break;
case CXL_POISON_TRACE_INJECT:
ev.trace_type = "Inject";
break;
case CXL_POISON_TRACE_CLEAR:
ev.trace_type = "Clear";
break;
default:
ev.trace_type = "Invalid";
}
if (trace_seq_printf(s, "trace_type:%s ", ev.trace_type) <= 0)
return -1;
ev.region = tep_get_field_raw(s, event, "region",
record, &len, 1);
if (!ev.region)
return -1;
if (trace_seq_printf(s, "region:%s ", ev.region) <= 0)
return -1;
ev.uuid = tep_get_field_raw(s, event, "uuid",
record, &len, 1);
if (!ev.uuid)
return -1;
if (trace_seq_printf(s, "region_uuid:%s ", ev.uuid) <= 0)
return -1;
if (tep_get_field_val(s, event, "hpa", record, &val, 1) < 0)
return -1;
ev.hpa = val;
if (trace_seq_printf(s, "poison list: hpa:0x%llx ", (unsigned long long)ev.hpa) <= 0)
return -1;
if (tep_get_field_val(s, event, "dpa", record, &val, 1) < 0)
return -1;
ev.dpa = val;
if (trace_seq_printf(s, "dpa:0x%llx ", (unsigned long long)ev.dpa) <= 0)
return -1;
if (tep_get_field_val(s, event, "dpa_length", record, &val, 1) < 0)
return -1;
ev.dpa_length = val;
if (trace_seq_printf(s, "dpa_length:0x%x ", ev.dpa_length) <= 0)
return -1;
if (tep_get_field_val(s, event, "source", record, &val, 1) < 0)
return -1;
switch (val) {
case CXL_POISON_SOURCE_UNKNOWN:
ev.source = "Unknown";
break;
case CXL_POISON_SOURCE_EXTERNAL:
ev.source = "External";
break;
case CXL_POISON_SOURCE_INTERNAL:
ev.source = "Internal";
break;
case CXL_POISON_SOURCE_INJECTED:
ev.source = "Injected";
break;
case CXL_POISON_SOURCE_VENDOR:
ev.source = "Vendor";
break;
default:
ev.source = "Invalid";
}
if (trace_seq_printf(s, "source:%s ", ev.source) <= 0)
return -1;
if (tep_get_field_val(s, event, "flags", record, &val, 1) < 0)
return -1;
ev.flags = val;
if (trace_seq_printf(s, "flags:%d ", ev.flags) <= 0)
return -1;
if (ev.flags & CXL_POISON_FLAG_OVERFLOW) {
if (tep_get_field_val(s, event, "overflow_ts", record, &val, 1) < 0)
return -1;
convert_timestamp(val, ev.overflow_ts, sizeof(ev.overflow_ts));
} else {
strscpy(ev.overflow_ts, "1970-01-01 00:00:00 +0000",
sizeof(ev.overflow_ts));
}
if (trace_seq_printf(s, "overflow timestamp:%s\n", ev.overflow_ts) <= 0)
return -1;
/* Insert data into the SGBD */
#ifdef HAVE_SQLITE3
ras_store_cxl_poison_event(ras, &ev);
#endif
#ifdef HAVE_ABRT_REPORT
/* Report event to ABRT */
ras_report_cxl_poison_event(ras, &ev);
#endif
return 0;
}
/* CXL AER Errors */
#define CXL_AER_UE_CACHE_DATA_PARITY BIT(0)
#define CXL_AER_UE_CACHE_ADDR_PARITY BIT(1)
#define CXL_AER_UE_CACHE_BE_PARITY BIT(2)
#define CXL_AER_UE_CACHE_DATA_ECC BIT(3)
#define CXL_AER_UE_MEM_DATA_PARITY BIT(4)
#define CXL_AER_UE_MEM_ADDR_PARITY BIT(5)
#define CXL_AER_UE_MEM_BE_PARITY BIT(6)
#define CXL_AER_UE_MEM_DATA_ECC BIT(7)
#define CXL_AER_UE_REINIT_THRESH BIT(8)
#define CXL_AER_UE_RSVD_ENCODE BIT(9)
#define CXL_AER_UE_POISON BIT(10)
#define CXL_AER_UE_RECV_OVERFLOW BIT(11)
#define CXL_AER_UE_INTERNAL_ERR BIT(14)
#define CXL_AER_UE_IDE_TX_ERR BIT(15)
#define CXL_AER_UE_IDE_RX_ERR BIT(16)
#define CXL_AER_CE_CACHE_DATA_ECC BIT(0)
#define CXL_AER_CE_MEM_DATA_ECC BIT(1)
#define CXL_AER_CE_CRC_THRESH BIT(2)
#define CXL_AER_CE_RETRY_THRESH BIT(3)
#define CXL_AER_CE_CACHE_POISON BIT(4)
#define CXL_AER_CE_MEM_POISON BIT(5)
#define CXL_AER_CE_PHYS_LAYER_ERR BIT(6)
struct cxl_error_list {
uint32_t bit;
const char *error;
};
static const struct cxl_error_list cxl_aer_ue[] = {
{ .bit = CXL_AER_UE_CACHE_DATA_PARITY, .error = "Cache Data Parity Error" },
{ .bit = CXL_AER_UE_CACHE_ADDR_PARITY, .error = "Cache Address Parity Error" },
{ .bit = CXL_AER_UE_CACHE_BE_PARITY, .error = "Cache Byte Enable Parity Error" },
{ .bit = CXL_AER_UE_CACHE_DATA_ECC, .error = "Cache Data ECC Error" },
{ .bit = CXL_AER_UE_MEM_DATA_PARITY, .error = "Memory Data Parity Error" },
{ .bit = CXL_AER_UE_MEM_ADDR_PARITY, .error = "Memory Address Parity Error" },
{ .bit = CXL_AER_UE_MEM_BE_PARITY, .error = "Memory Byte Enable Parity Error" },
{ .bit = CXL_AER_UE_MEM_DATA_ECC, .error = "Memory Data ECC Error" },
{ .bit = CXL_AER_UE_REINIT_THRESH, .error = "REINIT Threshold Hit" },
{ .bit = CXL_AER_UE_RSVD_ENCODE, .error = "Received Unrecognized Encoding" },
{ .bit = CXL_AER_UE_POISON, .error = "Received Poison From Peer" },
{ .bit = CXL_AER_UE_RECV_OVERFLOW, .error = "Receiver Overflow" },
{ .bit = CXL_AER_UE_INTERNAL_ERR, .error = "Component Specific Error" },
{ .bit = CXL_AER_UE_IDE_TX_ERR, .error = "IDE Tx Error" },
{ .bit = CXL_AER_UE_IDE_RX_ERR, .error = "IDE Rx Error" },
};
static const struct cxl_error_list cxl_aer_ce[] = {
{ .bit = CXL_AER_CE_CACHE_DATA_ECC, .error = "Cache Data ECC Error" },
{ .bit = CXL_AER_CE_MEM_DATA_ECC, .error = "Memory Data ECC Error" },
{ .bit = CXL_AER_CE_CRC_THRESH, .error = "CRC Threshold Hit" },
{ .bit = CXL_AER_CE_RETRY_THRESH, .error = "Retry Threshold" },
{ .bit = CXL_AER_CE_CACHE_POISON, .error = "Received Cache Poison From Peer" },
{ .bit = CXL_AER_CE_MEM_POISON, .error = "Received Memory Poison From Peer" },
{ .bit = CXL_AER_CE_PHYS_LAYER_ERR, .error = "Received Error From Physical Layer" },
};
static int decode_cxl_error_status(struct trace_seq *s, uint32_t status,
const struct cxl_error_list *cxl_error_list,
uint8_t num_elems)
{
int i;
for (i = 0; i < num_elems; i++) {
if (status & cxl_error_list[i].bit)
if (trace_seq_printf(s, "\'%s\' ", cxl_error_list[i].error) <= 0)
return -1;
}
return 0;
}
int ras_cxl_aer_ue_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context)
{
int len, i;
unsigned long long val;
struct ras_events *ras = context;
struct ras_cxl_aer_ue_event ev;
memset(&ev, 0, sizeof(ev));
get_timestamp(s, record, ras, (char *)&ev.timestamp, sizeof(ev.timestamp));
if (trace_seq_printf(s, "%s ", ev.timestamp) <= 0)
return -1;
ev.memdev = tep_get_field_raw(s, event, "memdev",
record, &len, 1);
if (!ev.memdev)
return -1;
if (trace_seq_printf(s, "memdev:%s ", ev.memdev) <= 0)
return -1;
ev.host = tep_get_field_raw(s, event, "host",
record, &len, 1);
if (!ev.host)
return -1;
if (trace_seq_printf(s, "host:%s ", ev.host) <= 0)
return -1;
if (tep_get_field_val(s, event, "serial", record, &val, 1) < 0)
return -1;
ev.serial = val;
if (trace_seq_printf(s, "serial:0x%llx ", (unsigned long long)ev.serial) <= 0)
return -1;
if (tep_get_field_val(s, event, "status", record, &val, 1) < 0)
return -1;
ev.error_status = val;
if (trace_seq_printf(s, "error status:") <= 0)
return -1;
if (decode_cxl_error_status(s, ev.error_status,
cxl_aer_ue, ARRAY_SIZE(cxl_aer_ue)) < 0)
return -1;
if (tep_get_field_val(s, event, "first_error", record, &val, 1) < 0)
return -1;
ev.first_error = val;
if (trace_seq_printf(s, "first error:") <= 0)
return -1;
if (decode_cxl_error_status(s, ev.first_error,
cxl_aer_ue, ARRAY_SIZE(cxl_aer_ue)) < 0)
return -1;
ev.header_log = tep_get_field_raw(s, event, "header_log",
record, &len, 1);
if (!ev.header_log)
return -1;
if (trace_seq_printf(s, "header log:\n") <= 0)
return -1;
for (i = 0; i < CXL_HEADERLOG_SIZE_U32; i++) {
if (trace_seq_printf(s, "%08x ", ev.header_log[i]) <= 0)
break;
if (i > 0 && ((i % 20) == 0))
if (trace_seq_printf(s, "\n") <= 0)
break;
/* Convert header log data to the big-endian format because
* the SQLite database seems uses the big-endian storage.
*/
ev.header_log[i] = htobe32(ev.header_log[i]);
}
if (i < CXL_HEADERLOG_SIZE_U32)
return -1;
/* Insert data into the SGBD */
#ifdef HAVE_SQLITE3
ras_store_cxl_aer_ue_event(ras, &ev);
#endif
#ifdef HAVE_ABRT_REPORT
/* Report event to ABRT */
ras_report_cxl_aer_ue_event(ras, &ev);
#endif
return 0;
}
int ras_cxl_aer_ce_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context)
{
int len;
unsigned long long val;
struct ras_events *ras = context;
struct ras_cxl_aer_ce_event ev;
get_timestamp(s, record, ras, (char *)&ev.timestamp, sizeof(ev.timestamp));
if (trace_seq_printf(s, "%s ", ev.timestamp) <= 0)
return -1;
ev.memdev = tep_get_field_raw(s, event, "memdev",
record, &len, 1);
if (!ev.memdev)
return -1;
if (trace_seq_printf(s, "memdev:%s ", ev.memdev) <= 0)
return -1;
ev.host = tep_get_field_raw(s, event, "host",
record, &len, 1);
if (!ev.host)
return -1;
if (trace_seq_printf(s, "host:%s ", ev.host) <= 0)
return -1;
if (tep_get_field_val(s, event, "serial", record, &val, 1) < 0)
return -1;
ev.serial = val;
if (trace_seq_printf(s, "serial:0x%llx ", (unsigned long long)ev.serial) <= 0)
return -1;
if (tep_get_field_val(s, event, "status", record, &val, 1) < 0)
return -1;
ev.error_status = val;
if (trace_seq_printf(s, "error status:") <= 0)
return -1;
if (decode_cxl_error_status(s, ev.error_status,
cxl_aer_ce, ARRAY_SIZE(cxl_aer_ce)) < 0)
return -1;
/* Insert data into the SGBD */
#ifdef HAVE_SQLITE3
ras_store_cxl_aer_ce_event(ras, &ev);
#endif
#ifdef HAVE_ABRT_REPORT
/* Report event to ABRT */
ras_report_cxl_aer_ce_event(ras, &ev);
#endif
return 0;
}
/*
* CXL rev 3.0 section 8.2.9.2.2; Table 8-49
*/
enum cxl_event_log_type {
CXL_EVENT_TYPE_INFO = 0x00,
CXL_EVENT_TYPE_WARN,
CXL_EVENT_TYPE_FAIL,
CXL_EVENT_TYPE_FATAL,
CXL_EVENT_TYPE_UNKNOWN
};
static char *cxl_event_log_type_str(uint32_t log_type)
{
switch (log_type) {
case CXL_EVENT_TYPE_INFO:
return "Informational";
case CXL_EVENT_TYPE_WARN:
return "Warning";
case CXL_EVENT_TYPE_FAIL:
return "Failure";
case CXL_EVENT_TYPE_FATAL:
return "Fatal";
default:
break;
}
return "Unknown";
}
int ras_cxl_overflow_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context)
{
int len;
unsigned long long val;
struct ras_events *ras = context;
struct ras_cxl_overflow_event ev;
memset(&ev, 0, sizeof(ev));
get_timestamp(s, record, ras, (char *)&ev.timestamp, sizeof(ev.timestamp));
if (trace_seq_printf(s, "%s ", ev.timestamp) <= 0)
return -1;
ev.memdev = tep_get_field_raw(s, event, "memdev", record, &len, 1);
if (!ev.memdev)
return -1;
if (trace_seq_printf(s, "memdev:%s ", ev.memdev) <= 0)
return -1;
ev.host = tep_get_field_raw(s, event, "host", record, &len, 1);
if (!ev.host)
return -1;
if (trace_seq_printf(s, "host:%s ", ev.host) <= 0)
return -1;
if (tep_get_field_val(s, event, "serial", record, &val, 1) < 0)
return -1;
ev.serial = val;
if (trace_seq_printf(s, "serial:0x%llx ", (unsigned long long)ev.serial) <= 0)
return -1;
if (tep_get_field_val(s, event, "log", record, &val, 1) < 0)
return -1;
ev.log_type = cxl_event_log_type_str(val);
if (trace_seq_printf(s, "log type:%s ", ev.log_type) <= 0)
return -1;
if (tep_get_field_val(s, event, "count", record, &val, 1) < 0)
return -1;
ev.count = val;
if (tep_get_field_val(s, event, "first_ts", record, &val, 1) < 0)
return -1;
convert_timestamp(val, ev.first_ts, sizeof(ev.first_ts));
if (tep_get_field_val(s, event, "last_ts", record, &val, 1) < 0)
return -1;
convert_timestamp(val, ev.last_ts, sizeof(ev.last_ts));
if (ev.count) {
if (trace_seq_printf(s, "%u errors from %s to %s\n",
ev.count, ev.first_ts, ev.last_ts) <= 0)
return -1;
}
/* Insert data into the SGBD */
#ifdef HAVE_SQLITE3
ras_store_cxl_overflow_event(ras, &ev);
#endif
#ifdef HAVE_ABRT_REPORT
/* Report event to ABRT */
ras_report_cxl_overflow_event(ras, &ev);
#endif
return 0;
}
/*
* Common Event Record Format
* CXL 3.0 section 8.2.9.2.1; Table 8-42
*/
#define CXL_EVENT_RECORD_FLAG_PERMANENT BIT(2)
#define CXL_EVENT_RECORD_FLAG_MAINT_NEEDED BIT(3)
#define CXL_EVENT_RECORD_FLAG_PERF_DEGRADED BIT(4)
#define CXL_EVENT_RECORD_FLAG_HW_REPLACE BIT(5)
static const struct cxl_event_flags cxl_hdr_flags[] = {
{ .bit = CXL_EVENT_RECORD_FLAG_PERMANENT, .flag = "PERMANENT_CONDITION" },
{ .bit = CXL_EVENT_RECORD_FLAG_MAINT_NEEDED, .flag = "MAINTENANCE_NEEDED" },
{ .bit = CXL_EVENT_RECORD_FLAG_PERF_DEGRADED, .flag = "PERFORMANCE_DEGRADED" },
{ .bit = CXL_EVENT_RECORD_FLAG_HW_REPLACE, .flag = "HARDWARE_REPLACEMENT_NEEDED" },
};
static int handle_ras_cxl_common_hdr(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context,
struct ras_cxl_event_common_hdr *hdr)
{
int len;
unsigned long long val;
struct ras_events *ras = context;
get_timestamp(s, record, ras, (char *)&hdr->timestamp, sizeof(hdr->timestamp));
if (trace_seq_printf(s, "%s ", hdr->timestamp) <= 0)
return -1;
hdr->memdev = tep_get_field_raw(s, event, "memdev", record, &len, 1);
if (!hdr->memdev)
return -1;
if (trace_seq_printf(s, "memdev:%s ", hdr->memdev) <= 0)
return -1;
hdr->host = tep_get_field_raw(s, event, "host", record, &len, 1);
if (!hdr->host)
return -1;
if (trace_seq_printf(s, "host:%s ", hdr->host) <= 0)
return -1;
if (tep_get_field_val(s, event, "serial", record, &val, 1) < 0)
return -1;
hdr->serial = val;
if (trace_seq_printf(s, "serial:0x%llx ", (unsigned long long)hdr->serial) <= 0)
return -1;
if (tep_get_field_val(s, event, "log", record, &val, 1) < 0)
return -1;
hdr->log_type = cxl_event_log_type_str(val);
if (trace_seq_printf(s, "log type:%s ", hdr->log_type) <= 0)
return -1;
hdr->hdr_uuid = tep_get_field_raw(s, event, "hdr_uuid", record, &len, 1);
if (!hdr->hdr_uuid)
return -1;
hdr->hdr_uuid = uuid_be(hdr->hdr_uuid);
if (trace_seq_printf(s, "hdr_uuid:%s ", hdr->hdr_uuid) <= 0)
return -1;
if (tep_get_field_val(s, event, "hdr_flags", record, &val, 1) < 0)
return -1;
hdr->hdr_flags = val;
if (decode_cxl_event_flags(s, hdr->hdr_flags, cxl_hdr_flags,
ARRAY_SIZE(cxl_hdr_flags)) < 0)
return -1;
if (tep_get_field_val(s, event, "hdr_handle", record, &val, 1) < 0)
return -1;
hdr->hdr_handle = val;
if (trace_seq_printf(s, "hdr_handle:0x%x ", hdr->hdr_handle) <= 0)
return -1;
if (tep_get_field_val(s, event, "hdr_related_handle", record, &val, 1) < 0)
return -1;
hdr->hdr_related_handle = val;
if (trace_seq_printf(s, "hdr_related_handle:0x%x ", hdr->hdr_related_handle) <= 0)
return -1;
if (tep_get_field_val(s, event, "hdr_timestamp", record, &val, 1) < 0)
return -1;
convert_timestamp(val, hdr->hdr_timestamp, sizeof(hdr->hdr_timestamp));
if (trace_seq_printf(s, "hdr_timestamp:%s ", hdr->hdr_timestamp) <= 0)
return -1;
if (tep_get_field_val(s, event, "hdr_length", record, &val, 1) < 0)
return -1;
hdr->hdr_length = val;
if (trace_seq_printf(s, "hdr_length:%u ", hdr->hdr_length) <= 0)
return -1;
if (tep_get_field_val(s, event, "hdr_maint_op_class", record, &val, 1) < 0)
return -1;
hdr->hdr_maint_op_class = val;
if (trace_seq_printf(s, "hdr_maint_op_class:%u ", hdr->hdr_maint_op_class) <= 0)
return -1;
return 0;
}
int ras_cxl_generic_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context)
{
int len, i;
struct ras_events *ras = context;
struct ras_cxl_generic_event ev;
const uint8_t *buf;
memset(&ev, 0, sizeof(ev));
if (handle_ras_cxl_common_hdr(s, record, event, context, &ev.hdr) < 0)
return -1;
ev.data = tep_get_field_raw(s, event, "data", record, &len, 1);
if (!ev.data)
return -1;
i = 0;
buf = ev.data;
if (trace_seq_printf(s, "\ndata:\n %08x: ", i) <= 0)
return -1;
for (i = 0; i < CXL_EVENT_RECORD_DATA_LENGTH; i += 4) {
if (i > 0 && ((i % 16) == 0))
if (trace_seq_printf(s, "\n %08x: ", i) <= 0)
break;
if (trace_seq_printf(s, "%02x%02x%02x%02x ",
buf[i], buf[i + 1], buf[i + 2], buf[i + 3]) <= 0)
break;
}
/* Insert data into the SGBD */
#ifdef HAVE_SQLITE3
ras_store_cxl_generic_event(ras, &ev);
#endif
#ifdef HAVE_ABRT_REPORT
/* Report event to ABRT */
ras_report_cxl_generic_event(ras, &ev);
#endif
return 0;
}
#define CXL_DPA_VOLATILE BIT(0)
#define CXL_DPA_NOT_REPAIRABLE BIT(1)
static const struct cxl_event_flags cxl_dpa_flags[] = {
{ .bit = CXL_DPA_VOLATILE, .flag = "VOLATILE" },
{ .bit = CXL_DPA_NOT_REPAIRABLE, .flag = "NOT_REPAIRABLE" },
};
/*
* General Media Event Record - GMER
* CXL rev 3.0 Section 8.2.9.2.1.1; Table 8-43
*/
#define CXL_GMER_EVT_DESC_UNCORECTABLE_EVENT BIT(0)
#define CXL_GMER_EVT_DESC_THRESHOLD_EVENT BIT(1)
#define CXL_GMER_EVT_DESC_POISON_LIST_OVERFLOW BIT(2)
static const struct cxl_event_flags cxl_gmer_event_desc_flags[] = {
{ .bit = CXL_GMER_EVT_DESC_UNCORECTABLE_EVENT, .flag = "UNCORRECTABLE EVENT" },
{ .bit = CXL_GMER_EVT_DESC_THRESHOLD_EVENT, .flag = "THRESHOLD EVENT" },
{ .bit = CXL_GMER_EVT_DESC_POISON_LIST_OVERFLOW, .flag = "POISON LIST OVERFLOW" },
};
#define CXL_GMER_VALID_CHANNEL BIT(0)
#define CXL_GMER_VALID_RANK BIT(1)
#define CXL_GMER_VALID_DEVICE BIT(2)
#define CXL_GMER_VALID_COMPONENT BIT(3)
static const char * const cxl_gmer_mem_event_type[] = {
"ECC Error",
"Invalid Address",
"Data Path Error",
};
static const char * const cxl_gmer_trans_type[] = {
"Unknown",
"Host Read",
"Host Write",
"Host Scan Media",
"Host Inject Poison",
"Internal Media Scrub",
"Internal Media Management",
};
int ras_cxl_general_media_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context)
{
int len, i;
unsigned long long val;
struct ras_events *ras = context;
struct ras_cxl_general_media_event ev;
memset(&ev, 0, sizeof(ev));
if (handle_ras_cxl_common_hdr(s, record, event, context, &ev.hdr) < 0)
return -1;
if (tep_get_field_val(s, event, "dpa", record, &val, 1) < 0)
return -1;
ev.dpa = val;
if (trace_seq_printf(s, "dpa:0x%llx ", (unsigned long long)ev.dpa) <= 0)
return -1;
if (tep_get_field_val(s, event, "dpa_flags", record, &val, 1) < 0)
return -1;
ev.dpa_flags = val;
if (trace_seq_printf(s, "dpa_flags:") <= 0)
return -1;
if (decode_cxl_event_flags(s, ev.dpa_flags, cxl_dpa_flags, ARRAY_SIZE(cxl_dpa_flags)) < 0)
return -1;
if (tep_get_field_val(s, event, "descriptor", record, &val, 1) < 0)
return -1;
ev.descriptor = val;
if (trace_seq_printf(s, "descriptor:") <= 0)
return -1;
if (decode_cxl_event_flags(s, ev.descriptor, cxl_gmer_event_desc_flags,
ARRAY_SIZE(cxl_gmer_event_desc_flags)) < 0)
return -1;
if (tep_get_field_val(s, event, "type", record, &val, 1) < 0)
return -1;
ev.type = val;
if (trace_seq_printf(s, "type:%s ",
get_cxl_type_str(cxl_gmer_mem_event_type,
ARRAY_SIZE(cxl_gmer_mem_event_type), ev.type)) <= 0)
return -1;
if (tep_get_field_val(s, event, "transaction_type", record, &val, 1) < 0)
return -1;
ev.transaction_type = val;
if (trace_seq_printf(s, "transaction_type:%s ",
get_cxl_type_str(cxl_gmer_trans_type,
ARRAY_SIZE(cxl_gmer_trans_type),
ev.transaction_type)) <= 0)
return -1;
if (tep_get_field_val(s, event, "validity_flags", record, &val, 1) < 0)
return -1;
ev.validity_flags = val;
if (ev.validity_flags & CXL_GMER_VALID_CHANNEL) {
if (tep_get_field_val(s, event, "channel", record, &val, 1) < 0)
return -1;
ev.channel = val;
if (trace_seq_printf(s, "channel:%u ", ev.channel) <= 0)
return -1;
}
if (ev.validity_flags & CXL_GMER_VALID_RANK) {
if (tep_get_field_val(s, event, "rank", record, &val, 1) < 0)
return -1;
ev.rank = val;
if (trace_seq_printf(s, "rank:%u ", ev.rank) <= 0)
return -1;
}
if (ev.validity_flags & CXL_GMER_VALID_DEVICE) {
if (tep_get_field_val(s, event, "device", record, &val, 1) < 0)
return -1;
ev.device = val;
if (trace_seq_printf(s, "device:%x ", ev.device) <= 0)
return -1;
}
if (ev.validity_flags & CXL_GMER_VALID_COMPONENT) {
ev.comp_id = tep_get_field_raw(s, event, "comp_id", record, &len, 1);
if (!ev.comp_id)
return -1;
if (trace_seq_printf(s, "comp_id:") <= 0)
return -1;
for (i = 0; i < CXL_EVENT_GEN_MED_COMP_ID_SIZE; i++) {
if (trace_seq_printf(s, "%02x ", ev.comp_id[i]) <= 0)
break;
}
}
/* Insert data into the SGBD */
#ifdef HAVE_SQLITE3
ras_store_cxl_general_media_event(ras, &ev);
#endif
#ifdef HAVE_ABRT_REPORT
/* Report event to ABRT */
ras_report_cxl_general_media_event(ras, &ev);
#endif
return 0;
}
/*
* DRAM Event Record - DER
*
* CXL rev 3.0 section 8.2.9.2.1.2; Table 8-44
*/
#define CXL_DER_VALID_CHANNEL BIT(0)
#define CXL_DER_VALID_RANK BIT(1)
#define CXL_DER_VALID_NIBBLE BIT(2)
#define CXL_DER_VALID_BANK_GROUP BIT(3)
#define CXL_DER_VALID_BANK BIT(4)
#define CXL_DER_VALID_ROW BIT(5)
#define CXL_DER_VALID_COLUMN BIT(6)
#define CXL_DER_VALID_CORRECTION_MASK BIT(7)
int ras_cxl_dram_event_handler(struct trace_seq *s,
struct tep_record *record,
struct tep_event *event, void *context)
{
int len, i;
unsigned long long val;
struct ras_events *ras = context;
struct ras_cxl_dram_event ev;
memset(&ev, 0, sizeof(ev));
if (handle_ras_cxl_common_hdr(s, record, event, context, &ev.hdr) < 0)
return -1;
if (tep_get_field_val(s, event, "dpa", record, &val, 1) < 0)
return -1;
ev.dpa = val;
if (trace_seq_printf(s, "dpa:0x%llx ", (unsigned long long)ev.dpa) <= 0)
return -1;
if (tep_get_field_val(s, event, "dpa_flags", record, &val, 1) < 0)
return -1;
ev.dpa_flags = val;
if (trace_seq_printf(s, "dpa_flags:") <= 0)
return -1;
if (decode_cxl_event_flags(s, ev.dpa_flags, cxl_dpa_flags,
ARRAY_SIZE(cxl_dpa_flags)) < 0)
return -1;
if (tep_get_field_val(s, event, "descriptor", record, &val, 1) < 0)
return -1;
ev.descriptor = val;
if (trace_seq_printf(s, "descriptor:") <= 0)
return -1;
if (decode_cxl_event_flags(s, ev.descriptor, cxl_gmer_event_desc_flags,
ARRAY_SIZE(cxl_gmer_event_desc_flags)) < 0)
return -1;
if (tep_get_field_val(s, event, "type", record, &val, 1) < 0)
return -1;
ev.type = val;
if (trace_seq_printf(s, "type:%s ",
get_cxl_type_str(cxl_gmer_mem_event_type,
ARRAY_SIZE(cxl_gmer_mem_event_type),
ev.type)) <= 0)
return -1;
if (tep_get_field_val(s, event, "transaction_type", record, &val, 1) < 0)
return -1;
ev.transaction_type = val;
if (trace_seq_printf(s, "transaction_type:%s ",
get_cxl_type_str(cxl_gmer_trans_type,
ARRAY_SIZE(cxl_gmer_trans_type),
ev.transaction_type)) <= 0)
return -1;
if (tep_get_field_val(s, event, "validity_flags", record, &val, 1) < 0)
return -1;
ev.validity_flags = val;
if (ev.validity_flags & CXL_DER_VALID_CHANNEL) {
if (tep_get_field_val(s, event, "channel", record, &val, 1) < 0)
return -1;
ev.channel = val;
if (trace_seq_printf(s, "channel:%u ", ev.channel) <= 0)
return -1;
}
if (ev.validity_flags & CXL_DER_VALID_RANK) {
if (tep_get_field_val(s, event, "rank", record, &val, 1) < 0)
return -1;
ev.rank = val;
if (trace_seq_printf(s, "rank:%u ", ev.rank) <= 0)
return -1;
}
if (ev.validity_flags & CXL_DER_VALID_NIBBLE) {
if (tep_get_field_val(s, event, "nibble_mask", record, &val, 1) < 0)
return -1;
ev.nibble_mask = val;
if (trace_seq_printf(s, "nibble_mask:%u ", ev.nibble_mask) <= 0)
return -1;
}
if (ev.validity_flags & CXL_DER_VALID_BANK_GROUP) {
if (tep_get_field_val(s, event, "bank_group", record, &val, 1) < 0)
return -1;
ev.bank_group = val;
if (trace_seq_printf(s, "bank_group:%u ", ev.bank_group) <= 0)
return -1;
}
if (ev.validity_flags & CXL_DER_VALID_BANK) {
if (tep_get_field_val(s, event, "bank", record, &val, 1) < 0)
return -1;
ev.bank = val;
if (trace_seq_printf(s, "bank:%u ", ev.bank) <= 0)
return -1;
}
if (ev.validity_flags & CXL_DER_VALID_ROW) {
if (tep_get_field_val(s, event, "row", record, &val, 1) < 0)
return -1;
ev.row = val;
if (trace_seq_printf(s, "row:%u ", ev.row) <= 0)
return -1;
}
if (ev.validity_flags & CXL_DER_VALID_COLUMN) {
if (tep_get_field_val(s, event, "column", record, &val, 1) < 0)
return -1;
ev.column = val;
if (trace_seq_printf(s, "column:%u ", ev.column) <= 0)
return -1;
}
if (ev.validity_flags & CXL_DER_VALID_CORRECTION_MASK) {
ev.cor_mask = tep_get_field_raw(s, event, "cor_mask", record, &len, 1);
if (!ev.cor_mask)
return -1;
if (trace_seq_printf(s, "correction_mask:") <= 0)