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