mce_amd.c 9.8 KB

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