blob: d0e850eea50ac86c98a415101d1d4a3e9f0df684 [file] [log] [blame]
Borislav Petkovb70ef012009-06-25 19:32:38 +02001#include <linux/module.h>
2#include "edac_mce_amd.h"
Doug Thompsonb52401ce2009-05-06 17:57:20 +02003
Borislav Petkov549d0422009-07-24 13:51:42 +02004static bool report_gart_errors;
Borislav Petkovb69b29d2009-07-27 16:21:14 +02005static void (*nb_bus_decoder)(int node_id, struct err_regs *regs);
Borislav Petkov549d0422009-07-24 13:51:42 +02006
7void amd_report_gart_errors(bool v)
8{
9 report_gart_errors = v;
10}
11EXPORT_SYMBOL_GPL(amd_report_gart_errors);
12
Borislav Petkovb69b29d2009-07-27 16:21:14 +020013void amd_register_ecc_decoder(void (*f)(int, struct err_regs *))
Borislav Petkov549d0422009-07-24 13:51:42 +020014{
15 nb_bus_decoder = f;
16}
17EXPORT_SYMBOL_GPL(amd_register_ecc_decoder);
18
Borislav Petkovb69b29d2009-07-27 16:21:14 +020019void amd_unregister_ecc_decoder(void (*f)(int, struct err_regs *))
Borislav Petkov549d0422009-07-24 13:51:42 +020020{
21 if (nb_bus_decoder) {
22 WARN_ON(nb_bus_decoder != f);
23
24 nb_bus_decoder = NULL;
25 }
26}
27EXPORT_SYMBOL_GPL(amd_unregister_ecc_decoder);
28
Doug Thompsonb52401ce2009-05-06 17:57:20 +020029/*
30 * string representation for the different MCA reported error types, see F3x48
31 * or MSR0000_0411.
32 */
Borislav Petkov63375832010-09-06 18:13:39 +020033
34/* transaction type */
35const char *tt_msgs[] = { "INSN", "DATA", "GEN", "RESV" };
Borislav Petkovb70ef012009-06-25 19:32:38 +020036EXPORT_SYMBOL_GPL(tt_msgs);
Doug Thompsonb52401ce2009-05-06 17:57:20 +020037
Borislav Petkov63375832010-09-06 18:13:39 +020038/* cache level */
39const char *ll_msgs[] = { "RESV", "L1", "L2", "L3/GEN" };
Borislav Petkovb70ef012009-06-25 19:32:38 +020040EXPORT_SYMBOL_GPL(ll_msgs);
Doug Thompsonb52401ce2009-05-06 17:57:20 +020041
Borislav Petkov63375832010-09-06 18:13:39 +020042/* memory transaction type */
Doug Thompsonb52401ce2009-05-06 17:57:20 +020043const char *rrrr_msgs[] = {
Borislav Petkov63375832010-09-06 18:13:39 +020044 "GEN", "RD", "WR", "DRD", "DWR", "IRD", "PRF", "EV", "SNP"
Doug Thompsonb52401ce2009-05-06 17:57:20 +020045};
Borislav Petkovb70ef012009-06-25 19:32:38 +020046EXPORT_SYMBOL_GPL(rrrr_msgs);
Doug Thompsonb52401ce2009-05-06 17:57:20 +020047
Borislav Petkov63375832010-09-06 18:13:39 +020048/* participating processor */
49const char *pp_msgs[] = { "SRC", "RES", "OBS", "GEN" };
Borislav Petkovb70ef012009-06-25 19:32:38 +020050EXPORT_SYMBOL_GPL(pp_msgs);
Doug Thompsonb52401ce2009-05-06 17:57:20 +020051
Borislav Petkov63375832010-09-06 18:13:39 +020052/* request timeout */
53const char *to_msgs[] = { "no timeout", "timed out" };
Borislav Petkovb70ef012009-06-25 19:32:38 +020054EXPORT_SYMBOL_GPL(to_msgs);
Doug Thompsonb52401ce2009-05-06 17:57:20 +020055
Borislav Petkov63375832010-09-06 18:13:39 +020056/* memory or i/o */
57const char *ii_msgs[] = { "MEM", "RESV", "IO", "GEN" };
Borislav Petkovb70ef012009-06-25 19:32:38 +020058EXPORT_SYMBOL_GPL(ii_msgs);
Doug Thompsonb52401ce2009-05-06 17:57:20 +020059
Borislav Petkov1c43f2e2009-07-23 15:47:51 +020060/*
61 * Map the 4 or 5 (family-specific) bits of Extended Error code to the
62 * string table.
63 */
64const char *ext_msgs[] = {
65 "K8 ECC error", /* 0_0000b */
66 "CRC error on link", /* 0_0001b */
67 "Sync error packets on link", /* 0_0010b */
68 "Master Abort during link operation", /* 0_0011b */
69 "Target Abort during link operation", /* 0_0100b */
70 "Invalid GART PTE entry during table walk", /* 0_0101b */
71 "Unsupported atomic RMW command received", /* 0_0110b */
72 "WDT error: NB transaction timeout", /* 0_0111b */
73 "ECC/ChipKill ECC error", /* 0_1000b */
74 "SVM DEV Error", /* 0_1001b */
75 "Link Data error", /* 0_1010b */
76 "Link/L3/Probe Filter Protocol error", /* 0_1011b */
77 "NB Internal Arrays Parity error", /* 0_1100b */
78 "DRAM Address/Control Parity error", /* 0_1101b */
79 "Link Transmission error", /* 0_1110b */
80 "GART/DEV Table Walk Data error" /* 0_1111b */
81 "Res 0x100 error", /* 1_0000b */
82 "Res 0x101 error", /* 1_0001b */
83 "Res 0x102 error", /* 1_0010b */
84 "Res 0x103 error", /* 1_0011b */
85 "Res 0x104 error", /* 1_0100b */
86 "Res 0x105 error", /* 1_0101b */
87 "Res 0x106 error", /* 1_0110b */
88 "Res 0x107 error", /* 1_0111b */
89 "Res 0x108 error", /* 1_1000b */
90 "Res 0x109 error", /* 1_1001b */
91 "Res 0x10A error", /* 1_1010b */
92 "Res 0x10B error", /* 1_1011b */
93 "ECC error in L3 Cache Data", /* 1_1100b */
94 "L3 Cache Tag error", /* 1_1101b */
95 "L3 Cache LRU Parity error", /* 1_1110b */
96 "Probe Filter error" /* 1_1111b */
Doug Thompsonb52401ce2009-05-06 17:57:20 +020097};
Borislav Petkovb70ef012009-06-25 19:32:38 +020098EXPORT_SYMBOL_GPL(ext_msgs);
Borislav Petkov549d0422009-07-24 13:51:42 +020099
Borislav Petkov51966242009-07-28 13:50:43 +0200100static void amd_decode_dc_mce(u64 mc0_status)
101{
102 u32 ec = mc0_status & 0xffff;
103 u32 xec = (mc0_status >> 16) & 0xf;
104
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200105 pr_emerg(HW_ERR "Data Cache Error: ");
Borislav Petkov51966242009-07-28 13:50:43 +0200106
107 if (xec == 1 && TLB_ERROR(ec))
108 pr_cont(": %s TLB multimatch.\n", LL_MSG(ec));
109 else if (xec == 0) {
110 if (mc0_status & (1ULL << 40))
111 pr_cont(" during Data Scrub.\n");
112 else if (TLB_ERROR(ec))
113 pr_cont(": %s TLB parity error.\n", LL_MSG(ec));
114 else if (MEM_ERROR(ec)) {
115 u8 ll = ec & 0x3;
116 u8 tt = (ec >> 2) & 0x3;
117 u8 rrrr = (ec >> 4) & 0xf;
118
119 /* see F10h BKDG (31116), Table 92. */
120 if (ll == 0x1) {
121 if (tt != 0x1)
122 goto wrong_dc_mce;
123
124 pr_cont(": Data/Tag %s error.\n", RRRR_MSG(ec));
125
126 } else if (ll == 0x2 && rrrr == 0x3)
127 pr_cont(" during L1 linefill from L2.\n");
128 else
129 goto wrong_dc_mce;
130 } else if (BUS_ERROR(ec) && boot_cpu_data.x86 == 0xf)
131 pr_cont(" during system linefill.\n");
132 else
133 goto wrong_dc_mce;
134 } else
135 goto wrong_dc_mce;
136
137 return;
138
139wrong_dc_mce:
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200140 pr_emerg(HW_ERR "Corrupted DC MCE info?\n");
Borislav Petkov51966242009-07-28 13:50:43 +0200141}
142
Borislav Petkovab5535e2009-07-28 14:06:26 +0200143static void amd_decode_ic_mce(u64 mc1_status)
144{
145 u32 ec = mc1_status & 0xffff;
146 u32 xec = (mc1_status >> 16) & 0xf;
147
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200148 pr_emerg(HW_ERR "Instruction Cache Error");
Borislav Petkovab5535e2009-07-28 14:06:26 +0200149
150 if (xec == 1 && TLB_ERROR(ec))
151 pr_cont(": %s TLB multimatch.\n", LL_MSG(ec));
152 else if (xec == 0) {
153 if (TLB_ERROR(ec))
154 pr_cont(": %s TLB Parity error.\n", LL_MSG(ec));
155 else if (BUS_ERROR(ec)) {
156 if (boot_cpu_data.x86 == 0xf &&
157 (mc1_status & (1ULL << 58)))
158 pr_cont(" during system linefill.\n");
159 else
160 pr_cont(" during attempted NB data read.\n");
161 } else if (MEM_ERROR(ec)) {
162 u8 ll = ec & 0x3;
163 u8 rrrr = (ec >> 4) & 0xf;
164
165 if (ll == 0x2)
166 pr_cont(" during a linefill from L2.\n");
167 else if (ll == 0x1) {
168
169 switch (rrrr) {
170 case 0x5:
171 pr_cont(": Parity error during "
172 "data load.\n");
173 break;
174
175 case 0x7:
176 pr_cont(": Copyback Parity/Victim"
177 " error.\n");
178 break;
179
180 case 0x8:
181 pr_cont(": Tag Snoop error.\n");
182 break;
183
184 default:
185 goto wrong_ic_mce;
186 break;
187 }
188 }
189 } else
190 goto wrong_ic_mce;
191 } else
192 goto wrong_ic_mce;
193
194 return;
195
196wrong_ic_mce:
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200197 pr_emerg(HW_ERR "Corrupted IC MCE info?\n");
Borislav Petkovab5535e2009-07-28 14:06:26 +0200198}
199
Borislav Petkov56cad2d2009-07-28 14:14:24 +0200200static void amd_decode_bu_mce(u64 mc2_status)
201{
202 u32 ec = mc2_status & 0xffff;
203 u32 xec = (mc2_status >> 16) & 0xf;
204
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200205 pr_emerg(HW_ERR "Bus Unit Error");
Borislav Petkov56cad2d2009-07-28 14:14:24 +0200206
207 if (xec == 0x1)
208 pr_cont(" in the write data buffers.\n");
209 else if (xec == 0x3)
210 pr_cont(" in the victim data buffers.\n");
211 else if (xec == 0x2 && MEM_ERROR(ec))
212 pr_cont(": %s error in the L2 cache tags.\n", RRRR_MSG(ec));
213 else if (xec == 0x0) {
214 if (TLB_ERROR(ec))
215 pr_cont(": %s error in a Page Descriptor Cache or "
216 "Guest TLB.\n", TT_MSG(ec));
217 else if (BUS_ERROR(ec))
218 pr_cont(": %s/ECC error in data read from NB: %s.\n",
219 RRRR_MSG(ec), PP_MSG(ec));
220 else if (MEM_ERROR(ec)) {
221 u8 rrrr = (ec >> 4) & 0xf;
222
223 if (rrrr >= 0x7)
224 pr_cont(": %s error during data copyback.\n",
225 RRRR_MSG(ec));
226 else if (rrrr <= 0x1)
227 pr_cont(": %s parity/ECC error during data "
228 "access from L2.\n", RRRR_MSG(ec));
229 else
230 goto wrong_bu_mce;
231 } else
232 goto wrong_bu_mce;
233 } else
234 goto wrong_bu_mce;
235
236 return;
237
238wrong_bu_mce:
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200239 pr_emerg(HW_ERR "Corrupted BU MCE info?\n");
Borislav Petkov56cad2d2009-07-28 14:14:24 +0200240}
241
Borislav Petkovf9350ef2009-07-28 14:17:30 +0200242static void amd_decode_ls_mce(u64 mc3_status)
243{
244 u32 ec = mc3_status & 0xffff;
245 u32 xec = (mc3_status >> 16) & 0xf;
246
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200247 pr_emerg(HW_ERR "Load Store Error");
Borislav Petkovf9350ef2009-07-28 14:17:30 +0200248
249 if (xec == 0x0) {
250 u8 rrrr = (ec >> 4) & 0xf;
251
252 if (!BUS_ERROR(ec) || (rrrr != 0x3 && rrrr != 0x4))
253 goto wrong_ls_mce;
254
255 pr_cont(" during %s.\n", RRRR_MSG(ec));
256 }
257 return;
258
259wrong_ls_mce:
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200260 pr_emerg(HW_ERR "Corrupted LS MCE info?\n");
Borislav Petkovf9350ef2009-07-28 14:17:30 +0200261}
262
Borislav Petkov0ee8efa2010-08-30 12:34:19 +0200263void amd_decode_nb_mce(int node_id, struct err_regs *regs)
Borislav Petkov549d0422009-07-24 13:51:42 +0200264{
Borislav Petkov549d0422009-07-24 13:51:42 +0200265 u32 ec = ERROR_CODE(regs->nbsl);
Borislav Petkov549d0422009-07-24 13:51:42 +0200266
Borislav Petkov256f7272009-12-15 16:03:53 +0100267 /*
268 * GART TLB error reporting is disabled by default. Bail out early.
269 */
270 if (TLB_ERROR(ec) && !report_gart_errors)
271 return;
272
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200273 pr_emerg(HW_ERR "Northbridge Error, node %d", node_id);
Borislav Petkov549d0422009-07-24 13:51:42 +0200274
275 /*
276 * F10h, revD can disable ErrCpu[3:0] so check that first and also the
277 * value encoding has changed so interpret those differently
278 */
279 if ((boot_cpu_data.x86 == 0x10) &&
Borislav Petkovcec79242009-10-27 19:12:02 +0100280 (boot_cpu_data.x86_model > 7)) {
Borislav Petkov549d0422009-07-24 13:51:42 +0200281 if (regs->nbsh & K8_NBSH_ERR_CPU_VAL)
282 pr_cont(", core: %u\n", (u8)(regs->nbsh & 0xf));
283 } else {
Borislav Petkov5b89d2f2010-03-09 20:38:48 +0100284 u8 assoc_cpus = regs->nbsh & 0xf;
285
286 if (assoc_cpus > 0)
287 pr_cont(", core: %d", fls(assoc_cpus) - 1);
288
289 pr_cont("\n");
Borislav Petkov549d0422009-07-24 13:51:42 +0200290 }
291
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200292 pr_emerg(HW_ERR "%s.\n", EXT_ERR_MSG(regs->nbsl));
Borislav Petkovd93cc222009-07-28 10:56:15 +0200293
294 if (BUS_ERROR(ec) && nb_bus_decoder)
295 nb_bus_decoder(node_id, regs);
296}
297EXPORT_SYMBOL_GPL(amd_decode_nb_mce);
298
Borislav Petkov53bd5fe2009-07-28 14:20:46 +0200299static void amd_decode_fr_mce(u64 mc5_status)
300{
301 /* we have only one error signature so match all fields at once. */
302 if ((mc5_status & 0xffff) == 0x0f0f)
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200303 pr_emerg(HW_ERR " FR Error: CPU Watchdog timer expire.\n");
Borislav Petkov53bd5fe2009-07-28 14:20:46 +0200304 else
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200305 pr_emerg(HW_ERR "Corrupted FR MCE info?\n");
Borislav Petkov53bd5fe2009-07-28 14:20:46 +0200306}
307
Borislav Petkov63375832010-09-06 18:13:39 +0200308static inline void amd_decode_err_code(u16 ec)
Borislav Petkovd93cc222009-07-28 10:56:15 +0200309{
Borislav Petkov549d0422009-07-24 13:51:42 +0200310 if (TLB_ERROR(ec)) {
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200311 pr_emerg(HW_ERR "Transaction: %s, Cache Level: %s\n",
Borislav Petkov549d0422009-07-24 13:51:42 +0200312 TT_MSG(ec), LL_MSG(ec));
313 } else if (MEM_ERROR(ec)) {
Borislav Petkov63375832010-09-06 18:13:39 +0200314 pr_emerg(HW_ERR "Transaction: %s, Type: %s, Cache Level: %s\n",
Borislav Petkov549d0422009-07-24 13:51:42 +0200315 RRRR_MSG(ec), TT_MSG(ec), LL_MSG(ec));
316 } else if (BUS_ERROR(ec)) {
Borislav Petkov63375832010-09-06 18:13:39 +0200317 pr_emerg(HW_ERR "Transaction: %s (%s), %s, Cache Level: %s, "
Borislav Petkovd93cc222009-07-28 10:56:15 +0200318 "Participating Processor: %s\n",
319 RRRR_MSG(ec), II_MSG(ec), TO_MSG(ec), LL_MSG(ec),
320 PP_MSG(ec));
321 } else
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200322 pr_emerg(HW_ERR "Huh? Unknown MCE error 0x%x\n", ec);
Borislav Petkov549d0422009-07-24 13:51:42 +0200323}
Borislav Petkov549d0422009-07-24 13:51:42 +0200324
Borislav Petkovfb253192009-10-07 13:20:38 +0200325static int amd_decode_mce(struct notifier_block *nb, unsigned long val,
326 void *data)
Borislav Petkov549d0422009-07-24 13:51:42 +0200327{
Borislav Petkovfb253192009-10-07 13:20:38 +0200328 struct mce *m = (struct mce *)data;
Borislav Petkov549d0422009-07-24 13:51:42 +0200329 struct err_regs regs;
Borislav Petkovb69b29d2009-07-27 16:21:14 +0200330 int node, ecc;
Borislav Petkov549d0422009-07-24 13:51:42 +0200331
Borislav Petkovc9f281f2010-08-18 18:21:42 +0200332 pr_emerg(HW_ERR "MC%d_STATUS: ", m->bank);
Borislav Petkov549d0422009-07-24 13:51:42 +0200333
Borislav Petkov37b73702010-08-24 18:21:42 +0200334 pr_cont("%sorrected error, other errors lost: %s, "
Borislav Petkovb69b29d2009-07-27 16:21:14 +0200335 "CPU context corrupt: %s",
336 ((m->status & MCI_STATUS_UC) ? "Unc" : "C"),
Borislav Petkov37b73702010-08-24 18:21:42 +0200337 ((m->status & MCI_STATUS_OVER) ? "yes" : "no"),
Borislav Petkovb69b29d2009-07-27 16:21:14 +0200338 ((m->status & MCI_STATUS_PCC) ? "yes" : "no"));
Borislav Petkov549d0422009-07-24 13:51:42 +0200339
Borislav Petkovb69b29d2009-07-27 16:21:14 +0200340 /* do the two bits[14:13] together */
Borislav Petkov35d824b2010-04-30 15:19:02 +0200341 ecc = (m->status >> 45) & 0x3;
Borislav Petkovb69b29d2009-07-27 16:21:14 +0200342 if (ecc)
343 pr_cont(", %sECC Error", ((ecc == 2) ? "C" : "U"));
344
345 pr_cont("\n");
346
Borislav Petkov51966242009-07-28 13:50:43 +0200347 switch (m->bank) {
348 case 0:
349 amd_decode_dc_mce(m->status);
350 break;
Borislav Petkovd93cc222009-07-28 10:56:15 +0200351
Borislav Petkovab5535e2009-07-28 14:06:26 +0200352 case 1:
353 amd_decode_ic_mce(m->status);
354 break;
355
Borislav Petkov56cad2d2009-07-28 14:14:24 +0200356 case 2:
357 amd_decode_bu_mce(m->status);
358 break;
359
Borislav Petkovf9350ef2009-07-28 14:17:30 +0200360 case 3:
361 amd_decode_ls_mce(m->status);
362 break;
363
Borislav Petkov51966242009-07-28 13:50:43 +0200364 case 4:
Borislav Petkovb69b29d2009-07-27 16:21:14 +0200365 regs.nbsl = (u32) m->status;
366 regs.nbsh = (u32)(m->status >> 32);
367 regs.nbeal = (u32) m->addr;
368 regs.nbeah = (u32)(m->addr >> 32);
Andreas Herrmann6a812692009-09-16 11:33:40 +0200369 node = amd_get_nb_id(m->extcpu);
Borislav Petkovb69b29d2009-07-27 16:21:14 +0200370
Borislav Petkov0ee8efa2010-08-30 12:34:19 +0200371 amd_decode_nb_mce(node, &regs);
Borislav Petkov51966242009-07-28 13:50:43 +0200372 break;
373
Borislav Petkov53bd5fe2009-07-28 14:20:46 +0200374 case 5:
375 amd_decode_fr_mce(m->status);
376 break;
377
Borislav Petkov51966242009-07-28 13:50:43 +0200378 default:
379 break;
Borislav Petkovb69b29d2009-07-27 16:21:14 +0200380 }
Borislav Petkov51966242009-07-28 13:50:43 +0200381
382 amd_decode_err_code(m->status & 0xffff);
Borislav Petkovfb253192009-10-07 13:20:38 +0200383
384 return NOTIFY_STOP;
Borislav Petkov549d0422009-07-24 13:51:42 +0200385}
Ingo Molnarf436f8b2009-10-01 16:14:32 +0200386
Borislav Petkovfb253192009-10-07 13:20:38 +0200387static struct notifier_block amd_mce_dec_nb = {
388 .notifier_call = amd_decode_mce,
389};
390
Ingo Molnarf436f8b2009-10-01 16:14:32 +0200391static int __init mce_amd_init(void)
392{
393 /*
Borislav Petkove045c292010-08-06 18:55:45 +0200394 * We can decode MCEs for K8, F10h and F11h CPUs:
Ingo Molnarf436f8b2009-10-01 16:14:32 +0200395 */
Borislav Petkove045c292010-08-06 18:55:45 +0200396 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
397 return 0;
398
399 if (boot_cpu_data.x86 < 0xf || boot_cpu_data.x86 > 0x11)
400 return 0;
401
402 atomic_notifier_chain_register(&x86_mce_decoder_chain, &amd_mce_dec_nb);
Ingo Molnarf436f8b2009-10-01 16:14:32 +0200403
404 return 0;
405}
406early_initcall(mce_amd_init);
Borislav Petkov0d18b2e2009-10-02 15:31:48 +0200407
408#ifdef MODULE
409static void __exit mce_amd_exit(void)
410{
Borislav Petkovfb253192009-10-07 13:20:38 +0200411 atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &amd_mce_dec_nb);
Borislav Petkov0d18b2e2009-10-02 15:31:48 +0200412}
413
414MODULE_DESCRIPTION("AMD MCE decoder");
415MODULE_ALIAS("edac-mce-amd");
416MODULE_LICENSE("GPL");
417module_exit(mce_amd_exit);
418#endif