blob: fd19f36b3129278343f37ee5e59dfa280713eb9c [file] [log] [blame]
Matias Bjørlingcd9e9802015-10-28 19:54:55 +01001/*
2 * Copyright (C) 2015 CNEX Labs. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License version
6 * 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; see the file COPYING. If not, write to
15 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
16 * USA.
17 */
18
19#ifndef _UAPI_LINUX_LIGHTNVM_H
20#define _UAPI_LINUX_LIGHTNVM_H
21
22#ifdef __KERNEL__
23#include <linux/kernel.h>
24#include <linux/ioctl.h>
25#else /* __KERNEL__ */
26#include <stdio.h>
27#include <sys/ioctl.h>
28#define DISK_NAME_LEN 32
29#endif /* __KERNEL__ */
30
31#include <linux/types.h>
32#include <linux/ioctl.h>
33
34#define NVM_TTYPE_NAME_MAX 48
35#define NVM_TTYPE_MAX 63
Matias Bjørlinge3eb3792016-01-12 07:49:36 +010036#define NVM_MMTYPE_LEN 8
Matias Bjørlingcd9e9802015-10-28 19:54:55 +010037
38#define NVM_CTRL_FILE "/dev/lightnvm/control"
39
40struct nvm_ioctl_info_tgt {
41 __u32 version[3];
42 __u32 reserved;
43 char tgtname[NVM_TTYPE_NAME_MAX];
44};
45
46struct nvm_ioctl_info {
47 __u32 version[3]; /* in/out - major, minor, patch */
48 __u16 tgtsize; /* number of targets */
49 __u16 reserved16; /* pad to 4K page */
50 __u32 reserved[12];
51 struct nvm_ioctl_info_tgt tgts[NVM_TTYPE_MAX];
52};
53
54enum {
55 NVM_DEVICE_ACTIVE = 1 << 0,
56};
57
58struct nvm_ioctl_device_info {
59 char devname[DISK_NAME_LEN];
60 char bmname[NVM_TTYPE_NAME_MAX];
61 __u32 bmversion[3];
62 __u32 flags;
63 __u32 reserved[8];
64};
65
66struct nvm_ioctl_get_devices {
67 __u32 nr_devices;
68 __u32 reserved[31];
69 struct nvm_ioctl_device_info info[31];
70};
71
72struct nvm_ioctl_create_simple {
73 __u32 lun_begin;
74 __u32 lun_end;
75};
76
77enum {
78 NVM_CONFIG_TYPE_SIMPLE = 0,
79};
80
81struct nvm_ioctl_create_conf {
82 __u32 type;
83 union {
84 struct nvm_ioctl_create_simple s;
85 };
86};
87
88struct nvm_ioctl_create {
89 char dev[DISK_NAME_LEN]; /* open-channel SSD device */
90 char tgttype[NVM_TTYPE_NAME_MAX]; /* target type name */
91 char tgtname[DISK_NAME_LEN]; /* dev to expose target as */
92
93 __u32 flags;
94
95 struct nvm_ioctl_create_conf conf;
96};
97
98struct nvm_ioctl_remove {
99 char tgtname[DISK_NAME_LEN];
100
101 __u32 flags;
102};
103
Matias Bjørling55696152016-01-12 07:49:37 +0100104struct nvm_ioctl_dev_init {
105 char dev[DISK_NAME_LEN]; /* open-channel SSD device */
106 char mmtype[NVM_MMTYPE_LEN]; /* register to media manager */
107
108 __u32 flags;
109};
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100110
Matias Bjørling8b4970c2016-01-12 07:49:39 +0100111enum {
112 NVM_FACTORY_ERASE_ONLY_USER = 1 << 0, /* erase only blocks used as
113 * host blks or grown blks */
114 NVM_FACTORY_RESET_HOST_BLKS = 1 << 1, /* remove host blk marks */
115 NVM_FACTORY_RESET_GRWN_BBLKS = 1 << 2, /* remove grown blk marks */
116 NVM_FACTORY_NR_BITS = 1 << 3, /* stops here */
117};
118
119struct nvm_ioctl_dev_factory {
120 char dev[DISK_NAME_LEN];
121
122 __u32 flags;
123};
124
Matias Bjørling84d4add2017-01-31 13:17:16 +0100125struct nvm_user_vio {
126 __u8 opcode;
127 __u8 flags;
128 __u16 control;
129 __u16 nppas;
130 __u16 rsvd;
131 __u64 metadata;
132 __u64 addr;
133 __u64 ppa_list;
134 __u32 metadata_len;
135 __u32 data_len;
136 __u64 status;
137 __u32 result;
138 __u32 rsvd3[3];
139};
140
141struct nvm_passthru_vio {
142 __u8 opcode;
143 __u8 flags;
144 __u8 rsvd[2];
145 __u32 nsid;
146 __u32 cdw2;
147 __u32 cdw3;
148 __u64 metadata;
149 __u64 addr;
150 __u32 metadata_len;
151 __u32 data_len;
152 __u64 ppa_list;
153 __u16 nppas;
154 __u16 control;
155 __u32 cdw13;
156 __u32 cdw14;
157 __u32 cdw15;
158 __u64 status;
159 __u32 result;
160 __u32 timeout_ms;
161};
162
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100163/* The ioctl type, 'L', 0x20 - 0x2F documented in ioctl-number.txt */
164enum {
165 /* top level cmds */
166 NVM_INFO_CMD = 0x20,
167 NVM_GET_DEVICES_CMD,
168
169 /* device level cmds */
170 NVM_DEV_CREATE_CMD,
171 NVM_DEV_REMOVE_CMD,
Matias Bjørling55696152016-01-12 07:49:37 +0100172
173 /* Init a device to support LightNVM media managers */
174 NVM_DEV_INIT_CMD,
Matias Bjørling8b4970c2016-01-12 07:49:39 +0100175
176 /* Factory reset device */
177 NVM_DEV_FACTORY_CMD,
Matias Bjørling84d4add2017-01-31 13:17:16 +0100178
179 /* Vector user I/O */
180 NVM_DEV_VIO_ADMIN_CMD = 0x41,
181 NVM_DEV_VIO_CMD = 0x42,
182 NVM_DEV_VIO_USER_CMD = 0x43,
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100183};
184
185#define NVM_IOCTL 'L' /* 0x4c */
186
187#define NVM_INFO _IOWR(NVM_IOCTL, NVM_INFO_CMD, \
188 struct nvm_ioctl_info)
189#define NVM_GET_DEVICES _IOR(NVM_IOCTL, NVM_GET_DEVICES_CMD, \
190 struct nvm_ioctl_get_devices)
191#define NVM_DEV_CREATE _IOW(NVM_IOCTL, NVM_DEV_CREATE_CMD, \
192 struct nvm_ioctl_create)
193#define NVM_DEV_REMOVE _IOW(NVM_IOCTL, NVM_DEV_REMOVE_CMD, \
194 struct nvm_ioctl_remove)
Matias Bjørling55696152016-01-12 07:49:37 +0100195#define NVM_DEV_INIT _IOW(NVM_IOCTL, NVM_DEV_INIT_CMD, \
196 struct nvm_ioctl_dev_init)
Matias Bjørling8b4970c2016-01-12 07:49:39 +0100197#define NVM_DEV_FACTORY _IOW(NVM_IOCTL, NVM_DEV_FACTORY_CMD, \
198 struct nvm_ioctl_dev_factory)
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100199
Matias Bjørling84d4add2017-01-31 13:17:16 +0100200#define NVME_NVM_IOCTL_IO_VIO _IOWR(NVM_IOCTL, NVM_DEV_VIO_USER_CMD, \
201 struct nvm_passthru_vio)
202#define NVME_NVM_IOCTL_ADMIN_VIO _IOWR(NVM_IOCTL, NVM_DEV_VIO_ADMIN_CMD,\
203 struct nvm_passthru_vio)
204#define NVME_NVM_IOCTL_SUBMIT_VIO _IOWR(NVM_IOCTL, NVM_DEV_VIO_CMD,\
205 struct nvm_user_vio)
206
Matias Bjørlingcd9e9802015-10-28 19:54:55 +0100207#define NVM_VERSION_MAJOR 1
208#define NVM_VERSION_MINOR 0
209#define NVM_VERSION_PATCHLEVEL 0
210
211#endif