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