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