nfit.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*
  2. * NVDIMM Firmware Interface Table - NFIT
  3. *
  4. * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of version 2 of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. #ifndef __NFIT_H__
  16. #define __NFIT_H__
  17. #include <linux/workqueue.h>
  18. #include <linux/libnvdimm.h>
  19. #include <linux/ndctl.h>
  20. #include <linux/types.h>
  21. #include <linux/acpi.h>
  22. #include <acpi/acuuid.h>
  23. /* ACPI 6.1 */
  24. #define UUID_NFIT_BUS "2f10e7a4-9e91-11e4-89d3-123b93f75cba"
  25. /* http://pmem.io/documents/NVDIMM_DSM_Interface-V1.6.pdf */
  26. #define UUID_NFIT_DIMM "4309ac30-0d11-11e4-9191-0800200c9a66"
  27. /* https://github.com/HewlettPackard/hpe-nvm/blob/master/Documentation/ */
  28. #define UUID_NFIT_DIMM_N_HPE1 "9002c334-acf3-4c0e-9642-a235f0d53bc6"
  29. #define UUID_NFIT_DIMM_N_HPE2 "5008664b-b758-41a0-a03c-27c2f2d04f7e"
  30. /* https://msdn.microsoft.com/library/windows/hardware/mt604741 */
  31. #define UUID_NFIT_DIMM_N_MSFT "1ee68b36-d4bd-4a1a-9a16-4f8e53d46e05"
  32. #define ACPI_NFIT_MEM_FAILED_MASK (ACPI_NFIT_MEM_SAVE_FAILED \
  33. | ACPI_NFIT_MEM_RESTORE_FAILED | ACPI_NFIT_MEM_FLUSH_FAILED \
  34. | ACPI_NFIT_MEM_NOT_ARMED | ACPI_NFIT_MEM_MAP_FAILED)
  35. #define NVDIMM_FAMILY_MAX NVDIMM_FAMILY_MSFT
  36. #define NVDIMM_STANDARD_CMDMASK \
  37. (1 << ND_CMD_SMART | 1 << ND_CMD_SMART_THRESHOLD | 1 << ND_CMD_DIMM_FLAGS \
  38. | 1 << ND_CMD_GET_CONFIG_SIZE | 1 << ND_CMD_GET_CONFIG_DATA \
  39. | 1 << ND_CMD_SET_CONFIG_DATA | 1 << ND_CMD_VENDOR_EFFECT_LOG_SIZE \
  40. | 1 << ND_CMD_VENDOR_EFFECT_LOG | 1 << ND_CMD_VENDOR)
  41. /*
  42. * Command numbers that the kernel needs to know about to handle
  43. * non-default DSM revision ids
  44. */
  45. enum nvdimm_family_cmds {
  46. NVDIMM_INTEL_LATCH_SHUTDOWN = 10,
  47. NVDIMM_INTEL_GET_MODES = 11,
  48. NVDIMM_INTEL_GET_FWINFO = 12,
  49. NVDIMM_INTEL_START_FWUPDATE = 13,
  50. NVDIMM_INTEL_SEND_FWUPDATE = 14,
  51. NVDIMM_INTEL_FINISH_FWUPDATE = 15,
  52. NVDIMM_INTEL_QUERY_FWUPDATE = 16,
  53. NVDIMM_INTEL_SET_THRESHOLD = 17,
  54. NVDIMM_INTEL_INJECT_ERROR = 18,
  55. };
  56. #define NVDIMM_INTEL_CMDMASK \
  57. (NVDIMM_STANDARD_CMDMASK | 1 << NVDIMM_INTEL_GET_MODES \
  58. | 1 << NVDIMM_INTEL_GET_FWINFO | 1 << NVDIMM_INTEL_START_FWUPDATE \
  59. | 1 << NVDIMM_INTEL_SEND_FWUPDATE | 1 << NVDIMM_INTEL_FINISH_FWUPDATE \
  60. | 1 << NVDIMM_INTEL_QUERY_FWUPDATE | 1 << NVDIMM_INTEL_SET_THRESHOLD \
  61. | 1 << NVDIMM_INTEL_INJECT_ERROR | 1 << NVDIMM_INTEL_LATCH_SHUTDOWN)
  62. enum nfit_uuids {
  63. /* for simplicity alias the uuid index with the family id */
  64. NFIT_DEV_DIMM = NVDIMM_FAMILY_INTEL,
  65. NFIT_DEV_DIMM_N_HPE1 = NVDIMM_FAMILY_HPE1,
  66. NFIT_DEV_DIMM_N_HPE2 = NVDIMM_FAMILY_HPE2,
  67. NFIT_DEV_DIMM_N_MSFT = NVDIMM_FAMILY_MSFT,
  68. NFIT_SPA_VOLATILE,
  69. NFIT_SPA_PM,
  70. NFIT_SPA_DCR,
  71. NFIT_SPA_BDW,
  72. NFIT_SPA_VDISK,
  73. NFIT_SPA_VCD,
  74. NFIT_SPA_PDISK,
  75. NFIT_SPA_PCD,
  76. NFIT_DEV_BUS,
  77. NFIT_UUID_MAX,
  78. };
  79. /*
  80. * Region format interface codes are stored with the interface as the
  81. * LSB and the function as the MSB.
  82. */
  83. #define NFIT_FIC_BYTE cpu_to_le16(0x101) /* byte-addressable energy backed */
  84. #define NFIT_FIC_BLK cpu_to_le16(0x201) /* block-addressable non-energy backed */
  85. #define NFIT_FIC_BYTEN cpu_to_le16(0x301) /* byte-addressable non-energy backed */
  86. enum {
  87. NFIT_BLK_READ_FLUSH = 1,
  88. NFIT_BLK_DCR_LATCH = 2,
  89. NFIT_ARS_STATUS_DONE = 0,
  90. NFIT_ARS_STATUS_BUSY = 1 << 16,
  91. NFIT_ARS_STATUS_NONE = 2 << 16,
  92. NFIT_ARS_STATUS_INTR = 3 << 16,
  93. NFIT_ARS_START_BUSY = 6,
  94. NFIT_ARS_CAP_NONE = 1,
  95. NFIT_ARS_F_OVERFLOW = 1,
  96. NFIT_ARS_TIMEOUT = 90,
  97. };
  98. enum nfit_root_notifiers {
  99. NFIT_NOTIFY_UPDATE = 0x80,
  100. NFIT_NOTIFY_UC_MEMORY_ERROR = 0x81,
  101. };
  102. enum nfit_dimm_notifiers {
  103. NFIT_NOTIFY_DIMM_HEALTH = 0x81,
  104. };
  105. enum nfit_ars_state {
  106. ARS_REQ,
  107. ARS_DONE,
  108. ARS_SHORT,
  109. ARS_FAILED,
  110. };
  111. struct nfit_spa {
  112. struct list_head list;
  113. struct nd_region *nd_region;
  114. unsigned long ars_state;
  115. u32 clear_err_unit;
  116. u32 max_ars;
  117. struct acpi_nfit_system_address spa[0];
  118. };
  119. struct nfit_dcr {
  120. struct list_head list;
  121. struct acpi_nfit_control_region dcr[0];
  122. };
  123. struct nfit_bdw {
  124. struct list_head list;
  125. struct acpi_nfit_data_region bdw[0];
  126. };
  127. struct nfit_idt {
  128. struct list_head list;
  129. struct acpi_nfit_interleave idt[0];
  130. };
  131. struct nfit_flush {
  132. struct list_head list;
  133. struct acpi_nfit_flush_address flush[0];
  134. };
  135. struct nfit_memdev {
  136. struct list_head list;
  137. struct acpi_nfit_memory_map memdev[0];
  138. };
  139. /* assembled tables for a given dimm/memory-device */
  140. struct nfit_mem {
  141. struct nvdimm *nvdimm;
  142. struct acpi_nfit_memory_map *memdev_dcr;
  143. struct acpi_nfit_memory_map *memdev_pmem;
  144. struct acpi_nfit_memory_map *memdev_bdw;
  145. struct acpi_nfit_control_region *dcr;
  146. struct acpi_nfit_data_region *bdw;
  147. struct acpi_nfit_system_address *spa_dcr;
  148. struct acpi_nfit_system_address *spa_bdw;
  149. struct acpi_nfit_interleave *idt_dcr;
  150. struct acpi_nfit_interleave *idt_bdw;
  151. struct kernfs_node *flags_attr;
  152. struct nfit_flush *nfit_flush;
  153. struct list_head list;
  154. struct acpi_device *adev;
  155. struct acpi_nfit_desc *acpi_desc;
  156. struct resource *flush_wpq;
  157. unsigned long dsm_mask;
  158. int family;
  159. bool has_lsr;
  160. bool has_lsw;
  161. };
  162. struct acpi_nfit_desc {
  163. struct nvdimm_bus_descriptor nd_desc;
  164. struct acpi_table_header acpi_header;
  165. struct mutex init_mutex;
  166. struct list_head memdevs;
  167. struct list_head flushes;
  168. struct list_head dimms;
  169. struct list_head spas;
  170. struct list_head dcrs;
  171. struct list_head bdws;
  172. struct list_head idts;
  173. struct nvdimm_bus *nvdimm_bus;
  174. struct device *dev;
  175. u8 ars_start_flags;
  176. struct nd_cmd_ars_status *ars_status;
  177. struct delayed_work dwork;
  178. struct list_head list;
  179. struct kernfs_node *scrub_count_state;
  180. unsigned int max_ars;
  181. unsigned int scrub_count;
  182. unsigned int scrub_mode;
  183. unsigned int cancel:1;
  184. unsigned long dimm_cmd_force_en;
  185. unsigned long bus_cmd_force_en;
  186. unsigned long bus_nfit_cmd_force_en;
  187. unsigned int platform_cap;
  188. unsigned int scrub_tmo;
  189. int (*blk_do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
  190. void *iobuf, u64 len, int rw);
  191. };
  192. enum scrub_mode {
  193. HW_ERROR_SCRUB_OFF,
  194. HW_ERROR_SCRUB_ON,
  195. };
  196. enum nd_blk_mmio_selector {
  197. BDW,
  198. DCR,
  199. };
  200. struct nd_blk_addr {
  201. union {
  202. void __iomem *base;
  203. void *aperture;
  204. };
  205. };
  206. struct nfit_blk {
  207. struct nfit_blk_mmio {
  208. struct nd_blk_addr addr;
  209. u64 size;
  210. u64 base_offset;
  211. u32 line_size;
  212. u32 num_lines;
  213. u32 table_size;
  214. struct acpi_nfit_interleave *idt;
  215. struct acpi_nfit_system_address *spa;
  216. } mmio[2];
  217. struct nd_region *nd_region;
  218. u64 bdw_offset; /* post interleave offset */
  219. u64 stat_offset;
  220. u64 cmd_offset;
  221. u32 dimm_flags;
  222. };
  223. extern struct list_head acpi_descs;
  224. extern struct mutex acpi_desc_lock;
  225. int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc, unsigned long flags);
  226. #ifdef CONFIG_X86_MCE
  227. void nfit_mce_register(void);
  228. void nfit_mce_unregister(void);
  229. #else
  230. static inline void nfit_mce_register(void)
  231. {
  232. }
  233. static inline void nfit_mce_unregister(void)
  234. {
  235. }
  236. #endif
  237. int nfit_spa_type(struct acpi_nfit_system_address *spa);
  238. static inline struct acpi_nfit_memory_map *__to_nfit_memdev(
  239. struct nfit_mem *nfit_mem)
  240. {
  241. if (nfit_mem->memdev_dcr)
  242. return nfit_mem->memdev_dcr;
  243. return nfit_mem->memdev_pmem;
  244. }
  245. static inline struct acpi_nfit_desc *to_acpi_desc(
  246. struct nvdimm_bus_descriptor *nd_desc)
  247. {
  248. return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
  249. }
  250. const guid_t *to_nfit_uuid(enum nfit_uuids id);
  251. int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz);
  252. void acpi_nfit_shutdown(void *data);
  253. void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event);
  254. void __acpi_nvdimm_notify(struct device *dev, u32 event);
  255. int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
  256. unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc);
  257. void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev);
  258. #endif /* __NFIT_H__ */