1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Definitions for the NVM Express interface
4 * Copyright (c) 2011-2014, Intel Corporation.
10 #include <linux/bits.h>
11 #include <linux/types.h>
12 #include <linux/uuid.h>
14 /* NQN names in commands fields specified one size */
15 #define NVMF_NQN_FIELD_LEN 256
17 /* However the max length of a qualified name is another size */
18 #define NVMF_NQN_SIZE 223
20 #define NVMF_TRSVCID_SIZE 32
21 #define NVMF_TRADDR_SIZE 256
22 #define NVMF_TSAS_SIZE 256
24 #define NVME_DISC_SUBSYS_NAME "nqn.2014-08.org.nvmexpress.discovery"
26 #define NVME_NSID_ALL 0xffffffff
28 /* Special NSSR value, 'NVMe' */
29 #define NVME_SUBSYS_RESET 0x4E564D65
31 enum nvme_subsys_type {
32 /* Referral to another discovery type target subsystem */
35 /* NVME type target subsystem */
38 /* Current discovery type target subsystem */
43 NVME_CTRL_IO = 1, /* I/O controller */
44 NVME_CTRL_DISC = 2, /* Discovery controller */
45 NVME_CTRL_ADMIN = 3, /* Administrative controller */
49 NVME_DCTYPE_NOT_REPORTED = 0,
50 NVME_DCTYPE_DDC = 1, /* Direct Discovery Controller */
51 NVME_DCTYPE_CDC = 2, /* Central Discovery Controller */
54 /* Address Family codes for Discovery Log Page entry ADRFAM field */
56 NVMF_ADDR_FAMILY_PCI = 0, /* PCIe */
57 NVMF_ADDR_FAMILY_IP4 = 1, /* IP4 */
58 NVMF_ADDR_FAMILY_IP6 = 2, /* IP6 */
59 NVMF_ADDR_FAMILY_IB = 3, /* InfiniBand */
60 NVMF_ADDR_FAMILY_FC = 4, /* Fibre Channel */
61 NVMF_ADDR_FAMILY_LOOP = 254, /* Reserved for host usage */
65 /* Transport Type codes for Discovery Log Page entry TRTYPE field */
67 NVMF_TRTYPE_PCI = 0, /* PCI */
68 NVMF_TRTYPE_RDMA = 1, /* RDMA */
69 NVMF_TRTYPE_FC = 2, /* Fibre Channel */
70 NVMF_TRTYPE_TCP = 3, /* TCP/IP */
71 NVMF_TRTYPE_LOOP = 254, /* Reserved for host usage */
75 /* Transport Requirements codes for Discovery Log Page entry TREQ field */
77 NVMF_TREQ_NOT_SPECIFIED = 0, /* Not specified */
78 NVMF_TREQ_REQUIRED = 1, /* Required */
79 NVMF_TREQ_NOT_REQUIRED = 2, /* Not Required */
80 #define NVME_TREQ_SECURE_CHANNEL_MASK \
81 (NVMF_TREQ_REQUIRED | NVMF_TREQ_NOT_REQUIRED)
83 NVMF_TREQ_DISABLE_SQFLOW = (1 << 2), /* Supports SQ flow control disable */
86 /* RDMA QP Service Type codes for Discovery Log Page entry TSAS
90 NVMF_RDMA_QPTYPE_CONNECTED = 1, /* Reliable Connected */
91 NVMF_RDMA_QPTYPE_DATAGRAM = 2, /* Reliable Datagram */
92 NVMF_RDMA_QPTYPE_INVALID = 0xff,
95 /* RDMA Provider Type codes for Discovery Log Page entry TSAS
99 NVMF_RDMA_PRTYPE_NOT_SPECIFIED = 1, /* No Provider Specified */
100 NVMF_RDMA_PRTYPE_IB = 2, /* InfiniBand */
101 NVMF_RDMA_PRTYPE_ROCE = 3, /* InfiniBand RoCE */
102 NVMF_RDMA_PRTYPE_ROCEV2 = 4, /* InfiniBand RoCEV2 */
103 NVMF_RDMA_PRTYPE_IWARP = 5, /* IWARP */
106 /* RDMA Connection Management Service Type codes for Discovery Log Page
107 * entry TSAS RDMA_CMS field
110 NVMF_RDMA_CMS_RDMA_CM = 1, /* Sockets based endpoint addressing */
113 /* TSAS SECTYPE for TCP transport */
115 NVMF_TCP_SECTYPE_NONE = 0, /* No Security */
116 NVMF_TCP_SECTYPE_TLS12 = 1, /* TLSv1.2, NVMe-oF 1.1 and NVMe-TCP 3.6.1.1 */
117 NVMF_TCP_SECTYPE_TLS13 = 2, /* TLSv1.3, NVMe-oF 1.1 and NVMe-TCP 3.6.1.1 */
118 NVMF_TCP_SECTYPE_INVALID = 0xff,
121 #define NVME_AQ_DEPTH 32
122 #define NVME_NR_AEN_COMMANDS 1
123 #define NVME_AQ_BLK_MQ_DEPTH (NVME_AQ_DEPTH - NVME_NR_AEN_COMMANDS)
126 * Subtract one to leave an empty queue entry for 'Full Queue' condition. See
127 * NVM-Express 1.2 specification, section 4.1.2.
129 #define NVME_AQ_MQ_TAG_DEPTH (NVME_AQ_BLK_MQ_DEPTH - 1)
132 NVME_REG_CAP = 0x0000, /* Controller Capabilities */
133 NVME_REG_VS = 0x0008, /* Version */
134 NVME_REG_INTMS = 0x000c, /* Interrupt Mask Set */
135 NVME_REG_INTMC = 0x0010, /* Interrupt Mask Clear */
136 NVME_REG_CC = 0x0014, /* Controller Configuration */
137 NVME_REG_CSTS = 0x001c, /* Controller Status */
138 NVME_REG_NSSR = 0x0020, /* NVM Subsystem Reset */
139 NVME_REG_AQA = 0x0024, /* Admin Queue Attributes */
140 NVME_REG_ASQ = 0x0028, /* Admin SQ Base Address */
141 NVME_REG_ACQ = 0x0030, /* Admin CQ Base Address */
142 NVME_REG_CMBLOC = 0x0038, /* Controller Memory Buffer Location */
143 NVME_REG_CMBSZ = 0x003c, /* Controller Memory Buffer Size */
144 NVME_REG_BPINFO = 0x0040, /* Boot Partition Information */
145 NVME_REG_BPRSEL = 0x0044, /* Boot Partition Read Select */
146 NVME_REG_BPMBL = 0x0048, /* Boot Partition Memory Buffer
149 NVME_REG_CMBMSC = 0x0050, /* Controller Memory Buffer Memory
152 NVME_REG_CRTO = 0x0068, /* Controller Ready Timeouts */
153 NVME_REG_PMRCAP = 0x0e00, /* Persistent Memory Capabilities */
154 NVME_REG_PMRCTL = 0x0e04, /* Persistent Memory Region Control */
155 NVME_REG_PMRSTS = 0x0e08, /* Persistent Memory Region Status */
156 NVME_REG_PMREBS = 0x0e0c, /* Persistent Memory Region Elasticity
159 NVME_REG_PMRSWTP = 0x0e10, /* Persistent Memory Region Sustained
162 NVME_REG_DBS = 0x1000, /* SQ 0 Tail Doorbell */
165 #define NVME_CAP_MQES(cap) ((cap) & 0xffff)
166 #define NVME_CAP_TIMEOUT(cap) (((cap) >> 24) & 0xff)
167 #define NVME_CAP_STRIDE(cap) (((cap) >> 32) & 0xf)
168 #define NVME_CAP_NSSRC(cap) (((cap) >> 36) & 0x1)
169 #define NVME_CAP_CSS(cap) (((cap) >> 37) & 0xff)
170 #define NVME_CAP_MPSMIN(cap) (((cap) >> 48) & 0xf)
171 #define NVME_CAP_MPSMAX(cap) (((cap) >> 52) & 0xf)
172 #define NVME_CAP_CMBS(cap) (((cap) >> 57) & 0x1)
174 #define NVME_CMB_BIR(cmbloc) ((cmbloc) & 0x7)
175 #define NVME_CMB_OFST(cmbloc) (((cmbloc) >> 12) & 0xfffff)
177 #define NVME_CRTO_CRIMT(crto) ((crto) >> 16)
178 #define NVME_CRTO_CRWMT(crto) ((crto) & 0xffff)
181 NVME_CMBSZ_SQS = 1 << 0,
182 NVME_CMBSZ_CQS = 1 << 1,
183 NVME_CMBSZ_LISTS = 1 << 2,
184 NVME_CMBSZ_RDS = 1 << 3,
185 NVME_CMBSZ_WDS = 1 << 4,
187 NVME_CMBSZ_SZ_SHIFT = 12,
188 NVME_CMBSZ_SZ_MASK = 0xfffff,
190 NVME_CMBSZ_SZU_SHIFT = 8,
191 NVME_CMBSZ_SZU_MASK = 0xf,
195 * Submission and Completion Queue Entry Sizes for the NVM command set.
196 * (In bytes and specified as a power of two (2^n)).
198 #define NVME_ADM_SQES 6
199 #define NVME_NVM_IOSQES 6
200 #define NVME_NVM_IOCQES 4
203 * Controller Configuration (CC) register (Offset 14h)
206 /* Enable (EN): bit 0 */
207 NVME_CC_ENABLE = 1 << 0,
208 NVME_CC_EN_SHIFT = 0,
210 /* Bits 03:01 are reserved (NVMe Base Specification rev 2.1) */
212 /* I/O Command Set Selected (CSS): bits 06:04 */
213 NVME_CC_CSS_SHIFT = 4,
214 NVME_CC_CSS_MASK = 7 << NVME_CC_CSS_SHIFT,
215 NVME_CC_CSS_NVM = 0 << NVME_CC_CSS_SHIFT,
216 NVME_CC_CSS_CSI = 6 << NVME_CC_CSS_SHIFT,
218 /* Memory Page Size (MPS): bits 10:07 */
219 NVME_CC_MPS_SHIFT = 7,
220 NVME_CC_MPS_MASK = 0xf << NVME_CC_MPS_SHIFT,
222 /* Arbitration Mechanism Selected (AMS): bits 13:11 */
223 NVME_CC_AMS_SHIFT = 11,
224 NVME_CC_AMS_MASK = 7 << NVME_CC_AMS_SHIFT,
225 NVME_CC_AMS_RR = 0 << NVME_CC_AMS_SHIFT,
226 NVME_CC_AMS_WRRU = 1 << NVME_CC_AMS_SHIFT,
227 NVME_CC_AMS_VS = 7 << NVME_CC_AMS_SHIFT,
229 /* Shutdown Notification (SHN): bits 15:14 */
230 NVME_CC_SHN_SHIFT = 14,
231 NVME_CC_SHN_MASK = 3 << NVME_CC_SHN_SHIFT,
232 NVME_CC_SHN_NONE = 0 << NVME_CC_SHN_SHIFT,
233 NVME_CC_SHN_NORMAL = 1 << NVME_CC_SHN_SHIFT,
234 NVME_CC_SHN_ABRUPT = 2 << NVME_CC_SHN_SHIFT,
236 /* I/O Submission Queue Entry Size (IOSQES): bits 19:16 */
237 NVME_CC_IOSQES_SHIFT = 16,
238 NVME_CC_IOSQES_MASK = 0xf << NVME_CC_IOSQES_SHIFT,
239 NVME_CC_IOSQES = NVME_NVM_IOSQES << NVME_CC_IOSQES_SHIFT,
241 /* I/O Completion Queue Entry Size (IOCQES): bits 23:20 */
242 NVME_CC_IOCQES_SHIFT = 20,
243 NVME_CC_IOCQES_MASK = 0xf << NVME_CC_IOCQES_SHIFT,
244 NVME_CC_IOCQES = NVME_NVM_IOCQES << NVME_CC_IOCQES_SHIFT,
246 /* Controller Ready Independent of Media Enable (CRIME): bit 24 */
247 NVME_CC_CRIME = 1 << 24,
249 /* Bits 25:31 are reserved (NVMe Base Specification rev 2.1) */
253 NVME_CSTS_RDY = 1 << 0,
254 NVME_CSTS_CFS = 1 << 1,
255 NVME_CSTS_NSSRO = 1 << 4,
256 NVME_CSTS_PP = 1 << 5,
257 NVME_CSTS_SHST_NORMAL = 0 << 2,
258 NVME_CSTS_SHST_OCCUR = 1 << 2,
259 NVME_CSTS_SHST_CMPLT = 2 << 2,
260 NVME_CSTS_SHST_MASK = 3 << 2,
264 NVME_CMBMSC_CRE = 1 << 0,
265 NVME_CMBMSC_CMSE = 1 << 1,
269 NVME_CAP_CSS_NVM = 1 << 0,
270 NVME_CAP_CSS_CSI = 1 << 6,
274 NVME_CAP_CRMS_CRWMS = 1ULL << 59,
275 NVME_CAP_CRMS_CRIMS = 1ULL << 60,
278 struct nvme_id_power_state {
279 __le16 max_power; /* centiwatts */
282 __le32 entry_lat; /* microseconds */
283 __le32 exit_lat; /* microseconds */
292 __u8 active_work_scale;
297 NVME_PS_FLAGS_MAX_POWER_SCALE = 1 << 0,
298 NVME_PS_FLAGS_NON_OP_STATE = 1 << 1,
301 enum nvme_ctrl_attr {
302 NVME_CTRL_ATTR_HID_128_BIT = (1 << 0),
303 NVME_CTRL_ATTR_TBKAS = (1 << 6),
304 NVME_CTRL_ATTR_ELBAS = (1 << 15),
305 NVME_CTRL_ATTR_RHII = (1 << 18),
306 NVME_CTRL_ATTR_FDPS = (1 << 19),
309 struct nvme_id_ctrl {
393 struct nvme_id_power_state psd[32];
398 NVME_CTRL_CMIC_MULTI_PORT = 1 << 0,
399 NVME_CTRL_CMIC_MULTI_CTRL = 1 << 1,
400 NVME_CTRL_CMIC_ANA = 1 << 3,
401 NVME_CTRL_ONCS_COMPARE = 1 << 0,
402 NVME_CTRL_ONCS_WRITE_UNCORRECTABLE = 1 << 1,
403 NVME_CTRL_ONCS_DSM = 1 << 2,
404 NVME_CTRL_ONCS_WRITE_ZEROES = 1 << 3,
405 NVME_CTRL_ONCS_RESERVATIONS = 1 << 5,
406 NVME_CTRL_ONCS_TIMESTAMP = 1 << 6,
407 NVME_CTRL_VWC_PRESENT = 1 << 0,
408 NVME_CTRL_OACS_SEC_SUPP = 1 << 0,
409 NVME_CTRL_OACS_NS_MNGT_SUPP = 1 << 3,
410 NVME_CTRL_OACS_DIRECTIVES = 1 << 5,
411 NVME_CTRL_OACS_DBBUF_SUPP = 1 << 8,
412 NVME_CTRL_LPA_CMD_EFFECTS_LOG = 1 << 1,
413 NVME_CTRL_CTRATT_128_ID = 1 << 0,
414 NVME_CTRL_CTRATT_NON_OP_PSP = 1 << 1,
415 NVME_CTRL_CTRATT_NVM_SETS = 1 << 2,
416 NVME_CTRL_CTRATT_READ_RECV_LVLS = 1 << 3,
417 NVME_CTRL_CTRATT_ENDURANCE_GROUPS = 1 << 4,
418 NVME_CTRL_CTRATT_PREDICTABLE_LAT = 1 << 5,
419 NVME_CTRL_CTRATT_NAMESPACE_GRANULARITY = 1 << 7,
420 NVME_CTRL_CTRATT_UUID_LIST = 1 << 9,
421 NVME_CTRL_SGLS_BYTE_ALIGNED = 1,
422 NVME_CTRL_SGLS_DWORD_ALIGNED = 2,
423 NVME_CTRL_SGLS_KSDBDS = 1 << 2,
424 NVME_CTRL_SGLS_MSDS = 1 << 19,
425 NVME_CTRL_SGLS_SAOS = 1 << 20,
469 struct nvme_lbaf lbaf[64];
473 /* I/O Command Set Independent Identify Namespace Data Structure */
474 struct nvme_id_ns_cs_indep {
488 struct nvme_zns_lbafe {
494 struct nvme_id_ns_zns {
502 struct nvme_zns_lbafe lbafe[64];
506 struct nvme_id_ctrl_zns {
511 struct nvme_id_ns_nvm {
520 NVME_ID_NS_NVM_STS_MASK = 0x7f,
521 NVME_ID_NS_NVM_GUARD_SHIFT = 7,
522 NVME_ID_NS_NVM_GUARD_MASK = 0x3,
523 NVME_ID_NS_NVM_QPIF_SHIFT = 9,
524 NVME_ID_NS_NVM_QPIF_MASK = 0xf,
525 NVME_ID_NS_NVM_QPIFS = 1 << 3,
528 static inline __u8 nvme_elbaf_sts(__u32 elbaf)
530 return elbaf & NVME_ID_NS_NVM_STS_MASK;
533 static inline __u8 nvme_elbaf_guard_type(__u32 elbaf)
535 return (elbaf >> NVME_ID_NS_NVM_GUARD_SHIFT) & NVME_ID_NS_NVM_GUARD_MASK;
538 static inline __u8 nvme_elbaf_qualified_guard_type(__u32 elbaf)
540 return (elbaf >> NVME_ID_NS_NVM_QPIF_SHIFT) & NVME_ID_NS_NVM_QPIF_MASK;
543 struct nvme_id_ctrl_nvm {
554 NVME_ID_CNS_NS = 0x00,
555 NVME_ID_CNS_CTRL = 0x01,
556 NVME_ID_CNS_NS_ACTIVE_LIST = 0x02,
557 NVME_ID_CNS_NS_DESC_LIST = 0x03,
558 NVME_ID_CNS_CS_NS = 0x05,
559 NVME_ID_CNS_CS_CTRL = 0x06,
560 NVME_ID_CNS_NS_ACTIVE_LIST_CS = 0x07,
561 NVME_ID_CNS_NS_CS_INDEP = 0x08,
562 NVME_ID_CNS_NS_PRESENT_LIST = 0x10,
563 NVME_ID_CNS_NS_PRESENT = 0x11,
564 NVME_ID_CNS_CTRL_NS_LIST = 0x12,
565 NVME_ID_CNS_CTRL_LIST = 0x13,
566 NVME_ID_CNS_SCNDRY_CTRL_LIST = 0x15,
567 NVME_ID_CNS_NS_GRANULARITY = 0x16,
568 NVME_ID_CNS_UUID_LIST = 0x17,
569 NVME_ID_CNS_ENDGRP_LIST = 0x19,
578 NVME_DIR_IDENTIFY = 0x00,
579 NVME_DIR_STREAMS = 0x01,
580 NVME_DIR_SND_ID_OP_ENABLE = 0x01,
581 NVME_DIR_SND_ST_OP_REL_ID = 0x01,
582 NVME_DIR_SND_ST_OP_REL_RSC = 0x02,
583 NVME_DIR_RCV_ID_OP_PARAM = 0x01,
584 NVME_DIR_RCV_ST_OP_PARAM = 0x01,
585 NVME_DIR_RCV_ST_OP_STATUS = 0x02,
586 NVME_DIR_RCV_ST_OP_RESOURCE = 0x03,
587 NVME_DIR_ENDIR = 0x01,
591 NVME_NS_FEAT_THIN = 1 << 0,
592 NVME_NS_FEAT_ATOMICS = 1 << 1,
593 NVME_NS_FEAT_IO_OPT = 1 << 4,
594 NVME_NS_ATTR_RO = 1 << 0,
595 NVME_NS_FLBAS_LBA_MASK = 0xf,
596 NVME_NS_FLBAS_LBA_UMASK = 0x60,
597 NVME_NS_FLBAS_LBA_SHIFT = 1,
598 NVME_NS_FLBAS_META_EXT = 0x10,
599 NVME_NS_NMIC_SHARED = 1 << 0,
600 NVME_NS_ROTATIONAL = 1 << 4,
601 NVME_NS_VWC_NOT_PRESENT = 1 << 5,
602 NVME_LBAF_RP_BEST = 0,
603 NVME_LBAF_RP_BETTER = 1,
604 NVME_LBAF_RP_GOOD = 2,
605 NVME_LBAF_RP_DEGRADED = 3,
606 NVME_NS_DPC_PI_LAST = 1 << 4,
607 NVME_NS_DPC_PI_FIRST = 1 << 3,
608 NVME_NS_DPC_PI_TYPE3 = 1 << 2,
609 NVME_NS_DPC_PI_TYPE2 = 1 << 1,
610 NVME_NS_DPC_PI_TYPE1 = 1 << 0,
611 NVME_NS_DPS_PI_FIRST = 1 << 3,
612 NVME_NS_DPS_PI_MASK = 0x7,
613 NVME_NS_DPS_PI_TYPE1 = 1,
614 NVME_NS_DPS_PI_TYPE2 = 2,
615 NVME_NS_DPS_PI_TYPE3 = 3,
619 NVME_NSTAT_NRDY = 1 << 0,
623 NVME_NVM_NS_16B_GUARD = 0,
624 NVME_NVM_NS_32B_GUARD = 1,
625 NVME_NVM_NS_64B_GUARD = 2,
626 NVME_NVM_NS_QTYPE_GUARD = 3,
629 static inline __u8 nvme_lbaf_index(__u8 flbas)
631 return (flbas & NVME_NS_FLBAS_LBA_MASK) |
632 ((flbas & NVME_NS_FLBAS_LBA_UMASK) >> NVME_NS_FLBAS_LBA_SHIFT);
635 /* Identify Namespace Metadata Capabilities (MC): */
637 NVME_MC_EXTENDED_LBA = (1 << 0),
638 NVME_MC_METADATA_PTR = (1 << 1),
641 struct nvme_ns_id_desc {
647 #define NVME_NIDT_EUI64_LEN 8
648 #define NVME_NIDT_NGUID_LEN 16
649 #define NVME_NIDT_UUID_LEN 16
650 #define NVME_NIDT_CSI_LEN 1
653 NVME_NIDT_EUI64 = 0x01,
654 NVME_NIDT_NGUID = 0x02,
655 NVME_NIDT_UUID = 0x03,
656 NVME_NIDT_CSI = 0x04,
659 struct nvme_endurance_group_log {
681 struct nvme_rotational_media_log {
693 struct nvme_fdp_config {
695 #define FDPCFG_FDPE (1U << 0)
700 struct nvme_fdp_ruh_desc {
705 struct nvme_fdp_config_desc {
716 struct nvme_fdp_ruh_desc ruhs[];
719 struct nvme_fdp_config_log {
726 * This is followed by variable number of nvme_fdp_config_desc
727 * structures, but sparse doesn't like nested variable sized arrays.
731 struct nvme_smart_log {
732 __u8 critical_warning;
737 __u8 endu_grp_crit_warn_sumry;
739 __u8 data_units_read[16];
740 __u8 data_units_written[16];
742 __u8 host_writes[16];
743 __u8 ctrl_busy_time[16];
744 __u8 power_cycles[16];
745 __u8 power_on_hours[16];
746 __u8 unsafe_shutdowns[16];
747 __u8 media_errors[16];
748 __u8 num_err_log_entries[16];
749 __le32 warning_temp_time;
750 __le32 critical_comp_time;
751 __le16 temp_sensor[8];
752 __le32 thm_temp1_trans_count;
753 __le32 thm_temp2_trans_count;
754 __le32 thm_temp1_total_time;
755 __le32 thm_temp2_total_time;
759 struct nvme_fw_slot_info_log {
767 NVME_CMD_EFFECTS_CSUPP = 1 << 0,
768 NVME_CMD_EFFECTS_LBCC = 1 << 1,
769 NVME_CMD_EFFECTS_NCC = 1 << 2,
770 NVME_CMD_EFFECTS_NIC = 1 << 3,
771 NVME_CMD_EFFECTS_CCC = 1 << 4,
772 NVME_CMD_EFFECTS_CSER_MASK = GENMASK(15, 14),
773 NVME_CMD_EFFECTS_CSE_MASK = GENMASK(18, 16),
774 NVME_CMD_EFFECTS_UUID_SEL = 1 << 19,
775 NVME_CMD_EFFECTS_SCOPE_MASK = GENMASK(31, 20),
778 struct nvme_effects_log {
784 enum nvme_ana_state {
785 NVME_ANA_OPTIMIZED = 0x01,
786 NVME_ANA_NONOPTIMIZED = 0x02,
787 NVME_ANA_INACCESSIBLE = 0x03,
788 NVME_ANA_PERSISTENT_LOSS = 0x04,
789 NVME_ANA_CHANGE = 0x0f,
792 struct nvme_ana_group_desc {
801 /* flag for the log specific field of the ANA log */
802 #define NVME_ANA_LOG_RGO (1 << 0)
804 struct nvme_ana_rsp_hdr {
810 struct nvme_zone_descriptor {
822 NVME_ZONE_TYPE_SEQWRITE_REQ = 0x2,
825 struct nvme_zone_report {
828 struct nvme_zone_descriptor entries[];
832 NVME_SMART_CRIT_SPARE = 1 << 0,
833 NVME_SMART_CRIT_TEMPERATURE = 1 << 1,
834 NVME_SMART_CRIT_RELIABILITY = 1 << 2,
835 NVME_SMART_CRIT_MEDIA = 1 << 3,
836 NVME_SMART_CRIT_VOLATILE_MEMORY = 1 << 4,
848 NVME_AER_ERROR_PERSIST_INT_ERR = 0x03,
852 NVME_AER_NOTICE_NS_CHANGED = 0x00,
853 NVME_AER_NOTICE_FW_ACT_STARTING = 0x01,
854 NVME_AER_NOTICE_ANA = 0x03,
855 NVME_AER_NOTICE_DISC_CHANGED = 0xf0,
859 NVME_AEN_BIT_NS_ATTR = 8,
860 NVME_AEN_BIT_FW_ACT = 9,
861 NVME_AEN_BIT_ANA_CHANGE = 11,
862 NVME_AEN_BIT_DISC_CHANGE = 31,
866 NVME_AEN_CFG_NS_ATTR = 1 << NVME_AEN_BIT_NS_ATTR,
867 NVME_AEN_CFG_FW_ACT = 1 << NVME_AEN_BIT_FW_ACT,
868 NVME_AEN_CFG_ANA_CHANGE = 1 << NVME_AEN_BIT_ANA_CHANGE,
869 NVME_AEN_CFG_DISC_CHANGE = 1 << NVME_AEN_BIT_DISC_CHANGE,
872 struct nvme_lba_range_type {
883 NVME_LBART_TYPE_FS = 0x01,
884 NVME_LBART_TYPE_RAID = 0x02,
885 NVME_LBART_TYPE_CACHE = 0x03,
886 NVME_LBART_TYPE_SWAP = 0x04,
888 NVME_LBART_ATTRIB_TEMP = 1 << 0,
889 NVME_LBART_ATTRIB_HIDE = 1 << 1,
893 NVME_PR_WRITE_EXCLUSIVE = 1,
894 NVME_PR_EXCLUSIVE_ACCESS = 2,
895 NVME_PR_WRITE_EXCLUSIVE_REG_ONLY = 3,
896 NVME_PR_EXCLUSIVE_ACCESS_REG_ONLY = 4,
897 NVME_PR_WRITE_EXCLUSIVE_ALL_REGS = 5,
898 NVME_PR_EXCLUSIVE_ACCESS_ALL_REGS = 6,
902 NVME_EXTENDED_DATA_STRUCT = 0x1,
905 struct nvme_registered_ctrl {
913 struct nvme_reservation_status {
920 struct nvme_registered_ctrl regctl_ds[];
923 struct nvme_registered_ctrl_ext {
932 struct nvme_reservation_status_ext {
940 struct nvme_registered_ctrl_ext regctl_eds[];
946 nvme_cmd_flush = 0x00,
947 nvme_cmd_write = 0x01,
948 nvme_cmd_read = 0x02,
949 nvme_cmd_write_uncor = 0x04,
950 nvme_cmd_compare = 0x05,
951 nvme_cmd_write_zeroes = 0x08,
953 nvme_cmd_verify = 0x0c,
954 nvme_cmd_resv_register = 0x0d,
955 nvme_cmd_resv_report = 0x0e,
956 nvme_cmd_resv_acquire = 0x11,
957 nvme_cmd_io_mgmt_recv = 0x12,
958 nvme_cmd_resv_release = 0x15,
959 nvme_cmd_zone_mgmt_send = 0x79,
960 nvme_cmd_zone_mgmt_recv = 0x7a,
961 nvme_cmd_zone_append = 0x7d,
962 nvme_cmd_vendor_start = 0x80,
965 #define nvme_opcode_name(opcode) { opcode, #opcode }
966 #define show_nvm_opcode_name(val) \
967 __print_symbolic(val, \
968 nvme_opcode_name(nvme_cmd_flush), \
969 nvme_opcode_name(nvme_cmd_write), \
970 nvme_opcode_name(nvme_cmd_read), \
971 nvme_opcode_name(nvme_cmd_write_uncor), \
972 nvme_opcode_name(nvme_cmd_compare), \
973 nvme_opcode_name(nvme_cmd_write_zeroes), \
974 nvme_opcode_name(nvme_cmd_dsm), \
975 nvme_opcode_name(nvme_cmd_verify), \
976 nvme_opcode_name(nvme_cmd_resv_register), \
977 nvme_opcode_name(nvme_cmd_resv_report), \
978 nvme_opcode_name(nvme_cmd_resv_acquire), \
979 nvme_opcode_name(nvme_cmd_io_mgmt_recv), \
980 nvme_opcode_name(nvme_cmd_resv_release), \
981 nvme_opcode_name(nvme_cmd_zone_mgmt_send), \
982 nvme_opcode_name(nvme_cmd_zone_mgmt_recv), \
983 nvme_opcode_name(nvme_cmd_zone_append))
988 * Descriptor subtype - lower 4 bits of nvme_(keyed_)sgl_desc identifier
990 * @NVME_SGL_FMT_ADDRESS: absolute address of the data block
991 * @NVME_SGL_FMT_OFFSET: relative offset of the in-capsule data block
992 * @NVME_SGL_FMT_TRANSPORT_A: transport defined format, value 0xA
993 * @NVME_SGL_FMT_INVALIDATE: RDMA transport specific remote invalidation
997 NVME_SGL_FMT_ADDRESS = 0x00,
998 NVME_SGL_FMT_OFFSET = 0x01,
999 NVME_SGL_FMT_TRANSPORT_A = 0x0A,
1000 NVME_SGL_FMT_INVALIDATE = 0x0f,
1004 * Descriptor type - upper 4 bits of nvme_(keyed_)sgl_desc identifier
1006 * For struct nvme_sgl_desc:
1007 * @NVME_SGL_FMT_DATA_DESC: data block descriptor
1008 * @NVME_SGL_FMT_SEG_DESC: sgl segment descriptor
1009 * @NVME_SGL_FMT_LAST_SEG_DESC: last sgl segment descriptor
1011 * For struct nvme_keyed_sgl_desc:
1012 * @NVME_KEY_SGL_FMT_DATA_DESC: keyed data block descriptor
1014 * Transport-specific SGL types:
1015 * @NVME_TRANSPORT_SGL_DATA_DESC: Transport SGL data dlock descriptor
1018 NVME_SGL_FMT_DATA_DESC = 0x00,
1019 NVME_SGL_FMT_SEG_DESC = 0x02,
1020 NVME_SGL_FMT_LAST_SEG_DESC = 0x03,
1021 NVME_KEY_SGL_FMT_DATA_DESC = 0x04,
1022 NVME_TRANSPORT_SGL_DATA_DESC = 0x05,
1025 struct nvme_sgl_desc {
1032 struct nvme_keyed_sgl_desc {
1039 union nvme_data_ptr {
1044 struct nvme_sgl_desc sgl;
1045 struct nvme_keyed_sgl_desc ksgl;
1049 * Lowest two bits of our flags field (FUSE field in the spec):
1051 * @NVME_CMD_FUSE_FIRST: Fused Operation, first command
1052 * @NVME_CMD_FUSE_SECOND: Fused Operation, second command
1054 * Highest two bits in our flags field (PSDT field in the spec):
1056 * @NVME_CMD_PSDT_SGL_METABUF: Use SGLS for this transfer,
1057 * If used, MPTR contains addr of single physical buffer (byte aligned).
1058 * @NVME_CMD_PSDT_SGL_METASEG: Use SGLS for this transfer,
1059 * If used, MPTR contains an address of an SGL segment containing
1060 * exactly 1 SGL descriptor (qword aligned).
1063 NVME_CMD_FUSE_FIRST = (1 << 0),
1064 NVME_CMD_FUSE_SECOND = (1 << 1),
1066 NVME_CMD_SGL_METABUF = (1 << 6),
1067 NVME_CMD_SGL_METASEG = (1 << 7),
1068 NVME_CMD_SGL_ALL = NVME_CMD_SGL_METABUF | NVME_CMD_SGL_METASEG,
1071 struct nvme_common_command {
1078 union nvme_data_ptr dptr;
1089 struct nvme_rw_command {
1097 union nvme_data_ptr dptr;
1108 NVME_RW_LR = 1 << 15,
1109 NVME_RW_FUA = 1 << 14,
1110 NVME_RW_APPEND_PIREMAP = 1 << 9,
1111 NVME_RW_DSM_FREQ_UNSPEC = 0,
1112 NVME_RW_DSM_FREQ_TYPICAL = 1,
1113 NVME_RW_DSM_FREQ_RARE = 2,
1114 NVME_RW_DSM_FREQ_READS = 3,
1115 NVME_RW_DSM_FREQ_WRITES = 4,
1116 NVME_RW_DSM_FREQ_RW = 5,
1117 NVME_RW_DSM_FREQ_ONCE = 6,
1118 NVME_RW_DSM_FREQ_PREFETCH = 7,
1119 NVME_RW_DSM_FREQ_TEMP = 8,
1120 NVME_RW_DSM_LATENCY_NONE = 0 << 4,
1121 NVME_RW_DSM_LATENCY_IDLE = 1 << 4,
1122 NVME_RW_DSM_LATENCY_NORM = 2 << 4,
1123 NVME_RW_DSM_LATENCY_LOW = 3 << 4,
1124 NVME_RW_DSM_SEQ_REQ = 1 << 6,
1125 NVME_RW_DSM_COMPRESSED = 1 << 7,
1126 NVME_RW_PRINFO_PRCHK_REF = 1 << 10,
1127 NVME_RW_PRINFO_PRCHK_APP = 1 << 11,
1128 NVME_RW_PRINFO_PRCHK_GUARD = 1 << 12,
1129 NVME_RW_PRINFO_PRACT = 1 << 13,
1130 NVME_RW_DTYPE_STREAMS = 1 << 4,
1131 NVME_RW_DTYPE_DPLCMT = 2 << 4,
1132 NVME_WZ_DEAC = 1 << 9,
1135 struct nvme_dsm_cmd {
1141 union nvme_data_ptr dptr;
1148 NVME_DSMGMT_IDR = 1 << 0,
1149 NVME_DSMGMT_IDW = 1 << 1,
1150 NVME_DSMGMT_AD = 1 << 2,
1153 #define NVME_DSM_MAX_RANGES 256
1155 struct nvme_dsm_range {
1161 struct nvme_write_zeroes_cmd {
1168 union nvme_data_ptr dptr;
1178 enum nvme_zone_mgmt_action {
1179 NVME_ZONE_CLOSE = 0x1,
1180 NVME_ZONE_FINISH = 0x2,
1181 NVME_ZONE_OPEN = 0x3,
1182 NVME_ZONE_RESET = 0x4,
1183 NVME_ZONE_OFFLINE = 0x5,
1184 NVME_ZONE_SET_DESC_EXT = 0x10,
1187 struct nvme_zone_mgmt_send_cmd {
1194 union nvme_data_ptr dptr;
1203 struct nvme_zone_mgmt_recv_cmd {
1209 union nvme_data_ptr dptr;
1219 struct nvme_io_mgmt_recv_cmd {
1225 union nvme_data_ptr dptr;
1234 NVME_IO_MGMT_RECV_MO_RUHS = 1,
1237 struct nvme_fdp_ruh_status_desc {
1245 struct nvme_fdp_ruh_status {
1248 struct nvme_fdp_ruh_status_desc ruhsd[];
1252 NVME_ZRA_ZONE_REPORT = 0,
1253 NVME_ZRASF_ZONE_REPORT_ALL = 0,
1254 NVME_ZRASF_ZONE_STATE_EMPTY = 0x01,
1255 NVME_ZRASF_ZONE_STATE_IMP_OPEN = 0x02,
1256 NVME_ZRASF_ZONE_STATE_EXP_OPEN = 0x03,
1257 NVME_ZRASF_ZONE_STATE_CLOSED = 0x04,
1258 NVME_ZRASF_ZONE_STATE_READONLY = 0x05,
1259 NVME_ZRASF_ZONE_STATE_FULL = 0x06,
1260 NVME_ZRASF_ZONE_STATE_OFFLINE = 0x07,
1261 NVME_REPORT_ZONE_PARTIAL = 1,
1267 NVME_TEMP_THRESH_MASK = 0xffff,
1268 NVME_TEMP_THRESH_SELECT_SHIFT = 16,
1269 NVME_TEMP_THRESH_TYPE_UNDER = 0x100000,
1272 struct nvme_feat_auto_pst {
1277 NVME_HOST_MEM_ENABLE = (1 << 0),
1278 NVME_HOST_MEM_RETURN = (1 << 1),
1281 struct nvme_feat_host_behavior {
1289 NVME_ENABLE_ACRE = 1,
1290 NVME_ENABLE_LBAFEE = 1,
1293 /* Admin commands */
1295 enum nvme_admin_opcode {
1296 nvme_admin_delete_sq = 0x00,
1297 nvme_admin_create_sq = 0x01,
1298 nvme_admin_get_log_page = 0x02,
1299 nvme_admin_delete_cq = 0x04,
1300 nvme_admin_create_cq = 0x05,
1301 nvme_admin_identify = 0x06,
1302 nvme_admin_abort_cmd = 0x08,
1303 nvme_admin_set_features = 0x09,
1304 nvme_admin_get_features = 0x0a,
1305 nvme_admin_async_event = 0x0c,
1306 nvme_admin_ns_mgmt = 0x0d,
1307 nvme_admin_activate_fw = 0x10,
1308 nvme_admin_download_fw = 0x11,
1309 nvme_admin_dev_self_test = 0x14,
1310 nvme_admin_ns_attach = 0x15,
1311 nvme_admin_keep_alive = 0x18,
1312 nvme_admin_directive_send = 0x19,
1313 nvme_admin_directive_recv = 0x1a,
1314 nvme_admin_virtual_mgmt = 0x1c,
1315 nvme_admin_nvme_mi_send = 0x1d,
1316 nvme_admin_nvme_mi_recv = 0x1e,
1317 nvme_admin_dbbuf = 0x7C,
1318 nvme_admin_format_nvm = 0x80,
1319 nvme_admin_security_send = 0x81,
1320 nvme_admin_security_recv = 0x82,
1321 nvme_admin_sanitize_nvm = 0x84,
1322 nvme_admin_get_lba_status = 0x86,
1323 nvme_admin_vendor_start = 0xC0,
1326 #define nvme_admin_opcode_name(opcode) { opcode, #opcode }
1327 #define show_admin_opcode_name(val) \
1328 __print_symbolic(val, \
1329 nvme_admin_opcode_name(nvme_admin_delete_sq), \
1330 nvme_admin_opcode_name(nvme_admin_create_sq), \
1331 nvme_admin_opcode_name(nvme_admin_get_log_page), \
1332 nvme_admin_opcode_name(nvme_admin_delete_cq), \
1333 nvme_admin_opcode_name(nvme_admin_create_cq), \
1334 nvme_admin_opcode_name(nvme_admin_identify), \
1335 nvme_admin_opcode_name(nvme_admin_abort_cmd), \
1336 nvme_admin_opcode_name(nvme_admin_set_features), \
1337 nvme_admin_opcode_name(nvme_admin_get_features), \
1338 nvme_admin_opcode_name(nvme_admin_async_event), \
1339 nvme_admin_opcode_name(nvme_admin_ns_mgmt), \
1340 nvme_admin_opcode_name(nvme_admin_activate_fw), \
1341 nvme_admin_opcode_name(nvme_admin_download_fw), \
1342 nvme_admin_opcode_name(nvme_admin_dev_self_test), \
1343 nvme_admin_opcode_name(nvme_admin_ns_attach), \
1344 nvme_admin_opcode_name(nvme_admin_keep_alive), \
1345 nvme_admin_opcode_name(nvme_admin_directive_send), \
1346 nvme_admin_opcode_name(nvme_admin_directive_recv), \
1347 nvme_admin_opcode_name(nvme_admin_virtual_mgmt), \
1348 nvme_admin_opcode_name(nvme_admin_nvme_mi_send), \
1349 nvme_admin_opcode_name(nvme_admin_nvme_mi_recv), \
1350 nvme_admin_opcode_name(nvme_admin_dbbuf), \
1351 nvme_admin_opcode_name(nvme_admin_format_nvm), \
1352 nvme_admin_opcode_name(nvme_admin_security_send), \
1353 nvme_admin_opcode_name(nvme_admin_security_recv), \
1354 nvme_admin_opcode_name(nvme_admin_sanitize_nvm), \
1355 nvme_admin_opcode_name(nvme_admin_get_lba_status))
1358 NVME_QUEUE_PHYS_CONTIG = (1 << 0),
1359 NVME_CQ_IRQ_ENABLED = (1 << 1),
1360 NVME_SQ_PRIO_URGENT = (0 << 1),
1361 NVME_SQ_PRIO_HIGH = (1 << 1),
1362 NVME_SQ_PRIO_MEDIUM = (2 << 1),
1363 NVME_SQ_PRIO_LOW = (3 << 1),
1364 NVME_FEAT_ARBITRATION = 0x01,
1365 NVME_FEAT_POWER_MGMT = 0x02,
1366 NVME_FEAT_LBA_RANGE = 0x03,
1367 NVME_FEAT_TEMP_THRESH = 0x04,
1368 NVME_FEAT_ERR_RECOVERY = 0x05,
1369 NVME_FEAT_VOLATILE_WC = 0x06,
1370 NVME_FEAT_NUM_QUEUES = 0x07,
1371 NVME_FEAT_IRQ_COALESCE = 0x08,
1372 NVME_FEAT_IRQ_CONFIG = 0x09,
1373 NVME_FEAT_WRITE_ATOMIC = 0x0a,
1374 NVME_FEAT_ASYNC_EVENT = 0x0b,
1375 NVME_FEAT_AUTO_PST = 0x0c,
1376 NVME_FEAT_HOST_MEM_BUF = 0x0d,
1377 NVME_FEAT_TIMESTAMP = 0x0e,
1378 NVME_FEAT_KATO = 0x0f,
1379 NVME_FEAT_HCTM = 0x10,
1380 NVME_FEAT_NOPSC = 0x11,
1381 NVME_FEAT_RRL = 0x12,
1382 NVME_FEAT_PLM_CONFIG = 0x13,
1383 NVME_FEAT_PLM_WINDOW = 0x14,
1384 NVME_FEAT_HOST_BEHAVIOR = 0x16,
1385 NVME_FEAT_SANITIZE = 0x17,
1386 NVME_FEAT_FDP = 0x1d,
1387 NVME_FEAT_SW_PROGRESS = 0x80,
1388 NVME_FEAT_HOST_ID = 0x81,
1389 NVME_FEAT_RESV_MASK = 0x82,
1390 NVME_FEAT_RESV_PERSIST = 0x83,
1391 NVME_FEAT_WRITE_PROTECT = 0x84,
1392 NVME_FEAT_VENDOR_START = 0xC0,
1393 NVME_FEAT_VENDOR_END = 0xFF,
1394 NVME_LOG_SUPPORTED = 0x00,
1395 NVME_LOG_ERROR = 0x01,
1396 NVME_LOG_SMART = 0x02,
1397 NVME_LOG_FW_SLOT = 0x03,
1398 NVME_LOG_CHANGED_NS = 0x04,
1399 NVME_LOG_CMD_EFFECTS = 0x05,
1400 NVME_LOG_DEVICE_SELF_TEST = 0x06,
1401 NVME_LOG_TELEMETRY_HOST = 0x07,
1402 NVME_LOG_TELEMETRY_CTRL = 0x08,
1403 NVME_LOG_ENDURANCE_GROUP = 0x09,
1404 NVME_LOG_ANA = 0x0c,
1405 NVME_LOG_FEATURES = 0x12,
1406 NVME_LOG_RMI = 0x16,
1407 NVME_LOG_FDP_CONFIGS = 0x20,
1408 NVME_LOG_DISC = 0x70,
1409 NVME_LOG_RESERVATION = 0x80,
1410 NVME_FWACT_REPL = (0 << 3),
1411 NVME_FWACT_REPL_ACTV = (1 << 3),
1412 NVME_FWACT_ACTV = (2 << 3),
1415 struct nvme_supported_log {
1420 NVME_LIDS_LSUPP = 1 << 0,
1423 struct nvme_supported_features_log {
1428 NVME_FIS_FSUPP = 1 << 0,
1429 NVME_FIS_NSCPE = 1 << 20,
1430 NVME_FIS_CSCPE = 1 << 21,
1433 /* NVMe Namespace Write Protect State */
1435 NVME_NS_NO_WRITE_PROTECT = 0,
1436 NVME_NS_WRITE_PROTECT,
1437 NVME_NS_WRITE_PROTECT_POWER_CYCLE,
1438 NVME_NS_WRITE_PROTECT_PERMANENT,
1441 #define NVME_MAX_CHANGED_NAMESPACES 1024
1443 struct nvme_identify {
1449 union nvme_data_ptr dptr;
1459 #define NVME_IDENTIFY_DATA_SIZE 4096
1461 struct nvme_features {
1467 union nvme_data_ptr dptr;
1476 struct nvme_host_mem_buf_desc {
1482 struct nvme_create_cq {
1496 struct nvme_create_sq {
1510 struct nvme_delete_queue {
1520 struct nvme_abort_cmd {
1530 struct nvme_download_firmware {
1535 union nvme_data_ptr dptr;
1541 struct nvme_format_cmd {
1551 struct nvme_get_log_page_command {
1557 union nvme_data_ptr dptr;
1559 __u8 lsp; /* upper 4 bits reserved */
1575 struct nvme_directive_cmd {
1581 union nvme_data_ptr dptr;
1594 * Fabrics subcommands.
1596 enum nvmf_fabrics_opcode {
1597 nvme_fabrics_command = 0x7f,
1600 enum nvmf_capsule_command {
1601 nvme_fabrics_type_property_set = 0x00,
1602 nvme_fabrics_type_connect = 0x01,
1603 nvme_fabrics_type_property_get = 0x04,
1604 nvme_fabrics_type_auth_send = 0x05,
1605 nvme_fabrics_type_auth_receive = 0x06,
1608 #define nvme_fabrics_type_name(type) { type, #type }
1609 #define show_fabrics_type_name(type) \
1610 __print_symbolic(type, \
1611 nvme_fabrics_type_name(nvme_fabrics_type_property_set), \
1612 nvme_fabrics_type_name(nvme_fabrics_type_connect), \
1613 nvme_fabrics_type_name(nvme_fabrics_type_property_get), \
1614 nvme_fabrics_type_name(nvme_fabrics_type_auth_send), \
1615 nvme_fabrics_type_name(nvme_fabrics_type_auth_receive))
1618 * If not fabrics command, fctype will be ignored.
1620 #define show_opcode_name(qid, opcode, fctype) \
1621 ((opcode) == nvme_fabrics_command ? \
1622 show_fabrics_type_name(fctype) : \
1624 show_nvm_opcode_name(opcode) : \
1625 show_admin_opcode_name(opcode)))
1627 struct nvmf_common_command {
1637 * The legal cntlid range a NVMe Target will provide.
1638 * Note that cntlid of value 0 is considered illegal in the fabrics world.
1639 * Devices based on earlier specs did not have the subsystem concept;
1640 * therefore, those devices had their cntlid value set to 0 as a result.
1642 #define NVME_CNTLID_MIN 1
1643 #define NVME_CNTLID_MAX 0xffef
1644 #define NVME_CNTLID_DYNAMIC 0xffff
1646 #define MAX_DISC_LOGS 255
1648 /* Discovery log page entry flags (EFLAGS): */
1650 NVME_DISC_EFLAGS_EPCSD = (1 << 1),
1651 NVME_DISC_EFLAGS_DUPRETINFO = (1 << 0),
1654 /* Discovery log page entry */
1655 struct nvmf_disc_rsp_page_entry {
1665 char trsvcid[NVMF_TRSVCID_SIZE];
1667 char subnqn[NVMF_NQN_FIELD_LEN];
1668 char traddr[NVMF_TRADDR_SIZE];
1670 char common[NVMF_TSAS_SIZE];
1685 /* Discovery log page header */
1686 struct nvmf_disc_rsp_page_hdr {
1691 struct nvmf_disc_rsp_page_entry entries[];
1695 NVME_CONNECT_DISABLE_SQFLOW = (1 << 2),
1698 struct nvmf_connect_command {
1704 union nvme_data_ptr dptr;
1715 NVME_CONNECT_AUTHREQ_ASCR = (1U << 18),
1716 NVME_CONNECT_AUTHREQ_ATR = (1U << 17),
1719 struct nvmf_connect_data {
1723 char subsysnqn[NVMF_NQN_FIELD_LEN];
1724 char hostnqn[NVMF_NQN_FIELD_LEN];
1728 struct nvmf_property_set_command {
1741 struct nvmf_property_get_command {
1753 struct nvmf_auth_common_command {
1759 union nvme_data_ptr dptr;
1768 struct nvmf_auth_send_command {
1774 union nvme_data_ptr dptr;
1783 struct nvmf_auth_receive_command {
1789 union nvme_data_ptr dptr;
1798 /* Value for secp */
1800 NVME_AUTH_DHCHAP_PROTOCOL_IDENTIFIER = 0xe9,
1803 /* Defined value for auth_type */
1805 NVME_AUTH_COMMON_MESSAGES = 0x00,
1806 NVME_AUTH_DHCHAP_MESSAGES = 0x01,
1809 /* Defined messages for auth_id */
1811 NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE = 0x00,
1812 NVME_AUTH_DHCHAP_MESSAGE_CHALLENGE = 0x01,
1813 NVME_AUTH_DHCHAP_MESSAGE_REPLY = 0x02,
1814 NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1 = 0x03,
1815 NVME_AUTH_DHCHAP_MESSAGE_SUCCESS2 = 0x04,
1816 NVME_AUTH_DHCHAP_MESSAGE_FAILURE2 = 0xf0,
1817 NVME_AUTH_DHCHAP_MESSAGE_FAILURE1 = 0xf1,
1820 struct nvmf_auth_dhchap_protocol_descriptor {
1829 NVME_AUTH_DHCHAP_AUTH_ID = 0x01,
1832 /* Defined hash functions for DH-HMAC-CHAP authentication */
1834 NVME_AUTH_HASH_SHA256 = 0x01,
1835 NVME_AUTH_HASH_SHA384 = 0x02,
1836 NVME_AUTH_HASH_SHA512 = 0x03,
1837 NVME_AUTH_HASH_INVALID = 0xff,
1840 /* Defined Diffie-Hellman group identifiers for DH-HMAC-CHAP authentication */
1842 NVME_AUTH_DHGROUP_NULL = 0x00,
1843 NVME_AUTH_DHGROUP_2048 = 0x01,
1844 NVME_AUTH_DHGROUP_3072 = 0x02,
1845 NVME_AUTH_DHGROUP_4096 = 0x03,
1846 NVME_AUTH_DHGROUP_6144 = 0x04,
1847 NVME_AUTH_DHGROUP_8192 = 0x05,
1848 NVME_AUTH_DHGROUP_INVALID = 0xff,
1852 NVME_AUTH_SECP_NOSC = 0x00,
1853 NVME_AUTH_SECP_SC = 0x01,
1854 NVME_AUTH_SECP_NEWTLSPSK = 0x02,
1855 NVME_AUTH_SECP_REPLACETLSPSK = 0x03,
1858 union nvmf_auth_protocol {
1859 struct nvmf_auth_dhchap_protocol_descriptor dhchap;
1862 struct nvmf_auth_dhchap_negotiate_data {
1869 union nvmf_auth_protocol auth_protocol[];
1872 struct nvmf_auth_dhchap_challenge_data {
1883 /* 'hl' bytes of challenge value */
1885 /* followed by 'dhvlen' bytes of DH value */
1888 struct nvmf_auth_dhchap_reply_data {
1899 /* 'hl' bytes of response data */
1901 /* followed by 'hl' bytes of Challenge value */
1902 /* followed by 'dhvlen' bytes of DH value */
1906 NVME_AUTH_DHCHAP_RESPONSE_VALID = (1 << 0),
1909 struct nvmf_auth_dhchap_success1_data {
1918 /* 'hl' bytes of response value */
1922 struct nvmf_auth_dhchap_success2_data {
1930 struct nvmf_auth_dhchap_failure_data {
1940 NVME_AUTH_DHCHAP_FAILURE_REASON_FAILED = 0x01,
1944 NVME_AUTH_DHCHAP_FAILURE_FAILED = 0x01,
1945 NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE = 0x02,
1946 NVME_AUTH_DHCHAP_FAILURE_CONCAT_MISMATCH = 0x03,
1947 NVME_AUTH_DHCHAP_FAILURE_HASH_UNUSABLE = 0x04,
1948 NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE = 0x05,
1949 NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD = 0x06,
1950 NVME_AUTH_DHCHAP_FAILURE_INCORRECT_MESSAGE = 0x07,
1964 struct streams_directive_params {
1976 struct nvme_command {
1978 struct nvme_common_command common;
1979 struct nvme_rw_command rw;
1980 struct nvme_identify identify;
1981 struct nvme_features features;
1982 struct nvme_create_cq create_cq;
1983 struct nvme_create_sq create_sq;
1984 struct nvme_delete_queue delete_queue;
1985 struct nvme_download_firmware dlfw;
1986 struct nvme_format_cmd format;
1987 struct nvme_dsm_cmd dsm;
1988 struct nvme_write_zeroes_cmd write_zeroes;
1989 struct nvme_zone_mgmt_send_cmd zms;
1990 struct nvme_zone_mgmt_recv_cmd zmr;
1991 struct nvme_abort_cmd abort;
1992 struct nvme_get_log_page_command get_log_page;
1993 struct nvmf_common_command fabrics;
1994 struct nvmf_connect_command connect;
1995 struct nvmf_property_set_command prop_set;
1996 struct nvmf_property_get_command prop_get;
1997 struct nvmf_auth_common_command auth_common;
1998 struct nvmf_auth_send_command auth_send;
1999 struct nvmf_auth_receive_command auth_receive;
2000 struct nvme_dbbuf dbbuf;
2001 struct nvme_directive_cmd directive;
2002 struct nvme_io_mgmt_recv_cmd imr;
2006 static inline bool nvme_is_fabrics(const struct nvme_command *cmd)
2008 return cmd->common.opcode == nvme_fabrics_command;
2011 #ifdef CONFIG_NVME_VERBOSE_ERRORS
2012 const char *nvme_get_error_status_str(u16 status);
2013 const char *nvme_get_opcode_str(u8 opcode);
2014 const char *nvme_get_admin_opcode_str(u8 opcode);
2015 const char *nvme_get_fabrics_opcode_str(u8 opcode);
2016 #else /* CONFIG_NVME_VERBOSE_ERRORS */
2017 static inline const char *nvme_get_error_status_str(u16 status)
2021 static inline const char *nvme_get_opcode_str(u8 opcode)
2025 static inline const char *nvme_get_admin_opcode_str(u8 opcode)
2030 static inline const char *nvme_get_fabrics_opcode_str(u8 opcode)
2032 return "Fabrics Cmd";
2034 #endif /* CONFIG_NVME_VERBOSE_ERRORS */
2036 static inline const char *nvme_opcode_str(int qid, u8 opcode)
2038 return qid ? nvme_get_opcode_str(opcode) :
2039 nvme_get_admin_opcode_str(opcode);
2042 static inline const char *nvme_fabrics_opcode_str(
2043 int qid, const struct nvme_command *cmd)
2045 if (nvme_is_fabrics(cmd))
2046 return nvme_get_fabrics_opcode_str(cmd->fabrics.fctype);
2048 return nvme_opcode_str(qid, cmd->common.opcode);
2051 struct nvme_error_slot {
2055 __le16 status_field;
2056 __le16 param_error_location;
2065 static inline bool nvme_is_write(const struct nvme_command *cmd)
2070 * Why can't we simply have a Fabrics In and Fabrics out command?
2072 if (unlikely(nvme_is_fabrics(cmd)))
2073 return cmd->fabrics.fctype & 1;
2074 return cmd->common.opcode & 1;
2079 * Generic Command Status:
2081 NVME_SCT_GENERIC = 0x0,
2082 NVME_SC_SUCCESS = 0x0,
2083 NVME_SC_INVALID_OPCODE = 0x1,
2084 NVME_SC_INVALID_FIELD = 0x2,
2085 NVME_SC_CMDID_CONFLICT = 0x3,
2086 NVME_SC_DATA_XFER_ERROR = 0x4,
2087 NVME_SC_POWER_LOSS = 0x5,
2088 NVME_SC_INTERNAL = 0x6,
2089 NVME_SC_ABORT_REQ = 0x7,
2090 NVME_SC_ABORT_QUEUE = 0x8,
2091 NVME_SC_FUSED_FAIL = 0x9,
2092 NVME_SC_FUSED_MISSING = 0xa,
2093 NVME_SC_INVALID_NS = 0xb,
2094 NVME_SC_CMD_SEQ_ERROR = 0xc,
2095 NVME_SC_SGL_INVALID_LAST = 0xd,
2096 NVME_SC_SGL_INVALID_COUNT = 0xe,
2097 NVME_SC_SGL_INVALID_DATA = 0xf,
2098 NVME_SC_SGL_INVALID_METADATA = 0x10,
2099 NVME_SC_SGL_INVALID_TYPE = 0x11,
2100 NVME_SC_CMB_INVALID_USE = 0x12,
2101 NVME_SC_PRP_INVALID_OFFSET = 0x13,
2102 NVME_SC_ATOMIC_WU_EXCEEDED = 0x14,
2103 NVME_SC_OP_DENIED = 0x15,
2104 NVME_SC_SGL_INVALID_OFFSET = 0x16,
2105 NVME_SC_RESERVED = 0x17,
2106 NVME_SC_HOST_ID_INCONSIST = 0x18,
2107 NVME_SC_KA_TIMEOUT_EXPIRED = 0x19,
2108 NVME_SC_KA_TIMEOUT_INVALID = 0x1A,
2109 NVME_SC_ABORTED_PREEMPT_ABORT = 0x1B,
2110 NVME_SC_SANITIZE_FAILED = 0x1C,
2111 NVME_SC_SANITIZE_IN_PROGRESS = 0x1D,
2112 NVME_SC_SGL_INVALID_GRANULARITY = 0x1E,
2113 NVME_SC_CMD_NOT_SUP_CMB_QUEUE = 0x1F,
2114 NVME_SC_NS_WRITE_PROTECTED = 0x20,
2115 NVME_SC_CMD_INTERRUPTED = 0x21,
2116 NVME_SC_TRANSIENT_TR_ERR = 0x22,
2117 NVME_SC_ADMIN_COMMAND_MEDIA_NOT_READY = 0x24,
2118 NVME_SC_INVALID_IO_CMD_SET = 0x2C,
2120 NVME_SC_LBA_RANGE = 0x80,
2121 NVME_SC_CAP_EXCEEDED = 0x81,
2122 NVME_SC_NS_NOT_READY = 0x82,
2123 NVME_SC_RESERVATION_CONFLICT = 0x83,
2124 NVME_SC_FORMAT_IN_PROGRESS = 0x84,
2127 * Command Specific Status:
2129 NVME_SCT_COMMAND_SPECIFIC = 0x100,
2130 NVME_SC_CQ_INVALID = 0x100,
2131 NVME_SC_QID_INVALID = 0x101,
2132 NVME_SC_QUEUE_SIZE = 0x102,
2133 NVME_SC_ABORT_LIMIT = 0x103,
2134 NVME_SC_ABORT_MISSING = 0x104,
2135 NVME_SC_ASYNC_LIMIT = 0x105,
2136 NVME_SC_FIRMWARE_SLOT = 0x106,
2137 NVME_SC_FIRMWARE_IMAGE = 0x107,
2138 NVME_SC_INVALID_VECTOR = 0x108,
2139 NVME_SC_INVALID_LOG_PAGE = 0x109,
2140 NVME_SC_INVALID_FORMAT = 0x10a,
2141 NVME_SC_FW_NEEDS_CONV_RESET = 0x10b,
2142 NVME_SC_INVALID_QUEUE = 0x10c,
2143 NVME_SC_FEATURE_NOT_SAVEABLE = 0x10d,
2144 NVME_SC_FEATURE_NOT_CHANGEABLE = 0x10e,
2145 NVME_SC_FEATURE_NOT_PER_NS = 0x10f,
2146 NVME_SC_FW_NEEDS_SUBSYS_RESET = 0x110,
2147 NVME_SC_FW_NEEDS_RESET = 0x111,
2148 NVME_SC_FW_NEEDS_MAX_TIME = 0x112,
2149 NVME_SC_FW_ACTIVATE_PROHIBITED = 0x113,
2150 NVME_SC_OVERLAPPING_RANGE = 0x114,
2151 NVME_SC_NS_INSUFFICIENT_CAP = 0x115,
2152 NVME_SC_NS_ID_UNAVAILABLE = 0x116,
2153 NVME_SC_NS_ALREADY_ATTACHED = 0x118,
2154 NVME_SC_NS_IS_PRIVATE = 0x119,
2155 NVME_SC_NS_NOT_ATTACHED = 0x11a,
2156 NVME_SC_THIN_PROV_NOT_SUPP = 0x11b,
2157 NVME_SC_CTRL_LIST_INVALID = 0x11c,
2158 NVME_SC_SELT_TEST_IN_PROGRESS = 0x11d,
2159 NVME_SC_BP_WRITE_PROHIBITED = 0x11e,
2160 NVME_SC_CTRL_ID_INVALID = 0x11f,
2161 NVME_SC_SEC_CTRL_STATE_INVALID = 0x120,
2162 NVME_SC_CTRL_RES_NUM_INVALID = 0x121,
2163 NVME_SC_RES_ID_INVALID = 0x122,
2164 NVME_SC_PMR_SAN_PROHIBITED = 0x123,
2165 NVME_SC_ANA_GROUP_ID_INVALID = 0x124,
2166 NVME_SC_ANA_ATTACH_FAILED = 0x125,
2169 * I/O Command Set Specific - NVM commands:
2171 NVME_SC_BAD_ATTRIBUTES = 0x180,
2172 NVME_SC_INVALID_PI = 0x181,
2173 NVME_SC_READ_ONLY = 0x182,
2174 NVME_SC_CMD_SIZE_LIM_EXCEEDED = 0x183,
2177 * I/O Command Set Specific - Fabrics commands:
2179 NVME_SC_CONNECT_FORMAT = 0x180,
2180 NVME_SC_CONNECT_CTRL_BUSY = 0x181,
2181 NVME_SC_CONNECT_INVALID_PARAM = 0x182,
2182 NVME_SC_CONNECT_RESTART_DISC = 0x183,
2183 NVME_SC_CONNECT_INVALID_HOST = 0x184,
2185 NVME_SC_DISCOVERY_RESTART = 0x190,
2186 NVME_SC_AUTH_REQUIRED = 0x191,
2189 * I/O Command Set Specific - Zoned commands:
2191 NVME_SC_ZONE_BOUNDARY_ERROR = 0x1b8,
2192 NVME_SC_ZONE_FULL = 0x1b9,
2193 NVME_SC_ZONE_READ_ONLY = 0x1ba,
2194 NVME_SC_ZONE_OFFLINE = 0x1bb,
2195 NVME_SC_ZONE_INVALID_WRITE = 0x1bc,
2196 NVME_SC_ZONE_TOO_MANY_ACTIVE = 0x1bd,
2197 NVME_SC_ZONE_TOO_MANY_OPEN = 0x1be,
2198 NVME_SC_ZONE_INVALID_TRANSITION = 0x1bf,
2201 * Media and Data Integrity Errors:
2203 NVME_SCT_MEDIA_ERROR = 0x200,
2204 NVME_SC_WRITE_FAULT = 0x280,
2205 NVME_SC_READ_ERROR = 0x281,
2206 NVME_SC_GUARD_CHECK = 0x282,
2207 NVME_SC_APPTAG_CHECK = 0x283,
2208 NVME_SC_REFTAG_CHECK = 0x284,
2209 NVME_SC_COMPARE_FAILED = 0x285,
2210 NVME_SC_ACCESS_DENIED = 0x286,
2211 NVME_SC_UNWRITTEN_BLOCK = 0x287,
2214 * Path-related Errors:
2216 NVME_SCT_PATH = 0x300,
2217 NVME_SC_INTERNAL_PATH_ERROR = 0x300,
2218 NVME_SC_ANA_PERSISTENT_LOSS = 0x301,
2219 NVME_SC_ANA_INACCESSIBLE = 0x302,
2220 NVME_SC_ANA_TRANSITION = 0x303,
2221 NVME_SC_CTRL_PATH_ERROR = 0x360,
2222 NVME_SC_HOST_PATH_ERROR = 0x370,
2223 NVME_SC_HOST_ABORTED_CMD = 0x371,
2225 NVME_SC_MASK = 0x00ff, /* Status Code */
2226 NVME_SCT_MASK = 0x0700, /* Status Code Type */
2227 NVME_SCT_SC_MASK = NVME_SCT_MASK | NVME_SC_MASK,
2229 NVME_STATUS_CRD = 0x1800, /* Command Retry Delayed */
2230 NVME_STATUS_MORE = 0x2000,
2231 NVME_STATUS_DNR = 0x4000, /* Do Not Retry */
2234 #define NVME_SCT(status) ((status) >> 8 & 7)
2236 struct nvme_completion {
2238 * Used by Admin and Fabrics commands to return data:
2245 __le16 sq_head; /* how much of this queue may be reclaimed */
2246 __le16 sq_id; /* submission queue that generated this entry */
2247 __u16 command_id; /* of the command which completed */
2248 __le16 status; /* did the command fail, and if so, why? */
2251 #define NVME_VS(major, minor, tertiary) \
2252 (((major) << 16) | ((minor) << 8) | (tertiary))
2254 #define NVME_MAJOR(ver) ((ver) >> 16)
2255 #define NVME_MINOR(ver) (((ver) >> 8) & 0xff)
2256 #define NVME_TERTIARY(ver) ((ver) & 0xff)
2259 NVME_AEN_RESV_LOG_PAGE_AVALIABLE = 0x00,
2263 NVME_PR_LOG_EMPTY_LOG_PAGE = 0x00,
2264 NVME_PR_LOG_REGISTRATION_PREEMPTED = 0x01,
2265 NVME_PR_LOG_RESERVATION_RELEASED = 0x02,
2266 NVME_PR_LOG_RESERVATOIN_PREEMPTED = 0x03,
2270 NVME_PR_NOTIFY_BIT_REG_PREEMPTED = 1,
2271 NVME_PR_NOTIFY_BIT_RESV_RELEASED = 2,
2272 NVME_PR_NOTIFY_BIT_RESV_PREEMPTED = 3,
2275 struct nvme_pr_log {
2284 struct nvmet_pr_register_data {
2289 struct nvmet_pr_acquire_data {
2294 struct nvmet_pr_release_data {
2298 enum nvme_pr_capabilities {
2299 NVME_PR_SUPPORT_PTPL = 1,
2300 NVME_PR_SUPPORT_WRITE_EXCLUSIVE = 1 << 1,
2301 NVME_PR_SUPPORT_EXCLUSIVE_ACCESS = 1 << 2,
2302 NVME_PR_SUPPORT_WRITE_EXCLUSIVE_REG_ONLY = 1 << 3,
2303 NVME_PR_SUPPORT_EXCLUSIVE_ACCESS_REG_ONLY = 1 << 4,
2304 NVME_PR_SUPPORT_WRITE_EXCLUSIVE_ALL_REGS = 1 << 5,
2305 NVME_PR_SUPPORT_EXCLUSIVE_ACCESS_ALL_REGS = 1 << 6,
2306 NVME_PR_SUPPORT_IEKEY_VER_1_3_DEF = 1 << 7,
2309 enum nvme_pr_register_action {
2310 NVME_PR_REGISTER_ACT_REG = 0,
2311 NVME_PR_REGISTER_ACT_UNREG = 1,
2312 NVME_PR_REGISTER_ACT_REPLACE = 1 << 1,
2315 enum nvme_pr_acquire_action {
2316 NVME_PR_ACQUIRE_ACT_ACQUIRE = 0,
2317 NVME_PR_ACQUIRE_ACT_PREEMPT = 1,
2318 NVME_PR_ACQUIRE_ACT_PREEMPT_AND_ABORT = 1 << 1,
2321 enum nvme_pr_release_action {
2322 NVME_PR_RELEASE_ACT_RELEASE = 0,
2323 NVME_PR_RELEASE_ACT_CLEAR = 1,
2326 enum nvme_pr_change_ptpl {
2327 NVME_PR_CPTPL_NO_CHANGE = 0,
2328 NVME_PR_CPTPL_RESV = 1 << 30,
2329 NVME_PR_CPTPL_CLEARED = 2 << 30,
2330 NVME_PR_CPTPL_PERSIST = 3 << 30,
2333 #define NVME_PR_IGNORE_KEY (1 << 3)
2335 #endif /* _LINUX_NVME_H */