Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 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 | |
| 9 | #ifndef _SKX_COMM_EDAC_H |
| 10 | #define _SKX_COMM_EDAC_H |
| 11 | |
Qiuxu Zhuo | 2f4348e | 2021-06-11 10:01:18 -0700 | [diff] [blame] | 12 | #include <linux/bits.h> |
| 13 | |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 14 | #define MSG_SIZE 1024 |
| 15 | |
| 16 | /* |
| 17 | * Debug macros |
| 18 | */ |
| 19 | #define skx_printk(level, fmt, arg...) \ |
| 20 | edac_printk(level, "skx", fmt, ##arg) |
| 21 | |
| 22 | #define skx_mc_printk(mci, level, fmt, arg...) \ |
| 23 | edac_mc_chipset_printk(mci, level, "skx", fmt, ##arg) |
| 24 | |
| 25 | /* |
| 26 | * Get a bit field at register value <v>, from bit <lo> to bit <hi> |
| 27 | */ |
| 28 | #define GET_BITFIELD(v, lo, hi) \ |
| 29 | (((v) & GENMASK_ULL((hi), (lo))) >> (lo)) |
| 30 | |
| 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 */ |
| 34 | |
Qiuxu Zhuo | c945088 | 2021-06-11 10:01:20 -0700 | [diff] [blame] | 35 | #define I10NM_NUM_DDR_IMC 4 |
| 36 | #define I10NM_NUM_DDR_CHANNELS 2 |
| 37 | #define I10NM_NUM_DDR_DIMMS 2 |
| 38 | |
| 39 | #define I10NM_NUM_HBM_IMC 16 |
| 40 | #define I10NM_NUM_HBM_CHANNELS 2 |
| 41 | #define I10NM_NUM_HBM_DIMMS 1 |
| 42 | |
| 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) |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 46 | |
| 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) |
| 51 | |
| 52 | #define IS_DIMM_PRESENT(r) GET_BITFIELD(r, 15, 15) |
| 53 | #define IS_NVDIMM_PRESENT(r, i) GET_BITFIELD(r, i, i) |
| 54 | |
| 55 | /* |
| 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. |
| 59 | */ |
| 60 | struct skx_dev { |
| 61 | struct list_head list; |
| 62 | u8 bus[4]; |
| 63 | int seg; |
| 64 | struct pci_dev *sad_all; |
| 65 | struct pci_dev *util_all; |
| 66 | struct pci_dev *uracu; /* for i10nm CPU */ |
Qiuxu Zhuo | c945088 | 2021-06-11 10:01:20 -0700 | [diff] [blame] | 67 | struct pci_dev *pcu_cr3; /* for HBM memory detection */ |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 68 | u32 mcroute; |
| 69 | struct skx_imc { |
| 70 | struct mem_ctl_info *mci; |
| 71 | struct pci_dev *mdev; /* for i10nm CPU */ |
| 72 | void __iomem *mbase; /* for i10nm CPU */ |
Qiuxu Zhuo | 479f58d | 2020-11-17 20:49:53 +0800 | [diff] [blame] | 73 | int chan_mmio_sz; /* for i10nm CPU */ |
Qiuxu Zhuo | c945088 | 2021-06-11 10:01:20 -0700 | [diff] [blame] | 74 | int num_channels; /* channels per memory controller */ |
| 75 | int num_dimms; /* dimms per channel */ |
| 76 | bool hbm_mc; |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 77 | u8 mc; /* system wide mc# */ |
| 78 | u8 lmc; /* socket relative mc# */ |
| 79 | u8 src_id, node_id; |
| 80 | struct skx_channel { |
| 81 | struct pci_dev *cdev; |
Tony Luck | e80634a | 2019-08-15 14:53:28 -0700 | [diff] [blame] | 82 | struct pci_dev *edev; |
Youquan Song | cf4e6d5 | 2021-08-18 10:57:01 -0700 | [diff] [blame] | 83 | u32 retry_rd_err_log_s; |
| 84 | u32 retry_rd_err_log_d; |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 85 | struct skx_dimm { |
| 86 | u8 close_pg; |
| 87 | u8 bank_xor_enable; |
| 88 | u8 fine_grain_bank; |
| 89 | u8 rowbits; |
| 90 | u8 colbits; |
| 91 | } dimms[NUM_DIMMS]; |
| 92 | } chan[NUM_CHANNELS]; |
| 93 | } imc[NUM_IMC]; |
| 94 | }; |
| 95 | |
| 96 | struct skx_pvt { |
| 97 | struct skx_imc *imc; |
| 98 | }; |
| 99 | |
| 100 | enum type { |
| 101 | SKX, |
Qiuxu Zhuo | 479f58d | 2020-11-17 20:49:53 +0800 | [diff] [blame] | 102 | I10NM, |
| 103 | SPR |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | enum { |
| 107 | INDEX_SOCKET, |
| 108 | INDEX_MEMCTRL, |
| 109 | INDEX_CHANNEL, |
| 110 | INDEX_DIMM, |
Qiuxu Zhuo | 2f4348e | 2021-06-11 10:01:18 -0700 | [diff] [blame] | 111 | INDEX_NM_FIRST, |
| 112 | INDEX_NM_MEMCTRL = INDEX_NM_FIRST, |
| 113 | INDEX_NM_CHANNEL, |
| 114 | INDEX_NM_DIMM, |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 115 | INDEX_MAX |
| 116 | }; |
| 117 | |
Qiuxu Zhuo | 2f4348e | 2021-06-11 10:01:18 -0700 | [diff] [blame] | 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) |
| 121 | |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 122 | struct decoded_addr { |
| 123 | struct skx_dev *dev; |
| 124 | u64 addr; |
| 125 | int socket; |
| 126 | int imc; |
| 127 | int channel; |
| 128 | u64 chan_addr; |
| 129 | int sktways; |
| 130 | int chanways; |
| 131 | int dimm; |
| 132 | int rank; |
| 133 | int channel_rank; |
| 134 | u64 rank_address; |
| 135 | int row; |
| 136 | int column; |
| 137 | int bank_address; |
| 138 | int bank_group; |
| 139 | }; |
| 140 | |
Qiuxu Zhuo | ee5340a | 2020-04-24 20:18:14 +0800 | [diff] [blame] | 141 | struct res_config { |
| 142 | enum type type; |
| 143 | /* Configuration agent device ID */ |
| 144 | unsigned int decs_did; |
| 145 | /* Default bus number configuration register offset */ |
| 146 | int busno_cfg_offset; |
Qiuxu Zhuo | 479f58d | 2020-11-17 20:49:53 +0800 | [diff] [blame] | 147 | /* Per DDR channel memory-mapped I/O size */ |
| 148 | int ddr_chan_mmio_sz; |
Qiuxu Zhuo | c945088 | 2021-06-11 10:01:20 -0700 | [diff] [blame] | 149 | /* Per HBM channel memory-mapped I/O size */ |
| 150 | int hbm_chan_mmio_sz; |
Qiuxu Zhuo | 479f58d | 2020-11-17 20:49:53 +0800 | [diff] [blame] | 151 | bool support_ddr5; |
Qiuxu Zhuo | 4bd4d32 | 2021-06-11 10:01:19 -0700 | [diff] [blame] | 152 | /* SAD device number and function number */ |
| 153 | unsigned int sad_all_devfn; |
| 154 | int sad_all_offset; |
Youquan Song | cf4e6d5 | 2021-08-18 10:57:01 -0700 | [diff] [blame] | 155 | /* Offsets of retry_rd_err_log registers */ |
| 156 | u32 *offsets_scrub; |
| 157 | u32 *offsets_demand; |
Qiuxu Zhuo | ee5340a | 2020-04-24 20:18:14 +0800 | [diff] [blame] | 158 | }; |
| 159 | |
Qiuxu Zhuo | 479f58d | 2020-11-17 20:49:53 +0800 | [diff] [blame] | 160 | typedef int (*get_dimm_config_f)(struct mem_ctl_info *mci, |
| 161 | struct res_config *cfg); |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 162 | typedef bool (*skx_decode_f)(struct decoded_addr *res); |
Youquan Song | cf4e6d5 | 2021-08-18 10:57:01 -0700 | [diff] [blame] | 163 | typedef void (*skx_show_retry_log_f)(struct decoded_addr *res, char *msg, int len, bool scrub_err); |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 164 | |
| 165 | int __init skx_adxl_get(void); |
| 166 | void __exit skx_adxl_put(void); |
Tony Luck | e80634a | 2019-08-15 14:53:28 -0700 | [diff] [blame] | 167 | void skx_set_decode(skx_decode_f decode, skx_show_retry_log_f show_retry_log); |
Qiuxu Zhuo | 2f4348e | 2021-06-11 10:01:18 -0700 | [diff] [blame] | 168 | void skx_set_mem_cfg(bool mem_cfg_2lm); |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 169 | |
Qiuxu Zhuo | 1dc78f1 | 2019-06-26 14:16:55 +0800 | [diff] [blame] | 170 | int skx_get_src_id(struct skx_dev *d, int off, u8 *id); |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 171 | int skx_get_node_id(struct skx_dev *d, u8 *id); |
| 172 | |
Qiuxu Zhuo | ee5340a | 2020-04-24 20:18:14 +0800 | [diff] [blame] | 173 | int skx_get_all_bus_mappings(struct res_config *cfg, struct list_head **list); |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 174 | |
| 175 | int skx_get_hi_lo(unsigned int did, int off[], u64 *tolm, u64 *tohm); |
| 176 | |
Qiuxu Zhuo | 1032095 | 2020-05-15 20:34:06 +0800 | [diff] [blame] | 177 | int skx_get_dimm_info(u32 mtr, u32 mcmtr, u32 amap, struct dimm_info *dimm, |
Qiuxu Zhuo | 479f58d | 2020-11-17 20:49:53 +0800 | [diff] [blame] | 178 | struct skx_imc *imc, int chan, int dimmno, |
| 179 | struct res_config *cfg); |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 180 | |
| 181 | int skx_get_nvdimm_info(struct dimm_info *dimm, struct skx_imc *imc, |
| 182 | int chan, int dimmno, const char *mod_str); |
| 183 | |
| 184 | int skx_register_mci(struct skx_imc *imc, struct pci_dev *pdev, |
| 185 | const char *ctl_name, const char *mod_str, |
Qiuxu Zhuo | 479f58d | 2020-11-17 20:49:53 +0800 | [diff] [blame] | 186 | get_dimm_config_f get_dimm_config, |
| 187 | struct res_config *cfg); |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 188 | |
| 189 | int skx_mce_check_error(struct notifier_block *nb, unsigned long val, |
| 190 | void *data); |
| 191 | |
| 192 | void skx_remove(void); |
| 193 | |
Qiuxu Zhuo | 88a242c | 2019-01-30 11:15:17 -0800 | [diff] [blame] | 194 | #endif /* _SKX_COMM_EDAC_H */ |