2 * nvme structure declarations and helper functions for the
9 #include <linux/nvme_ioctl.h>
13 * If the uapi headers installed on the system lacks nvme uring command
14 * support, use the local version to prevent compilation issues.
16 #ifndef CONFIG_NVME_URING_CMD
17 struct nvme_uring_cmd {
38 #define NVME_URING_CMD_IO _IOWR('N', 0x80, struct nvme_uring_cmd)
39 #define NVME_URING_CMD_IO_VEC _IOWR('N', 0x81, struct nvme_uring_cmd)
40 #endif /* CONFIG_NVME_URING_CMD */
42 #define NVME_DEFAULT_IOCTL_TIMEOUT 0
43 #define NVME_IDENTIFY_DATA_SIZE 4096
44 #define NVME_IDENTIFY_CSI_SHIFT 24
45 #define NVME_NQN_LENGTH 256
47 #define NVME_PI_APP_DISABLE 0xFFFF
48 #define NVME_PI_REF_DISABLE 0xFFFFFFFF
50 #define NVME_ZNS_ZRA_REPORT_ZONES 0
51 #define NVME_ZNS_ZRAS_FEAT_ERZ (1 << 16)
52 #define NVME_ZNS_ZSA_RESET 0x4
53 #define NVME_ZONE_TYPE_SEQWRITE_REQ 0x2
55 #define NVME_ATTRIBUTE_DEALLOCATE (1 << 2)
57 enum nvme_identify_cns {
58 NVME_IDENTIFY_CNS_NS = 0x00,
59 NVME_IDENTIFY_CNS_CTRL = 0x01,
60 NVME_IDENTIFY_CNS_CSI_NS = 0x05,
61 NVME_IDENTIFY_CNS_CSI_CTRL = 0x06,
70 enum nvme_admin_opcode {
71 nvme_admin_identify = 0x06,
75 nvme_cmd_write = 0x01,
78 nvme_cmd_io_mgmt_recv = 0x12,
79 nvme_zns_cmd_mgmt_send = 0x79,
80 nvme_zns_cmd_mgmt_recv = 0x7a,
84 NVME_ZNS_ZS_EMPTY = 0x1,
85 NVME_ZNS_ZS_IMPL_OPEN = 0x2,
86 NVME_ZNS_ZS_EXPL_OPEN = 0x3,
87 NVME_ZNS_ZS_CLOSED = 0x4,
88 NVME_ZNS_ZS_READ_ONLY = 0xd,
89 NVME_ZNS_ZS_FULL = 0xe,
90 NVME_ZNS_ZS_OFFLINE = 0xf,
93 enum nvme_id_ctrl_ctratt {
94 NVME_CTRL_CTRATT_ELBAS = 1 << 15,
98 NVME_ID_NS_NVM_STS_MASK = 0x7f,
99 NVME_ID_NS_NVM_GUARD_SHIFT = 7,
100 NVME_ID_NS_NVM_GUARD_MASK = 0x3,
104 NVME_NVM_NS_16B_GUARD = 0,
105 NVME_NVM_NS_32B_GUARD = 1,
106 NVME_NVM_NS_64B_GUARD = 2,
121 enum nvme_id_ns_dps {
122 NVME_NS_DPS_PI_NONE = 0,
123 NVME_NS_DPS_PI_TYPE1 = 1,
124 NVME_NS_DPS_PI_TYPE2 = 2,
125 NVME_NS_DPS_PI_TYPE3 = 3,
126 NVME_NS_DPS_PI_MASK = 7 << 0,
127 NVME_NS_DPS_PI_FIRST = 1 << 3,
130 enum nvme_io_control_flags {
131 NVME_IO_PRINFO_PRCHK_REF = 1U << 26,
132 NVME_IO_PRINFO_PRCHK_APP = 1U << 27,
133 NVME_IO_PRINFO_PRCHK_GUARD = 1U << 28,
134 NVME_IO_PRINFO_PRACT = 1U << 29,
137 struct nvme_pi_data {
150 /* 16 bit guard protection Information format */
151 struct nvme_16b_guard_pif {
157 /* 64 bit guard protection Information format */
158 struct nvme_64b_guard_pif {
202 struct nvme_lbaf lbaf[64];
224 struct nvme_id_ctrl {
308 char subnqn[NVME_NQN_LENGTH];
321 struct nvme_id_psd psd[32];
325 struct nvme_nvm_id_ns {
333 static inline int ilog2(uint32_t i)
344 struct nvme_zns_lbafe {
350 struct nvme_zns_id_ns {
368 struct nvme_zns_lbafe lbafe[64];
372 struct nvme_zns_desc {
384 struct nvme_zone_report {
387 struct nvme_zns_desc entries[];
390 struct nvme_fdp_ruh_status_desc {
398 struct nvme_fdp_ruh_status {
401 struct nvme_fdp_ruh_status_desc ruhss[];
404 struct nvme_dsm_range {
410 struct nvme_cmd_ext_io_opts {
416 int fio_nvme_iomgmt_ruhs(struct thread_data *td, struct fio_file *f,
417 struct nvme_fdp_ruh_status *ruhs, __u32 bytes);
419 int fio_nvme_get_info(struct fio_file *f, __u64 *nlba, __u32 pi_act,
420 struct nvme_data *data);
422 int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
423 struct iovec *iov, struct nvme_dsm_range *dsm);
425 void fio_nvme_pi_fill(struct nvme_uring_cmd *cmd, struct io_u *io_u,
426 struct nvme_cmd_ext_io_opts *opts);
428 int fio_nvme_pi_verify(struct nvme_data *data, struct io_u *io_u);
430 int fio_nvme_get_zoned_model(struct thread_data *td, struct fio_file *f,
431 enum zbd_zoned_model *model);
433 int fio_nvme_report_zones(struct thread_data *td, struct fio_file *f,
434 uint64_t offset, struct zbd_zone *zbdz,
435 unsigned int nr_zones);
437 int fio_nvme_reset_wp(struct thread_data *td, struct fio_file *f,
438 uint64_t offset, uint64_t length);
440 int fio_nvme_get_max_open_zones(struct thread_data *td, struct fio_file *f,
441 unsigned int *max_open_zones);