blob: 03ac067a80b9f779fe2ef726672f222ba4403be7 [file] [log] [blame]
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -08001/* 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 Zhuo2f4348e2021-06-11 10:01:18 -070012#include <linux/bits.h>
13
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -080014#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 Zhuoc9450882021-06-11 10:01:20 -070035#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 Zhuo88a242c2019-01-30 11:15:17 -080046
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 */
60struct 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 Zhuoc9450882021-06-11 10:01:20 -070067 struct pci_dev *pcu_cr3; /* for HBM memory detection */
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -080068 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 Zhuo479f58d2020-11-17 20:49:53 +080073 int chan_mmio_sz; /* for i10nm CPU */
Qiuxu Zhuoc9450882021-06-11 10:01:20 -070074 int num_channels; /* channels per memory controller */
75 int num_dimms; /* dimms per channel */
76 bool hbm_mc;
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -080077 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 Lucke80634a2019-08-15 14:53:28 -070082 struct pci_dev *edev;
Youquan Songcf4e6d52021-08-18 10:57:01 -070083 u32 retry_rd_err_log_s;
84 u32 retry_rd_err_log_d;
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -080085 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
96struct skx_pvt {
97 struct skx_imc *imc;
98};
99
100enum type {
101 SKX,
Qiuxu Zhuo479f58d2020-11-17 20:49:53 +0800102 I10NM,
103 SPR
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800104};
105
106enum {
107 INDEX_SOCKET,
108 INDEX_MEMCTRL,
109 INDEX_CHANNEL,
110 INDEX_DIMM,
Qiuxu Zhuo2f4348e2021-06-11 10:01:18 -0700111 INDEX_NM_FIRST,
112 INDEX_NM_MEMCTRL = INDEX_NM_FIRST,
113 INDEX_NM_CHANNEL,
114 INDEX_NM_DIMM,
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800115 INDEX_MAX
116};
117
Qiuxu Zhuo2f4348e2021-06-11 10:01:18 -0700118#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 Zhuo88a242c2019-01-30 11:15:17 -0800122struct 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 Zhuoee5340a2020-04-24 20:18:14 +0800141struct 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 Zhuo479f58d2020-11-17 20:49:53 +0800147 /* Per DDR channel memory-mapped I/O size */
148 int ddr_chan_mmio_sz;
Qiuxu Zhuoc9450882021-06-11 10:01:20 -0700149 /* Per HBM channel memory-mapped I/O size */
150 int hbm_chan_mmio_sz;
Qiuxu Zhuo479f58d2020-11-17 20:49:53 +0800151 bool support_ddr5;
Qiuxu Zhuo4bd4d322021-06-11 10:01:19 -0700152 /* SAD device number and function number */
153 unsigned int sad_all_devfn;
154 int sad_all_offset;
Youquan Songcf4e6d52021-08-18 10:57:01 -0700155 /* Offsets of retry_rd_err_log registers */
156 u32 *offsets_scrub;
157 u32 *offsets_demand;
Qiuxu Zhuoee5340a2020-04-24 20:18:14 +0800158};
159
Qiuxu Zhuo479f58d2020-11-17 20:49:53 +0800160typedef int (*get_dimm_config_f)(struct mem_ctl_info *mci,
161 struct res_config *cfg);
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800162typedef bool (*skx_decode_f)(struct decoded_addr *res);
Youquan Songcf4e6d52021-08-18 10:57:01 -0700163typedef void (*skx_show_retry_log_f)(struct decoded_addr *res, char *msg, int len, bool scrub_err);
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800164
165int __init skx_adxl_get(void);
166void __exit skx_adxl_put(void);
Tony Lucke80634a2019-08-15 14:53:28 -0700167void skx_set_decode(skx_decode_f decode, skx_show_retry_log_f show_retry_log);
Qiuxu Zhuo2f4348e2021-06-11 10:01:18 -0700168void skx_set_mem_cfg(bool mem_cfg_2lm);
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800169
Qiuxu Zhuo1dc78f12019-06-26 14:16:55 +0800170int skx_get_src_id(struct skx_dev *d, int off, u8 *id);
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800171int skx_get_node_id(struct skx_dev *d, u8 *id);
172
Qiuxu Zhuoee5340a2020-04-24 20:18:14 +0800173int skx_get_all_bus_mappings(struct res_config *cfg, struct list_head **list);
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800174
175int skx_get_hi_lo(unsigned int did, int off[], u64 *tolm, u64 *tohm);
176
Qiuxu Zhuo10320952020-05-15 20:34:06 +0800177int skx_get_dimm_info(u32 mtr, u32 mcmtr, u32 amap, struct dimm_info *dimm,
Qiuxu Zhuo479f58d2020-11-17 20:49:53 +0800178 struct skx_imc *imc, int chan, int dimmno,
179 struct res_config *cfg);
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800180
181int skx_get_nvdimm_info(struct dimm_info *dimm, struct skx_imc *imc,
182 int chan, int dimmno, const char *mod_str);
183
184int skx_register_mci(struct skx_imc *imc, struct pci_dev *pdev,
185 const char *ctl_name, const char *mod_str,
Qiuxu Zhuo479f58d2020-11-17 20:49:53 +0800186 get_dimm_config_f get_dimm_config,
187 struct res_config *cfg);
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800188
189int skx_mce_check_error(struct notifier_block *nb, unsigned long val,
190 void *data);
191
192void skx_remove(void);
193
Qiuxu Zhuo88a242c2019-01-30 11:15:17 -0800194#endif /* _SKX_COMM_EDAC_H */