| 1 | /* |
| 2 | * nvme structure declarations and helper functions for the |
| 3 | * io_uring_cmd engine. |
| 4 | */ |
| 5 | |
| 6 | #ifndef FIO_NVME_H |
| 7 | #define FIO_NVME_H |
| 8 | |
| 9 | #include <linux/nvme_ioctl.h> |
| 10 | #include "../fio.h" |
| 11 | |
| 12 | /* |
| 13 | * If the uapi headers installed on the system lacks nvme uring command |
| 14 | * support, use the local version to prevent compilation issues. |
| 15 | */ |
| 16 | #ifndef CONFIG_NVME_URING_CMD |
| 17 | struct nvme_uring_cmd { |
| 18 | __u8 opcode; |
| 19 | __u8 flags; |
| 20 | __u16 rsvd1; |
| 21 | __u32 nsid; |
| 22 | __u32 cdw2; |
| 23 | __u32 cdw3; |
| 24 | __u64 metadata; |
| 25 | __u64 addr; |
| 26 | __u32 metadata_len; |
| 27 | __u32 data_len; |
| 28 | __u32 cdw10; |
| 29 | __u32 cdw11; |
| 30 | __u32 cdw12; |
| 31 | __u32 cdw13; |
| 32 | __u32 cdw14; |
| 33 | __u32 cdw15; |
| 34 | __u32 timeout_ms; |
| 35 | __u32 rsvd2; |
| 36 | }; |
| 37 | |
| 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 */ |
| 41 | |
| 42 | #define NVME_DEFAULT_IOCTL_TIMEOUT 0 |
| 43 | #define NVME_IDENTIFY_DATA_SIZE 4096 |
| 44 | #define NVME_IDENTIFY_CSI_SHIFT 24 |
| 45 | |
| 46 | #define NVME_ZNS_ZRA_REPORT_ZONES 0 |
| 47 | #define NVME_ZNS_ZRAS_FEAT_ERZ (1 << 16) |
| 48 | #define NVME_ZNS_ZSA_RESET 0x4 |
| 49 | #define NVME_ZONE_TYPE_SEQWRITE_REQ 0x2 |
| 50 | |
| 51 | enum nvme_identify_cns { |
| 52 | NVME_IDENTIFY_CNS_NS = 0x00, |
| 53 | NVME_IDENTIFY_CNS_CSI_NS = 0x05, |
| 54 | NVME_IDENTIFY_CNS_CSI_CTRL = 0x06, |
| 55 | }; |
| 56 | |
| 57 | enum nvme_csi { |
| 58 | NVME_CSI_NVM = 0, |
| 59 | NVME_CSI_KV = 1, |
| 60 | NVME_CSI_ZNS = 2, |
| 61 | }; |
| 62 | |
| 63 | enum nvme_admin_opcode { |
| 64 | nvme_admin_identify = 0x06, |
| 65 | }; |
| 66 | |
| 67 | enum nvme_io_opcode { |
| 68 | nvme_cmd_write = 0x01, |
| 69 | nvme_cmd_read = 0x02, |
| 70 | nvme_cmd_io_mgmt_recv = 0x12, |
| 71 | nvme_zns_cmd_mgmt_send = 0x79, |
| 72 | nvme_zns_cmd_mgmt_recv = 0x7a, |
| 73 | }; |
| 74 | |
| 75 | enum nvme_zns_zs { |
| 76 | NVME_ZNS_ZS_EMPTY = 0x1, |
| 77 | NVME_ZNS_ZS_IMPL_OPEN = 0x2, |
| 78 | NVME_ZNS_ZS_EXPL_OPEN = 0x3, |
| 79 | NVME_ZNS_ZS_CLOSED = 0x4, |
| 80 | NVME_ZNS_ZS_READ_ONLY = 0xd, |
| 81 | NVME_ZNS_ZS_FULL = 0xe, |
| 82 | NVME_ZNS_ZS_OFFLINE = 0xf, |
| 83 | }; |
| 84 | |
| 85 | struct nvme_data { |
| 86 | __u32 nsid; |
| 87 | __u32 lba_shift; |
| 88 | }; |
| 89 | |
| 90 | struct nvme_lbaf { |
| 91 | __le16 ms; |
| 92 | __u8 ds; |
| 93 | __u8 rp; |
| 94 | }; |
| 95 | |
| 96 | struct nvme_id_ns { |
| 97 | __le64 nsze; |
| 98 | __le64 ncap; |
| 99 | __le64 nuse; |
| 100 | __u8 nsfeat; |
| 101 | __u8 nlbaf; |
| 102 | __u8 flbas; |
| 103 | __u8 mc; |
| 104 | __u8 dpc; |
| 105 | __u8 dps; |
| 106 | __u8 nmic; |
| 107 | __u8 rescap; |
| 108 | __u8 fpi; |
| 109 | __u8 dlfeat; |
| 110 | __le16 nawun; |
| 111 | __le16 nawupf; |
| 112 | __le16 nacwu; |
| 113 | __le16 nabsn; |
| 114 | __le16 nabo; |
| 115 | __le16 nabspf; |
| 116 | __le16 noiob; |
| 117 | __u8 nvmcap[16]; |
| 118 | __le16 npwg; |
| 119 | __le16 npwa; |
| 120 | __le16 npdg; |
| 121 | __le16 npda; |
| 122 | __le16 nows; |
| 123 | __le16 mssrl; |
| 124 | __le32 mcl; |
| 125 | __u8 msrc; |
| 126 | __u8 rsvd81[11]; |
| 127 | __le32 anagrpid; |
| 128 | __u8 rsvd96[3]; |
| 129 | __u8 nsattr; |
| 130 | __le16 nvmsetid; |
| 131 | __le16 endgid; |
| 132 | __u8 nguid[16]; |
| 133 | __u8 eui64[8]; |
| 134 | struct nvme_lbaf lbaf[16]; |
| 135 | __u8 rsvd192[192]; |
| 136 | __u8 vs[3712]; |
| 137 | }; |
| 138 | |
| 139 | static inline int ilog2(uint32_t i) |
| 140 | { |
| 141 | int log = -1; |
| 142 | |
| 143 | while (i) { |
| 144 | i >>= 1; |
| 145 | log++; |
| 146 | } |
| 147 | return log; |
| 148 | } |
| 149 | |
| 150 | struct nvme_zns_lbafe { |
| 151 | __le64 zsze; |
| 152 | __u8 zdes; |
| 153 | __u8 rsvd9[7]; |
| 154 | }; |
| 155 | |
| 156 | struct nvme_zns_id_ns { |
| 157 | __le16 zoc; |
| 158 | __le16 ozcs; |
| 159 | __le32 mar; |
| 160 | __le32 mor; |
| 161 | __le32 rrl; |
| 162 | __le32 frl; |
| 163 | __le32 rrl1; |
| 164 | __le32 rrl2; |
| 165 | __le32 rrl3; |
| 166 | __le32 frl1; |
| 167 | __le32 frl2; |
| 168 | __le32 frl3; |
| 169 | __le32 numzrwa; |
| 170 | __le16 zrwafg; |
| 171 | __le16 zrwasz; |
| 172 | __u8 zrwacap; |
| 173 | __u8 rsvd53[2763]; |
| 174 | struct nvme_zns_lbafe lbafe[64]; |
| 175 | __u8 vs[256]; |
| 176 | }; |
| 177 | |
| 178 | struct nvme_zns_desc { |
| 179 | __u8 zt; |
| 180 | __u8 zs; |
| 181 | __u8 za; |
| 182 | __u8 zai; |
| 183 | __u8 rsvd4[4]; |
| 184 | __le64 zcap; |
| 185 | __le64 zslba; |
| 186 | __le64 wp; |
| 187 | __u8 rsvd32[32]; |
| 188 | }; |
| 189 | |
| 190 | struct nvme_zone_report { |
| 191 | __le64 nr_zones; |
| 192 | __u8 rsvd8[56]; |
| 193 | struct nvme_zns_desc entries[]; |
| 194 | }; |
| 195 | |
| 196 | struct nvme_fdp_ruh_status_desc { |
| 197 | __u16 pid; |
| 198 | __u16 ruhid; |
| 199 | __u32 earutr; |
| 200 | __u64 ruamw; |
| 201 | __u8 rsvd16[16]; |
| 202 | }; |
| 203 | |
| 204 | struct nvme_fdp_ruh_status { |
| 205 | __u8 rsvd0[14]; |
| 206 | __le16 nruhsd; |
| 207 | struct nvme_fdp_ruh_status_desc ruhss[]; |
| 208 | }; |
| 209 | |
| 210 | int fio_nvme_iomgmt_ruhs(struct thread_data *td, struct fio_file *f, |
| 211 | struct nvme_fdp_ruh_status *ruhs, __u32 bytes); |
| 212 | |
| 213 | int fio_nvme_get_info(struct fio_file *f, __u32 *nsid, __u32 *lba_sz, |
| 214 | __u64 *nlba); |
| 215 | |
| 216 | int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u, |
| 217 | struct iovec *iov); |
| 218 | |
| 219 | int fio_nvme_get_zoned_model(struct thread_data *td, struct fio_file *f, |
| 220 | enum zbd_zoned_model *model); |
| 221 | |
| 222 | int fio_nvme_report_zones(struct thread_data *td, struct fio_file *f, |
| 223 | uint64_t offset, struct zbd_zone *zbdz, |
| 224 | unsigned int nr_zones); |
| 225 | |
| 226 | int fio_nvme_reset_wp(struct thread_data *td, struct fio_file *f, |
| 227 | uint64_t offset, uint64_t length); |
| 228 | |
| 229 | int fio_nvme_get_max_open_zones(struct thread_data *td, struct fio_file *f, |
| 230 | unsigned int *max_open_zones); |
| 231 | |
| 232 | #endif |