forked from linux-nvme/nvme-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocp-telemetry-decode.c
1817 lines (1575 loc) · 59.7 KB
/
ocp-telemetry-decode.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) 2024 Western Digital Corporation or its affiliates.
*
* Authors: Jeff Lien <jeff.lien@wdc.com>,
*/
#include "common.h"
#include "nvme.h"
#include "libnvme.h"
#include "plugin.h"
#include "linux/types.h"
#include "util/types.h"
#include "nvme-print.h"
#include "ocp-telemetry-decode.h"
void print_vu_event_data(__u32 size, __u8 *data)
{
int j;
__u16 vu_event_id = *(__u16 *)data;
printf(" VU Event ID : 0x%02x\n", le16_to_cpu(vu_event_id));
printf(" VU Data : 0x");
for (j = 2; j < size; j++)
printf("%x", data[j]);
printf("\n\n");
}
void print_stats_desc(struct telemetry_stats_desc *stat_desc)
{
int j;
/* Get the statistics Identifier string name and data size */
__u16 stat_id = stat_desc->id;
__u32 stat_data_sz = ((stat_desc->size) * 4);
printf("Statistics Identifier : 0x%x, %s\n",
stat_id, telemetry_stat_id_to_string(stat_id));
printf("Statistics info : 0x%x\n", stat_desc->info);
printf("NS info : 0x%x\n", stat_desc->ns_info);
printf("Statistic Data Size : 0x%x\n", le16_to_cpu(stat_data_sz));
printf("Namespace ID[15:0] : 0x%x\n", stat_desc->nsid);
if (stat_data_sz > 0) {
printf("%s : 0x",
telemetry_stat_id_to_string(stat_id));
for (j = 0; j < stat_data_sz; j++)
printf("%02x", stat_desc->data[j]);
printf("\n");
}
printf("\n");
}
void print_telemetry_fifo_event(__u8 class_type,
__u16 id, __u8 size_dw, __u8 *data)
{
int j;
const char *class_str = NULL;
__u32 size = size_dw * 4;
char time_str[40];
uint64_t timestamp = 0;
memset((void *)time_str, '\0', 40);
if (class_type) {
class_str = telemetry_event_class_to_string(class_type);
printf("Event Class : %s\n", class_str);
printf(" Size : 0x%02x\n", size);
}
switch (class_type) {
case TELEMETRY_TIMESTAMP_CLASS:
timestamp = (0x0000FFFFFFFFFFFF & le64_to_cpu(*(uint64_t *)data));
memset((void *)time_str, 0, 9);
sprintf((char *)time_str, "%04d:%02d:%02d", (int)(le64_to_cpu(timestamp)/3600),
(int)((le64_to_cpu(timestamp%3600)/60)),
(int)(le64_to_cpu(timestamp%60)));
printf(" Event ID : 0x%04x %s\n", id, telemetry_ts_event_to_string(id));
printf(" Timestamp : %s\n", time_str);
if (size > 8) {
printf(" VU Data : 0x");
for (j = 8; j < size; j++)
printf("%02x", data[j]);
printf("\n\n");
}
break;
case TELEMETRY_PCIE_CLASS:
printf(" Event ID : 0x%04x %s\n",
id, telemetry_pcie_event_id_to_string(id));
printf(" State : 0x%02x %s\n",
data[0], telemetry_pcie_state_data_to_string(data[0]));
printf(" Speed : 0x%02x %s\n",
data[1], telemetry_pcie_speed_data_to_string(data[1]));
printf(" Width : 0x%02x %s\n",
data[2], telemetry_pcie_width_data_to_string(data[2]));
if (size > 4) {
printf(" VU Data : ");
for (j = 4; j < size; j++)
printf("%x", data[j]);
printf("\n\n");
}
break;
case TELEMETRY_NVME_CLASS:
printf(" Event ID : 0x%04x %s\n",
id, telemetry_nvme_event_id_to_string(id));
if ((id == ADMIN_QUEUE_NONZERO_STATUS) ||
(id == IO_QUEUE_NONZERO_STATUS)) {
printf(" Cmd Op Code : 0x%02x\n", data[0]);
__u16 status;
__u16 cmd_id;
__u16 sq_id;
memcpy(&status, &data[1], sizeof(status));
memcpy(&cmd_id, &data[3], sizeof(cmd_id));
memcpy(&sq_id, &data[5], sizeof(sq_id));
printf(" Status Code : 0x%04x\n", le16_to_cpu(status));
printf(" Cmd ID : 0x%04x\n", le16_to_cpu(cmd_id));
printf(" SQ ID : 0x%04x\n", le16_to_cpu(sq_id));
printf(" LID,FID,Other Cmd Reserved : 0x%02x\n", data[7]);
} else if (id == CC_REGISTER_CHANGED) {
__u32 cc_reg_data = *(__u32 *)data;
printf(" CC Reg Data : 0x%08x\n",
le32_to_cpu(cc_reg_data));
} else if (id == CSTS_REGISTER_CHANGED) {
__u32 csts_reg_data = *(__u32 *)data;
printf(" CSTS Reg Data : 0x%08x\n",
le32_to_cpu(csts_reg_data));
} else if (id == OOB_COMMAND) {
printf(" Cmd Op Code : 0x%02x\n", data[0]);
__u16 status;
memcpy(&status, &data[1], sizeof(status));
printf(" Admin Cmd Status : 0x%04x\n", le16_to_cpu(status));
printf(" NVMe MI SC : 0x%02x\n", data[3]);
printf(" Byte1 Req Msg : 0x%02x\n", data[4]);
printf(" Byte2 Req Msg : 0x%02x\n", data[5]);
} else if (id == OOB_AER_EVENT_MSG_TRANS) {
__u64 aem = *(__u64 *)data;
printf(" AEM : 0x%016"PRIx64"\n",
le64_to_cpu(aem));
}
if (size > 8)
print_vu_event_data((size-8), (__u8 *)&data[8]);
break;
case TELEMETRY_RESET_CLASS:
printf(" Event ID : 0x%04x %s\n",
id, telemetry_reset_event_id_to_string(id));
if (size)
print_vu_event_data(size, data);
break;
case TELEMETRY_BOOT_SEQ_CLASS:
printf(" Event ID : 0x%04x %s\n",
id, telemetry_boot_seq_event_id_to_string(id));
if (size)
print_vu_event_data(size, data);
break;
case TELEMETRY_FW_ASSERT_CLASS:
printf(" Event ID : 0x%04x %s\n",
id, telemetry_fw_assert_event_id_to_string(id));
if (size)
print_vu_event_data(size, data);
break;
case TELEMETRY_TEMPERATURE_CLASS:
printf(" Event ID : 0x%04x %s\n",
id, telemetry_temperature_event_id_to_string(id));
if (size)
print_vu_event_data(size, data);
break;
case TELEMETRY_MEDIA_DBG_CLASS:
printf(" Event ID : 0x%04x %s\n",
id, telemetry_media_debug_event_id_to_string(id));
if (size)
print_vu_event_data(size, data);
break;
case TELEMETRY_MEDIA_WEAR_CLASS:
printf(" Event ID : 0x%04x %s\n",
id, telemetry_media_wear_event_id_to_string(id));
__u32 host_tb_written = *(__u32 *)&data[0];
__u32 media_tb_written = *(__u32 *)&data[4];
__u32 media_tb_erased = *(__u32 *)&data[8];
printf(" Host TB Written : 0x%04x\n",
le16_to_cpu(host_tb_written));
printf(" Media TB Written : 0x%04x\n",
le16_to_cpu(media_tb_written));
printf(" Media TB Erased : 0x%04x\n",
le16_to_cpu(media_tb_erased));
if (size > 12)
print_vu_event_data((size-12), (__u8 *)&data[12]);
break;
case TELEMETRY_STAT_SNAPSHOT_CLASS:
printf(" Statistic ID : 0x%02x %s\n",
id, telemetry_stat_id_to_string(id));
print_stats_desc((struct telemetry_stats_desc *)data);
break;
case TELEMETRY_VIRTUAL_FIFO_EVENT_CLASS:
printf(" Event ID : 0x%04x %s\n",
id, telemetry_virtual_fifo_event_id_to_string(id));
__u16 vu_event_id = *(__u16 *)data;
printf(" VU Virtual FIFO Event ID : 0x%02x\n", le16_to_cpu(vu_event_id));
printf("\n");
break;
default:
/*
* printf("Unknown Event Class Type\n");
* printf("Data : 0x");
* for (j = 0; j < size; j++)
* printf("%x", data[j]);
* printf("\n\n");
*/
break;
}
}
struct statistic_entry statistic_identifiers_map[] = {
{ 0x00, "Error, this entry does not exist." },
{ 0x01, "Outstanding Admin Commands" },
{ 0x02, "Host Write Bandwidth"},
{ 0x03, "GC Write Bandwidth"},
{ 0x04, "Active Namespaces"},
{ 0x05, "Internal Write Workload"},
{ 0x06, "Internal Read Workload"},
{ 0x07, "Internal Write Queue Depth"},
{ 0x08, "Internal Read Queue Depth"},
{ 0x09, "Pending Trim LBA Count"},
{ 0x0A, "Host Trim LBA Request Count"},
{ 0x0B, "Current NVMe Power State"},
{ 0x0C, "Current DSSD Power State"},
{ 0x0D, "Program Fail Count"},
{ 0x0E, "Erase Fail Count"},
{ 0x0F, "Read Disturb Writes"},
{ 0x10, "Retention Writes"},
{ 0x11, "Wear Leveling Writes"},
{ 0x12, "Read Recovery Writes"},
{ 0x13, "GC Writes"},
{ 0x14, "SRAM Correctable Count"},
{ 0x15, "DRAM Correctable Count"},
{ 0x16, "SRAM Uncorrectable Count"},
{ 0x17, "DRAM Uncorrectable Count"},
{ 0x18, "Data Integrity Error Count"},
{ 0x19, "Read Retry Error Count"},
{ 0x1A, "PERST Events Count"},
{ 0x1B, "Max Die Bad Block"},
{ 0x1C, "Max NAND Channel Bad Block"},
{ 0x1D, "Minimum NAND Channel Bad Block"}
};
struct request_data host_log_page_header[] = {
{ "LogIdentifier", 1 },
{ "Reserved1", 4 },
{ "IEEE OUI Identifier", 3 },
{ "Telemetry Host-Initiated Data Area 1 Last Block", 2 },
{ "Telemetry Host-Initiated Data Area 2 Last Block", 2 },
{ "Telemetry Host-Initiated Data Area 3 Last Block", 2 },
{ "Reserved2", 2 },
{ "Telemetry Host-Initiated Data Area 4 Last Block", 4 },
{ "Reserved3", 360 },
{ "Telemetry Host-Initiated Scope", 1 },
{ "Telemetry Host Initiated Generation Number", 1 },
{ "Telemetry Host-Initiated Data Available", 1 },
{ "Telemetry Controller-Initiated Data Generation Number", 1 }
};
struct request_data controller_log_page_header[] = {
{ "LogIdentifier", 1 },
{ "Reserved1", 4 },
{ "IEEE OUI Identifier", 3 },
{ "Telemetry Host-Initiated Data Area 1 Last Block", 2 },
{ "Telemetry Host-Initiated Data Area 2 Last Block", 2 },
{ "Telemetry Host-Initiated Data Area 3 Last Block", 2 },
{ "Reserved2", 2 },
{ "Telemetry Host-Initiated Data Area 4 Last Block", 4 },
{ "Reserved3", 361 },
{ "Telemetry Controller-Initiated Scope", 1 },
{ "Telemetry Controller-Initiated Data Available", 1 },
{ "Telemetry Controller-Initiated Data Generation Number", 1 }
};
struct request_data reason_identifier[] = {
{ "Error ID", 64 },
{ "File ID", 8 },
{ "Line Number", 2 },
{ "Valid Flags", 1 },
{ "Reserved", 21 },
{ "VU Reason Extension", 32 }
};
struct request_data ocp_header_in_da1[] = {
{ "Major Version", 2 },
{ "Minor Version", 2 },
{ "Reserved1", 4 },
{ "Timestamp", 8 },
{ "Log page GUID", GUID_LEN },
{ "Number Telemetry Profiles Supported", 1 },
{ "Telemetry Profile Selected", 1 },
{ "Reserved2", 6 },
{ "Telemetry String Log Size", 8 },
{ "Reserved3", 8 },
{ "Firmware Revision", 8 },
{ "Reserved4", 32 },
{ "Data Area 1 Statistic Start", 8 },
{ "Data Area 1 Statistic Size", 8 },
{ "Data Area 2 Statistic Start", 8 },
{ "Data Area 2 Statistic Size", 8 },
{ "Reserved5", 32 },
{ "Event FIFO 1 Data Area", 1 },
{ "Event FIFO 2 Data Area", 1 },
{ "Event FIFO 3 Data Area", 1 },
{ "Event FIFO 4 Data Area", 1 },
{ "Event FIFO 5 Data Area", 1 },
{ "Event FIFO 6 Data Area", 1 },
{ "Event FIFO 7 Data Area", 1 },
{ "Event FIFO 8 Data Area", 1 },
{ "Event FIFO 9 Data Area", 1 },
{ "Event FIFO 10 Data Area", 1 },
{ "Event FIFO 11 Data Area", 1 },
{ "Event FIFO 12 Data Area", 1 },
{ "Event FIFO 13 Data Area", 1 },
{ "Event FIFO 14 Data Area", 1 },
{ "Event FIFO 15 Data Area", 1 },
{ "Event FIFO 16 Data Area", 1 },
{ "Event FIFO 1 Start", 8 },
{ "Event FIFO 1 Size", 8 },
{ "Event FIFO 2 Start", 8 },
{ "Event FIFO 2 Size", 8 },
{ "Event FIFO 3 Start", 8 },
{ "Event FIFO 3 Size", 8 },
{ "Event FIFO 4 Start", 8 },
{ "Event FIFO 4 Size", 8 },
{ "Event FIFO 5 Start", 8 },
{ "Event FIFO 5 Size", 8 },
{ "Event FIFO 6 Start", 8 },
{ "Event FIFO 6 Size", 8 },
{ "Event FIFO 7 Start", 8 },
{ "Event FIFO 7 Size", 8 },
{ "Event FIFO 8 Start", 8 },
{ "Event FIFO 8 Size", 8 },
{ "Event FIFO 9 Start", 8 },
{ "Event FIFO 9 Size", 8 },
{ "Event FIFO 10 Start", 8 },
{ "Event FIFO 10 Size", 8 },
{ "Event FIFO 11 Start", 8 },
{ "Event FIFO 11 Size", 8 },
{ "Event FIFO 12 Start", 8 },
{ "Event FIFO 12 Size", 8 },
{ "Event FIFO 13 Start", 8 },
{ "Event FIFO 13 Size", 8 },
{ "Event FIFO 14 Start", 8 },
{ "Event FIFO 14 Size", 8 },
{ "Event FIFO 15 Start", 8 },
{ "Event FIFO 15 Size", 8 },
{ "Event FIFO 16 Start", 8 },
{ "Event FIFO 16 Size", 8 },
{ "Reserved6", 80 }
};
struct request_data smart[] = {
{ "Critical Warning", 1 },
{ "Composite Temperature", 2 },
{ "Available Spare", 1 },
{ "Available Spare Threshold", 1 },
{ "Percentage Used", 1 },
{ "Reserved1", 26 },
{ "Data Units Read", 16 },
{ "Data Units Written", 16 },
{ "Host Read Commands", 16 },
{ "Host Write Commands", 16 },
{ "Controller Busy Time", 16 },
{ "Power Cycles", 16 },
{ "Power On Hours", 16 },
{ "Unsafe Shutdowns", 16 },
{ "Media and Data Integrity Errors", 16 },
{ "Number of Error Information Log Entries", 16 },
{ "Warning Composite Temperature Time", 4 },
{ "Critical Composite Temperature Time", 4 },
{ "Temperature Sensor 1", 2 },
{ "Temperature Sensor 2", 2 },
{ "Temperature Sensor 3", 2 },
{ "Temperature Sensor 4", 2 },
{ "Temperature Sensor 5", 2 },
{ "Temperature Sensor 6", 2 },
{ "Temperature Sensor 7", 2 },
{ "Temperature Sensor 8", 2 },
{ "Thermal Management Temperature 1 Transition Count", 4 },
{ "Thermal Management Temperature 2 Transition Count", 4 },
{ "Total Time for Thermal Management Temperature 1", 4 },
{ "Total Time for Thermal Management Temperature 2", 4 },
{ "Reserved2", 280 }
};
struct request_data smart_extended[] = {
{ "Physical Media Units Written", 16 },
{ "Physical Media Units Read", 16 },
{ "Bad User NAND Blocks Raw Count", 6 },
{ "Bad User NAND Blocks Normalized Value", 2 },
{ "Bad System NAND Blocks Raw Count", 6 },
{ "Bad System NAND Blocks Normalized Value", 2 },
{ "XOR Recovery Count", 8 },
{ "Uncorrectable Read Error Count", 8 },
{ "Soft ECC Error Count", 8 },
{ "End to End Correction Counts Detected Errors", 4 },
{ "End to End Correction Counts Corrected Errors", 4 },
{ "System Data Percent Used", 1 },
{ "Refresh Counts", 7 },
{ "Maximum User Data Erase Count", 4 },
{ "Minimum User Data Erase Count", 4 },
{ "Number of thermal throttling events", 1 },
{ "Current Throttling Status", 1 },
{ "Errata Version Field", 1 },
{ "Point Version Field", 2 },
{ "Minor Version Field", 2 },
{ "Major Version Field", 1 },
{ "PCIe Correctable Error Count", 8 },
{ "Incomplete Shutdowns", 4 },
{ "Reserved1", 4 },
{ "Percent Free Blocks", 1 },
{ "Reserved2", 7 },
{ "Capacitor Health", 2 },
{ "NVMe Base Errata Version", 1 },
{ "NVMe Command Set Errata Version", 1 },
{ "Reserved3", 4 },
{ "Unaligned IO", 8 },
{ "Security Version Number", 8 },
{ "Total NUSE", 8 },
{ "PLP Start Count", 16 },
{ "Endurance Estimate", 16 },
{ "PCIe Link Retraining Count", 8 },
{ "Power State Change Count", 8 },
{ "Lowest Permitted Firmware Revision", 8 },
{ "Reserved4", 278 },
{ "Log Page Version", 2 },
{ "Log page GUID", GUID_LEN }
};
#ifdef CONFIG_JSONC
void json_add_formatted_u32_str(struct json_object *pobject, const char *msg, unsigned int pdata)
{
char data_str[70] = { 0 };
sprintf(data_str, "0x%x", pdata);
json_object_add_value_string(pobject, msg, data_str);
}
void json_add_formatted_var_size_str(struct json_object *pobject, const char *msg, __u8 *pdata,
unsigned int data_size)
{
char description_str[256] = "";
char temp_buffer[3] = { 0 };
for (size_t i = 0; i < data_size; ++i) {
sprintf(temp_buffer, "%02X", pdata[i]);
strcat(description_str, temp_buffer);
}
json_object_add_value_string(pobject, msg, description_str);
}
#endif /* CONFIG_JSONC */
int get_telemetry_das_offset_and_size(
struct nvme_ocp_telemetry_common_header *ptelemetry_common_header,
struct nvme_ocp_telemetry_offsets *ptelemetry_das_offset)
{
if (NULL == ptelemetry_common_header || NULL == ptelemetry_das_offset) {
nvme_show_error("Invalid input arguments.");
return -1;
}
if (ptelemetry_common_header->log_id == NVME_LOG_LID_TELEMETRY_HOST)
ptelemetry_das_offset->header_size =
sizeof(struct nvme_ocp_telemetry_host_initiated_header);
else if (ptelemetry_common_header->log_id == NVME_LOG_LID_TELEMETRY_CTRL)
ptelemetry_das_offset->header_size =
sizeof(struct nvme_ocp_telemetry_controller_initiated_header);
else
return -1;
ptelemetry_das_offset->da1_start_offset = ptelemetry_das_offset->header_size;
ptelemetry_das_offset->da1_size = ptelemetry_common_header->da1_last_block *
OCP_TELEMETRY_DATA_BLOCK_SIZE;
ptelemetry_das_offset->da2_start_offset = ptelemetry_das_offset->da1_start_offset +
ptelemetry_das_offset->da1_size;
ptelemetry_das_offset->da2_size =
(ptelemetry_common_header->da2_last_block -
ptelemetry_common_header->da1_last_block) * OCP_TELEMETRY_DATA_BLOCK_SIZE;
ptelemetry_das_offset->da3_start_offset = ptelemetry_das_offset->da2_start_offset +
ptelemetry_das_offset->da2_size;
ptelemetry_das_offset->da3_size =
(ptelemetry_common_header->da3_last_block -
ptelemetry_common_header->da2_last_block) * OCP_TELEMETRY_DATA_BLOCK_SIZE;
ptelemetry_das_offset->da4_start_offset = ptelemetry_das_offset->da3_start_offset +
ptelemetry_das_offset->da3_size;
ptelemetry_das_offset->da4_size =
(ptelemetry_common_header->da4_last_block -
ptelemetry_common_header->da3_last_block) * OCP_TELEMETRY_DATA_BLOCK_SIZE;
return 0;
}
int get_statistic_id_ascii_string(int identifier, char *description)
{
if (!pstring_buffer || !description)
return -1;
struct nvme_ocp_telemetry_string_header *pocp_ts_header =
(struct nvme_ocp_telemetry_string_header *)pstring_buffer;
//Calculating the sizes of the tables. Note: Data is present in the form of DWORDS,
//So multiplying with sizeof(DWORD)
unsigned long long sits_table_size = (pocp_ts_header->sitsz) * SIZE_OF_DWORD;
//Calculating number of entries present in all 3 tables
int sits_entries = (int)sits_table_size /
sizeof(struct nvme_ocp_statistics_identifier_string_table);
for (int sits_entry = 0; sits_entry < sits_entries; sits_entry++) {
struct nvme_ocp_statistics_identifier_string_table
*peach_statistic_entry =
(struct nvme_ocp_statistics_identifier_string_table *)
(pstring_buffer + (pocp_ts_header->sits * SIZE_OF_DWORD) +
(sits_entry *
sizeof(struct nvme_ocp_statistics_identifier_string_table)));
if (identifier == (int)peach_statistic_entry->vs_statistic_identifier) {
char *pdescription = (char *)(pstring_buffer +
(pocp_ts_header->ascts * SIZE_OF_DWORD) +
(peach_statistic_entry->ascii_id_offset *
SIZE_OF_DWORD));
memcpy(description, pdescription,
peach_statistic_entry->ascii_id_length + 1);
return 0;
}
}
// If ASCII string isn't found, see in our internal Map
// for 2.5 Spec defined strings
if (identifier <= 0x1D) {
strcpy(description, statistic_identifiers_map[identifier].description);
return 0;
}
return -1;
}
int get_event_id_ascii_string(int identifier, int debug_event_class, char *description)
{
if (pstring_buffer == NULL)
return -1;
struct nvme_ocp_telemetry_string_header *pocp_ts_header =
(struct nvme_ocp_telemetry_string_header *)pstring_buffer;
//Calculating the sizes of the tables. Note: Data is present in the form of DWORDS,
//So multiplying with sizeof(DWORD)
unsigned long long ests_table_size = (pocp_ts_header->estsz) * SIZE_OF_DWORD;
//Calculating number of entries present in all 3 tables
int ests_entries = (int)ests_table_size / sizeof(struct nvme_ocp_event_string_table);
for (int ests_entry = 0; ests_entry < ests_entries; ests_entry++) {
struct nvme_ocp_event_string_table *peach_event_entry =
(struct nvme_ocp_event_string_table *)
(pstring_buffer + (pocp_ts_header->ests * SIZE_OF_DWORD) +
(ests_entry * sizeof(struct nvme_ocp_event_string_table)));
if (identifier == (int)peach_event_entry->event_identifier &&
debug_event_class == (int)peach_event_entry->debug_event_class) {
char *pdescription = (char *)(pstring_buffer +
(pocp_ts_header->ascts * SIZE_OF_DWORD) +
(peach_event_entry->ascii_id_offset * SIZE_OF_DWORD));
memcpy(description, pdescription,
peach_event_entry->ascii_id_length + 1);
return 0;
}
}
return -1;
}
int get_vu_event_id_ascii_string(int identifier, int debug_event_class, char *description)
{
if (pstring_buffer == NULL)
return -1;
struct nvme_ocp_telemetry_string_header *pocp_ts_header =
(struct nvme_ocp_telemetry_string_header *)pstring_buffer;
//Calculating the sizes of the tables. Note: Data is present in the form of DWORDS,
//So multiplying with sizeof(DWORD)
unsigned long long vuests_table_size = (pocp_ts_header->vu_estsz) * SIZE_OF_DWORD;
//Calculating number of entries present in all 3 tables
int vu_ests_entries = (int)vuests_table_size /
sizeof(struct nvme_ocp_vu_event_string_table);
for (int vu_ests_entry = 0; vu_ests_entry < vu_ests_entries; vu_ests_entry++) {
struct nvme_ocp_vu_event_string_table *peach_vu_event_entry =
(struct nvme_ocp_vu_event_string_table *)
(pstring_buffer + (pocp_ts_header->vu_ests * SIZE_OF_DWORD) +
(vu_ests_entry * sizeof(struct nvme_ocp_vu_event_string_table)));
if (identifier == (int)peach_vu_event_entry->vu_event_identifier &&
debug_event_class ==
(int)peach_vu_event_entry->debug_event_class) {
char *pdescription = (char *)(pstring_buffer +
(pocp_ts_header->ascts * SIZE_OF_DWORD) +
(peach_vu_event_entry->ascii_id_offset * SIZE_OF_DWORD));
memcpy(description, pdescription,
peach_vu_event_entry->ascii_id_length + 1);
return 0;
}
}
return -1;
}
int parse_ocp_telemetry_string_log(int event_fifo_num, int identifier, int debug_event_class,
enum ocp_telemetry_string_tables string_table, char *description)
{
if (pstring_buffer == NULL)
return -1;
if (event_fifo_num != 0) {
struct nvme_ocp_telemetry_string_header *pocp_ts_header =
(struct nvme_ocp_telemetry_string_header *)pstring_buffer;
if (*pocp_ts_header->fifo_ascii_string[event_fifo_num-1] != '\0')
memcpy(description, pocp_ts_header->fifo_ascii_string[event_fifo_num-1],
16);
else
description = "";
return 0;
}
if (string_table == STATISTICS_IDENTIFIER_STRING)
get_statistic_id_ascii_string(identifier, description);
else if (string_table == EVENT_STRING && debug_event_class < 0x80)
get_event_id_ascii_string(identifier, debug_event_class, description);
else if (string_table == VU_EVENT_STRING || debug_event_class >= 0x80)
get_vu_event_id_ascii_string(identifier, debug_event_class, description);
return 0;
}
#ifdef CONFIG_JSONC
void parse_time_stamp_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
struct json_object *pevent_fifos_object, FILE *fp)
{
struct nvme_ocp_time_stamp_dbg_evt_class_format *ptime_stamp_event =
(struct nvme_ocp_time_stamp_dbg_evt_class_format *) pevent_specific_data;
struct nvme_ocp_common_dbg_evt_class_vu_data *ptime_stamp_event_vu_data = NULL;
__u16 vu_event_id = 0;
__u8 *pdata = NULL;
char description_str[256] = "";
unsigned int vu_data_size = 0;
bool vu_data_present = false;
if ((pevent_descriptor->event_data_size * SIZE_OF_DWORD) >
sizeof(struct nvme_ocp_time_stamp_dbg_evt_class_format)) {
vu_data_present = true;
vu_data_size =
((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
(sizeof(struct nvme_ocp_time_stamp_dbg_evt_class_format) +
SIZE_OF_VU_EVENT_ID));
ptime_stamp_event_vu_data =
(struct nvme_ocp_common_dbg_evt_class_vu_data *)((__u64)ptime_stamp_event +
sizeof(struct nvme_ocp_time_stamp_dbg_evt_class_format));
vu_event_id = le16_to_cpu(ptime_stamp_event_vu_data->vu_event_identifier);
pdata = (__u8 *)&(ptime_stamp_event_vu_data->data);
parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING, description_str);
}
if (pevent_fifos_object != NULL) {
json_add_formatted_var_size_str(pevent_descriptor_obj, STR_CLASS_SPECIFIC_DATA,
ptime_stamp_event->time_stamp, DATA_SIZE_8);
if (vu_data_present) {
json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
vu_event_id);
json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
description_str);
json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
vu_data_size);
}
} else {
if (fp) {
print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
ptime_stamp_event->time_stamp, DATA_SIZE_8, fp);
if (vu_data_present) {
fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
}
} else {
print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
ptime_stamp_event->time_stamp, DATA_SIZE_8, fp);
if (vu_data_present) {
printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
}
}
}
}
void parse_pcie_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
struct json_object *pevent_fifos_object, FILE *fp)
{
struct nvme_ocp_pcie_dbg_evt_class_format *ppcie_event =
(struct nvme_ocp_pcie_dbg_evt_class_format *) pevent_specific_data;
struct nvme_ocp_common_dbg_evt_class_vu_data *ppcie_event_vu_data = NULL;
__u16 vu_event_id = 0;
__u8 *pdata = NULL;
char description_str[256] = "";
unsigned int vu_data_size = 0;
bool vu_data_present = false;
if ((pevent_descriptor->event_data_size * SIZE_OF_DWORD) >
sizeof(struct nvme_ocp_pcie_dbg_evt_class_format)) {
vu_data_present = true;
vu_data_size =
((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
(sizeof(struct nvme_ocp_pcie_dbg_evt_class_format) +
SIZE_OF_VU_EVENT_ID));
ppcie_event_vu_data =
(struct nvme_ocp_common_dbg_evt_class_vu_data *)((__u64)ppcie_event +
sizeof(struct nvme_ocp_pcie_dbg_evt_class_format));
vu_event_id = le16_to_cpu(ppcie_event_vu_data->vu_event_identifier);
pdata = (__u8 *)&(ppcie_event_vu_data->data);
parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING, description_str);
}
if (pevent_fifos_object != NULL) {
json_add_formatted_var_size_str(pevent_descriptor_obj, STR_CLASS_SPECIFIC_DATA,
ppcie_event->pCIeDebugEventData, DATA_SIZE_4);
if (vu_data_present) {
json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
vu_event_id);
json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
description_str);
json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
vu_data_size);
}
} else {
if (fp) {
print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
ppcie_event->pCIeDebugEventData, DATA_SIZE_4, fp);
if (vu_data_present) {
fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
}
} else {
print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
ppcie_event->pCIeDebugEventData, DATA_SIZE_4, fp);
if (vu_data_present) {
printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
}
}
}
}
void parse_nvme_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
struct json_object *pevent_fifos_object, FILE *fp)
{
struct nvme_ocp_nvme_dbg_evt_class_format *pnvme_event =
(struct nvme_ocp_nvme_dbg_evt_class_format *) pevent_specific_data;
struct nvme_ocp_common_dbg_evt_class_vu_data *pnvme_event_vu_data = NULL;
__u16 vu_event_id = 0;
__u8 *pdata = NULL;
char description_str[256] = "";
unsigned int vu_data_size = 0;
bool vu_data_present = false;
if ((pevent_descriptor->event_data_size * SIZE_OF_DWORD) >
sizeof(struct nvme_ocp_nvme_dbg_evt_class_format)) {
vu_data_present = true;
vu_data_size =
((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
(sizeof(struct nvme_ocp_nvme_dbg_evt_class_format) +
SIZE_OF_VU_EVENT_ID));
pnvme_event_vu_data =
(struct nvme_ocp_common_dbg_evt_class_vu_data *)((__u64)pnvme_event +
sizeof(struct nvme_ocp_nvme_dbg_evt_class_format));
vu_event_id = le16_to_cpu(pnvme_event_vu_data->vu_event_identifier);
pdata = (__u8 *)&(pnvme_event_vu_data->data);
parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING,
description_str);
}
if (pevent_fifos_object != NULL) {
json_add_formatted_var_size_str(pevent_descriptor_obj, STR_CLASS_SPECIFIC_DATA,
pnvme_event->nvmeDebugEventData, DATA_SIZE_8);
if (vu_data_present) {
json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
vu_event_id);
json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
description_str);
json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
vu_data_size);
}
} else {
if (fp) {
print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
pnvme_event->nvmeDebugEventData, DATA_SIZE_8, fp);
if (vu_data_present) {
fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
}
} else {
print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
pnvme_event->nvmeDebugEventData, DATA_SIZE_8, fp);
if (vu_data_present) {
printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
}
}
}
}
void parse_common_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
struct json_object *pevent_fifos_object, FILE *fp)
{
if (pevent_specific_data) {
struct nvme_ocp_common_dbg_evt_class_vu_data *pcommon_debug_event_vu_data =
(struct nvme_ocp_common_dbg_evt_class_vu_data *) pevent_specific_data;
__u16 vu_event_id = le16_to_cpu(pcommon_debug_event_vu_data->vu_event_identifier);
char description_str[256] = "";
__u8 *pdata = (__u8 *)&(pcommon_debug_event_vu_data->data);
unsigned int vu_data_size = ((pevent_descriptor->event_data_size *
SIZE_OF_DWORD) - SIZE_OF_VU_EVENT_ID);
parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING, description_str);
if (pevent_fifos_object != NULL) {
json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
vu_event_id);
json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
description_str);
json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
vu_data_size);
} else {
if (fp) {
fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
} else {
printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
}
}
}
}
void parse_media_wear_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
struct json_object *pevent_fifos_object, FILE *fp)
{
struct nvme_ocp_media_wear_dbg_evt_class_format *pmedia_wear_event =
(struct nvme_ocp_media_wear_dbg_evt_class_format *) pevent_specific_data;
struct nvme_ocp_common_dbg_evt_class_vu_data *pmedia_wear_event_vu_data = NULL;
__u16 vu_event_id = 0;
__u8 *pdata = NULL;
char description_str[256] = "";
unsigned int vu_data_size = 0;
bool vu_data_present = false;
if ((pevent_descriptor->event_data_size * SIZE_OF_DWORD) >
sizeof(struct nvme_ocp_media_wear_dbg_evt_class_format)) {
vu_data_present = true;
vu_data_size =
((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
(sizeof(struct nvme_ocp_media_wear_dbg_evt_class_format) +
SIZE_OF_VU_EVENT_ID));
pmedia_wear_event_vu_data =
(struct nvme_ocp_common_dbg_evt_class_vu_data *)((__u64)pmedia_wear_event +
sizeof(struct nvme_ocp_media_wear_dbg_evt_class_format));
vu_event_id = le16_to_cpu(pmedia_wear_event_vu_data->vu_event_identifier);
pdata = (__u8 *)&(pmedia_wear_event_vu_data->data);
parse_ocp_telemetry_string_log(0, vu_event_id,
pevent_descriptor->debug_event_class_type,
VU_EVENT_STRING,
description_str);
}
if (pevent_fifos_object != NULL) {
json_add_formatted_var_size_str(pevent_descriptor_obj, STR_CLASS_SPECIFIC_DATA,
pmedia_wear_event->currentMediaWear, DATA_SIZE_12);
if (vu_data_present) {
json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
vu_event_id);
json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
description_str);
json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
vu_data_size);
}
} else {
if (fp) {
print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
pmedia_wear_event->currentMediaWear, DATA_SIZE_12, fp);
if (vu_data_present) {
fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
}
} else {
print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
pmedia_wear_event->currentMediaWear, DATA_SIZE_12, NULL);
if (vu_data_present) {
printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
print_formatted_var_size_str(STR_VU_DATA, pdata, vu_data_size, fp);
}
}
}
}
int parse_event_fifo(unsigned int fifo_num, unsigned char *pfifo_start,
struct json_object *pevent_fifos_object, unsigned char *pstring_buffer,
struct nvme_ocp_telemetry_offsets *poffsets, __u64 fifo_size, FILE *fp)
{
if (NULL == pfifo_start || NULL == poffsets) {
nvme_show_error("Input buffer was NULL");
return -1;
}
int status = 0;
unsigned int event_fifo_number = fifo_num + 1;
char *description = (char *)malloc((40 + 1) * sizeof(char));
memset(description, 0, sizeof(40));
status =
parse_ocp_telemetry_string_log(event_fifo_number, 0, 0, EVENT_STRING, description);
if (status != 0) {
nvme_show_error("Failed to get C9 String. status: %d\n", status);
return -1;
}
char event_fifo_name[100] = {0};
snprintf(event_fifo_name, sizeof(event_fifo_name), "%s%d%s%s", "EVENT FIFO ",
event_fifo_number, " - ", description);
struct json_object *pevent_fifo_array = NULL;