mce_amd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. #include <linux/module.h>
  2. #include <linux/slab.h>
  3. #include "mce_amd.h"
  4. static struct amd_decoder_ops *fam_ops;
  5. static bool report_gart_errors;
  6. static void (*nb_bus_decoder)(int node_id, struct mce *m, u32 nbcfg);
  7. void amd_report_gart_errors(bool v)
  8. {
  9. report_gart_errors = v;
  10. }
  11. EXPORT_SYMBOL_GPL(amd_report_gart_errors);
  12. void amd_register_ecc_decoder(void (*f)(int, struct mce *, u32))
  13. {
  14. nb_bus_decoder = f;
  15. }
  16. EXPORT_SYMBOL_GPL(amd_register_ecc_decoder);
  17. void amd_unregister_ecc_decoder(void (*f)(int, struct mce *, u32))
  18. {
  19. if (nb_bus_decoder) {
  20. WARN_ON(nb_bus_decoder != f);
  21. nb_bus_decoder = NULL;
  22. }
  23. }
  24. EXPORT_SYMBOL_GPL(amd_unregister_ecc_decoder);
  25. /*
  26. * string representation for the different MCA reported error types, see F3x48
  27. * or MSR0000_0411.
  28. */
  29. /* transaction type */
  30. const char *tt_msgs[] = { "INSN", "DATA", "GEN", "RESV" };
  31. EXPORT_SYMBOL_GPL(tt_msgs);
  32. /* cache level */
  33. const char *ll_msgs[] = { "RESV", "L1", "L2", "L3/GEN" };
  34. EXPORT_SYMBOL_GPL(ll_msgs);
  35. /* memory transaction type */
  36. const char *rrrr_msgs[] = {
  37. "GEN", "RD", "WR", "DRD", "DWR", "IRD", "PRF", "EV", "SNP"
  38. };
  39. EXPORT_SYMBOL_GPL(rrrr_msgs);
  40. /* participating processor */
  41. const char *pp_msgs[] = { "SRC", "RES", "OBS", "GEN" };
  42. EXPORT_SYMBOL_GPL(pp_msgs);
  43. /* request timeout */
  44. const char *to_msgs[] = { "no timeout", "timed out" };
  45. EXPORT_SYMBOL_GPL(to_msgs);
  46. /* memory or i/o */
  47. const char *ii_msgs[] = { "MEM", "RESV", "IO", "GEN" };
  48. EXPORT_SYMBOL_GPL(ii_msgs);
  49. /*
  50. * Map the 4 or 5 (family-specific) bits of Extended Error code to the
  51. * string table.
  52. */
  53. const char *ext_msgs[] = {
  54. "K8 ECC error", /* 0_0000b */
  55. "CRC error on link", /* 0_0001b */
  56. "Sync error packets on link", /* 0_0010b */
  57. "Master Abort during link operation", /* 0_0011b */
  58. "Target Abort during link operation", /* 0_0100b */
  59. "Invalid GART PTE entry during table walk", /* 0_0101b */
  60. "Unsupported atomic RMW command received", /* 0_0110b */
  61. "WDT error: NB transaction timeout", /* 0_0111b */
  62. "ECC/ChipKill ECC error", /* 0_1000b */
  63. "SVM DEV Error", /* 0_1001b */
  64. "Link Data error", /* 0_1010b */
  65. "Link/L3/Probe Filter Protocol error", /* 0_1011b */
  66. "NB Internal Arrays Parity error", /* 0_1100b */
  67. "DRAM Address/Control Parity error", /* 0_1101b */
  68. "Link Transmission error", /* 0_1110b */
  69. "GART/DEV Table Walk Data error" /* 0_1111b */
  70. "Res 0x100 error", /* 1_0000b */
  71. "Res 0x101 error", /* 1_0001b */
  72. "Res 0x102 error", /* 1_0010b */
  73. "Res 0x103 error", /* 1_0011b */
  74. "Res 0x104 error", /* 1_0100b */
  75. "Res 0x105 error", /* 1_0101b */
  76. "Res 0x106 error", /* 1_0110b */
  77. "Res 0x107 error", /* 1_0111b */
  78. "Res 0x108 error", /* 1_1000b */
  79. "Res 0x109 error", /* 1_1001b */
  80. "Res 0x10A error", /* 1_1010b */
  81. "Res 0x10B error", /* 1_1011b */
  82. "ECC error in L3 Cache Data", /* 1_1100b */
  83. "L3 Cache Tag error", /* 1_1101b */
  84. "L3 Cache LRU Parity error", /* 1_1110b */
  85. "Probe Filter error" /* 1_1111b */
  86. };
  87. EXPORT_SYMBOL_GPL(ext_msgs);
  88. static bool f10h_dc_mce(u16 ec)
  89. {
  90. u8 r4 = (ec >> 4) & 0xf;
  91. bool ret = false;
  92. if (r4 == R4_GEN) {
  93. pr_cont("during data scrub.\n");
  94. return true;
  95. }
  96. if (MEM_ERROR(ec)) {
  97. u8 ll = ec & 0x3;
  98. ret = true;
  99. if (ll == LL_L2)
  100. pr_cont("during L1 linefill from L2.\n");
  101. else if (ll == LL_L1)
  102. pr_cont("Data/Tag %s error.\n", RRRR_MSG(ec));
  103. else
  104. ret = false;
  105. }
  106. return ret;
  107. }
  108. static bool k8_dc_mce(u16 ec)
  109. {
  110. if (BUS_ERROR(ec)) {
  111. pr_cont("during system linefill.\n");
  112. return true;
  113. }
  114. return f10h_dc_mce(ec);
  115. }
  116. static bool f14h_dc_mce(u16 ec)
  117. {
  118. u8 r4 = (ec >> 4) & 0xf;
  119. u8 ll = ec & 0x3;
  120. u8 tt = (ec >> 2) & 0x3;
  121. u8 ii = tt;
  122. bool ret = true;
  123. if (MEM_ERROR(ec)) {
  124. if (tt != TT_DATA || ll != LL_L1)
  125. return false;
  126. switch (r4) {
  127. case R4_DRD:
  128. case R4_DWR:
  129. pr_cont("Data/Tag parity error due to %s.\n",
  130. (r4 == R4_DRD ? "load/hw prf" : "store"));
  131. break;
  132. case R4_EVICT:
  133. pr_cont("Copyback parity error on a tag miss.\n");
  134. break;
  135. case R4_SNOOP:
  136. pr_cont("Tag parity error during snoop.\n");
  137. break;
  138. default:
  139. ret = false;
  140. }
  141. } else if (BUS_ERROR(ec)) {
  142. if ((ii != II_MEM && ii != II_IO) || ll != LL_LG)
  143. return false;
  144. pr_cont("System read data error on a ");
  145. switch (r4) {
  146. case R4_RD:
  147. pr_cont("TLB reload.\n");
  148. break;
  149. case R4_DWR:
  150. pr_cont("store.\n");
  151. break;
  152. case R4_DRD:
  153. pr_cont("load.\n");
  154. break;
  155. default:
  156. ret = false;
  157. }
  158. } else {
  159. ret = false;
  160. }
  161. return ret;
  162. }
  163. static void amd_decode_dc_mce(struct mce *m)
  164. {
  165. u16 ec = m->status & 0xffff;
  166. u8 xec = (m->status >> 16) & 0xf;
  167. pr_emerg(HW_ERR "Data Cache Error: ");
  168. /* TLB error signatures are the same across families */
  169. if (TLB_ERROR(ec)) {
  170. u8 tt = (ec >> 2) & 0x3;
  171. if (tt == TT_DATA) {
  172. pr_cont("%s TLB %s.\n", LL_MSG(ec),
  173. (xec ? "multimatch" : "parity error"));
  174. return;
  175. }
  176. else
  177. goto wrong_dc_mce;
  178. }
  179. if (!fam_ops->dc_mce(ec))
  180. goto wrong_dc_mce;
  181. return;
  182. wrong_dc_mce:
  183. pr_emerg(HW_ERR "Corrupted DC MCE info?\n");
  184. }
  185. static void amd_decode_ic_mce(struct mce *m)
  186. {
  187. u32 ec = m->status & 0xffff;
  188. u32 xec = (m->status >> 16) & 0xf;
  189. pr_emerg(HW_ERR "Instruction Cache Error");
  190. if (xec == 1 && TLB_ERROR(ec))
  191. pr_cont(": %s TLB multimatch.\n", LL_MSG(ec));
  192. else if (xec == 0) {
  193. if (TLB_ERROR(ec))
  194. pr_cont(": %s TLB Parity error.\n", LL_MSG(ec));
  195. else if (BUS_ERROR(ec)) {
  196. if (boot_cpu_data.x86 == 0xf &&
  197. (m->status & BIT(58)))
  198. pr_cont(" during system linefill.\n");
  199. else
  200. pr_cont(" during attempted NB data read.\n");
  201. } else if (MEM_ERROR(ec)) {
  202. u8 ll = ec & 0x3;
  203. u8 rrrr = (ec >> 4) & 0xf;
  204. if (ll == 0x2)
  205. pr_cont(" during a linefill from L2.\n");
  206. else if (ll == 0x1) {
  207. switch (rrrr) {
  208. case 0x5:
  209. pr_cont(": Parity error during "
  210. "data load.\n");
  211. break;
  212. case 0x7:
  213. pr_cont(": Copyback Parity/Victim"
  214. " error.\n");
  215. break;
  216. case 0x8:
  217. pr_cont(": Tag Snoop error.\n");
  218. break;
  219. default:
  220. goto wrong_ic_mce;
  221. break;
  222. }
  223. }
  224. } else
  225. goto wrong_ic_mce;
  226. } else
  227. goto wrong_ic_mce;
  228. return;
  229. wrong_ic_mce:
  230. pr_emerg(HW_ERR "Corrupted IC MCE info?\n");
  231. }
  232. static void amd_decode_bu_mce(struct mce *m)
  233. {
  234. u32 ec = m->status & 0xffff;
  235. u32 xec = (m->status >> 16) & 0xf;
  236. pr_emerg(HW_ERR "Bus Unit Error");
  237. if (xec == 0x1)
  238. pr_cont(" in the write data buffers.\n");
  239. else if (xec == 0x3)
  240. pr_cont(" in the victim data buffers.\n");
  241. else if (xec == 0x2 && MEM_ERROR(ec))
  242. pr_cont(": %s error in the L2 cache tags.\n", RRRR_MSG(ec));
  243. else if (xec == 0x0) {
  244. if (TLB_ERROR(ec))
  245. pr_cont(": %s error in a Page Descriptor Cache or "
  246. "Guest TLB.\n", TT_MSG(ec));
  247. else if (BUS_ERROR(ec))
  248. pr_cont(": %s/ECC error in data read from NB: %s.\n",
  249. RRRR_MSG(ec), PP_MSG(ec));
  250. else if (MEM_ERROR(ec)) {
  251. u8 rrrr = (ec >> 4) & 0xf;
  252. if (rrrr >= 0x7)
  253. pr_cont(": %s error during data copyback.\n",
  254. RRRR_MSG(ec));
  255. else if (rrrr <= 0x1)
  256. pr_cont(": %s parity/ECC error during data "
  257. "access from L2.\n", RRRR_MSG(ec));
  258. else
  259. goto wrong_bu_mce;
  260. } else
  261. goto wrong_bu_mce;
  262. } else
  263. goto wrong_bu_mce;
  264. return;
  265. wrong_bu_mce:
  266. pr_emerg(HW_ERR "Corrupted BU MCE info?\n");
  267. }
  268. static void amd_decode_ls_mce(struct mce *m)
  269. {
  270. u32 ec = m->status & 0xffff;
  271. u32 xec = (m->status >> 16) & 0xf;
  272. pr_emerg(HW_ERR "Load Store Error");
  273. if (xec == 0x0) {
  274. u8 rrrr = (ec >> 4) & 0xf;
  275. if (!BUS_ERROR(ec) || (rrrr != 0x3 && rrrr != 0x4))
  276. goto wrong_ls_mce;
  277. pr_cont(" during %s.\n", RRRR_MSG(ec));
  278. }
  279. return;
  280. wrong_ls_mce:
  281. pr_emerg(HW_ERR "Corrupted LS MCE info?\n");
  282. }
  283. void amd_decode_nb_mce(int node_id, struct mce *m, u32 nbcfg)
  284. {
  285. u32 ec = m->status & 0xffff;
  286. u32 nbsh = (u32)(m->status >> 32);
  287. u32 nbsl = (u32)m->status;
  288. /*
  289. * GART TLB error reporting is disabled by default. Bail out early.
  290. */
  291. if (TLB_ERROR(ec) && !report_gart_errors)
  292. return;
  293. pr_emerg(HW_ERR "Northbridge Error, node %d", node_id);
  294. /*
  295. * F10h, revD can disable ErrCpu[3:0] so check that first and also the
  296. * value encoding has changed so interpret those differently
  297. */
  298. if ((boot_cpu_data.x86 == 0x10) &&
  299. (boot_cpu_data.x86_model > 7)) {
  300. if (nbsh & K8_NBSH_ERR_CPU_VAL)
  301. pr_cont(", core: %u\n", (u8)(nbsh & 0xf));
  302. } else {
  303. u8 assoc_cpus = nbsh & 0xf;
  304. if (assoc_cpus > 0)
  305. pr_cont(", core: %d", fls(assoc_cpus) - 1);
  306. pr_cont("\n");
  307. }
  308. pr_emerg(HW_ERR "%s.\n", EXT_ERR_MSG(nbsl));
  309. if (BUS_ERROR(ec) && nb_bus_decoder)
  310. nb_bus_decoder(node_id, m, nbcfg);
  311. }
  312. EXPORT_SYMBOL_GPL(amd_decode_nb_mce);
  313. static void amd_decode_fr_mce(struct mce *m)
  314. {
  315. /* we have only one error signature so match all fields at once. */
  316. if ((m->status & 0xffff) == 0x0f0f)
  317. pr_emerg(HW_ERR " FR Error: CPU Watchdog timer expire.\n");
  318. else
  319. pr_emerg(HW_ERR "Corrupted FR MCE info?\n");
  320. }
  321. static inline void amd_decode_err_code(u16 ec)
  322. {
  323. if (TLB_ERROR(ec)) {
  324. pr_emerg(HW_ERR "Transaction: %s, Cache Level: %s\n",
  325. TT_MSG(ec), LL_MSG(ec));
  326. } else if (MEM_ERROR(ec)) {
  327. pr_emerg(HW_ERR "Transaction: %s, Type: %s, Cache Level: %s\n",
  328. RRRR_MSG(ec), TT_MSG(ec), LL_MSG(ec));
  329. } else if (BUS_ERROR(ec)) {
  330. pr_emerg(HW_ERR "Transaction: %s (%s), %s, Cache Level: %s, "
  331. "Participating Processor: %s\n",
  332. RRRR_MSG(ec), II_MSG(ec), TO_MSG(ec), LL_MSG(ec),
  333. PP_MSG(ec));
  334. } else
  335. pr_emerg(HW_ERR "Huh? Unknown MCE error 0x%x\n", ec);
  336. }
  337. int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
  338. {
  339. struct mce *m = (struct mce *)data;
  340. int node, ecc;
  341. pr_emerg(HW_ERR "MC%d_STATUS: ", m->bank);
  342. pr_cont("%sorrected error, other errors lost: %s, "
  343. "CPU context corrupt: %s",
  344. ((m->status & MCI_STATUS_UC) ? "Unc" : "C"),
  345. ((m->status & MCI_STATUS_OVER) ? "yes" : "no"),
  346. ((m->status & MCI_STATUS_PCC) ? "yes" : "no"));
  347. /* do the two bits[14:13] together */
  348. ecc = (m->status >> 45) & 0x3;
  349. if (ecc)
  350. pr_cont(", %sECC Error", ((ecc == 2) ? "C" : "U"));
  351. pr_cont("\n");
  352. switch (m->bank) {
  353. case 0:
  354. amd_decode_dc_mce(m);
  355. break;
  356. case 1:
  357. amd_decode_ic_mce(m);
  358. break;
  359. case 2:
  360. amd_decode_bu_mce(m);
  361. break;
  362. case 3:
  363. amd_decode_ls_mce(m);
  364. break;
  365. case 4:
  366. node = amd_get_nb_id(m->extcpu);
  367. amd_decode_nb_mce(node, m, 0);
  368. break;
  369. case 5:
  370. amd_decode_fr_mce(m);
  371. break;
  372. default:
  373. break;
  374. }
  375. amd_decode_err_code(m->status & 0xffff);
  376. return NOTIFY_STOP;
  377. }
  378. EXPORT_SYMBOL_GPL(amd_decode_mce);
  379. static struct notifier_block amd_mce_dec_nb = {
  380. .notifier_call = amd_decode_mce,
  381. };
  382. static int __init mce_amd_init(void)
  383. {
  384. /*
  385. * We can decode MCEs for K8, F10h and F11h CPUs:
  386. */
  387. if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
  388. return 0;
  389. if (boot_cpu_data.x86 < 0xf || boot_cpu_data.x86 > 0x11)
  390. return 0;
  391. fam_ops = kzalloc(sizeof(struct amd_decoder_ops), GFP_KERNEL);
  392. if (!fam_ops)
  393. return -ENOMEM;
  394. switch (boot_cpu_data.x86) {
  395. case 0xf:
  396. fam_ops->dc_mce = k8_dc_mce;
  397. break;
  398. case 0x10:
  399. fam_ops->dc_mce = f10h_dc_mce;
  400. break;
  401. case 0x14:
  402. fam_ops->dc_mce = f14h_dc_mce;
  403. break;
  404. default:
  405. printk(KERN_WARNING "Huh? What family is that: %d?!\n",
  406. boot_cpu_data.x86);
  407. kfree(fam_ops);
  408. return -EINVAL;
  409. }
  410. atomic_notifier_chain_register(&x86_mce_decoder_chain, &amd_mce_dec_nb);
  411. return 0;
  412. }
  413. early_initcall(mce_amd_init);
  414. #ifdef MODULE
  415. static void __exit mce_amd_exit(void)
  416. {
  417. atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &amd_mce_dec_nb);
  418. kfree(fam_ops);
  419. }
  420. MODULE_DESCRIPTION("AMD MCE decoder");
  421. MODULE_ALIAS("edac-mce-amd");
  422. MODULE_LICENSE("GPL");
  423. module_exit(mce_amd_exit);
  424. #endif