#ifndef _NVME_REG_H
#define _NVME_REG_H
#include <sys/nvme.h>
#pragma pack(1)
#ifdef __cplusplus
extern "C" {
#endif
#define NVME_MAX_ADMIN_QUEUE_LEN 4096
#define NVME_REG_CAP 0x0
#define NVME_REG_VS 0x8
#define NVME_REG_INTMS 0xc
#define NVME_REG_INTMC 0x10
#define NVME_REG_CC 0x14
#define NVME_REG_CSTS 0x1c
#define NVME_REG_NSSR 0x20
#define NVME_REG_AQA 0x24
#define NVME_REG_ASQ 0x28
#define NVME_REG_ACQ 0x30
#define NVME_REG_CMBLOC 0x38
#define NVME_REG_CMBSZ 0x3C
#define NVME_REG_BPINFO 0x40
#define NVME_REG_BPRSEL 0x44
#define NVME_REG_BPMBL 0x48
#define NVME_REG_SQTDBL(nvme, n) \
(0x1000 + ((2 * (n)) * nvme->n_doorbell_stride))
#define NVME_REG_CQHDBL(nvme, n) \
(0x1000 + ((2 * (n) + 1) * nvme->n_doorbell_stride))
#define NVME_CAP_CSS_NVM 1
#define NVME_CAP_AMS_WRR 1
typedef union {
struct {
uint16_t cap_mqes;
uint8_t cap_cqr:1;
uint8_t cap_ams:2;
uint8_t cap_rsvd1:5;
uint8_t cap_to;
uint16_t cap_dstrd:4;
uint16_t cap_nssrs:1;
uint16_t cap_css:8;
uint16_t cap_rsvd2:2;
uint8_t cap_bps:1;
uint8_t cap_mpsmin:4;
uint8_t cap_mpsmax:4;
uint8_t cap_rsvd3;
} b;
uint64_t r;
} nvme_reg_cap_t;
typedef union {
struct {
uint8_t vs_rsvd;
uint8_t vs_mnr;
uint16_t vs_mjr;
} b;
uint32_t r;
} nvme_reg_vs_t;
#define NVME_CC_SHN_NORMAL 1
#define NVME_CC_SHN_ABRUPT 2
typedef union {
struct {
uint16_t cc_en:1;
uint16_t cc_rsvd1:3;
uint16_t cc_css:3;
uint16_t cc_mps:4;
uint16_t cc_ams:3;
uint16_t cc_shn:2;
uint8_t cc_iosqes:4;
uint8_t cc_iocqes:4;
uint8_t cc_rsvd2;
} b;
uint32_t r;
} nvme_reg_cc_t;
#define NVME_CSTS_SHN_OCCURING 1
#define NVME_CSTS_SHN_COMPLETE 2
typedef union {
struct {
uint32_t csts_rdy:1;
uint32_t csts_cfs:1;
uint32_t csts_shst:2;
uint32_t csts_nssro:1;
uint32_t csts_pp:1;
uint32_t csts_rsvd:26;
} b;
uint32_t r;
} nvme_reg_csts_t;
#define NVME_NSSR_NSSRC 0x4e564d65
typedef uint32_t nvme_reg_nssr_t;
typedef union {
struct {
uint16_t aqa_asqs:12;
uint16_t aqa_rsvd1:4;
uint16_t aqa_acqs:12;
uint16_t aqa_rsvd2:4;
} b;
uint32_t r;
} nvme_reg_aqa_t;
typedef uint64_t nvme_reg_asq_t;
typedef uint64_t nvme_reg_acq_t;
typedef union {
struct {
uint32_t cmbloc_bir:3;
uint32_t cmbloc_rsvd:9;
uint32_t cmbloc_ofst:20;
} b;
uint32_t r;
} nvme_reg_cmbloc_t;
typedef union {
struct {
uint32_t cmbsz_sqs:1;
uint32_t cmbsz_cqs:1;
uint32_t cmbsz_lists:1;
uint32_t cmbsz_rds:1;
uint32_t cmbsz_wds:1;
uint32_t cmbsz_rsvd:3;
uint32_t cmbsz_szu:4;
uint32_t cmbsz_sz:20;
} b;
uint32_t r;
} nvme_reg_cmbsz_t;
typedef union {
struct {
uint32_t bpinfo_bpsz:15;
uint32_t bpinfo_rsvd:9;
uint32_t bpinfo_brs:2;
uint32_t bpinfo_rsvd2:5;
uint32_t bpinfo_abpid:1;
} b;
uint32_t r;
} nvme_reg_bpinfo_t;
typedef union {
struct {
uint32_t bprsel_bprsz:10;
uint32_t bprsel_bprof:20;
uint32_t bprsel_rsvd:1;
uint32_t bprsel_bpid:1;
} b;
uint32_t r;
} nvme_reg_bprsel_t;
typedef uint64_t nvme_reg_bpbml_t;
typedef union {
struct {
uint16_t sqtdbl_sqt;
uint16_t sqtdbl_rsvd;
} b;
uint32_t r;
} nvme_reg_sqtdbl_t;
typedef union {
struct {
uint16_t cqhdbl_cqh;
uint16_t cqhdbl_rsvd;
} b;
uint32_t r;
} nvme_reg_cqhdbl_t;
typedef struct {
uint64_t sgl_addr;
uint32_t sgl_len;
uint8_t sgl_rsvd[3];
uint8_t sgl_zero:4;
uint8_t sgl_type:4;
} nvme_sgl_t;
#define NVME_SGL_DATA_BLOCK 0
#define NVME_SGL_BIT_BUCKET 1
#define NVME_SGL_SEGMENT 2
#define NVME_SGL_LAST_SEGMENT 3
#define NVME_SGL_VENDOR 0xf
typedef struct {
uint8_t sqe_opc;
uint8_t sqe_fuse:2;
uint8_t sqe_rsvd:5;
uint8_t sqe_psdt:1;
uint16_t sqe_cid;
uint32_t sqe_nsid;
uint64_t sqe_rsvd1;
union {
uint64_t m_ptr;
uint64_t m_sglp;
} sqe_m;
union {
uint64_t d_prp[2];
nvme_sgl_t d_sgl;
} sqe_dptr;
uint32_t sqe_cdw10;
uint32_t sqe_cdw11;
uint32_t sqe_cdw12;
uint32_t sqe_cdw13;
uint32_t sqe_cdw14;
uint32_t sqe_cdw15;
} nvme_sqe_t;
#define NVME_OPC_DELETE_SQUEUE 0x0
#define NVME_OPC_CREATE_SQUEUE 0x1
#define NVME_OPC_GET_LOG_PAGE 0x2
#define NVME_OPC_DELETE_CQUEUE 0x4
#define NVME_OPC_CREATE_CQUEUE 0x5
#define NVME_OPC_IDENTIFY 0x6
#define NVME_OPC_ABORT 0x8
#define NVME_OPC_SET_FEATURES 0x9
#define NVME_OPC_GET_FEATURES 0xa
#define NVME_OPC_ASYNC_EVENT 0xc
#define NVME_OPC_NS_MGMT 0xd
#define NVME_OPC_FW_ACTIVATE 0x10
#define NVME_OPC_FW_IMAGE_LOAD 0x11
#define NVME_OPC_SELF_TEST 0x14
#define NVME_OPC_NS_ATTACH 0x15
#define NVME_OPC_KEEP_ALIVE 0x18
#define NVME_OPC_DIRECTIVE_SEND 0x19
#define NVME_OPC_DIRECTIVE_RECV 0x1A
#define NVME_OPC_VIRT_MGMT 0x1C
#define NVME_OPC_NVMEMI_SEND 0x1D
#define NVME_OPC_NVMEMI_RECV 0x1E
#define NVME_OPC_DB_CONFIG 0x7C
#define NVME_OPC_VENDOR_LOW 0xC0
#define NVME_OPC_VENDOR_HIGH 0xFF
#define NVME_IS_VENDOR_SPECIFIC_CMD(x) \
((x) >= NVME_OPC_VENDOR_LOW && (x) <= NVME_OPC_VENDOR_HIGH)
#define NVME_OPC_NVM_FORMAT 0x80
#define NVME_OPC_NVM_SEC_SEND 0x81
#define NVME_OPC_NVM_SEC_RECV 0x82
#define NVME_OPC_NVM_FLUSH 0x0
#define NVME_OPC_NVM_WRITE 0x1
#define NVME_OPC_NVM_READ 0x2
#define NVME_OPC_NVM_WRITE_UNC 0x4
#define NVME_OPC_NVM_COMPARE 0x5
#define NVME_OPC_NVM_WRITE_ZERO 0x8
#define NVME_OPC_NVM_DSET_MGMT 0x9
#define NVME_OPC_NVM_RESV_REG 0xd
#define NVME_OPC_NVM_RESV_REPRT 0xe
#define NVME_OPC_NVM_RESV_ACQ 0x11
#define NVME_OPC_NVM_RESV_REL 0x12
typedef struct {
uint32_t cqe_dw0;
uint32_t cqe_rsvd1;
uint16_t cqe_sqhd;
uint16_t cqe_sqid;
uint16_t cqe_cid;
nvme_cqe_sf_t cqe_sf;
} nvme_cqe_t;
#define NVME_ASYNC_TYPE_ERROR 0x0
#define NVME_ASYNC_TYPE_HEALTH 0x1
#define NVME_ASYNC_TYPE_NOTICE 0x2
#define NVME_ASYNC_TYPE_VENDOR 0x7
#define NVME_ASYNC_ERROR_INV_SQ 0x0
#define NVME_ASYNC_ERROR_INV_DBL 0x1
#define NVME_ASYNC_ERROR_DIAGFAIL 0x2
#define NVME_ASYNC_ERROR_PERSISTENT 0x3
#define NVME_ASYNC_ERROR_TRANSIENT 0x4
#define NVME_ASYNC_ERROR_FW_LOAD 0x5
#define NVME_ASYNC_HEALTH_RELIABILITY 0x0
#define NVME_ASYNC_HEALTH_TEMPERATURE 0x1
#define NVME_ASYNC_HEALTH_SPARE 0x2
#define NVME_ASYNC_NOTICE_NS_CHANGE 0x0
#define NVME_ASYNC_NOTICE_FW_ACTIVATE 0x1
#define NVME_ASYNC_NOTICE_TELEMETRY 0x2
#define NVME_ASYNC_NOTICE_NS_ASYMM 0x3
#define NVME_ASYNC_NOTICE_LATENCYLOG 0x4
#define NVME_ASYNC_NOTICE_LBASTATUS 0x5
#define NVME_ASYNC_NOTICE_ENDURANCELOG 0x6
typedef union {
struct {
uint8_t ae_type:3;
uint8_t ae_rsvd1:5;
uint8_t ae_info;
uint8_t ae_logpage;
uint8_t ae_rsvd2;
} b;
uint32_t r;
} nvme_async_event_t;
typedef union {
struct {
uint16_t q_qid;
uint16_t q_qsize;
} b;
uint32_t r;
} nvme_create_queue_dw10_t;
typedef union {
struct {
uint16_t cq_pc:1;
uint16_t cq_ien:1;
uint16_t cq_rsvd:14;
uint16_t cq_iv;
} b;
uint32_t r;
} nvme_create_cq_dw11_t;
typedef union {
struct {
uint16_t sq_pc:1;
uint16_t sq_qprio:2;
uint16_t sq_rsvd:13;
uint16_t sq_cqid;
} b;
uint32_t r;
} nvme_create_sq_dw11_t;
typedef union {
struct {
uint16_t ac_sqid;
uint16_t ac_cid;
} b;
uint32_t r;
} nvme_abort_cmd_t;
typedef union {
struct {
uint8_t lp_lid;
uint8_t lp_lsp:7;
uint8_t lp_rae:1;
uint16_t lp_lnumdl;
} b;
uint32_t r;
} nvme_getlogpage_dw10_t;
typedef union {
struct {
uint16_t lp_numdu;
uint16_t lp_lsi;
} b;
uint32_t r;
} nvme_getlogpage_dw11_t;
typedef union {
struct {
uint8_t lp_uuid:7;
uint8_t lp_rsvd1:1;
uint8_t lp_rsvd2;
uint8_t lp_rsvd3:7;
uint8_t lp_ot:1;
uint8_t lp_csi;
} b;
uint32_t r;
} nvme_getlogpage_dw14_t;
#define NVME_DSET_MGMT_ATTR_OPT_READ 0x01
#define NVME_DSET_MGMT_ATTR_OPT_WRITE 0x02
#define NVME_DSET_MGMT_ATTR_DEALLOCATE 0x04
#define NVME_DSET_MGMT_MAX_RANGES 256
typedef struct {
uint32_t nr_ctxattr;
uint32_t nr_len;
uint64_t nr_lba;
} nvme_range_t;
typedef union {
struct {
uint8_t id_cns;
uint8_t id_rsvd0;
uint16_t id_cntid;
} b;
uint32_t r;
} nvme_identify_dw10_t;
typedef union {
struct {
uint32_t nsm_sel:4;
uint32_t nsm_rsvd0:28;
} b;
uint32_t r;
} nvme_ns_mgmt_dw10_t;
typedef union {
struct {
uint32_t nsm_rsvd0:24;
uint32_t nsm_csi:8;
} b;
uint32_t r;
} nvme_ns_mgmt_dw11_t;
#define NVME_NS_MGMT_NS_CREATE 0
#define NVME_NS_MGMT_NS_DELETE 1
#ifdef __cplusplus
}
#endif
#pragma pack()
#endif