nfit.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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_SHORT,
  107. ARS_REQ_LONG,
  108. ARS_FAILED,
  109. };
  110. struct nfit_spa {
  111. struct list_head list;
  112. struct nd_region *nd_region;
  113. unsigned long ars_state;
  114. u32 clear_err_unit;
  115. u32 max_ars;
  116. struct acpi_nfit_system_address spa[0];
  117. };
  118. struct nfit_dcr {
  119. struct list_head list;
  120. struct acpi_nfit_control_region dcr[0];
  121. };
  122. struct nfit_bdw {
  123. struct list_head list;
  124. struct acpi_nfit_data_region bdw[0];
  125. };
  126. struct nfit_idt {
  127. struct list_head list;
  128. struct acpi_nfit_interleave idt[0];
  129. };
  130. struct nfit_flush {
  131. struct list_head list;
  132. struct acpi_nfit_flush_address flush[0];
  133. };
  134. struct nfit_memdev {
  135. struct list_head list;
  136. struct acpi_nfit_memory_map memdev[0];
  137. };
  138. enum nfit_mem_flags {
  139. NFIT_MEM_LSR,
  140. NFIT_MEM_LSW,
  141. NFIT_MEM_DIRTY,
  142. NFIT_MEM_DIRTY_COUNT,
  143. };
  144. /* assembled tables for a given dimm/memory-device */
  145. struct nfit_mem {
  146. struct nvdimm *nvdimm;
  147. struct acpi_nfit_memory_map *memdev_dcr;
  148. struct acpi_nfit_memory_map *memdev_pmem;
  149. struct acpi_nfit_memory_map *memdev_bdw;
  150. struct acpi_nfit_control_region *dcr;
  151. struct acpi_nfit_data_region *bdw;
  152. struct acpi_nfit_system_address *spa_dcr;
  153. struct acpi_nfit_system_address *spa_bdw;
  154. struct acpi_nfit_interleave *idt_dcr;
  155. struct acpi_nfit_interleave *idt_bdw;
  156. struct kernfs_node *flags_attr;
  157. struct nfit_flush *nfit_flush;
  158. struct list_head list;
  159. struct acpi_device *adev;
  160. struct acpi_nfit_desc *acpi_desc;
  161. struct resource *flush_wpq;
  162. unsigned long dsm_mask;
  163. unsigned long flags;
  164. u32 dirty_shutdown;
  165. int family;
  166. };
  167. struct acpi_nfit_desc {
  168. struct nvdimm_bus_descriptor nd_desc;
  169. struct acpi_table_header acpi_header;
  170. struct mutex init_mutex;
  171. struct list_head memdevs;
  172. struct list_head flushes;
  173. struct list_head dimms;
  174. struct list_head spas;
  175. struct list_head dcrs;
  176. struct list_head bdws;
  177. struct list_head idts;
  178. struct nvdimm_bus *nvdimm_bus;
  179. struct device *dev;
  180. u8 ars_start_flags;
  181. struct nd_cmd_ars_status *ars_status;
  182. struct nfit_spa *scrub_spa;
  183. struct delayed_work dwork;
  184. struct list_head list;
  185. struct kernfs_node *scrub_count_state;
  186. unsigned int max_ars;
  187. unsigned int scrub_count;
  188. unsigned int scrub_mode;
  189. unsigned int scrub_busy:1;
  190. unsigned int cancel:1;
  191. unsigned long dimm_cmd_force_en;
  192. unsigned long bus_cmd_force_en;
  193. unsigned long bus_nfit_cmd_force_en;
  194. unsigned int platform_cap;
  195. unsigned int scrub_tmo;
  196. int (*blk_do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
  197. void *iobuf, u64 len, int rw);
  198. };
  199. enum scrub_mode {
  200. HW_ERROR_SCRUB_OFF,
  201. HW_ERROR_SCRUB_ON,
  202. };
  203. enum nd_blk_mmio_selector {
  204. BDW,
  205. DCR,
  206. };
  207. struct nd_blk_addr {
  208. union {
  209. void __iomem *base;
  210. void *aperture;
  211. };
  212. };
  213. struct nfit_blk {
  214. struct nfit_blk_mmio {
  215. struct nd_blk_addr addr;
  216. u64 size;
  217. u64 base_offset;
  218. u32 line_size;
  219. u32 num_lines;
  220. u32 table_size;
  221. struct acpi_nfit_interleave *idt;
  222. struct acpi_nfit_system_address *spa;
  223. } mmio[2];
  224. struct nd_region *nd_region;
  225. u64 bdw_offset; /* post interleave offset */
  226. u64 stat_offset;
  227. u64 cmd_offset;
  228. u32 dimm_flags;
  229. };
  230. extern struct list_head acpi_descs;
  231. extern struct mutex acpi_desc_lock;
  232. int acpi_nfit_ars_rescan(struct acpi_nfit_desc *acpi_desc,
  233. enum nfit_ars_state req_type);
  234. #ifdef CONFIG_X86_MCE
  235. void nfit_mce_register(void);
  236. void nfit_mce_unregister(void);
  237. #else
  238. static inline void nfit_mce_register(void)
  239. {
  240. }
  241. static inline void nfit_mce_unregister(void)
  242. {
  243. }
  244. #endif
  245. int nfit_spa_type(struct acpi_nfit_system_address *spa);
  246. static inline struct acpi_nfit_memory_map *__to_nfit_memdev(
  247. struct nfit_mem *nfit_mem)
  248. {
  249. if (nfit_mem->memdev_dcr)
  250. return nfit_mem->memdev_dcr;
  251. return nfit_mem->memdev_pmem;
  252. }
  253. static inline struct acpi_nfit_desc *to_acpi_desc(
  254. struct nvdimm_bus_descriptor *nd_desc)
  255. {
  256. return container_of(nd_desc, struct acpi_nfit_desc, nd_desc);
  257. }
  258. const guid_t *to_nfit_uuid(enum nfit_uuids id);
  259. int acpi_nfit_init(struct acpi_nfit_desc *acpi_desc, void *nfit, acpi_size sz);
  260. void acpi_nfit_shutdown(void *data);
  261. void __acpi_nfit_notify(struct device *dev, acpi_handle handle, u32 event);
  262. void __acpi_nvdimm_notify(struct device *dev, u32 event);
  263. int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm,
  264. unsigned int cmd, void *buf, unsigned int buf_len, int *cmd_rc);
  265. void acpi_nfit_desc_init(struct acpi_nfit_desc *acpi_desc, struct device *dev);
  266. #endif /* __NFIT_H__ */