ndctl.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. static const char * const names[] = {
  159. [ND_CMD_ARS_CAP] = "ars_cap",
  160. [ND_CMD_ARS_START] = "ars_start",
  161. [ND_CMD_ARS_STATUS] = "ars_status",
  162. [ND_CMD_CLEAR_ERROR] = "clear_error",
  163. [ND_CMD_CALL] = "cmd_call",
  164. };
  165. if (cmd < ARRAY_SIZE(names) && names[cmd])
  166. return names[cmd];
  167. return "unknown";
  168. }
  169. static inline const char *nvdimm_cmd_name(unsigned cmd)
  170. {
  171. static const char * const names[] = {
  172. [ND_CMD_SMART] = "smart",
  173. [ND_CMD_SMART_THRESHOLD] = "smart_thresh",
  174. [ND_CMD_DIMM_FLAGS] = "flags",
  175. [ND_CMD_GET_CONFIG_SIZE] = "get_size",
  176. [ND_CMD_GET_CONFIG_DATA] = "get_data",
  177. [ND_CMD_SET_CONFIG_DATA] = "set_data",
  178. [ND_CMD_VENDOR_EFFECT_LOG_SIZE] = "effect_size",
  179. [ND_CMD_VENDOR_EFFECT_LOG] = "effect_log",
  180. [ND_CMD_VENDOR] = "vendor",
  181. [ND_CMD_CALL] = "cmd_call",
  182. };
  183. if (cmd < ARRAY_SIZE(names) && names[cmd])
  184. return names[cmd];
  185. return "unknown";
  186. }
  187. #define ND_IOCTL 'N'
  188. #define ND_IOCTL_SMART _IOWR(ND_IOCTL, ND_CMD_SMART,\
  189. struct nd_cmd_smart)
  190. #define ND_IOCTL_SMART_THRESHOLD _IOWR(ND_IOCTL, ND_CMD_SMART_THRESHOLD,\
  191. struct nd_cmd_smart_threshold)
  192. #define ND_IOCTL_DIMM_FLAGS _IOWR(ND_IOCTL, ND_CMD_DIMM_FLAGS,\
  193. struct nd_cmd_dimm_flags)
  194. #define ND_IOCTL_GET_CONFIG_SIZE _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_SIZE,\
  195. struct nd_cmd_get_config_size)
  196. #define ND_IOCTL_GET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_DATA,\
  197. struct nd_cmd_get_config_data_hdr)
  198. #define ND_IOCTL_SET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_SET_CONFIG_DATA,\
  199. struct nd_cmd_set_config_hdr)
  200. #define ND_IOCTL_VENDOR _IOWR(ND_IOCTL, ND_CMD_VENDOR,\
  201. struct nd_cmd_vendor_hdr)
  202. #define ND_IOCTL_ARS_CAP _IOWR(ND_IOCTL, ND_CMD_ARS_CAP,\
  203. struct nd_cmd_ars_cap)
  204. #define ND_IOCTL_ARS_START _IOWR(ND_IOCTL, ND_CMD_ARS_START,\
  205. struct nd_cmd_ars_start)
  206. #define ND_IOCTL_ARS_STATUS _IOWR(ND_IOCTL, ND_CMD_ARS_STATUS,\
  207. struct nd_cmd_ars_status)
  208. #define ND_IOCTL_CLEAR_ERROR _IOWR(ND_IOCTL, ND_CMD_CLEAR_ERROR,\
  209. struct nd_cmd_clear_error)
  210. #define ND_DEVICE_DIMM 1 /* nd_dimm: container for "config data" */
  211. #define ND_DEVICE_REGION_PMEM 2 /* nd_region: (parent of PMEM namespaces) */
  212. #define ND_DEVICE_REGION_BLK 3 /* nd_region: (parent of BLK namespaces) */
  213. #define ND_DEVICE_NAMESPACE_IO 4 /* legacy persistent memory */
  214. #define ND_DEVICE_NAMESPACE_PMEM 5 /* PMEM namespace (may alias with BLK) */
  215. #define ND_DEVICE_NAMESPACE_BLK 6 /* BLK namespace (may alias with PMEM) */
  216. #define ND_DEVICE_DAX_PMEM 7 /* Device DAX interface to pmem */
  217. enum nd_driver_flags {
  218. ND_DRIVER_DIMM = 1 << ND_DEVICE_DIMM,
  219. ND_DRIVER_REGION_PMEM = 1 << ND_DEVICE_REGION_PMEM,
  220. ND_DRIVER_REGION_BLK = 1 << ND_DEVICE_REGION_BLK,
  221. ND_DRIVER_NAMESPACE_IO = 1 << ND_DEVICE_NAMESPACE_IO,
  222. ND_DRIVER_NAMESPACE_PMEM = 1 << ND_DEVICE_NAMESPACE_PMEM,
  223. ND_DRIVER_NAMESPACE_BLK = 1 << ND_DEVICE_NAMESPACE_BLK,
  224. ND_DRIVER_DAX_PMEM = 1 << ND_DEVICE_DAX_PMEM,
  225. };
  226. enum {
  227. ND_MIN_NAMESPACE_SIZE = 0x00400000,
  228. };
  229. enum ars_masks {
  230. ARS_STATUS_MASK = 0x0000FFFF,
  231. ARS_EXT_STATUS_SHIFT = 16,
  232. };
  233. /*
  234. * struct nd_cmd_pkg
  235. *
  236. * is a wrapper to a quasi pass thru interface for invoking firmware
  237. * associated with nvdimms.
  238. *
  239. * INPUT PARAMETERS
  240. *
  241. * nd_family corresponds to the firmware (e.g. DSM) interface.
  242. *
  243. * nd_command are the function index advertised by the firmware.
  244. *
  245. * nd_size_in is the size of the input parameters being passed to firmware
  246. *
  247. * OUTPUT PARAMETERS
  248. *
  249. * nd_fw_size is the size of the data firmware wants to return for
  250. * the call. If nd_fw_size is greater than size of nd_size_out, only
  251. * the first nd_size_out bytes are returned.
  252. */
  253. struct nd_cmd_pkg {
  254. __u64 nd_family; /* family of commands */
  255. __u64 nd_command;
  256. __u32 nd_size_in; /* INPUT: size of input args */
  257. __u32 nd_size_out; /* INPUT: size of payload */
  258. __u32 nd_reserved2[9]; /* reserved must be zero */
  259. __u32 nd_fw_size; /* OUTPUT: size fw wants to return */
  260. unsigned char nd_payload[]; /* Contents of call */
  261. };
  262. /* These NVDIMM families represent pre-standardization command sets */
  263. #define NVDIMM_FAMILY_INTEL 0
  264. #define NVDIMM_FAMILY_HPE1 1
  265. #define NVDIMM_FAMILY_HPE2 2
  266. #define NVDIMM_FAMILY_MSFT 3
  267. #define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\
  268. struct nd_cmd_pkg)
  269. #endif /* __NDCTL_H__ */