forked from linux-nvme/libnvme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioctl.h
More file actions
4609 lines (4328 loc) · 153 KB
/
ioctl.h
File metadata and controls
4609 lines (4328 loc) · 153 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: LGPL-2.1-or-later
/*
* This file is part of libnvme.
* Copyright (c) 2020 Western Digital Corporation or its affiliates.
*
* Authors: Keith Busch <[email protected]>
* Chaitanya Kulkarni <[email protected]>
*/
#ifndef _LIBNVME_IOCTL_H
#define _LIBNVME_IOCTL_H
#include <stddef.h>
#include <sys/ioctl.h>
#include <nvme/types.h>
#include <nvme/api-types.h>
/*
* We can not always count on the kernel UAPI being installed. Use the same
* 'ifdef' guard to avoid double definitions just in case.
*/
#ifndef _UAPI_LINUX_NVME_IOCTL_H
#define _UAPI_LINUX_NVME_IOCTL_H
#ifndef _LINUX_NVME_IOCTL_H
#define _LINUX_NVME_IOCTL_H
/**
* DOC: ioctl.h
*
* Linux NVMe ioctl interface functions
*/
/* '0' is interpreted by the kernel to mean 'apply the default timeout' */
#define NVME_DEFAULT_IOCTL_TIMEOUT 0
/*
* 4k is the smallest possible transfer unit, so restricting to 4k
* avoids having to check the MDTS value of the controller.
*/
#define NVME_LOG_PAGE_PDU_SIZE 4096
/*
* should not exceed CAP.MQES, 16 is rational for most ssd
*/
#define NVME_URING_ENTRIES 16
/**
* struct nvme_passthru_cmd - nvme passthrough command structure
* @opcode: Operation code, see &enum nvme_io_opcodes and &enum nvme_admin_opcodes
* @flags: Not supported: intended for command flags (eg: SGL, FUSE)
* @rsvd1: Reserved for future use
* @nsid: Namespace Identifier, or Fabrics type
* @cdw2: Command Dword 2 (no spec defined use)
* @cdw3: Command Dword 3 (no spec defined use)
* @metadata: User space address to metadata buffer (NULL if not used)
* @addr: User space address to data buffer (NULL if not used)
* @metadata_len: Metadata buffer transfer length
* @data_len: Data buffer transfer length
* @cdw10: Command Dword 10 (command specific)
* @cdw11: Command Dword 11 (command specific)
* @cdw12: Command Dword 12 (command specific)
* @cdw13: Command Dword 13 (command specific)
* @cdw14: Command Dword 14 (command specific)
* @cdw15: Command Dword 15 (command specific)
* @timeout_ms: If non-zero, overrides system default timeout in milliseconds
* @result: Set on completion to the command's CQE DWORD 0 controller response
*/
struct nvme_passthru_cmd {
__u8 opcode;
__u8 flags;
__u16 rsvd1;
__u32 nsid;
__u32 cdw2;
__u32 cdw3;
__u64 metadata;
__u64 addr;
__u32 metadata_len;
__u32 data_len;
__u32 cdw10;
__u32 cdw11;
__u32 cdw12;
__u32 cdw13;
__u32 cdw14;
__u32 cdw15;
__u32 timeout_ms;
__u32 result;
};
/**
* struct nvme_passthru_cmd64 - 64-bit nvme passthrough command structure
* @opcode: Operation code, see &enum nvme_io_opcodes and &enum nvme_admin_opcodes
* @flags: Not supported: intended for command flags (eg: SGL, FUSE)
* @rsvd1: Reserved for future use
* @nsid: Namespace Identifier, or Fabrics type
* @cdw2: Command Dword 2 (no spec defined use)
* @cdw3: Command Dword 3 (no spec defined use)
* @metadata: User space address to metadata buffer (NULL if not used)
* @addr: User space address to data buffer (NULL if not used)
* @metadata_len: Metadata buffer transfer length
* @data_len: Data buffer transfer length
* @cdw10: Command Dword 10 (command specific)
* @cdw11: Command Dword 11 (command specific)
* @cdw12: Command Dword 12 (command specific)
* @cdw13: Command Dword 13 (command specific)
* @cdw14: Command Dword 14 (command specific)
* @cdw15: Command Dword 15 (command specific)
* @timeout_ms: If non-zero, overrides system default timeout in milliseconds
* @rsvd2: Reserved for future use (and fills an implicit struct pad
* @result: Set on completion to the command's CQE DWORD 0-1 controller response
*/
struct nvme_passthru_cmd64 {
__u8 opcode;
__u8 flags;
__u16 rsvd1;
__u32 nsid;
__u32 cdw2;
__u32 cdw3;
__u64 metadata;
__u64 addr;
__u32 metadata_len;
__u32 data_len;
__u32 cdw10;
__u32 cdw11;
__u32 cdw12;
__u32 cdw13;
__u32 cdw14;
__u32 cdw15;
__u32 timeout_ms;
__u32 rsvd2;
__u64 result;
};
/**
* struct nvme_uring_cmd - nvme uring command structure
* @opcode: Operation code, see &enum nvme_io_opcodes and &enum nvme_admin_opcodes
* @flags: Not supported: intended for command flags (eg: SGL, FUSE)
* @rsvd1: Reserved for future use
* @nsid: Namespace Identifier, or Fabrics type
* @cdw2: Command Dword 2 (no spec defined use)
* @cdw3: Command Dword 3 (no spec defined use)
* @metadata: User space address to metadata buffer (NULL if not used)
* @addr: User space address to data buffer (NULL if not used)
* @metadata_len: Metadata buffer transfer length
* @data_len: Data buffer transfer length
* @cdw10: Command Dword 10 (command specific)
* @cdw11: Command Dword 11 (command specific)
* @cdw12: Command Dword 12 (command specific)
* @cdw13: Command Dword 13 (command specific)
* @cdw14: Command Dword 14 (command specific)
* @cdw15: Command Dword 15 (command specific)
* @timeout_ms: If non-zero, overrides system default timeout in milliseconds
* @rsvd2: Reserved for future use (and fills an implicit struct pad
*/
struct nvme_uring_cmd {
__u8 opcode;
__u8 flags;
__u16 rsvd1;
__u32 nsid;
__u32 cdw2;
__u32 cdw3;
__u64 metadata;
__u64 addr;
__u32 metadata_len;
__u32 data_len;
__u32 cdw10;
__u32 cdw11;
__u32 cdw12;
__u32 cdw13;
__u32 cdw14;
__u32 cdw15;
__u32 timeout_ms;
__u32 rsvd2;
};
#define NVME_IOCTL_ID _IO('N', 0x40)
#define NVME_IOCTL_RESET _IO('N', 0x44)
#define NVME_IOCTL_SUBSYS_RESET _IO('N', 0x45)
#define NVME_IOCTL_RESCAN _IO('N', 0x46)
#define NVME_IOCTL_ADMIN_CMD _IOWR('N', 0x41, struct nvme_passthru_cmd)
#define NVME_IOCTL_IO_CMD _IOWR('N', 0x43, struct nvme_passthru_cmd)
#define NVME_IOCTL_ADMIN64_CMD _IOWR('N', 0x47, struct nvme_passthru_cmd64)
#define NVME_IOCTL_IO64_CMD _IOWR('N', 0x48, struct nvme_passthru_cmd64)
/* io_uring async commands: */
#define NVME_URING_CMD_IO _IOWR('N', 0x80, struct nvme_uring_cmd)
#define NVME_URING_CMD_IO_VEC _IOWR('N', 0x81, struct nvme_uring_cmd)
#define NVME_URING_CMD_ADMIN _IOWR('N', 0x82, struct nvme_uring_cmd)
#define NVME_URING_CMD_ADMIN_VEC _IOWR('N', 0x83, struct nvme_uring_cmd)
#endif /* _UAPI_LINUX_NVME_IOCTL_H */
#endif /* _LINUX_NVME_IOCTL_H */
/**
* sizeof_args - Helper function used to determine structure sizes
* @type: Argument structure type
* @member: Member inside the type
* @align: Alignment information
*/
#define sizeof_args(type, member, align) \
({ \
type s; \
size_t t = offsetof(type, member) + sizeof(s.member); \
size_t p = (sizeof(align) - (t % sizeof(align))) % sizeof(align); \
t + p; \
})
enum nvme_cmd_dword_fields {
NVME_DEVICE_SELF_TEST_CDW10_STC_SHIFT = 0,
NVME_DEVICE_SELF_TEST_CDW10_STC_MASK = 0xf,
NVME_DIRECTIVE_CDW11_DOPER_SHIFT = 0,
NVME_DIRECTIVE_CDW11_DTYPE_SHIFT = 8,
NVME_DIRECTIVE_CDW11_DPSEC_SHIFT = 16,
NVME_DIRECTIVE_CDW11_DOPER_MASK = 0xff,
NVME_DIRECTIVE_CDW11_DTYPE_MASK = 0xff,
NVME_DIRECTIVE_CDW11_DPSEC_MASK = 0xffff,
NVME_DIRECTIVE_SEND_IDENTIFY_CDW12_ENDIR_SHIFT = 0,
NVME_DIRECTIVE_SEND_IDENTIFY_CDW12_DTYPE_SHIFT = 1,
NVME_DIRECTIVE_SEND_IDENTIFY_CDW12_ENDIR_MASK = 0x1,
NVME_DIRECTIVE_SEND_IDENTIFY_CDW12_DTYPE_MASK = 0x1,
NVME_FW_COMMIT_CDW10_FS_SHIFT = 0,
NVME_FW_COMMIT_CDW10_CA_SHIFT = 3,
NVME_FW_COMMIT_CDW10_BPID_SHIFT = 31,
NVME_FW_COMMIT_CDW10_FS_MASK = 0x7,
NVME_FW_COMMIT_CDW10_CA_MASK = 0x7,
NVME_FW_COMMIT_CDW10_BPID_MASK = 0x1,
NVME_GET_FEATURES_CDW10_SEL_SHIFT = 8,
NVME_GET_FEATURES_CDW10_SEL_MASK = 0x7,
NVME_SET_FEATURES_CDW10_SAVE_SHIFT = 31,
NVME_SET_FEATURES_CDW10_SAVE_MASK = 0x1,
NVME_FEATURES_CDW10_FID_SHIFT = 0,
NVME_FEATURES_CDW14_UUID_SHIFT = 0,
NVME_FEATURES_CDW10_FID_MASK = 0xff,
NVME_FEATURES_CDW14_UUID_MASK = 0x7f,
NVME_LOG_CDW10_LID_SHIFT = 0,
NVME_LOG_CDW10_LSP_SHIFT = 8,
NVME_LOG_CDW10_RAE_SHIFT = 15,
NVME_LOG_CDW10_NUMDL_SHIFT = 16,
NVME_LOG_CDW11_NUMDU_SHIFT = 0,
NVME_LOG_CDW11_LSI_SHIFT = 16,
NVME_LOG_CDW14_UUID_SHIFT = 0,
NVME_LOG_CDW14_CSI_SHIFT = 24,
NVME_LOG_CDW14_OT_SHIFT = 23,
NVME_LOG_CDW10_LID_MASK = 0xff,
NVME_LOG_CDW10_LSP_MASK = 0x7f,
NVME_LOG_CDW10_RAE_MASK = 0x1,
NVME_LOG_CDW10_NUMDL_MASK = 0xffff,
NVME_LOG_CDW11_NUMDU_MASK = 0xffff,
NVME_LOG_CDW11_LSI_MASK = 0xffff,
NVME_LOG_CDW14_UUID_MASK = 0x7f,
NVME_LOG_CDW14_CSI_MASK = 0xff,
NVME_LOG_CDW14_OT_MASK = 0x1,
NVME_IDENTIFY_CDW10_CNS_SHIFT = 0,
NVME_IDENTIFY_CDW10_CNTID_SHIFT = 16,
NVME_IDENTIFY_CDW11_CNSSPECID_SHIFT = 0,
NVME_IDENTIFY_CDW14_UUID_SHIFT = 0,
NVME_IDENTIFY_CDW11_CSI_SHIFT = 24,
NVME_IDENTIFY_CDW10_CNS_MASK = 0xff,
NVME_IDENTIFY_CDW10_CNTID_MASK = 0xffff,
NVME_IDENTIFY_CDW11_CNSSPECID_MASK = 0xffff,
NVME_IDENTIFY_CDW14_UUID_MASK = 0x7f,
NVME_IDENTIFY_CDW11_CSI_MASK = 0xff,
NVME_NAMESPACE_ATTACH_CDW10_SEL_SHIFT = 0,
NVME_NAMESPACE_ATTACH_CDW10_SEL_MASK = 0xf,
NVME_NAMESPACE_MGMT_CDW10_SEL_SHIFT = 0,
NVME_NAMESPACE_MGMT_CDW10_SEL_MASK = 0xf,
NVME_NAMESPACE_MGMT_CDW11_CSI_SHIFT = 24,
NVME_NAMESPACE_MGMT_CDW11_CSI_MASK = 0xff,
NVME_VIRT_MGMT_CDW10_ACT_SHIFT = 0,
NVME_VIRT_MGMT_CDW10_RT_SHIFT = 8,
NVME_VIRT_MGMT_CDW10_CNTLID_SHIFT = 16,
NVME_VIRT_MGMT_CDW11_NR_SHIFT = 0,
NVME_VIRT_MGMT_CDW10_ACT_MASK = 0xf,
NVME_VIRT_MGMT_CDW10_RT_MASK = 0x7,
NVME_VIRT_MGMT_CDW10_CNTLID_MASK = 0xffff,
NVME_VIRT_MGMT_CDW11_NR_MASK = 0xffff,
NVME_FORMAT_CDW10_LBAF_SHIFT = 0,
NVME_FORMAT_CDW10_MSET_SHIFT = 4,
NVME_FORMAT_CDW10_PI_SHIFT = 5,
NVME_FORMAT_CDW10_PIL_SHIFT = 8,
NVME_FORMAT_CDW10_SES_SHIFT = 9,
NVME_FORMAT_CDW10_LBAFU_SHIFT = 12,
NVME_FORMAT_CDW10_LBAF_MASK = 0xf,
NVME_FORMAT_CDW10_MSET_MASK = 0x1,
NVME_FORMAT_CDW10_PI_MASK = 0x7,
NVME_FORMAT_CDW10_PIL_MASK = 0x1,
NVME_FORMAT_CDW10_SES_MASK = 0x7,
NVME_FORMAT_CDW10_LBAFU_MASK = 0x3,
NVME_SANITIZE_CDW10_SANACT_SHIFT = 0,
NVME_SANITIZE_CDW10_AUSE_SHIFT = 3,
NVME_SANITIZE_CDW10_OWPASS_SHIFT = 4,
NVME_SANITIZE_CDW10_OIPBP_SHIFT = 8,
NVME_SANITIZE_CDW10_NODAS_SHIFT = 9,
NVME_SANITIZE_CDW10_EMVS_SHIFT = 10,
NVME_SANITIZE_CDW10_SANACT_MASK = 0x7,
NVME_SANITIZE_CDW10_AUSE_MASK = 0x1,
NVME_SANITIZE_CDW10_OWPASS_MASK = 0xf,
NVME_SANITIZE_CDW10_OIPBP_MASK = 0x1,
NVME_SANITIZE_CDW10_NODAS_MASK = 0x1,
NVME_SANITIZE_CDW10_EMVS_MASK = 0x1,
NVME_SECURITY_NSSF_SHIFT = 0,
NVME_SECURITY_SPSP0_SHIFT = 8,
NVME_SECURITY_SPSP1_SHIFT = 16,
NVME_SECURITY_SECP_SHIFT = 24,
NVME_SECURITY_NSSF_MASK = 0xff,
NVME_SECURITY_SPSP0_MASK = 0xff,
NVME_SECURITY_SPSP1_MASK = 0xff,
NVME_SECURITY_SECP_MASK = 0xffff,
NVME_GET_LBA_STATUS_CDW13_RL_SHIFT = 0,
NVME_GET_LBA_STATUS_CDW13_ATYPE_SHIFT = 24,
NVME_GET_LBA_STATUS_CDW13_RL_MASK = 0xffff,
NVME_GET_LBA_STATUS_CDW13_ATYPE_MASK = 0xff,
NVME_ZNS_MGMT_SEND_ZSASO_SHIFT = 9,
NVME_ZNS_MGMT_SEND_ZSASO_MASK = 0x1,
NVME_ZNS_MGMT_SEND_SEL_SHIFT = 8,
NVME_ZNS_MGMT_SEND_SEL_MASK = 0x1,
NVME_ZNS_MGMT_SEND_ZSA_SHIFT = 0,
NVME_ZNS_MGMT_SEND_ZSA_MASK = 0xff,
NVME_ZNS_MGMT_RECV_ZRA_SHIFT = 0,
NVME_ZNS_MGMT_RECV_ZRA_MASK = 0xff,
NVME_ZNS_MGMT_RECV_ZRASF_SHIFT = 8,
NVME_ZNS_MGMT_RECV_ZRASF_MASK = 0xff,
NVME_ZNS_MGMT_RECV_ZRAS_FEAT_SHIFT = 16,
NVME_ZNS_MGMT_RECV_ZRAS_FEAT_MASK = 0x1,
NVME_DIM_TAS_SHIFT = 0,
NVME_DIM_TAS_MASK = 0xF,
NVME_ABORT_CDW10_SQID_SHIFT = 0,
NVME_ABORT_CDW10_CID_SHIFT = 16,
NVME_ABORT_CDW10_SQID_MASK = 0xff,
NVME_ABORT_CDW10_CID_MASK = 0xff,
};
enum nvme_cqe_dword_fields {
NVME_ABORT_CQEDW0_IANP_SHIFT = 0,
NVME_ABORT_CQEDW0_IANP_MASK = 0x1,
};
/**
* nvme_submit_admin_passthru64() - Submit a 64-bit nvme passthrough admin
* command
* @fd: File descriptor of nvme device
* @cmd: The nvme admin command to send
* @result: Optional field to return the result from the CQE DW0-1
*
* Uses NVME_IOCTL_ADMIN64_CMD for the ioctl request.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
int nvme_submit_admin_passthru64(int fd, struct nvme_passthru_cmd64 *cmd,
__u64 *result);
/**
* nvme_admin_passthru64() - Submit a 64-bit nvme passthrough command
* @fd: File descriptor of nvme device
* @opcode: The nvme io command to send
* @flags: NVMe command flags (not used)
* @rsvd: Reserved for future use
* @nsid: Namespace identifier
* @cdw2: Command dword 2
* @cdw3: Command dword 3
* @cdw10: Command dword 10
* @cdw11: Command dword 11
* @cdw12: Command dword 12
* @cdw13: Command dword 13
* @cdw14: Command dword 14
* @cdw15: Command dword 15
* @data_len: Length of the data transferred in this command in bytes
* @data: Pointer to user address of the data buffer
* @metadata_len:Length of metadata transferred in this command
* @metadata: Pointer to user address of the metadata buffer
* @timeout_ms: How long the kernel waits for the command to complete
* @result: Optional field to return the result from the CQE dword 0
*
* Parameterized form of nvme_submit_admin_passthru64(). This sets up and
* submits a &struct nvme_passthru_cmd64.
*
* Known values for @opcode are defined in &enum nvme_admin_opcode.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
int nvme_admin_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd,
__u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11,
__u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15,
__u32 data_len, void *data, __u32 metadata_len, void *metadata,
__u32 timeout_ms, __u64 *result);
/**
* nvme_submit_admin_passthru() - Submit an nvme passthrough admin command
* @fd: File descriptor of nvme device
* @cmd: The nvme admin command to send
* @result: Optional field to return the result from the CQE DW0
*
* Uses NVME_IOCTL_ADMIN_CMD for the ioctl request.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
int nvme_submit_admin_passthru(int fd, struct nvme_passthru_cmd *cmd,
__u32 *result);
/**
* nvme_admin_passthru() - Submit an nvme passthrough command
* @fd: File descriptor of nvme device
* @opcode: The nvme io command to send
* @flags: NVMe command flags (not used)
* @rsvd: Reserved for future use
* @nsid: Namespace identifier
* @cdw2: Command dword 2
* @cdw3: Command dword 3
* @cdw10: Command dword 10
* @cdw11: Command dword 11
* @cdw12: Command dword 12
* @cdw13: Command dword 13
* @cdw14: Command dword 14
* @cdw15: Command dword 15
* @data_len: Length of the data transferred in this command in bytes
* @data: Pointer to user address of the data buffer
* @metadata_len:Length of metadata transferred in this command
* @metadata: Pointer to user address of the metadata buffer
* @timeout_ms: How long the kernel waits for the command to complete
* @result: Optional field to return the result from the CQE dword 0
*
* Parameterized form of nvme_submit_admin_passthru(). This sets up and
* submits a &struct nvme_passthru_cmd.
*
* Known values for @opcode are defined in &enum nvme_admin_opcode.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
int nvme_admin_passthru(int fd, __u8 opcode, __u8 flags, __u16 rsvd,
__u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11,
__u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15,
__u32 data_len, void *data, __u32 metadata_len, void *metadata,
__u32 timeout_ms, __u32 *result);
/**
* nvme_submit_io_passthru64() - Submit a 64-bit nvme passthrough command
* @fd: File descriptor of nvme device
* @cmd: The nvme io command to send
* @result: Optional field to return the result from the CQE DW0-1
*
* Uses NVME_IOCTL_IO64_CMD for the ioctl request.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
int nvme_submit_io_passthru64(int fd, struct nvme_passthru_cmd64 *cmd,
__u64 *result);
/**
* nvme_io_passthru64() - Submit an nvme io passthrough command
* @fd: File descriptor of nvme device
* @opcode: The nvme io command to send
* @flags: NVMe command flags (not used)
* @rsvd: Reserved for future use
* @nsid: Namespace identifier
* @cdw2: Command dword 2
* @cdw3: Command dword 3
* @cdw10: Command dword 10
* @cdw11: Command dword 11
* @cdw12: Command dword 12
* @cdw13: Command dword 13
* @cdw14: Command dword 14
* @cdw15: Command dword 15
* @data_len: Length of the data transferred in this command in bytes
* @data: Pointer to user address of the data buffer
* @metadata_len:Length of metadata transferred in this command
* @metadata: Pointer to user address of the metadata buffer
* @timeout_ms: How long the kernel waits for the command to complete
* @result: Optional field to return the result from the CQE dword 0
*
* Parameterized form of nvme_submit_io_passthru64(). This sets up and submits
* a &struct nvme_passthru_cmd64.
*
* Known values for @opcode are defined in &enum nvme_io_opcode.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
int nvme_io_passthru64(int fd, __u8 opcode, __u8 flags, __u16 rsvd,
__u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11,
__u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15,
__u32 data_len, void *data, __u32 metadata_len, void *metadata,
__u32 timeout_ms, __u64 *result);
/**
* nvme_submit_io_passthru() - Submit an nvme passthrough command
* @fd: File descriptor of nvme device
* @cmd: The nvme io command to send
* @result: Optional field to return the result from the CQE dword 0
* @result: Optional field to return the result from the CQE DW0
*
* Uses NVME_IOCTL_IO_CMD for the ioctl request.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
int nvme_submit_io_passthru(int fd, struct nvme_passthru_cmd *cmd,
__u32 *result);
/**
* nvme_io_passthru() - Submit an nvme io passthrough command
* @fd: File descriptor of nvme device
* @opcode: The nvme io command to send
* @flags: NVMe command flags (not used)
* @rsvd: Reserved for future use
* @nsid: Namespace identifier
* @cdw2: Command dword 2
* @cdw3: Command dword 3
* @cdw10: Command dword 10
* @cdw11: Command dword 11
* @cdw12: Command dword 12
* @cdw13: Command dword 13
* @cdw14: Command dword 14
* @cdw15: Command dword 15
* @data_len: Length of the data transferred in this command in bytes
* @data: Pointer to user address of the data buffer
* @metadata_len:Length of metadata transferred in this command
* @metadata: Pointer to user address of the metadata buffer
* @timeout_ms: How long the kernel waits for the command to complete
* @result: Optional field to return the result from the CQE dword 0
*
* Parameterized form of nvme_submit_io_passthru(). This sets up and submits
* a &struct nvme_passthru_cmd.
*
* Known values for @opcode are defined in &enum nvme_io_opcode.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
int nvme_io_passthru(int fd, __u8 opcode, __u8 flags, __u16 rsvd,
__u32 nsid, __u32 cdw2, __u32 cdw3, __u32 cdw10, __u32 cdw11,
__u32 cdw12, __u32 cdw13, __u32 cdw14, __u32 cdw15,
__u32 data_len, void *data, __u32 metadata_len, void *metadata,
__u32 timeout_ms, __u32 *result);
/**
* nvme_subsystem_reset() - Initiate a subsystem reset
* @fd: File descriptor of nvme device
*
* This should only be sent to controller handles, not to namespaces.
*
* Return: Zero if a subsystem reset was initiated or -1 with errno set
* otherwise.
*/
int nvme_subsystem_reset(int fd);
/**
* nvme_ctrl_reset() - Initiate a controller reset
* @fd: File descriptor of nvme device
*
* This should only be sent to controller handles, not to namespaces.
*
* Return: 0 if a reset was initiated or -1 with errno set otherwise.
*/
int nvme_ctrl_reset(int fd);
/**
* nvme_ns_rescan() - Initiate a controller rescan
* @fd: File descriptor of nvme device
*
* This should only be sent to controller handles, not to namespaces.
*
* Return: 0 if a rescan was initiated or -1 with errno set otherwise.
*/
int nvme_ns_rescan(int fd);
/**
* nvme_get_nsid() - Retrieve the NSID from a namespace file descriptor
* @fd: File descriptor of nvme namespace
* @nsid: User pointer to namespace id
*
* This should only be sent to namespace handles, not to controllers. The
* kernel's interface returns the nsid as the return value. This is unfortunate
* for many architectures that are incapable of allowing distinguishing a
* namespace id > 0x80000000 from a negative error number.
*
* Return: 0 if @nsid was set successfully or -1 with errno set otherwise.
*/
int nvme_get_nsid(int fd, __u32 *nsid);
/**
* nvme_identify() - Send the NVMe Identify command
* @args: &struct nvme_identify_args argument structure
*
* The Identify command returns a data buffer that describes information about
* the NVM subsystem, the controller or the namespace(s).
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
int nvme_identify(struct nvme_identify_args *args);
static inline int nvme_identify_cns_nsid(int fd, enum nvme_identify_cns cns,
__u32 nsid, void *data)
{
struct nvme_identify_args args = {
.result = NULL,
.data = data,
.args_size = sizeof(args),
.fd = fd,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.cns = cns,
.csi = NVME_CSI_NVM,
.nsid = nsid,
.cntid = NVME_CNTLID_NONE,
.cns_specific_id = NVME_CNSSPECID_NONE,
.uuidx = NVME_UUID_NONE,
};
return nvme_identify(&args);
}
/**
* nvme_identify_ctrl() - Retrieves nvme identify controller
* @fd: File descriptor of nvme device
* @id: User space destination address to transfer the data,
*
* Sends nvme identify with CNS value %NVME_IDENTIFY_CNS_CTRL.
*
* See &struct nvme_id_ctrl for details on the data returned.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_ctrl(int fd, struct nvme_id_ctrl *id)
{
return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_CTRL,
NVME_NSID_NONE, id);
}
/**
* nvme_identify_ns() - Retrieves nvme identify namespace
* @fd: File descriptor of nvme device
* @nsid: Namespace to identify
* @ns: User space destination address to transfer the data
*
* If the Namespace Identifier (NSID) field specifies an active NSID, then the
* Identify Namespace data structure is returned to the host for that specified
* namespace.
*
* If the controller supports the Namespace Management capability and the NSID
* field is set to %NVME_NSID_ALL, then the controller returns an Identify Namespace
* data structure that specifies capabilities that are common across namespaces
* for this controller.
*
* See &struct nvme_id_ns for details on the structure returned.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_ns(int fd, __u32 nsid, struct nvme_id_ns *ns)
{
return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_NS, nsid, ns);
}
/**
* nvme_identify_allocated_ns() - Same as nvme_identify_ns, but only for
* allocated namespaces
* @fd: File descriptor of nvme device
* @nsid: Namespace to identify
* @ns: User space destination address to transfer the data
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_allocated_ns(int fd, __u32 nsid,
struct nvme_id_ns *ns)
{
return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_ALLOCATED_NS,
nsid, ns);
}
/**
* nvme_identify_active_ns_list() - Retrieves active namespaces id list
* @fd: File descriptor of nvme device
* @nsid: Return namespaces greater than this identifier
* @list: User space destination address to transfer the data
*
* A list of 1024 namespace IDs is returned to the host containing NSIDs in
* increasing order that are greater than the value specified in the Namespace
* Identifier (nsid) field of the command.
*
* See &struct nvme_ns_list for the definition of the returned structure.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_active_ns_list(int fd, __u32 nsid,
struct nvme_ns_list *list)
{
return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_NS_ACTIVE_LIST,
nsid, list);
}
/**
* nvme_identify_allocated_ns_list() - Retrieves allocated namespace id list
* @fd: File descriptor of nvme device
* @nsid: Return namespaces greater than this identifier
* @list: User space destination address to transfer the data
*
* A list of 1024 namespace IDs is returned to the host containing NSIDs in
* increasing order that are greater than the value specified in the Namespace
* Identifier (nsid) field of the command.
*
* See &struct nvme_ns_list for the definition of the returned structure.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_allocated_ns_list(int fd, __u32 nsid,
struct nvme_ns_list *list)
{
return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_ALLOCATED_NS_LIST,
nsid, list);
}
/**
* nvme_identify_ctrl_list() - Retrieves identify controller list
* @fd: File descriptor of nvme device
* @cntid: Starting CNTLID to return in the list
* @cntlist: User space destination address to transfer the data
*
* Up to 2047 controller identifiers is returned containing a controller
* identifier greater than or equal to the controller identifier specified in
* @cntid.
*
* See &struct nvme_ctrl_list for a definition of the structure returned.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_ctrl_list(int fd, __u16 cntid,
struct nvme_ctrl_list *cntlist)
{
struct nvme_identify_args args = {
.result = NULL,
.data = cntlist,
.args_size = sizeof(args),
.fd = fd,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.cns = NVME_IDENTIFY_CNS_CTRL_LIST,
.csi = NVME_CSI_NVM,
.nsid = NVME_NSID_NONE,
.cntid = cntid,
.cns_specific_id = NVME_CNSSPECID_NONE,
.uuidx = NVME_UUID_NONE,
};
return nvme_identify(&args);
}
/**
* nvme_identify_nsid_ctrl_list() - Retrieves controller list attached to an nsid
* @fd: File descriptor of nvme device
* @nsid: Return controllers that are attached to this nsid
* @cntid: Starting CNTLID to return in the list
* @cntlist: User space destination address to transfer the data
*
* Up to 2047 controller identifiers are returned containing a controller
* identifier greater than or equal to the controller identifier specified in
* @cntid attached to @nsid.
*
* See &struct nvme_ctrl_list for a definition of the structure returned.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1
*/
static inline int nvme_identify_nsid_ctrl_list(int fd, __u32 nsid, __u16 cntid,
struct nvme_ctrl_list *cntlist)
{
struct nvme_identify_args args = {
.result = NULL,
.data = cntlist,
.args_size = sizeof(args),
.fd = fd,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.cns = NVME_IDENTIFY_CNS_NS_CTRL_LIST,
.csi = NVME_CSI_NVM,
.nsid = nsid,
.cntid = cntid,
.cns_specific_id = NVME_CNSSPECID_NONE,
.uuidx = NVME_UUID_NONE,
};
return nvme_identify(&args);
}
/**
* nvme_identify_ns_descs() - Retrieves namespace descriptor list
* @fd: File descriptor of nvme device
* @nsid: The namespace id to retrieve descriptors
* @descs: User space destination address to transfer the data
*
* A list of Namespace Identification Descriptor structures is returned to the
* host for the namespace specified in the Namespace Identifier (NSID) field if
* it is an active NSID.
*
* The data returned is in the form of an array of 'struct nvme_ns_id_desc'.
*
* See &struct nvme_ns_id_desc for the definition of the returned structure.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_ns_descs(int fd, __u32 nsid,
struct nvme_ns_id_desc *descs)
{
return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_NS_DESC_LIST,
nsid, descs);
}
/**
* nvme_identify_nvmset_list() - Retrieves NVM Set List
* @fd: File descriptor of nvme device
* @nvmsetid: NVM Set Identifier
* @nvmset: User space destination address to transfer the data
*
* Retrieves an NVM Set List, &struct nvme_id_nvmset_list. The data structure
* is an ordered list by NVM Set Identifier, starting with the first NVM Set
* Identifier supported by the NVM subsystem that is equal to or greater than
* the NVM Set Identifier.
*
* See &struct nvme_id_nvmset_list for the definition of the returned structure.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_nvmset_list(int fd, __u16 nvmsetid,
struct nvme_id_nvmset_list *nvmset)
{
struct nvme_identify_args args = {
.result = NULL,
.data = nvmset,
.args_size = sizeof(args),
.fd = fd,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.cns = NVME_IDENTIFY_CNS_NVMSET_LIST,
.csi = NVME_CSI_NVM,
.nsid = NVME_NSID_NONE,
.cntid = NVME_CNTLID_NONE,
.cns_specific_id = nvmsetid,
.uuidx = NVME_UUID_NONE,
};
return nvme_identify(&args);
}
/**
* nvme_identify_primary_ctrl() - Retrieve NVMe Primary Controller
* identification
* @fd: File descriptor of nvme device
* @cntid: Return controllers starting at this identifier
* @cap: User space destination buffer address to transfer the data
*
* See &struct nvme_primary_ctrl_cap for the definition of the returned structure, @cap.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_primary_ctrl(int fd, __u16 cntid,
struct nvme_primary_ctrl_cap *cap)
{
struct nvme_identify_args args = {
.result = NULL,
.data = cap,
.args_size = sizeof(args),
.fd = fd,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.cns = NVME_IDENTIFY_CNS_PRIMARY_CTRL_CAP,
.csi = NVME_CSI_NVM,
.nsid = NVME_NSID_NONE,
.cntid = cntid,
.cns_specific_id = NVME_CNSSPECID_NONE,
.uuidx = NVME_UUID_NONE,
};
return nvme_identify(&args);
}
/**
* nvme_identify_secondary_ctrl_list() - Retrieves secondary controller list
* @fd: File descriptor of nvme device
* @cntid: Return controllers starting at this identifier
* @sc_list: User space destination address to transfer the data
*
* A Secondary Controller List is returned to the host for up to 127 secondary
* controllers associated with the primary controller processing this command.
* The list contains entries for controller identifiers greater than or equal
* to the value specified in the Controller Identifier (cntid).
*
* See &struct nvme_secondary_ctrls_list for a definition of the returned
* structure.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_secondary_ctrl_list(int fd,
__u16 cntid, struct nvme_secondary_ctrl_list *sc_list)
{
struct nvme_identify_args args = {
.result = NULL,
.data = sc_list,
.args_size = sizeof(args),
.fd = fd,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.cns = NVME_IDENTIFY_CNS_SECONDARY_CTRL_LIST,
.csi = NVME_CSI_NVM,
.nsid = NVME_NSID_NONE,
.cntid = cntid,
.cns_specific_id = NVME_CNSSPECID_NONE,
.uuidx = NVME_UUID_NONE,
};
return nvme_identify(&args);
}
/**
* nvme_identify_ns_granularity() - Retrieves namespace granularity
* identification
* @fd: File descriptor of nvme device
* @gr_list: User space destination address to transfer the data
*
* If the controller supports reporting of Namespace Granularity, then a
* Namespace Granularity List is returned to the host for up to sixteen
* namespace granularity descriptors
*
* See &struct nvme_id_ns_granularity_list for the definition of the returned
* structure.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_ns_granularity(int fd,
struct nvme_id_ns_granularity_list *gr_list)
{
return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_NS_GRANULARITY,
NVME_NSID_NONE, gr_list);
}
/**
* nvme_identify_uuid() - Retrieves device's UUIDs
* @fd: File descriptor of nvme device
* @uuid_list: User space destination address to transfer the data
*
* Each UUID List entry is either 0h, the NVMe Invalid UUID, or a valid UUID.
* Valid UUIDs are those which are non-zero and are not the NVMe Invalid UUID.
*
* See &struct nvme_id_uuid_list for the definition of the returned structure.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_uuid(int fd, struct nvme_id_uuid_list *uuid_list)
{
return nvme_identify_cns_nsid(fd, NVME_IDENTIFY_CNS_UUID_LIST,
NVME_NSID_NONE, uuid_list);
}
/**
* nvme_identify_ns_csi() - I/O command set specific identify namespace data
* @fd: File descriptor of nvme device
* @nsid: Namespace to identify
* @uuidx: UUID Index for differentiating vendor specific encoding
* @csi: Command Set Identifier
* @data: User space destination address to transfer the data
*
* An I/O Command Set specific Identify Namespace data structure is returned
* for the namespace specified in @nsid.
*
* Return: The nvme command status if a response was received (see
* &enum nvme_status_field) or -1 with errno set otherwise.
*/
static inline int nvme_identify_ns_csi(int fd, __u32 nsid, __u8 uuidx,
enum nvme_csi csi, void *data)
{
struct nvme_identify_args args = {
.result = NULL,
.data = data,
.args_size = sizeof(args),
.fd = fd,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
.cns = NVME_IDENTIFY_CNS_CSI_NS,
.csi = csi,
.nsid = nsid,
.cntid = NVME_CNTLID_NONE,
.cns_specific_id = NVME_CNSSPECID_NONE,
.uuidx = uuidx,
};
return nvme_identify(&args);
}
/**
* nvme_identify_ctrl_csi() - I/O command set specific Identify Controller data