lightnvm.h 4.9 KB

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