edac_mce_amd.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. #include <linux/module.h>
  2. #include "edac_mce_amd.h"
  3. static bool report_gart_errors;
  4. static void (*nb_bus_decoder)(int node_id, struct err_regs *regs);
  5. static void (*orig_mce_callback)(struct mce *m);
  6. void amd_report_gart_errors(bool v)
  7. {
  8. report_gart_errors = v;
  9. }
  10. EXPORT_SYMBOL_GPL(amd_report_gart_errors);
  11. void amd_register_ecc_decoder(void (*f)(int, struct err_regs *))
  12. {
  13. nb_bus_decoder = f;
  14. }
  15. EXPORT_SYMBOL_GPL(amd_register_ecc_decoder);
  16. void amd_unregister_ecc_decoder(void (*f)(int, struct err_regs *))
  17. {
  18. if (nb_bus_decoder) {
  19. WARN_ON(nb_bus_decoder != f);
  20. nb_bus_decoder = NULL;
  21. }
  22. }
  23. EXPORT_SYMBOL_GPL(amd_unregister_ecc_decoder);
  24. /*
  25. * string representation for the different MCA reported error types, see F3x48
  26. * or MSR0000_0411.
  27. */
  28. const char *tt_msgs[] = { /* transaction type */
  29. "instruction",
  30. "data",
  31. "generic",
  32. "reserved"
  33. };
  34. EXPORT_SYMBOL_GPL(tt_msgs);
  35. const char *ll_msgs[] = { /* cache level */
  36. "L0",
  37. "L1",
  38. "L2",
  39. "L3/generic"
  40. };
  41. EXPORT_SYMBOL_GPL(ll_msgs);
  42. const char *rrrr_msgs[] = {
  43. "generic",
  44. "generic read",
  45. "generic write",
  46. "data read",
  47. "data write",
  48. "inst fetch",
  49. "prefetch",
  50. "evict",
  51. "snoop",
  52. "reserved RRRR= 9",
  53. "reserved RRRR= 10",
  54. "reserved RRRR= 11",
  55. "reserved RRRR= 12",
  56. "reserved RRRR= 13",
  57. "reserved RRRR= 14",
  58. "reserved RRRR= 15"
  59. };
  60. EXPORT_SYMBOL_GPL(rrrr_msgs);
  61. const char *pp_msgs[] = { /* participating processor */
  62. "local node originated (SRC)",
  63. "local node responded to request (RES)",
  64. "local node observed as 3rd party (OBS)",
  65. "generic"
  66. };
  67. EXPORT_SYMBOL_GPL(pp_msgs);
  68. const char *to_msgs[] = {
  69. "no timeout",
  70. "timed out"
  71. };
  72. EXPORT_SYMBOL_GPL(to_msgs);
  73. const char *ii_msgs[] = { /* memory or i/o */
  74. "mem access",
  75. "reserved",
  76. "i/o access",
  77. "generic"
  78. };
  79. EXPORT_SYMBOL_GPL(ii_msgs);
  80. /*
  81. * Map the 4 or 5 (family-specific) bits of Extended Error code to the
  82. * string table.
  83. */
  84. const char *ext_msgs[] = {
  85. "K8 ECC error", /* 0_0000b */
  86. "CRC error on link", /* 0_0001b */
  87. "Sync error packets on link", /* 0_0010b */
  88. "Master Abort during link operation", /* 0_0011b */
  89. "Target Abort during link operation", /* 0_0100b */
  90. "Invalid GART PTE entry during table walk", /* 0_0101b */
  91. "Unsupported atomic RMW command received", /* 0_0110b */
  92. "WDT error: NB transaction timeout", /* 0_0111b */
  93. "ECC/ChipKill ECC error", /* 0_1000b */
  94. "SVM DEV Error", /* 0_1001b */
  95. "Link Data error", /* 0_1010b */
  96. "Link/L3/Probe Filter Protocol error", /* 0_1011b */
  97. "NB Internal Arrays Parity error", /* 0_1100b */
  98. "DRAM Address/Control Parity error", /* 0_1101b */
  99. "Link Transmission error", /* 0_1110b */
  100. "GART/DEV Table Walk Data error" /* 0_1111b */
  101. "Res 0x100 error", /* 1_0000b */
  102. "Res 0x101 error", /* 1_0001b */
  103. "Res 0x102 error", /* 1_0010b */
  104. "Res 0x103 error", /* 1_0011b */
  105. "Res 0x104 error", /* 1_0100b */
  106. "Res 0x105 error", /* 1_0101b */
  107. "Res 0x106 error", /* 1_0110b */
  108. "Res 0x107 error", /* 1_0111b */
  109. "Res 0x108 error", /* 1_1000b */
  110. "Res 0x109 error", /* 1_1001b */
  111. "Res 0x10A error", /* 1_1010b */
  112. "Res 0x10B error", /* 1_1011b */
  113. "ECC error in L3 Cache Data", /* 1_1100b */
  114. "L3 Cache Tag error", /* 1_1101b */
  115. "L3 Cache LRU Parity error", /* 1_1110b */
  116. "Probe Filter error" /* 1_1111b */
  117. };
  118. EXPORT_SYMBOL_GPL(ext_msgs);
  119. static void amd_decode_dc_mce(u64 mc0_status)
  120. {
  121. u32 ec = mc0_status & 0xffff;
  122. u32 xec = (mc0_status >> 16) & 0xf;
  123. pr_emerg(" Data Cache Error");
  124. if (xec == 1 && TLB_ERROR(ec))
  125. pr_cont(": %s TLB multimatch.\n", LL_MSG(ec));
  126. else if (xec == 0) {
  127. if (mc0_status & (1ULL << 40))
  128. pr_cont(" during Data Scrub.\n");
  129. else if (TLB_ERROR(ec))
  130. pr_cont(": %s TLB parity error.\n", LL_MSG(ec));
  131. else if (MEM_ERROR(ec)) {
  132. u8 ll = ec & 0x3;
  133. u8 tt = (ec >> 2) & 0x3;
  134. u8 rrrr = (ec >> 4) & 0xf;
  135. /* see F10h BKDG (31116), Table 92. */
  136. if (ll == 0x1) {
  137. if (tt != 0x1)
  138. goto wrong_dc_mce;
  139. pr_cont(": Data/Tag %s error.\n", RRRR_MSG(ec));
  140. } else if (ll == 0x2 && rrrr == 0x3)
  141. pr_cont(" during L1 linefill from L2.\n");
  142. else
  143. goto wrong_dc_mce;
  144. } else if (BUS_ERROR(ec) && boot_cpu_data.x86 == 0xf)
  145. pr_cont(" during system linefill.\n");
  146. else
  147. goto wrong_dc_mce;
  148. } else
  149. goto wrong_dc_mce;
  150. return;
  151. wrong_dc_mce:
  152. pr_warning("Corrupted DC MCE info?\n");
  153. }
  154. static void amd_decode_ic_mce(u64 mc1_status)
  155. {
  156. u32 ec = mc1_status & 0xffff;
  157. u32 xec = (mc1_status >> 16) & 0xf;
  158. pr_emerg(" Instruction Cache Error");
  159. if (xec == 1 && TLB_ERROR(ec))
  160. pr_cont(": %s TLB multimatch.\n", LL_MSG(ec));
  161. else if (xec == 0) {
  162. if (TLB_ERROR(ec))
  163. pr_cont(": %s TLB Parity error.\n", LL_MSG(ec));
  164. else if (BUS_ERROR(ec)) {
  165. if (boot_cpu_data.x86 == 0xf &&
  166. (mc1_status & (1ULL << 58)))
  167. pr_cont(" during system linefill.\n");
  168. else
  169. pr_cont(" during attempted NB data read.\n");
  170. } else if (MEM_ERROR(ec)) {
  171. u8 ll = ec & 0x3;
  172. u8 rrrr = (ec >> 4) & 0xf;
  173. if (ll == 0x2)
  174. pr_cont(" during a linefill from L2.\n");
  175. else if (ll == 0x1) {
  176. switch (rrrr) {
  177. case 0x5:
  178. pr_cont(": Parity error during "
  179. "data load.\n");
  180. break;
  181. case 0x7:
  182. pr_cont(": Copyback Parity/Victim"
  183. " error.\n");
  184. break;
  185. case 0x8:
  186. pr_cont(": Tag Snoop error.\n");
  187. break;
  188. default:
  189. goto wrong_ic_mce;
  190. break;
  191. }
  192. }
  193. } else
  194. goto wrong_ic_mce;
  195. } else
  196. goto wrong_ic_mce;
  197. return;
  198. wrong_ic_mce:
  199. pr_warning("Corrupted IC MCE info?\n");
  200. }
  201. static void amd_decode_bu_mce(u64 mc2_status)
  202. {
  203. u32 ec = mc2_status & 0xffff;
  204. u32 xec = (mc2_status >> 16) & 0xf;
  205. pr_emerg(" Bus Unit Error");
  206. if (xec == 0x1)
  207. pr_cont(" in the write data buffers.\n");
  208. else if (xec == 0x3)
  209. pr_cont(" in the victim data buffers.\n");
  210. else if (xec == 0x2 && MEM_ERROR(ec))
  211. pr_cont(": %s error in the L2 cache tags.\n", RRRR_MSG(ec));
  212. else if (xec == 0x0) {
  213. if (TLB_ERROR(ec))
  214. pr_cont(": %s error in a Page Descriptor Cache or "
  215. "Guest TLB.\n", TT_MSG(ec));
  216. else if (BUS_ERROR(ec))
  217. pr_cont(": %s/ECC error in data read from NB: %s.\n",
  218. RRRR_MSG(ec), PP_MSG(ec));
  219. else if (MEM_ERROR(ec)) {
  220. u8 rrrr = (ec >> 4) & 0xf;
  221. if (rrrr >= 0x7)
  222. pr_cont(": %s error during data copyback.\n",
  223. RRRR_MSG(ec));
  224. else if (rrrr <= 0x1)
  225. pr_cont(": %s parity/ECC error during data "
  226. "access from L2.\n", RRRR_MSG(ec));
  227. else
  228. goto wrong_bu_mce;
  229. } else
  230. goto wrong_bu_mce;
  231. } else
  232. goto wrong_bu_mce;
  233. return;
  234. wrong_bu_mce:
  235. pr_warning("Corrupted BU MCE info?\n");
  236. }
  237. static void amd_decode_ls_mce(u64 mc3_status)
  238. {
  239. u32 ec = mc3_status & 0xffff;
  240. u32 xec = (mc3_status >> 16) & 0xf;
  241. pr_emerg(" Load Store Error");
  242. if (xec == 0x0) {
  243. u8 rrrr = (ec >> 4) & 0xf;
  244. if (!BUS_ERROR(ec) || (rrrr != 0x3 && rrrr != 0x4))
  245. goto wrong_ls_mce;
  246. pr_cont(" during %s.\n", RRRR_MSG(ec));
  247. }
  248. return;
  249. wrong_ls_mce:
  250. pr_warning("Corrupted LS MCE info?\n");
  251. }
  252. void amd_decode_nb_mce(int node_id, struct err_regs *regs, int handle_errors)
  253. {
  254. u32 ec = ERROR_CODE(regs->nbsl);
  255. u32 xec = EXT_ERROR_CODE(regs->nbsl);
  256. if (!handle_errors)
  257. return;
  258. pr_emerg(" Northbridge Error, node %d", node_id);
  259. /*
  260. * F10h, revD can disable ErrCpu[3:0] so check that first and also the
  261. * value encoding has changed so interpret those differently
  262. */
  263. if ((boot_cpu_data.x86 == 0x10) &&
  264. (boot_cpu_data.x86_model > 8)) {
  265. if (regs->nbsh & K8_NBSH_ERR_CPU_VAL)
  266. pr_cont(", core: %u\n", (u8)(regs->nbsh & 0xf));
  267. } else {
  268. pr_cont(", core: %d\n", ilog2((regs->nbsh & 0xf)));
  269. }
  270. pr_emerg("%s.\n", EXT_ERR_MSG(xec));
  271. if (BUS_ERROR(ec) && nb_bus_decoder)
  272. nb_bus_decoder(node_id, regs);
  273. }
  274. EXPORT_SYMBOL_GPL(amd_decode_nb_mce);
  275. static void amd_decode_fr_mce(u64 mc5_status)
  276. {
  277. /* we have only one error signature so match all fields at once. */
  278. if ((mc5_status & 0xffff) == 0x0f0f)
  279. pr_emerg(" FR Error: CPU Watchdog timer expire.\n");
  280. else
  281. pr_warning("Corrupted FR MCE info?\n");
  282. }
  283. static inline void amd_decode_err_code(unsigned int ec)
  284. {
  285. if (TLB_ERROR(ec)) {
  286. /*
  287. * GART errors are intended to help graphics driver developers
  288. * to detect bad GART PTEs. It is recommended by AMD to disable
  289. * GART table walk error reporting by default[1] (currently
  290. * being disabled in mce_cpu_quirks()) and according to the
  291. * comment in mce_cpu_quirks(), such GART errors can be
  292. * incorrectly triggered. We may see these errors anyway and
  293. * unless requested by the user, they won't be reported.
  294. *
  295. * [1] section 13.10.1 on BIOS and Kernel Developers Guide for
  296. * AMD NPT family 0Fh processors
  297. */
  298. if (!report_gart_errors)
  299. return;
  300. pr_emerg(" Transaction: %s, Cache Level %s\n",
  301. TT_MSG(ec), LL_MSG(ec));
  302. } else if (MEM_ERROR(ec)) {
  303. pr_emerg(" Transaction: %s, Type: %s, Cache Level: %s",
  304. RRRR_MSG(ec), TT_MSG(ec), LL_MSG(ec));
  305. } else if (BUS_ERROR(ec)) {
  306. pr_emerg(" Transaction type: %s(%s), %s, Cache Level: %s, "
  307. "Participating Processor: %s\n",
  308. RRRR_MSG(ec), II_MSG(ec), TO_MSG(ec), LL_MSG(ec),
  309. PP_MSG(ec));
  310. } else
  311. pr_warning("Huh? Unknown MCE error 0x%x\n", ec);
  312. }
  313. static void amd_decode_mce(struct mce *m)
  314. {
  315. struct err_regs regs;
  316. int node, ecc;
  317. pr_emerg("MC%d_STATUS: ", m->bank);
  318. pr_cont("%sorrected error, report: %s, MiscV: %svalid, "
  319. "CPU context corrupt: %s",
  320. ((m->status & MCI_STATUS_UC) ? "Unc" : "C"),
  321. ((m->status & MCI_STATUS_EN) ? "yes" : "no"),
  322. ((m->status & MCI_STATUS_MISCV) ? "" : "in"),
  323. ((m->status & MCI_STATUS_PCC) ? "yes" : "no"));
  324. /* do the two bits[14:13] together */
  325. ecc = m->status & (3ULL << 45);
  326. if (ecc)
  327. pr_cont(", %sECC Error", ((ecc == 2) ? "C" : "U"));
  328. pr_cont("\n");
  329. switch (m->bank) {
  330. case 0:
  331. amd_decode_dc_mce(m->status);
  332. break;
  333. case 1:
  334. amd_decode_ic_mce(m->status);
  335. break;
  336. case 2:
  337. amd_decode_bu_mce(m->status);
  338. break;
  339. case 3:
  340. amd_decode_ls_mce(m->status);
  341. break;
  342. case 4:
  343. regs.nbsl = (u32) m->status;
  344. regs.nbsh = (u32)(m->status >> 32);
  345. regs.nbeal = (u32) m->addr;
  346. regs.nbeah = (u32)(m->addr >> 32);
  347. node = amd_get_nb_id(m->extcpu);
  348. amd_decode_nb_mce(node, &regs, 1);
  349. break;
  350. case 5:
  351. amd_decode_fr_mce(m->status);
  352. break;
  353. default:
  354. break;
  355. }
  356. amd_decode_err_code(m->status & 0xffff);
  357. }
  358. static int __init mce_amd_init(void)
  359. {
  360. /*
  361. * We can decode MCEs for Opteron and later CPUs:
  362. */
  363. if ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) &&
  364. (boot_cpu_data.x86 >= 0xf)) {
  365. /* safe the default decode mce callback */
  366. orig_mce_callback = x86_mce_decode_callback;
  367. x86_mce_decode_callback = amd_decode_mce;
  368. }
  369. return 0;
  370. }
  371. early_initcall(mce_amd_init);
  372. #ifdef MODULE
  373. static void __exit mce_amd_exit(void)
  374. {
  375. x86_mce_decode_callback = orig_mce_callback;
  376. }
  377. MODULE_DESCRIPTION("AMD MCE decoder");
  378. MODULE_ALIAS("edac-mce-amd");
  379. MODULE_LICENSE("GPL");
  380. module_exit(mce_amd_exit);
  381. #endif