cpp-d1064d
[cross.git] / i686-linux-gnu-4.7 / usr / include / 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 _LINUX_LIGHTNVM_H
21 #define _LINUX_LIGHTNVM_H
22
23 #include <stdio.h>
24 #include <sys/ioctl.h>
25 #define DISK_NAME_LEN 32
26
27 #include <linux/types.h>
28 #include <linux/ioctl.h>
29
30 #define NVM_TTYPE_NAME_MAX 48
31 #define NVM_TTYPE_MAX 63
32 #define NVM_MMTYPE_LEN 8
33
34 #define NVM_CTRL_FILE "/dev/lightnvm/control"
35
36 struct nvm_ioctl_info_tgt {
37         __u32 version[3];
38         __u32 reserved;
39         char tgtname[NVM_TTYPE_NAME_MAX];
40 };
41
42 struct nvm_ioctl_info {
43         __u32 version[3];       /* in/out - major, minor, patch */
44         __u16 tgtsize;          /* number of targets */
45         __u16 reserved16;       /* pad to 4K page */
46         __u32 reserved[12];
47         struct nvm_ioctl_info_tgt tgts[NVM_TTYPE_MAX];
48 };
49
50 enum {
51         NVM_DEVICE_ACTIVE = 1 << 0,
52 };
53
54 struct nvm_ioctl_device_info {
55         char devname[DISK_NAME_LEN];
56         char bmname[NVM_TTYPE_NAME_MAX];
57         __u32 bmversion[3];
58         __u32 flags;
59         __u32 reserved[8];
60 };
61
62 struct nvm_ioctl_get_devices {
63         __u32 nr_devices;
64         __u32 reserved[31];
65         struct nvm_ioctl_device_info info[31];
66 };
67
68 struct nvm_ioctl_create_simple {
69         __u32 lun_begin;
70         __u32 lun_end;
71 };
72
73 struct nvm_ioctl_create_extended {
74         __u16 lun_begin;
75         __u16 lun_end;
76         __u16 op;
77         __u16 rsv;
78 };
79
80 enum {
81         NVM_CONFIG_TYPE_SIMPLE = 0,
82         NVM_CONFIG_TYPE_EXTENDED = 1,
83 };
84
85 struct nvm_ioctl_create_conf {
86         __u32 type;
87         union {
88                 struct nvm_ioctl_create_simple s;
89                 struct nvm_ioctl_create_extended e;
90         };
91 };
92
93 enum {
94         NVM_TARGET_FACTORY = 1 << 0,    /* Init target in factory mode */
95 };
96
97 struct nvm_ioctl_create {
98         char dev[DISK_NAME_LEN];                /* open-channel SSD device */
99         char tgttype[NVM_TTYPE_NAME_MAX];       /* target type name */
100         char tgtname[DISK_NAME_LEN];            /* dev to expose target as */
101
102         __u32 flags;
103
104         struct nvm_ioctl_create_conf conf;
105 };
106
107 struct nvm_ioctl_remove {
108         char tgtname[DISK_NAME_LEN];
109
110         __u32 flags;
111 };
112
113 struct nvm_ioctl_dev_init {
114         char dev[DISK_NAME_LEN];                /* open-channel SSD device */
115         char mmtype[NVM_MMTYPE_LEN];            /* register to media manager */
116
117         __u32 flags;
118 };
119
120 enum {
121         NVM_FACTORY_ERASE_ONLY_USER     = 1 << 0, /* erase only blocks used as
122                                                    * host blks or grown blks */
123         NVM_FACTORY_RESET_HOST_BLKS     = 1 << 1, /* remove host blk marks */
124         NVM_FACTORY_RESET_GRWN_BBLKS    = 1 << 2, /* remove grown blk marks */
125         NVM_FACTORY_NR_BITS             = 1 << 3, /* stops here */
126 };
127
128 struct nvm_ioctl_dev_factory {
129         char dev[DISK_NAME_LEN];
130
131         __u32 flags;
132 };
133
134 struct nvm_user_vio {
135         __u8 opcode;
136         __u8 flags;
137         __u16 control;
138         __u16 nppas;
139         __u16 rsvd;
140         __u64 metadata;
141         __u64 addr;
142         __u64 ppa_list;
143         __u32 metadata_len;
144         __u32 data_len;
145         __u64 status;
146         __u32 result;
147         __u32 rsvd3[3];
148 };
149
150 struct nvm_passthru_vio {
151         __u8 opcode;
152         __u8 flags;
153         __u8 rsvd[2];
154         __u32 nsid;
155         __u32 cdw2;
156         __u32 cdw3;
157         __u64 metadata;
158         __u64 addr;
159         __u32 metadata_len;
160         __u32 data_len;
161         __u64 ppa_list;
162         __u16 nppas;
163         __u16 control;
164         __u32 cdw13;
165         __u32 cdw14;
166         __u32 cdw15;
167         __u64 status;
168         __u32 result;
169         __u32 timeout_ms;
170 };
171
172 /* The ioctl type, 'L', 0x20 - 0x2F documented in ioctl-number.txt */
173 enum {
174         /* top level cmds */
175         NVM_INFO_CMD = 0x20,
176         NVM_GET_DEVICES_CMD,
177
178         /* device level cmds */
179         NVM_DEV_CREATE_CMD,
180         NVM_DEV_REMOVE_CMD,
181
182         /* Init a device to support LightNVM media managers */
183         NVM_DEV_INIT_CMD,
184
185         /* Factory reset device */
186         NVM_DEV_FACTORY_CMD,
187
188         /* Vector user I/O */
189         NVM_DEV_VIO_ADMIN_CMD = 0x41,
190         NVM_DEV_VIO_CMD = 0x42,
191         NVM_DEV_VIO_USER_CMD = 0x43,
192 };
193
194 #define NVM_IOCTL 'L' /* 0x4c */
195
196 #define NVM_INFO                _IOWR(NVM_IOCTL, NVM_INFO_CMD, \
197                                                 struct nvm_ioctl_info)
198 #define NVM_GET_DEVICES         _IOR(NVM_IOCTL, NVM_GET_DEVICES_CMD, \
199                                                 struct nvm_ioctl_get_devices)
200 #define NVM_DEV_CREATE          _IOW(NVM_IOCTL, NVM_DEV_CREATE_CMD, \
201                                                 struct nvm_ioctl_create)
202 #define NVM_DEV_REMOVE          _IOW(NVM_IOCTL, NVM_DEV_REMOVE_CMD, \
203                                                 struct nvm_ioctl_remove)
204 #define NVM_DEV_INIT            _IOW(NVM_IOCTL, NVM_DEV_INIT_CMD, \
205                                                 struct nvm_ioctl_dev_init)
206 #define NVM_DEV_FACTORY         _IOW(NVM_IOCTL, NVM_DEV_FACTORY_CMD, \
207                                                 struct nvm_ioctl_dev_factory)
208
209 #define NVME_NVM_IOCTL_IO_VIO           _IOWR(NVM_IOCTL, NVM_DEV_VIO_USER_CMD, \
210                                                 struct nvm_passthru_vio)
211 #define NVME_NVM_IOCTL_ADMIN_VIO        _IOWR(NVM_IOCTL, NVM_DEV_VIO_ADMIN_CMD,\
212                                                 struct nvm_passthru_vio)
213 #define NVME_NVM_IOCTL_SUBMIT_VIO       _IOWR(NVM_IOCTL, NVM_DEV_VIO_CMD,\
214                                                 struct nvm_user_vio)
215
216 #define NVM_VERSION_MAJOR       1
217 #define NVM_VERSION_MINOR       0
218 #define NVM_VERSION_PATCHLEVEL  0
219
220 #endif