Commit | Line | Data |
---|---|---|
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 | |
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 | enum nvme_identify_cns { | |
47 | NVME_IDENTIFY_CNS_NS = 0x00, | |
48 | }; | |
49 | ||
50 | enum nvme_csi { | |
51 | NVME_CSI_NVM = 0, | |
52 | NVME_CSI_KV = 1, | |
53 | NVME_CSI_ZNS = 2, | |
54 | }; | |
55 | ||
56 | enum nvme_admin_opcode { | |
57 | nvme_admin_identify = 0x06, | |
58 | }; | |
59 | ||
60 | enum nvme_io_opcode { | |
61 | nvme_cmd_write = 0x01, | |
62 | nvme_cmd_read = 0x02, | |
63 | }; | |
64 | ||
65 | struct nvme_data { | |
66 | __u32 nsid; | |
67 | __u32 lba_shift; | |
68 | }; | |
69 | ||
70 | struct nvme_lbaf { | |
71 | __le16 ms; | |
72 | __u8 ds; | |
73 | __u8 rp; | |
74 | }; | |
75 | ||
76 | struct nvme_id_ns { | |
77 | __le64 nsze; | |
78 | __le64 ncap; | |
79 | __le64 nuse; | |
80 | __u8 nsfeat; | |
81 | __u8 nlbaf; | |
82 | __u8 flbas; | |
83 | __u8 mc; | |
84 | __u8 dpc; | |
85 | __u8 dps; | |
86 | __u8 nmic; | |
87 | __u8 rescap; | |
88 | __u8 fpi; | |
89 | __u8 dlfeat; | |
90 | __le16 nawun; | |
91 | __le16 nawupf; | |
92 | __le16 nacwu; | |
93 | __le16 nabsn; | |
94 | __le16 nabo; | |
95 | __le16 nabspf; | |
96 | __le16 noiob; | |
97 | __u8 nvmcap[16]; | |
98 | __le16 npwg; | |
99 | __le16 npwa; | |
100 | __le16 npdg; | |
101 | __le16 npda; | |
102 | __le16 nows; | |
103 | __le16 mssrl; | |
104 | __le32 mcl; | |
105 | __u8 msrc; | |
106 | __u8 rsvd81[11]; | |
107 | __le32 anagrpid; | |
108 | __u8 rsvd96[3]; | |
109 | __u8 nsattr; | |
110 | __le16 nvmsetid; | |
111 | __le16 endgid; | |
112 | __u8 nguid[16]; | |
113 | __u8 eui64[8]; | |
114 | struct nvme_lbaf lbaf[16]; | |
115 | __u8 rsvd192[192]; | |
116 | __u8 vs[3712]; | |
117 | }; | |
118 | ||
119 | static inline int ilog2(uint32_t i) | |
120 | { | |
121 | int log = -1; | |
122 | ||
123 | while (i) { | |
124 | i >>= 1; | |
125 | log++; | |
126 | } | |
127 | return log; | |
128 | } | |
129 | ||
130 | int fio_nvme_get_info(struct fio_file *f, __u32 *nsid, __u32 *lba_sz, | |
131 | __u64 *nlba); | |
132 | ||
133 | int fio_nvme_uring_cmd_prep(struct nvme_uring_cmd *cmd, struct io_u *io_u, | |
134 | struct iovec *iov); | |
135 | ||
136 | #endif |