1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Common codes for both the skx_edac driver and Intel 10nm server EDAC driver.
4 * Originally split out from the skx_edac driver.
6 * Copyright (c) 2018, Intel Corporation.
9 #ifndef _SKX_COMM_EDAC_H
10 #define _SKX_COMM_EDAC_H
12 #include <linux/bits.h>
19 #define skx_printk(level, fmt, arg...) \
20 edac_printk(level, "skx", fmt, ##arg)
22 #define skx_mc_printk(mci, level, fmt, arg...) \
23 edac_mc_chipset_printk(mci, level, "skx", fmt, ##arg)
26 * Get a bit field at register value <v>, from bit <lo> to bit <hi>
28 #define GET_BITFIELD(v, lo, hi) \
29 (((v) & GENMASK_ULL((hi), (lo))) >> (lo))
31 #define SKX_NUM_IMC 2 /* Memory controllers per socket */
32 #define SKX_NUM_CHANNELS 3 /* Channels per memory controller */
33 #define SKX_NUM_DIMMS 2 /* Max DIMMS per channel */
35 #define I10NM_NUM_DDR_IMC 4
36 #define I10NM_NUM_DDR_CHANNELS 2
37 #define I10NM_NUM_DDR_DIMMS 2
39 #define I10NM_NUM_HBM_IMC 16
40 #define I10NM_NUM_HBM_CHANNELS 2
41 #define I10NM_NUM_HBM_DIMMS 1
43 #define I10NM_NUM_IMC (I10NM_NUM_DDR_IMC + I10NM_NUM_HBM_IMC)
44 #define I10NM_NUM_CHANNELS MAX(I10NM_NUM_DDR_CHANNELS, I10NM_NUM_HBM_CHANNELS)
45 #define I10NM_NUM_DIMMS MAX(I10NM_NUM_DDR_DIMMS, I10NM_NUM_HBM_DIMMS)
47 #define MAX(a, b) ((a) > (b) ? (a) : (b))
48 #define NUM_IMC MAX(SKX_NUM_IMC, I10NM_NUM_IMC)
49 #define NUM_CHANNELS MAX(SKX_NUM_CHANNELS, I10NM_NUM_CHANNELS)
50 #define NUM_DIMMS MAX(SKX_NUM_DIMMS, I10NM_NUM_DIMMS)
52 #define IS_DIMM_PRESENT(r) GET_BITFIELD(r, 15, 15)
53 #define IS_NVDIMM_PRESENT(r, i) GET_BITFIELD(r, i, i)
56 * Each cpu socket contains some pci devices that provide global
57 * information, and also some that are local to each of the two
58 * memory controllers on the die.
61 struct list_head list;
64 struct pci_dev *sad_all;
65 struct pci_dev *util_all;
66 struct pci_dev *uracu; /* for i10nm CPU */
67 struct pci_dev *pcu_cr3; /* for HBM memory detection */
70 struct mem_ctl_info *mci;
71 struct pci_dev *mdev; /* for i10nm CPU */
72 void __iomem *mbase; /* for i10nm CPU */
73 int chan_mmio_sz; /* for i10nm CPU */
74 int num_channels; /* channels per memory controller */
75 int num_dimms; /* dimms per channel */
77 u8 mc; /* system wide mc# */
78 u8 lmc; /* socket relative mc# */
83 u32 retry_rd_err_log_s;
84 u32 retry_rd_err_log_d;
112 INDEX_NM_MEMCTRL = INDEX_NM_FIRST,
118 #define BIT_NM_MEMCTRL BIT_ULL(INDEX_NM_MEMCTRL)
119 #define BIT_NM_CHANNEL BIT_ULL(INDEX_NM_CHANNEL)
120 #define BIT_NM_DIMM BIT_ULL(INDEX_NM_DIMM)
122 struct decoded_addr {
143 /* Configuration agent device ID */
144 unsigned int decs_did;
145 /* Default bus number configuration register offset */
146 int busno_cfg_offset;
147 /* Per DDR channel memory-mapped I/O size */
148 int ddr_chan_mmio_sz;
149 /* Per HBM channel memory-mapped I/O size */
150 int hbm_chan_mmio_sz;
152 /* SAD device number and function number */
153 unsigned int sad_all_devfn;
155 /* Offsets of retry_rd_err_log registers */
160 typedef int (*get_dimm_config_f)(struct mem_ctl_info *mci,
161 struct res_config *cfg);
162 typedef bool (*skx_decode_f)(struct decoded_addr *res);
163 typedef void (*skx_show_retry_log_f)(struct decoded_addr *res, char *msg, int len, bool scrub_err);
165 int __init skx_adxl_get(void);
166 void __exit skx_adxl_put(void);
167 void skx_set_decode(skx_decode_f decode, skx_show_retry_log_f show_retry_log);
168 void skx_set_mem_cfg(bool mem_cfg_2lm);
170 int skx_get_src_id(struct skx_dev *d, int off, u8 *id);
171 int skx_get_node_id(struct skx_dev *d, u8 *id);
173 int skx_get_all_bus_mappings(struct res_config *cfg, struct list_head **list);
175 int skx_get_hi_lo(unsigned int did, int off[], u64 *tolm, u64 *tohm);
177 int skx_get_dimm_info(u32 mtr, u32 mcmtr, u32 amap, struct dimm_info *dimm,
178 struct skx_imc *imc, int chan, int dimmno,
179 struct res_config *cfg);
181 int skx_get_nvdimm_info(struct dimm_info *dimm, struct skx_imc *imc,
182 int chan, int dimmno, const char *mod_str);
184 int skx_register_mci(struct skx_imc *imc, struct pci_dev *pdev,
185 const char *ctl_name, const char *mod_str,
186 get_dimm_config_f get_dimm_config,
187 struct res_config *cfg);
189 int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
192 void skx_remove(void);
194 #endif /* _SKX_COMM_EDAC_H */