Merge tag 'for-5.5/drivers-post-20191122' of git://git.kernel.dk/linux-block
[sfrench/cifs-2.6.git] / include / uapi / linux / lightnvm.h
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Copyright (C) 2015 CNEX Labs.  All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License version
7  * 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; see the file COPYING.  If not, write to
16  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
17  * USA.
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 /* __KERNEL__ */
27 #include <stdio.h>
28 #include <sys/ioctl.h>
29 #define DISK_NAME_LEN 32
30 #endif /* __KERNEL__ */
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];       /* in/out - major, minor, patch */
49         __u16 tgtsize;          /* number of targets */
50         __u16 reserved16;       /* pad to 4K page */
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,    /* Init target in factory mode */
100 };
101
102 struct nvm_ioctl_create {
103         char dev[DISK_NAME_LEN];                /* open-channel SSD device */
104         char tgttype[NVM_TTYPE_NAME_MAX];       /* target type name */
105         char tgtname[DISK_NAME_LEN];            /* dev to expose target as */
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];                /* open-channel SSD device */
120         char mmtype[NVM_MMTYPE_LEN];            /* register to media manager */
121
122         __u32 flags;
123 };
124
125 enum {
126         NVM_FACTORY_ERASE_ONLY_USER     = 1 << 0, /* erase only blocks used as
127                                                    * host blks or grown blks */
128         NVM_FACTORY_RESET_HOST_BLKS     = 1 << 1, /* remove host blk marks */
129         NVM_FACTORY_RESET_GRWN_BBLKS    = 1 << 2, /* remove grown blk marks */
130         NVM_FACTORY_NR_BITS             = 1 << 3, /* stops here */
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 /* The ioctl type, 'L', 0x20 - 0x2F documented in ioctl-number.txt */
178 enum {
179         /* top level cmds */
180         NVM_INFO_CMD = 0x20,
181         NVM_GET_DEVICES_CMD,
182
183         /* device level cmds */
184         NVM_DEV_CREATE_CMD,
185         NVM_DEV_REMOVE_CMD,
186
187         /* Init a device to support LightNVM media managers */
188         NVM_DEV_INIT_CMD,
189
190         /* Factory reset device */
191         NVM_DEV_FACTORY_CMD,
192
193         /* Vector user I/O */
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' /* 0x4c */
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