Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 2 | #include "amd64_edac.h" |
Andreas Herrmann | 23ac4ae | 2010-09-17 18:03:43 +0200 | [diff] [blame] | 3 | #include <asm/amd_nb.h> |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 4 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 5 | static struct edac_pci_ctl_info *pci_ctl; |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 6 | |
| 7 | static int report_gart_errors; |
| 8 | module_param(report_gart_errors, int, 0644); |
| 9 | |
| 10 | /* |
| 11 | * Set by command line parameter. If BIOS has enabled the ECC, this override is |
| 12 | * cleared to prevent re-enabling the hardware by this driver. |
| 13 | */ |
| 14 | static int ecc_enable_override; |
| 15 | module_param(ecc_enable_override, int, 0644); |
| 16 | |
Tejun Heo | a29d8b8 | 2010-02-02 14:39:15 +0900 | [diff] [blame] | 17 | static struct msr __percpu *msrs; |
Borislav Petkov | 5054225 | 2009-12-11 18:14:40 +0100 | [diff] [blame] | 18 | |
Yazen Ghannam | 38ddd4d | 2019-10-22 20:35:09 +0000 | [diff] [blame] | 19 | static struct amd64_family_type *fam_type; |
| 20 | |
Borislav Petkov | 2ec591a | 2015-02-17 10:58:34 +0100 | [diff] [blame] | 21 | /* Per-node stuff */ |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 22 | static struct ecc_settings **ecc_stngs; |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 23 | |
| 24 | /* |
Borislav Petkov | b70ef01 | 2009-06-25 19:32:38 +0200 | [diff] [blame] | 25 | * Valid scrub rates for the K8 hardware memory scrubber. We map the scrubbing |
| 26 | * bandwidth to a valid bit pattern. The 'set' operation finds the 'matching- |
| 27 | * or higher value'. |
| 28 | * |
| 29 | *FIXME: Produce a better mapping/linearisation. |
| 30 | */ |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 31 | static const struct scrubrate { |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 32 | u32 scrubval; /* bit pattern for scrub rate */ |
| 33 | u32 bandwidth; /* bandwidth consumed (bytes/sec) */ |
| 34 | } scrubrates[] = { |
Borislav Petkov | b70ef01 | 2009-06-25 19:32:38 +0200 | [diff] [blame] | 35 | { 0x01, 1600000000UL}, |
| 36 | { 0x02, 800000000UL}, |
| 37 | { 0x03, 400000000UL}, |
| 38 | { 0x04, 200000000UL}, |
| 39 | { 0x05, 100000000UL}, |
| 40 | { 0x06, 50000000UL}, |
| 41 | { 0x07, 25000000UL}, |
| 42 | { 0x08, 12284069UL}, |
| 43 | { 0x09, 6274509UL}, |
| 44 | { 0x0A, 3121951UL}, |
| 45 | { 0x0B, 1560975UL}, |
| 46 | { 0x0C, 781440UL}, |
| 47 | { 0x0D, 390720UL}, |
| 48 | { 0x0E, 195300UL}, |
| 49 | { 0x0F, 97650UL}, |
| 50 | { 0x10, 48854UL}, |
| 51 | { 0x11, 24427UL}, |
| 52 | { 0x12, 12213UL}, |
| 53 | { 0x13, 6101UL}, |
| 54 | { 0x14, 3051UL}, |
| 55 | { 0x15, 1523UL}, |
| 56 | { 0x16, 761UL}, |
| 57 | { 0x00, 0UL}, /* scrubbing off */ |
| 58 | }; |
| 59 | |
Borislav Petkov | 66fed2d | 2012-08-09 18:41:07 +0200 | [diff] [blame] | 60 | int __amd64_read_pci_cfg_dword(struct pci_dev *pdev, int offset, |
| 61 | u32 *val, const char *func) |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 62 | { |
| 63 | int err = 0; |
| 64 | |
| 65 | err = pci_read_config_dword(pdev, offset, val); |
| 66 | if (err) |
| 67 | amd64_warn("%s: error reading F%dx%03x.\n", |
| 68 | func, PCI_FUNC(pdev->devfn), offset); |
| 69 | |
| 70 | return err; |
| 71 | } |
| 72 | |
| 73 | int __amd64_write_pci_cfg_dword(struct pci_dev *pdev, int offset, |
| 74 | u32 val, const char *func) |
| 75 | { |
| 76 | int err = 0; |
| 77 | |
| 78 | err = pci_write_config_dword(pdev, offset, val); |
| 79 | if (err) |
| 80 | amd64_warn("%s: error writing to F%dx%03x.\n", |
| 81 | func, PCI_FUNC(pdev->devfn), offset); |
| 82 | |
| 83 | return err; |
| 84 | } |
| 85 | |
| 86 | /* |
Borislav Petkov | 73ba859 | 2011-09-19 17:34:45 +0200 | [diff] [blame] | 87 | * Select DCT to which PCI cfg accesses are routed |
| 88 | */ |
| 89 | static void f15h_select_dct(struct amd64_pvt *pvt, u8 dct) |
| 90 | { |
| 91 | u32 reg = 0; |
| 92 | |
| 93 | amd64_read_pci_cfg(pvt->F1, DCT_CFG_SEL, ®); |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 94 | reg &= (pvt->model == 0x30) ? ~3 : ~1; |
Borislav Petkov | 73ba859 | 2011-09-19 17:34:45 +0200 | [diff] [blame] | 95 | reg |= dct; |
| 96 | amd64_write_pci_cfg(pvt->F1, DCT_CFG_SEL, reg); |
| 97 | } |
| 98 | |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 99 | /* |
| 100 | * |
| 101 | * Depending on the family, F2 DCT reads need special handling: |
| 102 | * |
| 103 | * K8: has a single DCT only and no address offsets >= 0x100 |
| 104 | * |
| 105 | * F10h: each DCT has its own set of regs |
| 106 | * DCT0 -> F2x040.. |
| 107 | * DCT1 -> F2x140.. |
| 108 | * |
| 109 | * F16h: has only 1 DCT |
| 110 | * |
| 111 | * F15h: we select which DCT we access using F1x10C[DctCfgSel] |
| 112 | */ |
| 113 | static inline int amd64_read_dct_pci_cfg(struct amd64_pvt *pvt, u8 dct, |
| 114 | int offset, u32 *val) |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 115 | { |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 116 | switch (pvt->fam) { |
| 117 | case 0xf: |
| 118 | if (dct || offset >= 0x100) |
| 119 | return -EINVAL; |
| 120 | break; |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 121 | |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 122 | case 0x10: |
| 123 | if (dct) { |
| 124 | /* |
| 125 | * Note: If ganging is enabled, barring the regs |
| 126 | * F2x[1,0]98 and F2x[1,0]9C; reads reads to F2x1xx |
| 127 | * return 0. (cf. Section 2.8.1 F10h BKDG) |
| 128 | */ |
| 129 | if (dct_ganging_enabled(pvt)) |
| 130 | return 0; |
| 131 | |
| 132 | offset += 0x100; |
| 133 | } |
| 134 | break; |
| 135 | |
| 136 | case 0x15: |
| 137 | /* |
| 138 | * F15h: F2x1xx addresses do not map explicitly to DCT1. |
| 139 | * We should select which DCT we access using F1x10C[DctCfgSel] |
| 140 | */ |
| 141 | dct = (dct && pvt->model == 0x30) ? 3 : dct; |
| 142 | f15h_select_dct(pvt, dct); |
| 143 | break; |
| 144 | |
| 145 | case 0x16: |
| 146 | if (dct) |
| 147 | return -EINVAL; |
| 148 | break; |
| 149 | |
| 150 | default: |
| 151 | break; |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 152 | } |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 153 | return amd64_read_pci_cfg(pvt->F2, offset, val); |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Borislav Petkov | b70ef01 | 2009-06-25 19:32:38 +0200 | [diff] [blame] | 156 | /* |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 157 | * Memory scrubber control interface. For K8, memory scrubbing is handled by |
| 158 | * hardware and can involve L2 cache, dcache as well as the main memory. With |
| 159 | * F10, this is extended to L3 cache scrubbing on CPU models sporting that |
| 160 | * functionality. |
| 161 | * |
| 162 | * This causes the "units" for the scrubbing speed to vary from 64 byte blocks |
| 163 | * (dram) over to cache lines. This is nasty, so we will use bandwidth in |
| 164 | * bytes/sec for the setting. |
| 165 | * |
| 166 | * Currently, we only do dram scrubbing. If the scrubbing is done in software on |
| 167 | * other archs, we might not have access to the caches directly. |
| 168 | */ |
| 169 | |
Yazen Ghannam | 8051c0a | 2016-11-17 17:57:42 -0500 | [diff] [blame] | 170 | static inline void __f17h_set_scrubval(struct amd64_pvt *pvt, u32 scrubval) |
| 171 | { |
| 172 | /* |
| 173 | * Fam17h supports scrub values between 0x5 and 0x14. Also, the values |
| 174 | * are shifted down by 0x5, so scrubval 0x5 is written to the register |
| 175 | * as 0x0, scrubval 0x6 as 0x1, etc. |
| 176 | */ |
| 177 | if (scrubval >= 0x5 && scrubval <= 0x14) { |
| 178 | scrubval -= 0x5; |
| 179 | pci_write_bits32(pvt->F6, F17H_SCR_LIMIT_ADDR, scrubval, 0xF); |
| 180 | pci_write_bits32(pvt->F6, F17H_SCR_BASE_ADDR, 1, 0x1); |
| 181 | } else { |
| 182 | pci_write_bits32(pvt->F6, F17H_SCR_BASE_ADDR, 0, 0x1); |
| 183 | } |
| 184 | } |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 185 | /* |
Yazen Ghannam | 8051c0a | 2016-11-17 17:57:42 -0500 | [diff] [blame] | 186 | * Scan the scrub rate mapping table for a close or matching bandwidth value to |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 187 | * issue. If requested is too big, then use last maximum value found. |
| 188 | */ |
Aravind Gopalakrishnan | da92110 | 2015-09-28 06:43:12 -0500 | [diff] [blame] | 189 | static int __set_scrub_rate(struct amd64_pvt *pvt, u32 new_bw, u32 min_rate) |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 190 | { |
| 191 | u32 scrubval; |
| 192 | int i; |
| 193 | |
| 194 | /* |
| 195 | * map the configured rate (new_bw) to a value specific to the AMD64 |
| 196 | * memory controller and apply to register. Search for the first |
| 197 | * bandwidth entry that is greater or equal than the setting requested |
| 198 | * and program that. If at last entry, turn off DRAM scrubbing. |
Andrew Morton | 168bfee | 2012-10-23 14:09:39 -0700 | [diff] [blame] | 199 | * |
| 200 | * If no suitable bandwidth is found, turn off DRAM scrubbing entirely |
| 201 | * by falling back to the last element in scrubrates[]. |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 202 | */ |
Andrew Morton | 168bfee | 2012-10-23 14:09:39 -0700 | [diff] [blame] | 203 | for (i = 0; i < ARRAY_SIZE(scrubrates) - 1; i++) { |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 204 | /* |
| 205 | * skip scrub rates which aren't recommended |
| 206 | * (see F10 BKDG, F3x58) |
| 207 | */ |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 208 | if (scrubrates[i].scrubval < min_rate) |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 209 | continue; |
| 210 | |
| 211 | if (scrubrates[i].bandwidth <= new_bw) |
| 212 | break; |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | scrubval = scrubrates[i].scrubval; |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 216 | |
Pu Wen | c4a3e94 | 2018-09-27 16:31:28 +0200 | [diff] [blame] | 217 | if (pvt->fam == 0x17 || pvt->fam == 0x18) { |
Yazen Ghannam | 8051c0a | 2016-11-17 17:57:42 -0500 | [diff] [blame] | 218 | __f17h_set_scrubval(pvt, scrubval); |
| 219 | } else if (pvt->fam == 0x15 && pvt->model == 0x60) { |
Aravind Gopalakrishnan | da92110 | 2015-09-28 06:43:12 -0500 | [diff] [blame] | 220 | f15h_select_dct(pvt, 0); |
| 221 | pci_write_bits32(pvt->F2, F15H_M60H_SCRCTRL, scrubval, 0x001F); |
| 222 | f15h_select_dct(pvt, 1); |
| 223 | pci_write_bits32(pvt->F2, F15H_M60H_SCRCTRL, scrubval, 0x001F); |
| 224 | } else { |
| 225 | pci_write_bits32(pvt->F3, SCRCTRL, scrubval, 0x001F); |
| 226 | } |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 227 | |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 228 | if (scrubval) |
| 229 | return scrubrates[i].bandwidth; |
| 230 | |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 231 | return 0; |
| 232 | } |
| 233 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 234 | static int set_scrub_rate(struct mem_ctl_info *mci, u32 bw) |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 235 | { |
| 236 | struct amd64_pvt *pvt = mci->pvt_info; |
Borislav Petkov | 87b3e0e | 2011-01-19 20:02:38 +0100 | [diff] [blame] | 237 | u32 min_scrubrate = 0x5; |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 238 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 239 | if (pvt->fam == 0xf) |
Borislav Petkov | 87b3e0e | 2011-01-19 20:02:38 +0100 | [diff] [blame] | 240 | min_scrubrate = 0x0; |
| 241 | |
Aravind Gopalakrishnan | da92110 | 2015-09-28 06:43:12 -0500 | [diff] [blame] | 242 | if (pvt->fam == 0x15) { |
| 243 | /* Erratum #505 */ |
| 244 | if (pvt->model < 0x10) |
| 245 | f15h_select_dct(pvt, 0); |
Borislav Petkov | 73ba859 | 2011-09-19 17:34:45 +0200 | [diff] [blame] | 246 | |
Aravind Gopalakrishnan | da92110 | 2015-09-28 06:43:12 -0500 | [diff] [blame] | 247 | if (pvt->model == 0x60) |
| 248 | min_scrubrate = 0x6; |
| 249 | } |
| 250 | return __set_scrub_rate(pvt, bw, min_scrubrate); |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 251 | } |
| 252 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 253 | static int get_scrub_rate(struct mem_ctl_info *mci) |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 254 | { |
| 255 | struct amd64_pvt *pvt = mci->pvt_info; |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 256 | int i, retval = -EINVAL; |
Yazen Ghannam | 8051c0a | 2016-11-17 17:57:42 -0500 | [diff] [blame] | 257 | u32 scrubval = 0; |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 258 | |
Yazen Ghannam | 8051c0a | 2016-11-17 17:57:42 -0500 | [diff] [blame] | 259 | switch (pvt->fam) { |
| 260 | case 0x15: |
Aravind Gopalakrishnan | da92110 | 2015-09-28 06:43:12 -0500 | [diff] [blame] | 261 | /* Erratum #505 */ |
| 262 | if (pvt->model < 0x10) |
| 263 | f15h_select_dct(pvt, 0); |
Borislav Petkov | 73ba859 | 2011-09-19 17:34:45 +0200 | [diff] [blame] | 264 | |
Aravind Gopalakrishnan | da92110 | 2015-09-28 06:43:12 -0500 | [diff] [blame] | 265 | if (pvt->model == 0x60) |
| 266 | amd64_read_pci_cfg(pvt->F2, F15H_M60H_SCRCTRL, &scrubval); |
Yazen Ghannam | 8051c0a | 2016-11-17 17:57:42 -0500 | [diff] [blame] | 267 | break; |
| 268 | |
| 269 | case 0x17: |
Pu Wen | c4a3e94 | 2018-09-27 16:31:28 +0200 | [diff] [blame] | 270 | case 0x18: |
Yazen Ghannam | 8051c0a | 2016-11-17 17:57:42 -0500 | [diff] [blame] | 271 | amd64_read_pci_cfg(pvt->F6, F17H_SCR_BASE_ADDR, &scrubval); |
| 272 | if (scrubval & BIT(0)) { |
| 273 | amd64_read_pci_cfg(pvt->F6, F17H_SCR_LIMIT_ADDR, &scrubval); |
| 274 | scrubval &= 0xF; |
| 275 | scrubval += 0x5; |
| 276 | } else { |
| 277 | scrubval = 0; |
| 278 | } |
| 279 | break; |
| 280 | |
| 281 | default: |
Aravind Gopalakrishnan | da92110 | 2015-09-28 06:43:12 -0500 | [diff] [blame] | 282 | amd64_read_pci_cfg(pvt->F3, SCRCTRL, &scrubval); |
Yazen Ghannam | 8051c0a | 2016-11-17 17:57:42 -0500 | [diff] [blame] | 283 | break; |
| 284 | } |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 285 | |
| 286 | scrubval = scrubval & 0x001F; |
| 287 | |
Roel Kluin | 926311f | 2010-01-11 20:58:21 +0100 | [diff] [blame] | 288 | for (i = 0; i < ARRAY_SIZE(scrubrates); i++) { |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 289 | if (scrubrates[i].scrubval == scrubval) { |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 290 | retval = scrubrates[i].bandwidth; |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 291 | break; |
| 292 | } |
| 293 | } |
Borislav Petkov | 3909444 | 2010-11-24 19:52:09 +0100 | [diff] [blame] | 294 | return retval; |
Doug Thompson | 2bc6541 | 2009-05-04 20:11:14 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 297 | /* |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 298 | * returns true if the SysAddr given by sys_addr matches the |
| 299 | * DRAM base/limit associated with node_id |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 300 | */ |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 301 | static bool base_limit_match(struct amd64_pvt *pvt, u64 sys_addr, u8 nid) |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 302 | { |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 303 | u64 addr; |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 304 | |
| 305 | /* The K8 treats this as a 40-bit value. However, bits 63-40 will be |
| 306 | * all ones if the most significant implemented address bit is 1. |
| 307 | * Here we discard bits 63-40. See section 3.4.2 of AMD publication |
| 308 | * 24592: AMD x86-64 Architecture Programmer's Manual Volume 1 |
| 309 | * Application Programming. |
| 310 | */ |
| 311 | addr = sys_addr & 0x000000ffffffffffull; |
| 312 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 313 | return ((addr >= get_dram_base(pvt, nid)) && |
| 314 | (addr <= get_dram_limit(pvt, nid))); |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /* |
| 318 | * Attempt to map a SysAddr to a node. On success, return a pointer to the |
| 319 | * mem_ctl_info structure for the node that the SysAddr maps to. |
| 320 | * |
| 321 | * On failure, return NULL. |
| 322 | */ |
| 323 | static struct mem_ctl_info *find_mc_by_sys_addr(struct mem_ctl_info *mci, |
| 324 | u64 sys_addr) |
| 325 | { |
| 326 | struct amd64_pvt *pvt; |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 327 | u8 node_id; |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 328 | u32 intlv_en, bits; |
| 329 | |
| 330 | /* |
| 331 | * Here we use the DRAM Base (section 3.4.4.1) and DRAM Limit (section |
| 332 | * 3.4.4.2) registers to map the SysAddr to a node ID. |
| 333 | */ |
| 334 | pvt = mci->pvt_info; |
| 335 | |
| 336 | /* |
| 337 | * The value of this field should be the same for all DRAM Base |
| 338 | * registers. Therefore we arbitrarily choose to read it from the |
| 339 | * register for node 0. |
| 340 | */ |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 341 | intlv_en = dram_intlv_en(pvt, 0); |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 342 | |
| 343 | if (intlv_en == 0) { |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 344 | for (node_id = 0; node_id < DRAM_RANGES; node_id++) { |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 345 | if (base_limit_match(pvt, sys_addr, node_id)) |
Borislav Petkov | 8edc544 | 2009-09-18 12:39:19 +0200 | [diff] [blame] | 346 | goto found; |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 347 | } |
Borislav Petkov | 8edc544 | 2009-09-18 12:39:19 +0200 | [diff] [blame] | 348 | goto err_no_match; |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 349 | } |
| 350 | |
Borislav Petkov | 72f158f | 2009-09-18 12:27:27 +0200 | [diff] [blame] | 351 | if (unlikely((intlv_en != 0x01) && |
| 352 | (intlv_en != 0x03) && |
| 353 | (intlv_en != 0x07))) { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 354 | amd64_warn("DRAM Base[IntlvEn] junk value: 0x%x, BIOS bug?\n", intlv_en); |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | bits = (((u32) sys_addr) >> 12) & intlv_en; |
| 359 | |
| 360 | for (node_id = 0; ; ) { |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 361 | if ((dram_intlv_sel(pvt, node_id) & intlv_en) == bits) |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 362 | break; /* intlv_sel field matches */ |
| 363 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 364 | if (++node_id >= DRAM_RANGES) |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 365 | goto err_no_match; |
| 366 | } |
| 367 | |
| 368 | /* sanity test for sys_addr */ |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 369 | if (unlikely(!base_limit_match(pvt, sys_addr, node_id))) { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 370 | amd64_warn("%s: sys_addr 0x%llx falls outside base/limit address" |
| 371 | "range for node %d with node interleaving enabled.\n", |
| 372 | __func__, sys_addr, node_id); |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 373 | return NULL; |
| 374 | } |
| 375 | |
| 376 | found: |
Borislav Petkov | b487c33 | 2011-02-21 18:55:00 +0100 | [diff] [blame] | 377 | return edac_mc_find((int)node_id); |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 378 | |
| 379 | err_no_match: |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 380 | edac_dbg(2, "sys_addr 0x%lx doesn't match any node\n", |
| 381 | (unsigned long)sys_addr); |
Doug Thompson | 6775763 | 2009-04-27 15:53:22 +0200 | [diff] [blame] | 382 | |
| 383 | return NULL; |
| 384 | } |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 385 | |
| 386 | /* |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 387 | * compute the CS base address of the @csrow on the DRAM controller @dct. |
| 388 | * For details see F2x[5C:40] in the processor's BKDG |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 389 | */ |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 390 | static void get_cs_base_and_mask(struct amd64_pvt *pvt, int csrow, u8 dct, |
| 391 | u64 *base, u64 *mask) |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 392 | { |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 393 | u64 csbase, csmask, base_bits, mask_bits; |
| 394 | u8 addr_shift; |
| 395 | |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 396 | if (pvt->fam == 0xf && pvt->ext_model < K8_REV_F) { |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 397 | csbase = pvt->csels[dct].csbases[csrow]; |
| 398 | csmask = pvt->csels[dct].csmasks[csrow]; |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 399 | base_bits = GENMASK_ULL(31, 21) | GENMASK_ULL(15, 9); |
| 400 | mask_bits = GENMASK_ULL(29, 21) | GENMASK_ULL(15, 9); |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 401 | addr_shift = 4; |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 402 | |
| 403 | /* |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 404 | * F16h and F15h, models 30h and later need two addr_shift values: |
| 405 | * 8 for high and 6 for low (cf. F16h BKDG). |
| 406 | */ |
| 407 | } else if (pvt->fam == 0x16 || |
| 408 | (pvt->fam == 0x15 && pvt->model >= 0x30)) { |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 409 | csbase = pvt->csels[dct].csbases[csrow]; |
| 410 | csmask = pvt->csels[dct].csmasks[csrow >> 1]; |
| 411 | |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 412 | *base = (csbase & GENMASK_ULL(15, 5)) << 6; |
| 413 | *base |= (csbase & GENMASK_ULL(30, 19)) << 8; |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 414 | |
| 415 | *mask = ~0ULL; |
| 416 | /* poke holes for the csmask */ |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 417 | *mask &= ~((GENMASK_ULL(15, 5) << 6) | |
| 418 | (GENMASK_ULL(30, 19) << 8)); |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 419 | |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 420 | *mask |= (csmask & GENMASK_ULL(15, 5)) << 6; |
| 421 | *mask |= (csmask & GENMASK_ULL(30, 19)) << 8; |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 422 | |
| 423 | return; |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 424 | } else { |
| 425 | csbase = pvt->csels[dct].csbases[csrow]; |
| 426 | csmask = pvt->csels[dct].csmasks[csrow >> 1]; |
| 427 | addr_shift = 8; |
| 428 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 429 | if (pvt->fam == 0x15) |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 430 | base_bits = mask_bits = |
| 431 | GENMASK_ULL(30,19) | GENMASK_ULL(13,5); |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 432 | else |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 433 | base_bits = mask_bits = |
| 434 | GENMASK_ULL(28,19) | GENMASK_ULL(13,5); |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | *base = (csbase & base_bits) << addr_shift; |
| 438 | |
| 439 | *mask = ~0ULL; |
| 440 | /* poke holes for the csmask */ |
| 441 | *mask &= ~(mask_bits << addr_shift); |
| 442 | /* OR them in */ |
| 443 | *mask |= (csmask & mask_bits) << addr_shift; |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 446 | #define for_each_chip_select(i, dct, pvt) \ |
| 447 | for (i = 0; i < pvt->csels[dct].b_cnt; i++) |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 448 | |
Borislav Petkov | 614ec9d | 2011-01-13 18:02:22 +0100 | [diff] [blame] | 449 | #define chip_select_base(i, dct, pvt) \ |
| 450 | pvt->csels[dct].csbases[i] |
| 451 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 452 | #define for_each_chip_select_mask(i, dct, pvt) \ |
| 453 | for (i = 0; i < pvt->csels[dct].m_cnt; i++) |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 454 | |
Yazen Ghannam | 4d30d2b | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 455 | #define for_each_umc(i) \ |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 456 | for (i = 0; i < fam_type->max_mcs; i++) |
Yazen Ghannam | 4d30d2b | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 457 | |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 458 | /* |
| 459 | * @input_addr is an InputAddr associated with the node given by mci. Return the |
| 460 | * csrow that input_addr maps to, or -1 on failure (no csrow claims input_addr). |
| 461 | */ |
| 462 | static int input_addr_to_csrow(struct mem_ctl_info *mci, u64 input_addr) |
| 463 | { |
| 464 | struct amd64_pvt *pvt; |
| 465 | int csrow; |
| 466 | u64 base, mask; |
| 467 | |
| 468 | pvt = mci->pvt_info; |
| 469 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 470 | for_each_chip_select(csrow, 0, pvt) { |
| 471 | if (!csrow_enabled(csrow, 0, pvt)) |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 472 | continue; |
| 473 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 474 | get_cs_base_and_mask(pvt, csrow, 0, &base, &mask); |
| 475 | |
| 476 | mask = ~mask; |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 477 | |
| 478 | if ((input_addr & mask) == (base & mask)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 479 | edac_dbg(2, "InputAddr 0x%lx matches csrow %d (node %d)\n", |
| 480 | (unsigned long)input_addr, csrow, |
| 481 | pvt->mc_node_id); |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 482 | |
| 483 | return csrow; |
| 484 | } |
| 485 | } |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 486 | edac_dbg(2, "no matching csrow for InputAddr 0x%lx (MC node %d)\n", |
| 487 | (unsigned long)input_addr, pvt->mc_node_id); |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 488 | |
| 489 | return -1; |
| 490 | } |
| 491 | |
| 492 | /* |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 493 | * Obtain info from the DRAM Hole Address Register (section 3.4.8, pub #26094) |
| 494 | * for the node represented by mci. Info is passed back in *hole_base, |
| 495 | * *hole_offset, and *hole_size. Function returns 0 if info is valid or 1 if |
| 496 | * info is invalid. Info may be invalid for either of the following reasons: |
| 497 | * |
| 498 | * - The revision of the node is not E or greater. In this case, the DRAM Hole |
| 499 | * Address Register does not exist. |
| 500 | * |
| 501 | * - The DramHoleValid bit is cleared in the DRAM Hole Address Register, |
| 502 | * indicating that its contents are not valid. |
| 503 | * |
| 504 | * The values passed back in *hole_base, *hole_offset, and *hole_size are |
| 505 | * complete 32-bit values despite the fact that the bitfields in the DHAR |
| 506 | * only represent bits 31-24 of the base and offset values. |
| 507 | */ |
| 508 | int amd64_get_dram_hole_info(struct mem_ctl_info *mci, u64 *hole_base, |
| 509 | u64 *hole_offset, u64 *hole_size) |
| 510 | { |
| 511 | struct amd64_pvt *pvt = mci->pvt_info; |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 512 | |
| 513 | /* only revE and later have the DRAM Hole Address Register */ |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 514 | if (pvt->fam == 0xf && pvt->ext_model < K8_REV_E) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 515 | edac_dbg(1, " revision %d for node %d does not support DHAR\n", |
| 516 | pvt->ext_model, pvt->mc_node_id); |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 517 | return 1; |
| 518 | } |
| 519 | |
Borislav Petkov | bc21fa5 | 2010-11-11 17:29:13 +0100 | [diff] [blame] | 520 | /* valid for Fam10h and above */ |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 521 | if (pvt->fam >= 0x10 && !dhar_mem_hoist_valid(pvt)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 522 | edac_dbg(1, " Dram Memory Hoisting is DISABLED on this system\n"); |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 523 | return 1; |
| 524 | } |
| 525 | |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 526 | if (!dhar_valid(pvt)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 527 | edac_dbg(1, " Dram Memory Hoisting is DISABLED on this node %d\n", |
| 528 | pvt->mc_node_id); |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 529 | return 1; |
| 530 | } |
| 531 | |
| 532 | /* This node has Memory Hoisting */ |
| 533 | |
| 534 | /* +------------------+--------------------+--------------------+----- |
| 535 | * | memory | DRAM hole | relocated | |
| 536 | * | [0, (x - 1)] | [x, 0xffffffff] | addresses from | |
| 537 | * | | | DRAM hole | |
| 538 | * | | | [0x100000000, | |
| 539 | * | | | (0x100000000+ | |
| 540 | * | | | (0xffffffff-x))] | |
| 541 | * +------------------+--------------------+--------------------+----- |
| 542 | * |
| 543 | * Above is a diagram of physical memory showing the DRAM hole and the |
| 544 | * relocated addresses from the DRAM hole. As shown, the DRAM hole |
| 545 | * starts at address x (the base address) and extends through address |
| 546 | * 0xffffffff. The DRAM Hole Address Register (DHAR) relocates the |
| 547 | * addresses in the hole so that they start at 0x100000000. |
| 548 | */ |
| 549 | |
Borislav Petkov | 1f31677 | 2012-08-10 12:50:50 +0200 | [diff] [blame] | 550 | *hole_base = dhar_base(pvt); |
| 551 | *hole_size = (1ULL << 32) - *hole_base; |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 552 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 553 | *hole_offset = (pvt->fam > 0xf) ? f10_dhar_offset(pvt) |
| 554 | : k8_dhar_offset(pvt); |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 555 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 556 | edac_dbg(1, " DHAR info for node %d base 0x%lx offset 0x%lx size 0x%lx\n", |
| 557 | pvt->mc_node_id, (unsigned long)*hole_base, |
| 558 | (unsigned long)*hole_offset, (unsigned long)*hole_size); |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 559 | |
| 560 | return 0; |
| 561 | } |
| 562 | EXPORT_SYMBOL_GPL(amd64_get_dram_hole_info); |
| 563 | |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 564 | /* |
| 565 | * Return the DramAddr that the SysAddr given by @sys_addr maps to. It is |
| 566 | * assumed that sys_addr maps to the node given by mci. |
| 567 | * |
| 568 | * The first part of section 3.4.4 (p. 70) shows how the DRAM Base (section |
| 569 | * 3.4.4.1) and DRAM Limit (section 3.4.4.2) registers are used to translate a |
| 570 | * SysAddr to a DramAddr. If the DRAM Hole Address Register (DHAR) is enabled, |
| 571 | * then it is also involved in translating a SysAddr to a DramAddr. Sections |
| 572 | * 3.4.8 and 3.5.8.2 describe the DHAR and how it is used for memory hoisting. |
| 573 | * These parts of the documentation are unclear. I interpret them as follows: |
| 574 | * |
| 575 | * When node n receives a SysAddr, it processes the SysAddr as follows: |
| 576 | * |
| 577 | * 1. It extracts the DRAMBase and DRAMLimit values from the DRAM Base and DRAM |
| 578 | * Limit registers for node n. If the SysAddr is not within the range |
| 579 | * specified by the base and limit values, then node n ignores the Sysaddr |
| 580 | * (since it does not map to node n). Otherwise continue to step 2 below. |
| 581 | * |
| 582 | * 2. If the DramHoleValid bit of the DHAR for node n is clear, the DHAR is |
| 583 | * disabled so skip to step 3 below. Otherwise see if the SysAddr is within |
| 584 | * the range of relocated addresses (starting at 0x100000000) from the DRAM |
| 585 | * hole. If not, skip to step 3 below. Else get the value of the |
| 586 | * DramHoleOffset field from the DHAR. To obtain the DramAddr, subtract the |
| 587 | * offset defined by this value from the SysAddr. |
| 588 | * |
| 589 | * 3. Obtain the base address for node n from the DRAMBase field of the DRAM |
| 590 | * Base register for node n. To obtain the DramAddr, subtract the base |
| 591 | * address from the SysAddr, as shown near the start of section 3.4.4 (p.70). |
| 592 | */ |
| 593 | static u64 sys_addr_to_dram_addr(struct mem_ctl_info *mci, u64 sys_addr) |
| 594 | { |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 595 | struct amd64_pvt *pvt = mci->pvt_info; |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 596 | u64 dram_base, hole_base, hole_offset, hole_size, dram_addr; |
Borislav Petkov | 1f31677 | 2012-08-10 12:50:50 +0200 | [diff] [blame] | 597 | int ret; |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 598 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 599 | dram_base = get_dram_base(pvt, pvt->mc_node_id); |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 600 | |
| 601 | ret = amd64_get_dram_hole_info(mci, &hole_base, &hole_offset, |
| 602 | &hole_size); |
| 603 | if (!ret) { |
Borislav Petkov | 1f31677 | 2012-08-10 12:50:50 +0200 | [diff] [blame] | 604 | if ((sys_addr >= (1ULL << 32)) && |
| 605 | (sys_addr < ((1ULL << 32) + hole_size))) { |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 606 | /* use DHAR to translate SysAddr to DramAddr */ |
| 607 | dram_addr = sys_addr - hole_offset; |
| 608 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 609 | edac_dbg(2, "using DHAR to translate SysAddr 0x%lx to DramAddr 0x%lx\n", |
| 610 | (unsigned long)sys_addr, |
| 611 | (unsigned long)dram_addr); |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 612 | |
| 613 | return dram_addr; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | /* |
| 618 | * Translate the SysAddr to a DramAddr as shown near the start of |
| 619 | * section 3.4.4 (p. 70). Although sys_addr is a 64-bit value, the k8 |
| 620 | * only deals with 40-bit values. Therefore we discard bits 63-40 of |
| 621 | * sys_addr below. If bit 39 of sys_addr is 1 then the bits we |
| 622 | * discard are all 1s. Otherwise the bits we discard are all 0s. See |
| 623 | * section 3.4.2 of AMD publication 24592: AMD x86-64 Architecture |
| 624 | * Programmer's Manual Volume 1 Application Programming. |
| 625 | */ |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 626 | dram_addr = (sys_addr & GENMASK_ULL(39, 0)) - dram_base; |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 627 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 628 | edac_dbg(2, "using DRAM Base register to translate SysAddr 0x%lx to DramAddr 0x%lx\n", |
| 629 | (unsigned long)sys_addr, (unsigned long)dram_addr); |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 630 | return dram_addr; |
| 631 | } |
| 632 | |
| 633 | /* |
| 634 | * @intlv_en is the value of the IntlvEn field from a DRAM Base register |
| 635 | * (section 3.4.4.1). Return the number of bits from a SysAddr that are used |
| 636 | * for node interleaving. |
| 637 | */ |
| 638 | static int num_node_interleave_bits(unsigned intlv_en) |
| 639 | { |
| 640 | static const int intlv_shift_table[] = { 0, 1, 0, 2, 0, 0, 0, 3 }; |
| 641 | int n; |
| 642 | |
| 643 | BUG_ON(intlv_en > 7); |
| 644 | n = intlv_shift_table[intlv_en]; |
| 645 | return n; |
| 646 | } |
| 647 | |
| 648 | /* Translate the DramAddr given by @dram_addr to an InputAddr. */ |
| 649 | static u64 dram_addr_to_input_addr(struct mem_ctl_info *mci, u64 dram_addr) |
| 650 | { |
| 651 | struct amd64_pvt *pvt; |
| 652 | int intlv_shift; |
| 653 | u64 input_addr; |
| 654 | |
| 655 | pvt = mci->pvt_info; |
| 656 | |
| 657 | /* |
| 658 | * See the start of section 3.4.4 (p. 70, BKDG #26094, K8, revA-E) |
| 659 | * concerning translating a DramAddr to an InputAddr. |
| 660 | */ |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 661 | intlv_shift = num_node_interleave_bits(dram_intlv_en(pvt, 0)); |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 662 | input_addr = ((dram_addr >> intlv_shift) & GENMASK_ULL(35, 12)) + |
Borislav Petkov | f678b8c | 2010-12-13 19:21:07 +0100 | [diff] [blame] | 663 | (dram_addr & 0xfff); |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 664 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 665 | edac_dbg(2, " Intlv Shift=%d DramAddr=0x%lx maps to InputAddr=0x%lx\n", |
| 666 | intlv_shift, (unsigned long)dram_addr, |
| 667 | (unsigned long)input_addr); |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 668 | |
| 669 | return input_addr; |
| 670 | } |
| 671 | |
| 672 | /* |
| 673 | * Translate the SysAddr represented by @sys_addr to an InputAddr. It is |
| 674 | * assumed that @sys_addr maps to the node given by mci. |
| 675 | */ |
| 676 | static u64 sys_addr_to_input_addr(struct mem_ctl_info *mci, u64 sys_addr) |
| 677 | { |
| 678 | u64 input_addr; |
| 679 | |
| 680 | input_addr = |
| 681 | dram_addr_to_input_addr(mci, sys_addr_to_dram_addr(mci, sys_addr)); |
| 682 | |
Masanari Iida | c19ca6c | 2016-02-08 20:53:12 +0900 | [diff] [blame] | 683 | edac_dbg(2, "SysAddr 0x%lx translates to InputAddr 0x%lx\n", |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 684 | (unsigned long)sys_addr, (unsigned long)input_addr); |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 685 | |
| 686 | return input_addr; |
| 687 | } |
| 688 | |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 689 | /* Map the Error address to a PAGE and PAGE OFFSET. */ |
| 690 | static inline void error_address_to_page_and_offset(u64 error_address, |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 691 | struct err_info *err) |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 692 | { |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 693 | err->page = (u32) (error_address >> PAGE_SHIFT); |
| 694 | err->offset = ((u32) error_address) & ~PAGE_MASK; |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | /* |
| 698 | * @sys_addr is an error address (a SysAddr) extracted from the MCA NB Address |
| 699 | * Low (section 3.6.4.5) and MCA NB Address High (section 3.6.4.6) registers |
| 700 | * of a node that detected an ECC memory error. mci represents the node that |
| 701 | * the error address maps to (possibly different from the node that detected |
| 702 | * the error). Return the number of the csrow that sys_addr maps to, or -1 on |
| 703 | * error. |
| 704 | */ |
| 705 | static int sys_addr_to_csrow(struct mem_ctl_info *mci, u64 sys_addr) |
| 706 | { |
| 707 | int csrow; |
| 708 | |
| 709 | csrow = input_addr_to_csrow(mci, sys_addr_to_input_addr(mci, sys_addr)); |
| 710 | |
| 711 | if (csrow == -1) |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 712 | amd64_mc_err(mci, "Failed to translate InputAddr to csrow for " |
| 713 | "address 0x%lx\n", (unsigned long)sys_addr); |
Doug Thompson | 93c2df5 | 2009-05-04 20:46:50 +0200 | [diff] [blame] | 714 | return csrow; |
| 715 | } |
Doug Thompson | e2ce725 | 2009-04-27 15:57:12 +0200 | [diff] [blame] | 716 | |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 717 | static int get_channel_from_ecc_syndrome(struct mem_ctl_info *, u16); |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 718 | |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 719 | /* |
| 720 | * Determine if the DIMMs have ECC enabled. ECC is enabled ONLY if all the DIMMs |
| 721 | * are ECC capable. |
| 722 | */ |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 723 | static unsigned long determine_edac_cap(struct amd64_pvt *pvt) |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 724 | { |
Dan Carpenter | 1f6189e | 2011-10-06 02:30:25 -0400 | [diff] [blame] | 725 | unsigned long edac_cap = EDAC_FLAG_NONE; |
Yazen Ghannam | d27f3a3 | 2016-11-17 17:57:40 -0500 | [diff] [blame] | 726 | u8 bit; |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 727 | |
Yazen Ghannam | d27f3a3 | 2016-11-17 17:57:40 -0500 | [diff] [blame] | 728 | if (pvt->umc) { |
| 729 | u8 i, umc_en_mask = 0, dimm_ecc_en_mask = 0; |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 730 | |
Yazen Ghannam | 4d30d2b | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 731 | for_each_umc(i) { |
Yazen Ghannam | d27f3a3 | 2016-11-17 17:57:40 -0500 | [diff] [blame] | 732 | if (!(pvt->umc[i].sdp_ctrl & UMC_SDP_INIT)) |
| 733 | continue; |
| 734 | |
| 735 | umc_en_mask |= BIT(i); |
| 736 | |
| 737 | /* UMC Configuration bit 12 (DimmEccEn) */ |
| 738 | if (pvt->umc[i].umc_cfg & BIT(12)) |
| 739 | dimm_ecc_en_mask |= BIT(i); |
| 740 | } |
| 741 | |
| 742 | if (umc_en_mask == dimm_ecc_en_mask) |
| 743 | edac_cap = EDAC_FLAG_SECDED; |
| 744 | } else { |
| 745 | bit = (pvt->fam > 0xf || pvt->ext_model >= K8_REV_F) |
| 746 | ? 19 |
| 747 | : 17; |
| 748 | |
| 749 | if (pvt->dclr0 & BIT(bit)) |
| 750 | edac_cap = EDAC_FLAG_SECDED; |
| 751 | } |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 752 | |
| 753 | return edac_cap; |
| 754 | } |
| 755 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 756 | static void debug_display_dimm_sizes(struct amd64_pvt *, u8); |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 757 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 758 | static void debug_dump_dramcfg_low(struct amd64_pvt *pvt, u32 dclr, int chan) |
Borislav Petkov | 68798e1 | 2009-11-03 16:18:33 +0100 | [diff] [blame] | 759 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 760 | edac_dbg(1, "F2x%d90 (DRAM Cfg Low): 0x%08x\n", chan, dclr); |
Borislav Petkov | 68798e1 | 2009-11-03 16:18:33 +0100 | [diff] [blame] | 761 | |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 762 | if (pvt->dram_type == MEM_LRDDR3) { |
| 763 | u32 dcsm = pvt->csels[chan].csmasks[0]; |
| 764 | /* |
| 765 | * It's assumed all LRDIMMs in a DCT are going to be of |
| 766 | * same 'type' until proven otherwise. So, use a cs |
| 767 | * value of '0' here to get dcsm value. |
| 768 | */ |
| 769 | edac_dbg(1, " LRDIMM %dx rank multiply\n", (dcsm & 0x3)); |
| 770 | } |
| 771 | |
| 772 | edac_dbg(1, "All DIMMs support ECC:%s\n", |
| 773 | (dclr & BIT(19)) ? "yes" : "no"); |
| 774 | |
Borislav Petkov | 68798e1 | 2009-11-03 16:18:33 +0100 | [diff] [blame] | 775 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 776 | edac_dbg(1, " PAR/ERR parity: %s\n", |
| 777 | (dclr & BIT(8)) ? "enabled" : "disabled"); |
Borislav Petkov | 68798e1 | 2009-11-03 16:18:33 +0100 | [diff] [blame] | 778 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 779 | if (pvt->fam == 0x10) |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 780 | edac_dbg(1, " DCT 128bit mode width: %s\n", |
| 781 | (dclr & BIT(11)) ? "128b" : "64b"); |
Borislav Petkov | 68798e1 | 2009-11-03 16:18:33 +0100 | [diff] [blame] | 782 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 783 | edac_dbg(1, " x4 logical DIMMs present: L0: %s L1: %s L2: %s L3: %s\n", |
| 784 | (dclr & BIT(12)) ? "yes" : "no", |
| 785 | (dclr & BIT(13)) ? "yes" : "no", |
| 786 | (dclr & BIT(14)) ? "yes" : "no", |
| 787 | (dclr & BIT(15)) ? "yes" : "no"); |
Borislav Petkov | 68798e1 | 2009-11-03 16:18:33 +0100 | [diff] [blame] | 788 | } |
| 789 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 790 | #define CS_EVEN_PRIMARY BIT(0) |
| 791 | #define CS_ODD_PRIMARY BIT(1) |
Yazen Ghannam | 81f5090 | 2019-08-22 00:00:02 +0000 | [diff] [blame] | 792 | #define CS_EVEN_SECONDARY BIT(2) |
| 793 | #define CS_ODD_SECONDARY BIT(3) |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 794 | |
Yazen Ghannam | 81f5090 | 2019-08-22 00:00:02 +0000 | [diff] [blame] | 795 | #define CS_EVEN (CS_EVEN_PRIMARY | CS_EVEN_SECONDARY) |
| 796 | #define CS_ODD (CS_ODD_PRIMARY | CS_ODD_SECONDARY) |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 797 | |
| 798 | static int f17_get_cs_mode(int dimm, u8 ctrl, struct amd64_pvt *pvt) |
Yazen Ghannam | fc00c6a | 2019-02-28 15:36:12 +0000 | [diff] [blame] | 799 | { |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 800 | int cs_mode = 0; |
Yazen Ghannam | fc00c6a | 2019-02-28 15:36:12 +0000 | [diff] [blame] | 801 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 802 | if (csrow_enabled(2 * dimm, ctrl, pvt)) |
| 803 | cs_mode |= CS_EVEN_PRIMARY; |
Yazen Ghannam | fc00c6a | 2019-02-28 15:36:12 +0000 | [diff] [blame] | 804 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 805 | if (csrow_enabled(2 * dimm + 1, ctrl, pvt)) |
| 806 | cs_mode |= CS_ODD_PRIMARY; |
| 807 | |
Yazen Ghannam | 81f5090 | 2019-08-22 00:00:02 +0000 | [diff] [blame] | 808 | /* Asymmetric dual-rank DIMM support. */ |
| 809 | if (csrow_sec_enabled(2 * dimm + 1, ctrl, pvt)) |
| 810 | cs_mode |= CS_ODD_SECONDARY; |
| 811 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 812 | return cs_mode; |
Yazen Ghannam | fc00c6a | 2019-02-28 15:36:12 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 815 | static void debug_display_dimm_sizes_df(struct amd64_pvt *pvt, u8 ctrl) |
| 816 | { |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 817 | int dimm, size0, size1, cs0, cs1, cs_mode; |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 818 | |
| 819 | edac_printk(KERN_DEBUG, EDAC_MC, "UMC%d chip selects:\n", ctrl); |
| 820 | |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 821 | for (dimm = 0; dimm < 2; dimm++) { |
Yazen Ghannam | eb77e6b | 2017-04-27 12:11:54 -0500 | [diff] [blame] | 822 | cs0 = dimm * 2; |
Yazen Ghannam | eb77e6b | 2017-04-27 12:11:54 -0500 | [diff] [blame] | 823 | cs1 = dimm * 2 + 1; |
| 824 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 825 | cs_mode = f17_get_cs_mode(dimm, ctrl, pvt); |
| 826 | |
| 827 | size0 = pvt->ops->dbam_to_cs(pvt, ctrl, cs_mode, cs0); |
| 828 | size1 = pvt->ops->dbam_to_cs(pvt, ctrl, cs_mode, cs1); |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 829 | |
| 830 | amd64_info(EDAC_MC ": %d: %5dMB %d: %5dMB\n", |
Yazen Ghannam | eb77e6b | 2017-04-27 12:11:54 -0500 | [diff] [blame] | 831 | cs0, size0, |
| 832 | cs1, size1); |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 833 | } |
| 834 | } |
| 835 | |
| 836 | static void __dump_misc_regs_df(struct amd64_pvt *pvt) |
| 837 | { |
| 838 | struct amd64_umc *umc; |
| 839 | u32 i, tmp, umc_base; |
| 840 | |
Yazen Ghannam | 4d30d2b | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 841 | for_each_umc(i) { |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 842 | umc_base = get_umc_base(i); |
| 843 | umc = &pvt->umc[i]; |
| 844 | |
| 845 | edac_dbg(1, "UMC%d DIMM cfg: 0x%x\n", i, umc->dimm_cfg); |
| 846 | edac_dbg(1, "UMC%d UMC cfg: 0x%x\n", i, umc->umc_cfg); |
| 847 | edac_dbg(1, "UMC%d SDP ctrl: 0x%x\n", i, umc->sdp_ctrl); |
| 848 | edac_dbg(1, "UMC%d ECC ctrl: 0x%x\n", i, umc->ecc_ctrl); |
| 849 | |
| 850 | amd_smn_read(pvt->mc_node_id, umc_base + UMCCH_ECC_BAD_SYMBOL, &tmp); |
| 851 | edac_dbg(1, "UMC%d ECC bad symbol: 0x%x\n", i, tmp); |
| 852 | |
| 853 | amd_smn_read(pvt->mc_node_id, umc_base + UMCCH_UMC_CAP, &tmp); |
| 854 | edac_dbg(1, "UMC%d UMC cap: 0x%x\n", i, tmp); |
| 855 | edac_dbg(1, "UMC%d UMC cap high: 0x%x\n", i, umc->umc_cap_hi); |
| 856 | |
| 857 | edac_dbg(1, "UMC%d ECC capable: %s, ChipKill ECC capable: %s\n", |
| 858 | i, (umc->umc_cap_hi & BIT(30)) ? "yes" : "no", |
| 859 | (umc->umc_cap_hi & BIT(31)) ? "yes" : "no"); |
| 860 | edac_dbg(1, "UMC%d All DIMMs support ECC: %s\n", |
| 861 | i, (umc->umc_cfg & BIT(12)) ? "yes" : "no"); |
| 862 | edac_dbg(1, "UMC%d x4 DIMMs present: %s\n", |
| 863 | i, (umc->dimm_cfg & BIT(6)) ? "yes" : "no"); |
| 864 | edac_dbg(1, "UMC%d x16 DIMMs present: %s\n", |
| 865 | i, (umc->dimm_cfg & BIT(7)) ? "yes" : "no"); |
| 866 | |
| 867 | if (pvt->dram_type == MEM_LRDDR4) { |
| 868 | amd_smn_read(pvt->mc_node_id, umc_base + UMCCH_ADDR_CFG, &tmp); |
| 869 | edac_dbg(1, "UMC%d LRDIMM %dx rank multiply\n", |
| 870 | i, 1 << ((tmp >> 4) & 0x3)); |
| 871 | } |
| 872 | |
| 873 | debug_display_dimm_sizes_df(pvt, i); |
| 874 | } |
| 875 | |
| 876 | edac_dbg(1, "F0x104 (DRAM Hole Address): 0x%08x, base: 0x%08x\n", |
| 877 | pvt->dhar, dhar_base(pvt)); |
| 878 | } |
| 879 | |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 880 | /* Display and decode various NB registers for debug purposes. */ |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 881 | static void __dump_misc_regs(struct amd64_pvt *pvt) |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 882 | { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 883 | edac_dbg(1, "F3xE8 (NB Cap): 0x%08x\n", pvt->nbcap); |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 884 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 885 | edac_dbg(1, " NB two channel DRAM capable: %s\n", |
| 886 | (pvt->nbcap & NBCAP_DCT_DUAL) ? "yes" : "no"); |
Borislav Petkov | 68798e1 | 2009-11-03 16:18:33 +0100 | [diff] [blame] | 887 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 888 | edac_dbg(1, " ECC capable: %s, ChipKill ECC capable: %s\n", |
| 889 | (pvt->nbcap & NBCAP_SECDED) ? "yes" : "no", |
| 890 | (pvt->nbcap & NBCAP_CHIPKILL) ? "yes" : "no"); |
Borislav Petkov | 68798e1 | 2009-11-03 16:18:33 +0100 | [diff] [blame] | 891 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 892 | debug_dump_dramcfg_low(pvt, pvt->dclr0, 0); |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 893 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 894 | edac_dbg(1, "F3xB0 (Online Spare): 0x%08x\n", pvt->online_spare); |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 895 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 896 | edac_dbg(1, "F1xF0 (DRAM Hole Address): 0x%08x, base: 0x%08x, offset: 0x%08x\n", |
| 897 | pvt->dhar, dhar_base(pvt), |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 898 | (pvt->fam == 0xf) ? k8_dhar_offset(pvt) |
| 899 | : f10_dhar_offset(pvt)); |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 900 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 901 | debug_display_dimm_sizes(pvt, 0); |
Borislav Petkov | 4d79636 | 2011-02-03 15:59:57 +0100 | [diff] [blame] | 902 | |
Borislav Petkov | 8de1d91 | 2009-10-16 13:39:30 +0200 | [diff] [blame] | 903 | /* everything below this point is Fam10h and above */ |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 904 | if (pvt->fam == 0xf) |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 905 | return; |
Borislav Petkov | 4d79636 | 2011-02-03 15:59:57 +0100 | [diff] [blame] | 906 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 907 | debug_display_dimm_sizes(pvt, 1); |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 908 | |
Borislav Petkov | 8de1d91 | 2009-10-16 13:39:30 +0200 | [diff] [blame] | 909 | /* Only if NOT ganged does dclr1 have valid info */ |
Borislav Petkov | 68798e1 | 2009-11-03 16:18:33 +0100 | [diff] [blame] | 910 | if (!dct_ganging_enabled(pvt)) |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 911 | debug_dump_dramcfg_low(pvt, pvt->dclr1, 1); |
Doug Thompson | 2da1165 | 2009-04-27 16:09:09 +0200 | [diff] [blame] | 912 | } |
| 913 | |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 914 | /* Display and decode various NB registers for debug purposes. */ |
| 915 | static void dump_misc_regs(struct amd64_pvt *pvt) |
| 916 | { |
| 917 | if (pvt->umc) |
| 918 | __dump_misc_regs_df(pvt); |
| 919 | else |
| 920 | __dump_misc_regs(pvt); |
| 921 | |
| 922 | edac_dbg(1, " DramHoleValid: %s\n", dhar_valid(pvt) ? "yes" : "no"); |
| 923 | |
Yazen Ghannam | 7835961 | 2019-02-28 15:36:11 +0000 | [diff] [blame] | 924 | amd64_info("using x%u syndromes.\n", pvt->ecc_sym_sz); |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 925 | } |
| 926 | |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 927 | /* |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 928 | * See BKDG, F2x[1,0][5C:40], F2[1,0][6C:60] |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 929 | */ |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 930 | static void prep_chip_selects(struct amd64_pvt *pvt) |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 931 | { |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 932 | if (pvt->fam == 0xf && pvt->ext_model < K8_REV_F) { |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 933 | pvt->csels[0].b_cnt = pvt->csels[1].b_cnt = 8; |
| 934 | pvt->csels[0].m_cnt = pvt->csels[1].m_cnt = 8; |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 935 | } else if (pvt->fam == 0x15 && pvt->model == 0x30) { |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 936 | pvt->csels[0].b_cnt = pvt->csels[1].b_cnt = 4; |
| 937 | pvt->csels[0].m_cnt = pvt->csels[1].m_cnt = 2; |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 938 | } else if (pvt->fam >= 0x17) { |
| 939 | int umc; |
| 940 | |
| 941 | for_each_umc(umc) { |
| 942 | pvt->csels[umc].b_cnt = 4; |
| 943 | pvt->csels[umc].m_cnt = 2; |
| 944 | } |
| 945 | |
Borislav Petkov | 9d858bb | 2009-09-21 14:35:51 +0200 | [diff] [blame] | 946 | } else { |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 947 | pvt->csels[0].b_cnt = pvt->csels[1].b_cnt = 8; |
| 948 | pvt->csels[0].m_cnt = pvt->csels[1].m_cnt = 4; |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 952 | static void read_umc_base_mask(struct amd64_pvt *pvt) |
| 953 | { |
Yazen Ghannam | 7574729 | 2019-08-22 00:00:01 +0000 | [diff] [blame] | 954 | u32 umc_base_reg, umc_base_reg_sec; |
| 955 | u32 umc_mask_reg, umc_mask_reg_sec; |
| 956 | u32 base_reg, base_reg_sec; |
| 957 | u32 mask_reg, mask_reg_sec; |
| 958 | u32 *base, *base_sec; |
| 959 | u32 *mask, *mask_sec; |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 960 | int cs, umc; |
| 961 | |
| 962 | for_each_umc(umc) { |
| 963 | umc_base_reg = get_umc_base(umc) + UMCCH_BASE_ADDR; |
Yazen Ghannam | 7574729 | 2019-08-22 00:00:01 +0000 | [diff] [blame] | 964 | umc_base_reg_sec = get_umc_base(umc) + UMCCH_BASE_ADDR_SEC; |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 965 | |
| 966 | for_each_chip_select(cs, umc, pvt) { |
| 967 | base = &pvt->csels[umc].csbases[cs]; |
Yazen Ghannam | 7574729 | 2019-08-22 00:00:01 +0000 | [diff] [blame] | 968 | base_sec = &pvt->csels[umc].csbases_sec[cs]; |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 969 | |
| 970 | base_reg = umc_base_reg + (cs * 4); |
Yazen Ghannam | 7574729 | 2019-08-22 00:00:01 +0000 | [diff] [blame] | 971 | base_reg_sec = umc_base_reg_sec + (cs * 4); |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 972 | |
| 973 | if (!amd_smn_read(pvt->mc_node_id, base_reg, base)) |
| 974 | edac_dbg(0, " DCSB%d[%d]=0x%08x reg: 0x%x\n", |
| 975 | umc, cs, *base, base_reg); |
Yazen Ghannam | 7574729 | 2019-08-22 00:00:01 +0000 | [diff] [blame] | 976 | |
| 977 | if (!amd_smn_read(pvt->mc_node_id, base_reg_sec, base_sec)) |
| 978 | edac_dbg(0, " DCSB_SEC%d[%d]=0x%08x reg: 0x%x\n", |
| 979 | umc, cs, *base_sec, base_reg_sec); |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | umc_mask_reg = get_umc_base(umc) + UMCCH_ADDR_MASK; |
Yazen Ghannam | 7574729 | 2019-08-22 00:00:01 +0000 | [diff] [blame] | 983 | umc_mask_reg_sec = get_umc_base(umc) + UMCCH_ADDR_MASK_SEC; |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 984 | |
| 985 | for_each_chip_select_mask(cs, umc, pvt) { |
| 986 | mask = &pvt->csels[umc].csmasks[cs]; |
Yazen Ghannam | 7574729 | 2019-08-22 00:00:01 +0000 | [diff] [blame] | 987 | mask_sec = &pvt->csels[umc].csmasks_sec[cs]; |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 988 | |
| 989 | mask_reg = umc_mask_reg + (cs * 4); |
Yazen Ghannam | 7574729 | 2019-08-22 00:00:01 +0000 | [diff] [blame] | 990 | mask_reg_sec = umc_mask_reg_sec + (cs * 4); |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 991 | |
| 992 | if (!amd_smn_read(pvt->mc_node_id, mask_reg, mask)) |
| 993 | edac_dbg(0, " DCSM%d[%d]=0x%08x reg: 0x%x\n", |
| 994 | umc, cs, *mask, mask_reg); |
Yazen Ghannam | 7574729 | 2019-08-22 00:00:01 +0000 | [diff] [blame] | 995 | |
| 996 | if (!amd_smn_read(pvt->mc_node_id, mask_reg_sec, mask_sec)) |
| 997 | edac_dbg(0, " DCSM_SEC%d[%d]=0x%08x reg: 0x%x\n", |
| 998 | umc, cs, *mask_sec, mask_reg_sec); |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 999 | } |
| 1000 | } |
| 1001 | } |
| 1002 | |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1003 | /* |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1004 | * Function 2 Offset F10_DCSB0; read in the DCS Base and DCS Mask registers |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1005 | */ |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 1006 | static void read_dct_base_mask(struct amd64_pvt *pvt) |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1007 | { |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1008 | int cs; |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1009 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1010 | prep_chip_selects(pvt); |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1011 | |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1012 | if (pvt->umc) |
| 1013 | return read_umc_base_mask(pvt); |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 1014 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1015 | for_each_chip_select(cs, 0, pvt) { |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1016 | int reg0 = DCSB0 + (cs * 4); |
| 1017 | int reg1 = DCSB1 + (cs * 4); |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1018 | u32 *base0 = &pvt->csels[0].csbases[cs]; |
| 1019 | u32 *base1 = &pvt->csels[1].csbases[cs]; |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 1020 | |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1021 | if (!amd64_read_dct_pci_cfg(pvt, 0, reg0, base0)) |
| 1022 | edac_dbg(0, " DCSB0[%d]=0x%08x reg: F2x%x\n", |
| 1023 | cs, *base0, reg0); |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1024 | |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1025 | if (pvt->fam == 0xf) |
| 1026 | continue; |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 1027 | |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1028 | if (!amd64_read_dct_pci_cfg(pvt, 1, reg0, base1)) |
| 1029 | edac_dbg(0, " DCSB1[%d]=0x%08x reg: F2x%x\n", |
| 1030 | cs, *base1, (pvt->fam == 0x10) ? reg1 |
| 1031 | : reg0); |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1032 | } |
| 1033 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1034 | for_each_chip_select_mask(cs, 0, pvt) { |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1035 | int reg0 = DCSM0 + (cs * 4); |
| 1036 | int reg1 = DCSM1 + (cs * 4); |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1037 | u32 *mask0 = &pvt->csels[0].csmasks[cs]; |
| 1038 | u32 *mask1 = &pvt->csels[1].csmasks[cs]; |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 1039 | |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1040 | if (!amd64_read_dct_pci_cfg(pvt, 0, reg0, mask0)) |
| 1041 | edac_dbg(0, " DCSM0[%d]=0x%08x reg: F2x%x\n", |
| 1042 | cs, *mask0, reg0); |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1043 | |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1044 | if (pvt->fam == 0xf) |
| 1045 | continue; |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 1046 | |
Yazen Ghannam | d971e28 | 2019-08-21 23:59:55 +0000 | [diff] [blame] | 1047 | if (!amd64_read_dct_pci_cfg(pvt, 1, reg0, mask1)) |
| 1048 | edac_dbg(0, " DCSM1[%d]=0x%08x reg: F2x%x\n", |
| 1049 | cs, *mask1, (pvt->fam == 0x10) ? reg1 |
| 1050 | : reg0); |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1051 | } |
| 1052 | } |
| 1053 | |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1054 | static void determine_memory_type(struct amd64_pvt *pvt) |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1055 | { |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1056 | u32 dram_ctrl, dcsm; |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1057 | |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1058 | switch (pvt->fam) { |
| 1059 | case 0xf: |
| 1060 | if (pvt->ext_model >= K8_REV_F) |
| 1061 | goto ddr3; |
| 1062 | |
| 1063 | pvt->dram_type = (pvt->dclr0 & BIT(18)) ? MEM_DDR : MEM_RDDR; |
| 1064 | return; |
| 1065 | |
| 1066 | case 0x10: |
Borislav Petkov | 6b4c0bd | 2009-11-12 15:37:57 +0100 | [diff] [blame] | 1067 | if (pvt->dchr0 & DDR3_MODE) |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1068 | goto ddr3; |
| 1069 | |
| 1070 | pvt->dram_type = (pvt->dclr0 & BIT(16)) ? MEM_DDR2 : MEM_RDDR2; |
| 1071 | return; |
| 1072 | |
| 1073 | case 0x15: |
| 1074 | if (pvt->model < 0x60) |
| 1075 | goto ddr3; |
| 1076 | |
| 1077 | /* |
| 1078 | * Model 0x60h needs special handling: |
| 1079 | * |
| 1080 | * We use a Chip Select value of '0' to obtain dcsm. |
| 1081 | * Theoretically, it is possible to populate LRDIMMs of different |
| 1082 | * 'Rank' value on a DCT. But this is not the common case. So, |
| 1083 | * it's reasonable to assume all DIMMs are going to be of same |
| 1084 | * 'type' until proven otherwise. |
| 1085 | */ |
| 1086 | amd64_read_dct_pci_cfg(pvt, 0, DRAM_CONTROL, &dram_ctrl); |
| 1087 | dcsm = pvt->csels[0].csmasks[0]; |
| 1088 | |
| 1089 | if (((dram_ctrl >> 8) & 0x7) == 0x2) |
| 1090 | pvt->dram_type = MEM_DDR4; |
| 1091 | else if (pvt->dclr0 & BIT(16)) |
| 1092 | pvt->dram_type = MEM_DDR3; |
| 1093 | else if (dcsm & 0x3) |
| 1094 | pvt->dram_type = MEM_LRDDR3; |
Borislav Petkov | 6b4c0bd | 2009-11-12 15:37:57 +0100 | [diff] [blame] | 1095 | else |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1096 | pvt->dram_type = MEM_RDDR3; |
| 1097 | |
| 1098 | return; |
| 1099 | |
| 1100 | case 0x16: |
| 1101 | goto ddr3; |
| 1102 | |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 1103 | case 0x17: |
Pu Wen | c4a3e94 | 2018-09-27 16:31:28 +0200 | [diff] [blame] | 1104 | case 0x18: |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 1105 | if ((pvt->umc[0].dimm_cfg | pvt->umc[1].dimm_cfg) & BIT(5)) |
| 1106 | pvt->dram_type = MEM_LRDDR4; |
| 1107 | else if ((pvt->umc[0].dimm_cfg | pvt->umc[1].dimm_cfg) & BIT(4)) |
| 1108 | pvt->dram_type = MEM_RDDR4; |
| 1109 | else |
| 1110 | pvt->dram_type = MEM_DDR4; |
| 1111 | return; |
| 1112 | |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1113 | default: |
| 1114 | WARN(1, KERN_ERR "%s: Family??? 0x%x\n", __func__, pvt->fam); |
| 1115 | pvt->dram_type = MEM_EMPTY; |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1116 | } |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1117 | return; |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1118 | |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1119 | ddr3: |
| 1120 | pvt->dram_type = (pvt->dclr0 & BIT(16)) ? MEM_DDR3 : MEM_RDDR3; |
Doug Thompson | 94be4bf | 2009-04-27 16:12:00 +0200 | [diff] [blame] | 1121 | } |
| 1122 | |
Borislav Petkov | cb32850 | 2010-12-22 14:28:24 +0100 | [diff] [blame] | 1123 | /* Get the number of DCT channels the memory controller is using. */ |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1124 | static int k8_early_channel_count(struct amd64_pvt *pvt) |
| 1125 | { |
Borislav Petkov | cb32850 | 2010-12-22 14:28:24 +0100 | [diff] [blame] | 1126 | int flag; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1127 | |
Borislav Petkov | 9f56da0 | 2010-10-01 19:44:53 +0200 | [diff] [blame] | 1128 | if (pvt->ext_model >= K8_REV_F) |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1129 | /* RevF (NPT) and later */ |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1130 | flag = pvt->dclr0 & WIDTH_128; |
Borislav Petkov | 9f56da0 | 2010-10-01 19:44:53 +0200 | [diff] [blame] | 1131 | else |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1132 | /* RevE and earlier */ |
| 1133 | flag = pvt->dclr0 & REVE_WIDTH_128; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1134 | |
| 1135 | /* not used */ |
| 1136 | pvt->dclr1 = 0; |
| 1137 | |
| 1138 | return (flag) ? 2 : 1; |
| 1139 | } |
| 1140 | |
Borislav Petkov | 7004662 | 2011-01-10 14:37:27 +0100 | [diff] [blame] | 1141 | /* On F10h and later ErrAddr is MC4_ADDR[47:1] */ |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 1142 | static u64 get_error_address(struct amd64_pvt *pvt, struct mce *m) |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1143 | { |
Borislav Petkov | 2ec591a | 2015-02-17 10:58:34 +0100 | [diff] [blame] | 1144 | u16 mce_nid = amd_get_nb_id(m->extcpu); |
| 1145 | struct mem_ctl_info *mci; |
Borislav Petkov | 7004662 | 2011-01-10 14:37:27 +0100 | [diff] [blame] | 1146 | u8 start_bit = 1; |
| 1147 | u8 end_bit = 47; |
Borislav Petkov | 2ec591a | 2015-02-17 10:58:34 +0100 | [diff] [blame] | 1148 | u64 addr; |
| 1149 | |
| 1150 | mci = edac_mc_find(mce_nid); |
| 1151 | if (!mci) |
| 1152 | return 0; |
| 1153 | |
| 1154 | pvt = mci->pvt_info; |
Borislav Petkov | 7004662 | 2011-01-10 14:37:27 +0100 | [diff] [blame] | 1155 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 1156 | if (pvt->fam == 0xf) { |
Borislav Petkov | 7004662 | 2011-01-10 14:37:27 +0100 | [diff] [blame] | 1157 | start_bit = 3; |
| 1158 | end_bit = 39; |
| 1159 | } |
| 1160 | |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1161 | addr = m->addr & GENMASK_ULL(end_bit, start_bit); |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1162 | |
| 1163 | /* |
| 1164 | * Erratum 637 workaround |
| 1165 | */ |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 1166 | if (pvt->fam == 0x15) { |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1167 | u64 cc6_base, tmp_addr; |
| 1168 | u32 tmp; |
Daniel J Blueman | 8b84c8d | 2012-11-27 14:32:10 +0800 | [diff] [blame] | 1169 | u8 intlv_en; |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1170 | |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1171 | if ((addr & GENMASK_ULL(47, 24)) >> 24 != 0x00fdf7) |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1172 | return addr; |
| 1173 | |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1174 | |
| 1175 | amd64_read_pci_cfg(pvt->F1, DRAM_LOCAL_NODE_LIM, &tmp); |
| 1176 | intlv_en = tmp >> 21 & 0x7; |
| 1177 | |
| 1178 | /* add [47:27] + 3 trailing bits */ |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1179 | cc6_base = (tmp & GENMASK_ULL(20, 0)) << 3; |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1180 | |
| 1181 | /* reverse and add DramIntlvEn */ |
| 1182 | cc6_base |= intlv_en ^ 0x7; |
| 1183 | |
| 1184 | /* pin at [47:24] */ |
| 1185 | cc6_base <<= 24; |
| 1186 | |
| 1187 | if (!intlv_en) |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1188 | return cc6_base | (addr & GENMASK_ULL(23, 0)); |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1189 | |
| 1190 | amd64_read_pci_cfg(pvt->F1, DRAM_LOCAL_NODE_BASE, &tmp); |
| 1191 | |
| 1192 | /* faster log2 */ |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1193 | tmp_addr = (addr & GENMASK_ULL(23, 12)) << __fls(intlv_en + 1); |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1194 | |
| 1195 | /* OR DramIntlvSel into bits [14:12] */ |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1196 | tmp_addr |= (tmp & GENMASK_ULL(23, 21)) >> 9; |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1197 | |
| 1198 | /* add remaining [11:0] bits from original MC4_ADDR */ |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1199 | tmp_addr |= addr & GENMASK_ULL(11, 0); |
Borislav Petkov | c1ae683 | 2011-03-30 15:42:10 +0200 | [diff] [blame] | 1200 | |
| 1201 | return cc6_base | tmp_addr; |
| 1202 | } |
| 1203 | |
| 1204 | return addr; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1205 | } |
| 1206 | |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1207 | static struct pci_dev *pci_get_related_function(unsigned int vendor, |
| 1208 | unsigned int device, |
| 1209 | struct pci_dev *related) |
| 1210 | { |
| 1211 | struct pci_dev *dev = NULL; |
| 1212 | |
| 1213 | while ((dev = pci_get_device(vendor, device, dev))) { |
| 1214 | if (pci_domain_nr(dev->bus) == pci_domain_nr(related->bus) && |
| 1215 | (dev->bus->number == related->bus->number) && |
| 1216 | (PCI_SLOT(dev->devfn) == PCI_SLOT(related->devfn))) |
| 1217 | break; |
| 1218 | } |
| 1219 | |
| 1220 | return dev; |
| 1221 | } |
| 1222 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 1223 | static void read_dram_base_limit_regs(struct amd64_pvt *pvt, unsigned range) |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1224 | { |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1225 | struct amd_northbridge *nb; |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 1226 | struct pci_dev *f1 = NULL; |
| 1227 | unsigned int pci_func; |
Borislav Petkov | 71d2a32 | 2011-02-21 19:37:24 +0100 | [diff] [blame] | 1228 | int off = range << 3; |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1229 | u32 llim; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1230 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 1231 | amd64_read_pci_cfg(pvt->F1, DRAM_BASE_LO + off, &pvt->ranges[range].base.lo); |
| 1232 | amd64_read_pci_cfg(pvt->F1, DRAM_LIMIT_LO + off, &pvt->ranges[range].lim.lo); |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1233 | |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 1234 | if (pvt->fam == 0xf) |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 1235 | return; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1236 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 1237 | if (!dram_rw(pvt, range)) |
| 1238 | return; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1239 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 1240 | amd64_read_pci_cfg(pvt->F1, DRAM_BASE_HI + off, &pvt->ranges[range].base.hi); |
| 1241 | amd64_read_pci_cfg(pvt->F1, DRAM_LIMIT_HI + off, &pvt->ranges[range].lim.hi); |
Borislav Petkov | f08e457 | 2011-03-21 20:45:06 +0100 | [diff] [blame] | 1242 | |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1243 | /* F15h: factor in CC6 save area by reading dst node's limit reg */ |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 1244 | if (pvt->fam != 0x15) |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1245 | return; |
Borislav Petkov | f08e457 | 2011-03-21 20:45:06 +0100 | [diff] [blame] | 1246 | |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1247 | nb = node_to_amd_nb(dram_dst_node(pvt, range)); |
| 1248 | if (WARN_ON(!nb)) |
| 1249 | return; |
Borislav Petkov | f08e457 | 2011-03-21 20:45:06 +0100 | [diff] [blame] | 1250 | |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1251 | if (pvt->model == 0x60) |
| 1252 | pci_func = PCI_DEVICE_ID_AMD_15H_M60H_NB_F1; |
| 1253 | else if (pvt->model == 0x30) |
| 1254 | pci_func = PCI_DEVICE_ID_AMD_15H_M30H_NB_F1; |
| 1255 | else |
| 1256 | pci_func = PCI_DEVICE_ID_AMD_15H_NB_F1; |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 1257 | |
| 1258 | f1 = pci_get_related_function(nb->misc->vendor, pci_func, nb->misc); |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1259 | if (WARN_ON(!f1)) |
| 1260 | return; |
Borislav Petkov | f08e457 | 2011-03-21 20:45:06 +0100 | [diff] [blame] | 1261 | |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1262 | amd64_read_pci_cfg(f1, DRAM_LOCAL_NODE_LIM, &llim); |
Borislav Petkov | f08e457 | 2011-03-21 20:45:06 +0100 | [diff] [blame] | 1263 | |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1264 | pvt->ranges[range].lim.lo &= GENMASK_ULL(15, 0); |
Borislav Petkov | f08e457 | 2011-03-21 20:45:06 +0100 | [diff] [blame] | 1265 | |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1266 | /* {[39:27],111b} */ |
| 1267 | pvt->ranges[range].lim.lo |= ((llim & 0x1fff) << 3 | 0x7) << 16; |
Borislav Petkov | f08e457 | 2011-03-21 20:45:06 +0100 | [diff] [blame] | 1268 | |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1269 | pvt->ranges[range].lim.hi &= GENMASK_ULL(7, 0); |
Borislav Petkov | f08e457 | 2011-03-21 20:45:06 +0100 | [diff] [blame] | 1270 | |
Daniel J Blueman | e2c0bff | 2012-11-30 16:44:19 +0800 | [diff] [blame] | 1271 | /* [47:40] */ |
| 1272 | pvt->ranges[range].lim.hi |= llim >> 13; |
| 1273 | |
| 1274 | pci_dev_put(f1); |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1275 | } |
| 1276 | |
Borislav Petkov | f192c7b | 2011-01-10 14:24:32 +0100 | [diff] [blame] | 1277 | static void k8_map_sysaddr_to_csrow(struct mem_ctl_info *mci, u64 sys_addr, |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1278 | struct err_info *err) |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1279 | { |
Borislav Petkov | f192c7b | 2011-01-10 14:24:32 +0100 | [diff] [blame] | 1280 | struct amd64_pvt *pvt = mci->pvt_info; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1281 | |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1282 | error_address_to_page_and_offset(sys_addr, err); |
Mauro Carvalho Chehab | ab5a503 | 2012-04-16 15:03:50 -0300 | [diff] [blame] | 1283 | |
| 1284 | /* |
| 1285 | * Find out which node the error address belongs to. This may be |
| 1286 | * different from the node that detected the error. |
| 1287 | */ |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1288 | err->src_mci = find_mc_by_sys_addr(mci, sys_addr); |
| 1289 | if (!err->src_mci) { |
Mauro Carvalho Chehab | ab5a503 | 2012-04-16 15:03:50 -0300 | [diff] [blame] | 1290 | amd64_mc_err(mci, "failed to map error addr 0x%lx to a node\n", |
| 1291 | (unsigned long)sys_addr); |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1292 | err->err_code = ERR_NODE; |
Mauro Carvalho Chehab | ab5a503 | 2012-04-16 15:03:50 -0300 | [diff] [blame] | 1293 | return; |
| 1294 | } |
| 1295 | |
| 1296 | /* Now map the sys_addr to a CSROW */ |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1297 | err->csrow = sys_addr_to_csrow(err->src_mci, sys_addr); |
| 1298 | if (err->csrow < 0) { |
| 1299 | err->err_code = ERR_CSROW; |
Mauro Carvalho Chehab | ab5a503 | 2012-04-16 15:03:50 -0300 | [diff] [blame] | 1300 | return; |
| 1301 | } |
| 1302 | |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1303 | /* CHIPKILL enabled */ |
Borislav Petkov | f192c7b | 2011-01-10 14:24:32 +0100 | [diff] [blame] | 1304 | if (pvt->nbcfg & NBCFG_CHIPKILL) { |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1305 | err->channel = get_channel_from_ecc_syndrome(mci, err->syndrome); |
| 1306 | if (err->channel < 0) { |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1307 | /* |
| 1308 | * Syndrome didn't map, so we don't know which of the |
| 1309 | * 2 DIMMs is in error. So we need to ID 'both' of them |
| 1310 | * as suspect. |
| 1311 | */ |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1312 | amd64_mc_warn(err->src_mci, "unknown syndrome 0x%04x - " |
Mauro Carvalho Chehab | ab5a503 | 2012-04-16 15:03:50 -0300 | [diff] [blame] | 1313 | "possible error reporting race\n", |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1314 | err->syndrome); |
| 1315 | err->err_code = ERR_CHANNEL; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1316 | return; |
| 1317 | } |
| 1318 | } else { |
| 1319 | /* |
| 1320 | * non-chipkill ecc mode |
| 1321 | * |
| 1322 | * The k8 documentation is unclear about how to determine the |
| 1323 | * channel number when using non-chipkill memory. This method |
| 1324 | * was obtained from email communication with someone at AMD. |
| 1325 | * (Wish the email was placed in this comment - norsk) |
| 1326 | */ |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1327 | err->channel = ((sys_addr & BIT(3)) != 0); |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1328 | } |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1329 | } |
| 1330 | |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1331 | static int ddr2_cs_size(unsigned i, bool dct_width) |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1332 | { |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1333 | unsigned shift = 0; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1334 | |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1335 | if (i <= 2) |
| 1336 | shift = i; |
| 1337 | else if (!(i & 0x1)) |
| 1338 | shift = i >> 1; |
Borislav Petkov | 1433eb9 | 2009-10-21 13:44:36 +0200 | [diff] [blame] | 1339 | else |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1340 | shift = (i + 1) >> 1; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1341 | |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1342 | return 128 << (shift + !!dct_width); |
| 1343 | } |
| 1344 | |
| 1345 | static int k8_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct, |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1346 | unsigned cs_mode, int cs_mask_nr) |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1347 | { |
| 1348 | u32 dclr = dct ? pvt->dclr1 : pvt->dclr0; |
| 1349 | |
| 1350 | if (pvt->ext_model >= K8_REV_F) { |
| 1351 | WARN_ON(cs_mode > 11); |
| 1352 | return ddr2_cs_size(cs_mode, dclr & WIDTH_128); |
| 1353 | } |
| 1354 | else if (pvt->ext_model >= K8_REV_D) { |
Borislav Petkov | 11b0a31 | 2011-11-09 21:28:43 +0100 | [diff] [blame] | 1355 | unsigned diff; |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1356 | WARN_ON(cs_mode > 10); |
| 1357 | |
Borislav Petkov | 11b0a31 | 2011-11-09 21:28:43 +0100 | [diff] [blame] | 1358 | /* |
| 1359 | * the below calculation, besides trying to win an obfuscated C |
| 1360 | * contest, maps cs_mode values to DIMM chip select sizes. The |
| 1361 | * mappings are: |
| 1362 | * |
| 1363 | * cs_mode CS size (mb) |
| 1364 | * ======= ============ |
| 1365 | * 0 32 |
| 1366 | * 1 64 |
| 1367 | * 2 128 |
| 1368 | * 3 128 |
| 1369 | * 4 256 |
| 1370 | * 5 512 |
| 1371 | * 6 256 |
| 1372 | * 7 512 |
| 1373 | * 8 1024 |
| 1374 | * 9 1024 |
| 1375 | * 10 2048 |
| 1376 | * |
| 1377 | * Basically, it calculates a value with which to shift the |
| 1378 | * smallest CS size of 32MB. |
| 1379 | * |
| 1380 | * ddr[23]_cs_size have a similar purpose. |
| 1381 | */ |
| 1382 | diff = cs_mode/3 + (unsigned)(cs_mode > 5); |
| 1383 | |
| 1384 | return 32 << (cs_mode - diff); |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1385 | } |
| 1386 | else { |
| 1387 | WARN_ON(cs_mode > 6); |
| 1388 | return 32 << cs_mode; |
| 1389 | } |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1390 | } |
| 1391 | |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1392 | /* |
| 1393 | * Get the number of DCT channels in use. |
| 1394 | * |
| 1395 | * Return: |
| 1396 | * number of Memory Channels in operation |
| 1397 | * Pass back: |
| 1398 | * contents of the DCL0_LOW register |
| 1399 | */ |
Borislav Petkov | 7d20d14 | 2011-01-07 17:58:04 +0100 | [diff] [blame] | 1400 | static int f1x_early_channel_count(struct amd64_pvt *pvt) |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1401 | { |
Borislav Petkov | 6ba5dcd | 2009-10-13 19:26:55 +0200 | [diff] [blame] | 1402 | int i, j, channels = 0; |
Doug Thompson | ddff876 | 2009-04-27 16:14:52 +0200 | [diff] [blame] | 1403 | |
Borislav Petkov | 7d20d14 | 2011-01-07 17:58:04 +0100 | [diff] [blame] | 1404 | /* On F10h, if we are in 128 bit mode, then we are using 2 channels */ |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 1405 | if (pvt->fam == 0x10 && (pvt->dclr0 & WIDTH_128)) |
Borislav Petkov | 7d20d14 | 2011-01-07 17:58:04 +0100 | [diff] [blame] | 1406 | return 2; |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1407 | |
| 1408 | /* |
Borislav Petkov | d16149e | 2009-10-16 19:55:49 +0200 | [diff] [blame] | 1409 | * Need to check if in unganged mode: In such, there are 2 channels, |
| 1410 | * but they are not in 128 bit mode and thus the above 'dclr0' status |
| 1411 | * bit will be OFF. |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1412 | * |
| 1413 | * Need to check DCT0[0] and DCT1[0] to see if only one of them has |
| 1414 | * their CSEnable bit on. If so, then SINGLE DIMM case. |
| 1415 | */ |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1416 | edac_dbg(0, "Data width is not 128 bits - need more decoding\n"); |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1417 | |
| 1418 | /* |
| 1419 | * Check DRAM Bank Address Mapping values for each DIMM to see if there |
| 1420 | * is more than just one DIMM present in unganged mode. Need to check |
| 1421 | * both controllers since DIMMs can be placed in either one. |
| 1422 | */ |
Borislav Petkov | 525a1b2 | 2010-12-21 15:53:27 +0100 | [diff] [blame] | 1423 | for (i = 0; i < 2; i++) { |
| 1424 | u32 dbam = (i ? pvt->dbam1 : pvt->dbam0); |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1425 | |
Wan Wei | 57a3085 | 2009-08-07 17:04:49 +0200 | [diff] [blame] | 1426 | for (j = 0; j < 4; j++) { |
| 1427 | if (DBAM_DIMM(j, dbam) > 0) { |
| 1428 | channels++; |
| 1429 | break; |
| 1430 | } |
| 1431 | } |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1432 | } |
| 1433 | |
Borislav Petkov | d16149e | 2009-10-16 19:55:49 +0200 | [diff] [blame] | 1434 | if (channels > 2) |
| 1435 | channels = 2; |
| 1436 | |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 1437 | amd64_info("MCT channel count: %d\n", channels); |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1438 | |
| 1439 | return channels; |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1440 | } |
| 1441 | |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 1442 | static int f17_early_channel_count(struct amd64_pvt *pvt) |
| 1443 | { |
| 1444 | int i, channels = 0; |
| 1445 | |
| 1446 | /* SDP Control bit 31 (SdpInit) is clear for unused UMC channels */ |
Yazen Ghannam | 4d30d2b | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 1447 | for_each_umc(i) |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 1448 | channels += !!(pvt->umc[i].sdp_ctrl & UMC_SDP_INIT); |
| 1449 | |
| 1450 | amd64_info("MCT channel count: %d\n", channels); |
| 1451 | |
| 1452 | return channels; |
| 1453 | } |
| 1454 | |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1455 | static int ddr3_cs_size(unsigned i, bool dct_width) |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1456 | { |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1457 | unsigned shift = 0; |
| 1458 | int cs_size = 0; |
| 1459 | |
| 1460 | if (i == 0 || i == 3 || i == 4) |
| 1461 | cs_size = -1; |
| 1462 | else if (i <= 2) |
| 1463 | shift = i; |
| 1464 | else if (i == 12) |
| 1465 | shift = 7; |
| 1466 | else if (!(i & 0x1)) |
| 1467 | shift = i >> 1; |
| 1468 | else |
| 1469 | shift = (i + 1) >> 1; |
| 1470 | |
| 1471 | if (cs_size != -1) |
| 1472 | cs_size = (128 * (1 << !!dct_width)) << shift; |
| 1473 | |
| 1474 | return cs_size; |
| 1475 | } |
| 1476 | |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1477 | static int ddr3_lrdimm_cs_size(unsigned i, unsigned rank_multiply) |
| 1478 | { |
| 1479 | unsigned shift = 0; |
| 1480 | int cs_size = 0; |
| 1481 | |
| 1482 | if (i < 4 || i == 6) |
| 1483 | cs_size = -1; |
| 1484 | else if (i == 12) |
| 1485 | shift = 7; |
| 1486 | else if (!(i & 0x1)) |
| 1487 | shift = i >> 1; |
| 1488 | else |
| 1489 | shift = (i + 1) >> 1; |
| 1490 | |
| 1491 | if (cs_size != -1) |
| 1492 | cs_size = rank_multiply * (128 << shift); |
| 1493 | |
| 1494 | return cs_size; |
| 1495 | } |
| 1496 | |
| 1497 | static int ddr4_cs_size(unsigned i) |
| 1498 | { |
| 1499 | int cs_size = 0; |
| 1500 | |
| 1501 | if (i == 0) |
| 1502 | cs_size = -1; |
| 1503 | else if (i == 1) |
| 1504 | cs_size = 1024; |
| 1505 | else |
| 1506 | /* Min cs_size = 1G */ |
| 1507 | cs_size = 1024 * (1 << (i >> 1)); |
| 1508 | |
| 1509 | return cs_size; |
| 1510 | } |
| 1511 | |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1512 | static int f10_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct, |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1513 | unsigned cs_mode, int cs_mask_nr) |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1514 | { |
| 1515 | u32 dclr = dct ? pvt->dclr1 : pvt->dclr0; |
| 1516 | |
| 1517 | WARN_ON(cs_mode > 11); |
Borislav Petkov | 1433eb9 | 2009-10-21 13:44:36 +0200 | [diff] [blame] | 1518 | |
| 1519 | if (pvt->dchr0 & DDR3_MODE || pvt->dchr1 & DDR3_MODE) |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1520 | return ddr3_cs_size(cs_mode, dclr & WIDTH_128); |
Borislav Petkov | 1433eb9 | 2009-10-21 13:44:36 +0200 | [diff] [blame] | 1521 | else |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1522 | return ddr2_cs_size(cs_mode, dclr & WIDTH_128); |
| 1523 | } |
Borislav Petkov | 1433eb9 | 2009-10-21 13:44:36 +0200 | [diff] [blame] | 1524 | |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1525 | /* |
| 1526 | * F15h supports only 64bit DCT interfaces |
| 1527 | */ |
| 1528 | static int f15_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct, |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1529 | unsigned cs_mode, int cs_mask_nr) |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 1530 | { |
| 1531 | WARN_ON(cs_mode > 12); |
| 1532 | |
| 1533 | return ddr3_cs_size(cs_mode, false); |
Doug Thompson | 1afd3c9 | 2009-04-27 16:16:50 +0200 | [diff] [blame] | 1534 | } |
| 1535 | |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1536 | /* F15h M60h supports DDR4 mapping as well.. */ |
| 1537 | static int f15_m60h_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct, |
| 1538 | unsigned cs_mode, int cs_mask_nr) |
| 1539 | { |
| 1540 | int cs_size; |
| 1541 | u32 dcsm = pvt->csels[dct].csmasks[cs_mask_nr]; |
| 1542 | |
| 1543 | WARN_ON(cs_mode > 12); |
| 1544 | |
| 1545 | if (pvt->dram_type == MEM_DDR4) { |
| 1546 | if (cs_mode > 9) |
| 1547 | return -1; |
| 1548 | |
| 1549 | cs_size = ddr4_cs_size(cs_mode); |
| 1550 | } else if (pvt->dram_type == MEM_LRDDR3) { |
| 1551 | unsigned rank_multiply = dcsm & 0xf; |
| 1552 | |
| 1553 | if (rank_multiply == 3) |
| 1554 | rank_multiply = 4; |
| 1555 | cs_size = ddr3_lrdimm_cs_size(cs_mode, rank_multiply); |
| 1556 | } else { |
| 1557 | /* Minimum cs size is 512mb for F15hM60h*/ |
| 1558 | if (cs_mode == 0x1) |
| 1559 | return -1; |
| 1560 | |
| 1561 | cs_size = ddr3_cs_size(cs_mode, false); |
| 1562 | } |
| 1563 | |
| 1564 | return cs_size; |
| 1565 | } |
| 1566 | |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 1567 | /* |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 1568 | * F16h and F15h model 30h have only limited cs_modes. |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 1569 | */ |
| 1570 | static int f16_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct, |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 1571 | unsigned cs_mode, int cs_mask_nr) |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 1572 | { |
| 1573 | WARN_ON(cs_mode > 12); |
| 1574 | |
| 1575 | if (cs_mode == 6 || cs_mode == 8 || |
| 1576 | cs_mode == 9 || cs_mode == 12) |
| 1577 | return -1; |
| 1578 | else |
| 1579 | return ddr3_cs_size(cs_mode, false); |
| 1580 | } |
| 1581 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 1582 | static int f17_addr_mask_to_cs_size(struct amd64_pvt *pvt, u8 umc, |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 1583 | unsigned int cs_mode, int csrow_nr) |
| 1584 | { |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 1585 | u32 addr_mask_orig, addr_mask_deinterleaved; |
| 1586 | u32 msb, weight, num_zero_bits; |
| 1587 | int dimm, size = 0; |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 1588 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 1589 | /* No Chip Selects are enabled. */ |
| 1590 | if (!cs_mode) |
| 1591 | return size; |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 1592 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 1593 | /* Requested size of an even CS but none are enabled. */ |
| 1594 | if (!(cs_mode & CS_EVEN) && !(csrow_nr & 1)) |
| 1595 | return size; |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 1596 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 1597 | /* Requested size of an odd CS but none are enabled. */ |
| 1598 | if (!(cs_mode & CS_ODD) && (csrow_nr & 1)) |
| 1599 | return size; |
| 1600 | |
| 1601 | /* |
| 1602 | * There is one mask per DIMM, and two Chip Selects per DIMM. |
| 1603 | * CS0 and CS1 -> DIMM0 |
| 1604 | * CS2 and CS3 -> DIMM1 |
| 1605 | */ |
| 1606 | dimm = csrow_nr >> 1; |
| 1607 | |
Yazen Ghannam | 81f5090 | 2019-08-22 00:00:02 +0000 | [diff] [blame] | 1608 | /* Asymmetric dual-rank DIMM support. */ |
| 1609 | if ((csrow_nr & 1) && (cs_mode & CS_ODD_SECONDARY)) |
| 1610 | addr_mask_orig = pvt->csels[umc].csmasks_sec[dimm]; |
| 1611 | else |
| 1612 | addr_mask_orig = pvt->csels[umc].csmasks[dimm]; |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 1613 | |
| 1614 | /* |
| 1615 | * The number of zero bits in the mask is equal to the number of bits |
| 1616 | * in a full mask minus the number of bits in the current mask. |
| 1617 | * |
| 1618 | * The MSB is the number of bits in the full mask because BIT[0] is |
| 1619 | * always 0. |
| 1620 | */ |
| 1621 | msb = fls(addr_mask_orig) - 1; |
| 1622 | weight = hweight_long(addr_mask_orig); |
| 1623 | num_zero_bits = msb - weight; |
| 1624 | |
| 1625 | /* Take the number of zero bits off from the top of the mask. */ |
| 1626 | addr_mask_deinterleaved = GENMASK_ULL(msb - num_zero_bits, 1); |
| 1627 | |
| 1628 | edac_dbg(1, "CS%d DIMM%d AddrMasks:\n", csrow_nr, dimm); |
| 1629 | edac_dbg(1, " Original AddrMask: 0x%x\n", addr_mask_orig); |
| 1630 | edac_dbg(1, " Deinterleaved AddrMask: 0x%x\n", addr_mask_deinterleaved); |
| 1631 | |
| 1632 | /* Register [31:1] = Address [39:9]. Size is in kBs here. */ |
| 1633 | size = (addr_mask_deinterleaved >> 2) + 1; |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 1634 | |
| 1635 | /* Return size in MBs. */ |
| 1636 | return size >> 10; |
| 1637 | } |
| 1638 | |
Borislav Petkov | 5a5d237 | 2011-01-17 17:52:57 +0100 | [diff] [blame] | 1639 | static void read_dram_ctl_register(struct amd64_pvt *pvt) |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1640 | { |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1641 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 1642 | if (pvt->fam == 0xf) |
Borislav Petkov | 5a5d237 | 2011-01-17 17:52:57 +0100 | [diff] [blame] | 1643 | return; |
| 1644 | |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 1645 | if (!amd64_read_pci_cfg(pvt->F2, DCT_SEL_LO, &pvt->dct_sel_lo)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1646 | edac_dbg(0, "F2x110 (DCTSelLow): 0x%08x, High range addrs at: 0x%x\n", |
| 1647 | pvt->dct_sel_lo, dct_sel_baseaddr(pvt)); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1648 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1649 | edac_dbg(0, " DCTs operate in %s mode\n", |
| 1650 | (dct_ganging_enabled(pvt) ? "ganged" : "unganged")); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1651 | |
Borislav Petkov | 72381bd | 2009-10-09 19:14:43 +0200 | [diff] [blame] | 1652 | if (!dct_ganging_enabled(pvt)) |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1653 | edac_dbg(0, " Address range split per DCT: %s\n", |
| 1654 | (dct_high_range_enabled(pvt) ? "yes" : "no")); |
Borislav Petkov | 72381bd | 2009-10-09 19:14:43 +0200 | [diff] [blame] | 1655 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1656 | edac_dbg(0, " data interleave for ECC: %s, DRAM cleared since last warm reset: %s\n", |
| 1657 | (dct_data_intlv_enabled(pvt) ? "enabled" : "disabled"), |
| 1658 | (dct_memory_cleared(pvt) ? "yes" : "no")); |
Borislav Petkov | 72381bd | 2009-10-09 19:14:43 +0200 | [diff] [blame] | 1659 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1660 | edac_dbg(0, " channel interleave: %s, " |
| 1661 | "interleave bits selector: 0x%x\n", |
| 1662 | (dct_interleave_enabled(pvt) ? "enabled" : "disabled"), |
| 1663 | dct_sel_interleave_addr(pvt)); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1664 | } |
| 1665 | |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 1666 | amd64_read_pci_cfg(pvt->F2, DCT_SEL_HI, &pvt->dct_sel_hi); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1667 | } |
| 1668 | |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1669 | /* |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 1670 | * Determine channel (DCT) based on the interleaving mode (see F15h M30h BKDG, |
| 1671 | * 2.10.12 Memory Interleaving Modes). |
| 1672 | */ |
| 1673 | static u8 f15_m30h_determine_channel(struct amd64_pvt *pvt, u64 sys_addr, |
| 1674 | u8 intlv_en, int num_dcts_intlv, |
| 1675 | u32 dct_sel) |
| 1676 | { |
| 1677 | u8 channel = 0; |
| 1678 | u8 select; |
| 1679 | |
| 1680 | if (!(intlv_en)) |
| 1681 | return (u8)(dct_sel); |
| 1682 | |
| 1683 | if (num_dcts_intlv == 2) { |
| 1684 | select = (sys_addr >> 8) & 0x3; |
| 1685 | channel = select ? 0x3 : 0; |
Aravind Gopalakrishnan | 9d0e8d8 | 2014-01-21 15:03:36 -0600 | [diff] [blame] | 1686 | } else if (num_dcts_intlv == 4) { |
| 1687 | u8 intlv_addr = dct_sel_interleave_addr(pvt); |
| 1688 | switch (intlv_addr) { |
| 1689 | case 0x4: |
| 1690 | channel = (sys_addr >> 8) & 0x3; |
| 1691 | break; |
| 1692 | case 0x5: |
| 1693 | channel = (sys_addr >> 9) & 0x3; |
| 1694 | break; |
| 1695 | } |
| 1696 | } |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 1697 | return channel; |
| 1698 | } |
| 1699 | |
| 1700 | /* |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1701 | * Determine channel (DCT) based on the interleaving mode: F10h BKDG, 2.8.9 Memory |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1702 | * Interleaving Modes. |
| 1703 | */ |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 1704 | static u8 f1x_determine_channel(struct amd64_pvt *pvt, u64 sys_addr, |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1705 | bool hi_range_sel, u8 intlv_en) |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1706 | { |
Borislav Petkov | 151fa71 | 2011-02-21 19:33:10 +0100 | [diff] [blame] | 1707 | u8 dct_sel_high = (pvt->dct_sel_lo >> 1) & 1; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1708 | |
| 1709 | if (dct_ganging_enabled(pvt)) |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1710 | return 0; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1711 | |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1712 | if (hi_range_sel) |
| 1713 | return dct_sel_high; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1714 | |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1715 | /* |
| 1716 | * see F2x110[DctSelIntLvAddr] - channel interleave mode |
| 1717 | */ |
| 1718 | if (dct_interleave_enabled(pvt)) { |
| 1719 | u8 intlv_addr = dct_sel_interleave_addr(pvt); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1720 | |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1721 | /* return DCT select function: 0=DCT0, 1=DCT1 */ |
| 1722 | if (!intlv_addr) |
| 1723 | return sys_addr >> 6 & 1; |
| 1724 | |
| 1725 | if (intlv_addr & 0x2) { |
| 1726 | u8 shift = intlv_addr & 0x1 ? 9 : 6; |
Yazen Ghannam | dc0a50a8 | 2016-08-03 10:59:15 -0400 | [diff] [blame] | 1727 | u32 temp = hweight_long((u32) ((sys_addr >> 16) & 0x1F)) & 1; |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1728 | |
| 1729 | return ((sys_addr >> shift) & 1) ^ temp; |
| 1730 | } |
| 1731 | |
Yazen Ghannam | dc0a50a8 | 2016-08-03 10:59:15 -0400 | [diff] [blame] | 1732 | if (intlv_addr & 0x4) { |
| 1733 | u8 shift = intlv_addr & 0x1 ? 9 : 8; |
| 1734 | |
| 1735 | return (sys_addr >> shift) & 1; |
| 1736 | } |
| 1737 | |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1738 | return (sys_addr >> (12 + hweight8(intlv_en))) & 1; |
| 1739 | } |
| 1740 | |
| 1741 | if (dct_high_range_enabled(pvt)) |
| 1742 | return ~dct_sel_high & 1; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1743 | |
| 1744 | return 0; |
| 1745 | } |
| 1746 | |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 1747 | /* Convert the sys_addr to the normalized DCT address */ |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 1748 | static u64 f1x_get_norm_dct_addr(struct amd64_pvt *pvt, u8 range, |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 1749 | u64 sys_addr, bool hi_rng, |
| 1750 | u32 dct_sel_base_addr) |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1751 | { |
| 1752 | u64 chan_off; |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 1753 | u64 dram_base = get_dram_base(pvt, range); |
| 1754 | u64 hole_off = f10_dhar_offset(pvt); |
Dan Carpenter | 6f3508f | 2016-01-20 12:54:51 +0300 | [diff] [blame] | 1755 | u64 dct_sel_base_off = (u64)(pvt->dct_sel_hi & 0xFFFFFC00) << 16; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1756 | |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 1757 | if (hi_rng) { |
| 1758 | /* |
| 1759 | * if |
| 1760 | * base address of high range is below 4Gb |
| 1761 | * (bits [47:27] at [31:11]) |
| 1762 | * DRAM address space on this DCT is hoisted above 4Gb && |
| 1763 | * sys_addr > 4Gb |
| 1764 | * |
| 1765 | * remove hole offset from sys_addr |
| 1766 | * else |
| 1767 | * remove high range offset from sys_addr |
| 1768 | */ |
| 1769 | if ((!(dct_sel_base_addr >> 16) || |
| 1770 | dct_sel_base_addr < dhar_base(pvt)) && |
Borislav Petkov | 972ea17 | 2011-02-21 19:43:02 +0100 | [diff] [blame] | 1771 | dhar_valid(pvt) && |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 1772 | (sys_addr >= BIT_64(32))) |
Borislav Petkov | bc21fa5 | 2010-11-11 17:29:13 +0100 | [diff] [blame] | 1773 | chan_off = hole_off; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1774 | else |
| 1775 | chan_off = dct_sel_base_off; |
| 1776 | } else { |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 1777 | /* |
| 1778 | * if |
| 1779 | * we have a valid hole && |
| 1780 | * sys_addr > 4Gb |
| 1781 | * |
| 1782 | * remove hole |
| 1783 | * else |
| 1784 | * remove dram base to normalize to DCT address |
| 1785 | */ |
Borislav Petkov | 972ea17 | 2011-02-21 19:43:02 +0100 | [diff] [blame] | 1786 | if (dhar_valid(pvt) && (sys_addr >= BIT_64(32))) |
Borislav Petkov | bc21fa5 | 2010-11-11 17:29:13 +0100 | [diff] [blame] | 1787 | chan_off = hole_off; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1788 | else |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 1789 | chan_off = dram_base; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1790 | } |
| 1791 | |
Chen, Gong | 10ef6b0 | 2013-10-18 14:29:07 -0700 | [diff] [blame] | 1792 | return (sys_addr & GENMASK_ULL(47,6)) - (chan_off & GENMASK_ULL(47,23)); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1793 | } |
| 1794 | |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1795 | /* |
| 1796 | * checks if the csrow passed in is marked as SPARED, if so returns the new |
| 1797 | * spare row |
| 1798 | */ |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1799 | static int f10_process_possible_spare(struct amd64_pvt *pvt, u8 dct, int csrow) |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1800 | { |
Borislav Petkov | 614ec9d | 2011-01-13 18:02:22 +0100 | [diff] [blame] | 1801 | int tmp_cs; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1802 | |
Borislav Petkov | 614ec9d | 2011-01-13 18:02:22 +0100 | [diff] [blame] | 1803 | if (online_spare_swap_done(pvt, dct) && |
| 1804 | csrow == online_spare_bad_dramcs(pvt, dct)) { |
| 1805 | |
| 1806 | for_each_chip_select(tmp_cs, dct, pvt) { |
| 1807 | if (chip_select_base(tmp_cs, dct, pvt) & 0x2) { |
| 1808 | csrow = tmp_cs; |
| 1809 | break; |
| 1810 | } |
| 1811 | } |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1812 | } |
| 1813 | return csrow; |
| 1814 | } |
| 1815 | |
| 1816 | /* |
| 1817 | * Iterate over the DRAM DCT "base" and "mask" registers looking for a |
| 1818 | * SystemAddr match on the specified 'ChannelSelect' and 'NodeID' |
| 1819 | * |
| 1820 | * Return: |
| 1821 | * -EINVAL: NOT FOUND |
| 1822 | * 0..csrow = Chip-Select Row |
| 1823 | */ |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 1824 | static int f1x_lookup_addr_in_dct(u64 in_addr, u8 nid, u8 dct) |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1825 | { |
| 1826 | struct mem_ctl_info *mci; |
| 1827 | struct amd64_pvt *pvt; |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1828 | u64 cs_base, cs_mask; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1829 | int cs_found = -EINVAL; |
| 1830 | int csrow; |
| 1831 | |
Borislav Petkov | 2ec591a | 2015-02-17 10:58:34 +0100 | [diff] [blame] | 1832 | mci = edac_mc_find(nid); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1833 | if (!mci) |
| 1834 | return cs_found; |
| 1835 | |
| 1836 | pvt = mci->pvt_info; |
| 1837 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1838 | edac_dbg(1, "input addr: 0x%llx, DCT: %d\n", in_addr, dct); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1839 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1840 | for_each_chip_select(csrow, dct, pvt) { |
| 1841 | if (!csrow_enabled(csrow, dct, pvt)) |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1842 | continue; |
| 1843 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1844 | get_cs_base_and_mask(pvt, csrow, dct, &cs_base, &cs_mask); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1845 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1846 | edac_dbg(1, " CSROW=%d CSBase=0x%llx CSMask=0x%llx\n", |
| 1847 | csrow, cs_base, cs_mask); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1848 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1849 | cs_mask = ~cs_mask; |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1850 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1851 | edac_dbg(1, " (InputAddr & ~CSMask)=0x%llx (CSBase & ~CSMask)=0x%llx\n", |
| 1852 | (in_addr & cs_mask), (cs_base & cs_mask)); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1853 | |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1854 | if ((in_addr & cs_mask) == (cs_base & cs_mask)) { |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 1855 | if (pvt->fam == 0x15 && pvt->model >= 0x30) { |
| 1856 | cs_found = csrow; |
| 1857 | break; |
| 1858 | } |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1859 | cs_found = f10_process_possible_spare(pvt, dct, csrow); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1860 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1861 | edac_dbg(1, " MATCH csrow=%d\n", cs_found); |
Doug Thompson | 6163b5d | 2009-04-27 16:20:17 +0200 | [diff] [blame] | 1862 | break; |
| 1863 | } |
| 1864 | } |
| 1865 | return cs_found; |
| 1866 | } |
| 1867 | |
Borislav Petkov | 95b0ef5 | 2011-01-11 22:08:07 +0100 | [diff] [blame] | 1868 | /* |
| 1869 | * See F2x10C. Non-interleaved graphics framebuffer memory under the 16G is |
| 1870 | * swapped with a region located at the bottom of memory so that the GPU can use |
| 1871 | * the interleaved region and thus two channels. |
| 1872 | */ |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 1873 | static u64 f1x_swap_interleaved_region(struct amd64_pvt *pvt, u64 sys_addr) |
Borislav Petkov | 95b0ef5 | 2011-01-11 22:08:07 +0100 | [diff] [blame] | 1874 | { |
| 1875 | u32 swap_reg, swap_base, swap_limit, rgn_size, tmp_addr; |
| 1876 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 1877 | if (pvt->fam == 0x10) { |
Borislav Petkov | 95b0ef5 | 2011-01-11 22:08:07 +0100 | [diff] [blame] | 1878 | /* only revC3 and revE have that feature */ |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 1879 | if (pvt->model < 4 || (pvt->model < 0xa && pvt->stepping < 3)) |
Borislav Petkov | 95b0ef5 | 2011-01-11 22:08:07 +0100 | [diff] [blame] | 1880 | return sys_addr; |
| 1881 | } |
| 1882 | |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 1883 | amd64_read_pci_cfg(pvt->F2, SWAP_INTLV_REG, &swap_reg); |
Borislav Petkov | 95b0ef5 | 2011-01-11 22:08:07 +0100 | [diff] [blame] | 1884 | |
| 1885 | if (!(swap_reg & 0x1)) |
| 1886 | return sys_addr; |
| 1887 | |
| 1888 | swap_base = (swap_reg >> 3) & 0x7f; |
| 1889 | swap_limit = (swap_reg >> 11) & 0x7f; |
| 1890 | rgn_size = (swap_reg >> 20) & 0x7f; |
| 1891 | tmp_addr = sys_addr >> 27; |
| 1892 | |
| 1893 | if (!(sys_addr >> 34) && |
| 1894 | (((tmp_addr >= swap_base) && |
| 1895 | (tmp_addr <= swap_limit)) || |
| 1896 | (tmp_addr < rgn_size))) |
| 1897 | return sys_addr ^ (u64)swap_base << 27; |
| 1898 | |
| 1899 | return sys_addr; |
| 1900 | } |
| 1901 | |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1902 | /* For a given @dram_range, check if @sys_addr falls within it. */ |
Borislav Petkov | e761359a | 2011-02-21 19:49:01 +0100 | [diff] [blame] | 1903 | static int f1x_match_to_this_node(struct amd64_pvt *pvt, unsigned range, |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1904 | u64 sys_addr, int *chan_sel) |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1905 | { |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1906 | int cs_found = -EINVAL; |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 1907 | u64 chan_addr; |
Borislav Petkov | 5d4b58e | 2011-01-13 16:01:13 +0100 | [diff] [blame] | 1908 | u32 dct_sel_base; |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 1909 | u8 channel; |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1910 | bool high_range = false; |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1911 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 1912 | u8 node_id = dram_dst_node(pvt, range); |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1913 | u8 intlv_en = dram_intlv_en(pvt, range); |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 1914 | u32 intlv_sel = dram_intlv_sel(pvt, range); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1915 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1916 | edac_dbg(1, "(range %d) SystemAddr= 0x%llx Limit=0x%llx\n", |
| 1917 | range, sys_addr, get_dram_limit(pvt, range)); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1918 | |
Borislav Petkov | 355fba6 | 2011-01-17 13:03:26 +0100 | [diff] [blame] | 1919 | if (dhar_valid(pvt) && |
| 1920 | dhar_base(pvt) <= sys_addr && |
| 1921 | sys_addr < BIT_64(32)) { |
| 1922 | amd64_warn("Huh? Address is in the MMIO hole: 0x%016llx\n", |
| 1923 | sys_addr); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1924 | return -EINVAL; |
Borislav Petkov | 355fba6 | 2011-01-17 13:03:26 +0100 | [diff] [blame] | 1925 | } |
| 1926 | |
Borislav Petkov | f030ddf | 2011-04-08 15:05:21 +0200 | [diff] [blame] | 1927 | if (intlv_en && (intlv_sel != ((sys_addr >> 12) & intlv_en))) |
Borislav Petkov | 355fba6 | 2011-01-17 13:03:26 +0100 | [diff] [blame] | 1928 | return -EINVAL; |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1929 | |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 1930 | sys_addr = f1x_swap_interleaved_region(pvt, sys_addr); |
Borislav Petkov | 95b0ef5 | 2011-01-11 22:08:07 +0100 | [diff] [blame] | 1931 | |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1932 | dct_sel_base = dct_sel_baseaddr(pvt); |
| 1933 | |
| 1934 | /* |
| 1935 | * check whether addresses >= DctSelBaseAddr[47:27] are to be used to |
| 1936 | * select between DCT0 and DCT1. |
| 1937 | */ |
| 1938 | if (dct_high_range_enabled(pvt) && |
| 1939 | !dct_ganging_enabled(pvt) && |
| 1940 | ((sys_addr >> 27) >= (dct_sel_base >> 11))) |
Borislav Petkov | 229a7a1 | 2010-12-09 18:57:54 +0100 | [diff] [blame] | 1941 | high_range = true; |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1942 | |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 1943 | channel = f1x_determine_channel(pvt, sys_addr, high_range, intlv_en); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1944 | |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 1945 | chan_addr = f1x_get_norm_dct_addr(pvt, range, sys_addr, |
Borislav Petkov | c8e518d | 2010-12-10 19:49:19 +0100 | [diff] [blame] | 1946 | high_range, dct_sel_base); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1947 | |
Borislav Petkov | e2f79db | 2011-01-13 14:57:34 +0100 | [diff] [blame] | 1948 | /* Remove node interleaving, see F1x120 */ |
| 1949 | if (intlv_en) |
| 1950 | chan_addr = ((chan_addr >> (12 + hweight8(intlv_en))) << 12) | |
| 1951 | (chan_addr & 0xfff); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1952 | |
Borislav Petkov | 5d4b58e | 2011-01-13 16:01:13 +0100 | [diff] [blame] | 1953 | /* remove channel interleave */ |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1954 | if (dct_interleave_enabled(pvt) && |
| 1955 | !dct_high_range_enabled(pvt) && |
| 1956 | !dct_ganging_enabled(pvt)) { |
Borislav Petkov | 5d4b58e | 2011-01-13 16:01:13 +0100 | [diff] [blame] | 1957 | |
| 1958 | if (dct_sel_interleave_addr(pvt) != 1) { |
| 1959 | if (dct_sel_interleave_addr(pvt) == 0x3) |
| 1960 | /* hash 9 */ |
| 1961 | chan_addr = ((chan_addr >> 10) << 9) | |
| 1962 | (chan_addr & 0x1ff); |
| 1963 | else |
| 1964 | /* A[6] or hash 6 */ |
| 1965 | chan_addr = ((chan_addr >> 7) << 6) | |
| 1966 | (chan_addr & 0x3f); |
| 1967 | } else |
| 1968 | /* A[12] */ |
| 1969 | chan_addr = ((chan_addr >> 13) << 12) | |
| 1970 | (chan_addr & 0xfff); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1971 | } |
| 1972 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 1973 | edac_dbg(1, " Normalized DCT addr: 0x%llx\n", chan_addr); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1974 | |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 1975 | cs_found = f1x_lookup_addr_in_dct(chan_addr, node_id, channel); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1976 | |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1977 | if (cs_found >= 0) |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1978 | *chan_sel = channel; |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 1979 | |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 1980 | return cs_found; |
| 1981 | } |
| 1982 | |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 1983 | static int f15_m30h_match_to_this_node(struct amd64_pvt *pvt, unsigned range, |
| 1984 | u64 sys_addr, int *chan_sel) |
| 1985 | { |
| 1986 | int cs_found = -EINVAL; |
| 1987 | int num_dcts_intlv = 0; |
| 1988 | u64 chan_addr, chan_offset; |
| 1989 | u64 dct_base, dct_limit; |
| 1990 | u32 dct_cont_base_reg, dct_cont_limit_reg, tmp; |
| 1991 | u8 channel, alias_channel, leg_mmio_hole, dct_sel, dct_offset_en; |
| 1992 | |
| 1993 | u64 dhar_offset = f10_dhar_offset(pvt); |
| 1994 | u8 intlv_addr = dct_sel_interleave_addr(pvt); |
| 1995 | u8 node_id = dram_dst_node(pvt, range); |
| 1996 | u8 intlv_en = dram_intlv_en(pvt, range); |
| 1997 | |
| 1998 | amd64_read_pci_cfg(pvt->F1, DRAM_CONT_BASE, &dct_cont_base_reg); |
| 1999 | amd64_read_pci_cfg(pvt->F1, DRAM_CONT_LIMIT, &dct_cont_limit_reg); |
| 2000 | |
| 2001 | dct_offset_en = (u8) ((dct_cont_base_reg >> 3) & BIT(0)); |
| 2002 | dct_sel = (u8) ((dct_cont_base_reg >> 4) & 0x7); |
| 2003 | |
| 2004 | edac_dbg(1, "(range %d) SystemAddr= 0x%llx Limit=0x%llx\n", |
| 2005 | range, sys_addr, get_dram_limit(pvt, range)); |
| 2006 | |
| 2007 | if (!(get_dram_base(pvt, range) <= sys_addr) && |
| 2008 | !(get_dram_limit(pvt, range) >= sys_addr)) |
| 2009 | return -EINVAL; |
| 2010 | |
| 2011 | if (dhar_valid(pvt) && |
| 2012 | dhar_base(pvt) <= sys_addr && |
| 2013 | sys_addr < BIT_64(32)) { |
| 2014 | amd64_warn("Huh? Address is in the MMIO hole: 0x%016llx\n", |
| 2015 | sys_addr); |
| 2016 | return -EINVAL; |
| 2017 | } |
| 2018 | |
| 2019 | /* Verify sys_addr is within DCT Range. */ |
Aravind Gopalakrishnan | 4fc06b3 | 2013-08-24 10:47:48 -0500 | [diff] [blame] | 2020 | dct_base = (u64) dct_sel_baseaddr(pvt); |
| 2021 | dct_limit = (dct_cont_limit_reg >> 11) & 0x1FFF; |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2022 | |
| 2023 | if (!(dct_cont_base_reg & BIT(0)) && |
Aravind Gopalakrishnan | 4fc06b3 | 2013-08-24 10:47:48 -0500 | [diff] [blame] | 2024 | !(dct_base <= (sys_addr >> 27) && |
| 2025 | dct_limit >= (sys_addr >> 27))) |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2026 | return -EINVAL; |
| 2027 | |
| 2028 | /* Verify number of dct's that participate in channel interleaving. */ |
| 2029 | num_dcts_intlv = (int) hweight8(intlv_en); |
| 2030 | |
| 2031 | if (!(num_dcts_intlv % 2 == 0) || (num_dcts_intlv > 4)) |
| 2032 | return -EINVAL; |
| 2033 | |
Yazen Ghannam | dc0a50a8 | 2016-08-03 10:59:15 -0400 | [diff] [blame] | 2034 | if (pvt->model >= 0x60) |
| 2035 | channel = f1x_determine_channel(pvt, sys_addr, false, intlv_en); |
| 2036 | else |
| 2037 | channel = f15_m30h_determine_channel(pvt, sys_addr, intlv_en, |
| 2038 | num_dcts_intlv, dct_sel); |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2039 | |
| 2040 | /* Verify we stay within the MAX number of channels allowed */ |
Aravind Gopalakrishnan | 7f3f524 | 2013-12-04 11:40:11 -0600 | [diff] [blame] | 2041 | if (channel > 3) |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2042 | return -EINVAL; |
| 2043 | |
| 2044 | leg_mmio_hole = (u8) (dct_cont_base_reg >> 1 & BIT(0)); |
| 2045 | |
| 2046 | /* Get normalized DCT addr */ |
| 2047 | if (leg_mmio_hole && (sys_addr >= BIT_64(32))) |
| 2048 | chan_offset = dhar_offset; |
| 2049 | else |
Aravind Gopalakrishnan | 4fc06b3 | 2013-08-24 10:47:48 -0500 | [diff] [blame] | 2050 | chan_offset = dct_base << 27; |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2051 | |
| 2052 | chan_addr = sys_addr - chan_offset; |
| 2053 | |
| 2054 | /* remove channel interleave */ |
| 2055 | if (num_dcts_intlv == 2) { |
| 2056 | if (intlv_addr == 0x4) |
| 2057 | chan_addr = ((chan_addr >> 9) << 8) | |
| 2058 | (chan_addr & 0xff); |
| 2059 | else if (intlv_addr == 0x5) |
| 2060 | chan_addr = ((chan_addr >> 10) << 9) | |
| 2061 | (chan_addr & 0x1ff); |
| 2062 | else |
| 2063 | return -EINVAL; |
| 2064 | |
| 2065 | } else if (num_dcts_intlv == 4) { |
| 2066 | if (intlv_addr == 0x4) |
| 2067 | chan_addr = ((chan_addr >> 10) << 8) | |
| 2068 | (chan_addr & 0xff); |
| 2069 | else if (intlv_addr == 0x5) |
| 2070 | chan_addr = ((chan_addr >> 11) << 9) | |
| 2071 | (chan_addr & 0x1ff); |
| 2072 | else |
| 2073 | return -EINVAL; |
| 2074 | } |
| 2075 | |
| 2076 | if (dct_offset_en) { |
| 2077 | amd64_read_pci_cfg(pvt->F1, |
| 2078 | DRAM_CONT_HIGH_OFF + (int) channel * 4, |
| 2079 | &tmp); |
Aravind Gopalakrishnan | 4fc06b3 | 2013-08-24 10:47:48 -0500 | [diff] [blame] | 2080 | chan_addr += (u64) ((tmp >> 11) & 0xfff) << 27; |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | f15h_select_dct(pvt, channel); |
| 2084 | |
| 2085 | edac_dbg(1, " Normalized DCT addr: 0x%llx\n", chan_addr); |
| 2086 | |
| 2087 | /* |
| 2088 | * Find Chip select: |
| 2089 | * if channel = 3, then alias it to 1. This is because, in F15 M30h, |
| 2090 | * there is support for 4 DCT's, but only 2 are currently functional. |
| 2091 | * They are DCT0 and DCT3. But we have read all registers of DCT3 into |
| 2092 | * pvt->csels[1]. So we need to use '1' here to get correct info. |
| 2093 | * Refer F15 M30h BKDG Section 2.10 and 2.10.3 for clarifications. |
| 2094 | */ |
| 2095 | alias_channel = (channel == 3) ? 1 : channel; |
| 2096 | |
| 2097 | cs_found = f1x_lookup_addr_in_dct(chan_addr, node_id, alias_channel); |
| 2098 | |
| 2099 | if (cs_found >= 0) |
| 2100 | *chan_sel = alias_channel; |
| 2101 | |
| 2102 | return cs_found; |
| 2103 | } |
| 2104 | |
| 2105 | static int f1x_translate_sysaddr_to_cs(struct amd64_pvt *pvt, |
| 2106 | u64 sys_addr, |
| 2107 | int *chan_sel) |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2108 | { |
Borislav Petkov | e761359a | 2011-02-21 19:49:01 +0100 | [diff] [blame] | 2109 | int cs_found = -EINVAL; |
| 2110 | unsigned range; |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2111 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 2112 | for (range = 0; range < DRAM_RANGES; range++) { |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 2113 | if (!dram_rw(pvt, range)) |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2114 | continue; |
| 2115 | |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2116 | if (pvt->fam == 0x15 && pvt->model >= 0x30) |
| 2117 | cs_found = f15_m30h_match_to_this_node(pvt, range, |
| 2118 | sys_addr, |
| 2119 | chan_sel); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2120 | |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2121 | else if ((get_dram_base(pvt, range) <= sys_addr) && |
| 2122 | (get_dram_limit(pvt, range) >= sys_addr)) { |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 2123 | cs_found = f1x_match_to_this_node(pvt, range, |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2124 | sys_addr, chan_sel); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2125 | if (cs_found >= 0) |
| 2126 | break; |
| 2127 | } |
| 2128 | } |
| 2129 | return cs_found; |
| 2130 | } |
| 2131 | |
| 2132 | /* |
Borislav Petkov | bdc30a0 | 2009-11-13 15:10:43 +0100 | [diff] [blame] | 2133 | * For reference see "2.8.5 Routing DRAM Requests" in F10 BKDG. This code maps |
| 2134 | * a @sys_addr to NodeID, DCT (channel) and chip select (CSROW). |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2135 | * |
Borislav Petkov | bdc30a0 | 2009-11-13 15:10:43 +0100 | [diff] [blame] | 2136 | * The @sys_addr is usually an error address received from the hardware |
| 2137 | * (MCX_ADDR). |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2138 | */ |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 2139 | static void f1x_map_sysaddr_to_csrow(struct mem_ctl_info *mci, u64 sys_addr, |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2140 | struct err_info *err) |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2141 | { |
| 2142 | struct amd64_pvt *pvt = mci->pvt_info; |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2143 | |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2144 | error_address_to_page_and_offset(sys_addr, err); |
Mauro Carvalho Chehab | ab5a503 | 2012-04-16 15:03:50 -0300 | [diff] [blame] | 2145 | |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2146 | err->csrow = f1x_translate_sysaddr_to_cs(pvt, sys_addr, &err->channel); |
| 2147 | if (err->csrow < 0) { |
| 2148 | err->err_code = ERR_CSROW; |
Borislav Petkov | bdc30a0 | 2009-11-13 15:10:43 +0100 | [diff] [blame] | 2149 | return; |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2150 | } |
Borislav Petkov | bdc30a0 | 2009-11-13 15:10:43 +0100 | [diff] [blame] | 2151 | |
Borislav Petkov | bdc30a0 | 2009-11-13 15:10:43 +0100 | [diff] [blame] | 2152 | /* |
| 2153 | * We need the syndromes for channel detection only when we're |
| 2154 | * ganged. Otherwise @chan should already contain the channel at |
| 2155 | * this point. |
| 2156 | */ |
Borislav Petkov | a97fa68 | 2010-12-23 14:07:18 +0100 | [diff] [blame] | 2157 | if (dct_ganging_enabled(pvt)) |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2158 | err->channel = get_channel_from_ecc_syndrome(mci, err->syndrome); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | /* |
Borislav Petkov | 8566c4d | 2009-10-16 13:48:28 +0200 | [diff] [blame] | 2162 | * debug routine to display the memory sizes of all logical DIMMs and its |
Borislav Petkov | cb32850 | 2010-12-22 14:28:24 +0100 | [diff] [blame] | 2163 | * CSROWs |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2164 | */ |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 2165 | static void debug_display_dimm_sizes(struct amd64_pvt *pvt, u8 ctrl) |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2166 | { |
Borislav Petkov | bb89f5a | 2012-09-12 18:06:00 +0200 | [diff] [blame] | 2167 | int dimm, size0, size1; |
Borislav Petkov | 525a1b2 | 2010-12-21 15:53:27 +0100 | [diff] [blame] | 2168 | u32 *dcsb = ctrl ? pvt->csels[1].csbases : pvt->csels[0].csbases; |
| 2169 | u32 dbam = ctrl ? pvt->dbam1 : pvt->dbam0; |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2170 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 2171 | if (pvt->fam == 0xf) { |
Borislav Petkov | 8566c4d | 2009-10-16 13:48:28 +0200 | [diff] [blame] | 2172 | /* K8 families < revF not supported yet */ |
Borislav Petkov | 1433eb9 | 2009-10-21 13:44:36 +0200 | [diff] [blame] | 2173 | if (pvt->ext_model < K8_REV_F) |
Borislav Petkov | 8566c4d | 2009-10-16 13:48:28 +0200 | [diff] [blame] | 2174 | return; |
| 2175 | else |
| 2176 | WARN_ON(ctrl != 0); |
| 2177 | } |
| 2178 | |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 2179 | if (pvt->fam == 0x10) { |
| 2180 | dbam = (ctrl && !dct_ganging_enabled(pvt)) ? pvt->dbam1 |
| 2181 | : pvt->dbam0; |
| 2182 | dcsb = (ctrl && !dct_ganging_enabled(pvt)) ? |
| 2183 | pvt->csels[1].csbases : |
| 2184 | pvt->csels[0].csbases; |
| 2185 | } else if (ctrl) { |
| 2186 | dbam = pvt->dbam0; |
| 2187 | dcsb = pvt->csels[1].csbases; |
| 2188 | } |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2189 | edac_dbg(1, "F2x%d80 (DRAM Bank Address Mapping): 0x%08x\n", |
| 2190 | ctrl, dbam); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2191 | |
Borislav Petkov | 8566c4d | 2009-10-16 13:48:28 +0200 | [diff] [blame] | 2192 | edac_printk(KERN_DEBUG, EDAC_MC, "DCT%d chip selects:\n", ctrl); |
| 2193 | |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2194 | /* Dump memory sizes for DIMM and its CSROWs */ |
| 2195 | for (dimm = 0; dimm < 4; dimm++) { |
| 2196 | |
| 2197 | size0 = 0; |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 2198 | if (dcsb[dimm*2] & DCSB_CS_ENABLE) |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 2199 | /* |
| 2200 | * For F15m60h, we need multiplier for LRDIMM cs_size |
| 2201 | * calculation. We pass dimm value to the dbam_to_cs |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 2202 | * mapper so we can find the multiplier from the |
| 2203 | * corresponding DCSM. |
| 2204 | */ |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 2205 | size0 = pvt->ops->dbam_to_cs(pvt, ctrl, |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 2206 | DBAM_DIMM(dimm, dbam), |
| 2207 | dimm); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2208 | |
| 2209 | size1 = 0; |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 2210 | if (dcsb[dimm*2 + 1] & DCSB_CS_ENABLE) |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 2211 | size1 = pvt->ops->dbam_to_cs(pvt, ctrl, |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 2212 | DBAM_DIMM(dimm, dbam), |
| 2213 | dimm); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2214 | |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 2215 | amd64_info(EDAC_MC ": %d: %5dMB %d: %5dMB\n", |
Borislav Petkov | bb89f5a | 2012-09-12 18:06:00 +0200 | [diff] [blame] | 2216 | dimm * 2, size0, |
| 2217 | dimm * 2 + 1, size1); |
Doug Thompson | f71d0a0 | 2009-04-27 16:22:43 +0200 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 2221 | static struct amd64_family_type family_types[] = { |
Doug Thompson | 4d37607 | 2009-04-27 16:25:05 +0200 | [diff] [blame] | 2222 | [K8_CPUS] = { |
Borislav Petkov | 0092b20 | 2010-10-01 19:20:05 +0200 | [diff] [blame] | 2223 | .ctl_name = "K8", |
Borislav Petkov | 8d5b5d9 | 2010-10-01 20:11:07 +0200 | [diff] [blame] | 2224 | .f1_id = PCI_DEVICE_ID_AMD_K8_NB_ADDRMAP, |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2225 | .f2_id = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2226 | .max_mcs = 2, |
Doug Thompson | 4d37607 | 2009-04-27 16:25:05 +0200 | [diff] [blame] | 2227 | .ops = { |
Borislav Petkov | 1433eb9 | 2009-10-21 13:44:36 +0200 | [diff] [blame] | 2228 | .early_channel_count = k8_early_channel_count, |
Borislav Petkov | 1433eb9 | 2009-10-21 13:44:36 +0200 | [diff] [blame] | 2229 | .map_sysaddr_to_csrow = k8_map_sysaddr_to_csrow, |
| 2230 | .dbam_to_cs = k8_dbam_to_chip_select, |
Doug Thompson | 4d37607 | 2009-04-27 16:25:05 +0200 | [diff] [blame] | 2231 | } |
| 2232 | }, |
| 2233 | [F10_CPUS] = { |
Borislav Petkov | 0092b20 | 2010-10-01 19:20:05 +0200 | [diff] [blame] | 2234 | .ctl_name = "F10h", |
Borislav Petkov | 8d5b5d9 | 2010-10-01 20:11:07 +0200 | [diff] [blame] | 2235 | .f1_id = PCI_DEVICE_ID_AMD_10H_NB_MAP, |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2236 | .f2_id = PCI_DEVICE_ID_AMD_10H_NB_DRAM, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2237 | .max_mcs = 2, |
Doug Thompson | 4d37607 | 2009-04-27 16:25:05 +0200 | [diff] [blame] | 2238 | .ops = { |
Borislav Petkov | 7d20d14 | 2011-01-07 17:58:04 +0100 | [diff] [blame] | 2239 | .early_channel_count = f1x_early_channel_count, |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 2240 | .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, |
Borislav Petkov | 1433eb9 | 2009-10-21 13:44:36 +0200 | [diff] [blame] | 2241 | .dbam_to_cs = f10_dbam_to_chip_select, |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 2242 | } |
| 2243 | }, |
| 2244 | [F15_CPUS] = { |
| 2245 | .ctl_name = "F15h", |
Borislav Petkov | df71a05 | 2011-01-19 18:15:10 +0100 | [diff] [blame] | 2246 | .f1_id = PCI_DEVICE_ID_AMD_15H_NB_F1, |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2247 | .f2_id = PCI_DEVICE_ID_AMD_15H_NB_F2, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2248 | .max_mcs = 2, |
Borislav Petkov | b2b0c60 | 2010-10-08 18:32:29 +0200 | [diff] [blame] | 2249 | .ops = { |
Borislav Petkov | 7d20d14 | 2011-01-07 17:58:04 +0100 | [diff] [blame] | 2250 | .early_channel_count = f1x_early_channel_count, |
Borislav Petkov | b15f0fc | 2011-01-17 15:59:58 +0100 | [diff] [blame] | 2251 | .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, |
Borislav Petkov | 41d8bfa | 2011-01-18 19:16:08 +0100 | [diff] [blame] | 2252 | .dbam_to_cs = f15_dbam_to_chip_select, |
Doug Thompson | 4d37607 | 2009-04-27 16:25:05 +0200 | [diff] [blame] | 2253 | } |
| 2254 | }, |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2255 | [F15_M30H_CPUS] = { |
| 2256 | .ctl_name = "F15h_M30h", |
| 2257 | .f1_id = PCI_DEVICE_ID_AMD_15H_M30H_NB_F1, |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2258 | .f2_id = PCI_DEVICE_ID_AMD_15H_M30H_NB_F2, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2259 | .max_mcs = 2, |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2260 | .ops = { |
| 2261 | .early_channel_count = f1x_early_channel_count, |
| 2262 | .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, |
| 2263 | .dbam_to_cs = f16_dbam_to_chip_select, |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 2264 | } |
| 2265 | }, |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 2266 | [F15_M60H_CPUS] = { |
| 2267 | .ctl_name = "F15h_M60h", |
| 2268 | .f1_id = PCI_DEVICE_ID_AMD_15H_M60H_NB_F1, |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2269 | .f2_id = PCI_DEVICE_ID_AMD_15H_M60H_NB_F2, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2270 | .max_mcs = 2, |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 2271 | .ops = { |
| 2272 | .early_channel_count = f1x_early_channel_count, |
| 2273 | .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, |
| 2274 | .dbam_to_cs = f15_m60h_dbam_to_chip_select, |
| 2275 | } |
| 2276 | }, |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 2277 | [F16_CPUS] = { |
| 2278 | .ctl_name = "F16h", |
| 2279 | .f1_id = PCI_DEVICE_ID_AMD_16H_NB_F1, |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2280 | .f2_id = PCI_DEVICE_ID_AMD_16H_NB_F2, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2281 | .max_mcs = 2, |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 2282 | .ops = { |
| 2283 | .early_channel_count = f1x_early_channel_count, |
| 2284 | .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, |
| 2285 | .dbam_to_cs = f16_dbam_to_chip_select, |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 2286 | } |
| 2287 | }, |
Aravind Gopalakrishnan | 85a8885 | 2014-02-20 10:28:46 -0600 | [diff] [blame] | 2288 | [F16_M30H_CPUS] = { |
| 2289 | .ctl_name = "F16h_M30h", |
| 2290 | .f1_id = PCI_DEVICE_ID_AMD_16H_M30H_NB_F1, |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2291 | .f2_id = PCI_DEVICE_ID_AMD_16H_M30H_NB_F2, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2292 | .max_mcs = 2, |
Aravind Gopalakrishnan | 85a8885 | 2014-02-20 10:28:46 -0600 | [diff] [blame] | 2293 | .ops = { |
| 2294 | .early_channel_count = f1x_early_channel_count, |
| 2295 | .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow, |
| 2296 | .dbam_to_cs = f16_dbam_to_chip_select, |
Aravind Gopalakrishnan | 85a8885 | 2014-02-20 10:28:46 -0600 | [diff] [blame] | 2297 | } |
| 2298 | }, |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 2299 | [F17_CPUS] = { |
| 2300 | .ctl_name = "F17h", |
| 2301 | .f0_id = PCI_DEVICE_ID_AMD_17H_DF_F0, |
| 2302 | .f6_id = PCI_DEVICE_ID_AMD_17H_DF_F6, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2303 | .max_mcs = 2, |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 2304 | .ops = { |
| 2305 | .early_channel_count = f17_early_channel_count, |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 2306 | .dbam_to_cs = f17_addr_mask_to_cs_size, |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 2307 | } |
| 2308 | }, |
Michael Jin | 8960de4 | 2018-08-16 15:28:40 -0400 | [diff] [blame] | 2309 | [F17_M10H_CPUS] = { |
| 2310 | .ctl_name = "F17h_M10h", |
| 2311 | .f0_id = PCI_DEVICE_ID_AMD_17H_M10H_DF_F0, |
| 2312 | .f6_id = PCI_DEVICE_ID_AMD_17H_M10H_DF_F6, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2313 | .max_mcs = 2, |
Michael Jin | 8960de4 | 2018-08-16 15:28:40 -0400 | [diff] [blame] | 2314 | .ops = { |
| 2315 | .early_channel_count = f17_early_channel_count, |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 2316 | .dbam_to_cs = f17_addr_mask_to_cs_size, |
Michael Jin | 8960de4 | 2018-08-16 15:28:40 -0400 | [diff] [blame] | 2317 | } |
| 2318 | }, |
Yazen Ghannam | 6e846239 | 2019-02-28 15:36:09 +0000 | [diff] [blame] | 2319 | [F17_M30H_CPUS] = { |
| 2320 | .ctl_name = "F17h_M30h", |
| 2321 | .f0_id = PCI_DEVICE_ID_AMD_17H_M30H_DF_F0, |
| 2322 | .f6_id = PCI_DEVICE_ID_AMD_17H_M30H_DF_F6, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2323 | .max_mcs = 8, |
Yazen Ghannam | 6e846239 | 2019-02-28 15:36:09 +0000 | [diff] [blame] | 2324 | .ops = { |
| 2325 | .early_channel_count = f17_early_channel_count, |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 2326 | .dbam_to_cs = f17_addr_mask_to_cs_size, |
Yazen Ghannam | 6e846239 | 2019-02-28 15:36:09 +0000 | [diff] [blame] | 2327 | } |
| 2328 | }, |
Isaac Vaughn | 3e443eb | 2019-09-06 23:21:38 +0000 | [diff] [blame] | 2329 | [F17_M70H_CPUS] = { |
| 2330 | .ctl_name = "F17h_M70h", |
| 2331 | .f0_id = PCI_DEVICE_ID_AMD_17H_M70H_DF_F0, |
| 2332 | .f6_id = PCI_DEVICE_ID_AMD_17H_M70H_DF_F6, |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 2333 | .max_mcs = 2, |
Isaac Vaughn | 3e443eb | 2019-09-06 23:21:38 +0000 | [diff] [blame] | 2334 | .ops = { |
| 2335 | .early_channel_count = f17_early_channel_count, |
| 2336 | .dbam_to_cs = f17_addr_mask_to_cs_size, |
| 2337 | } |
| 2338 | }, |
Doug Thompson | 4d37607 | 2009-04-27 16:25:05 +0200 | [diff] [blame] | 2339 | }; |
| 2340 | |
Doug Thompson | b1289d6 | 2009-04-27 16:37:05 +0200 | [diff] [blame] | 2341 | /* |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2342 | * These are tables of eigenvectors (one per line) which can be used for the |
| 2343 | * construction of the syndrome tables. The modified syndrome search algorithm |
| 2344 | * uses those to find the symbol in error and thus the DIMM. |
Doug Thompson | b1289d6 | 2009-04-27 16:37:05 +0200 | [diff] [blame] | 2345 | * |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2346 | * Algorithm courtesy of Ross LaFetra from AMD. |
Doug Thompson | b1289d6 | 2009-04-27 16:37:05 +0200 | [diff] [blame] | 2347 | */ |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 2348 | static const u16 x4_vectors[] = { |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2349 | 0x2f57, 0x1afe, 0x66cc, 0xdd88, |
| 2350 | 0x11eb, 0x3396, 0x7f4c, 0xeac8, |
| 2351 | 0x0001, 0x0002, 0x0004, 0x0008, |
| 2352 | 0x1013, 0x3032, 0x4044, 0x8088, |
| 2353 | 0x106b, 0x30d6, 0x70fc, 0xe0a8, |
| 2354 | 0x4857, 0xc4fe, 0x13cc, 0x3288, |
| 2355 | 0x1ac5, 0x2f4a, 0x5394, 0xa1e8, |
| 2356 | 0x1f39, 0x251e, 0xbd6c, 0x6bd8, |
| 2357 | 0x15c1, 0x2a42, 0x89ac, 0x4758, |
| 2358 | 0x2b03, 0x1602, 0x4f0c, 0xca08, |
| 2359 | 0x1f07, 0x3a0e, 0x6b04, 0xbd08, |
| 2360 | 0x8ba7, 0x465e, 0x244c, 0x1cc8, |
| 2361 | 0x2b87, 0x164e, 0x642c, 0xdc18, |
| 2362 | 0x40b9, 0x80de, 0x1094, 0x20e8, |
| 2363 | 0x27db, 0x1eb6, 0x9dac, 0x7b58, |
| 2364 | 0x11c1, 0x2242, 0x84ac, 0x4c58, |
| 2365 | 0x1be5, 0x2d7a, 0x5e34, 0xa718, |
| 2366 | 0x4b39, 0x8d1e, 0x14b4, 0x28d8, |
| 2367 | 0x4c97, 0xc87e, 0x11fc, 0x33a8, |
| 2368 | 0x8e97, 0x497e, 0x2ffc, 0x1aa8, |
| 2369 | 0x16b3, 0x3d62, 0x4f34, 0x8518, |
| 2370 | 0x1e2f, 0x391a, 0x5cac, 0xf858, |
| 2371 | 0x1d9f, 0x3b7a, 0x572c, 0xfe18, |
| 2372 | 0x15f5, 0x2a5a, 0x5264, 0xa3b8, |
| 2373 | 0x1dbb, 0x3b66, 0x715c, 0xe3f8, |
| 2374 | 0x4397, 0xc27e, 0x17fc, 0x3ea8, |
| 2375 | 0x1617, 0x3d3e, 0x6464, 0xb8b8, |
| 2376 | 0x23ff, 0x12aa, 0xab6c, 0x56d8, |
| 2377 | 0x2dfb, 0x1ba6, 0x913c, 0x7328, |
| 2378 | 0x185d, 0x2ca6, 0x7914, 0x9e28, |
| 2379 | 0x171b, 0x3e36, 0x7d7c, 0xebe8, |
| 2380 | 0x4199, 0x82ee, 0x19f4, 0x2e58, |
| 2381 | 0x4807, 0xc40e, 0x130c, 0x3208, |
| 2382 | 0x1905, 0x2e0a, 0x5804, 0xac08, |
| 2383 | 0x213f, 0x132a, 0xadfc, 0x5ba8, |
| 2384 | 0x19a9, 0x2efe, 0xb5cc, 0x6f88, |
Doug Thompson | b1289d6 | 2009-04-27 16:37:05 +0200 | [diff] [blame] | 2385 | }; |
| 2386 | |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 2387 | static const u16 x8_vectors[] = { |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2388 | 0x0145, 0x028a, 0x2374, 0x43c8, 0xa1f0, 0x0520, 0x0a40, 0x1480, |
| 2389 | 0x0211, 0x0422, 0x0844, 0x1088, 0x01b0, 0x44e0, 0x23c0, 0xed80, |
| 2390 | 0x1011, 0x0116, 0x022c, 0x0458, 0x08b0, 0x8c60, 0x2740, 0x4e80, |
| 2391 | 0x0411, 0x0822, 0x1044, 0x0158, 0x02b0, 0x2360, 0x46c0, 0xab80, |
| 2392 | 0x0811, 0x1022, 0x012c, 0x0258, 0x04b0, 0x4660, 0x8cc0, 0x2780, |
| 2393 | 0x2071, 0x40e2, 0xa0c4, 0x0108, 0x0210, 0x0420, 0x0840, 0x1080, |
| 2394 | 0x4071, 0x80e2, 0x0104, 0x0208, 0x0410, 0x0820, 0x1040, 0x2080, |
| 2395 | 0x8071, 0x0102, 0x0204, 0x0408, 0x0810, 0x1020, 0x2040, 0x4080, |
| 2396 | 0x019d, 0x03d6, 0x136c, 0x2198, 0x50b0, 0xb2e0, 0x0740, 0x0e80, |
| 2397 | 0x0189, 0x03ea, 0x072c, 0x0e58, 0x1cb0, 0x56e0, 0x37c0, 0xf580, |
| 2398 | 0x01fd, 0x0376, 0x06ec, 0x0bb8, 0x1110, 0x2220, 0x4440, 0x8880, |
| 2399 | 0x0163, 0x02c6, 0x1104, 0x0758, 0x0eb0, 0x2be0, 0x6140, 0xc280, |
| 2400 | 0x02fd, 0x01c6, 0x0b5c, 0x1108, 0x07b0, 0x25a0, 0x8840, 0x6180, |
| 2401 | 0x0801, 0x012e, 0x025c, 0x04b8, 0x1370, 0x26e0, 0x57c0, 0xb580, |
| 2402 | 0x0401, 0x0802, 0x015c, 0x02b8, 0x22b0, 0x13e0, 0x7140, 0xe280, |
| 2403 | 0x0201, 0x0402, 0x0804, 0x01b8, 0x11b0, 0x31a0, 0x8040, 0x7180, |
| 2404 | 0x0101, 0x0202, 0x0404, 0x0808, 0x1010, 0x2020, 0x4040, 0x8080, |
| 2405 | 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, |
| 2406 | 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000, |
| 2407 | }; |
| 2408 | |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 2409 | static int decode_syndrome(u16 syndrome, const u16 *vectors, unsigned num_vecs, |
Borislav Petkov | d34a6ec | 2011-02-23 17:41:50 +0100 | [diff] [blame] | 2410 | unsigned v_dim) |
Doug Thompson | b1289d6 | 2009-04-27 16:37:05 +0200 | [diff] [blame] | 2411 | { |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2412 | unsigned int i, err_sym; |
Doug Thompson | b1289d6 | 2009-04-27 16:37:05 +0200 | [diff] [blame] | 2413 | |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2414 | for (err_sym = 0; err_sym < num_vecs / v_dim; err_sym++) { |
| 2415 | u16 s = syndrome; |
Borislav Petkov | d34a6ec | 2011-02-23 17:41:50 +0100 | [diff] [blame] | 2416 | unsigned v_idx = err_sym * v_dim; |
| 2417 | unsigned v_end = (err_sym + 1) * v_dim; |
Doug Thompson | b1289d6 | 2009-04-27 16:37:05 +0200 | [diff] [blame] | 2418 | |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2419 | /* walk over all 16 bits of the syndrome */ |
| 2420 | for (i = 1; i < (1U << 16); i <<= 1) { |
| 2421 | |
| 2422 | /* if bit is set in that eigenvector... */ |
| 2423 | if (v_idx < v_end && vectors[v_idx] & i) { |
| 2424 | u16 ev_comp = vectors[v_idx++]; |
| 2425 | |
| 2426 | /* ... and bit set in the modified syndrome, */ |
| 2427 | if (s & i) { |
| 2428 | /* remove it. */ |
| 2429 | s ^= ev_comp; |
| 2430 | |
| 2431 | if (!s) |
| 2432 | return err_sym; |
| 2433 | } |
| 2434 | |
| 2435 | } else if (s & i) |
| 2436 | /* can't get to zero, move to next symbol */ |
| 2437 | break; |
| 2438 | } |
Doug Thompson | b1289d6 | 2009-04-27 16:37:05 +0200 | [diff] [blame] | 2439 | } |
| 2440 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2441 | edac_dbg(0, "syndrome(%x) not found\n", syndrome); |
Doug Thompson | b1289d6 | 2009-04-27 16:37:05 +0200 | [diff] [blame] | 2442 | return -1; |
| 2443 | } |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2444 | |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2445 | static int map_err_sym_to_channel(int err_sym, int sym_size) |
| 2446 | { |
| 2447 | if (sym_size == 4) |
| 2448 | switch (err_sym) { |
| 2449 | case 0x20: |
| 2450 | case 0x21: |
| 2451 | return 0; |
| 2452 | break; |
| 2453 | case 0x22: |
| 2454 | case 0x23: |
| 2455 | return 1; |
| 2456 | break; |
| 2457 | default: |
| 2458 | return err_sym >> 4; |
| 2459 | break; |
| 2460 | } |
| 2461 | /* x8 symbols */ |
| 2462 | else |
| 2463 | switch (err_sym) { |
| 2464 | /* imaginary bits not in a DIMM */ |
| 2465 | case 0x10: |
| 2466 | WARN(1, KERN_ERR "Invalid error symbol: 0x%x\n", |
| 2467 | err_sym); |
| 2468 | return -1; |
| 2469 | break; |
| 2470 | |
| 2471 | case 0x11: |
| 2472 | return 0; |
| 2473 | break; |
| 2474 | case 0x12: |
| 2475 | return 1; |
| 2476 | break; |
| 2477 | default: |
| 2478 | return err_sym >> 3; |
| 2479 | break; |
| 2480 | } |
| 2481 | return -1; |
| 2482 | } |
| 2483 | |
| 2484 | static int get_channel_from_ecc_syndrome(struct mem_ctl_info *mci, u16 syndrome) |
| 2485 | { |
| 2486 | struct amd64_pvt *pvt = mci->pvt_info; |
Borislav Petkov | ad6a32e | 2010-03-09 12:46:00 +0100 | [diff] [blame] | 2487 | int err_sym = -1; |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2488 | |
Borislav Petkov | a3b7db0 | 2011-01-19 20:35:12 +0100 | [diff] [blame] | 2489 | if (pvt->ecc_sym_sz == 8) |
Borislav Petkov | ad6a32e | 2010-03-09 12:46:00 +0100 | [diff] [blame] | 2490 | err_sym = decode_syndrome(syndrome, x8_vectors, |
| 2491 | ARRAY_SIZE(x8_vectors), |
Borislav Petkov | a3b7db0 | 2011-01-19 20:35:12 +0100 | [diff] [blame] | 2492 | pvt->ecc_sym_sz); |
| 2493 | else if (pvt->ecc_sym_sz == 4) |
Borislav Petkov | ad6a32e | 2010-03-09 12:46:00 +0100 | [diff] [blame] | 2494 | err_sym = decode_syndrome(syndrome, x4_vectors, |
| 2495 | ARRAY_SIZE(x4_vectors), |
Borislav Petkov | a3b7db0 | 2011-01-19 20:35:12 +0100 | [diff] [blame] | 2496 | pvt->ecc_sym_sz); |
Borislav Petkov | ad6a32e | 2010-03-09 12:46:00 +0100 | [diff] [blame] | 2497 | else { |
Borislav Petkov | a3b7db0 | 2011-01-19 20:35:12 +0100 | [diff] [blame] | 2498 | amd64_warn("Illegal syndrome type: %u\n", pvt->ecc_sym_sz); |
Borislav Petkov | ad6a32e | 2010-03-09 12:46:00 +0100 | [diff] [blame] | 2499 | return err_sym; |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2500 | } |
Borislav Petkov | ad6a32e | 2010-03-09 12:46:00 +0100 | [diff] [blame] | 2501 | |
Borislav Petkov | a3b7db0 | 2011-01-19 20:35:12 +0100 | [diff] [blame] | 2502 | return map_err_sym_to_channel(err_sym, pvt->ecc_sym_sz); |
Borislav Petkov | bfc04ae | 2009-11-12 19:05:07 +0100 | [diff] [blame] | 2503 | } |
| 2504 | |
Yazen Ghannam | e70984d | 2016-11-17 17:57:31 -0500 | [diff] [blame] | 2505 | static void __log_ecc_error(struct mem_ctl_info *mci, struct err_info *err, |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2506 | u8 ecc_type) |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2507 | { |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2508 | enum hw_event_mc_err_type err_type; |
| 2509 | const char *string; |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2510 | |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2511 | if (ecc_type == 2) |
| 2512 | err_type = HW_EVENT_ERR_CORRECTED; |
| 2513 | else if (ecc_type == 1) |
| 2514 | err_type = HW_EVENT_ERR_UNCORRECTED; |
Yazen Ghannam | d12a969 | 2016-11-17 17:57:32 -0500 | [diff] [blame] | 2515 | else if (ecc_type == 3) |
| 2516 | err_type = HW_EVENT_ERR_DEFERRED; |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2517 | else { |
| 2518 | WARN(1, "Something is rotten in the state of Denmark.\n"); |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2519 | return; |
| 2520 | } |
| 2521 | |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2522 | switch (err->err_code) { |
| 2523 | case DECODE_OK: |
| 2524 | string = ""; |
| 2525 | break; |
| 2526 | case ERR_NODE: |
| 2527 | string = "Failed to map error addr to a node"; |
| 2528 | break; |
| 2529 | case ERR_CSROW: |
| 2530 | string = "Failed to map error addr to a csrow"; |
| 2531 | break; |
| 2532 | case ERR_CHANNEL: |
Yazen Ghannam | 713ad54 | 2016-11-28 12:59:53 -0600 | [diff] [blame] | 2533 | string = "Unknown syndrome - possible error reporting race"; |
| 2534 | break; |
| 2535 | case ERR_SYND: |
| 2536 | string = "MCA_SYND not valid - unknown syndrome and csrow"; |
| 2537 | break; |
| 2538 | case ERR_NORM_ADDR: |
| 2539 | string = "Cannot decode normalized address"; |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2540 | break; |
| 2541 | default: |
| 2542 | string = "WTF error"; |
| 2543 | break; |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2544 | } |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2545 | |
| 2546 | edac_mc_handle_error(err_type, mci, 1, |
| 2547 | err->page, err->offset, err->syndrome, |
| 2548 | err->csrow, err->channel, -1, |
| 2549 | string, ""); |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2550 | } |
| 2551 | |
Borislav Petkov | df781d0 | 2013-12-15 17:29:44 +0100 | [diff] [blame] | 2552 | static inline void decode_bus_error(int node_id, struct mce *m) |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2553 | { |
Daniel J Blueman | 0c510cc | 2015-02-17 11:34:38 +0800 | [diff] [blame] | 2554 | struct mem_ctl_info *mci; |
| 2555 | struct amd64_pvt *pvt; |
Borislav Petkov | f192c7b | 2011-01-10 14:24:32 +0100 | [diff] [blame] | 2556 | u8 ecc_type = (m->status >> 45) & 0x3; |
Borislav Petkov | 66fed2d | 2012-08-09 18:41:07 +0200 | [diff] [blame] | 2557 | u8 xec = XEC(m->status, 0x1f); |
| 2558 | u16 ec = EC(m->status); |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2559 | u64 sys_addr; |
| 2560 | struct err_info err; |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2561 | |
Daniel J Blueman | 0c510cc | 2015-02-17 11:34:38 +0800 | [diff] [blame] | 2562 | mci = edac_mc_find(node_id); |
| 2563 | if (!mci) |
| 2564 | return; |
| 2565 | |
| 2566 | pvt = mci->pvt_info; |
| 2567 | |
Borislav Petkov | 66fed2d | 2012-08-09 18:41:07 +0200 | [diff] [blame] | 2568 | /* Bail out early if this was an 'observed' error */ |
Borislav Petkov | 5980bb9 | 2011-01-07 16:26:49 +0100 | [diff] [blame] | 2569 | if (PP(ec) == NBSL_PP_OBS) |
Borislav Petkov | b70ef01 | 2009-06-25 19:32:38 +0200 | [diff] [blame] | 2570 | return; |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2571 | |
Borislav Petkov | ecaf560 | 2009-07-23 16:32:01 +0200 | [diff] [blame] | 2572 | /* Do only ECC errors */ |
| 2573 | if (xec && xec != F10_NBSL_EXT_ERR_ECC) |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2574 | return; |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2575 | |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2576 | memset(&err, 0, sizeof(err)); |
| 2577 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 2578 | sys_addr = get_error_address(pvt, m); |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2579 | |
Borislav Petkov | ecaf560 | 2009-07-23 16:32:01 +0200 | [diff] [blame] | 2580 | if (ecc_type == 2) |
Borislav Petkov | 33ca064 | 2012-08-30 18:01:36 +0200 | [diff] [blame] | 2581 | err.syndrome = extract_syndrome(m->status); |
| 2582 | |
| 2583 | pvt->ops->map_sysaddr_to_csrow(mci, sys_addr, &err); |
| 2584 | |
Yazen Ghannam | e70984d | 2016-11-17 17:57:31 -0500 | [diff] [blame] | 2585 | __log_ecc_error(mci, &err, ecc_type); |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 2586 | } |
| 2587 | |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2588 | /* |
Yazen Ghannam | 713ad54 | 2016-11-28 12:59:53 -0600 | [diff] [blame] | 2589 | * To find the UMC channel represented by this bank we need to match on its |
| 2590 | * instance_id. The instance_id of a bank is held in the lower 32 bits of its |
| 2591 | * IPID. |
Yazen Ghannam | bdcee77 | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 2592 | * |
| 2593 | * Currently, we can derive the channel number by looking at the 6th nibble in |
| 2594 | * the instance_id. For example, instance_id=0xYXXXXX where Y is the channel |
| 2595 | * number. |
Yazen Ghannam | 713ad54 | 2016-11-28 12:59:53 -0600 | [diff] [blame] | 2596 | */ |
Yazen Ghannam | bdcee77 | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 2597 | static int find_umc_channel(struct mce *m) |
Yazen Ghannam | 713ad54 | 2016-11-28 12:59:53 -0600 | [diff] [blame] | 2598 | { |
Yazen Ghannam | bdcee77 | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 2599 | return (m->ipid & GENMASK(31, 0)) >> 20; |
Yazen Ghannam | 713ad54 | 2016-11-28 12:59:53 -0600 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | static void decode_umc_error(int node_id, struct mce *m) |
| 2603 | { |
| 2604 | u8 ecc_type = (m->status >> 45) & 0x3; |
| 2605 | struct mem_ctl_info *mci; |
| 2606 | struct amd64_pvt *pvt; |
| 2607 | struct err_info err; |
| 2608 | u64 sys_addr; |
| 2609 | |
| 2610 | mci = edac_mc_find(node_id); |
| 2611 | if (!mci) |
| 2612 | return; |
| 2613 | |
| 2614 | pvt = mci->pvt_info; |
| 2615 | |
| 2616 | memset(&err, 0, sizeof(err)); |
| 2617 | |
| 2618 | if (m->status & MCI_STATUS_DEFERRED) |
| 2619 | ecc_type = 3; |
| 2620 | |
Yazen Ghannam | bdcee77 | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 2621 | err.channel = find_umc_channel(m); |
Yazen Ghannam | 713ad54 | 2016-11-28 12:59:53 -0600 | [diff] [blame] | 2622 | |
Yazen Ghannam | 713ad54 | 2016-11-28 12:59:53 -0600 | [diff] [blame] | 2623 | if (!(m->status & MCI_STATUS_SYNDV)) { |
| 2624 | err.err_code = ERR_SYND; |
| 2625 | goto log_error; |
| 2626 | } |
| 2627 | |
| 2628 | if (ecc_type == 2) { |
| 2629 | u8 length = (m->synd >> 18) & 0x3f; |
| 2630 | |
| 2631 | if (length) |
| 2632 | err.syndrome = (m->synd >> 32) & GENMASK(length - 1, 0); |
| 2633 | else |
| 2634 | err.err_code = ERR_CHANNEL; |
| 2635 | } |
| 2636 | |
| 2637 | err.csrow = m->synd & 0x7; |
| 2638 | |
Yazen Ghannam | 8a2eaab | 2019-08-22 00:00:00 +0000 | [diff] [blame] | 2639 | if (umc_normaddr_to_sysaddr(m->addr, pvt->mc_node_id, err.channel, &sys_addr)) { |
| 2640 | err.err_code = ERR_NORM_ADDR; |
| 2641 | goto log_error; |
| 2642 | } |
| 2643 | |
| 2644 | error_address_to_page_and_offset(sys_addr, &err); |
| 2645 | |
Yazen Ghannam | 713ad54 | 2016-11-28 12:59:53 -0600 | [diff] [blame] | 2646 | log_error: |
| 2647 | __log_ecc_error(mci, &err, ecc_type); |
| 2648 | } |
| 2649 | |
| 2650 | /* |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2651 | * Use pvt->F3 which contains the F3 CPU PCI device to get the related |
| 2652 | * F1 (AddrMap) and F2 (Dct) devices. Return negative value on error. |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2653 | * Reserve F0 and F6 on systems with a UMC. |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2654 | */ |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2655 | static int |
| 2656 | reserve_mc_sibling_devs(struct amd64_pvt *pvt, u16 pci_id1, u16 pci_id2) |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2657 | { |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2658 | if (pvt->umc) { |
| 2659 | pvt->F0 = pci_get_related_function(pvt->F3->vendor, pci_id1, pvt->F3); |
| 2660 | if (!pvt->F0) { |
Borislav Petkov | 5246c54 | 2016-12-01 11:35:07 +0100 | [diff] [blame] | 2661 | amd64_err("F0 not found, device 0x%x (broken BIOS?)\n", pci_id1); |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2662 | return -ENODEV; |
| 2663 | } |
| 2664 | |
| 2665 | pvt->F6 = pci_get_related_function(pvt->F3->vendor, pci_id2, pvt->F3); |
| 2666 | if (!pvt->F6) { |
| 2667 | pci_dev_put(pvt->F0); |
| 2668 | pvt->F0 = NULL; |
| 2669 | |
Borislav Petkov | 5246c54 | 2016-12-01 11:35:07 +0100 | [diff] [blame] | 2670 | amd64_err("F6 not found: device 0x%x (broken BIOS?)\n", pci_id2); |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2671 | return -ENODEV; |
| 2672 | } |
Borislav Petkov | 5246c54 | 2016-12-01 11:35:07 +0100 | [diff] [blame] | 2673 | |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2674 | edac_dbg(1, "F0: %s\n", pci_name(pvt->F0)); |
| 2675 | edac_dbg(1, "F3: %s\n", pci_name(pvt->F3)); |
| 2676 | edac_dbg(1, "F6: %s\n", pci_name(pvt->F6)); |
| 2677 | |
| 2678 | return 0; |
| 2679 | } |
| 2680 | |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2681 | /* Reserve the ADDRESS MAP Device */ |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2682 | pvt->F1 = pci_get_related_function(pvt->F3->vendor, pci_id1, pvt->F3); |
Borislav Petkov | 8d5b5d9 | 2010-10-01 20:11:07 +0200 | [diff] [blame] | 2683 | if (!pvt->F1) { |
Borislav Petkov | 5246c54 | 2016-12-01 11:35:07 +0100 | [diff] [blame] | 2684 | amd64_err("F1 not found: device 0x%x (broken BIOS?)\n", pci_id1); |
Borislav Petkov | bbd0c1f | 2010-10-01 19:27:58 +0200 | [diff] [blame] | 2685 | return -ENODEV; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2686 | } |
| 2687 | |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2688 | /* Reserve the DCT Device */ |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2689 | pvt->F2 = pci_get_related_function(pvt->F3->vendor, pci_id2, pvt->F3); |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 2690 | if (!pvt->F2) { |
Borislav Petkov | 8d5b5d9 | 2010-10-01 20:11:07 +0200 | [diff] [blame] | 2691 | pci_dev_put(pvt->F1); |
| 2692 | pvt->F1 = NULL; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2693 | |
Borislav Petkov | 5246c54 | 2016-12-01 11:35:07 +0100 | [diff] [blame] | 2694 | amd64_err("F2 not found: device 0x%x (broken BIOS?)\n", pci_id2); |
| 2695 | return -ENODEV; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2696 | } |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2697 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2698 | edac_dbg(1, "F1: %s\n", pci_name(pvt->F1)); |
| 2699 | edac_dbg(1, "F2: %s\n", pci_name(pvt->F2)); |
| 2700 | edac_dbg(1, "F3: %s\n", pci_name(pvt->F3)); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2701 | |
| 2702 | return 0; |
| 2703 | } |
| 2704 | |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 2705 | static void free_mc_sibling_devs(struct amd64_pvt *pvt) |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2706 | { |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 2707 | if (pvt->umc) { |
| 2708 | pci_dev_put(pvt->F0); |
| 2709 | pci_dev_put(pvt->F6); |
| 2710 | } else { |
| 2711 | pci_dev_put(pvt->F1); |
| 2712 | pci_dev_put(pvt->F2); |
| 2713 | } |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2714 | } |
| 2715 | |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2716 | static void determine_ecc_sym_sz(struct amd64_pvt *pvt) |
| 2717 | { |
| 2718 | pvt->ecc_sym_sz = 4; |
| 2719 | |
| 2720 | if (pvt->umc) { |
| 2721 | u8 i; |
| 2722 | |
Yazen Ghannam | 4d30d2b | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 2723 | for_each_umc(i) { |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2724 | /* Check enabled channels only: */ |
Yazen Ghannam | 7835961 | 2019-02-28 15:36:11 +0000 | [diff] [blame] | 2725 | if (pvt->umc[i].sdp_ctrl & UMC_SDP_INIT) { |
| 2726 | if (pvt->umc[i].ecc_ctrl & BIT(9)) { |
| 2727 | pvt->ecc_sym_sz = 16; |
| 2728 | return; |
| 2729 | } else if (pvt->umc[i].ecc_ctrl & BIT(7)) { |
| 2730 | pvt->ecc_sym_sz = 8; |
| 2731 | return; |
| 2732 | } |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2733 | } |
| 2734 | } |
Yazen Ghannam | 7835961 | 2019-02-28 15:36:11 +0000 | [diff] [blame] | 2735 | } else if (pvt->fam >= 0x10) { |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2736 | u32 tmp; |
| 2737 | |
| 2738 | amd64_read_pci_cfg(pvt->F3, EXT_NB_MCA_CFG, &tmp); |
| 2739 | /* F16h has only DCT0, so no need to read dbam1. */ |
| 2740 | if (pvt->fam != 0x16) |
| 2741 | amd64_read_dct_pci_cfg(pvt, 1, DBAM0, &pvt->dbam1); |
| 2742 | |
| 2743 | /* F10h, revD and later can do x8 ECC too. */ |
| 2744 | if ((pvt->fam > 0x10 || pvt->model > 7) && tmp & BIT(25)) |
| 2745 | pvt->ecc_sym_sz = 8; |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | /* |
| 2750 | * Retrieve the hardware registers of the memory controller. |
| 2751 | */ |
| 2752 | static void __read_mc_regs_df(struct amd64_pvt *pvt) |
| 2753 | { |
| 2754 | u8 nid = pvt->mc_node_id; |
| 2755 | struct amd64_umc *umc; |
| 2756 | u32 i, umc_base; |
| 2757 | |
| 2758 | /* Read registers from each UMC */ |
Yazen Ghannam | 4d30d2b | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 2759 | for_each_umc(i) { |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2760 | |
| 2761 | umc_base = get_umc_base(i); |
| 2762 | umc = &pvt->umc[i]; |
| 2763 | |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 2764 | amd_smn_read(nid, umc_base + UMCCH_DIMM_CFG, &umc->dimm_cfg); |
| 2765 | amd_smn_read(nid, umc_base + UMCCH_UMC_CFG, &umc->umc_cfg); |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2766 | amd_smn_read(nid, umc_base + UMCCH_SDP_CTRL, &umc->sdp_ctrl); |
| 2767 | amd_smn_read(nid, umc_base + UMCCH_ECC_CTRL, &umc->ecc_ctrl); |
Yazen Ghannam | 07ed82e | 2016-11-28 08:50:21 -0600 | [diff] [blame] | 2768 | amd_smn_read(nid, umc_base + UMCCH_UMC_CAP_HI, &umc->umc_cap_hi); |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2769 | } |
| 2770 | } |
| 2771 | |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2772 | /* |
| 2773 | * Retrieve the hardware registers of the memory controller (this includes the |
| 2774 | * 'Address Map' and 'Misc' device regs) |
| 2775 | */ |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 2776 | static void read_mc_regs(struct amd64_pvt *pvt) |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2777 | { |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2778 | unsigned int range; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2779 | u64 msr_val; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2780 | |
| 2781 | /* |
| 2782 | * Retrieve TOP_MEM and TOP_MEM2; no masking off of reserved bits since |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2783 | * those are Read-As-Zero. |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2784 | */ |
Borislav Petkov | e97f8bb | 2009-10-12 15:27:45 +0200 | [diff] [blame] | 2785 | rdmsrl(MSR_K8_TOP_MEM1, pvt->top_mem); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2786 | edac_dbg(0, " TOP_MEM: 0x%016llx\n", pvt->top_mem); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2787 | |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2788 | /* Check first whether TOP_MEM2 is enabled: */ |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2789 | rdmsrl(MSR_K8_SYSCFG, msr_val); |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2790 | if (msr_val & BIT(21)) { |
Borislav Petkov | e97f8bb | 2009-10-12 15:27:45 +0200 | [diff] [blame] | 2791 | rdmsrl(MSR_K8_TOP_MEM2, pvt->top_mem2); |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2792 | edac_dbg(0, " TOP_MEM2: 0x%016llx\n", pvt->top_mem2); |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2793 | } else { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2794 | edac_dbg(0, " TOP_MEM2 disabled\n"); |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2795 | } |
| 2796 | |
| 2797 | if (pvt->umc) { |
| 2798 | __read_mc_regs_df(pvt); |
| 2799 | amd64_read_pci_cfg(pvt->F0, DF_DHAR, &pvt->dhar); |
| 2800 | |
| 2801 | goto skip; |
| 2802 | } |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2803 | |
Borislav Petkov | 5980bb9 | 2011-01-07 16:26:49 +0100 | [diff] [blame] | 2804 | amd64_read_pci_cfg(pvt->F3, NBCAP, &pvt->nbcap); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2805 | |
Borislav Petkov | 5a5d237 | 2011-01-17 17:52:57 +0100 | [diff] [blame] | 2806 | read_dram_ctl_register(pvt); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2807 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 2808 | for (range = 0; range < DRAM_RANGES; range++) { |
| 2809 | u8 rw; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2810 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 2811 | /* read settings for this DRAM range */ |
| 2812 | read_dram_base_limit_regs(pvt, range); |
Borislav Petkov | e97f8bb | 2009-10-12 15:27:45 +0200 | [diff] [blame] | 2813 | |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 2814 | rw = dram_rw(pvt, range); |
| 2815 | if (!rw) |
| 2816 | continue; |
| 2817 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2818 | edac_dbg(1, " DRAM range[%d], base: 0x%016llx; limit: 0x%016llx\n", |
| 2819 | range, |
| 2820 | get_dram_base(pvt, range), |
| 2821 | get_dram_limit(pvt, range)); |
Borislav Petkov | 7f19bf7 | 2010-10-21 18:52:53 +0200 | [diff] [blame] | 2822 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 2823 | edac_dbg(1, " IntlvEn=%s; Range access: %s%s IntlvSel=%d DstNode=%d\n", |
| 2824 | dram_intlv_en(pvt, range) ? "Enabled" : "Disabled", |
| 2825 | (rw & 0x1) ? "R" : "-", |
| 2826 | (rw & 0x2) ? "W" : "-", |
| 2827 | dram_intlv_sel(pvt, range), |
| 2828 | dram_dst_node(pvt, range)); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2829 | } |
| 2830 | |
Borislav Petkov | bc21fa5 | 2010-11-11 17:29:13 +0100 | [diff] [blame] | 2831 | amd64_read_pci_cfg(pvt->F1, DHAR, &pvt->dhar); |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 2832 | amd64_read_dct_pci_cfg(pvt, 0, DBAM0, &pvt->dbam0); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2833 | |
Borislav Petkov | 8d5b5d9 | 2010-10-01 20:11:07 +0200 | [diff] [blame] | 2834 | amd64_read_pci_cfg(pvt->F3, F10_ONLINE_SPARE, &pvt->online_spare); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2835 | |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 2836 | amd64_read_dct_pci_cfg(pvt, 0, DCLR0, &pvt->dclr0); |
| 2837 | amd64_read_dct_pci_cfg(pvt, 0, DCHR0, &pvt->dchr0); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2838 | |
Borislav Petkov | 78da121 | 2010-12-22 19:31:45 +0100 | [diff] [blame] | 2839 | if (!dct_ganging_enabled(pvt)) { |
Aravind Gopalakrishnan | 7981a28 | 2014-09-15 11:37:38 -0500 | [diff] [blame] | 2840 | amd64_read_dct_pci_cfg(pvt, 1, DCLR0, &pvt->dclr1); |
| 2841 | amd64_read_dct_pci_cfg(pvt, 1, DCHR0, &pvt->dchr1); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2842 | } |
Borislav Petkov | ad6a32e | 2010-03-09 12:46:00 +0100 | [diff] [blame] | 2843 | |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2844 | skip: |
| 2845 | read_dct_base_mask(pvt); |
| 2846 | |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 2847 | determine_memory_type(pvt); |
| 2848 | edac_dbg(1, " DIMM type: %s\n", edac_mem_types[pvt->dram_type]); |
Borislav Petkov | a3b7db0 | 2011-01-19 20:35:12 +0100 | [diff] [blame] | 2849 | |
Yazen Ghannam | b64ce7c | 2016-11-17 17:57:37 -0500 | [diff] [blame] | 2850 | determine_ecc_sym_sz(pvt); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | /* |
| 2854 | * NOTE: CPU Revision Dependent code |
| 2855 | * |
| 2856 | * Input: |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 2857 | * @csrow_nr ChipSelect Row Number (0..NUM_CHIPSELECTS-1) |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2858 | * k8 private pointer to --> |
| 2859 | * DRAM Bank Address mapping register |
| 2860 | * node_id |
| 2861 | * DCL register where dual_channel_active is |
| 2862 | * |
| 2863 | * The DBAM register consists of 4 sets of 4 bits each definitions: |
| 2864 | * |
| 2865 | * Bits: CSROWs |
| 2866 | * 0-3 CSROWs 0 and 1 |
| 2867 | * 4-7 CSROWs 2 and 3 |
| 2868 | * 8-11 CSROWs 4 and 5 |
| 2869 | * 12-15 CSROWs 6 and 7 |
| 2870 | * |
| 2871 | * Values range from: 0 to 15 |
| 2872 | * The meaning of the values depends on CPU revision and dual-channel state, |
| 2873 | * see relevant BKDG more info. |
| 2874 | * |
| 2875 | * The memory controller provides for total of only 8 CSROWs in its current |
| 2876 | * architecture. Each "pair" of CSROWs normally represents just one DIMM in |
| 2877 | * single channel or two (2) DIMMs in dual channel mode. |
| 2878 | * |
| 2879 | * The following code logic collapses the various tables for CSROW based on CPU |
| 2880 | * revision. |
| 2881 | * |
| 2882 | * Returns: |
| 2883 | * The number of PAGE_SIZE pages on the specified CSROW number it |
| 2884 | * encompasses |
| 2885 | * |
| 2886 | */ |
Yazen Ghannam | eb77e6b | 2017-04-27 12:11:54 -0500 | [diff] [blame] | 2887 | static u32 get_csrow_nr_pages(struct amd64_pvt *pvt, u8 dct, int csrow_nr_orig) |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2888 | { |
Ashish Shenoy | f92cae4 | 2012-02-22 17:20:38 -0800 | [diff] [blame] | 2889 | u32 dbam = dct ? pvt->dbam1 : pvt->dbam0; |
Yazen Ghannam | eb77e6b | 2017-04-27 12:11:54 -0500 | [diff] [blame] | 2890 | int csrow_nr = csrow_nr_orig; |
| 2891 | u32 cs_mode, nr_pages; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2892 | |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 2893 | if (!pvt->umc) { |
Yazen Ghannam | eb77e6b | 2017-04-27 12:11:54 -0500 | [diff] [blame] | 2894 | csrow_nr >>= 1; |
Yazen Ghannam | e53a3b2 | 2019-08-21 23:59:59 +0000 | [diff] [blame] | 2895 | cs_mode = DBAM_DIMM(csrow_nr, dbam); |
| 2896 | } else { |
| 2897 | cs_mode = f17_get_cs_mode(csrow_nr >> 1, dct, pvt); |
| 2898 | } |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2899 | |
Yazen Ghannam | eb77e6b | 2017-04-27 12:11:54 -0500 | [diff] [blame] | 2900 | nr_pages = pvt->ops->dbam_to_cs(pvt, dct, cs_mode, csrow_nr); |
| 2901 | nr_pages <<= 20 - PAGE_SHIFT; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2902 | |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2903 | edac_dbg(0, "csrow: %d, channel: %d, DBAM idx: %d\n", |
Yazen Ghannam | eb77e6b | 2017-04-27 12:11:54 -0500 | [diff] [blame] | 2904 | csrow_nr_orig, dct, cs_mode); |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2905 | edac_dbg(0, "nr_pages/channel: %u\n", nr_pages); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2906 | |
| 2907 | return nr_pages; |
| 2908 | } |
| 2909 | |
Yazen Ghannam | 353a1fc | 2019-08-21 23:59:57 +0000 | [diff] [blame] | 2910 | static int init_csrows_df(struct mem_ctl_info *mci) |
| 2911 | { |
| 2912 | struct amd64_pvt *pvt = mci->pvt_info; |
| 2913 | enum edac_type edac_mode = EDAC_NONE; |
| 2914 | enum dev_type dev_type = DEV_UNKNOWN; |
| 2915 | struct dimm_info *dimm; |
| 2916 | int empty = 1; |
| 2917 | u8 umc, cs; |
| 2918 | |
| 2919 | if (mci->edac_ctl_cap & EDAC_FLAG_S16ECD16ED) { |
| 2920 | edac_mode = EDAC_S16ECD16ED; |
| 2921 | dev_type = DEV_X16; |
| 2922 | } else if (mci->edac_ctl_cap & EDAC_FLAG_S8ECD8ED) { |
| 2923 | edac_mode = EDAC_S8ECD8ED; |
| 2924 | dev_type = DEV_X8; |
| 2925 | } else if (mci->edac_ctl_cap & EDAC_FLAG_S4ECD4ED) { |
| 2926 | edac_mode = EDAC_S4ECD4ED; |
| 2927 | dev_type = DEV_X4; |
| 2928 | } else if (mci->edac_ctl_cap & EDAC_FLAG_SECDED) { |
| 2929 | edac_mode = EDAC_SECDED; |
| 2930 | } |
| 2931 | |
| 2932 | for_each_umc(umc) { |
| 2933 | for_each_chip_select(cs, umc, pvt) { |
| 2934 | if (!csrow_enabled(cs, umc, pvt)) |
| 2935 | continue; |
| 2936 | |
| 2937 | empty = 0; |
| 2938 | dimm = mci->csrows[cs]->channels[umc]->dimm; |
| 2939 | |
| 2940 | edac_dbg(1, "MC node: %d, csrow: %d\n", |
| 2941 | pvt->mc_node_id, cs); |
| 2942 | |
| 2943 | dimm->nr_pages = get_csrow_nr_pages(pvt, umc, cs); |
| 2944 | dimm->mtype = pvt->dram_type; |
| 2945 | dimm->edac_mode = edac_mode; |
| 2946 | dimm->dtype = dev_type; |
Yazen Ghannam | 466503d | 2019-10-22 20:35:14 +0000 | [diff] [blame] | 2947 | dimm->grain = 64; |
Yazen Ghannam | 353a1fc | 2019-08-21 23:59:57 +0000 | [diff] [blame] | 2948 | } |
| 2949 | } |
| 2950 | |
| 2951 | return empty; |
| 2952 | } |
| 2953 | |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2954 | /* |
| 2955 | * Initialize the array of csrow attribute instances, based on the values |
| 2956 | * from pci config hardware registers. |
| 2957 | */ |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 2958 | static int init_csrows(struct mem_ctl_info *mci) |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2959 | { |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2960 | struct amd64_pvt *pvt = mci->pvt_info; |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 2961 | enum edac_type edac_mode = EDAC_NONE; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2962 | struct csrow_info *csrow; |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 2963 | struct dimm_info *dimm; |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2964 | int i, j, empty = 1; |
Mauro Carvalho Chehab | a895bf8 | 2012-01-28 09:09:38 -0300 | [diff] [blame] | 2965 | int nr_pages = 0; |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2966 | u32 val; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2967 | |
Yazen Ghannam | 353a1fc | 2019-08-21 23:59:57 +0000 | [diff] [blame] | 2968 | if (pvt->umc) |
| 2969 | return init_csrows_df(mci); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2970 | |
Yazen Ghannam | 353a1fc | 2019-08-21 23:59:57 +0000 | [diff] [blame] | 2971 | amd64_read_pci_cfg(pvt->F3, NBCFG, &val); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2972 | |
Yazen Ghannam | 353a1fc | 2019-08-21 23:59:57 +0000 | [diff] [blame] | 2973 | pvt->nbcfg = val; |
| 2974 | |
| 2975 | edac_dbg(0, "node %d, NBCFG=0x%08x[ChipKillEccCap: %d|DramEccEn: %d]\n", |
| 2976 | pvt->mc_node_id, val, |
| 2977 | !!(val & NBCFG_CHIPKILL), !!(val & NBCFG_ECC_ENABLE)); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2978 | |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2979 | /* |
| 2980 | * We iterate over DCT0 here but we look at DCT1 in parallel, if needed. |
| 2981 | */ |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 2982 | for_each_chip_select(i, 0, pvt) { |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2983 | bool row_dct0 = !!csrow_enabled(i, 0, pvt); |
| 2984 | bool row_dct1 = false; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2985 | |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 2986 | if (pvt->fam != 0xf) |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2987 | row_dct1 = !!csrow_enabled(i, 1, pvt); |
| 2988 | |
| 2989 | if (!row_dct0 && !row_dct1) |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2990 | continue; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2991 | |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2992 | csrow = mci->csrows[i]; |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 2993 | empty = 0; |
Borislav Petkov | 11c75ea | 2010-11-29 19:49:02 +0100 | [diff] [blame] | 2994 | |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 2995 | edac_dbg(1, "MC node: %d, csrow: %d\n", |
| 2996 | pvt->mc_node_id, i); |
| 2997 | |
Mauro Carvalho Chehab | 1eef128 | 2013-03-11 09:07:46 -0300 | [diff] [blame] | 2998 | if (row_dct0) { |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 2999 | nr_pages = get_csrow_nr_pages(pvt, 0, i); |
Mauro Carvalho Chehab | 1eef128 | 2013-03-11 09:07:46 -0300 | [diff] [blame] | 3000 | csrow->channels[0]->dimm->nr_pages = nr_pages; |
| 3001 | } |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 3002 | |
| 3003 | /* K8 has only one DCT */ |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 3004 | if (pvt->fam != 0xf && row_dct1) { |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3005 | int row_dct1_pages = get_csrow_nr_pages(pvt, 1, i); |
Mauro Carvalho Chehab | 1eef128 | 2013-03-11 09:07:46 -0300 | [diff] [blame] | 3006 | |
| 3007 | csrow->channels[1]->dimm->nr_pages = row_dct1_pages; |
| 3008 | nr_pages += row_dct1_pages; |
| 3009 | } |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 3010 | |
Borislav Petkov | 10de649 | 2012-09-12 19:00:38 +0200 | [diff] [blame] | 3011 | edac_dbg(1, "Total csrow%d pages: %u\n", i, nr_pages); |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 3012 | |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3013 | /* Determine DIMM ECC mode: */ |
Yazen Ghannam | 353a1fc | 2019-08-21 23:59:57 +0000 | [diff] [blame] | 3014 | if (pvt->nbcfg & NBCFG_ECC_ENABLE) { |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3015 | edac_mode = (pvt->nbcfg & NBCFG_CHIPKILL) |
| 3016 | ? EDAC_S4ECD4ED |
| 3017 | : EDAC_SECDED; |
| 3018 | } |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 3019 | |
| 3020 | for (j = 0; j < pvt->channel_count; j++) { |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 3021 | dimm = csrow->channels[j]->dimm; |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 3022 | dimm->mtype = pvt->dram_type; |
Mauro Carvalho Chehab | de3910eb | 2012-04-24 15:05:43 -0300 | [diff] [blame] | 3023 | dimm->edac_mode = edac_mode; |
Yazen Ghannam | 466503d | 2019-10-22 20:35:14 +0000 | [diff] [blame] | 3024 | dimm->grain = 64; |
Mauro Carvalho Chehab | 084a4fc | 2012-01-27 18:38:08 -0300 | [diff] [blame] | 3025 | } |
Doug Thompson | 0ec449e | 2009-04-27 19:41:25 +0200 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | return empty; |
| 3029 | } |
Doug Thompson | d27bf6f | 2009-05-06 17:55:27 +0200 | [diff] [blame] | 3030 | |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3031 | /* get all cores on this DCT */ |
Daniel J Blueman | 8b84c8d | 2012-11-27 14:32:10 +0800 | [diff] [blame] | 3032 | static void get_cpus_on_this_dct_cpumask(struct cpumask *mask, u16 nid) |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3033 | { |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3034 | int cpu; |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3035 | |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3036 | for_each_online_cpu(cpu) |
| 3037 | if (amd_get_nb_id(cpu) == nid) |
| 3038 | cpumask_set_cpu(cpu, mask); |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3039 | } |
| 3040 | |
| 3041 | /* check MCG_CTL on all the cpus on this node */ |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3042 | static bool nb_mce_bank_enabled_on_node(u16 nid) |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3043 | { |
Rusty Russell | ba578cb | 2009-11-03 14:56:35 +1030 | [diff] [blame] | 3044 | cpumask_var_t mask; |
Borislav Petkov | 5054225 | 2009-12-11 18:14:40 +0100 | [diff] [blame] | 3045 | int cpu, nbe; |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3046 | bool ret = false; |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3047 | |
Rusty Russell | ba578cb | 2009-11-03 14:56:35 +1030 | [diff] [blame] | 3048 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 3049 | amd64_warn("%s: Error allocating mask\n", __func__); |
Rusty Russell | ba578cb | 2009-11-03 14:56:35 +1030 | [diff] [blame] | 3050 | return false; |
| 3051 | } |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3052 | |
Rusty Russell | ba578cb | 2009-11-03 14:56:35 +1030 | [diff] [blame] | 3053 | get_cpus_on_this_dct_cpumask(mask, nid); |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3054 | |
Rusty Russell | ba578cb | 2009-11-03 14:56:35 +1030 | [diff] [blame] | 3055 | rdmsr_on_cpus(mask, MSR_IA32_MCG_CTL, msrs); |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3056 | |
Rusty Russell | ba578cb | 2009-11-03 14:56:35 +1030 | [diff] [blame] | 3057 | for_each_cpu(cpu, mask) { |
Borislav Petkov | 5054225 | 2009-12-11 18:14:40 +0100 | [diff] [blame] | 3058 | struct msr *reg = per_cpu_ptr(msrs, cpu); |
Borislav Petkov | 5980bb9 | 2011-01-07 16:26:49 +0100 | [diff] [blame] | 3059 | nbe = reg->l & MSR_MCGCTL_NBE; |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3060 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3061 | edac_dbg(0, "core: %u, MCG_CTL: 0x%llx, NB MSR is %s\n", |
| 3062 | cpu, reg->q, |
| 3063 | (nbe ? "enabled" : "disabled")); |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3064 | |
| 3065 | if (!nbe) |
| 3066 | goto out; |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3067 | } |
| 3068 | ret = true; |
| 3069 | |
| 3070 | out: |
Rusty Russell | ba578cb | 2009-11-03 14:56:35 +1030 | [diff] [blame] | 3071 | free_cpumask_var(mask); |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3072 | return ret; |
| 3073 | } |
| 3074 | |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 3075 | static int toggle_ecc_err_reporting(struct ecc_settings *s, u16 nid, bool on) |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3076 | { |
| 3077 | cpumask_var_t cmask; |
Borislav Petkov | 5054225 | 2009-12-11 18:14:40 +0100 | [diff] [blame] | 3078 | int cpu; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3079 | |
| 3080 | if (!zalloc_cpumask_var(&cmask, GFP_KERNEL)) { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 3081 | amd64_warn("%s: error allocating mask\n", __func__); |
Pan Bian | 0de2788 | 2016-12-04 14:07:18 +0800 | [diff] [blame] | 3082 | return -ENOMEM; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3083 | } |
| 3084 | |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3085 | get_cpus_on_this_dct_cpumask(cmask, nid); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3086 | |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3087 | rdmsr_on_cpus(cmask, MSR_IA32_MCG_CTL, msrs); |
| 3088 | |
| 3089 | for_each_cpu(cpu, cmask) { |
| 3090 | |
Borislav Petkov | 5054225 | 2009-12-11 18:14:40 +0100 | [diff] [blame] | 3091 | struct msr *reg = per_cpu_ptr(msrs, cpu); |
| 3092 | |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3093 | if (on) { |
Borislav Petkov | 5980bb9 | 2011-01-07 16:26:49 +0100 | [diff] [blame] | 3094 | if (reg->l & MSR_MCGCTL_NBE) |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3095 | s->flags.nb_mce_enable = 1; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3096 | |
Borislav Petkov | 5980bb9 | 2011-01-07 16:26:49 +0100 | [diff] [blame] | 3097 | reg->l |= MSR_MCGCTL_NBE; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3098 | } else { |
| 3099 | /* |
Borislav Petkov | d95cf4d | 2010-02-24 14:49:47 +0100 | [diff] [blame] | 3100 | * Turn off NB MCE reporting only when it was off before |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3101 | */ |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3102 | if (!s->flags.nb_mce_enable) |
Borislav Petkov | 5980bb9 | 2011-01-07 16:26:49 +0100 | [diff] [blame] | 3103 | reg->l &= ~MSR_MCGCTL_NBE; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3104 | } |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3105 | } |
| 3106 | wrmsr_on_cpus(cmask, MSR_IA32_MCG_CTL, msrs); |
| 3107 | |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3108 | free_cpumask_var(cmask); |
| 3109 | |
| 3110 | return 0; |
| 3111 | } |
| 3112 | |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 3113 | static bool enable_ecc_error_reporting(struct ecc_settings *s, u16 nid, |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3114 | struct pci_dev *F3) |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3115 | { |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3116 | bool ret = true; |
Borislav Petkov | c9f4f26 | 2010-12-22 19:48:20 +0100 | [diff] [blame] | 3117 | u32 value, mask = 0x3; /* UECC/CECC enable */ |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3118 | |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3119 | if (toggle_ecc_err_reporting(s, nid, ON)) { |
| 3120 | amd64_warn("Error enabling ECC reporting over MCGCTL!\n"); |
| 3121 | return false; |
| 3122 | } |
| 3123 | |
Borislav Petkov | c9f4f26 | 2010-12-22 19:48:20 +0100 | [diff] [blame] | 3124 | amd64_read_pci_cfg(F3, NBCTL, &value); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3125 | |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3126 | s->old_nbctl = value & mask; |
| 3127 | s->nbctl_valid = true; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3128 | |
| 3129 | value |= mask; |
Borislav Petkov | c9f4f26 | 2010-12-22 19:48:20 +0100 | [diff] [blame] | 3130 | amd64_write_pci_cfg(F3, NBCTL, value); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3131 | |
Borislav Petkov | a97fa68 | 2010-12-23 14:07:18 +0100 | [diff] [blame] | 3132 | amd64_read_pci_cfg(F3, NBCFG, &value); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3133 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3134 | edac_dbg(0, "1: node %d, NBCFG=0x%08x[DramEccEn: %d]\n", |
| 3135 | nid, value, !!(value & NBCFG_ECC_ENABLE)); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3136 | |
Borislav Petkov | a97fa68 | 2010-12-23 14:07:18 +0100 | [diff] [blame] | 3137 | if (!(value & NBCFG_ECC_ENABLE)) { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 3138 | amd64_warn("DRAM ECC disabled on this node, enabling...\n"); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3139 | |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3140 | s->flags.nb_ecc_prev = 0; |
Borislav Petkov | d95cf4d | 2010-02-24 14:49:47 +0100 | [diff] [blame] | 3141 | |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3142 | /* Attempt to turn on DRAM ECC Enable */ |
Borislav Petkov | a97fa68 | 2010-12-23 14:07:18 +0100 | [diff] [blame] | 3143 | value |= NBCFG_ECC_ENABLE; |
| 3144 | amd64_write_pci_cfg(F3, NBCFG, value); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3145 | |
Borislav Petkov | a97fa68 | 2010-12-23 14:07:18 +0100 | [diff] [blame] | 3146 | amd64_read_pci_cfg(F3, NBCFG, &value); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3147 | |
Borislav Petkov | a97fa68 | 2010-12-23 14:07:18 +0100 | [diff] [blame] | 3148 | if (!(value & NBCFG_ECC_ENABLE)) { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 3149 | amd64_warn("Hardware rejected DRAM ECC enable," |
| 3150 | "check memory DIMM configuration.\n"); |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3151 | ret = false; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3152 | } else { |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 3153 | amd64_info("Hardware accepted DRAM ECC Enable\n"); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3154 | } |
Borislav Petkov | d95cf4d | 2010-02-24 14:49:47 +0100 | [diff] [blame] | 3155 | } else { |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3156 | s->flags.nb_ecc_prev = 1; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3157 | } |
Borislav Petkov | d95cf4d | 2010-02-24 14:49:47 +0100 | [diff] [blame] | 3158 | |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3159 | edac_dbg(0, "2: node %d, NBCFG=0x%08x[DramEccEn: %d]\n", |
| 3160 | nid, value, !!(value & NBCFG_ECC_ENABLE)); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3161 | |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3162 | return ret; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3163 | } |
| 3164 | |
Daniel J Blueman | c7e5301 | 2012-11-30 16:44:20 +0800 | [diff] [blame] | 3165 | static void restore_ecc_error_reporting(struct ecc_settings *s, u16 nid, |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3166 | struct pci_dev *F3) |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3167 | { |
Borislav Petkov | c9f4f26 | 2010-12-22 19:48:20 +0100 | [diff] [blame] | 3168 | u32 value, mask = 0x3; /* UECC/CECC enable */ |
| 3169 | |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3170 | if (!s->nbctl_valid) |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3171 | return; |
| 3172 | |
Borislav Petkov | c9f4f26 | 2010-12-22 19:48:20 +0100 | [diff] [blame] | 3173 | amd64_read_pci_cfg(F3, NBCTL, &value); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3174 | value &= ~mask; |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3175 | value |= s->old_nbctl; |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3176 | |
Borislav Petkov | c9f4f26 | 2010-12-22 19:48:20 +0100 | [diff] [blame] | 3177 | amd64_write_pci_cfg(F3, NBCTL, value); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3178 | |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3179 | /* restore previous BIOS DRAM ECC "off" setting we force-enabled */ |
| 3180 | if (!s->flags.nb_ecc_prev) { |
Borislav Petkov | a97fa68 | 2010-12-23 14:07:18 +0100 | [diff] [blame] | 3181 | amd64_read_pci_cfg(F3, NBCFG, &value); |
| 3182 | value &= ~NBCFG_ECC_ENABLE; |
| 3183 | amd64_write_pci_cfg(F3, NBCFG, value); |
Borislav Petkov | d95cf4d | 2010-02-24 14:49:47 +0100 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | /* restore the NB Enable MCGCTL bit */ |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3187 | if (toggle_ecc_err_reporting(s, nid, OFF)) |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 3188 | amd64_warn("Error restoring NB MCGCTL settings!\n"); |
Borislav Petkov | f6d6ae9 | 2009-11-03 15:29:26 +0100 | [diff] [blame] | 3189 | } |
| 3190 | |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3191 | /* |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3192 | * EDAC requires that the BIOS have ECC enabled before |
| 3193 | * taking over the processing of ECC errors. A command line |
| 3194 | * option allows to force-enable hardware ECC later in |
| 3195 | * enable_ecc_error_reporting(). |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3196 | */ |
Borislav Petkov | cab4d27 | 2010-02-11 17:15:57 +0100 | [diff] [blame] | 3197 | static const char *ecc_msg = |
| 3198 | "ECC disabled in the BIOS or no ECC capability, module will not load.\n" |
| 3199 | " Either enable ECC checking or force module loading by setting " |
| 3200 | "'ecc_enable_override'.\n" |
| 3201 | " (Note that use of the override may cause unknown side effects.)\n"; |
Borislav Petkov | be3468e | 2009-08-05 15:47:22 +0200 | [diff] [blame] | 3202 | |
Yazen Ghannam | 1c9b08b | 2019-10-22 20:35:12 +0000 | [diff] [blame] | 3203 | static bool ecc_enabled(struct amd64_pvt *pvt) |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3204 | { |
Yazen Ghannam | 1c9b08b | 2019-10-22 20:35:12 +0000 | [diff] [blame] | 3205 | u16 nid = pvt->mc_node_id; |
Borislav Petkov | 0672453 | 2009-09-16 13:05:46 +0200 | [diff] [blame] | 3206 | bool nb_mce_en = false; |
Yazen Ghannam | 196b79f | 2016-11-17 17:57:34 -0500 | [diff] [blame] | 3207 | u8 ecc_en = 0, i; |
| 3208 | u32 value; |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3209 | |
Yazen Ghannam | 196b79f | 2016-11-17 17:57:34 -0500 | [diff] [blame] | 3210 | if (boot_cpu_data.x86 >= 0x17) { |
| 3211 | u8 umc_en_mask = 0, ecc_en_mask = 0; |
Yazen Ghannam | 1c9b08b | 2019-10-22 20:35:12 +0000 | [diff] [blame] | 3212 | struct amd64_umc *umc; |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3213 | |
Yazen Ghannam | 4d30d2b | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 3214 | for_each_umc(i) { |
Yazen Ghannam | 1c9b08b | 2019-10-22 20:35:12 +0000 | [diff] [blame] | 3215 | umc = &pvt->umc[i]; |
Yazen Ghannam | 196b79f | 2016-11-17 17:57:34 -0500 | [diff] [blame] | 3216 | |
| 3217 | /* Only check enabled UMCs. */ |
Yazen Ghannam | 1c9b08b | 2019-10-22 20:35:12 +0000 | [diff] [blame] | 3218 | if (!(umc->sdp_ctrl & UMC_SDP_INIT)) |
Yazen Ghannam | 196b79f | 2016-11-17 17:57:34 -0500 | [diff] [blame] | 3219 | continue; |
| 3220 | |
| 3221 | umc_en_mask |= BIT(i); |
| 3222 | |
Yazen Ghannam | 1c9b08b | 2019-10-22 20:35:12 +0000 | [diff] [blame] | 3223 | if (umc->umc_cap_hi & UMC_ECC_ENABLED) |
Yazen Ghannam | 196b79f | 2016-11-17 17:57:34 -0500 | [diff] [blame] | 3224 | ecc_en_mask |= BIT(i); |
| 3225 | } |
| 3226 | |
| 3227 | /* Check whether at least one UMC is enabled: */ |
| 3228 | if (umc_en_mask) |
| 3229 | ecc_en = umc_en_mask == ecc_en_mask; |
Yazen Ghannam | 11ab1ca | 2017-01-27 11:24:19 -0600 | [diff] [blame] | 3230 | else |
| 3231 | edac_dbg(0, "Node %d: No enabled UMCs.\n", nid); |
Yazen Ghannam | 196b79f | 2016-11-17 17:57:34 -0500 | [diff] [blame] | 3232 | |
| 3233 | /* Assume UMC MCA banks are enabled. */ |
| 3234 | nb_mce_en = true; |
| 3235 | } else { |
Yazen Ghannam | 1c9b08b | 2019-10-22 20:35:12 +0000 | [diff] [blame] | 3236 | amd64_read_pci_cfg(pvt->F3, NBCFG, &value); |
Yazen Ghannam | 196b79f | 2016-11-17 17:57:34 -0500 | [diff] [blame] | 3237 | |
| 3238 | ecc_en = !!(value & NBCFG_ECC_ENABLE); |
| 3239 | |
| 3240 | nb_mce_en = nb_mce_bank_enabled_on_node(nid); |
| 3241 | if (!nb_mce_en) |
Yazen Ghannam | 11ab1ca | 2017-01-27 11:24:19 -0600 | [diff] [blame] | 3242 | edac_dbg(0, "NB MCE bank disabled, set MSR 0x%08x[4] on node %d to enable.\n", |
Yazen Ghannam | 196b79f | 2016-11-17 17:57:34 -0500 | [diff] [blame] | 3243 | MSR_IA32_MCG_CTL, nid); |
| 3244 | } |
| 3245 | |
Yazen Ghannam | 11ab1ca | 2017-01-27 11:24:19 -0600 | [diff] [blame] | 3246 | amd64_info("Node %d: DRAM ECC %s.\n", |
| 3247 | nid, (ecc_en ? "enabled" : "disabled")); |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3248 | |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3249 | if (!ecc_en || !nb_mce_en) { |
Yazen Ghannam | 11ab1ca | 2017-01-27 11:24:19 -0600 | [diff] [blame] | 3250 | amd64_info("%s", ecc_msg); |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3251 | return false; |
Borislav Petkov | 43f5e68 | 2009-12-21 18:55:18 +0100 | [diff] [blame] | 3252 | } |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3253 | return true; |
Doug Thompson | f943199 | 2009-04-27 19:46:08 +0200 | [diff] [blame] | 3254 | } |
| 3255 | |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3256 | static inline void |
| 3257 | f17h_determine_edac_ctl_cap(struct mem_ctl_info *mci, struct amd64_pvt *pvt) |
| 3258 | { |
Yazen Ghannam | f8be8e5 | 2019-08-21 23:59:56 +0000 | [diff] [blame] | 3259 | u8 i, ecc_en = 1, cpk_en = 1, dev_x4 = 1, dev_x16 = 1; |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3260 | |
Yazen Ghannam | 4d30d2b | 2019-02-28 15:36:10 +0000 | [diff] [blame] | 3261 | for_each_umc(i) { |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3262 | if (pvt->umc[i].sdp_ctrl & UMC_SDP_INIT) { |
| 3263 | ecc_en &= !!(pvt->umc[i].umc_cap_hi & UMC_ECC_ENABLED); |
| 3264 | cpk_en &= !!(pvt->umc[i].umc_cap_hi & UMC_ECC_CHIPKILL_CAP); |
Yazen Ghannam | f8be8e5 | 2019-08-21 23:59:56 +0000 | [diff] [blame] | 3265 | |
| 3266 | dev_x4 &= !!(pvt->umc[i].dimm_cfg & BIT(6)); |
| 3267 | dev_x16 &= !!(pvt->umc[i].dimm_cfg & BIT(7)); |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | /* Set chipkill only if ECC is enabled: */ |
| 3272 | if (ecc_en) { |
| 3273 | mci->edac_ctl_cap |= EDAC_FLAG_SECDED; |
| 3274 | |
Yazen Ghannam | f8be8e5 | 2019-08-21 23:59:56 +0000 | [diff] [blame] | 3275 | if (!cpk_en) |
| 3276 | return; |
| 3277 | |
| 3278 | if (dev_x4) |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3279 | mci->edac_ctl_cap |= EDAC_FLAG_S4ECD4ED; |
Yazen Ghannam | f8be8e5 | 2019-08-21 23:59:56 +0000 | [diff] [blame] | 3280 | else if (dev_x16) |
| 3281 | mci->edac_ctl_cap |= EDAC_FLAG_S16ECD16ED; |
| 3282 | else |
| 3283 | mci->edac_ctl_cap |= EDAC_FLAG_S8ECD8ED; |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3284 | } |
| 3285 | } |
| 3286 | |
Yazen Ghannam | 38ddd4d | 2019-10-22 20:35:09 +0000 | [diff] [blame] | 3287 | static void setup_mci_misc_attrs(struct mem_ctl_info *mci) |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3288 | { |
| 3289 | struct amd64_pvt *pvt = mci->pvt_info; |
| 3290 | |
| 3291 | mci->mtype_cap = MEM_FLAG_DDR2 | MEM_FLAG_RDDR2; |
| 3292 | mci->edac_ctl_cap = EDAC_FLAG_NONE; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3293 | |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3294 | if (pvt->umc) { |
| 3295 | f17h_determine_edac_ctl_cap(mci, pvt); |
| 3296 | } else { |
| 3297 | if (pvt->nbcap & NBCAP_SECDED) |
| 3298 | mci->edac_ctl_cap |= EDAC_FLAG_SECDED; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3299 | |
Yazen Ghannam | 2d09d8f | 2016-11-29 08:51:56 -0600 | [diff] [blame] | 3300 | if (pvt->nbcap & NBCAP_CHIPKILL) |
| 3301 | mci->edac_ctl_cap |= EDAC_FLAG_S4ECD4ED; |
| 3302 | } |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3303 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3304 | mci->edac_cap = determine_edac_cap(pvt); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3305 | mci->mod_name = EDAC_MOD_STR; |
Yazen Ghannam | 38ddd4d | 2019-10-22 20:35:09 +0000 | [diff] [blame] | 3306 | mci->ctl_name = fam_type->ctl_name; |
Yazen Ghannam | e7934b7 | 2016-11-17 17:57:30 -0500 | [diff] [blame] | 3307 | mci->dev_name = pci_name(pvt->F3); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3308 | mci->ctl_page_to_phys = NULL; |
| 3309 | |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3310 | /* memory scrubber interface */ |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3311 | mci->set_sdram_scrub_rate = set_scrub_rate; |
| 3312 | mci->get_sdram_scrub_rate = get_scrub_rate; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3313 | } |
| 3314 | |
Borislav Petkov | 0092b20 | 2010-10-01 19:20:05 +0200 | [diff] [blame] | 3315 | /* |
| 3316 | * returns a pointer to the family descriptor on success, NULL otherwise. |
| 3317 | */ |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3318 | static struct amd64_family_type *per_family_init(struct amd64_pvt *pvt) |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 3319 | { |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 3320 | pvt->ext_model = boot_cpu_data.x86_model >> 4; |
Jia Zhang | b399151 | 2018-01-01 09:52:10 +0800 | [diff] [blame] | 3321 | pvt->stepping = boot_cpu_data.x86_stepping; |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 3322 | pvt->model = boot_cpu_data.x86_model; |
| 3323 | pvt->fam = boot_cpu_data.x86; |
| 3324 | |
| 3325 | switch (pvt->fam) { |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 3326 | case 0xf: |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3327 | fam_type = &family_types[K8_CPUS]; |
| 3328 | pvt->ops = &family_types[K8_CPUS].ops; |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 3329 | break; |
Borislav Petkov | df71a05 | 2011-01-19 18:15:10 +0100 | [diff] [blame] | 3330 | |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 3331 | case 0x10: |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3332 | fam_type = &family_types[F10_CPUS]; |
| 3333 | pvt->ops = &family_types[F10_CPUS].ops; |
Borislav Petkov | df71a05 | 2011-01-19 18:15:10 +0100 | [diff] [blame] | 3334 | break; |
| 3335 | |
| 3336 | case 0x15: |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 3337 | if (pvt->model == 0x30) { |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3338 | fam_type = &family_types[F15_M30H_CPUS]; |
| 3339 | pvt->ops = &family_types[F15_M30H_CPUS].ops; |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 3340 | break; |
Aravind Gopalakrishnan | a597d2a | 2014-10-30 12:16:09 +0100 | [diff] [blame] | 3341 | } else if (pvt->model == 0x60) { |
| 3342 | fam_type = &family_types[F15_M60H_CPUS]; |
| 3343 | pvt->ops = &family_types[F15_M60H_CPUS].ops; |
| 3344 | break; |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 3345 | } |
| 3346 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3347 | fam_type = &family_types[F15_CPUS]; |
| 3348 | pvt->ops = &family_types[F15_CPUS].ops; |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 3349 | break; |
| 3350 | |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 3351 | case 0x16: |
Aravind Gopalakrishnan | 85a8885 | 2014-02-20 10:28:46 -0600 | [diff] [blame] | 3352 | if (pvt->model == 0x30) { |
| 3353 | fam_type = &family_types[F16_M30H_CPUS]; |
| 3354 | pvt->ops = &family_types[F16_M30H_CPUS].ops; |
| 3355 | break; |
| 3356 | } |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3357 | fam_type = &family_types[F16_CPUS]; |
| 3358 | pvt->ops = &family_types[F16_CPUS].ops; |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 3359 | break; |
| 3360 | |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 3361 | case 0x17: |
Michael Jin | 8960de4 | 2018-08-16 15:28:40 -0400 | [diff] [blame] | 3362 | if (pvt->model >= 0x10 && pvt->model <= 0x2f) { |
| 3363 | fam_type = &family_types[F17_M10H_CPUS]; |
| 3364 | pvt->ops = &family_types[F17_M10H_CPUS].ops; |
| 3365 | break; |
Yazen Ghannam | 6e846239 | 2019-02-28 15:36:09 +0000 | [diff] [blame] | 3366 | } else if (pvt->model >= 0x30 && pvt->model <= 0x3f) { |
| 3367 | fam_type = &family_types[F17_M30H_CPUS]; |
| 3368 | pvt->ops = &family_types[F17_M30H_CPUS].ops; |
| 3369 | break; |
Isaac Vaughn | 3e443eb | 2019-09-06 23:21:38 +0000 | [diff] [blame] | 3370 | } else if (pvt->model >= 0x70 && pvt->model <= 0x7f) { |
| 3371 | fam_type = &family_types[F17_M70H_CPUS]; |
| 3372 | pvt->ops = &family_types[F17_M70H_CPUS].ops; |
| 3373 | break; |
Michael Jin | 8960de4 | 2018-08-16 15:28:40 -0400 | [diff] [blame] | 3374 | } |
Pu Wen | c4a3e94 | 2018-09-27 16:31:28 +0200 | [diff] [blame] | 3375 | /* fall through */ |
| 3376 | case 0x18: |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 3377 | fam_type = &family_types[F17_CPUS]; |
| 3378 | pvt->ops = &family_types[F17_CPUS].ops; |
Pu Wen | c4a3e94 | 2018-09-27 16:31:28 +0200 | [diff] [blame] | 3379 | |
| 3380 | if (pvt->fam == 0x18) |
| 3381 | family_types[F17_CPUS].ctl_name = "F18h"; |
Yazen Ghannam | f1cbbec | 2016-11-17 17:57:35 -0500 | [diff] [blame] | 3382 | break; |
| 3383 | |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 3384 | default: |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 3385 | amd64_err("Unsupported family!\n"); |
Borislav Petkov | 0092b20 | 2010-10-01 19:20:05 +0200 | [diff] [blame] | 3386 | return NULL; |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 3387 | } |
Borislav Petkov | 0092b20 | 2010-10-01 19:20:05 +0200 | [diff] [blame] | 3388 | |
Borislav Petkov | df71a05 | 2011-01-19 18:15:10 +0100 | [diff] [blame] | 3389 | amd64_info("%s %sdetected (node %d).\n", fam_type->ctl_name, |
Aravind Gopalakrishnan | 18b94f6 | 2013-08-09 11:54:49 -0500 | [diff] [blame] | 3390 | (pvt->fam == 0xf ? |
Borislav Petkov | 24f9a7f | 2010-10-07 18:29:15 +0200 | [diff] [blame] | 3391 | (pvt->ext_model >= K8_REV_F ? "revF or later " |
| 3392 | : "revE or earlier ") |
| 3393 | : ""), pvt->mc_node_id); |
Borislav Petkov | 0092b20 | 2010-10-01 19:20:05 +0200 | [diff] [blame] | 3394 | return fam_type; |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 3395 | } |
| 3396 | |
Takashi Iwai | e339f1e | 2015-02-04 11:48:53 +0100 | [diff] [blame] | 3397 | static const struct attribute_group *amd64_edac_attr_groups[] = { |
| 3398 | #ifdef CONFIG_EDAC_DEBUG |
| 3399 | &amd64_edac_dbg_group, |
| 3400 | #endif |
| 3401 | #ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION |
| 3402 | &amd64_edac_inj_group, |
| 3403 | #endif |
| 3404 | NULL |
| 3405 | }; |
| 3406 | |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3407 | static int hw_info_get(struct amd64_pvt *pvt) |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3408 | { |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 3409 | u16 pci_id1, pci_id2; |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3410 | int ret = -EINVAL; |
Borislav Petkov | 395ae78 | 2010-10-01 18:38:19 +0200 | [diff] [blame] | 3411 | |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 3412 | if (pvt->fam >= 0x17) { |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 3413 | pvt->umc = kcalloc(fam_type->max_mcs, sizeof(struct amd64_umc), GFP_KERNEL); |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3414 | if (!pvt->umc) |
| 3415 | return -ENOMEM; |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 3416 | |
| 3417 | pci_id1 = fam_type->f0_id; |
| 3418 | pci_id2 = fam_type->f6_id; |
| 3419 | } else { |
| 3420 | pci_id1 = fam_type->f1_id; |
| 3421 | pci_id2 = fam_type->f2_id; |
| 3422 | } |
| 3423 | |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3424 | ret = reserve_mc_sibling_devs(pvt, pci_id1, pci_id2); |
| 3425 | if (ret) |
| 3426 | return ret; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3427 | |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3428 | read_mc_regs(pvt); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3429 | |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3430 | return 0; |
| 3431 | } |
| 3432 | |
| 3433 | static void hw_info_put(struct amd64_pvt *pvt) |
| 3434 | { |
| 3435 | if (pvt->F0 || pvt->F1) |
| 3436 | free_mc_sibling_devs(pvt); |
| 3437 | |
| 3438 | kfree(pvt->umc); |
| 3439 | } |
| 3440 | |
| 3441 | static int init_one_instance(struct amd64_pvt *pvt) |
| 3442 | { |
| 3443 | struct mem_ctl_info *mci = NULL; |
| 3444 | struct edac_mc_layer layers[2]; |
| 3445 | int ret = -EINVAL; |
| 3446 | |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3447 | /* |
| 3448 | * We need to determine how many memory channels there are. Then use |
| 3449 | * that information for calculating the size of the dynamic instance |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3450 | * tables in the 'mci' structure. |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3451 | */ |
| 3452 | pvt->channel_count = pvt->ops->early_channel_count(pvt); |
| 3453 | if (pvt->channel_count < 0) |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3454 | return ret; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3455 | |
| 3456 | ret = -ENOMEM; |
Mauro Carvalho Chehab | ab5a503 | 2012-04-16 15:03:50 -0300 | [diff] [blame] | 3457 | layers[0].type = EDAC_MC_LAYER_CHIP_SELECT; |
| 3458 | layers[0].size = pvt->csels[0].b_cnt; |
| 3459 | layers[0].is_virt_csrow = true; |
| 3460 | layers[1].type = EDAC_MC_LAYER_CHANNEL; |
Borislav Petkov | f0a56c4 | 2013-07-23 20:01:23 +0200 | [diff] [blame] | 3461 | |
| 3462 | /* |
| 3463 | * Always allocate two channels since we can have setups with DIMMs on |
| 3464 | * only one channel. Also, this simplifies handling later for the price |
| 3465 | * of a couple of KBs tops. |
| 3466 | */ |
Yazen Ghannam | 5e4c552 | 2019-10-22 20:35:11 +0000 | [diff] [blame] | 3467 | layers[1].size = fam_type->max_mcs; |
Mauro Carvalho Chehab | ab5a503 | 2012-04-16 15:03:50 -0300 | [diff] [blame] | 3468 | layers[1].is_virt_csrow = false; |
Borislav Petkov | f0a56c4 | 2013-07-23 20:01:23 +0200 | [diff] [blame] | 3469 | |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3470 | mci = edac_mc_alloc(pvt->mc_node_id, ARRAY_SIZE(layers), layers, 0); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3471 | if (!mci) |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3472 | return ret; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3473 | |
| 3474 | mci->pvt_info = pvt; |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3475 | mci->pdev = &pvt->F3->dev; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3476 | |
Yazen Ghannam | 38ddd4d | 2019-10-22 20:35:09 +0000 | [diff] [blame] | 3477 | setup_mci_misc_attrs(mci); |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3478 | |
| 3479 | if (init_csrows(mci)) |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3480 | mci->edac_cap = EDAC_FLAG_NONE; |
| 3481 | |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3482 | ret = -ENODEV; |
Takashi Iwai | e339f1e | 2015-02-04 11:48:53 +0100 | [diff] [blame] | 3483 | if (edac_mc_add_mc_with_groups(mci, amd64_edac_attr_groups)) { |
Joe Perches | 956b9ba | 2012-04-29 17:08:39 -0300 | [diff] [blame] | 3484 | edac_dbg(1, "failed edac_mc_add_mc()\n"); |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3485 | edac_mc_free(mci); |
| 3486 | return ret; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3487 | } |
| 3488 | |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3489 | return 0; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3490 | } |
| 3491 | |
Yazen Ghannam | 582f94b | 2019-11-06 01:25:01 +0000 | [diff] [blame^] | 3492 | static bool instance_has_memory(struct amd64_pvt *pvt) |
| 3493 | { |
| 3494 | bool cs_enabled = false; |
| 3495 | int cs = 0, dct = 0; |
| 3496 | |
| 3497 | for (dct = 0; dct < fam_type->max_mcs; dct++) { |
| 3498 | for_each_chip_select(cs, dct, pvt) |
| 3499 | cs_enabled |= csrow_enabled(cs, dct, pvt); |
| 3500 | } |
| 3501 | |
| 3502 | return cs_enabled; |
| 3503 | } |
| 3504 | |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3505 | static int probe_one_instance(unsigned int nid) |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3506 | { |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3507 | struct pci_dev *F3 = node_to_amd_nb(nid)->misc; |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3508 | struct amd64_pvt *pvt = NULL; |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3509 | struct ecc_settings *s; |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3510 | int ret; |
Borislav Petkov | b8cfa02 | 2010-10-01 19:35:38 +0200 | [diff] [blame] | 3511 | |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3512 | ret = -ENOMEM; |
| 3513 | s = kzalloc(sizeof(struct ecc_settings), GFP_KERNEL); |
| 3514 | if (!s) |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3515 | goto err_out; |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3516 | |
| 3517 | ecc_stngs[nid] = s; |
| 3518 | |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3519 | pvt = kzalloc(sizeof(struct amd64_pvt), GFP_KERNEL); |
| 3520 | if (!pvt) |
| 3521 | goto err_settings; |
| 3522 | |
| 3523 | pvt->mc_node_id = nid; |
| 3524 | pvt->F3 = F3; |
| 3525 | |
| 3526 | fam_type = per_family_init(pvt); |
| 3527 | if (!fam_type) |
| 3528 | goto err_enable; |
| 3529 | |
| 3530 | ret = hw_info_get(pvt); |
| 3531 | if (ret < 0) |
| 3532 | goto err_enable; |
| 3533 | |
Yazen Ghannam | 582f94b | 2019-11-06 01:25:01 +0000 | [diff] [blame^] | 3534 | ret = 0; |
| 3535 | if (!instance_has_memory(pvt)) { |
| 3536 | amd64_info("Node %d: No DIMMs detected.\n", nid); |
| 3537 | goto err_enable; |
| 3538 | } |
| 3539 | |
Yazen Ghannam | 1c9b08b | 2019-10-22 20:35:12 +0000 | [diff] [blame] | 3540 | if (!ecc_enabled(pvt)) { |
Yazen Ghannam | 582f94b | 2019-11-06 01:25:01 +0000 | [diff] [blame^] | 3541 | ret = -ENODEV; |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3542 | |
| 3543 | if (!ecc_enable_override) |
| 3544 | goto err_enable; |
| 3545 | |
Yazen Ghannam | 044e7a4 | 2016-11-22 15:40:16 -0600 | [diff] [blame] | 3546 | if (boot_cpu_data.x86 >= 0x17) { |
| 3547 | amd64_warn("Forcing ECC on is not recommended on newer systems. Please enable ECC in BIOS."); |
| 3548 | goto err_enable; |
| 3549 | } else |
| 3550 | amd64_warn("Forcing ECC on!\n"); |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3551 | |
| 3552 | if (!enable_ecc_error_reporting(s, nid, F3)) |
| 3553 | goto err_enable; |
| 3554 | } |
| 3555 | |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3556 | ret = init_one_instance(pvt); |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3557 | if (ret < 0) { |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3558 | amd64_err("Error probing instance: %d\n", nid); |
Yazen Ghannam | 044e7a4 | 2016-11-22 15:40:16 -0600 | [diff] [blame] | 3559 | |
| 3560 | if (boot_cpu_data.x86 < 0x17) |
| 3561 | restore_ecc_error_reporting(s, nid, F3); |
Yazen Ghannam | 2b9b2c4 | 2017-01-24 16:32:24 -0600 | [diff] [blame] | 3562 | |
| 3563 | goto err_enable; |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3564 | } |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3565 | |
Yazen Ghannam | 582f94b | 2019-11-06 01:25:01 +0000 | [diff] [blame^] | 3566 | dump_misc_regs(pvt); |
| 3567 | |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3568 | return ret; |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3569 | |
| 3570 | err_enable: |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3571 | hw_info_put(pvt); |
| 3572 | kfree(pvt); |
| 3573 | |
| 3574 | err_settings: |
Borislav Petkov | 2299ef7 | 2010-10-15 17:44:04 +0200 | [diff] [blame] | 3575 | kfree(s); |
| 3576 | ecc_stngs[nid] = NULL; |
| 3577 | |
| 3578 | err_out: |
| 3579 | return ret; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3580 | } |
| 3581 | |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3582 | static void remove_one_instance(unsigned int nid) |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3583 | { |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3584 | struct pci_dev *F3 = node_to_amd_nb(nid)->misc; |
| 3585 | struct ecc_settings *s = ecc_stngs[nid]; |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3586 | struct mem_ctl_info *mci; |
| 3587 | struct amd64_pvt *pvt; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3588 | |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3589 | mci = find_mci_by_dev(&F3->dev); |
Borislav Petkov | a4b4bed | 2013-08-10 13:54:48 +0200 | [diff] [blame] | 3590 | WARN_ON(!mci); |
| 3591 | |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3592 | /* Remove from EDAC CORE tracking list */ |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3593 | mci = edac_mc_del_mc(&F3->dev); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3594 | if (!mci) |
| 3595 | return; |
| 3596 | |
| 3597 | pvt = mci->pvt_info; |
| 3598 | |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3599 | restore_ecc_error_reporting(s, nid, F3); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3600 | |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3601 | kfree(ecc_stngs[nid]); |
| 3602 | ecc_stngs[nid] = NULL; |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3603 | |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3604 | /* Free the EDAC CORE resources */ |
Borislav Petkov | 8f68ed9 | 2009-12-21 15:15:59 +0100 | [diff] [blame] | 3605 | mci->pvt_info = NULL; |
Borislav Petkov | 8f68ed9 | 2009-12-21 15:15:59 +0100 | [diff] [blame] | 3606 | |
Yazen Ghannam | 80355a3 | 2019-10-22 20:35:10 +0000 | [diff] [blame] | 3607 | hw_info_put(pvt); |
Borislav Petkov | 8f68ed9 | 2009-12-21 15:15:59 +0100 | [diff] [blame] | 3608 | kfree(pvt); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3609 | edac_mc_free(mci); |
| 3610 | } |
| 3611 | |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3612 | static void setup_pci_device(void) |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3613 | { |
| 3614 | struct mem_ctl_info *mci; |
| 3615 | struct amd64_pvt *pvt; |
| 3616 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3617 | if (pci_ctl) |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3618 | return; |
| 3619 | |
Borislav Petkov | 2ec591a | 2015-02-17 10:58:34 +0100 | [diff] [blame] | 3620 | mci = edac_mc_find(0); |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3621 | if (!mci) |
| 3622 | return; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3623 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3624 | pvt = mci->pvt_info; |
Yazen Ghannam | 936fc3a | 2016-11-17 17:57:36 -0500 | [diff] [blame] | 3625 | if (pvt->umc) |
| 3626 | pci_ctl = edac_pci_create_generic_ctl(&pvt->F0->dev, EDAC_MOD_STR); |
| 3627 | else |
| 3628 | pci_ctl = edac_pci_create_generic_ctl(&pvt->F2->dev, EDAC_MOD_STR); |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3629 | if (!pci_ctl) { |
| 3630 | pr_warn("%s(): Unable to create PCI control\n", __func__); |
| 3631 | pr_warn("%s(): PCI error report via EDAC not set\n", __func__); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | |
Yazen Ghannam | d6efab7 | 2016-09-15 19:07:17 -0500 | [diff] [blame] | 3635 | static const struct x86_cpu_id amd64_cpuids[] = { |
| 3636 | { X86_VENDOR_AMD, 0xF, X86_MODEL_ANY, X86_FEATURE_ANY, 0 }, |
| 3637 | { X86_VENDOR_AMD, 0x10, X86_MODEL_ANY, X86_FEATURE_ANY, 0 }, |
| 3638 | { X86_VENDOR_AMD, 0x15, X86_MODEL_ANY, X86_FEATURE_ANY, 0 }, |
| 3639 | { X86_VENDOR_AMD, 0x16, X86_MODEL_ANY, X86_FEATURE_ANY, 0 }, |
Yazen Ghannam | 95d3af6 | 2016-11-17 17:57:43 -0500 | [diff] [blame] | 3640 | { X86_VENDOR_AMD, 0x17, X86_MODEL_ANY, X86_FEATURE_ANY, 0 }, |
Pu Wen | c4a3e94 | 2018-09-27 16:31:28 +0200 | [diff] [blame] | 3641 | { X86_VENDOR_HYGON, 0x18, X86_MODEL_ANY, X86_FEATURE_ANY, 0 }, |
Yazen Ghannam | d6efab7 | 2016-09-15 19:07:17 -0500 | [diff] [blame] | 3642 | { } |
| 3643 | }; |
| 3644 | MODULE_DEVICE_TABLE(x86cpu, amd64_cpuids); |
| 3645 | |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3646 | static int __init amd64_edac_init(void) |
| 3647 | { |
Toshi Kani | 301375e | 2017-08-23 16:54:47 -0600 | [diff] [blame] | 3648 | const char *owner; |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3649 | int err = -ENODEV; |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3650 | int i; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3651 | |
Toshi Kani | 301375e | 2017-08-23 16:54:47 -0600 | [diff] [blame] | 3652 | owner = edac_get_owner(); |
| 3653 | if (owner && strncmp(owner, EDAC_MOD_STR, sizeof(EDAC_MOD_STR))) |
| 3654 | return -EBUSY; |
| 3655 | |
Yazen Ghannam | 1bd9900 | 2017-01-27 11:24:23 -0600 | [diff] [blame] | 3656 | if (!x86_match_cpu(amd64_cpuids)) |
| 3657 | return -ENODEV; |
| 3658 | |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 3659 | if (amd_cache_northbridges() < 0) |
Yazen Ghannam | 1bd9900 | 2017-01-27 11:24:23 -0600 | [diff] [blame] | 3660 | return -ENODEV; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3661 | |
Borislav Petkov | 6ba92fe | 2016-06-16 01:13:18 +0200 | [diff] [blame] | 3662 | opstate_init(); |
| 3663 | |
Borislav Petkov | cc4d886 | 2010-10-13 16:11:59 +0200 | [diff] [blame] | 3664 | err = -ENOMEM; |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 3665 | ecc_stngs = kcalloc(amd_nb_num(), sizeof(ecc_stngs[0]), GFP_KERNEL); |
Borislav Petkov | 2ec591a | 2015-02-17 10:58:34 +0100 | [diff] [blame] | 3666 | if (!ecc_stngs) |
Borislav Petkov | a9f0fbe | 2011-03-29 18:10:53 +0200 | [diff] [blame] | 3667 | goto err_free; |
Borislav Petkov | cc4d886 | 2010-10-13 16:11:59 +0200 | [diff] [blame] | 3668 | |
Borislav Petkov | 5054225 | 2009-12-11 18:14:40 +0100 | [diff] [blame] | 3669 | msrs = msrs_alloc(); |
Borislav Petkov | 56b34b9 | 2009-12-21 18:13:01 +0100 | [diff] [blame] | 3670 | if (!msrs) |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3671 | goto err_free; |
Borislav Petkov | 5054225 | 2009-12-11 18:14:40 +0100 | [diff] [blame] | 3672 | |
Yazen Ghannam | 2287c63 | 2017-01-13 09:52:19 -0600 | [diff] [blame] | 3673 | for (i = 0; i < amd_nb_num(); i++) { |
| 3674 | err = probe_one_instance(i); |
| 3675 | if (err) { |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3676 | /* unwind properly */ |
| 3677 | while (--i >= 0) |
| 3678 | remove_one_instance(i); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3679 | |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3680 | goto err_pci; |
| 3681 | } |
Yazen Ghannam | 2287c63 | 2017-01-13 09:52:19 -0600 | [diff] [blame] | 3682 | } |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3683 | |
Yazen Ghannam | 4688c9b | 2017-01-27 11:24:22 -0600 | [diff] [blame] | 3684 | if (!edac_has_mcs()) { |
| 3685 | err = -ENODEV; |
| 3686 | goto err_pci; |
| 3687 | } |
| 3688 | |
Yazen Ghannam | 234365f | 2017-01-24 16:32:25 -0600 | [diff] [blame] | 3689 | /* register stuff with EDAC MCE */ |
| 3690 | if (report_gart_errors) |
| 3691 | amd_report_gart_errors(true); |
| 3692 | |
| 3693 | if (boot_cpu_data.x86 >= 0x17) |
| 3694 | amd_register_ecc_decoder(decode_umc_error); |
| 3695 | else |
| 3696 | amd_register_ecc_decoder(decode_bus_error); |
| 3697 | |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3698 | setup_pci_device(); |
Tomasz Pala | f5b10c4 | 2014-11-02 11:22:12 +0100 | [diff] [blame] | 3699 | |
| 3700 | #ifdef CONFIG_X86_32 |
| 3701 | amd64_err("%s on 32-bit is unsupported. USE AT YOUR OWN RISK!\n", EDAC_MOD_STR); |
| 3702 | #endif |
| 3703 | |
Borislav Petkov | de0336b | 2016-04-27 12:21:21 +0200 | [diff] [blame] | 3704 | printk(KERN_INFO "AMD64 EDAC driver v%s\n", EDAC_AMD64_VERSION); |
| 3705 | |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3706 | return 0; |
Borislav Petkov | 56b34b9 | 2009-12-21 18:13:01 +0100 | [diff] [blame] | 3707 | |
Borislav Petkov | 56b34b9 | 2009-12-21 18:13:01 +0100 | [diff] [blame] | 3708 | err_pci: |
| 3709 | msrs_free(msrs); |
| 3710 | msrs = NULL; |
Borislav Petkov | cc4d886 | 2010-10-13 16:11:59 +0200 | [diff] [blame] | 3711 | |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3712 | err_free: |
Borislav Petkov | 360b7f3 | 2010-10-15 19:25:38 +0200 | [diff] [blame] | 3713 | kfree(ecc_stngs); |
| 3714 | ecc_stngs = NULL; |
| 3715 | |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3716 | return err; |
| 3717 | } |
| 3718 | |
| 3719 | static void __exit amd64_edac_exit(void) |
| 3720 | { |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3721 | int i; |
| 3722 | |
Borislav Petkov | d1ea71c | 2013-12-15 17:54:27 +0100 | [diff] [blame] | 3723 | if (pci_ctl) |
| 3724 | edac_pci_release_generic_ctl(pci_ctl); |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3725 | |
Yazen Ghannam | 234365f | 2017-01-24 16:32:25 -0600 | [diff] [blame] | 3726 | /* unregister from EDAC MCE */ |
| 3727 | amd_report_gart_errors(false); |
| 3728 | |
| 3729 | if (boot_cpu_data.x86 >= 0x17) |
| 3730 | amd_unregister_ecc_decoder(decode_umc_error); |
| 3731 | else |
| 3732 | amd_unregister_ecc_decoder(decode_bus_error); |
| 3733 | |
Borislav Petkov | 3f37a36 | 2016-05-06 19:44:27 +0200 | [diff] [blame] | 3734 | for (i = 0; i < amd_nb_num(); i++) |
| 3735 | remove_one_instance(i); |
Borislav Petkov | 5054225 | 2009-12-11 18:14:40 +0100 | [diff] [blame] | 3736 | |
Borislav Petkov | ae7bb7c | 2010-10-14 16:01:30 +0200 | [diff] [blame] | 3737 | kfree(ecc_stngs); |
| 3738 | ecc_stngs = NULL; |
| 3739 | |
Borislav Petkov | 5054225 | 2009-12-11 18:14:40 +0100 | [diff] [blame] | 3740 | msrs_free(msrs); |
| 3741 | msrs = NULL; |
Doug Thompson | 7d6034d | 2009-04-27 20:01:01 +0200 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | module_init(amd64_edac_init); |
| 3745 | module_exit(amd64_edac_exit); |
| 3746 | |
| 3747 | MODULE_LICENSE("GPL"); |
| 3748 | MODULE_AUTHOR("SoftwareBitMaker: Doug Thompson, " |
| 3749 | "Dave Peterson, Thayne Harbaugh"); |
| 3750 | MODULE_DESCRIPTION("MC support for AMD64 memory controllers - " |
| 3751 | EDAC_AMD64_VERSION); |
| 3752 | |
| 3753 | module_param(edac_op_state, int, 0444); |
| 3754 | MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); |