MCE, AMD: Correct VB data error description
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / edac / mce_amd.c
CommitLineData
b70ef010 1#include <linux/module.h>
888ab8e6
BP
2#include <linux/slab.h>
3
47ca08a4 4#include "mce_amd.h"
b52401ce 5
888ab8e6
BP
6static struct amd_decoder_ops *fam_ops;
7
2be64bfa 8static u8 xec_mask = 0xf;
5ce88f6e
BP
9static u8 nb_err_cpumask = 0xf;
10
549d042d 11static bool report_gart_errors;
b0b07a2b 12static void (*nb_bus_decoder)(int node_id, struct mce *m);
549d042d
BP
13
14void amd_report_gart_errors(bool v)
15{
16 report_gart_errors = v;
17}
18EXPORT_SYMBOL_GPL(amd_report_gart_errors);
19
b0b07a2b 20void amd_register_ecc_decoder(void (*f)(int, struct mce *))
549d042d
BP
21{
22 nb_bus_decoder = f;
23}
24EXPORT_SYMBOL_GPL(amd_register_ecc_decoder);
25
b0b07a2b 26void amd_unregister_ecc_decoder(void (*f)(int, struct mce *))
549d042d
BP
27{
28 if (nb_bus_decoder) {
29 WARN_ON(nb_bus_decoder != f);
30
31 nb_bus_decoder = NULL;
32 }
33}
34EXPORT_SYMBOL_GPL(amd_unregister_ecc_decoder);
35
b52401ce
DT
36/*
37 * string representation for the different MCA reported error types, see F3x48
38 * or MSR0000_0411.
39 */
6337583d
BP
40
41/* transaction type */
42const char *tt_msgs[] = { "INSN", "DATA", "GEN", "RESV" };
b70ef010 43EXPORT_SYMBOL_GPL(tt_msgs);
b52401ce 44
6337583d
BP
45/* cache level */
46const char *ll_msgs[] = { "RESV", "L1", "L2", "L3/GEN" };
b70ef010 47EXPORT_SYMBOL_GPL(ll_msgs);
b52401ce 48
6337583d 49/* memory transaction type */
b52401ce 50const char *rrrr_msgs[] = {
6337583d 51 "GEN", "RD", "WR", "DRD", "DWR", "IRD", "PRF", "EV", "SNP"
b52401ce 52};
b70ef010 53EXPORT_SYMBOL_GPL(rrrr_msgs);
b52401ce 54
6337583d
BP
55/* participating processor */
56const char *pp_msgs[] = { "SRC", "RES", "OBS", "GEN" };
b70ef010 57EXPORT_SYMBOL_GPL(pp_msgs);
b52401ce 58
6337583d
BP
59/* request timeout */
60const char *to_msgs[] = { "no timeout", "timed out" };
b70ef010 61EXPORT_SYMBOL_GPL(to_msgs);
b52401ce 62
6337583d
BP
63/* memory or i/o */
64const char *ii_msgs[] = { "MEM", "RESV", "IO", "GEN" };
b70ef010 65EXPORT_SYMBOL_GPL(ii_msgs);
b52401ce 66
5ce88f6e
BP
67static const char *f10h_nb_mce_desc[] = {
68 "HT link data error",
69 "Protocol error (link, L3, probe filter, etc.)",
70 "Parity error in NB-internal arrays",
71 "Link Retry due to IO link transmission error",
72 "L3 ECC data cache error",
73 "ECC error in L3 cache tag",
74 "L3 LRU parity bits error",
75 "ECC Error in the Probe Filter directory"
b52401ce 76};
549d042d 77
86039cd4
BP
78static const char * const f15h_ic_mce_desc[] = {
79 "UC during a demand linefill from L2",
80 "Parity error during data load from IC",
81 "Parity error for IC valid bit",
82 "Main tag parity error",
83 "Parity error in prediction queue",
84 "PFB data/address parity error",
85 "Parity error in the branch status reg",
86 "PFB promotion address error",
87 "Tag error during probe/victimization",
88 "Parity error for IC probe tag valid bit",
89 "PFB non-cacheable bit parity error",
90 "PFB valid bit parity error", /* xec = 0xd */
6c1173a6 91 "Microcode Patch Buffer", /* xec = 010 */
86039cd4
BP
92 "uop queue",
93 "insn buffer",
94 "predecode buffer",
95 "fetch address FIFO"
96};
97
70fdb494
BP
98static const char * const f15h_cu_mce_desc[] = {
99 "Fill ECC error on data fills", /* xec = 0x4 */
100 "Fill parity error on insn fills",
101 "Prefetcher request FIFO parity error",
102 "PRQ address parity error",
103 "PRQ data parity error",
104 "WCC Tag ECC error",
105 "WCC Data ECC error",
106 "WCB Data parity error",
b64a99c1 107 "VB Data ECC or parity error",
70fdb494
BP
108 "L2 Tag ECC error", /* xec = 0x10 */
109 "Hard L2 Tag ECC error",
110 "Multiple hits on L2 tag",
111 "XAB parity error",
112 "PRB address parity error"
113};
114
8259a7e5
BP
115static const char * const fr_ex_mce_desc[] = {
116 "CPU Watchdog timer expire",
117 "Wakeup array dest tag",
118 "AG payload array",
119 "EX payload array",
120 "IDRF array",
121 "Retire dispatch queue",
122 "Mapper checkpoint array",
123 "Physical register file EX0 port",
124 "Physical register file EX1 port",
125 "Physical register file AG0 port",
126 "Physical register file AG1 port",
127 "Flag register file",
128 "DE correctable error could not be corrected"
129};
130
25a4f8b0 131static bool f12h_dc_mce(u16 ec, u8 xec)
51966241 132{
888ab8e6 133 bool ret = false;
51966241 134
888ab8e6 135 if (MEM_ERROR(ec)) {
62452882 136 u8 ll = LL(ec);
888ab8e6 137 ret = true;
51966241 138
888ab8e6
BP
139 if (ll == LL_L2)
140 pr_cont("during L1 linefill from L2.\n");
141 else if (ll == LL_L1)
62452882 142 pr_cont("Data/Tag %s error.\n", R4_MSG(ec));
888ab8e6
BP
143 else
144 ret = false;
145 }
146 return ret;
147}
51966241 148
25a4f8b0 149static bool f10h_dc_mce(u16 ec, u8 xec)
9be0bb10 150{
62452882 151 if (R4(ec) == R4_GEN && LL(ec) == LL_L1) {
9be0bb10
BP
152 pr_cont("during data scrub.\n");
153 return true;
154 }
25a4f8b0 155 return f12h_dc_mce(ec, xec);
9be0bb10
BP
156}
157
25a4f8b0 158static bool k8_dc_mce(u16 ec, u8 xec)
888ab8e6
BP
159{
160 if (BUS_ERROR(ec)) {
161 pr_cont("during system linefill.\n");
162 return true;
163 }
51966241 164
25a4f8b0 165 return f10h_dc_mce(ec, xec);
888ab8e6
BP
166}
167
25a4f8b0 168static bool f14h_dc_mce(u16 ec, u8 xec)
888ab8e6 169{
62452882 170 u8 r4 = R4(ec);
888ab8e6
BP
171 bool ret = true;
172
173 if (MEM_ERROR(ec)) {
174
62452882 175 if (TT(ec) != TT_DATA || LL(ec) != LL_L1)
888ab8e6
BP
176 return false;
177
178 switch (r4) {
179 case R4_DRD:
180 case R4_DWR:
181 pr_cont("Data/Tag parity error due to %s.\n",
182 (r4 == R4_DRD ? "load/hw prf" : "store"));
183 break;
184 case R4_EVICT:
185 pr_cont("Copyback parity error on a tag miss.\n");
186 break;
187 case R4_SNOOP:
188 pr_cont("Tag parity error during snoop.\n");
189 break;
190 default:
191 ret = false;
192 }
193 } else if (BUS_ERROR(ec)) {
194
62452882 195 if ((II(ec) != II_MEM && II(ec) != II_IO) || LL(ec) != LL_LG)
888ab8e6
BP
196 return false;
197
198 pr_cont("System read data error on a ");
199
200 switch (r4) {
201 case R4_RD:
202 pr_cont("TLB reload.\n");
203 break;
204 case R4_DWR:
205 pr_cont("store.\n");
206 break;
207 case R4_DRD:
208 pr_cont("load.\n");
209 break;
210 default:
211 ret = false;
212 }
213 } else {
214 ret = false;
215 }
216
217 return ret;
218}
219
25a4f8b0
BP
220static bool f15h_dc_mce(u16 ec, u8 xec)
221{
222 bool ret = true;
223
224 if (MEM_ERROR(ec)) {
225
226 switch (xec) {
227 case 0x0:
228 pr_cont("Data Array access error.\n");
229 break;
230
231 case 0x1:
232 pr_cont("UC error during a linefill from L2/NB.\n");
233 break;
234
235 case 0x2:
236 case 0x11:
237 pr_cont("STQ access error.\n");
238 break;
239
240 case 0x3:
241 pr_cont("SCB access error.\n");
242 break;
243
244 case 0x10:
245 pr_cont("Tag error.\n");
246 break;
247
248 case 0x12:
249 pr_cont("LDQ access error.\n");
250 break;
251
252 default:
253 ret = false;
254 }
255 } else if (BUS_ERROR(ec)) {
256
257 if (!xec)
344f0a06 258 pr_cont("System Read Data Error.\n");
25a4f8b0 259 else
344f0a06 260 pr_cont(" Internal error condition type %d.\n", xec);
25a4f8b0
BP
261 } else
262 ret = false;
263
264 return ret;
265}
266
888ab8e6
BP
267static void amd_decode_dc_mce(struct mce *m)
268{
62452882
BP
269 u16 ec = EC(m->status);
270 u8 xec = XEC(m->status, xec_mask);
888ab8e6
BP
271
272 pr_emerg(HW_ERR "Data Cache Error: ");
273
274 /* TLB error signatures are the same across families */
275 if (TLB_ERROR(ec)) {
62452882 276 if (TT(ec) == TT_DATA) {
888ab8e6 277 pr_cont("%s TLB %s.\n", LL_MSG(ec),
25a4f8b0
BP
278 ((xec == 2) ? "locked miss"
279 : (xec ? "multimatch" : "parity")));
888ab8e6
BP
280 return;
281 }
25a4f8b0
BP
282 } else if (fam_ops->dc_mce(ec, xec))
283 ;
284 else
285 pr_emerg(HW_ERR "Corrupted DC MCE info?\n");
51966241
BP
286}
287
86039cd4 288static bool k8_ic_mce(u16 ec, u8 xec)
ab5535e7 289{
62452882 290 u8 ll = LL(ec);
dd53bce4 291 bool ret = true;
ab5535e7 292
dd53bce4
BP
293 if (!MEM_ERROR(ec))
294 return false;
ab5535e7 295
dd53bce4
BP
296 if (ll == 0x2)
297 pr_cont("during a linefill from L2.\n");
298 else if (ll == 0x1) {
62452882 299 switch (R4(ec)) {
dd53bce4
BP
300 case R4_IRD:
301 pr_cont("Parity error during data load.\n");
302 break;
ab5535e7 303
dd53bce4
BP
304 case R4_EVICT:
305 pr_cont("Copyback Parity/Victim error.\n");
306 break;
307
308 case R4_SNOOP:
309 pr_cont("Tag Snoop error.\n");
310 break;
311
312 default:
313 ret = false;
314 break;
315 }
ab5535e7 316 } else
dd53bce4 317 ret = false;
ab5535e7 318
dd53bce4
BP
319 return ret;
320}
321
86039cd4 322static bool f14h_ic_mce(u16 ec, u8 xec)
dd53bce4 323{
62452882 324 u8 r4 = R4(ec);
dd53bce4 325 bool ret = true;
ab5535e7 326
dd53bce4 327 if (MEM_ERROR(ec)) {
62452882 328 if (TT(ec) != 0 || LL(ec) != 1)
dd53bce4
BP
329 ret = false;
330
331 if (r4 == R4_IRD)
332 pr_cont("Data/tag array parity error for a tag hit.\n");
333 else if (r4 == R4_SNOOP)
334 pr_cont("Tag error during snoop/victimization.\n");
335 else
336 ret = false;
337 }
338 return ret;
339}
340
86039cd4
BP
341static bool f15h_ic_mce(u16 ec, u8 xec)
342{
343 bool ret = true;
344
345 if (!MEM_ERROR(ec))
346 return false;
347
348 switch (xec) {
349 case 0x0 ... 0xa:
350 pr_cont("%s.\n", f15h_ic_mce_desc[xec]);
351 break;
352
353 case 0xd:
354 pr_cont("%s.\n", f15h_ic_mce_desc[xec-2]);
355 break;
356
6c1173a6
BP
357 case 0x10:
358 pr_cont("%s.\n", f15h_ic_mce_desc[xec-4]);
359 break;
360
361 case 0x11 ... 0x14:
86039cd4
BP
362 pr_cont("Decoder %s parity error.\n", f15h_ic_mce_desc[xec-4]);
363 break;
364
365 default:
366 ret = false;
367 }
368 return ret;
369}
370
dd53bce4
BP
371static void amd_decode_ic_mce(struct mce *m)
372{
62452882
BP
373 u16 ec = EC(m->status);
374 u8 xec = XEC(m->status, xec_mask);
dd53bce4
BP
375
376 pr_emerg(HW_ERR "Instruction Cache Error: ");
377
378 if (TLB_ERROR(ec))
379 pr_cont("%s TLB %s.\n", LL_MSG(ec),
380 (xec ? "multimatch" : "parity error"));
381 else if (BUS_ERROR(ec)) {
525906bc 382 bool k8 = (boot_cpu_data.x86 == 0xf && (m->status & BIT_64(58)));
dd53bce4
BP
383
384 pr_cont("during %s.\n", (k8 ? "system linefill" : "NB data read"));
86039cd4 385 } else if (fam_ops->ic_mce(ec, xec))
dd53bce4
BP
386 ;
387 else
388 pr_emerg(HW_ERR "Corrupted IC MCE info?\n");
ab5535e7
BP
389}
390
7cfd4a87 391static void amd_decode_bu_mce(struct mce *m)
56cad2d6 392{
62452882
BP
393 u16 ec = EC(m->status);
394 u8 xec = XEC(m->status, xec_mask);
56cad2d6 395
c9f281fd 396 pr_emerg(HW_ERR "Bus Unit Error");
56cad2d6
BP
397
398 if (xec == 0x1)
399 pr_cont(" in the write data buffers.\n");
400 else if (xec == 0x3)
401 pr_cont(" in the victim data buffers.\n");
402 else if (xec == 0x2 && MEM_ERROR(ec))
62452882 403 pr_cont(": %s error in the L2 cache tags.\n", R4_MSG(ec));
56cad2d6
BP
404 else if (xec == 0x0) {
405 if (TLB_ERROR(ec))
406 pr_cont(": %s error in a Page Descriptor Cache or "
407 "Guest TLB.\n", TT_MSG(ec));
408 else if (BUS_ERROR(ec))
409 pr_cont(": %s/ECC error in data read from NB: %s.\n",
62452882 410 R4_MSG(ec), PP_MSG(ec));
56cad2d6 411 else if (MEM_ERROR(ec)) {
62452882 412 u8 r4 = R4(ec);
56cad2d6 413
62452882 414 if (r4 >= 0x7)
56cad2d6 415 pr_cont(": %s error during data copyback.\n",
62452882
BP
416 R4_MSG(ec));
417 else if (r4 <= 0x1)
56cad2d6 418 pr_cont(": %s parity/ECC error during data "
62452882 419 "access from L2.\n", R4_MSG(ec));
56cad2d6
BP
420 else
421 goto wrong_bu_mce;
422 } else
423 goto wrong_bu_mce;
424 } else
425 goto wrong_bu_mce;
426
427 return;
428
429wrong_bu_mce:
c9f281fd 430 pr_emerg(HW_ERR "Corrupted BU MCE info?\n");
56cad2d6
BP
431}
432
70fdb494
BP
433static void amd_decode_cu_mce(struct mce *m)
434{
62452882
BP
435 u16 ec = EC(m->status);
436 u8 xec = XEC(m->status, xec_mask);
70fdb494
BP
437
438 pr_emerg(HW_ERR "Combined Unit Error: ");
439
440 if (TLB_ERROR(ec)) {
441 if (xec == 0x0)
442 pr_cont("Data parity TLB read error.\n");
443 else if (xec == 0x1)
444 pr_cont("Poison data provided for TLB fill.\n");
445 else
446 goto wrong_cu_mce;
447 } else if (BUS_ERROR(ec)) {
448 if (xec > 2)
449 goto wrong_cu_mce;
450
451 pr_cont("Error during attempted NB data read.\n");
452 } else if (MEM_ERROR(ec)) {
453 switch (xec) {
454 case 0x4 ... 0xc:
455 pr_cont("%s.\n", f15h_cu_mce_desc[xec - 0x4]);
456 break;
457
458 case 0x10 ... 0x14:
459 pr_cont("%s.\n", f15h_cu_mce_desc[xec - 0x7]);
460 break;
461
462 default:
463 goto wrong_cu_mce;
464 }
465 }
466
467 return;
468
469wrong_cu_mce:
470 pr_emerg(HW_ERR "Corrupted CU MCE info?\n");
471}
472
7cfd4a87 473static void amd_decode_ls_mce(struct mce *m)
f9350efd 474{
62452882
BP
475 u16 ec = EC(m->status);
476 u8 xec = XEC(m->status, xec_mask);
ded50623 477
b18434ca 478 if (boot_cpu_data.x86 >= 0x14) {
ded50623
BP
479 pr_emerg("You shouldn't be seeing an LS MCE on this cpu family,"
480 " please report on LKML.\n");
481 return;
482 }
f9350efd 483
c9f281fd 484 pr_emerg(HW_ERR "Load Store Error");
f9350efd
BP
485
486 if (xec == 0x0) {
62452882 487 u8 r4 = R4(ec);
f9350efd 488
ded50623 489 if (!BUS_ERROR(ec) || (r4 != R4_DRD && r4 != R4_DWR))
f9350efd
BP
490 goto wrong_ls_mce;
491
62452882 492 pr_cont(" during %s.\n", R4_MSG(ec));
ded50623
BP
493 } else
494 goto wrong_ls_mce;
495
f9350efd
BP
496 return;
497
498wrong_ls_mce:
c9f281fd 499 pr_emerg(HW_ERR "Corrupted LS MCE info?\n");
f9350efd
BP
500}
501
5ce88f6e
BP
502static bool k8_nb_mce(u16 ec, u8 xec)
503{
504 bool ret = true;
505
506 switch (xec) {
507 case 0x1:
508 pr_cont("CRC error detected on HT link.\n");
509 break;
510
511 case 0x5:
512 pr_cont("Invalid GART PTE entry during GART table walk.\n");
513 break;
514
515 case 0x6:
516 pr_cont("Unsupported atomic RMW received from an IO link.\n");
517 break;
518
519 case 0x0:
520 case 0x8:
f0157b3a
BP
521 if (boot_cpu_data.x86 == 0x11)
522 return false;
523
5ce88f6e
BP
524 pr_cont("DRAM ECC error detected on the NB.\n");
525 break;
526
527 case 0xd:
528 pr_cont("Parity error on the DRAM addr/ctl signals.\n");
529 break;
530
531 default:
532 ret = false;
533 break;
534 }
535
536 return ret;
537}
538
539static bool f10h_nb_mce(u16 ec, u8 xec)
540{
541 bool ret = true;
542 u8 offset = 0;
543
544 if (k8_nb_mce(ec, xec))
545 return true;
546
547 switch(xec) {
548 case 0xa ... 0xc:
549 offset = 10;
550 break;
551
552 case 0xe:
553 offset = 11;
554 break;
555
556 case 0xf:
557 if (TLB_ERROR(ec))
558 pr_cont("GART Table Walk data error.\n");
559 else if (BUS_ERROR(ec))
560 pr_cont("DMA Exclusion Vector Table Walk error.\n");
561 else
562 ret = false;
563
564 goto out;
565 break;
566
05cd667d
BP
567 case 0x19:
568 if (boot_cpu_data.x86 == 0x15)
569 pr_cont("Compute Unit Data Error.\n");
570 else
571 ret = false;
572
573 goto out;
574 break;
575
5ce88f6e
BP
576 case 0x1c ... 0x1f:
577 offset = 24;
578 break;
579
580 default:
581 ret = false;
582
583 goto out;
584 break;
585 }
586
587 pr_cont("%s.\n", f10h_nb_mce_desc[xec - offset]);
588
589out:
590 return ret;
591}
592
cb9d5ecd 593static bool nb_noop_mce(u16 ec, u8 xec)
5ce88f6e
BP
594{
595 return false;
596}
597
b0b07a2b 598void amd_decode_nb_mce(struct mce *m)
549d042d 599{
df71a053 600 struct cpuinfo_x86 *c = &boot_cpu_data;
b0b07a2b
BP
601 int node_id = amd_get_nb_id(m->extcpu);
602 u16 ec = EC(m->status);
603 u8 xec = XEC(m->status, 0x1f);
256f7276 604
295d8cda 605 pr_emerg(HW_ERR "Northbridge Error (node %d): ", node_id);
6d5db466 606
5ce88f6e
BP
607 switch (xec) {
608 case 0x2:
609 pr_cont("Sync error (sync packets on HT link detected).\n");
610 return;
611
612 case 0x3:
613 pr_cont("HT Master abort.\n");
614 return;
615
616 case 0x4:
617 pr_cont("HT Target abort.\n");
618 return;
619
620 case 0x7:
621 pr_cont("NB Watchdog timeout.\n");
622 return;
623
624 case 0x9:
625 pr_cont("SVM DMA Exclusion Vector error.\n");
626 return;
627
628 default:
629 break;
549d042d
BP
630 }
631
5ce88f6e
BP
632 if (!fam_ops->nb_mce(ec, xec))
633 goto wrong_nb_mce;
634
df71a053 635 if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x15)
5ce88f6e 636 if ((xec == 0x8 || xec == 0x0) && nb_bus_decoder)
b0b07a2b 637 nb_bus_decoder(node_id, m);
d93cc222 638
5ce88f6e
BP
639 return;
640
641wrong_nb_mce:
642 pr_emerg(HW_ERR "Corrupted NB MCE info?\n");
d93cc222
BP
643}
644EXPORT_SYMBOL_GPL(amd_decode_nb_mce);
645
7cfd4a87 646static void amd_decode_fr_mce(struct mce *m)
53bd5fed 647{
8259a7e5 648 struct cpuinfo_x86 *c = &boot_cpu_data;
62452882 649 u8 xec = XEC(m->status, xec_mask);
8259a7e5
BP
650
651 if (c->x86 == 0xf || c->x86 == 0x11)
fe4ea262
BP
652 goto wrong_fr_mce;
653
8259a7e5
BP
654 if (c->x86 != 0x15 && xec != 0x0)
655 goto wrong_fr_mce;
656
657 pr_emerg(HW_ERR "%s Error: ",
658 (c->x86 == 0x15 ? "Execution Unit" : "FIROB"));
659
660 if (xec == 0x0 || xec == 0xc)
661 pr_cont("%s.\n", fr_ex_mce_desc[xec]);
662 else if (xec < 0xd)
663 pr_cont("%s parity error.\n", fr_ex_mce_desc[xec]);
664 else
665 goto wrong_fr_mce;
666
667 return;
fe4ea262
BP
668
669wrong_fr_mce:
670 pr_emerg(HW_ERR "Corrupted FR MCE info?\n");
53bd5fed
BP
671}
672
b8f85c47
BP
673static void amd_decode_fp_mce(struct mce *m)
674{
62452882 675 u8 xec = XEC(m->status, xec_mask);
b8f85c47
BP
676
677 pr_emerg(HW_ERR "Floating Point Unit Error: ");
678
679 switch (xec) {
680 case 0x1:
681 pr_cont("Free List");
682 break;
683
684 case 0x2:
685 pr_cont("Physical Register File");
686 break;
687
688 case 0x3:
689 pr_cont("Retire Queue");
690 break;
691
692 case 0x4:
693 pr_cont("Scheduler table");
694 break;
695
696 case 0x5:
697 pr_cont("Status Register File");
698 break;
699
700 default:
701 goto wrong_fp_mce;
702 break;
703 }
704
705 pr_cont(" parity error.\n");
706
707 return;
708
709wrong_fp_mce:
710 pr_emerg(HW_ERR "Corrupted FP MCE info?\n");
711}
712
6337583d 713static inline void amd_decode_err_code(u16 ec)
d93cc222 714{
fa7ae8cc
BP
715
716 pr_emerg(HW_ERR "cache level: %s", LL_MSG(ec));
717
718 if (BUS_ERROR(ec))
719 pr_cont(", mem/io: %s", II_MSG(ec));
720 else
721 pr_cont(", tx: %s", TT_MSG(ec));
722
723 if (MEM_ERROR(ec) || BUS_ERROR(ec)) {
724 pr_cont(", mem-tx: %s", R4_MSG(ec));
725
726 if (BUS_ERROR(ec))
727 pr_cont(", part-proc: %s (%s)", PP_MSG(ec), TO_MSG(ec));
728 }
729
730 pr_cont("\n");
549d042d 731}
549d042d 732
5ce88f6e
BP
733/*
734 * Filter out unwanted MCE signatures here.
735 */
736static bool amd_filter_mce(struct mce *m)
737{
738 u8 xec = (m->status >> 16) & 0x1f;
739
740 /*
741 * NB GART TLB error reporting is disabled by default.
742 */
743 if (m->bank == 4 && xec == 0x5 && !report_gart_errors)
744 return true;
745
746 return false;
747}
748
9cdeb404 749int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
549d042d 750{
fb253195 751 struct mce *m = (struct mce *)data;
fa7ae8cc 752 struct cpuinfo_x86 *c = &boot_cpu_data;
b0b07a2b 753 int ecc;
549d042d 754
5ce88f6e
BP
755 if (amd_filter_mce(m))
756 return NOTIFY_STOP;
757
086be786 758 pr_emerg(HW_ERR "CPU:%d\tMC%d_STATUS[%s|%s|%s|%s|%s",
bff7b812 759 m->extcpu, m->bank,
fa7ae8cc
BP
760 ((m->status & MCI_STATUS_OVER) ? "Over" : "-"),
761 ((m->status & MCI_STATUS_UC) ? "UE" : "CE"),
762 ((m->status & MCI_STATUS_MISCV) ? "MiscV" : "-"),
763 ((m->status & MCI_STATUS_PCC) ? "PCC" : "-"),
764 ((m->status & MCI_STATUS_ADDRV) ? "AddrV" : "-"));
549d042d 765
fa7ae8cc
BP
766 if (c->x86 == 0x15)
767 pr_cont("|%s|%s",
50adbbd8
RD
768 ((m->status & BIT_64(44)) ? "Deferred" : "-"),
769 ((m->status & BIT_64(43)) ? "Poison" : "-"));
549d042d 770
b69b29de 771 /* do the two bits[14:13] together */
35d824b2 772 ecc = (m->status >> 45) & 0x3;
b69b29de 773 if (ecc)
fa7ae8cc
BP
774 pr_cont("|%sECC", ((ecc == 2) ? "C" : "U"));
775
776 pr_cont("]: 0x%016llx\n", m->status);
b69b29de 777
086be786
BP
778 if (m->status & MCI_STATUS_ADDRV)
779 pr_emerg(HW_ERR "\tMC%d_ADDR: 0x%016llx\n", m->bank, m->addr);
b69b29de 780
51966241
BP
781 switch (m->bank) {
782 case 0:
7cfd4a87 783 amd_decode_dc_mce(m);
51966241 784 break;
d93cc222 785
ab5535e7 786 case 1:
7cfd4a87 787 amd_decode_ic_mce(m);
ab5535e7
BP
788 break;
789
56cad2d6 790 case 2:
fa7ae8cc 791 if (c->x86 == 0x15)
70fdb494
BP
792 amd_decode_cu_mce(m);
793 else
794 amd_decode_bu_mce(m);
56cad2d6
BP
795 break;
796
f9350efd 797 case 3:
7cfd4a87 798 amd_decode_ls_mce(m);
f9350efd
BP
799 break;
800
51966241 801 case 4:
b0b07a2b 802 amd_decode_nb_mce(m);
51966241
BP
803 break;
804
53bd5fed 805 case 5:
7cfd4a87 806 amd_decode_fr_mce(m);
53bd5fed
BP
807 break;
808
b8f85c47
BP
809 case 6:
810 amd_decode_fp_mce(m);
811 break;
812
51966241
BP
813 default:
814 break;
b69b29de 815 }
51966241
BP
816
817 amd_decode_err_code(m->status & 0xffff);
fb253195
BP
818
819 return NOTIFY_STOP;
549d042d 820}
9cdeb404 821EXPORT_SYMBOL_GPL(amd_decode_mce);
f436f8bb 822
fb253195
BP
823static struct notifier_block amd_mce_dec_nb = {
824 .notifier_call = amd_decode_mce,
825};
826
f436f8bb
IM
827static int __init mce_amd_init(void)
828{
bad11e03
BP
829 struct cpuinfo_x86 *c = &boot_cpu_data;
830
831 if (c->x86_vendor != X86_VENDOR_AMD)
e045c291
BP
832 return 0;
833
bad11e03
BP
834 if ((c->x86 < 0xf || c->x86 > 0x12) &&
835 (c->x86 != 0x14 || c->x86_model > 0xf) &&
836 (c->x86 != 0x15 || c->x86_model > 0xf))
e045c291
BP
837 return 0;
838
888ab8e6
BP
839 fam_ops = kzalloc(sizeof(struct amd_decoder_ops), GFP_KERNEL);
840 if (!fam_ops)
841 return -ENOMEM;
842
bad11e03 843 switch (c->x86) {
888ab8e6
BP
844 case 0xf:
845 fam_ops->dc_mce = k8_dc_mce;
dd53bce4 846 fam_ops->ic_mce = k8_ic_mce;
5ce88f6e 847 fam_ops->nb_mce = k8_nb_mce;
888ab8e6
BP
848 break;
849
850 case 0x10:
851 fam_ops->dc_mce = f10h_dc_mce;
dd53bce4 852 fam_ops->ic_mce = k8_ic_mce;
5ce88f6e 853 fam_ops->nb_mce = f10h_nb_mce;
888ab8e6
BP
854 break;
855
f0157b3a
BP
856 case 0x11:
857 fam_ops->dc_mce = k8_dc_mce;
858 fam_ops->ic_mce = k8_ic_mce;
859 fam_ops->nb_mce = f10h_nb_mce;
860 break;
861
9be0bb10
BP
862 case 0x12:
863 fam_ops->dc_mce = f12h_dc_mce;
e7281eb3 864 fam_ops->ic_mce = k8_ic_mce;
cb9d5ecd 865 fam_ops->nb_mce = nb_noop_mce;
9be0bb10
BP
866 break;
867
888ab8e6 868 case 0x14:
5ce88f6e 869 nb_err_cpumask = 0x3;
888ab8e6 870 fam_ops->dc_mce = f14h_dc_mce;
dd53bce4 871 fam_ops->ic_mce = f14h_ic_mce;
cb9d5ecd 872 fam_ops->nb_mce = nb_noop_mce;
888ab8e6
BP
873 break;
874
2be64bfa
BP
875 case 0x15:
876 xec_mask = 0x1f;
25a4f8b0 877 fam_ops->dc_mce = f15h_dc_mce;
86039cd4 878 fam_ops->ic_mce = f15h_ic_mce;
05cd667d 879 fam_ops->nb_mce = f10h_nb_mce;
2be64bfa
BP
880 break;
881
888ab8e6 882 default:
bad11e03 883 printk(KERN_WARNING "Huh? What family is that: %d?!\n", c->x86);
888ab8e6
BP
884 kfree(fam_ops);
885 return -EINVAL;
886 }
887
9530d608
BP
888 pr_info("MCE: In-kernel MCE decoding enabled.\n");
889
3653ada5 890 mce_register_decode_chain(&amd_mce_dec_nb);
f436f8bb
IM
891
892 return 0;
893}
894early_initcall(mce_amd_init);
0d18b2e3
BP
895
896#ifdef MODULE
897static void __exit mce_amd_exit(void)
898{
3653ada5 899 mce_unregister_decode_chain(&amd_mce_dec_nb);
888ab8e6 900 kfree(fam_ops);
0d18b2e3
BP
901}
902
903MODULE_DESCRIPTION("AMD MCE decoder");
904MODULE_ALIAS("edac-mce-amd");
905MODULE_LICENSE("GPL");
906module_exit(mce_amd_exit);
907#endif