docs: expand description for interval-based bw and iops statistics
[fio.git] / engines / nvme.h
CommitLineData
b3d5e3fd
AK
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
17struct 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
3d05e0ff
AK
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
16be6037
AK
51#define NVME_ATTRIBUTE_DEALLOCATE (1 << 2)
52
b3d5e3fd 53enum nvme_identify_cns {
3d05e0ff
AK
54 NVME_IDENTIFY_CNS_NS = 0x00,
55 NVME_IDENTIFY_CNS_CSI_NS = 0x05,
56 NVME_IDENTIFY_CNS_CSI_CTRL = 0x06,
b3d5e3fd
AK
57};
58
59enum nvme_csi {
60 NVME_CSI_NVM = 0,
61 NVME_CSI_KV = 1,
62 NVME_CSI_ZNS = 2,
63};
64
65enum nvme_admin_opcode {
66 nvme_admin_identify = 0x06,
67};
68
69enum nvme_io_opcode {
70 nvme_cmd_write = 0x01,
71 nvme_cmd_read = 0x02,
16be6037 72 nvme_cmd_dsm = 0x09,
a7e8aae0 73 nvme_cmd_io_mgmt_recv = 0x12,
3d05e0ff
AK
74 nvme_zns_cmd_mgmt_send = 0x79,
75 nvme_zns_cmd_mgmt_recv = 0x7a,
76};
77
78enum nvme_zns_zs {
79 NVME_ZNS_ZS_EMPTY = 0x1,
80 NVME_ZNS_ZS_IMPL_OPEN = 0x2,
81 NVME_ZNS_ZS_EXPL_OPEN = 0x3,
82 NVME_ZNS_ZS_CLOSED = 0x4,
83 NVME_ZNS_ZS_READ_ONLY = 0xd,
84 NVME_ZNS_ZS_FULL = 0xe,
85 NVME_ZNS_ZS_OFFLINE = 0xf,
b3d5e3fd
AK
86};
87
88struct nvme_data {
89 __u32 nsid;
90 __u32 lba_shift;
91};
92
93struct nvme_lbaf {
94 __le16 ms;
95 __u8 ds;
96 __u8 rp;
97};
98
99struct nvme_id_ns {
100 __le64 nsze;
101 __le64 ncap;
102 __le64 nuse;
103 __u8 nsfeat;
104 __u8 nlbaf;
105 __u8 flbas;
106 __u8 mc;
107 __u8 dpc;
108 __u8 dps;
109 __u8 nmic;
110 __u8 rescap;
111 __u8 fpi;
112 __u8 dlfeat;
113 __le16 nawun;
114 __le16 nawupf;
115 __le16 nacwu;
116 __le16 nabsn;
117 __le16 nabo;
118 __le16 nabspf;
119 __le16 noiob;
120 __u8 nvmcap[16];
121 __le16 npwg;
122 __le16 npwa;
123 __le16 npdg;
124 __le16 npda;
125 __le16 nows;
126 __le16 mssrl;
127 __le32 mcl;
128 __u8 msrc;
129 __u8 rsvd81[11];
130 __le32 anagrpid;
131 __u8 rsvd96[3];
132 __u8 nsattr;
133 __le16 nvmsetid;
134 __le16 endgid;
135 __u8 nguid[16];
136 __u8 eui64[8];
137 struct nvme_lbaf lbaf[16];
138 __u8 rsvd192[192];
139 __u8 vs[3712];
140};
141
142static inline int ilog2(uint32_t i)
143{
144 int log = -1;
145
146 while (i) {
147 i >>= 1;
148 log++;
149 }
150 return log;
151}
152
3d05e0ff
AK
153struct nvme_zns_lbafe {
154 __le64 zsze;
155 __u8 zdes;
156 __u8 rsvd9[7];
157};
158
159struct nvme_zns_id_ns {
160 __le16 zoc;
161 __le16 ozcs;
162 __le32 mar;
163 __le32 mor;
164 __le32 rrl;
165 __le32 frl;
166 __le32 rrl1;
167 __le32 rrl2;
168 __le32 rrl3;
169 __le32 frl1;
170 __le32 frl2;
171 __le32 frl3;
172 __le32 numzrwa;
173 __le16 zrwafg;
174 __le16 zrwasz;
175 __u8 zrwacap;
176 __u8 rsvd53[2763];
177 struct nvme_zns_lbafe lbafe[64];
178 __u8 vs[256];
179};
180
181struct nvme_zns_desc {
182 __u8 zt;
183 __u8 zs;
184 __u8 za;
185 __u8 zai;
186 __u8 rsvd4[4];
187 __le64 zcap;
188 __le64 zslba;
189 __le64 wp;
190 __u8 rsvd32[32];
191};
192
193struct nvme_zone_report {
194 __le64 nr_zones;
195 __u8 rsvd8[56];
196 struct nvme_zns_desc entries[];
197};
198
a7e8aae0
KB
199struct nvme_fdp_ruh_status_desc {
200 __u16 pid;
201 __u16 ruhid;
202 __u32 earutr;
203 __u64 ruamw;
204 __u8 rsvd16[16];
205};
206
207struct nvme_fdp_ruh_status {
208 __u8 rsvd0[14];
209 __le16 nruhsd;
210 struct nvme_fdp_ruh_status_desc ruhss[];
211};
212
16be6037
AK
213struct nvme_dsm_range {
214 __le32 cattr;
215 __le32 nlb;
216 __le64 slba;
217};
218
219int fio_nvme_trim(const struct thread_data *td, struct fio_file *f,
220 unsigned long long offset, unsigned long long len);
221
a7e8aae0
KB
222int fio_nvme_iomgmt_ruhs(struct thread_data *td, struct fio_file *f,
223 struct nvme_fdp_ruh_status *ruhs, __u32 bytes);
224
b3d5e3fd
AK
225int fio_nvme_get_info(struct fio_file *f, __u32 *nsid, __u32 *lba_sz,
226 __u64 *nlba);
227
228int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u,
229 struct iovec *iov);
230
3d05e0ff
AK
231int fio_nvme_get_zoned_model(struct thread_data *td, struct fio_file *f,
232 enum zbd_zoned_model *model);
233
234int fio_nvme_report_zones(struct thread_data *td, struct fio_file *f,
235 uint64_t offset, struct zbd_zone *zbdz,
236 unsigned int nr_zones);
237
238int fio_nvme_reset_wp(struct thread_data *td, struct fio_file *f,
239 uint64_t offset, uint64_t length);
240
241int fio_nvme_get_max_open_zones(struct thread_data *td, struct fio_file *f,
242 unsigned int *max_open_zones);
243
b3d5e3fd 244#endif