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