lightnvm.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  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. #ifndef _UAPI_LINUX_LIGHTNVM_H
  19. #define _UAPI_LINUX_LIGHTNVM_H
  20. #ifdef __KERNEL__
  21. #include <linux/kernel.h>
  22. #include <linux/ioctl.h>
  23. #else /* __KERNEL__ */
  24. #include <stdio.h>
  25. #include <sys/ioctl.h>
  26. #define DISK_NAME_LEN 32
  27. #endif /* __KERNEL__ */
  28. #include <linux/types.h>
  29. #include <linux/ioctl.h>
  30. #define NVM_TTYPE_NAME_MAX 48
  31. #define NVM_TTYPE_MAX 63
  32. #define NVM_MMTYPE_LEN 8
  33. #define NVM_CTRL_FILE "/dev/lightnvm/control"
  34. struct nvm_ioctl_info_tgt {
  35. __u32 version[3];
  36. __u32 reserved;
  37. char tgtname[NVM_TTYPE_NAME_MAX];
  38. };
  39. struct nvm_ioctl_info {
  40. __u32 version[3]; /* in/out - major, minor, patch */
  41. __u16 tgtsize; /* number of targets */
  42. __u16 reserved16; /* pad to 4K page */
  43. __u32 reserved[12];
  44. struct nvm_ioctl_info_tgt tgts[NVM_TTYPE_MAX];
  45. };
  46. enum {
  47. NVM_DEVICE_ACTIVE = 1 << 0,
  48. };
  49. struct nvm_ioctl_device_info {
  50. char devname[DISK_NAME_LEN];
  51. char bmname[NVM_TTYPE_NAME_MAX];
  52. __u32 bmversion[3];
  53. __u32 flags;
  54. __u32 reserved[8];
  55. };
  56. struct nvm_ioctl_get_devices {
  57. __u32 nr_devices;
  58. __u32 reserved[31];
  59. struct nvm_ioctl_device_info info[31];
  60. };
  61. struct nvm_ioctl_create_simple {
  62. __u32 lun_begin;
  63. __u32 lun_end;
  64. };
  65. enum {
  66. NVM_CONFIG_TYPE_SIMPLE = 0,
  67. };
  68. struct nvm_ioctl_create_conf {
  69. __u32 type;
  70. union {
  71. struct nvm_ioctl_create_simple s;
  72. };
  73. };
  74. struct nvm_ioctl_create {
  75. char dev[DISK_NAME_LEN]; /* open-channel SSD device */
  76. char tgttype[NVM_TTYPE_NAME_MAX]; /* target type name */
  77. char tgtname[DISK_NAME_LEN]; /* dev to expose target as */
  78. __u32 flags;
  79. struct nvm_ioctl_create_conf conf;
  80. };
  81. struct nvm_ioctl_remove {
  82. char tgtname[DISK_NAME_LEN];
  83. __u32 flags;
  84. };
  85. struct nvm_ioctl_dev_init {
  86. char dev[DISK_NAME_LEN]; /* open-channel SSD device */
  87. char mmtype[NVM_MMTYPE_LEN]; /* register to media manager */
  88. __u32 flags;
  89. };
  90. enum {
  91. NVM_FACTORY_ERASE_ONLY_USER = 1 << 0, /* erase only blocks used as
  92. * host blks or grown blks */
  93. NVM_FACTORY_RESET_HOST_BLKS = 1 << 1, /* remove host blk marks */
  94. NVM_FACTORY_RESET_GRWN_BBLKS = 1 << 2, /* remove grown blk marks */
  95. NVM_FACTORY_NR_BITS = 1 << 3, /* stops here */
  96. };
  97. struct nvm_ioctl_dev_factory {
  98. char dev[DISK_NAME_LEN];
  99. __u32 flags;
  100. };
  101. /* The ioctl type, 'L', 0x20 - 0x2F documented in ioctl-number.txt */
  102. enum {
  103. /* top level cmds */
  104. NVM_INFO_CMD = 0x20,
  105. NVM_GET_DEVICES_CMD,
  106. /* device level cmds */
  107. NVM_DEV_CREATE_CMD,
  108. NVM_DEV_REMOVE_CMD,
  109. /* Init a device to support LightNVM media managers */
  110. NVM_DEV_INIT_CMD,
  111. /* Factory reset device */
  112. NVM_DEV_FACTORY_CMD,
  113. };
  114. #define NVM_IOCTL 'L' /* 0x4c */
  115. #define NVM_INFO _IOWR(NVM_IOCTL, NVM_INFO_CMD, \
  116. struct nvm_ioctl_info)
  117. #define NVM_GET_DEVICES _IOR(NVM_IOCTL, NVM_GET_DEVICES_CMD, \
  118. struct nvm_ioctl_get_devices)
  119. #define NVM_DEV_CREATE _IOW(NVM_IOCTL, NVM_DEV_CREATE_CMD, \
  120. struct nvm_ioctl_create)
  121. #define NVM_DEV_REMOVE _IOW(NVM_IOCTL, NVM_DEV_REMOVE_CMD, \
  122. struct nvm_ioctl_remove)
  123. #define NVM_DEV_INIT _IOW(NVM_IOCTL, NVM_DEV_INIT_CMD, \
  124. struct nvm_ioctl_dev_init)
  125. #define NVM_DEV_FACTORY _IOW(NVM_IOCTL, NVM_DEV_FACTORY_CMD, \
  126. struct nvm_ioctl_dev_factory)
  127. #define NVM_VERSION_MAJOR 1
  128. #define NVM_VERSION_MINOR 0
  129. #define NVM_VERSION_PATCHLEVEL 0
  130. #endif