ndctl.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Copyright (c) 2014-2016, 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_dimm_flags {
  17. __u32 status;
  18. __u32 flags;
  19. } __packed;
  20. struct nd_cmd_get_config_size {
  21. __u32 status;
  22. __u32 config_size;
  23. __u32 max_xfer;
  24. } __packed;
  25. struct nd_cmd_get_config_data_hdr {
  26. __u32 in_offset;
  27. __u32 in_length;
  28. __u32 status;
  29. __u8 out_buf[0];
  30. } __packed;
  31. struct nd_cmd_set_config_hdr {
  32. __u32 in_offset;
  33. __u32 in_length;
  34. __u8 in_buf[0];
  35. } __packed;
  36. struct nd_cmd_vendor_hdr {
  37. __u32 opcode;
  38. __u32 in_length;
  39. __u8 in_buf[0];
  40. } __packed;
  41. struct nd_cmd_vendor_tail {
  42. __u32 status;
  43. __u32 out_length;
  44. __u8 out_buf[0];
  45. } __packed;
  46. struct nd_cmd_ars_cap {
  47. __u64 address;
  48. __u64 length;
  49. __u32 status;
  50. __u32 max_ars_out;
  51. __u32 clear_err_unit;
  52. __u16 flags;
  53. __u16 reserved;
  54. } __packed;
  55. struct nd_cmd_ars_start {
  56. __u64 address;
  57. __u64 length;
  58. __u16 type;
  59. __u8 flags;
  60. __u8 reserved[5];
  61. __u32 status;
  62. __u32 scrub_time;
  63. } __packed;
  64. struct nd_cmd_ars_status {
  65. __u32 status;
  66. __u32 out_length;
  67. __u64 address;
  68. __u64 length;
  69. __u64 restart_address;
  70. __u64 restart_length;
  71. __u16 type;
  72. __u16 flags;
  73. __u32 num_records;
  74. struct nd_ars_record {
  75. __u32 handle;
  76. __u32 reserved;
  77. __u64 err_address;
  78. __u64 length;
  79. } __packed records[0];
  80. } __packed;
  81. struct nd_cmd_clear_error {
  82. __u64 address;
  83. __u64 length;
  84. __u32 status;
  85. __u8 reserved[4];
  86. __u64 cleared;
  87. } __packed;
  88. enum {
  89. ND_CMD_IMPLEMENTED = 0,
  90. /* bus commands */
  91. ND_CMD_ARS_CAP = 1,
  92. ND_CMD_ARS_START = 2,
  93. ND_CMD_ARS_STATUS = 3,
  94. ND_CMD_CLEAR_ERROR = 4,
  95. /* per-dimm commands */
  96. ND_CMD_SMART = 1,
  97. ND_CMD_SMART_THRESHOLD = 2,
  98. ND_CMD_DIMM_FLAGS = 3,
  99. ND_CMD_GET_CONFIG_SIZE = 4,
  100. ND_CMD_GET_CONFIG_DATA = 5,
  101. ND_CMD_SET_CONFIG_DATA = 6,
  102. ND_CMD_VENDOR_EFFECT_LOG_SIZE = 7,
  103. ND_CMD_VENDOR_EFFECT_LOG = 8,
  104. ND_CMD_VENDOR = 9,
  105. ND_CMD_CALL = 10,
  106. };
  107. enum {
  108. ND_ARS_VOLATILE = 1,
  109. ND_ARS_PERSISTENT = 2,
  110. ND_ARS_RETURN_PREV_DATA = 1 << 1,
  111. ND_CONFIG_LOCKED = 1,
  112. };
  113. static inline const char *nvdimm_bus_cmd_name(unsigned cmd)
  114. {
  115. switch (cmd) {
  116. case ND_CMD_ARS_CAP: return "ars_cap";
  117. case ND_CMD_ARS_START: return "ars_start";
  118. case ND_CMD_ARS_STATUS: return "ars_status";
  119. case ND_CMD_CLEAR_ERROR: return "clear_error";
  120. case ND_CMD_CALL: return "cmd_call";
  121. default: return "unknown";
  122. }
  123. }
  124. static inline const char *nvdimm_cmd_name(unsigned cmd)
  125. {
  126. switch (cmd) {
  127. case ND_CMD_SMART: return "smart";
  128. case ND_CMD_SMART_THRESHOLD: return "smart_thresh";
  129. case ND_CMD_DIMM_FLAGS: return "flags";
  130. case ND_CMD_GET_CONFIG_SIZE: return "get_size";
  131. case ND_CMD_GET_CONFIG_DATA: return "get_data";
  132. case ND_CMD_SET_CONFIG_DATA: return "set_data";
  133. case ND_CMD_VENDOR_EFFECT_LOG_SIZE: return "effect_size";
  134. case ND_CMD_VENDOR_EFFECT_LOG: return "effect_log";
  135. case ND_CMD_VENDOR: return "vendor";
  136. case ND_CMD_CALL: return "cmd_call";
  137. default: return "unknown";
  138. }
  139. }
  140. #define ND_IOCTL 'N'
  141. #define ND_IOCTL_DIMM_FLAGS _IOWR(ND_IOCTL, ND_CMD_DIMM_FLAGS,\
  142. struct nd_cmd_dimm_flags)
  143. #define ND_IOCTL_GET_CONFIG_SIZE _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_SIZE,\
  144. struct nd_cmd_get_config_size)
  145. #define ND_IOCTL_GET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_DATA,\
  146. struct nd_cmd_get_config_data_hdr)
  147. #define ND_IOCTL_SET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_SET_CONFIG_DATA,\
  148. struct nd_cmd_set_config_hdr)
  149. #define ND_IOCTL_VENDOR _IOWR(ND_IOCTL, ND_CMD_VENDOR,\
  150. struct nd_cmd_vendor_hdr)
  151. #define ND_IOCTL_ARS_CAP _IOWR(ND_IOCTL, ND_CMD_ARS_CAP,\
  152. struct nd_cmd_ars_cap)
  153. #define ND_IOCTL_ARS_START _IOWR(ND_IOCTL, ND_CMD_ARS_START,\
  154. struct nd_cmd_ars_start)
  155. #define ND_IOCTL_ARS_STATUS _IOWR(ND_IOCTL, ND_CMD_ARS_STATUS,\
  156. struct nd_cmd_ars_status)
  157. #define ND_IOCTL_CLEAR_ERROR _IOWR(ND_IOCTL, ND_CMD_CLEAR_ERROR,\
  158. struct nd_cmd_clear_error)
  159. #define ND_DEVICE_DIMM 1 /* nd_dimm: container for "config data" */
  160. #define ND_DEVICE_REGION_PMEM 2 /* nd_region: (parent of PMEM namespaces) */
  161. #define ND_DEVICE_REGION_BLK 3 /* nd_region: (parent of BLK namespaces) */
  162. #define ND_DEVICE_NAMESPACE_IO 4 /* legacy persistent memory */
  163. #define ND_DEVICE_NAMESPACE_PMEM 5 /* PMEM namespace (may alias with BLK) */
  164. #define ND_DEVICE_NAMESPACE_BLK 6 /* BLK namespace (may alias with PMEM) */
  165. #define ND_DEVICE_DAX_PMEM 7 /* Device DAX interface to pmem */
  166. enum nd_driver_flags {
  167. ND_DRIVER_DIMM = 1 << ND_DEVICE_DIMM,
  168. ND_DRIVER_REGION_PMEM = 1 << ND_DEVICE_REGION_PMEM,
  169. ND_DRIVER_REGION_BLK = 1 << ND_DEVICE_REGION_BLK,
  170. ND_DRIVER_NAMESPACE_IO = 1 << ND_DEVICE_NAMESPACE_IO,
  171. ND_DRIVER_NAMESPACE_PMEM = 1 << ND_DEVICE_NAMESPACE_PMEM,
  172. ND_DRIVER_NAMESPACE_BLK = 1 << ND_DEVICE_NAMESPACE_BLK,
  173. ND_DRIVER_DAX_PMEM = 1 << ND_DEVICE_DAX_PMEM,
  174. };
  175. enum {
  176. ND_MIN_NAMESPACE_SIZE = PAGE_SIZE,
  177. };
  178. enum ars_masks {
  179. ARS_STATUS_MASK = 0x0000FFFF,
  180. ARS_EXT_STATUS_SHIFT = 16,
  181. };
  182. /*
  183. * struct nd_cmd_pkg
  184. *
  185. * is a wrapper to a quasi pass thru interface for invoking firmware
  186. * associated with nvdimms.
  187. *
  188. * INPUT PARAMETERS
  189. *
  190. * nd_family corresponds to the firmware (e.g. DSM) interface.
  191. *
  192. * nd_command are the function index advertised by the firmware.
  193. *
  194. * nd_size_in is the size of the input parameters being passed to firmware
  195. *
  196. * OUTPUT PARAMETERS
  197. *
  198. * nd_fw_size is the size of the data firmware wants to return for
  199. * the call. If nd_fw_size is greater than size of nd_size_out, only
  200. * the first nd_size_out bytes are returned.
  201. */
  202. struct nd_cmd_pkg {
  203. __u64 nd_family; /* family of commands */
  204. __u64 nd_command;
  205. __u32 nd_size_in; /* INPUT: size of input args */
  206. __u32 nd_size_out; /* INPUT: size of payload */
  207. __u32 nd_reserved2[9]; /* reserved must be zero */
  208. __u32 nd_fw_size; /* OUTPUT: size fw wants to return */
  209. unsigned char nd_payload[]; /* Contents of call */
  210. };
  211. /* These NVDIMM families represent pre-standardization command sets */
  212. #define NVDIMM_FAMILY_INTEL 0
  213. #define NVDIMM_FAMILY_HPE1 1
  214. #define NVDIMM_FAMILY_HPE2 2
  215. #define NVDIMM_FAMILY_MSFT 3
  216. #define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\
  217. struct nd_cmd_pkg)
  218. #endif /* __NDCTL_H__ */