forked from linux-nvme/nvme-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvme-print.c
3194 lines (2835 loc) · 115 KB
/
nvme-print.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
#include <endian.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "nvme-print.h"
#include "json.h"
#include "nvme-models.h"
#include "suffix.h"
static const char *nvme_ana_state_to_string(enum nvme_ana_state state)
{
switch (state) {
case NVME_ANA_OPTIMIZED:
return "optimized";
case NVME_ANA_NONOPTIMIZED:
return "non-optimized";
case NVME_ANA_INACCESSIBLE:
return "inaccessible";
case NVME_ANA_PERSISTENT_LOSS:
return "persistent-loss";
case NVME_ANA_CHANGE:
return "change";
}
return "invalid state";
}
static long double int128_to_double(__u8 *data)
{
int i;
long double result = 0;
for (i = 0; i < 16; i++) {
result *= 256;
result += data[15 - i];
}
return result;
}
void d(unsigned char *buf, int len, int width, int group)
{
int i, offset = 0, line_done = 0;
char ascii[width + 1];
printf(" ");
for (i = 0; i <= 15; i++)
printf("%3x", i);
for (i = 0; i < len; i++) {
line_done = 0;
if (i % width == 0)
printf( "\n%04x:", offset);
if (i % group == 0)
printf( " %02x", buf[i]);
else
printf( "%02x", buf[i]);
ascii[i % width] = (buf[i] >= '!' && buf[i] <= '~') ? buf[i] : '.';
if (((i + 1) % width) == 0) {
ascii[i % width + 1] = '\0';
printf( " \"%.*s\"", width, ascii);
offset += width;
line_done = 1;
}
}
if (!line_done) {
unsigned b = width - (i % width);
ascii[i % width + 1] = '\0';
printf( " %*s \"%.*s\"",
2 * b + b / group + (b % group ? 1 : 0), "",
width, ascii);
}
printf( "\n");
}
void d_raw(unsigned char *buf, unsigned len)
{
unsigned i;
for (i = 0; i < len; i++)
putchar(*(buf+i));
}
static void format(char *formatter, size_t fmt_sz, char *tofmt, size_t tofmtsz)
{
fmt_sz = snprintf(formatter,fmt_sz, "%-*.*s",
(int)tofmtsz, (int)tofmtsz, tofmt);
/* trim() the obnoxious trailing white lines */
while (fmt_sz) {
if (formatter[fmt_sz - 1] != ' ' && formatter[fmt_sz - 1] != '\0') {
formatter[fmt_sz] = '\0';
break;
}
fmt_sz--;
}
}
static void show_nvme_id_ctrl_cmic(__u8 cmic)
{
__u8 rsvd = (cmic & 0xF0) >> 4;
__u8 ana = (cmic & 0x8) >> 3;
__u8 sriov = (cmic & 0x4) >> 2;
__u8 mctl = (cmic & 0x2) >> 1;
__u8 mp = cmic & 0x1;
if (rsvd)
printf(" [7:4] : %#x\tReserved\n", rsvd);
printf(" [3:3] : %#x\tANA %ssupported\n", ana, ana ? "" : "not ");
printf(" [2:2] : %#x\t%s\n", sriov, sriov ? "SR-IOV" : "PCI");
printf(" [1:1] : %#x\t%s Controller\n",
mctl, mctl ? "Multi" : "Single");
printf(" [0:0] : %#x\t%s Port\n", mp, mp ? "Multi" : "Single");
printf("\n");
}
static void show_nvme_id_ctrl_oaes(__le32 ctrl_oaes)
{
__u32 oaes = le32_to_cpu(ctrl_oaes);
__u32 rsvd0 = (oaes & 0xFFFFFC00) >> 10;
__u32 nace = (oaes & 0x100) >> 8;
__u32 fan = (oaes & 0x200) >> 9;
__u32 rsvd1 = oaes & 0xFF;
if (rsvd0)
printf(" [31:10] : %#x\tReserved\n", rsvd0);
printf(" [9:9] : %#x\tFirmware Activation Notices %sSupported\n",
fan, fan ? "" : "Not ");
printf(" [8:8] : %#x\tNamespace Attribute Changed Event %sSupported\n",
nace, nace ? "" : "Not ");
if (rsvd1)
printf(" [7:0] : %#x\tReserved\n", rsvd1);
printf("\n");
}
static void show_nvme_id_ctrl_ctratt(__le32 ctrl_ctratt)
{
__u32 ctratt = le32_to_cpu(ctrl_ctratt);
__u32 rsvd0 = ctratt >> 6;
__u32 hostid128 = ctratt & NVME_CTRL_CTRATT_128_ID >> 0;
__u32 psp = ctratt & NVME_CTRL_CTRATT_NON_OP_PSP >> 1;
__u32 sets = ctratt & NVME_CTRL_CTRATT_NVM_SETS >> 2;
__u32 rrl = ctratt & NVME_CTRL_CTRATT_READ_RECV_LVLS >> 3;
__u32 eg = ctratt & NVME_CTRL_CTRATT_ENDURANCE_GROUPS >> 4;
__u32 iod = ctratt & NVME_CTRL_CTRATT_PREDICTABLE_LAT >> 5;
if (rsvd0)
printf(" [31:6] : %#x\tReserved\n", rsvd0);
printf(" [5:5] : %#x\tPredictable Latency Mode %sSupported\n",
iod, iod ? "" : "Not ");
printf(" [4:4] : %#x\tEndurance Groups %sSupported\n",
eg, eg ? "" : "Not ");
printf(" [3:3] : %#x\tRead Recovery Levels %sSupported\n",
rrl, rrl ? "" : "Not ");
printf(" [2:2] : %#x\tNVM Sets %sSupported\n",
sets, sets ? "" : "Not ");
printf(" [1:1] : %#x\tNon-Operational Power State Permissive %sSupported\n",
psp, psp ? "" : "Not ");
printf(" [0:0] : %#x\t128-bit Host Identifier %sSupported\n",
hostid128, hostid128 ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_oacs(__le16 ctrl_oacs)
{
__u16 oacs = le16_to_cpu(ctrl_oacs);
__u16 rsvd = (oacs & 0xFE00) >> 9;
__u16 dbc = (oacs & 0x100) >> 8;
__u16 vir = (oacs & 0x80) >> 7;
__u16 nmi = (oacs & 0x40) >> 6;
__u16 dir = (oacs & 0x20) >> 5;
__u16 sft = (oacs & 0x10) >> 4;
__u16 nsm = (oacs & 0x8) >> 3;
__u16 fwc = (oacs & 0x4) >> 2;
__u16 fmt = (oacs & 0x2) >> 1;
__u16 sec = oacs & 0x1;
if (rsvd)
printf(" [15:9] : %#x\tReserved\n", rsvd);
printf(" [8:8] : %#x\tDoorbell Buffer Config %sSupported\n",
dbc, dbc ? "" : "Not ");
printf(" [7:7] : %#x\tVirtualization Management %sSupported\n",
vir, vir ? "" : "Not ");
printf(" [6:6] : %#x\tNVMe-MI Send and Receive %sSupported\n",
nmi, nmi ? "" : "Not ");
printf(" [5:5] : %#x\tDirectives %sSupported\n",
dir, dir ? "" : "Not ");
printf(" [4:4] : %#x\tDevice Self-test %sSupported\n",
sft, sft ? "" : "Not ");
printf(" [3:3] : %#x\tNS Management and Attachment %sSupported\n",
nsm, nsm ? "" : "Not ");
printf(" [2:2] : %#x\tFW Commit and Download %sSupported\n",
fwc, fwc ? "" : "Not ");
printf(" [1:1] : %#x\tFormat NVM %sSupported\n",
fmt, fmt ? "" : "Not ");
printf(" [0:0] : %#x\tSecurity Send and Receive %sSupported\n",
sec, sec ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_frmw(__u8 frmw)
{
__u8 rsvd = (frmw & 0xE0) >> 5;
__u8 fawr = (frmw & 0x10) >> 4;
__u8 nfws = (frmw & 0xE) >> 1;
__u8 s1ro = frmw & 0x1;
if (rsvd)
printf(" [7:5] : %#x\tReserved\n", rsvd);
printf(" [4:4] : %#x\tFirmware Activate Without Reset %sSupported\n",
fawr, fawr ? "" : "Not ");
printf(" [3:1] : %#x\tNumber of Firmware Slots\n", nfws);
printf(" [0:0] : %#x\tFirmware Slot 1 Read%s\n",
s1ro, s1ro ? "-Only" : "/Write");
printf("\n");
}
static void show_nvme_id_ctrl_lpa(__u8 lpa)
{
__u8 rsvd = (lpa & 0xF0) >> 4;
__u8 telem = (lpa & 0x8) >> 3;
__u8 ed = (lpa & 0x4) >> 2;
__u8 celp = (lpa & 0x2) >> 1;
__u8 smlp = lpa & 0x1;
if (rsvd)
printf(" [7:4] : %#x\tReserved\n", rsvd);
printf(" [3:3] : %#x\tTelemetry host/controller initiated log page %sSuporrted\n",
telem, telem ? "" : "Not ");
printf(" [2:2] : %#x\tExtended data for Get Log Page %sSupported\n",
ed, ed ? "" : "Not ");
printf(" [1:1] : %#x\tCommand Effects Log Page %sSupported\n",
celp, celp ? "" : "Not ");
printf(" [0:0] : %#x\tSMART/Health Log Page per NS %sSupported\n",
smlp, smlp ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_avscc(__u8 avscc)
{
__u8 rsvd = (avscc & 0xFE) >> 1;
__u8 fmt = avscc & 0x1;
if (rsvd)
printf(" [7:1] : %#x\tReserved\n", rsvd);
printf(" [0:0] : %#x\tAdmin Vendor Specific Commands uses %s Format\n",
fmt, fmt ? "NVMe" : "Vendor Specific");
printf("\n");
}
static void show_nvme_id_ctrl_apsta(__u8 apsta)
{
__u8 rsvd = (apsta & 0xFE) >> 1;
__u8 apst = apsta & 0x1;
if (rsvd)
printf(" [7:1] : %#x\tReserved\n", rsvd);
printf(" [0:0] : %#x\tAutonomous Power State Transitions %sSupported\n",
apst, apst ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_rpmbs(__le32 ctrl_rpmbs)
{
__u32 rpmbs = le32_to_cpu(ctrl_rpmbs);
__u32 asz = (rpmbs & 0xFF000000) >> 24;
__u32 tsz = (rpmbs & 0xFF0000) >> 16;
__u32 rsvd = (rpmbs & 0xFFC0) >> 6;
__u32 auth = (rpmbs & 0x38) >> 3;
__u32 rpmb = rpmbs & 0x7;
printf(" [31:24]: %#x\tAccess Size\n", asz);
printf(" [23:16]: %#x\tTotal Size\n", tsz);
if (rsvd)
printf(" [15:6] : %#x\tReserved\n", rsvd);
printf(" [5:3] : %#x\tAuthentication Method\n", auth);
printf(" [2:0] : %#x\tNumber of RPMB Units\n", rpmb);
printf("\n");
}
static void show_nvme_id_ctrl_hctma(__le16 ctrl_hctma)
{
__u16 hctma = le16_to_cpu(ctrl_hctma);
__u16 rsvd = (hctma & 0xFFFE) >> 1;
__u16 hctm = hctma & 0x1;
if (rsvd)
printf(" [15:1] : %#x\tReserved\n", rsvd);
printf(" [0:0] : %#x\tHost Controlled Thermal Management %sSupported\n",
hctm, hctm ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_sanicap(__le32 ctrl_sanicap)
{
__u32 sanicap = le32_to_cpu(ctrl_sanicap);
__u32 rsvd = (sanicap & 0xFFFFFFF8) >> 3;
__u32 owr = (sanicap & 0x4) >> 2;
__u32 ber = (sanicap & 0x2) >> 1;
__u32 cer = sanicap & 0x1;
if (rsvd)
printf(" [31:3] : %#x\tReserved\n", rsvd);
printf(" [2:2] : %#x\tOverwrite Sanitize Operation %sSupported\n",
owr, owr ? "" : "Not ");
printf(" [1:1] : %#x\tBlock Erase Sanitize Operation %sSupported\n",
ber, ber ? "" : "Not ");
printf(" [0:0] : %#x\tCrypto Erase Sanitize Operation %sSupported\n",
cer, cer ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_anacap(__u8 anacap)
{
__u8 nz = (anacap & 0x80) >> 7;
__u8 grpid_change = (anacap & 0x40) >> 6;
__u8 rsvd = (anacap & 0x20) >> 5;
__u8 ana_change = (anacap & 0x10) >> 4;
__u8 ana_persist_loss = (anacap & 0x08) >> 3;
__u8 ana_inaccessible = (anacap & 0x04) >> 2;
__u8 ana_nonopt = (anacap & 0x02) >> 1;
__u8 ana_opt = (anacap & 0x01);
printf(" [7:7] : %#x\tNon-zero group ID %sSupported\n",
nz, nz ? "" : "Not ");
printf(" [6:6] : %#x\tGroup ID does %schange\n",
grpid_change, grpid_change ? "" : "not ");
if (rsvd)
printf(" [5:5] : %#x\tReserved\n", rsvd);
printf(" [4:4] : %#x\tANA Change state %sSupported\n",
ana_change, ana_change ? "" : "Not ");
printf(" [3:3] : %#x\tANA Persistent Loss state %sSupported\n",
ana_persist_loss, ana_persist_loss ? "" : "Not ");
printf(" [2:2] : %#x\tANA Inaccessible state %sSupported\n",
ana_inaccessible, ana_inaccessible ? "" : "Not ");
printf(" [1:1] : %#x\tANA Non-optimized state %sSupported\n",
ana_nonopt, ana_nonopt ? "" : "Not ");
printf(" [0:0] : %#x\tANA Optimized state %sSupported\n",
ana_opt, ana_opt ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_sqes(__u8 sqes)
{
__u8 msqes = (sqes & 0xF0) >> 4;
__u8 rsqes = sqes & 0xF;
printf(" [7:4] : %#x\tMax SQ Entry Size (%d)\n", msqes, 1 << msqes);
printf(" [3:0] : %#x\tMin SQ Entry Size (%d)\n", rsqes, 1 << rsqes);
printf("\n");
}
static void show_nvme_id_ctrl_cqes(__u8 cqes)
{
__u8 mcqes = (cqes & 0xF0) >> 4;
__u8 rcqes = cqes & 0xF;
printf(" [7:4] : %#x\tMax CQ Entry Size (%d)\n", mcqes, 1 << mcqes);
printf(" [3:0] : %#x\tMin CQ Entry Size (%d)\n", rcqes, 1 << rcqes);
printf("\n");
}
static void show_nvme_id_ctrl_oncs(__le16 ctrl_oncs)
{
__u16 oncs = le16_to_cpu(ctrl_oncs);
__u16 rsvd = (oncs & 0xFF80) >> 7;
__u16 tmst = (oncs & 0x40) >> 6;
__u16 resv = (oncs & 0x20) >> 5;
__u16 save = (oncs & 0x10) >> 4;
__u16 wzro = (oncs & 0x8) >> 3;
__u16 dsms = (oncs & 0x4) >> 2;
__u16 wunc = (oncs & 0x2) >> 1;
__u16 cmp = oncs & 0x1;
if (rsvd)
printf(" [15:6] : %#x\tReserved\n", rsvd);
printf(" [6:6] : %#x\tTimestamp %sSupported\n",
tmst, tmst ? "" : "Not ");
printf(" [5:5] : %#x\tReservations %sSupported\n",
resv, resv ? "" : "Not ");
printf(" [4:4] : %#x\tSave and Select %sSupported\n",
save, save ? "" : "Not ");
printf(" [3:3] : %#x\tWrite Zeroes %sSupported\n",
wzro, wzro ? "" : "Not ");
printf(" [2:2] : %#x\tData Set Management %sSupported\n",
dsms, dsms ? "" : "Not ");
printf(" [1:1] : %#x\tWrite Uncorrectable %sSupported\n",
wunc, wunc ? "" : "Not ");
printf(" [0:0] : %#x\tCompare %sSupported\n",
cmp, cmp ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_fuses(__le16 ctrl_fuses)
{
__u16 fuses = le16_to_cpu(ctrl_fuses);
__u16 rsvd = (fuses & 0xFE) >> 1;
__u16 cmpw = fuses & 0x1;
if (rsvd)
printf(" [15:1] : %#x\tReserved\n", rsvd);
printf(" [0:0] : %#x\tFused Compare and Write %sSupported\n",
cmpw, cmpw ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_fna(__u8 fna)
{
__u8 rsvd = (fna & 0xF8) >> 3;
__u8 cese = (fna & 0x4) >> 2;
__u8 cens = (fna & 0x2) >> 1;
__u8 fmns = fna & 0x1;
if (rsvd)
printf(" [7:3] : %#x\tReserved\n", rsvd);
printf(" [2:2] : %#x\tCrypto Erase %sSupported as part of Secure Erase\n",
cese, cese ? "" : "Not ");
printf(" [1:1] : %#x\tCrypto Erase Applies to %s Namespace(s)\n",
cens, cens ? "All" : "Single");
printf(" [0:0] : %#x\tFormat Applies to %s Namespace(s)\n",
fmns, fmns ? "All" : "Single");
printf("\n");
}
static void show_nvme_id_ctrl_vwc(__u8 vwc)
{
__u8 rsvd = (vwc & 0xFE) >> 1;
__u8 vwcp = vwc & 0x1;
if (rsvd)
printf(" [7:3] : %#x\tReserved\n", rsvd);
printf(" [0:0] : %#x\tVolatile Write Cache %sPresent\n",
vwcp, vwcp ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_nvscc(__u8 nvscc)
{
__u8 rsvd = (nvscc & 0xFE) >> 1;
__u8 fmt = nvscc & 0x1;
if (rsvd)
printf(" [7:1] : %#x\tReserved\n", rsvd);
printf(" [0:0] : %#x\tNVM Vendor Specific Commands uses %s Format\n",
fmt, fmt ? "NVMe" : "Vendor Specific");
printf("\n");
}
static void show_nvme_id_ctrl_nwpc(__u8 nwpc)
{
__u8 no_wp_wp = (nwpc & 0x01);
__u8 wp_power_cycle = (nwpc & 0x02) >> 1;
__u8 wp_permanent = (nwpc & 0x04) >> 2;
__u8 rsvd = (nwpc & 0xF8) >> 3;
if (rsvd)
printf(" [7:3] : %#x\tReserved\n", rsvd);
printf(" [2:2] : %#x\tPermanent Write Protect %sSupported\n",
wp_permanent, wp_permanent ? "" : "Not ");
printf(" [1:1] : %#x\tWrite Protect Until Power Supply %sSupported\n",
wp_power_cycle, wp_power_cycle ? "" : "Not ");
printf(" [0:0] : %#x\tNo Write Protect and Write Protect Namespace %sSupported\n",
no_wp_wp, no_wp_wp ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ctrl_sgls(__le32 ctrl_sgls)
{
__u32 sgls = le32_to_cpu(ctrl_sgls);
__u32 rsvd0 = (sgls & 0xFF700000) >> 21;
__u32 aofdsl = (sgls & 0x100000) >> 20;
__u32 mpcsd = (sgls & 0x80000) >> 19;
__u32 sglltb = (sgls & 0x40000) >> 18;
__u32 bacmdb = (sgls & 0x20000) >> 17;
__u32 bbs = (sgls & 0x10000) >> 16;
__u32 rsvd1 = (sgls & 0xFFF8) >> 3;
__u32 key = (sgls & 0x4) >> 2;
__u32 sglsp = sgls & 0x3;
if (rsvd0)
printf(" [31:21]: %#x\tReserved\n", rsvd0);
if (sglsp || (!sglsp && aofdsl))
printf(" [20:20]: %#x\tAddress Offsets %sSupported\n",
aofdsl, aofdsl ? "" : "Not ");
if (sglsp || (!sglsp && mpcsd))
printf(" [19:19]: %#x\tMetadata Pointer Containing "
"SGL Descriptor is %sSupported\n",
mpcsd, mpcsd ? "" : "Not ");
if (sglsp || (!sglsp && sglltb))
printf(" [18:18]: %#x\tSGL Length Larger than Buffer %sSupported\n",
sglltb, sglltb ? "" : "Not ");
if (sglsp || (!sglsp && bacmdb))
printf(" [17:17]: %#x\tByte-Aligned Contig. MD Buffer %sSupported\n",
bacmdb, bacmdb ? "" : "Not ");
if (sglsp || (!sglsp && bbs))
printf(" [16:16]: %#x\tSGL Bit-Bucket %sSupported\n",
bbs, bbs ? "" : "Not ");
if (rsvd1)
printf(" [15:3] : %#x\tReserved\n", rsvd1);
if (sglsp || (!sglsp && key))
printf(" [2:2] : %#x\tKeyed SGL Data Block descriptor %sSupported\n",
key, key ? "" : "Not ");
if (sglsp == 0x3)
printf(" [1:0] : %#x\tReserved\n", sglsp);
else if (sglsp == 0x2)
printf(" [1:0] : %#x\tScatter-Gather Lists Supported."
" Dword alignment required.\n", sglsp);
else if (sglsp == 0x1)
printf(" [1:0] : %#x\tScatter-Gather Lists Supported."
" No Dword alignment required.\n", sglsp);
else
printf(" [1:0] : %#x\tScatter-Gather Lists Not Supported\n", sglsp);
printf("\n");
}
static void show_nvme_id_ctrl_ctrattr(__u8 ctrattr)
{
__u8 rsvd = (ctrattr & 0xFE) >> 1;
__u8 scm = ctrattr & 0x1;
if (rsvd)
printf(" [7:1] : %#x\tReserved\n", rsvd);
printf(" [0:0] : %#x\t%s Controller Model\n",
scm, scm ? "Static" : "Dynamic");
printf("\n");
}
static void show_nvme_id_ns_nsfeat(__u8 nsfeat)
{
__u8 rsvd = (nsfeat & 0xF8) >> 3;
__u8 dulbe = (nsfeat & 0x4) >> 2;
__u8 na = (nsfeat & 0x2) >> 1;
__u8 thin = nsfeat & 0x1;
if (rsvd)
printf(" [7:3] : %#x\tReserved\n", rsvd);
printf(" [2:2] : %#x\tDeallocated or Unwritten Logical Block error %sSupported\n",
dulbe, dulbe ? "" : "Not ");
printf(" [1:1] : %#x\tNamespace uses %s\n",
na, na ? "NAWUN, NAWUPF, and NACWU" : "AWUN, AWUPF, and ACWU");
printf(" [0:0] : %#x\tThin Provisioning %sSupported\n",
thin, thin ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ns_flbas(__u8 flbas)
{
__u8 rsvd = (flbas & 0xE0) >> 5;
__u8 mdedata = (flbas & 0x10) >> 4;
__u8 lbaf = flbas & 0xF;
if (rsvd)
printf(" [7:5] : %#x\tReserved\n", rsvd);
printf(" [4:4] : %#x\tMetadata Transferred %s\n",
mdedata, mdedata ? "at End of Data LBA" : "in Separate Contiguous Buffer");
printf(" [3:0] : %#x\tCurrent LBA Format Selected\n", lbaf);
printf("\n");
}
static void show_nvme_id_ns_mc(__u8 mc)
{
__u8 rsvd = (mc & 0xFC) >> 2;
__u8 mdp = (mc & 0x2) >> 1;
__u8 extdlba = mc & 0x1;
if (rsvd)
printf(" [7:2] : %#x\tReserved\n", rsvd);
printf(" [1:1] : %#x\tMetadata Pointer %sSupported\n",
mdp, mdp ? "" : "Not ");
printf(" [0:0] : %#x\tMetadata as Part of Extended Data LBA %sSupported\n",
extdlba, extdlba ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ns_dpc(__u8 dpc)
{
__u8 rsvd = (dpc & 0xE0) >> 5;
__u8 pil8 = (dpc & 0x10) >> 4;
__u8 pif8 = (dpc & 0x8) >> 3;
__u8 pit3 = (dpc & 0x4) >> 2;
__u8 pit2 = (dpc & 0x2) >> 1;
__u8 pit1 = dpc & 0x1;
if (rsvd)
printf(" [7:5] : %#x\tReserved\n", rsvd);
printf(" [4:4] : %#x\tProtection Information Transferred as Last 8 Bytes of Metadata %sSupported\n",
pil8, pil8 ? "" : "Not ");
printf(" [3:3] : %#x\tProtection Information Transferred as First 8 Bytes of Metadata %sSupported\n",
pif8, pif8 ? "" : "Not ");
printf(" [2:2] : %#x\tProtection Information Type 3 %sSupported\n",
pit3, pit3 ? "" : "Not ");
printf(" [1:1] : %#x\tProtection Information Type 2 %sSupported\n",
pit2, pit2 ? "" : "Not ");
printf(" [0:0] : %#x\tProtection Information Type 1 %sSupported\n",
pit1, pit1 ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ns_dps(__u8 dps)
{
__u8 rsvd = (dps & 0xF0) >> 4;
__u8 pif8 = (dps & 0x8) >> 3;
__u8 pit = dps & 0x7;
if (rsvd)
printf(" [7:4] : %#x\tReserved\n", rsvd);
printf(" [3:3] : %#x\tProtection Information is Transferred as %s 8 Bytes of Metadata\n",
pif8, pif8 ? "First" : "Last");
printf(" [2:0] : %#x\tProtection Information %s\n", pit,
pit == 3 ? "Type 3 Enabled" :
pit == 2 ? "Type 2 Enabled" :
pit == 1 ? "Type 1 Enabled" :
pit == 0 ? "Disabled" : "Reserved Enabled");
printf("\n");
}
static void show_nvme_id_ns_nmic(__u8 nmic)
{
__u8 rsvd = (nmic & 0xFE) >> 1;
__u8 mp = nmic & 0x1;
if (rsvd)
printf(" [7:1] : %#x\tReserved\n", rsvd);
printf(" [0:0] : %#x\tNamespace Multipath %sCapable\n",
mp, mp ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ns_rescap(__u8 rescap)
{
__u8 rsvd = (rescap & 0x80) >> 7;
__u8 eaar = (rescap & 0x40) >> 6;
__u8 wear = (rescap & 0x20) >> 5;
__u8 earo = (rescap & 0x10) >> 4;
__u8 wero = (rescap & 0x8) >> 3;
__u8 ea = (rescap & 0x4) >> 2;
__u8 we = (rescap & 0x2) >> 1;
__u8 ptpl = rescap & 0x1;
if (rsvd)
printf(" [7:7] : %#x\tReserved\n", rsvd);
printf(" [6:6] : %#x\tExclusive Access - All Registrants %sSupported\n",
eaar, eaar ? "" : "Not ");
printf(" [5:5] : %#x\tWrite Exclusive - All Registrants %sSupported\n",
wear, wear ? "" : "Not ");
printf(" [4:4] : %#x\tExclusive Access - Registrants Only %sSupported\n",
earo, earo ? "" : "Not ");
printf(" [3:3] : %#x\tWrite Exclusive - Registrants Only %sSupported\n",
wero, wero ? "" : "Not ");
printf(" [2:2] : %#x\tExclusive Access %sSupported\n",
ea, ea ? "" : "Not ");
printf(" [1:1] : %#x\tWrite Exclusive %sSupported\n",
we, we ? "" : "Not ");
printf(" [0:0] : %#x\tPersist Through Power Loss %sSupported\n",
ptpl, ptpl ? "" : "Not ");
printf("\n");
}
static void show_nvme_id_ns_fpi(__u8 fpi)
{
__u8 fpis = (fpi & 0x80) >> 7;
__u8 fpii = fpi & 0x7F;
printf(" [7:7] : %#x\tFormat Progress Indicator %sSupported\n",
fpis, fpis ? "" : "Not ");
if (fpis || (!fpis && fpii))
printf(" [6:0] : %#x\tFormat Progress Indicator (Remaining %d%%)\n",
fpii, fpii);
printf("\n");
}
static void show_nvme_id_ns_dlfeat(__u8 dlfeat)
{
__u8 rsvd = (dlfeat & 0xE0) >> 5;
__u8 guard = (dlfeat & 0x10) >> 4;
__u8 dwz = (dlfeat & 0x8) >> 3;
__u8 val = dlfeat & 0x7;
if (rsvd)
printf(" [7:5] : %#x\tReserved\n", rsvd);
printf(" [4:4] : %#x\tGuard Field of Deallocated Logical Blocks is set to %s\n",
guard, guard ? "CRC of The Value Read" : "0xFFFF");
printf(" [3:3] : %#x\tDeallocate Bit in the Write Zeroes Commmand is %sSupported\n",
dwz, dwz ? "" : "Not ");
printf(" [2:0] : %#x\tBytes Read From a Deallocated Logical Block and its Metadata are %s\n", val,
val == 2 ? "0xFF" :
val == 1 ? "0x00" :
val == 0 ? "Not Reported" : "Reserved Value");
printf("\n");
}
void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
{
int i;
int human = mode & HUMAN,
vs = mode & VS;
printf("nsze : %#"PRIx64"\n", (uint64_t)le64_to_cpu(ns->nsze));
printf("ncap : %#"PRIx64"\n", (uint64_t)le64_to_cpu(ns->ncap));
printf("nuse : %#"PRIx64"\n", (uint64_t)le64_to_cpu(ns->nuse));
printf("nsfeat : %#x\n", ns->nsfeat);
if (human)
show_nvme_id_ns_nsfeat(ns->nsfeat);
printf("nlbaf : %d\n", ns->nlbaf);
printf("flbas : %#x\n", ns->flbas);
if (human)
show_nvme_id_ns_flbas(ns->flbas);
printf("mc : %#x\n", ns->mc);
if (human)
show_nvme_id_ns_mc(ns->mc);
printf("dpc : %#x\n", ns->dpc);
if (human)
show_nvme_id_ns_dpc(ns->dpc);
printf("dps : %#x\n", ns->dps);
if (human)
show_nvme_id_ns_dps(ns->dps);
printf("nmic : %#x\n", ns->nmic);
if (human)
show_nvme_id_ns_nmic(ns->nmic);
printf("rescap : %#x\n", ns->rescap);
if (human)
show_nvme_id_ns_rescap(ns->rescap);
printf("fpi : %#x\n", ns->fpi);
if (human)
show_nvme_id_ns_fpi(ns->fpi);
printf("dlfeat : %d\n", le16_to_cpu(ns->dlfeat));
if (human)
show_nvme_id_ns_dlfeat(ns->dlfeat);
printf("nawun : %d\n", le16_to_cpu(ns->nawun));
printf("nawupf : %d\n", le16_to_cpu(ns->nawupf));
printf("nacwu : %d\n", le16_to_cpu(ns->nacwu));
printf("nabsn : %d\n", le16_to_cpu(ns->nabsn));
printf("nabo : %d\n", le16_to_cpu(ns->nabo));
printf("nabspf : %d\n", le16_to_cpu(ns->nabspf));
printf("noiob : %d\n", le16_to_cpu(ns->noiob));
printf("nvmcap : %.0Lf\n", int128_to_double(ns->nvmcap));
printf("nsattr : %u\n", ns->nsattr);
printf("nvmsetid: %d\n", le16_to_cpu(ns->nvmsetid));
printf("anagrpid: %d\n", le32_to_cpu(ns->anagrpid));
printf("endgid : %d\n", le16_to_cpu(ns->endgid));
printf("nguid : ");
for (i = 0; i < 16; i++)
printf("%02x", ns->nguid[i]);
printf("\n");
printf("eui64 : ");
for (i = 0; i < 8; i++)
printf("%02x", ns->eui64[i]);
printf("\n");
for (i = 0; i <= ns->nlbaf; i++) {
if (human)
printf("LBA Format %2d : Metadata Size: %-3d bytes - "
"Data Size: %-2d bytes - Relative Performance: %#x %s %s\n", i,
le16_to_cpu(ns->lbaf[i].ms), 1 << ns->lbaf[i].ds, ns->lbaf[i].rp,
ns->lbaf[i].rp == 3 ? "Degraded" :
ns->lbaf[i].rp == 2 ? "Good" :
ns->lbaf[i].rp == 1 ? "Better" : "Best",
i == (ns->flbas & 0xf) ? "(in use)" : "");
else
printf("lbaf %2d : ms:%-3d lbads:%-2d rp:%#x %s\n", i,
le16_to_cpu(ns->lbaf[i].ms), ns->lbaf[i].ds, ns->lbaf[i].rp,
i == (ns->flbas & 0xf) ? "(in use)" : "");
}
if (vs) {
printf("vs[]:\n");
d(ns->vs, sizeof(ns->vs), 16, 1);
}
}
void json_nvme_id_ns_descs(void *data)
{
/* large enough to hold uuid str (37) or nguid str (32) + zero byte */
char json_str[40];
char *json_str_p;
union {
__u8 eui64[NVME_NIDT_EUI64_LEN];
__u8 nguid[NVME_NIDT_NGUID_LEN];
#ifdef LIBUUID
uuid_t uuid;
#endif
} desc;
struct json_object *root;
struct json_array *json_array = NULL;
off_t off;
int pos, len = 0;
int i;
for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
struct nvme_ns_id_desc *cur = data + pos;
const char *nidt_name = NULL;
if (cur->nidl == 0)
break;
memset(json_str, 0, sizeof(json_str));
json_str_p = json_str;
off = pos + sizeof(*cur);
switch (cur->nidt) {
case NVME_NIDT_EUI64:
memcpy(desc.eui64, data + off, sizeof(desc.eui64));
for (i = 0; i < sizeof(desc.eui64); i++)
json_str_p += sprintf(json_str_p, "%02x", desc.eui64[i]);
len += sizeof(desc.eui64);
nidt_name = "eui64";
break;
case NVME_NIDT_NGUID:
memcpy(desc.nguid, data + off, sizeof(desc.nguid));
for (i = 0; i < sizeof(desc.nguid); i++)
json_str_p += sprintf(json_str_p, "%02x", desc.nguid[i]);
len += sizeof(desc.nguid);
nidt_name = "nguid";
break;
#ifdef LIBUUID
case NVME_NIDT_UUID:
memcpy(desc.uuid, data + off, sizeof(desc.uuid));
uuid_unparse_lower(desc.uuid, json_str);
len += sizeof(desc.uuid);
nidt_name = "uuid";
break;
#endif
default:
/* Skip unnkown types */
len = cur->nidl;
break;
}
if (nidt_name) {
struct json_object *elem = json_create_object();
json_object_add_value_int(elem, "loc", pos);
json_object_add_value_int(elem, "nidt", (int)cur->nidt);
json_object_add_value_int(elem, "nidl", (int)cur->nidl);
json_object_add_value_string(elem, "type", nidt_name);
json_object_add_value_string(elem, nidt_name, json_str);
if (!json_array) {
json_array = json_create_array();
}
json_array_add_value_object(json_array, elem);
}
len += sizeof(*cur);
}
root = json_create_object();
if (json_array)
json_object_add_value_array(root, "ns-descs", json_array);
json_print_object(root, NULL);
printf("\n");
json_free_object(root);
}
void show_nvme_id_ns_descs(void *data)
{
int pos, len = 0;
int i;
#ifdef LIBUUID
uuid_t uuid;
char uuid_str[37];
#endif
__u8 eui64[8];
__u8 nguid[16];
for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
struct nvme_ns_id_desc *cur = data + pos;
if (cur->nidl == 0)
break;
switch (cur->nidt) {
case NVME_NIDT_EUI64:
memcpy(eui64, data + pos + sizeof(*cur), sizeof(eui64));
printf("eui64 : ");
for (i = 0; i < 8; i++)
printf("%02x", eui64[i]);
printf("\n");
len += sizeof(eui64);
break;
case NVME_NIDT_NGUID:
memcpy(nguid, data + pos + sizeof(*cur), sizeof(nguid));
printf("nguid : ");
for (i = 0; i < 16; i++)
printf("%02x", nguid[i]);
printf("\n");
len += sizeof(nguid);
break;
#ifdef LIBUUID
case NVME_NIDT_UUID:
memcpy(uuid, data + pos + sizeof(*cur), 16);
uuid_unparse_lower(uuid, uuid_str);
printf("uuid : %s\n", uuid_str);
len += sizeof(uuid);
break;
#endif
default:
/* Skip unnkown types */
len = cur->nidl;
break;
}
len += sizeof(*cur);
}
}
static void print_ps_power_and_scale(__le16 ctr_power, __u8 scale)
{
__u16 power = le16_to_cpu(ctr_power);
switch (scale & 0x3) {
case 0:
/* Not reported for this power state */
printf("-");
break;
case 1:
/* Units of 0.0001W */
printf("%01u.%04uW", power / 10000, power % 10000);
break;
case 2:
/* Units of 0.01W */
printf("%01u.%02uW", power / 100, scale % 100);
break;
default:
printf("reserved");
}
}
static void show_nvme_id_ctrl_power(struct nvme_id_ctrl *ctrl)
{
int i;
for (i = 0; i <= ctrl->npss; i++) {
__u16 max_power = le16_to_cpu(ctrl->psd[i].max_power);
printf("ps %4d : mp:", i);
if (ctrl->psd[i].flags & NVME_PS_FLAGS_MAX_POWER_SCALE)
printf("%01u.%04uW ", max_power / 10000, max_power % 10000);
else
printf("%01u.%02uW ", max_power / 100, max_power % 100);
if (ctrl->psd[i].flags & NVME_PS_FLAGS_NON_OP_STATE)
printf("non-");
printf("operational enlat:%d exlat:%d rrt:%d rrl:%d\n"
" rwt:%d rwl:%d idle_power:",
le32_to_cpu(ctrl->psd[i].entry_lat), le32_to_cpu(ctrl->psd[i].exit_lat),
ctrl->psd[i].read_tput, ctrl->psd[i].read_lat,
ctrl->psd[i].write_tput, ctrl->psd[i].write_lat);
print_ps_power_and_scale(ctrl->psd[i].idle_power,
POWER_SCALE(ctrl->psd[i].idle_scale));
printf(" active_power:");
print_ps_power_and_scale(ctrl->psd[i].active_power,
POWER_SCALE(ctrl->psd[i].active_work_scale));
printf("\n");
}
}
void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs, struct json_object *root))
{
int human = mode & HUMAN, vs = mode & VS;
printf("vid : %#x\n", le16_to_cpu(ctrl->vid));
printf("ssvid : %#x\n", le16_to_cpu(ctrl->ssvid));
printf("sn : %-.*s\n", (int)sizeof(ctrl->sn), ctrl->sn);
printf("mn : %-.*s\n", (int)sizeof(ctrl->mn), ctrl->mn);
printf("fr : %-.*s\n", (int)sizeof(ctrl->fr), ctrl->fr);
printf("rab : %d\n", ctrl->rab);
printf("ieee : %02x%02x%02x\n",
ctrl->ieee[2], ctrl->ieee[1], ctrl->ieee[0]);
printf("cmic : %#x\n", ctrl->cmic);
if (human)
show_nvme_id_ctrl_cmic(ctrl->cmic);
printf("mdts : %d\n", ctrl->mdts);
printf("cntlid : %x\n", le16_to_cpu(ctrl->cntlid));
printf("ver : %x\n", le32_to_cpu(ctrl->ver));
printf("rtd3r : %x\n", le32_to_cpu(ctrl->rtd3r));
printf("rtd3e : %x\n", le32_to_cpu(ctrl->rtd3e));
printf("oaes : %#x\n", le32_to_cpu(ctrl->oaes));
if (human)
show_nvme_id_ctrl_oaes(ctrl->oaes);
printf("ctratt : %#x\n", le32_to_cpu(ctrl->ctratt));
if (human)
show_nvme_id_ctrl_ctratt(ctrl->ctratt);
printf("rrls : %#x\n", le16_to_cpu(ctrl->rrls));
printf("oacs : %#x\n", le16_to_cpu(ctrl->oacs));
if (human)
show_nvme_id_ctrl_oacs(ctrl->oacs);
printf("acl : %d\n", ctrl->acl);
printf("aerl : %d\n", ctrl->aerl);
printf("frmw : %#x\n", ctrl->frmw);
if (human)
show_nvme_id_ctrl_frmw(ctrl->frmw);
printf("lpa : %#x\n", ctrl->lpa);
if (human)
show_nvme_id_ctrl_lpa(ctrl->lpa);
printf("elpe : %d\n", ctrl->elpe);
printf("npss : %d\n", ctrl->npss);
printf("avscc : %#x\n", ctrl->avscc);
if (human)
show_nvme_id_ctrl_avscc(ctrl->avscc);
printf("apsta : %#x\n", ctrl->apsta);
if (human)
show_nvme_id_ctrl_apsta(ctrl->apsta);
printf("wctemp : %d\n", le16_to_cpu(ctrl->wctemp));