ndctl.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * Copyright (c) 2014-2015, Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU Lesser General Public License,
  6. * version 2.1, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT ANY
  9. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  11. * more details.
  12. */
  13. #ifndef __NDCTL_H__
  14. #define __NDCTL_H__
  15. #include <linux/types.h>
  16. struct nd_cmd_smart {
  17. __u32 status;
  18. __u8 data[128];
  19. } __packed;
  20. struct nd_cmd_smart_threshold {
  21. __u32 status;
  22. __u8 data[8];
  23. } __packed;
  24. struct nd_cmd_dimm_flags {
  25. __u32 status;
  26. __u32 flags;
  27. } __packed;
  28. struct nd_cmd_get_config_size {
  29. __u32 status;
  30. __u32 config_size;
  31. __u32 max_xfer;
  32. } __packed;
  33. struct nd_cmd_get_config_data_hdr {
  34. __u32 in_offset;
  35. __u32 in_length;
  36. __u32 status;
  37. __u8 out_buf[0];
  38. } __packed;
  39. struct nd_cmd_set_config_hdr {
  40. __u32 in_offset;
  41. __u32 in_length;
  42. __u8 in_buf[0];
  43. } __packed;
  44. struct nd_cmd_vendor_hdr {
  45. __u32 opcode;
  46. __u32 in_length;
  47. __u8 in_buf[0];
  48. } __packed;
  49. struct nd_cmd_vendor_tail {
  50. __u32 status;
  51. __u32 out_length;
  52. __u8 out_buf[0];
  53. } __packed;
  54. struct nd_cmd_ars_cap {
  55. __u64 address;
  56. __u64 length;
  57. __u32 status;
  58. __u32 max_ars_out;
  59. } __packed;
  60. struct nd_cmd_ars_start {
  61. __u64 address;
  62. __u64 length;
  63. __u16 type;
  64. __u8 reserved[6];
  65. __u32 status;
  66. } __packed;
  67. struct nd_cmd_ars_status {
  68. __u32 status;
  69. __u32 out_length;
  70. __u64 address;
  71. __u64 length;
  72. __u16 type;
  73. __u32 num_records;
  74. struct nd_ars_record {
  75. __u32 handle;
  76. __u32 flags;
  77. __u64 err_address;
  78. __u64 length;
  79. } __packed records[0];
  80. } __packed;
  81. enum {
  82. ND_CMD_IMPLEMENTED = 0,
  83. /* bus commands */
  84. ND_CMD_ARS_CAP = 1,
  85. ND_CMD_ARS_START = 2,
  86. ND_CMD_ARS_STATUS = 3,
  87. /* per-dimm commands */
  88. ND_CMD_SMART = 1,
  89. ND_CMD_SMART_THRESHOLD = 2,
  90. ND_CMD_DIMM_FLAGS = 3,
  91. ND_CMD_GET_CONFIG_SIZE = 4,
  92. ND_CMD_GET_CONFIG_DATA = 5,
  93. ND_CMD_SET_CONFIG_DATA = 6,
  94. ND_CMD_VENDOR_EFFECT_LOG_SIZE = 7,
  95. ND_CMD_VENDOR_EFFECT_LOG = 8,
  96. ND_CMD_VENDOR = 9,
  97. };
  98. enum {
  99. ND_ARS_VOLATILE = 1,
  100. ND_ARS_PERSISTENT = 2,
  101. };
  102. static inline const char *nvdimm_bus_cmd_name(unsigned cmd)
  103. {
  104. static const char * const names[] = {
  105. [ND_CMD_ARS_CAP] = "ars_cap",
  106. [ND_CMD_ARS_START] = "ars_start",
  107. [ND_CMD_ARS_STATUS] = "ars_status",
  108. };
  109. if (cmd < ARRAY_SIZE(names) && names[cmd])
  110. return names[cmd];
  111. return "unknown";
  112. }
  113. static inline const char *nvdimm_cmd_name(unsigned cmd)
  114. {
  115. static const char * const names[] = {
  116. [ND_CMD_SMART] = "smart",
  117. [ND_CMD_SMART_THRESHOLD] = "smart_thresh",
  118. [ND_CMD_DIMM_FLAGS] = "flags",
  119. [ND_CMD_GET_CONFIG_SIZE] = "get_size",
  120. [ND_CMD_GET_CONFIG_DATA] = "get_data",
  121. [ND_CMD_SET_CONFIG_DATA] = "set_data",
  122. [ND_CMD_VENDOR_EFFECT_LOG_SIZE] = "effect_size",
  123. [ND_CMD_VENDOR_EFFECT_LOG] = "effect_log",
  124. [ND_CMD_VENDOR] = "vendor",
  125. };
  126. if (cmd < ARRAY_SIZE(names) && names[cmd])
  127. return names[cmd];
  128. return "unknown";
  129. }
  130. #define ND_IOCTL 'N'
  131. #define ND_IOCTL_SMART _IOWR(ND_IOCTL, ND_CMD_SMART,\
  132. struct nd_cmd_smart)
  133. #define ND_IOCTL_SMART_THRESHOLD _IOWR(ND_IOCTL, ND_CMD_SMART_THRESHOLD,\
  134. struct nd_cmd_smart_threshold)
  135. #define ND_IOCTL_DIMM_FLAGS _IOWR(ND_IOCTL, ND_CMD_DIMM_FLAGS,\
  136. struct nd_cmd_dimm_flags)
  137. #define ND_IOCTL_GET_CONFIG_SIZE _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_SIZE,\
  138. struct nd_cmd_get_config_size)
  139. #define ND_IOCTL_GET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_DATA,\
  140. struct nd_cmd_get_config_data_hdr)
  141. #define ND_IOCTL_SET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_SET_CONFIG_DATA,\
  142. struct nd_cmd_set_config_hdr)
  143. #define ND_IOCTL_VENDOR _IOWR(ND_IOCTL, ND_CMD_VENDOR,\
  144. struct nd_cmd_vendor_hdr)
  145. #define ND_IOCTL_ARS_CAP _IOWR(ND_IOCTL, ND_CMD_ARS_CAP,\
  146. struct nd_cmd_ars_cap)
  147. #define ND_IOCTL_ARS_START _IOWR(ND_IOCTL, ND_CMD_ARS_START,\
  148. struct nd_cmd_ars_start)
  149. #define ND_IOCTL_ARS_STATUS _IOWR(ND_IOCTL, ND_CMD_ARS_STATUS,\
  150. struct nd_cmd_ars_status)
  151. #define ND_DEVICE_DIMM 1 /* nd_dimm: container for "config data" */
  152. #define ND_DEVICE_REGION_PMEM 2 /* nd_region: (parent of PMEM namespaces) */
  153. #define ND_DEVICE_REGION_BLK 3 /* nd_region: (parent of BLK namespaces) */
  154. #define ND_DEVICE_NAMESPACE_IO 4 /* legacy persistent memory */
  155. #define ND_DEVICE_NAMESPACE_PMEM 5 /* PMEM namespace (may alias with BLK) */
  156. #define ND_DEVICE_NAMESPACE_BLK 6 /* BLK namespace (may alias with PMEM) */
  157. enum nd_driver_flags {
  158. ND_DRIVER_DIMM = 1 << ND_DEVICE_DIMM,
  159. ND_DRIVER_REGION_PMEM = 1 << ND_DEVICE_REGION_PMEM,
  160. ND_DRIVER_REGION_BLK = 1 << ND_DEVICE_REGION_BLK,
  161. ND_DRIVER_NAMESPACE_IO = 1 << ND_DEVICE_NAMESPACE_IO,
  162. ND_DRIVER_NAMESPACE_PMEM = 1 << ND_DEVICE_NAMESPACE_PMEM,
  163. ND_DRIVER_NAMESPACE_BLK = 1 << ND_DEVICE_NAMESPACE_BLK,
  164. };
  165. enum {
  166. ND_MIN_NAMESPACE_SIZE = 0x00400000,
  167. };
  168. enum ars_masks {
  169. ARS_STATUS_MASK = 0x0000FFFF,
  170. ARS_EXT_STATUS_SHIFT = 16,
  171. };
  172. #endif /* __NDCTL_H__ */