#define NVME_MAX_ADMIN_BUFFER 4096U
#define NVME_REG_CAP 0x0000
#define NVME_REG_VERS 0x0008
#define NVME_REG_INTSET 0x000C
#define NVME_REG_INTCLR 0x0010
#define NVME_REG_CONFIG 0x0014
#define NVME_REG_RESERVED_18 0x0018
#define NVME_REG_STATUS 0x001C
#define NVME_REG_SUBRESET 0x0020
#define NVME_REG_ADM_ATTR 0x0024
#define NVME_REG_ADM_SUBADR 0x0028
#define NVME_REG_ADM_COMADR 0x0030
#define NVME_REG_MEMBUF 0x0038
#define NVME_REG_MEMSIZE 0x003C
#define NVME_REG_RESERVED_40 0x0040
#define NVME_REG_CSS 0x0F00
#define NVME_REG_SUBQ_BELL(n, dstrd4) (0x1000 + ((n) * 2 + 0) * (dstrd4))
#define NVME_REG_COMQ_BELL(n, dstrd4) (0x1000 + ((n) * 2 + 1) * (dstrd4))
#define NVME_CAP_CSS_63 (0x8000000000000000LLU)
#define NVME_CAP_CSS_62 (0x4000000000000000LLU)
#define NVME_CAP_CSS_61 (0x2000000000000000LLU)
#define NVME_CAP_CSS_60 (0x1000000000000000LLU)
#define NVME_CAP_CSS_59 (0x0800000000000000LLU)
#define NVME_CAP_CSS_58 (0x0400000000000000LLU)
#define NVME_CAP_CSS_57 (0x0200000000000000LLU)
#define NVME_CAP_CSS_56 (0x0100000000000000LLU)
#define NVME_CAP_MEMPG_MAX (0x00F0000000000000LLU)
#define NVME_CAP_MEMPG_MIN (0x000F000000000000LLU)
#define NVME_CAP_RESERVED_47 (0x0000800000000000LLU)
#define NVME_CAP_RESERVED_46 (0x0000400000000000LLU)
#define NVME_CAP_RESERVED_45 (0x0000200000000000LLU)
#define NVME_CAP_CSS_44 (0x0000100000000000LLU)
#define NVME_CAP_CSS_43 (0x0000080000000000LLU)
#define NVME_CAP_CSS_42 (0x0000040000000000LLU)
#define NVME_CAP_CSS_41 (0x0000020000000000LLU)
#define NVME_CAP_CSS_40 (0x0000010000000000LLU)
#define NVME_CAP_CSS_39 (0x0000008000000000LLU)
#define NVME_CAP_CSS_38 (0x0000004000000000LLU)
#define NVME_CAP_CSS_NVM (0x0000002000000000LLU)
#define NVME_CAP_SUBRESET (0x0000001000000000LLU)
#define NVME_CAP_DSTRD_MASK (0x0000000F00000000LLU)
#define NVME_CAP_TIMEOUT (0x00000000FF000000LLU)
#define NVME_CAP_RESERVED_19 (0x0000000000F80000LLU)
#define NVME_CAP_AMS_VENDOR (0x0000000000040000LLU)
#define NVME_CAP_AMS_WRRUP (0x0000000000020000LLU)
#define NVME_CAP_CQR (0x0000000000010000LLU)
#define NVME_CAP_MQES (0x000000000000FFFFLLU)
#define NVME_CAP_MEMPG_MAX_GET(data) \
(1 << (12 + (((data) & NVME_CAP_MEMPG_MAX) >> 52)))
#define NVME_CAP_MEMPG_MIN_GET(data) \
(1 << (12 + (((data) & NVME_CAP_MEMPG_MIN) >> 48)))
#define NVME_CAP_DSTRD_GET(data) \
(4 << ((((data) & NVME_CAP_DSTRD_MASK) >> 32)))
#define NVME_CAP_TIMEOUT_GET(data) \
(((data) & NVME_CAP_TIMEOUT) >> 24)
#define NVME_CAP_MQES_GET(data) \
(((data) & NVME_CAP_MQES) + 1)
#define NVME_VERS_MAJOR (0xFFFF0000U)
#define NVME_VERS_MINOR (0x0000FF00U)
#define NVME_VERS_RESERVED_00 (0x00000000U)
#define NVME_VERS_MAJOR_GET(data) \
(((data) & NVME_VERS_MAJOR) >> 16)
#define NVME_VERS_MINOR_GET(data) \
(((data) & NVME_VERS_MINOR) >> 8)
#define NVME_CONFIG_RESERVED_24 0xFF000000U
#define NVME_CONFIG_IOCOM_ES 0x00F00000U
#define NVME_CONFIG_IOSUB_ES 0x000F0000U
#define NVME_CONFIG_IOCOM_ES_SET(pwr) ((pwr) << 20)
#define NVME_CONFIG_IOSUB_ES_SET(pwr) ((pwr) << 16)
#define NVME_CONFIG_SHUT_MASK 0x0000C000U
#define NVME_CONFIG_SHUT_NONE 0x00000000U
#define NVME_CONFIG_SHUT_NORM 0x00004000U
#define NVME_CONFIG_SHUT_EMERG 0x00008000U
#define NVME_CONFIG_SHUT_RES3 0x0000C000U
#define NVME_CONFIG_AMS_DEF 0x00000000U
#define NVME_CONFIG_AMS_WRRUP 0x00000800U
#define NVME_CONFIG_AMS_2 0x00001000U
#define NVME_CONFIG_AMS_3 0x00001800U
#define NVME_CONFIG_AMS_4 0x00002000U
#define NVME_CONFIG_AMS_5 0x00002800U
#define NVME_CONFIG_AMS_6 0x00003000U
#define NVME_CONFIG_AMS_VENDOR 0x00003800U
#define NVME_CONFIG_MEMPG 0x00000780U
#define NVME_CONFIG_CSS_MASK 0x00000070U
#define NVME_CONFIG_3 0x00000008U
#define NVME_CONFIG_2 0x00000004U
#define NVME_CONFIG_1 0x00000002U
#define NVME_CONFIG_EN 0x00000001U
#define NVME_CONFIG_CSS_NVM (0U << 4)
#define NVME_CONFIG_CSS_1 (1U << 4)
#define NVME_CONFIG_CSS_2 (2U << 4)
#define NVME_CONFIG_CSS_3 (3U << 4)
#define NVME_CONFIG_CSS_4 (4U << 4)
#define NVME_CONFIG_CSS_5 (5U << 4)
#define NVME_CONFIG_CSS_6 (6U << 4)
#define NVME_CONFIG_CSS_7 (7U << 4)
#define NVME_CONFIG_MEMPG_SET(pwr) \
(uint32_t)(((pwr) - 12) << 7)
#define NVME_STATUS_RESERVED 0xFFFFFFC0U
#define NVME_STATUS_PAUSED 0x00000020U
#define NVME_STATUS_SUBRESET 0x00000010U
#define NVME_STATUS_SHUT_MASK 0x0000000CU
#define NVME_STATUS_FATAL 0x00000002U
#define NVME_STATUS_RDY 0x00000001U
#define NVME_STATUS_SHUT_NORM 0x00000000U
#define NVME_STATUS_SHUT_INPROG 0x00000004U
#define NVME_STATUS_SHUT_DONE 0x00000008U
#define NVME_STATUS_SHUT_11 0x0000000CU
#define NVME_ATTR_RESERVED_31 0x80000000U
#define NVME_ATTR_RESERVED_30 0x40000000U
#define NVME_ATTR_RESERVED_29 0x20000000U
#define NVME_ATTR_RESERVED_28 0x10000000U
#define NVME_ATTR_COM 0x0FFF0000U
#define NVME_ATTR_RESERVED_15 0x00008000U
#define NVME_ATTR_RESERVED_14 0x00004000U
#define NVME_ATTR_RESERVED_13 0x00002000U
#define NVME_ATTR_RESERVED_12 0x00001000U
#define NVME_ATTR_SUB 0x00000FFFU
#define NVME_ATTR_COM_SET(nqe) (((nqe - 1) << 16) & NVME_ATTR_COM)
#define NVME_ATTR_SUB_SET(nqe) ((nqe - 1) & NVME_ATTR_SUB)
#define NVME_MEMBUF_OFFSET 0xFFFFF000U
#define NVME_MEMBUF_BAR 0x00000007U
#define NVME_MEMSIZE_SIZE 0xFFFFF000U
#define NVME_MEMSIZE_UNITS_MASK 0x00000F00U
#define NVME_MEMSIZE_UNITS_4K 0x00000000U
#define NVME_MEMSIZE_UNITS_64K 0x00000100U
#define NVME_MEMSIZE_UNITS_1M 0x00000200U
#define NVME_MEMSIZE_UNITS_16M 0x00000300U
#define NVME_MEMSIZE_UNITS_256M 0x00000400U
#define NVME_MEMSIZE_UNITS_4G 0x00000500U
#define NVME_MEMSIZE_UNITS_64G 0x00000600U
#define NVME_MEMSIZE_WDS 0x00000010U
#define NVME_MEMSIZE_RDS 0x00000008U
#define NVME_MEMSIZE_LISTS 0x00000004U
#define NVME_MEMSIZE_CQS 0x00000002U
#define NVME_MEMSIZE_SQS 0x00000001U
#define NVME_BELL_MASK 0x0000FFFFU
typedef struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint8_t opcode;
uint8_t flags;
uint16_t cid;
#else
uint16_t cid;
uint8_t flags;
uint8_t opcode;
#endif
uint32_t nsid;
uint32_t dw2;
uint32_t dw3;
uint64_t mptr;
uint64_t prp1;
uint64_t prp2;
} __packed nvme_subq_head_t;
#define NVME_SUBQFLG_PRP 0x00
#define NVME_SUBQFLG_SGL1 0x40
#define NVME_SUBQFLG_SGL2 0x80
#define NVME_SUBQFLG_RESERVEDS 0xC0
#define NVME_SUBQFLG_NORM 0x00
#define NVME_SUBQFLG_FUSED0 0x01
#define NVME_SUBQFLG_FUSED1 0x02
#define NVME_SUBQFLG_RESERVEDF 0x03
typedef struct {
nvme_subq_head_t head;
union {
uint32_t dw10;
uint32_t ndt;
};
union {
uint32_t dw11;
uint32_t ndm;
};
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} __packed nvme_subq_item_t;
typedef struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t subq_head_ptr;
uint16_t subq_id;
uint16_t cmd_id;
uint16_t status;
#else
uint16_t subq_id;
uint16_t subq_head_ptr;
uint16_t status;
uint16_t cmd_id;
#endif
} __packed nvme_comq_tail_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_comq_item_t;
#define NVME_COMQ_STATUS_DNR 0x8000U
#define NVME_COMQ_STATUS_MORE 0x4000U
#define NVME_COMQ_STATUS_29 0x2000U
#define NVME_COMQ_STATUS_28 0x1000U
#define NVME_COMQ_STATUS_TYPE 0x0E00U
#define NVME_COMQ_STATUS_CODE 0x01FEU
#define NVME_COMQ_STATUS_PHASE 0x0001U
#define NVME_COMQ_STATUS_TYPE_GET(data) \
(((data) & NVME_COMQ_STATUS_TYPE) >> 9)
#define NVME_COMQ_STATUS_CODE_GET(data) \
(((data) & NVME_COMQ_STATUS_CODE) >> 1)
#define NVME_STATUS_TYPE_GENERIC 0
#define NVME_STATUS_TYPE_SPECIFIC 1
#define NVME_STATUS_TYPE_MEDIA 2
#define NVME_STATUS_TYPE_3 3
#define NVME_STATUS_TYPE_4 4
#define NVME_STATUS_TYPE_5 5
#define NVME_STATUS_TYPE_6 6
#define NVME_STATUS_TYPE_VENDOR 7
#define NVME_CODE_SUCCESS 0x00
#define NVME_CODE_BADOP 0x01
#define NVME_CODE_BADFIELD 0x02
#define NVME_CODE_IDCONFLICT 0x03
#define NVME_CODE_BADXFER 0x04
#define NVME_CODE_ABORTED_PWRLOSS 0x05
#define NVME_CODE_INTERNAL 0x06
#define NVME_CODE_ABORTED_ONREQ 0x07
#define NVME_CODE_ABORTED_SQDEL 0x08
#define NVME_CODE_ABORTED_FUSEFAIL 0x09
#define NVME_CODE_ABORTED_FUSEMISSING 0x0A
#define NVME_CODE_BADNAMESPACE 0x0B
#define NVME_CODE_SEQERROR 0x0C
#define NVME_CODE_BADSGLSEG 0x0D
#define NVME_CODE_BADSGLCNT 0x0E
#define NVME_CODE_BADSGLLEN 0x0F
#define NVME_CODE_BADSGLMLEN 0x10
#define NVME_CODE_BADSGLTYPE 0x11
#define NVME_CODE_BADMEMBUFUSE 0x12
#define NVME_CODE_BADPRPOFF 0x13
#define NVME_CODE_ATOMICWUOVFL 0x14
#define NVME_CODE_LBA_RANGE 0x80
#define NVME_CODE_CAP_EXCEEDED 0x81
#define NVME_CODE_NAM_NOT_READY 0x82
#define NVME_CODE_RSV_CONFLICT 0x83
#define NVME_CODE_FMT_IN_PROG 0x84
#define NVME_CSSCODE_BADCOMQ 0x00
#define NVME_CSSCODE_BADQID 0x01
#define NVME_CSSCODE_BADQSIZE 0x02
#define NVME_CSSCODE_ABORTLIM 0x03
#define NVME_CSSCODE_RESERVED04 0x04
#define NVME_CSSCODE_ASYNCEVENTLIM 0x05
#define NVME_CSSCODE_BADFWSLOT 0x06
#define NVME_CSSCODE_BADFWIMAGE 0x07
#define NVME_CSSCODE_BADINTRVECT 0x08
#define NVME_CSSCODE_BADLOGPAGE 0x09
#define NVME_CSSCODE_BADFORMAT 0x0A
#define NVME_CSSCODE_FW_NEEDSCONVRESET 0x0B
#define NVME_CSSCODE_BADQDELETE 0x0C
#define NVME_CSSCODE_FEAT_NOT_SAVEABLE 0x0D
#define NVME_CSSCODE_FEAT_NOT_CHGABLE 0x0E
#define NVME_CSSCODE_FEAT_NOT_NSSPEC 0x0F
#define NVME_CSSCODE_FW_NEEDSSUBRESET 0x10
#define NVME_CSSCODE_FW_NEEDSRESET 0x11
#define NVME_CSSCODE_FW_NEEDSMAXTVIOLATE 0x12
#define NVME_CSSCODE_FW_PROHIBITED 0x13
#define NVME_CSSCODE_RANGE_OVERLAP 0x14
#define NVME_CSSCODE_NAM_INSUFF_CAP 0x15
#define NVME_CSSCODE_NAM_ID_UNAVAIL 0x16
#define NVME_CSSCODE_RESERVED17 0x17
#define NVME_CSSCODE_NAM_ALREADY_ATT 0x18
#define NVME_CSSCODE_NAM_IS_PRIVATE 0x19
#define NVME_CSSCODE_NAM_NOT_ATT 0x1A
#define NVME_CSSCODE_NO_THIN_PROVISION 0x1B
#define NVME_CSSCODE_CTLR_LIST_INVALID 0x1C
#define NVME_CSSCODE_ATTR_CONFLICT 0x80
#define NVME_CSSCODE_BADPROTINFO 0x81
#define NVME_CSSCODE_WRITE_TO_RDONLY 0x82
#define NVME_MEDCODE_WRITE_FAULT 0x80
#define NVME_MEDCODE_UNRECOV_READ_ERROR 0x81
#define NVME_MEDCODE_ETOE_GUARD_CHK 0x82
#define NVME_MEDCODE_ETOE_APPTAG_CHK 0x83
#define NVME_MEDCODE_ETOE_REFTAG_CHK 0x84
#define NVME_MEDCODE_COMPARE_FAILURE 0x85
#define NVME_MEDCODE_ACCESS_DENIED 0x86
#define NVME_MEDCODE_UNALLOCATED 0x87
#define NVME_OP_DELETE_SUBQ 0x00
#define NVME_OP_CREATE_SUBQ 0x01
#define NVME_OP_GET_LOG_PAGE 0x02
#define NVME_OP_DELETE_COMQ 0x04
#define NVME_OP_CREATE_COMQ 0x05
#define NVME_OP_IDENTIFY 0x06
#define NVME_OP_ABORT 0x08
#define NVME_OP_SET_FEATURES 0x09
#define NVME_OP_GET_FEATURES 0x0A
#define NVME_OP_ASY_EVENT_REQ 0x0C
#define NVME_OP_NAM_MANAGE 0x0D
#define NVME_OP_FW_COMMIT 0x10
#define NVME_OP_FW_DOWNLOAD 0x11
#define NVME_OP_NAM_ATTACH 0x15
#define NVME_OP_FORMATNVM 0x80
#define NVME_OP_SEC_SEND 0x81
#define NVME_OP_SEC_RECV 0x82
typedef struct {
nvme_subq_head_t head;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t subq_id;
uint16_t cmd_id;
#else
uint16_t cmd_id;
uint16_t subq_id;
#endif
uint32_t reserved11;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_abort_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_abort_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t reserved10;
uint32_t reserved11;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_async_cmd_t;
typedef struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint8_t type;
uint8_t info;
uint8_t lid;
uint8_t reserved03;
#else
uint8_t reserved03;
uint8_t lid;
uint8_t info;
uint8_t type;
#endif
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_async_res_t;
#define NVME_ASYNC_TYPE_MASK 0x07
#define NVME_ASYNC_TYPE_ERROR 0x00
#define NVME_ASYNC_TYPE_SMART 0x01
#define NVME_ASYNC_TYPE_NOTICE 0x02
#define NVME_ASYNC_TYPE_RESERVED3 0x03
#define NVME_ASYNC_TYPE_RESERVED4 0x04
#define NVME_ASYNC_TYPE_RESERVED5 0x05
#define NVME_ASYNC_TYPE_CSS 0x06
#define NVME_ASYNC_TYPE_VENDOR 0x07
#define NVME_ASYNC_INFO_INVDOORBELL 0x00
#define NVME_ASYNC_INFO_INVDOORVALUE 0x01
#define NVME_ASYNC_INFO_DIAGFAIL 0x02
#define NVME_ASYNC_INFO_INTRNL_FATAL 0x03
#define NVME_ASYNC_INFO_INTRNL_TRANS 0x04
#define NVME_ASYNC_INFO_FIRMLOADERR 0x05
#define NVME_ASYNC_INFO_UNRELIABLE 0x00
#define NVME_ASYNC_INFO_TEMP_THR 0x01
#define NVME_ASYNC_INFO_SPARE_BELOW_THR 0x02
#define NVME_ASYNC_INFO_NAM_ATTR_CHG 0x00
#define NVME_ASYNC_INFO_FW_ACT_START 0x01
#define NVME_ASYNC_INFO_RES_LOGPG_AVAIL 0x00
typedef struct {
nvme_subq_head_t head;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t comq_id;
uint16_t comq_size;
uint16_t flags;
uint16_t ivect;
#else
uint16_t comq_size;
uint16_t comq_id;
uint16_t ivect;
uint16_t flags;
#endif
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_createcomq_cmd_t;
#define NVME_CREATECOM_IEN 0x0002
#define NVME_CREATECOM_PC 0x0001
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_createcomq_res_t;
typedef struct {
nvme_subq_head_t head;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t subq_id;
uint16_t subq_size;
uint16_t flags;
uint16_t comq_id;
#else
uint16_t subq_size;
uint16_t subq_id;
uint16_t comq_id;
uint16_t flags;
#endif
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_createsubq_cmd_t;
#define NVME_CREATESUB_PRI 0x0006
#define NVME_CREATESUB_PRI_LOW 0x0006
#define NVME_CREATESUB_PRI_MED 0x0004
#define NVME_CREATESUB_PRI_HIG 0x0002
#define NVME_CREATESUB_PRI_URG 0x0000
#define NVME_CREATESUB_PC 0x0001
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_createsubq_res_t;
typedef struct {
nvme_subq_head_t head;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t qid;
uint16_t reserved02;
#else
uint16_t reserved02;
uint16_t qid;
#endif
uint32_t reserved11;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_deleteq_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_deleteq_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t flags;
uint32_t reserved11;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_getfeat_cmd_t;
#define NVME_GETFEAT_ID_MASK 0x000000FFU
#define NVME_GETFEAT_SEL_MASK 0x00000700U
#define NVME_GETFEAT_SEL_CUR 0x00000000U
#define NVME_GETFEAT_SEL_DEF 0x00000100U
#define NVME_GETFEAT_SEL_SAV 0x00000200U
#define NVME_GETFEAT_SEL_SUP 0x00000300U
#define NVME_GETFEAT_SEL_4 0x00000400U
#define NVME_GETFEAT_SEL_5 0x00000500U
#define NVME_GETFEAT_SEL_6 0x00000600U
#define NVME_GETFEAT_SEL_7 0x00000700U
typedef struct {
uint32_t cap;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_getfeat_res_t;
#define NVME_GETFEAT_CAP_SAVEABLE 0x00000001U
#define NVME_GETFEAT_CAP_NAM_SPECIFIC 0x00000002U
#define NVME_GETFEAT_CAP_CHANGEABLE 0x00000004U
typedef struct {
nvme_subq_head_t head;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint8_t lid;
uint8_t reserved01;
uint16_t numdl;
uint16_t numdu;
uint16_t reserved02;
#else
uint16_t numdl;
uint8_t reserved01;
uint8_t lid;
uint16_t reserved02;
uint16_t numdu;
#endif
uint32_t lpol;
uint32_t lpou;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_getlog_cmd_t;
#define NVME_GETLOGPG_NUMD_MASK 0x0FFF
#define NVME_LID_00 0x00
#define NVME_LID_ERROR 0x01
#define NVME_LID_SMART 0x02
#define NVME_LID_FWSLOT 0x03
#define NVME_LID_NAM_CHG_LIST 0x04
#define NVME_LID_CMDEFF 0x05
#define NVME_LID_RES_NOTIFY 0x80
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_getlog_res_t;
typedef struct {
nvme_subq_head_t head;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint8_t cns;
uint8_t reserved01;
uint16_t cntid;
#else
uint16_t cntid;
uint8_t reserved01;
uint8_t cns;
#endif
uint32_t reserved11;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_identify_cmd_t;
#define NVME_CNS_ACT_NS 0x00
#define NVME_CNS_CTLR 0x01
#define NVME_CNS_ACT_NSLIST 0x02
#define NVME_CNS_ALO_NSLIST 0x10
#define NVME_CNS_ALO_NS 0x11
#define NVME_CNS_ATT_CTLR_LIST 0x12
#define NVME_CNS_ANY_CTLR_LIST 0x13
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_identify_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t sel;
uint32_t reserved11;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_nsatt_cmd_t;
#define NVME_NSATT_SEL_MASK 0x0000000FU
#define NVME_NSATT_SEL_GET(data) \
((data) & NVME_NSATT_SEL_MASK)
#define NVME_NSATT_SEL_ATTACH 0
#define NVME_NSATT_SEL_DETACH 1
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_nsatt_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t sel;
uint32_t reserved11;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_nsmgmt_cmd_t;
#define NVME_NSMGMT_SEL_MASK 0x0000000FU
#define NVME_NSMGMT_SEL_GET(data) \
((data) & NVME_NSMGMT_SEL_MASK)
#define NVME_NSMGMT_SEL_CREATE 0
#define NVME_NSMGMT_SEL_DELETE 1
typedef struct {
uint32_t nsid;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_nsmgmt_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t flags;
union {
struct {
uint32_t dw11;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
};
struct {
uint8_t burst;
uint8_t lpw;
uint8_t mpw;
uint8_t hpw;
} arb;
#define NVME_ARB_BURST_MASK 0x07
#define NVME_ARB_BURST_MAX 0x07
struct {
uint8_t xflags;
uint8_t reserved01;
uint8_t reserved02;
uint8_t reserved03;
} pwrmgmt;
#define NVME_PWRMGMT_PS_MASK 0x1F;
#define NVME_PWRMGMT_WH_MASK 0xE0;
#define NVME_PWRMGMT_PS_SET(data) ((data) & NVME_PWRMGMT_PS_MASK)
#define NVME_PWRMGMT_WH_SET(data) (((data) << 5) & NVME_PWRMGMT_WH_MASK)
struct {
uint32_t xflags;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} lbarng;
#define NVME_LBARNG_NUM_MASK 0x0000003FU
struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t tmpth;
uint16_t xflags;
#else
uint16_t xflags;
uint16_t tmpth;
#endif
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} tempth;
#define NVME_TEMPTH_SEL_MASK 0x000FU
#define NVME_TEMPTH_TYPE_MASK 0x0030U
#define NVME_TEMPTH_TYPE_OVER 0x0000U
#define NVME_TEMPTH_TYPE_UNDER 0x0010U
#define NVME_TEMPTH_TYPE_2 0x0020U
#define NVME_TEMPTH_TYPE_3 0x0030U
struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t tler;
uint16_t xflags;
#else
uint16_t xflags;
uint16_t tler;
#endif
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} errrec;
#define NVME_ERRREC_DEALLOCERR 0x0001U
struct {
uint32_t xflags;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} volatilewc;
#define NVME_VOLATILEWC_ENABLE 0x0001U
struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t nsqr;
uint16_t ncqr;
#else
uint16_t ncqr;
uint16_t nsqr;
#endif
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} numqs;
struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint8_t thr;
uint8_t time;
uint16_t reserved02;
#else
uint16_t reserved02;
uint8_t time;
uint8_t thr;
#endif
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} intcoal;
struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t iv;
uint16_t xflags;
#else
uint16_t xflags;
uint16_t iv;
#endif
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} intvect;
#define NVME_INTVECT_CD 0x0001U
struct {
uint32_t xflags;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} wratom;
#define NVME_WRATOM_DN 0x00000001U
struct {
uint32_t xflags;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} asyncev;
#define NVME_ASYNCEV_SMART_MASK 0x000000FFU
#define NVME_ASYNCEV_NS_ATTR 0x00000100U
#define NVME_ASYNCEV_FW_ACTVTE 0x00000200U
struct {
uint32_t xflags;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} autops;
#define NVME_AUTOPS_ENABLE 0x00000001U
struct {
uint32_t xflags;
uint32_t sizepgs;
uint32_t hmdlla;
uint32_t hmdlua;
uint32_t count;
} hostmem;
#define NVME_HOSTMEM_RETURN 0x00000002U
#define NVME_HOSTMEM_ENABLE 0x00000001U
struct {
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint8_t pbslc;
uint8_t reserved01;
uint8_t reserved02;
uint8_t reserved03;
#else
uint8_t reserved03;
uint8_t reserved02;
uint8_t reserved01;
uint8_t pbslc;
#endif
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} sftprog;
struct {
uint32_t dw11;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} hostid;
struct {
uint32_t xflags;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} resnotify;
#define NVME_RESNOTIFY_RESPRE 0x00000008U
#define NVME_RESNOTIFY_RESREL 0x00000004U
#define NVME_RESNOTIFY_REGPRE 0x00000002U
struct {
uint32_t xflags;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} respersist;
#define NVME_RESPERSIST_PTPL 0x00000001U
};
} __packed nvme_setfeat_cmd_t;
#define NVME_SETFEAT_SAVE 0x80000000U
#define NVME_FID_MASK 0x000000FFU
#define NVME_FID_GET(data) \
((data) & NVME_FID_MASK)
#define NVME_FID_SET(fid) \
((fid) & NVME_FID_MASK)
#define NVME_FID_00 0x00
#define NVME_FID_ARB 0x01
#define NVME_FID_PWRMGMT 0x02
#define NVME_FID_LBARNGTYPE 0x03
#define NVME_FID_TEMPTHRESH 0x04
#define NVME_FID_ERRORRECOVERY 0x05
#define NVME_FID_VOLATILEWC 0x06
#define NVME_FID_NUMQUEUES 0x07
#define NVME_FID_INTCOALESCE 0x08
#define NVME_FID_INTVECTOR 0x09
#define NVME_FID_WRATOMICYNRM 0x0A
#define NVME_FID_ASYNCEVCFG 0x0B
#define NVME_FID_AUTOPS 0x0C
#define NVME_FID_HOSTMEMBUF 0x0D
#define NVME_FID_SFTPROGRESS 0x80
#define NVME_FID_HOSTID 0x81
#define NVME_FID_RESERVENOTMASK 0x82
#define NVME_FID_RESERVEPERSIST 0x83
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_setfeat_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t flags;
uint32_t reserved11;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_format_cmd_t;
#define NVME_FORMAT_SES_MASK 0x00000E00U
#define NVME_FORMAT_SES_NONE 0x00000000U
#define NVME_FORMAT_SES_NORM 0x00000200U
#define NVME_FORMAT_SES_CRYPTO 0x00000400U
#define NVME_FORMAT_PROT_FIRST 0x00000100U
#define NVME_FORMAT_PROT_MASK 0x000000E0U
#define NVME_FORMAT_PROT_NONE 0x00000000U
#define NVME_FORMAT_PROT_TYPE1 0x00000020U
#define NVME_FORMAT_PROT_TYPE2 0x00000040U
#define NVME_FORMAT_PROT_TYPE3 0x00000060U
#define NVME_FORMAT_MS 0x00000010U
#define NVME_FORMAT_LBA_FMT_MASK 0x0000000FU
#define NVME_FORMAT_LBA_FMT_SET(data) \
((data) & NVME_FORMAT_LBA_FMT_MASK)
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_format_res_t;
typedef struct {
nvme_subq_head_t head;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint8_t nssf;
uint8_t spsp0;
uint8_t spsp1;
uint8_t secp;
#else
uint8_t secp;
uint8_t spsp1;
uint8_t spsp0;
uint8_t nssf;
#endif
uint32_t alloc_len;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_secrecv_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_secrecv_res_t;
typedef struct {
nvme_subq_head_t head;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint8_t nssf;
uint8_t spsp0;
uint8_t spsp1;
uint8_t secp;
#else
uint8_t secp;
uint8_t spsp1;
uint8_t spsp0;
uint8_t nssf;
#endif
uint32_t xfer_len;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_secsend_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_secsend_res_t;
#define NVME_IOCMD_FLUSH 0x00
#define NVME_IOCMD_WRITE 0x01
#define NVME_IOCMD_READ 0x02
#define NVME_IOCMD_WRITEUC 0x04
#define NVME_IOCMD_COMPARE 0x05
#define NVME_IOCMD_WRITEZ 0x08
#define NVME_IOCMD_DATAMGMT 0x09
#define NVME_IOCMD_RESREG 0x0D
#define NVME_IOCMD_RESREP 0x0E
#define NVME_IOCMD_RESACQ 0x11
#define NVME_IOCMD_RESREL 0x15
#define NVME_IOFLG_LR 0x8000U
#define NVME_IOFLG_FUA 0x4000U
#define NVME_IOFLG_PRINFO_MASK 0x3C00U
#define NVME_IOFLG_RESV_MASK 0x03FFU
#define NVME_DSM_INCOMPRESSIBLE 0x00000080U
#define NVME_DSM_SEQREQ 0x00000040U
#define NVME_DSM_ACCLAT_MASK 0x00000030U
#define NVME_DSM_ACCLAT_UNSPEC 0x00000000U
#define NVME_DSM_ACCLAT_IDLE 0x00000010U
#define NVME_DSM_ACCLAT_NORM 0x00000020U
#define NVME_DSM_ACCLAT_LOW 0x00000030U
#define NVME_DSM_ACCFREQ_MASK 0x0000000FU
#define NVME_DSM_ACCFREQ_UNSPEC 0x00000000U
#define NVME_DSM_ACCFREQ_WRTYP 0x00000001U
#define NVME_DSM_ACCFREQ_WRLOW 0x00000002U
#define NVME_DSM_ACCFREQ_WLORHI 0x00000003U
#define NVME_DSM_ACCFREQ_WHIRLO 0x00000004U
#define NVME_DSM_ACCFREQ_WHIRHI 0x00000005U
#define NVME_DSM_ACCFREQ_RONETM 0x00000006U
#define NVME_DSM_ACCFREQ_RSPECU 0x00000007U
#define NVME_DSM_ACCFREQ_OVERWR 0x00000008U
typedef struct {
nvme_subq_head_t head;
uint32_t reserved10;
uint32_t reserved11;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_flush_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_flush_res_t;
typedef struct {
nvme_subq_head_t head;
uint64_t start_lba;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t count_lba;
uint16_t ioflags;
#else
uint16_t ioflags;
uint16_t count_lba;
#endif
uint32_t dsm;
uint32_t iilbrt;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t lbat;
uint16_t lbatm;
#else
uint16_t lbatm;
uint16_t lbat;
#endif
} __packed nvme_write_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_write_res_t;
typedef struct {
nvme_subq_head_t head;
uint64_t start_lba;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t count_lba;
uint16_t ioflags;
#else
uint16_t ioflags;
uint16_t count_lba;
#endif
uint32_t dsm;
uint32_t eilbrt;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t elbat;
uint16_t elbatm;
#else
uint16_t elbatm;
uint16_t elbat;
#endif
} __packed nvme_read_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_read_res_t;
typedef struct {
nvme_subq_head_t head;
uint64_t start_lba;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t count_lba;
uint16_t reserved12l;
#else
uint16_t reserved12l;
uint16_t count_lba;
#endif
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_writeuc_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_writeuc_res_t;
typedef struct {
nvme_subq_head_t head;
uint64_t start_lba;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t count_lba;
uint16_t ioflags;
#else
uint16_t ioflags;
uint16_t count_lba;
#endif
uint32_t reserved13;
uint32_t eilbrt;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t elbat;
uint16_t elbatm;
#else
uint16_t elbatm;
uint16_t elbat;
#endif
} __packed nvme_cmp_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_cmp_res_t;
typedef struct {
nvme_subq_head_t head;
uint64_t start_lba;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t count_lba;
uint16_t ioflags;
#else
uint16_t ioflags;
uint16_t count_lba;
#endif
uint32_t dsm;
uint32_t iilbrt;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint16_t lbat;
uint16_t lbatm;
#else
uint16_t lbatm;
uint16_t lbat;
#endif
} __packed nvme_writez_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_writez_res_t;
typedef struct {
nvme_subq_head_t head;
#if _BYTE_ORDER == _LITTLE_ENDIAN
uint8_t nr;
uint8_t reserved01;
uint8_t reserved02;
uint8_t reserved03;
#else
uint8_t reserved03;
uint8_t reserved02;
uint8_t reserved01;
uint8_t nr;
#endif
uint32_t flags;
uint32_t reserved12;
uint32_t reserved13;
uint32_t reserved14;
uint32_t reserved15;
} __packed nvme_datamgmt_cmd_t;
#define NVME_DATAMGT_AD 0x00000004U
#define NVME_DATAMGT_IDW 0x00000002U
#define NVME_DATAMGT_IDR 0x00000001U
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_datamgmt_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t dw10;
uint32_t dw11;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} __packed nvme_resreg_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_resreg_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t dw10;
uint32_t dw11;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} __packed nvme_resrep_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_resrep_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t dw10;
uint32_t dw11;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} __packed nvme_resacq_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_resacq_res_t;
typedef struct {
nvme_subq_head_t head;
uint32_t dw10;
uint32_t dw11;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
} __packed nvme_resrel_cmd_t;
typedef struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
} __packed nvme_resrel_res_t;
typedef union {
struct {
nvme_subq_head_t head;
uint32_t dw10;
uint32_t dw11;
uint32_t dw12;
uint32_t dw13;
uint32_t dw14;
uint32_t dw15;
};
nvme_subq_item_t item;
nvme_abort_cmd_t abort;
nvme_async_cmd_t async;
nvme_createcomq_cmd_t crcom;
nvme_createsubq_cmd_t crsub;
nvme_deleteq_cmd_t delete;
nvme_getfeat_cmd_t getfeat;
nvme_getlog_cmd_t getlog;
nvme_identify_cmd_t identify;
nvme_nsatt_cmd_t nsatt;
nvme_nsmgmt_cmd_t nsmgmt;
nvme_setfeat_cmd_t setfeat;
nvme_format_cmd_t format;
nvme_secrecv_cmd_t secrecv;
nvme_secsend_cmd_t secsend;
nvme_flush_cmd_t flush;
nvme_write_cmd_t write;
nvme_read_cmd_t read;
nvme_writeuc_cmd_t writeuc;
nvme_cmp_cmd_t cmp;
nvme_writez_cmd_t writez;
nvme_datamgmt_cmd_t datamgmt;
nvme_resreg_cmd_t resreg;
nvme_resrep_cmd_t resrep;
nvme_resacq_cmd_t resacq;
nvme_resrel_cmd_t resrel;
} __packed nvme_allcmd_t;
typedef union {
struct {
uint32_t dw0;
uint32_t dw1;
nvme_comq_tail_t tail;
};
nvme_comq_item_t item;
nvme_async_res_t async;
nvme_createcomq_res_t crcom;
nvme_createsubq_res_t crsub;
nvme_deleteq_res_t delete;
nvme_getfeat_res_t getfeat;
nvme_getlog_res_t getlog;
nvme_identify_res_t identify;
nvme_nsatt_res_t nsatt;
nvme_nsmgmt_res_t nsmgmt;
nvme_setfeat_res_t setfeat;
nvme_format_res_t format;
nvme_secrecv_res_t secrecv;
nvme_secsend_res_t secsend;
nvme_flush_res_t flush;
nvme_write_res_t write;
nvme_read_res_t read;
nvme_writeuc_res_t writeuc;
nvme_cmp_res_t cmp;
nvme_writez_res_t writez;
nvme_datamgmt_res_t datamgmt;
nvme_resreg_res_t resreg;
nvme_resrep_res_t resrep;
nvme_resacq_res_t resacq;
nvme_resrel_res_t resrel;
} __packed nvme_allres_t;
typedef union {
nvme_pwstate_data_t pwstate;
nvme_lba_fmt_data_t lbafmt;
nvme_ident_ctlr_data_t idctlr;
nvme_ident_ns_data_t idns;
nvme_ident_ns_list_t nslist;
nvme_ident_ctlr_list_t ctlrlist;
nvme_log_error_data_t logerr[64];
nvme_log_smart_data_t logsmart;
nvme_fw_slot_data_t fwslot;
nvme_nsmgmt_create_data_t nsmgmt;
nvme_cmdeff_data_t cmdeff;
nvme_resnotify_data_t resnotify;
} __packed nvme_admin_data_t;