1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #ifndef _UAPI_LINUX_LIGHTNVM_H
21 #define _UAPI_LINUX_LIGHTNVM_H
22
23 #ifdef __KERNEL__
24 #include <linux/kernel.h>
25 #include <linux/ioctl.h>
26 #else
27 #include <stdio.h>
28 #include <sys/ioctl.h>
29 #define DISK_NAME_LEN 32
30 #endif
31
32 #include <linux/types.h>
33 #include <linux/ioctl.h>
34
35 #define NVM_TTYPE_NAME_MAX 48
36 #define NVM_TTYPE_MAX 63
37 #define NVM_MMTYPE_LEN 8
38
39 #define NVM_CTRL_FILE "/dev/lightnvm/control"
40
41 struct nvm_ioctl_info_tgt {
42 __u32 version[3];
43 __u32 reserved;
44 char tgtname[NVM_TTYPE_NAME_MAX];
45 };
46
47 struct nvm_ioctl_info {
48 __u32 version[3];
49 __u16 tgtsize;
50 __u16 reserved16;
51 __u32 reserved[12];
52 struct nvm_ioctl_info_tgt tgts[NVM_TTYPE_MAX];
53 };
54
55 enum {
56 NVM_DEVICE_ACTIVE = 1 << 0,
57 };
58
59 struct nvm_ioctl_device_info {
60 char devname[DISK_NAME_LEN];
61 char bmname[NVM_TTYPE_NAME_MAX];
62 __u32 bmversion[3];
63 __u32 flags;
64 __u32 reserved[8];
65 };
66
67 struct nvm_ioctl_get_devices {
68 __u32 nr_devices;
69 __u32 reserved[31];
70 struct nvm_ioctl_device_info info[31];
71 };
72
73 struct nvm_ioctl_create_simple {
74 __u32 lun_begin;
75 __u32 lun_end;
76 };
77
78 struct nvm_ioctl_create_extended {
79 __u16 lun_begin;
80 __u16 lun_end;
81 __u16 op;
82 __u16 rsv;
83 };
84
85 enum {
86 NVM_CONFIG_TYPE_SIMPLE = 0,
87 NVM_CONFIG_TYPE_EXTENDED = 1,
88 };
89
90 struct nvm_ioctl_create_conf {
91 __u32 type;
92 union {
93 struct nvm_ioctl_create_simple s;
94 struct nvm_ioctl_create_extended e;
95 };
96 };
97
98 enum {
99 NVM_TARGET_FACTORY = 1 << 0,
100 };
101
102 struct nvm_ioctl_create {
103 char dev[DISK_NAME_LEN];
104 char tgttype[NVM_TTYPE_NAME_MAX];
105 char tgtname[DISK_NAME_LEN];
106
107 __u32 flags;
108
109 struct nvm_ioctl_create_conf conf;
110 };
111
112 struct nvm_ioctl_remove {
113 char tgtname[DISK_NAME_LEN];
114
115 __u32 flags;
116 };
117
118 struct nvm_ioctl_dev_init {
119 char dev[DISK_NAME_LEN];
120 char mmtype[NVM_MMTYPE_LEN];
121
122 __u32 flags;
123 };
124
125 enum {
126 NVM_FACTORY_ERASE_ONLY_USER = 1 << 0,
127
128 NVM_FACTORY_RESET_HOST_BLKS = 1 << 1,
129 NVM_FACTORY_RESET_GRWN_BBLKS = 1 << 2,
130 NVM_FACTORY_NR_BITS = 1 << 3,
131 };
132
133 struct nvm_ioctl_dev_factory {
134 char dev[DISK_NAME_LEN];
135
136 __u32 flags;
137 };
138
139 struct nvm_user_vio {
140 __u8 opcode;
141 __u8 flags;
142 __u16 control;
143 __u16 nppas;
144 __u16 rsvd;
145 __u64 metadata;
146 __u64 addr;
147 __u64 ppa_list;
148 __u32 metadata_len;
149 __u32 data_len;
150 __u64 status;
151 __u32 result;
152 __u32 rsvd3[3];
153 };
154
155 struct nvm_passthru_vio {
156 __u8 opcode;
157 __u8 flags;
158 __u8 rsvd[2];
159 __u32 nsid;
160 __u32 cdw2;
161 __u32 cdw3;
162 __u64 metadata;
163 __u64 addr;
164 __u32 metadata_len;
165 __u32 data_len;
166 __u64 ppa_list;
167 __u16 nppas;
168 __u16 control;
169 __u32 cdw13;
170 __u32 cdw14;
171 __u32 cdw15;
172 __u64 status;
173 __u32 result;
174 __u32 timeout_ms;
175 };
176
177
178 enum {
179
180 NVM_INFO_CMD = 0x20,
181 NVM_GET_DEVICES_CMD,
182
183
184 NVM_DEV_CREATE_CMD,
185 NVM_DEV_REMOVE_CMD,
186
187
188 NVM_DEV_INIT_CMD,
189
190
191 NVM_DEV_FACTORY_CMD,
192
193
194 NVM_DEV_VIO_ADMIN_CMD = 0x41,
195 NVM_DEV_VIO_CMD = 0x42,
196 NVM_DEV_VIO_USER_CMD = 0x43,
197 };
198
199 #define NVM_IOCTL 'L'
200
201 #define NVM_INFO _IOWR(NVM_IOCTL, NVM_INFO_CMD, \
202 struct nvm_ioctl_info)
203 #define NVM_GET_DEVICES _IOR(NVM_IOCTL, NVM_GET_DEVICES_CMD, \
204 struct nvm_ioctl_get_devices)
205 #define NVM_DEV_CREATE _IOW(NVM_IOCTL, NVM_DEV_CREATE_CMD, \
206 struct nvm_ioctl_create)
207 #define NVM_DEV_REMOVE _IOW(NVM_IOCTL, NVM_DEV_REMOVE_CMD, \
208 struct nvm_ioctl_remove)
209 #define NVM_DEV_INIT _IOW(NVM_IOCTL, NVM_DEV_INIT_CMD, \
210 struct nvm_ioctl_dev_init)
211 #define NVM_DEV_FACTORY _IOW(NVM_IOCTL, NVM_DEV_FACTORY_CMD, \
212 struct nvm_ioctl_dev_factory)
213
214 #define NVME_NVM_IOCTL_IO_VIO _IOWR(NVM_IOCTL, NVM_DEV_VIO_USER_CMD, \
215 struct nvm_passthru_vio)
216 #define NVME_NVM_IOCTL_ADMIN_VIO _IOWR(NVM_IOCTL, NVM_DEV_VIO_ADMIN_CMD,\
217 struct nvm_passthru_vio)
218 #define NVME_NVM_IOCTL_SUBMIT_VIO _IOWR(NVM_IOCTL, NVM_DEV_VIO_CMD,\
219 struct nvm_user_vio)
220
221 #define NVM_VERSION_MAJOR 1
222 #define NVM_VERSION_MINOR 0
223 #define NVM_VERSION_PATCHLEVEL 0
224
225 #endif