ndctl.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. __u32 reserved;
  96. } __packed;
  97. struct nd_cmd_ars_start {
  98. __u64 address;
  99. __u64 length;
  100. __u16 type;
  101. __u8 flags;
  102. __u8 reserved[5];
  103. __u32 status;
  104. __u32 scrub_time;
  105. } __packed;
  106. struct nd_cmd_ars_status {
  107. __u32 status;
  108. __u32 out_length;
  109. __u64 address;
  110. __u64 length;
  111. __u64 restart_address;
  112. __u64 restart_length;
  113. __u16 type;
  114. __u16 flags;
  115. __u32 num_records;
  116. struct nd_ars_record {
  117. __u32 handle;
  118. __u32 reserved;
  119. __u64 err_address;
  120. __u64 length;
  121. } __packed records[0];
  122. } __packed;
  123. struct nd_cmd_clear_error {
  124. __u64 address;
  125. __u64 length;
  126. __u32 status;
  127. __u8 reserved[4];
  128. __u64 cleared;
  129. } __packed;
  130. enum {
  131. ND_CMD_IMPLEMENTED = 0,
  132. /* bus commands */
  133. ND_CMD_ARS_CAP = 1,
  134. ND_CMD_ARS_START = 2,
  135. ND_CMD_ARS_STATUS = 3,
  136. ND_CMD_CLEAR_ERROR = 4,
  137. /* per-dimm commands */
  138. ND_CMD_SMART = 1,
  139. ND_CMD_SMART_THRESHOLD = 2,
  140. ND_CMD_DIMM_FLAGS = 3,
  141. ND_CMD_GET_CONFIG_SIZE = 4,
  142. ND_CMD_GET_CONFIG_DATA = 5,
  143. ND_CMD_SET_CONFIG_DATA = 6,
  144. ND_CMD_VENDOR_EFFECT_LOG_SIZE = 7,
  145. ND_CMD_VENDOR_EFFECT_LOG = 8,
  146. ND_CMD_VENDOR = 9,
  147. ND_CMD_CALL = 10,
  148. };
  149. enum {
  150. ND_ARS_VOLATILE = 1,
  151. ND_ARS_PERSISTENT = 2,
  152. };
  153. static inline const char *nvdimm_bus_cmd_name(unsigned cmd)
  154. {
  155. static const char * const names[] = {
  156. [ND_CMD_ARS_CAP] = "ars_cap",
  157. [ND_CMD_ARS_START] = "ars_start",
  158. [ND_CMD_ARS_STATUS] = "ars_status",
  159. [ND_CMD_CLEAR_ERROR] = "clear_error",
  160. };
  161. if (cmd < ARRAY_SIZE(names) && names[cmd])
  162. return names[cmd];
  163. return "unknown";
  164. }
  165. static inline const char *nvdimm_cmd_name(unsigned cmd)
  166. {
  167. static const char * const names[] = {
  168. [ND_CMD_SMART] = "smart",
  169. [ND_CMD_SMART_THRESHOLD] = "smart_thresh",
  170. [ND_CMD_DIMM_FLAGS] = "flags",
  171. [ND_CMD_GET_CONFIG_SIZE] = "get_size",
  172. [ND_CMD_GET_CONFIG_DATA] = "get_data",
  173. [ND_CMD_SET_CONFIG_DATA] = "set_data",
  174. [ND_CMD_VENDOR_EFFECT_LOG_SIZE] = "effect_size",
  175. [ND_CMD_VENDOR_EFFECT_LOG] = "effect_log",
  176. [ND_CMD_VENDOR] = "vendor",
  177. [ND_CMD_CALL] = "cmd_call",
  178. };
  179. if (cmd < ARRAY_SIZE(names) && names[cmd])
  180. return names[cmd];
  181. return "unknown";
  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 {
  223. ND_MIN_NAMESPACE_SIZE = 0x00400000,
  224. };
  225. enum ars_masks {
  226. ARS_STATUS_MASK = 0x0000FFFF,
  227. ARS_EXT_STATUS_SHIFT = 16,
  228. };
  229. /*
  230. * struct nd_cmd_pkg
  231. *
  232. * is a wrapper to a quasi pass thru interface for invoking firmware
  233. * associated with nvdimms.
  234. *
  235. * INPUT PARAMETERS
  236. *
  237. * nd_family corresponds to the firmware (e.g. DSM) interface.
  238. *
  239. * nd_command are the function index advertised by the firmware.
  240. *
  241. * nd_size_in is the size of the input parameters being passed to firmware
  242. *
  243. * OUTPUT PARAMETERS
  244. *
  245. * nd_fw_size is the size of the data firmware wants to return for
  246. * the call. If nd_fw_size is greater than size of nd_size_out, only
  247. * the first nd_size_out bytes are returned.
  248. */
  249. struct nd_cmd_pkg {
  250. __u64 nd_family; /* family of commands */
  251. __u64 nd_command;
  252. __u32 nd_size_in; /* INPUT: size of input args */
  253. __u32 nd_size_out; /* INPUT: size of payload */
  254. __u32 nd_reserved2[9]; /* reserved must be zero */
  255. __u32 nd_fw_size; /* OUTPUT: size fw wants to return */
  256. unsigned char nd_payload[]; /* Contents of call */
  257. };
  258. /* These NVDIMM families represent pre-standardization command sets */
  259. #define NVDIMM_FAMILY_INTEL 0
  260. #define NVDIMM_FAMILY_HPE1 1
  261. #define NVDIMM_FAMILY_HPE2 2
  262. #define NVDIMM_FAMILY_MSFT 3
  263. #define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\
  264. struct nd_cmd_pkg)
  265. #endif /* __NDCTL_H__ */