forked from linux-nvme/nvme-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocp-nvme.c
More file actions
3175 lines (2726 loc) · 86 KB
/
ocp-nvme.c
File metadata and controls
3175 lines (2726 loc) · 86 KB
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) 2023 Meta Platforms, Inc.
*
* Authors: Arthur Shau <[email protected]>,
* Wei Zhang <[email protected]>,
* Venkat Ramesh <[email protected]>
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <errno.h>
#include <limits.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include "common.h"
#include "nvme.h"
#include "libnvme.h"
#include "plugin.h"
#include "linux/types.h"
#include "util/types.h"
#include "logging.h"
#include "nvme-print.h"
#include "nvme-wrap.h"
#include "ocp-smart-extended-log.h"
#include "ocp-clear-features.h"
#include "ocp-fw-activation-history.h"
#include "ocp-telemetry-decode.h"
#include "ocp-hardware-component-log.h"
#include "ocp-print.h"
#include "ocp-types.h"
#define CREATE_CMD
#include "ocp-nvme.h"
#include "ocp-utils.h"
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Latency Monitor Log
#define C3_LATENCY_MON_LOG_BUF_LEN 0x200
static __u8 lat_mon_guid[GUID_LEN] = {
0x92, 0x7a, 0xc0, 0x8c,
0xd0, 0x84, 0x6c, 0x9c,
0x70, 0x43, 0xe6, 0xd4,
0x58, 0x5e, 0xd4, 0x85
};
#define RESERVED 0
struct __packed feature_latency_monitor {
__le16 active_bucket_timer_threshold;
__u8 active_threshold_a;
__u8 active_threshold_b;
__u8 active_threshold_c;
__u8 active_threshold_d;
__le16 active_latency_config;
__u8 active_latency_minimum_window;
__le16 debug_log_trigger_enable;
__u8 discard_debug_log;
__u8 latency_monitor_feature_enable;
__u8 reserved[4083];
};
struct erri_entry {
union {
__u8 flags;
struct {
__u8 enable:1;
__u8 single:1;
__u8 rsvd2:6;
};
};
__u8 rsvd1;
__le16 type;
union {
__u8 specific[28];
struct {
__le16 nrtdp;
__u8 rsvd4[26];
};
};
};
#define ERRI_ENTRIES_MAX 127
enum erri_type {
ERRI_TYPE_CPU_CTRL_HANG = 1,
ERRI_TYPE_NAND_HANG,
ERRI_TYPE_PLP_DEFECT,
ERRI_TYPE_LOGICAL_FIRMWARE_ERROR,
ERRI_TYPE_DRAM_CORRUPT_CRIT,
ERRI_TYPE_DRAM_CORRUPT_NON_CRIT,
ERRI_TYPE_NAND_CORRUPT,
ERRI_TYPE_SRAM_CORRUPT,
ERRI_TYPE_HW_MALFUNCTION,
ERRI_TYPE_NO_MORE_NAND_SPARES,
ERRI_TYPE_INCOMPLETE_SHUTDOWN,
ERRI_TYPE_METADATA_CORRUPTION,
ERRI_TYPE_CRITICAL_GC,
ERRI_TYPE_LATENCY_SPIKE,
ERRI_TYPE_IO_CMD_FAILURE,
ERRI_TYPE_IO_CMD_TIMEOUT,
ERRI_TYPE_ADMIN_CMD_FAILURE,
ERRI_TYPE_ADMIN_CMD_TIMEOUT,
ERRI_TYPE_THERMAL_THROTTLE_ENGAGED,
ERRI_TYPE_THERMAL_THROTTLE_DISENGAGED,
ERRI_TYPE_CRITICAL_TEMPERATURE_EVENT,
ERRI_TYPE_DIE_OFFLINE,
};
const char *erri_type_to_string(__le16 type)
{
switch (type) {
case ERRI_TYPE_CPU_CTRL_HANG:
return "CPU/controller hang";
case ERRI_TYPE_NAND_HANG:
return "NAND hang";
case ERRI_TYPE_PLP_DEFECT:
return "PLP defect";
case ERRI_TYPE_LOGICAL_FIRMWARE_ERROR:
return "logical firmware error";
case ERRI_TYPE_DRAM_CORRUPT_CRIT:
return "DRAM corruption critical path";
case ERRI_TYPE_DRAM_CORRUPT_NON_CRIT:
return "DRAM corruption non-critical path";
case ERRI_TYPE_NAND_CORRUPT:
return "NAND corruption";
case ERRI_TYPE_SRAM_CORRUPT:
return "SRAM corruption";
case ERRI_TYPE_HW_MALFUNCTION:
return "HW malfunction";
case ERRI_TYPE_NO_MORE_NAND_SPARES:
return "no more NAND spares available";
case ERRI_TYPE_INCOMPLETE_SHUTDOWN:
return "incomplete shutdown";
case ERRI_TYPE_METADATA_CORRUPTION:
return "Metadata Corruption";
case ERRI_TYPE_CRITICAL_GC:
return "Critical Garbage Collection";
case ERRI_TYPE_LATENCY_SPIKE:
return "Latency Spike";
case ERRI_TYPE_IO_CMD_FAILURE:
return "I/O command failure";
case ERRI_TYPE_IO_CMD_TIMEOUT:
return "I/O command timeout";
case ERRI_TYPE_ADMIN_CMD_FAILURE:
return "Admin command failure";
case ERRI_TYPE_ADMIN_CMD_TIMEOUT:
return "Admin command timeout";
case ERRI_TYPE_THERMAL_THROTTLE_ENGAGED:
return "Thermal Throttle Engaged";
case ERRI_TYPE_THERMAL_THROTTLE_DISENGAGED:
return "Thermal Throttle Disengaged";
case ERRI_TYPE_CRITICAL_TEMPERATURE_EVENT:
return "Critical Temperature Event";
case ERRI_TYPE_DIE_OFFLINE:
return "Die Offline";
default:
break;
}
return "unknown";
}
struct erri_get_cq_entry {
__u32 nume:7;
__u32 rsvd7:25;
};
struct erri_config {
char *file;
__u8 number;
__u16 type;
__u16 nrtdp;
};
struct ieee1667_get_cq_entry {
__u32 enabled:3;
__u32 rsvd3:29;
};
static const char *sel = "[0-3]: current/default/saved/supported";
static const char *no_uuid = "Skip UUID index search (UUID index not required for OCP 1.0)";
static const char *all_ns = "Apply to all namespaces";
const char *data = "Error injection data structure entries";
const char *number = "Number of valid error injection data entries";
static const char *type = "Error injection type";
static const char *nrtdp = "Number of reads to trigger device panic";
static const char *save = "Specifies that the controller shall save the attribute";
static const char *enable_ieee1667_silo = "enable IEEE1667 silo";
static int get_c3_log_page(struct nvme_dev *dev, char *format)
{
struct ssd_latency_monitor_log *log_data;
nvme_print_flags_t fmt;
int ret;
__u8 *data;
int i;
ret = validate_output_format(format, &fmt);
if (ret < 0) {
fprintf(stderr, "ERROR : OCP : invalid output format\n");
return ret;
}
data = malloc(sizeof(__u8) * C3_LATENCY_MON_LOG_BUF_LEN);
if (!data) {
fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno));
return -1;
}
memset(data, 0, sizeof(__u8) * C3_LATENCY_MON_LOG_BUF_LEN);
ret = ocp_get_log_simple(dev, OCP_LID_LMLOG, C3_LATENCY_MON_LOG_BUF_LEN, data);
if (strcmp(format, "json"))
fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret, false), ret);
if (!ret) {
log_data = (struct ssd_latency_monitor_log *)data;
/*
* check log page guid
* Verify GUID matches
*/
for (i = 0; i < 16; i++) {
if (lat_mon_guid[i] != log_data->log_page_guid[i]) {
int j;
fprintf(stderr, "ERROR : OCP : Unknown GUID in C3 Log Page data\n");
fprintf(stderr, "ERROR : OCP : Expected GUID: 0x");
for (j = 0; j < 16; j++)
fprintf(stderr, "%02x", lat_mon_guid[j]);
fprintf(stderr, "\nERROR : OCP : Actual GUID: 0x");
for (j = 0; j < 16; j++)
fprintf(stderr, "%02x", log_data->log_page_guid[j]);
fprintf(stderr, "\n");
ret = -1;
goto out;
}
}
ocp_c3_log(dev, log_data, fmt);
} else {
fprintf(stderr, "ERROR : OCP : Unable to read C3 data from buffer\n");
}
out:
free(data);
return ret;
}
static int ocp_latency_monitor_log(int argc, char **argv,
struct command *command,
struct plugin *plugin)
{
const char *desc = "Retrieve latency monitor log data.";
struct nvme_dev *dev;
int ret = 0;
struct config {
char *output_format;
};
struct config cfg = {
.output_format = "normal",
};
OPT_ARGS(opts) = {
OPT_FMT("output-format", 'o', &cfg.output_format,
"output Format: normal|json"),
OPT_END()
};
ret = parse_and_open(&dev, argc, argv, desc, opts);
if (ret)
return ret;
ret = get_c3_log_page(dev, cfg.output_format);
if (ret)
fprintf(stderr,
"ERROR : OCP : Failure reading the C3 Log Page, ret = %d\n",
ret);
dev_close(dev);
return ret;
}
int ocp_set_latency_monitor_feature(int argc, char **argv, struct command *cmd, struct plugin *plugin)
{
int err = -1;
struct nvme_dev *dev;
__u32 result;
struct feature_latency_monitor buf = { 0 };
__u32 nsid = NVME_NSID_ALL;
struct stat nvme_stat;
struct nvme_id_ctrl ctrl;
const char *desc = "Set Latency Monitor feature.";
const char *active_bucket_timer_threshold = "This is the value that loads the Active Bucket Timer Threshold.";
const char *active_threshold_a = "This is the value that loads into the Active Threshold A.";
const char *active_threshold_b = "This is the value that loads into the Active Threshold B.";
const char *active_threshold_c = "This is the value that loads into the Active Threshold C.";
const char *active_threshold_d = "This is the value that loads into the Active Threshold D.";
const char *active_latency_config = "This is the value that loads into the Active Latency Configuration.";
const char *active_latency_minimum_window = "This is the value that loads into the Active Latency Minimum Window.";
const char *debug_log_trigger_enable = "This is the value that loads into the Debug Log Trigger Enable.";
const char *discard_debug_log = "Discard Debug Log.";
const char *latency_monitor_feature_enable = "Latency Monitor Feature Enable.";
struct config {
__u16 active_bucket_timer_threshold;
__u8 active_threshold_a;
__u8 active_threshold_b;
__u8 active_threshold_c;
__u8 active_threshold_d;
__u16 active_latency_config;
__u8 active_latency_minimum_window;
__u16 debug_log_trigger_enable;
__u8 discard_debug_log;
__u8 latency_monitor_feature_enable;
};
struct config cfg = {
.active_bucket_timer_threshold = 0x7E0,
.active_threshold_a = 0x5,
.active_threshold_b = 0x13,
.active_threshold_c = 0x1E,
.active_threshold_d = 0x2E,
.active_latency_config = 0xFFF,
.active_latency_minimum_window = 0xA,
.debug_log_trigger_enable = 0,
.discard_debug_log = 0,
.latency_monitor_feature_enable = 0x1,
};
OPT_ARGS(opts) = {
OPT_UINT("active_bucket_timer_threshold", 't', &cfg.active_bucket_timer_threshold, active_bucket_timer_threshold),
OPT_UINT("active_threshold_a", 'a', &cfg.active_threshold_a, active_threshold_a),
OPT_UINT("active_threshold_b", 'b', &cfg.active_threshold_b, active_threshold_b),
OPT_UINT("active_threshold_c", 'c', &cfg.active_threshold_c, active_threshold_c),
OPT_UINT("active_threshold_d", 'd', &cfg.active_threshold_d, active_threshold_d),
OPT_UINT("active_latency_config", 'f', &cfg.active_latency_config, active_latency_config),
OPT_UINT("active_latency_minimum_window", 'w', &cfg.active_latency_minimum_window, active_latency_minimum_window),
OPT_UINT("debug_log_trigger_enable", 'r', &cfg.debug_log_trigger_enable, debug_log_trigger_enable),
OPT_UINT("discard_debug_log", 'l', &cfg.discard_debug_log, discard_debug_log),
OPT_UINT("latency_monitor_feature_enable", 'e', &cfg.latency_monitor_feature_enable, latency_monitor_feature_enable),
OPT_END()
};
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
err = fstat(dev_fd(dev), &nvme_stat);
if (err < 0)
return err;
if (S_ISBLK(nvme_stat.st_mode)) {
err = nvme_get_nsid(dev_fd(dev), &nsid);
if (err < 0) {
perror("invalid-namespace-id");
return err;
}
}
err = nvme_identify_ctrl(dev_fd(dev), &ctrl);
if (err)
return err;
buf.active_bucket_timer_threshold = cpu_to_le16(cfg.active_bucket_timer_threshold);
buf.active_threshold_a = cfg.active_threshold_a;
buf.active_threshold_b = cfg.active_threshold_b;
buf.active_threshold_c = cfg.active_threshold_c;
buf.active_threshold_d = cfg.active_threshold_d;
buf.active_latency_config = cpu_to_le16(cfg.active_latency_config);
buf.active_latency_minimum_window = cfg.active_latency_minimum_window;
buf.debug_log_trigger_enable = cpu_to_le16(cfg.debug_log_trigger_enable);
buf.discard_debug_log = cfg.discard_debug_log;
buf.latency_monitor_feature_enable = cfg.latency_monitor_feature_enable;
struct nvme_set_features_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.fid = OCP_FID_LM,
.nsid = 0,
.cdw12 = 0,
.save = 1,
.data_len = sizeof(struct feature_latency_monitor),
.data = (void *)&buf,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
err = nvme_set_features(&args);
if (err < 0) {
perror("set-feature");
} else if (!err) {
printf("NVME_FEAT_OCP_LATENCY_MONITOR: 0x%02x\n", OCP_FID_LM);
printf("active bucket timer threshold: 0x%x\n",
le16_to_cpu(buf.active_bucket_timer_threshold));
printf("active threshold a: 0x%x\n", buf.active_threshold_a);
printf("active threshold b: 0x%x\n", buf.active_threshold_b);
printf("active threshold c: 0x%x\n", buf.active_threshold_c);
printf("active threshold d: 0x%x\n", buf.active_threshold_d);
printf("active latency config: 0x%x\n", le16_to_cpu(buf.active_latency_config));
printf("active latency minimum window: 0x%x\n", buf.active_latency_minimum_window);
printf("debug log trigger enable: 0x%x\n",
le16_to_cpu(buf.debug_log_trigger_enable));
printf("discard debug log: 0x%x\n", buf.discard_debug_log);
printf("latency monitor feature enable: 0x%x\n", buf.latency_monitor_feature_enable);
} else if (err > 0) {
fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err, false), err);
}
return err;
}
static int ocp_get_latency_monitor_feature(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Define Issue Get Feature command (FID: 0xC5) Latency Monitor";
const char *sel = "[0-3]: current/default/saved/supported/";
const char *nsid = "Byte[04-07]: Namespace Identifier Valid/Invalid/Inactive";
_cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
__u32 result;
int err;
bool uuid;
__u8 uuid_index = 0;
struct config {
__u8 sel;
__u32 nsid;
};
struct config cfg = {
.sel = 0,
.nsid = 0,
};
OPT_ARGS(opts) = {
OPT_BYTE("sel", 's', &cfg.sel, sel),
OPT_UINT("namespace-id", 'n', &cfg.nsid, nsid),
OPT_FLAG("no-uuid", 'u', NULL, no_uuid),
OPT_END()
};
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
uuid = !argconfig_parse_seen(opts, "no-uuid");
if (uuid) {
/* OCP 2.0 requires UUID index support */
err = ocp_get_uuid_index(dev, &uuid_index);
if (err || !uuid_index) {
nvme_show_error("ERROR: No OCP UUID index found");
return err;
}
}
struct nvme_get_features_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.fid = OCP_FID_LM,
.nsid = cfg.nsid,
.sel = cfg.sel,
.cdw11 = 0,
.uuidx = uuid_index,
.data_len = 0,
.data = NULL,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
err = nvme_get_features(&args);
if (!err) {
printf("get-feature:0xC5 %s value: %#08x\n",
nvme_select_to_string(cfg.sel), result);
if (cfg.sel == NVME_GET_FEATURES_SEL_SUPPORTED)
nvme_show_select_result(0xC5, result);
} else {
nvme_show_error("Could not get feature: 0xC5");
}
return err;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// EOL/PLP Failure Mode
static const char *eol_plp_failure_mode_to_string(__u8 mode)
{
switch (mode) {
case 1:
return "Read only mode (ROM)";
case 2:
return "Write through mode (WTM)";
case 3:
return "Normal mode";
default:
break;
}
return "Reserved";
}
static int eol_plp_failure_mode_get(struct nvme_dev *dev, const __u32 nsid, const __u8 fid,
__u8 sel, bool uuid)
{
__u32 result;
int err;
struct nvme_get_features_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.fid = fid,
.nsid = nsid,
.sel = sel,
.cdw11 = 0,
.uuidx = 0,
.data_len = 0,
.data = NULL,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
if (uuid) {
/* OCP 2.0 requires UUID index support */
err = ocp_get_uuid_index(dev, &args.uuidx);
if (err || !args.uuidx) {
nvme_show_error("ERROR: No OCP UUID index found");
return err;
}
}
err = nvme_get_features(&args);
if (!err) {
nvme_show_result("End of Life Behavior (feature: %#0*x): %#0*x (%s: %s)",
fid ? 4 : 2, fid, result ? 10 : 8, result,
nvme_select_to_string(sel),
eol_plp_failure_mode_to_string(result));
if (sel == NVME_GET_FEATURES_SEL_SUPPORTED)
nvme_show_select_result(fid, result);
} else {
nvme_show_error("Could not get feature: %#0*x.", fid ? 4 : 2, fid);
}
return err;
}
static int eol_plp_failure_mode_set(struct nvme_dev *dev, const __u32 nsid,
const __u8 fid, __u8 mode, bool save,
bool uuid)
{
__u32 result;
int err;
__u8 uuid_index = 0;
if (uuid) {
/* OCP 2.0 requires UUID index support */
err = ocp_get_uuid_index(dev, &uuid_index);
if (err || !uuid_index) {
nvme_show_error("ERROR: No OCP UUID index found");
return err;
}
}
struct nvme_set_features_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
.fid = fid,
.nsid = nsid,
.cdw11 = mode << 30,
.cdw12 = 0,
.save = save,
.uuidx = uuid_index,
.cdw15 = 0,
.data_len = 0,
.data = NULL,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.result = &result,
};
err = nvme_set_features(&args);
if (err > 0) {
nvme_show_status(err);
} else if (err < 0) {
nvme_show_perror("Define EOL/PLP failure mode");
fprintf(stderr, "Command failed while parsing.\n");
} else {
nvme_show_result("Successfully set mode (feature: %#0*x): %#0*x (%s: %s).",
fid ? 4 : 2, fid, mode ? 10 : 8, mode,
save ? "Save" : "Not save",
eol_plp_failure_mode_to_string(mode));
}
return err;
}
static int eol_plp_failure_mode(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
const char *desc = "Define EOL or PLP circuitry failure mode.\n"
"No argument prints current mode.";
const char *mode = "[0-3]: default/rom/wtm/normal";
const __u32 nsid = 0;
const __u8 fid = OCP_FID_ROWTM;
struct nvme_dev *dev;
int err;
struct config {
__u8 mode;
bool save;
__u8 sel;
};
struct config cfg = {
.mode = 0,
.save = false,
.sel = 0,
};
NVME_ARGS(opts,
OPT_BYTE("mode", 'm', &cfg.mode, mode),
OPT_FLAG("save", 's', &cfg.save, save),
OPT_BYTE("sel", 'S', &cfg.sel, sel),
OPT_FLAG("no-uuid", 'n', NULL, no_uuid));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
return err;
if (argconfig_parse_seen(opts, "mode"))
err = eol_plp_failure_mode_set(dev, nsid, fid, cfg.mode,
cfg.save,
!argconfig_parse_seen(opts, "no-uuid"));
else
err = eol_plp_failure_mode_get(dev, nsid, fid, cfg.sel,
!argconfig_parse_seen(opts, "no-uuid"));
dev_close(dev);
return err;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Telemetry Log
//global buffers
static __le64 total_log_page_sz;
static __u8 *header_data;
static struct telemetry_str_log_format *log_data;
__u8 *ptelemetry_buffer;
__u8 *pstring_buffer;
__u8 *pC9_string_buffer;
static void get_serial_number(struct nvme_id_ctrl *ctrl, char *sn)
{
int i;
/* Remove trailing spaces from the name */
for (i = 0; i < sizeof(ctrl->sn); i++) {
if (ctrl->sn[i] == ' ')
break;
sn[i] = ctrl->sn[i];
}
}
static void print_telemetry_header(struct telemetry_initiated_log *logheader, int tele_type)
{
if (logheader) {
unsigned int i = 0, j = 0;
__u8 dataGenNum;
if (tele_type == TELEMETRY_TYPE_HOST) {
printf("============ Telemetry Host Header ============\n");
dataGenNum = logheader->DataHostGenerationNumber;
} else {
printf("========= Telemetry Controller Header =========\n");
dataGenNum = logheader->DataCtlrGenerationNumber;
}
printf("Log Identifier : 0x%02X\n", logheader->LogIdentifier);
printf("IEEE : 0x%02X%02X%02X\n",
logheader->IEEE[0], logheader->IEEE[1], logheader->IEEE[2]);
printf("Data Area 1 Last Block : 0x%04X\n",
le16_to_cpu(logheader->DataArea1LastBlock));
printf("Data Area 2 Last Block : 0x%04X\n",
le16_to_cpu(logheader->DataArea2LastBlock));
printf("Data Area 3 Last Block : 0x%04X\n",
le16_to_cpu(logheader->DataArea3LastBlock));
printf("Data Available : 0x%02X\n",
logheader->CtlrDataAvailable);
printf("Data Generation Number : 0x%02X\n",
dataGenNum);
printf("Reason Identifier :\n");
for (i = 0; i < 8; i++) {
for (j = 0; j < 16; j++)
printf("%02X ", logheader->ReasonIdentifier[127 - ((i * 16) + j)]);
printf("\n");
}
printf("===============================================\n\n");
}
}
static int get_telemetry_data(struct nvme_dev *dev, __u32 ns, __u8 tele_type,
__u32 data_len, void *data, __u8 nLSP, __u8 nRAE,
__u64 offset)
{
struct nvme_passthru_cmd cmd = {
.opcode = nvme_admin_get_log_page,
.nsid = ns,
.addr = (__u64)(uintptr_t) data,
.data_len = data_len,
};
__u32 numd = (data_len >> 2) - 1;
__u16 numdu = numd >> 16;
__u16 numdl = numd & 0xffff;
cmd.cdw10 = tele_type | (nLSP & 0x0F) << 8 | (nRAE & 0x01) << 15 | (numdl & 0xFFFF) << 16;
cmd.cdw11 = numdu;
cmd.cdw12 = (__u32)(0x00000000FFFFFFFF & offset);
cmd.cdw13 = (__u32)((0xFFFFFFFF00000000 & offset) >> 8);
cmd.cdw14 = 0;
return nvme_submit_admin_passthru(dev_fd(dev), &cmd, NULL);
}
static void print_telemetry_data_area_1(struct telemetry_data_area_1 *da1,
int tele_type)
{
if (da1) {
int i = 0;
if (tele_type == TELEMETRY_TYPE_HOST)
printf("============ Telemetry Host Data area 1 ============\n");
else
printf("========= Telemetry Controller Data area 1 =========\n");
printf("Major Version : 0x%x\n", le16_to_cpu(da1->major_version));
printf("Minor Version : 0x%x\n", le16_to_cpu(da1->minor_version));
printf("Timestamp : %"PRIu64"\n", le64_to_cpu(da1->timestamp));
printf("Log Page GUID : 0x");
for (int j = 15; j >= 0; j--)
printf("%02x", da1->log_page_guid[j]);
printf("\n");
printf("Number Telemetry Profiles Supported : 0x%x\n",
da1->no_of_tps_supp);
printf("Telemetry Profile Selected (TPS) : 0x%x\n",
da1->tps);
printf("Telemetry String Log Size (SLS) : 0x%"PRIx64"\n",
le64_to_cpu(da1->sls));
printf("Firmware Revision : ");
for (i = 0; i < 8; i++)
printf("%c", (char)da1->fw_revision[i]);
printf("\n");
printf("Data Area 1 Statistic Start : 0x%"PRIx64"\n",
le64_to_cpu(da1->da1_stat_start));
printf("Data Area 1 Statistic Size : 0x%"PRIx64"\n",
le64_to_cpu(da1->da1_stat_size));
printf("Data Area 2 Statistic Start : 0x%"PRIx64"\n",
le64_to_cpu(da1->da2_stat_start));
printf("Data Area 2 Statistic Size : 0x%"PRIx64"\n",
le64_to_cpu(da1->da2_stat_size));
for (i = 0; i < 16; i++) {
printf("Event FIFO %d Data Area : 0x%x\n",
i, da1->event_fifo_da[i]);
printf("Event FIFO %d Start : 0x%"PRIx64"\n",
i, le64_to_cpu(da1->event_fifos[i].start));
printf("Event FIFO %d Size : 0x%"PRIx64"\n",
i, le64_to_cpu(da1->event_fifos[i].size));
}
printf("SMART / Health Information :\n");
printf("0x");
for (i = 0; i < 512; i++)
printf("%02x", da1->smart_health_info[i]);
printf("\n");
printf("SMART / Health Information Extended :\n");
printf("0x");
for (i = 0; i < 512; i++)
printf("%02x", da1->smart_health_info_extended[i]);
printf("\n");
printf("===============================================\n\n");
}
}
static void print_telemetry_da_stat(struct telemetry_stats_desc *da_stat, int tele_type,
__u16 buf_size, __u8 data_area)
{
if (da_stat) {
unsigned int i = 0;
struct telemetry_stats_desc *next_da_stat = da_stat;
if (tele_type == TELEMETRY_TYPE_HOST)
printf("============ Telemetry Host Data Area %d Statistics ============\n",
data_area);
else
printf("========= Telemetry Controller Data Area %d Statistics =========\n",
data_area);
while ((i + 8) < buf_size) {
print_stats_desc(next_da_stat);
i += 8 + ((next_da_stat->size) * 4);
next_da_stat = (struct telemetry_stats_desc *)((void *)da_stat + i);
if ((next_da_stat->id == 0) && (next_da_stat->size == 0))
break;
}
printf("===============================================\n\n");
}
}
static void print_telemetry_da_fifo(struct telemetry_event_desc *da_fifo,
__u64 buf_size,
int tele_type,
int da,
int index)
{
if (da_fifo) {
__u64 i = 0;
struct telemetry_event_desc *next_da_fifo = da_fifo;
if (tele_type == TELEMETRY_TYPE_HOST)
printf("========= Telemetry Host Data area %d Event FIFO %d =========\n",
da, index);
else
printf("====== Telemetry Controller Data area %d Event FIFO %d ======\n",
da, index);
while ((i + 4) < buf_size) {
/* break if last entry */
if (next_da_fifo->class == 0)
break;
/* Print Event Data */
print_telemetry_fifo_event(next_da_fifo->class, /* Event class type */
next_da_fifo->id, /* Event ID */
next_da_fifo->size, /* Event data size */
(__u8 *)&next_da_fifo->data); /* Event data */
i += (4 + (next_da_fifo->size * 4));
next_da_fifo = (struct telemetry_event_desc *)((void *)da_fifo + i);
}
printf("===============================================\n\n");
}
}
static int extract_dump_get_log(struct nvme_dev *dev, char *featurename, char *filename, char *sn,
int dumpsize, int transfersize, __u32 nsid, __u8 log_id,
__u8 lsp, __u64 offset, bool rae)
{
int i = 0, err = 0;
char *data = calloc(transfersize, sizeof(char));
char filepath[FILE_NAME_SIZE] = {0,};
int output = 0;
int total_loop_cnt = dumpsize / transfersize;
int last_xfer_size = dumpsize % transfersize;
if (last_xfer_size)
total_loop_cnt++;
else
last_xfer_size = transfersize;
if (filename == 0)
snprintf(filepath, FILE_NAME_SIZE, "%s_%s.bin", featurename, sn);
else
snprintf(filepath, FILE_NAME_SIZE, "%s%s_%s.bin", filename, featurename, sn);
for (i = 0; i < total_loop_cnt; i++) {
memset(data, 0, transfersize);
struct nvme_get_log_args args = {
.lpo = offset,
.result = NULL,
.log = (void *)data,
.args_size = sizeof(args),
.fd = dev_fd(dev),
.lid = log_id,
.len = transfersize,
.nsid = nsid,
.lsp = lsp,
.uuidx = 0,
.rae = rae,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.csi = NVME_CSI_NVM,
.ot = false,
};
err = nvme_get_log(&args);
if (err) {
if (i > 0)
goto close_output;
else
goto end;
}
if (i != total_loop_cnt - 1) {
if (!i) {
output = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (output < 0) {
err = -13;
goto end;
}
}
if (write(output, data, transfersize) < 0) {
err = -10;
goto close_output;
}
} else {
if (write(output, data, last_xfer_size) < 0) {
err = -10;
goto close_output;
}
}
offset += transfersize;
printf("%d%%\r", (i + 1) * 100 / total_loop_cnt);
}
printf("100%%\nThe log file was saved at \"%s\"\n", filepath);
close_output:
close(output);
end:
free(data);
return err;
}
static int get_telemetry_dump(struct nvme_dev *dev, char *filename, char *sn,
enum TELEMETRY_TYPE tele_type, int data_area, bool header_print)
{
__u32 err = 0, nsid = 0;
__u64 da1_sz = 512, m_512_sz = 0, da1_off = 0, m_512_off = 0, diff = 0, temp_sz = 0,
temp_ofst = 0;
__u8 lsp = 0, rae = 0, flag = 0;
__u8 data[TELEMETRY_HEADER_SIZE] = { 0 };
unsigned int i = 0;
char data1[TELEMETRY_DATA_SIZE] = { 0 };
char *featurename = 0;
struct telemetry_initiated_log *logheader = (struct telemetry_initiated_log *)data;
struct telemetry_data_area_1 *da1 = (struct telemetry_data_area_1 *)data1;
__u64 offset = 0, size = 0;
char dumpname[FILE_NAME_SIZE] = { 0 };
if (tele_type == TELEMETRY_TYPE_HOST_0) {
featurename = "Host(0)";
lsp = 0;
rae = 0;
tele_type = TELEMETRY_TYPE_HOST;
} else if (tele_type == TELEMETRY_TYPE_HOST_1) {
featurename = "Host(1)";
lsp = 1;
rae = 0;
tele_type = TELEMETRY_TYPE_HOST;
} else {
featurename = "Controller";
lsp = 0;
rae = 1;
}
/* Get the telemetry header */
err = get_telemetry_data(dev, nsid, tele_type, TELEMETRY_HEADER_SIZE, (void *)data, lsp,
rae, 0);
if (err) {
printf("get_telemetry_header failed, err: %d.\n", err);
return err;
}
if (header_print)
print_telemetry_header(logheader, tele_type);
/* Get the telemetry data */
err = get_telemetry_data(dev, nsid, tele_type, TELEMETRY_DATA_SIZE, (void *)data1, lsp,
rae, 512);
if (err) {
printf("get_telemetry_data failed for type: 0x%x, err: %d.\n", tele_type, err);
return err;
}
print_telemetry_data_area_1(da1, tele_type);
/* Print the Data Area 1 Stats */
if (da1->da1_stat_size != 0) {