1 #include <linux/module.h>
2 #include <linux/slab.h>
6 static struct amd_decoder_ops *fam_ops;
8 static bool report_gart_errors;
9 static void (*nb_bus_decoder)(int node_id, struct mce *m, u32 nbcfg);
11 void amd_report_gart_errors(bool v)
13 report_gart_errors = v;
15 EXPORT_SYMBOL_GPL(amd_report_gart_errors);
17 void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32))
21 EXPORT_SYMBOL_GPL(amd_register_ecc_decoder);
23 void amd_unregister_ecc_decoder(void (*f)(int, struct mce *, u32))
26 WARN_ON(nb_bus_decoder != f);
28 nb_bus_decoder = NULL;
31 EXPORT_SYMBOL_GPL(amd_unregister_ecc_decoder);
34 * string representation for the different MCA reported error types, see F3x48
38 /* transaction type */
39 const char *tt_msgs[] = { "INSN", "DATA", "GEN", "RESV" };
40 EXPORT_SYMBOL_GPL(tt_msgs);
43 const char *ll_msgs[] = { "RESV", "L1", "L2", "L3/GEN" };
44 EXPORT_SYMBOL_GPL(ll_msgs);
46 /* memory transaction type */
47 const char *rrrr_msgs[] = {
48 "GEN", "RD", "WR", "DRD", "DWR", "IRD", "PRF", "EV", "SNP"
50 EXPORT_SYMBOL_GPL(rrrr_msgs);
52 /* participating processor */
53 const char *pp_msgs[] = { "SRC", "RES", "OBS", "GEN" };
54 EXPORT_SYMBOL_GPL(pp_msgs);
57 const char *to_msgs[] = { "no timeout", "timed out" };
58 EXPORT_SYMBOL_GPL(to_msgs);
61 const char *ii_msgs[] = { "MEM", "RESV", "IO", "GEN" };
62 EXPORT_SYMBOL_GPL(ii_msgs);
65 * Map the 4 or 5 (family-specific) bits of Extended Error code to the
68 const char *ext_msgs[] = {
69 "K8 ECC error", /* 0_0000b */
70 "CRC error on link", /* 0_0001b */
71 "Sync error packets on link", /* 0_0010b */
72 "Master Abort during link operation", /* 0_0011b */
73 "Target Abort during link operation", /* 0_0100b */
74 "Invalid GART PTE entry during table walk", /* 0_0101b */
75 "Unsupported atomic RMW command received", /* 0_0110b */
76 "WDT error: NB transaction timeout", /* 0_0111b */
77 "ECC/ChipKill ECC error", /* 0_1000b */
78 "SVM DEV Error", /* 0_1001b */
79 "Link Data error", /* 0_1010b */
80 "Link/L3/Probe Filter Protocol error", /* 0_1011b */
81 "NB Internal Arrays Parity error", /* 0_1100b */
82 "DRAM Address/Control Parity error", /* 0_1101b */
83 "Link Transmission error", /* 0_1110b */
84 "GART/DEV Table Walk Data error" /* 0_1111b */
85 "Res 0x100 error", /* 1_0000b */
86 "Res 0x101 error", /* 1_0001b */
87 "Res 0x102 error", /* 1_0010b */
88 "Res 0x103 error", /* 1_0011b */
89 "Res 0x104 error", /* 1_0100b */
90 "Res 0x105 error", /* 1_0101b */
91 "Res 0x106 error", /* 1_0110b */
92 "Res 0x107 error", /* 1_0111b */
93 "Res 0x108 error", /* 1_1000b */
94 "Res 0x109 error", /* 1_1001b */
95 "Res 0x10A error", /* 1_1010b */
96 "Res 0x10B error", /* 1_1011b */
97 "ECC error in L3 Cache Data", /* 1_1100b */
98 "L3 Cache Tag error", /* 1_1101b */
99 "L3 Cache LRU Parity error", /* 1_1110b */
100 "Probe Filter error" /* 1_1111b */
102 EXPORT_SYMBOL_GPL(ext_msgs);
104 static bool f10h_dc_mce(u16 ec)
106 u8 r4 = (ec >> 4) & 0xf;
110 pr_cont("during data scrub.\n");
119 pr_cont("during L1 linefill from L2.\n");
120 else if (ll == LL_L1)
121 pr_cont("Data/Tag %s error.\n", RRRR_MSG(ec));
128 static bool k8_dc_mce(u16 ec)
131 pr_cont("during system linefill.\n");
135 return f10h_dc_mce(ec);
138 static bool f14h_dc_mce(u16 ec)
140 u8 r4 = (ec >> 4) & 0xf;
142 u8 tt = (ec >> 2) & 0x3;
148 if (tt != TT_DATA || ll != LL_L1)
154 pr_cont("Data/Tag parity error due to %s.\n",
155 (r4 == R4_DRD ? "load/hw prf" : "store"));
158 pr_cont("Copyback parity error on a tag miss.\n");
161 pr_cont("Tag parity error during snoop.\n");
166 } else if (BUS_ERROR(ec)) {
168 if ((ii != II_MEM && ii != II_IO) || ll != LL_LG)
171 pr_cont("System read data error on a ");
175 pr_cont("TLB reload.\n");
193 static void amd_decode_dc_mce(struct mce *m)
195 u16 ec = m->status & 0xffff;
196 u8 xec = (m->status >> 16) & 0xf;
198 pr_emerg(HW_ERR "Data Cache Error: ");
200 /* TLB error signatures are the same across families */
202 u8 tt = (ec >> 2) & 0x3;
205 pr_cont("%s TLB %s.\n", LL_MSG(ec),
206 (xec ? "multimatch" : "parity error"));
213 if (!fam_ops->dc_mce(ec))
219 pr_emerg(HW_ERR "Corrupted DC MCE info?\n");
222 static bool k8_ic_mce(u16 ec)
225 u8 r4 = (ec >> 4) & 0xf;
232 pr_cont("during a linefill from L2.\n");
233 else if (ll == 0x1) {
236 pr_cont("Parity error during data load.\n");
240 pr_cont("Copyback Parity/Victim error.\n");
244 pr_cont("Tag Snoop error.\n");
257 static bool f14h_ic_mce(u16 ec)
260 u8 tt = (ec >> 2) & 0x3;
261 u8 r4 = (ec >> 4) & 0xf;
265 if (tt != 0 || ll != 1)
269 pr_cont("Data/tag array parity error for a tag hit.\n");
270 else if (r4 == R4_SNOOP)
271 pr_cont("Tag error during snoop/victimization.\n");
278 static void amd_decode_ic_mce(struct mce *m)
280 u16 ec = m->status & 0xffff;
281 u8 xec = (m->status >> 16) & 0xf;
283 pr_emerg(HW_ERR "Instruction Cache Error: ");
286 pr_cont("%s TLB %s.\n", LL_MSG(ec),
287 (xec ? "multimatch" : "parity error"));
288 else if (BUS_ERROR(ec)) {
289 bool k8 = (boot_cpu_data.x86 == 0xf && (m->status & BIT(58)));
291 pr_cont("during %s.\n", (k8 ? "system linefill" : "NB data read"));
292 } else if (fam_ops->ic_mce(ec))
295 pr_emerg(HW_ERR "Corrupted IC MCE info?\n");
298 static void amd_decode_bu_mce(struct mce *m)
300 u32 ec = m->status & 0xffff;
301 u32 xec = (m->status >> 16) & 0xf;
303 pr_emerg(HW_ERR "Bus Unit Error");
306 pr_cont(" in the write data buffers.\n");
308 pr_cont(" in the victim data buffers.\n");
309 else if (xec == 0x2 && MEM_ERROR(ec))
310 pr_cont(": %s error in the L2 cache tags.\n", RRRR_MSG(ec));
311 else if (xec == 0x0) {
313 pr_cont(": %s error in a Page Descriptor Cache or "
314 "Guest TLB.\n", TT_MSG(ec));
315 else if (BUS_ERROR(ec))
316 pr_cont(": %s/ECC error in data read from NB: %s.\n",
317 RRRR_MSG(ec), PP_MSG(ec));
318 else if (MEM_ERROR(ec)) {
319 u8 rrrr = (ec >> 4) & 0xf;
322 pr_cont(": %s error during data copyback.\n",
324 else if (rrrr <= 0x1)
325 pr_cont(": %s parity/ECC error during data "
326 "access from L2.\n", RRRR_MSG(ec));
337 pr_emerg(HW_ERR "Corrupted BU MCE info?\n");
340 static void amd_decode_ls_mce(struct mce *m)
342 u16 ec = m->status & 0xffff;
343 u8 xec = (m->status >> 16) & 0xf;
345 if (boot_cpu_data.x86 == 0x14) {
346 pr_emerg("You shouldn't be seeing an LS MCE on this cpu family,"
347 " please report on LKML.\n");
351 pr_emerg(HW_ERR "Load Store Error");
354 u8 r4 = (ec >> 4) & 0xf;
356 if (!BUS_ERROR(ec) || (r4 != R4_DRD && r4 != R4_DWR))
359 pr_cont(" during %s.\n", RRRR_MSG(ec));
366 pr_emerg(HW_ERR "Corrupted LS MCE info?\n");
369 void amd_decode_nb_mce(int node_id, struct mce *m, u32 nbcfg)
371 u32 ec = m->status & 0xffff;
372 u32 nbsh = (u32)(m->status >> 32);
373 u32 nbsl = (u32)m->status;
376 * GART TLB error reporting is disabled by default. Bail out early.
378 if (TLB_ERROR(ec) && !report_gart_errors)
381 pr_emerg(HW_ERR "Northbridge Error, node %d", node_id);
384 * F10h, revD can disable ErrCpu[3:0] so check that first and also the
385 * value encoding has changed so interpret those differently
387 if ((boot_cpu_data.x86 == 0x10) &&
388 (boot_cpu_data.x86_model > 7)) {
389 if (nbsh & K8_NBSH_ERR_CPU_VAL)
390 pr_cont(", core: %u\n", (u8)(nbsh & 0xf));
392 u8 assoc_cpus = nbsh & 0xf;
395 pr_cont(", core: %d", fls(assoc_cpus) - 1);
400 pr_emerg(HW_ERR "%s.\n", EXT_ERR_MSG(nbsl));
402 if (BUS_ERROR(ec) && nb_bus_decoder)
403 nb_bus_decoder(node_id, m, nbcfg);
405 EXPORT_SYMBOL_GPL(amd_decode_nb_mce);
407 static void amd_decode_fr_mce(struct mce *m)
409 /* we have only one error signature so match all fields at once. */
410 if ((m->status & 0xffff) == 0x0f0f)
411 pr_emerg(HW_ERR " FR Error: CPU Watchdog timer expire.\n");
413 pr_emerg(HW_ERR "Corrupted FR MCE info?\n");
416 static inline void amd_decode_err_code(u16 ec)
419 pr_emerg(HW_ERR "Transaction: %s, Cache Level: %s\n",
420 TT_MSG(ec), LL_MSG(ec));
421 } else if (MEM_ERROR(ec)) {
422 pr_emerg(HW_ERR "Transaction: %s, Type: %s, Cache Level: %s\n",
423 RRRR_MSG(ec), TT_MSG(ec), LL_MSG(ec));
424 } else if (BUS_ERROR(ec)) {
425 pr_emerg(HW_ERR "Transaction: %s (%s), %s, Cache Level: %s, "
426 "Participating Processor: %s\n",
427 RRRR_MSG(ec), II_MSG(ec), TO_MSG(ec), LL_MSG(ec),
430 pr_emerg(HW_ERR "Huh? Unknown MCE error 0x%x\n", ec);
433 int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
435 struct mce *m = (struct mce *)data;
438 pr_emerg(HW_ERR "MC%d_STATUS: ", m->bank);
440 pr_cont("%sorrected error, other errors lost: %s, "
441 "CPU context corrupt: %s",
442 ((m->status & MCI_STATUS_UC) ? "Unc" : "C"),
443 ((m->status & MCI_STATUS_OVER) ? "yes" : "no"),
444 ((m->status & MCI_STATUS_PCC) ? "yes" : "no"));
446 /* do the two bits[14:13] together */
447 ecc = (m->status >> 45) & 0x3;
449 pr_cont(", %sECC Error", ((ecc == 2) ? "C" : "U"));
455 amd_decode_dc_mce(m);
459 amd_decode_ic_mce(m);
463 amd_decode_bu_mce(m);
467 amd_decode_ls_mce(m);
471 node = amd_get_nb_id(m->extcpu);
472 amd_decode_nb_mce(node, m, 0);
476 amd_decode_fr_mce(m);
483 amd_decode_err_code(m->status & 0xffff);
487 EXPORT_SYMBOL_GPL(amd_decode_mce);
489 static struct notifier_block amd_mce_dec_nb = {
490 .notifier_call = amd_decode_mce,
493 static int __init mce_amd_init(void)
496 * We can decode MCEs for K8, F10h and F11h CPUs:
498 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
501 if (boot_cpu_data.x86 < 0xf || boot_cpu_data.x86 > 0x11)
504 fam_ops = kzalloc(sizeof(struct amd_decoder_ops), GFP_KERNEL);
508 switch (boot_cpu_data.x86) {
510 fam_ops->dc_mce = k8_dc_mce;
511 fam_ops->ic_mce = k8_ic_mce;
515 fam_ops->dc_mce = f10h_dc_mce;
516 fam_ops->ic_mce = k8_ic_mce;
520 fam_ops->dc_mce = f14h_dc_mce;
521 fam_ops->ic_mce = f14h_ic_mce;
525 printk(KERN_WARNING "Huh? What family is that: %d?!\n",
531 atomic_notifier_chain_register(&x86_mce_decoder_chain, &amd_mce_dec_nb);
535 early_initcall(mce_amd_init);
538 static void __exit mce_amd_exit(void)
540 atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &amd_mce_dec_nb);
544 MODULE_DESCRIPTION("AMD MCE decoder");
545 MODULE_ALIAS("edac-mce-amd");
546 MODULE_LICENSE("GPL");
547 module_exit(mce_amd_exit);