skx_common.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Common codes for both the skx_edac driver and Intel 10nm server EDAC driver.
  4. * Originally split out from the skx_edac driver.
  5. *
  6. * Copyright (c) 2018, Intel Corporation.
  7. */
  8. #ifndef _SKX_COMM_EDAC_H
  9. #define _SKX_COMM_EDAC_H
  10. #include <linux/bits.h>
  11. #include <asm/mce.h>
  12. #define MSG_SIZE 1024
  13. /*
  14. * Debug macros
  15. */
  16. #define skx_printk(level, fmt, arg...) \
  17. edac_printk(level, "skx", fmt, ##arg)
  18. #define skx_mc_printk(mci, level, fmt, arg...) \
  19. edac_mc_chipset_printk(mci, level, "skx", fmt, ##arg)
  20. /*
  21. * Get a bit field at register value <v>, from bit <lo> to bit <hi>
  22. */
  23. #define GET_BITFIELD(v, lo, hi) \
  24. (((v) & GENMASK_ULL((hi), (lo))) >> (lo))
  25. #define SKX_NUM_IMC 2 /* Memory controllers per socket */
  26. #define SKX_NUM_CHANNELS 3 /* Channels per memory controller */
  27. #define SKX_NUM_DIMMS 2 /* Max DIMMS per channel */
  28. #define I10NM_NUM_DDR_IMC 12
  29. #define I10NM_NUM_DDR_CHANNELS 2
  30. #define I10NM_NUM_DDR_DIMMS 2
  31. #define I10NM_NUM_HBM_IMC 16
  32. #define I10NM_NUM_HBM_CHANNELS 2
  33. #define I10NM_NUM_HBM_DIMMS 1
  34. #define I10NM_NUM_IMC (I10NM_NUM_DDR_IMC + I10NM_NUM_HBM_IMC)
  35. #define I10NM_NUM_CHANNELS MAX(I10NM_NUM_DDR_CHANNELS, I10NM_NUM_HBM_CHANNELS)
  36. #define I10NM_NUM_DIMMS MAX(I10NM_NUM_DDR_DIMMS, I10NM_NUM_HBM_DIMMS)
  37. #define NUM_IMC MAX(SKX_NUM_IMC, I10NM_NUM_IMC)
  38. #define NUM_CHANNELS MAX(SKX_NUM_CHANNELS, I10NM_NUM_CHANNELS)
  39. #define NUM_DIMMS MAX(SKX_NUM_DIMMS, I10NM_NUM_DIMMS)
  40. #define IS_DIMM_PRESENT(r) GET_BITFIELD(r, 15, 15)
  41. #define IS_NVDIMM_PRESENT(r, i) GET_BITFIELD(r, i, i)
  42. #define MCI_MISC_ECC_MODE(m) (((m) >> 59) & 15)
  43. #define MCI_MISC_ECC_DDRT 8 /* read from DDRT */
  44. /*
  45. * According to Intel Architecture spec vol 3B,
  46. * Table 15-10 "IA32_MCi_Status [15:0] Compound Error Code Encoding"
  47. * memory errors should fit one of these masks:
  48. * 000f 0000 1mmm cccc (binary)
  49. * 000f 0010 1mmm cccc (binary) [RAM used as cache]
  50. * where:
  51. * f = Correction Report Filtering Bit. If 1, subsequent errors
  52. * won't be shown
  53. * mmm = error type
  54. * cccc = channel
  55. */
  56. #define MCACOD_MEM_ERR_MASK 0xef80
  57. /*
  58. * Errors from either the memory of the 1-level memory system or the
  59. * 2nd level memory (the slow "far" memory) of the 2-level memory system.
  60. */
  61. #define MCACOD_MEM_CTL_ERR 0x80
  62. /*
  63. * Errors from the 1st level memory (the fast "near" memory as cache)
  64. * of the 2-level memory system.
  65. */
  66. #define MCACOD_EXT_MEM_ERR 0x280
  67. /* Max RRL register sets per {,sub-,pseudo-}channel. */
  68. #define NUM_RRL_SET 3
  69. /*
  70. * Each cpu socket contains some pci devices that provide global
  71. * information, and also some that are local to each of the two
  72. * memory controllers on the die.
  73. */
  74. struct skx_dev {
  75. struct list_head list;
  76. u8 bus[4];
  77. int seg;
  78. struct pci_dev *sad_all;
  79. struct pci_dev *util_all;
  80. struct pci_dev *uracu; /* for i10nm CPU */
  81. struct pci_dev *pcu_cr3; /* for HBM memory detection */
  82. u32 mcroute;
  83. /*
  84. * Some server BIOS may hide certain memory controllers, and the
  85. * EDAC driver skips those hidden memory controllers. However, the
  86. * ADXL still decodes memory error address using physical memory
  87. * controller indices. The mapping table is used to convert the
  88. * physical indices (reported by ADXL) to the logical indices
  89. * (used the EDAC driver) of present memory controllers during the
  90. * error handling process.
  91. */
  92. u8 mc_mapping[NUM_IMC];
  93. struct skx_imc {
  94. struct mem_ctl_info *mci;
  95. struct pci_dev *mdev; /* for i10nm CPU */
  96. void __iomem *mbase; /* for i10nm CPU */
  97. int chan_mmio_sz; /* for i10nm CPU */
  98. int num_channels; /* channels per memory controller */
  99. int num_dimms; /* dimms per channel */
  100. bool hbm_mc;
  101. u8 mc; /* system wide mc# */
  102. u8 lmc; /* socket relative mc# */
  103. u8 src_id, node_id;
  104. struct skx_channel {
  105. struct pci_dev *cdev;
  106. struct pci_dev *edev;
  107. /*
  108. * Two groups of RRL control registers per channel to save default RRL
  109. * settings of two {sub-,pseudo-}channels in Linux RRL control mode.
  110. */
  111. u32 rrl_ctl[2][NUM_RRL_SET];
  112. struct skx_dimm {
  113. u8 close_pg;
  114. u8 bank_xor_enable;
  115. u8 fine_grain_bank;
  116. u8 rowbits;
  117. u8 colbits;
  118. } dimms[NUM_DIMMS];
  119. } chan[NUM_CHANNELS];
  120. } imc[NUM_IMC];
  121. };
  122. struct skx_pvt {
  123. struct skx_imc *imc;
  124. };
  125. enum type {
  126. SKX,
  127. I10NM,
  128. SPR,
  129. GNR
  130. };
  131. enum {
  132. INDEX_SOCKET,
  133. INDEX_MEMCTRL,
  134. INDEX_CHANNEL,
  135. INDEX_DIMM,
  136. INDEX_CS,
  137. INDEX_NM_FIRST,
  138. INDEX_NM_MEMCTRL = INDEX_NM_FIRST,
  139. INDEX_NM_CHANNEL,
  140. INDEX_NM_DIMM,
  141. INDEX_NM_CS,
  142. INDEX_MAX
  143. };
  144. enum error_source {
  145. ERR_SRC_1LM,
  146. ERR_SRC_2LM_NM,
  147. ERR_SRC_2LM_FM,
  148. ERR_SRC_NOT_MEMORY,
  149. };
  150. #define BIT_NM_MEMCTRL BIT_ULL(INDEX_NM_MEMCTRL)
  151. #define BIT_NM_CHANNEL BIT_ULL(INDEX_NM_CHANNEL)
  152. #define BIT_NM_DIMM BIT_ULL(INDEX_NM_DIMM)
  153. #define BIT_NM_CS BIT_ULL(INDEX_NM_CS)
  154. struct decoded_addr {
  155. struct mce *mce;
  156. struct skx_dev *dev;
  157. u64 addr;
  158. int socket;
  159. int imc;
  160. int channel;
  161. u64 chan_addr;
  162. int sktways;
  163. int chanways;
  164. int dimm;
  165. int cs;
  166. int rank;
  167. int channel_rank;
  168. u64 rank_address;
  169. int row;
  170. int column;
  171. int bank_address;
  172. int bank_group;
  173. bool decoded_by_adxl;
  174. };
  175. struct pci_bdf {
  176. u32 bus : 8;
  177. u32 dev : 5;
  178. u32 fun : 3;
  179. };
  180. struct res_config {
  181. enum type type;
  182. /* Configuration agent device ID */
  183. unsigned int decs_did;
  184. /* Default bus number configuration register offset */
  185. int busno_cfg_offset;
  186. /* DDR memory controllers per socket */
  187. int ddr_imc_num;
  188. /* DDR channels per DDR memory controller */
  189. int ddr_chan_num;
  190. /* DDR DIMMs per DDR memory channel */
  191. int ddr_dimm_num;
  192. /* Per DDR channel memory-mapped I/O size */
  193. int ddr_chan_mmio_sz;
  194. /* HBM memory controllers per socket */
  195. int hbm_imc_num;
  196. /* HBM channels per HBM memory controller */
  197. int hbm_chan_num;
  198. /* HBM DIMMs per HBM memory channel */
  199. int hbm_dimm_num;
  200. /* Per HBM channel memory-mapped I/O size */
  201. int hbm_chan_mmio_sz;
  202. bool support_ddr5;
  203. /* SAD device BDF */
  204. struct pci_bdf sad_all_bdf;
  205. /* PCU device BDF */
  206. struct pci_bdf pcu_cr3_bdf;
  207. /* UTIL device BDF */
  208. struct pci_bdf util_all_bdf;
  209. /* URACU device BDF */
  210. struct pci_bdf uracu_bdf;
  211. /* DDR mdev device BDF */
  212. struct pci_bdf ddr_mdev_bdf;
  213. /* HBM mdev device BDF */
  214. struct pci_bdf hbm_mdev_bdf;
  215. int sad_all_offset;
  216. /* Offsets of retry_rd_err_log registers */
  217. u32 *offsets_scrub;
  218. u32 *offsets_scrub_hbm0;
  219. u32 *offsets_scrub_hbm1;
  220. u32 *offsets_demand;
  221. u32 *offsets_demand2;
  222. u32 *offsets_demand_hbm0;
  223. u32 *offsets_demand_hbm1;
  224. };
  225. typedef int (*get_dimm_config_f)(struct mem_ctl_info *mci,
  226. struct res_config *cfg);
  227. typedef bool (*skx_decode_f)(struct decoded_addr *res);
  228. typedef void (*skx_show_retry_log_f)(struct decoded_addr *res, char *msg, int len, bool scrub_err);
  229. int skx_adxl_get(void);
  230. void skx_adxl_put(void);
  231. void skx_set_decode(skx_decode_f decode, skx_show_retry_log_f show_retry_log);
  232. void skx_set_mem_cfg(bool mem_cfg_2lm);
  233. void skx_set_res_cfg(struct res_config *cfg);
  234. void skx_set_mc_mapping(struct skx_dev *d, u8 pmc, u8 lmc);
  235. int skx_get_src_id(struct skx_dev *d, int off, u8 *id);
  236. int skx_get_node_id(struct skx_dev *d, u8 *id);
  237. int skx_get_all_bus_mappings(struct res_config *cfg, struct list_head **list);
  238. int skx_get_hi_lo(unsigned int did, int off[], u64 *tolm, u64 *tohm);
  239. int skx_get_dimm_info(u32 mtr, u32 mcmtr, u32 amap, struct dimm_info *dimm,
  240. struct skx_imc *imc, int chan, int dimmno,
  241. struct res_config *cfg);
  242. int skx_get_nvdimm_info(struct dimm_info *dimm, struct skx_imc *imc,
  243. int chan, int dimmno, const char *mod_str);
  244. int skx_register_mci(struct skx_imc *imc, struct pci_dev *pdev,
  245. const char *ctl_name, const char *mod_str,
  246. get_dimm_config_f get_dimm_config,
  247. struct res_config *cfg);
  248. int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
  249. void *data);
  250. void skx_remove(void);
  251. #ifdef CONFIG_EDAC_DEBUG
  252. void skx_setup_debug(const char *name);
  253. void skx_teardown_debug(void);
  254. #else
  255. static inline void skx_setup_debug(const char *name) {}
  256. static inline void skx_teardown_debug(void) {}
  257. #endif
  258. #endif /* _SKX_COMM_EDAC_H */