ndctl.h 7.5 KB

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