ghes_edac.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /*
  2. * GHES/EDAC Linux driver
  3. *
  4. * This file may be distributed under the terms of the GNU General Public
  5. * License version 2.
  6. *
  7. * Copyright (c) 2013 by Mauro Carvalho Chehab <mchehab@redhat.com>
  8. *
  9. * Red Hat Inc. http://www.redhat.com
  10. */
  11. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #include <acpi/ghes.h>
  13. #include <linux/edac.h>
  14. #include <linux/dmi.h>
  15. #include "edac_core.h"
  16. #define GHES_EDAC_REVISION " Ver: 1.0.0"
  17. struct ghes_edac_pvt {
  18. struct list_head list;
  19. struct ghes *ghes;
  20. struct mem_ctl_info *mci;
  21. /* Buffers for the error handling routine */
  22. char other_detail[160];
  23. char msg[80];
  24. };
  25. static LIST_HEAD(ghes_reglist);
  26. static DEFINE_MUTEX(ghes_edac_lock);
  27. static int ghes_edac_mc_num;
  28. /* Memory Device - Type 17 of SMBIOS spec */
  29. struct memdev_dmi_entry {
  30. u8 type;
  31. u8 length;
  32. u16 handle;
  33. u16 phys_mem_array_handle;
  34. u16 mem_err_info_handle;
  35. u16 total_width;
  36. u16 data_width;
  37. u16 size;
  38. u8 form_factor;
  39. u8 device_set;
  40. u8 device_locator;
  41. u8 bank_locator;
  42. u8 memory_type;
  43. u16 type_detail;
  44. u16 speed;
  45. u8 manufacturer;
  46. u8 serial_number;
  47. u8 asset_tag;
  48. u8 part_number;
  49. u8 attributes;
  50. u32 extended_size;
  51. u16 conf_mem_clk_speed;
  52. } __attribute__((__packed__));
  53. struct ghes_edac_dimm_fill {
  54. struct mem_ctl_info *mci;
  55. unsigned count;
  56. };
  57. char *memory_type[] = {
  58. [MEM_EMPTY] = "EMPTY",
  59. [MEM_RESERVED] = "RESERVED",
  60. [MEM_UNKNOWN] = "UNKNOWN",
  61. [MEM_FPM] = "FPM",
  62. [MEM_EDO] = "EDO",
  63. [MEM_BEDO] = "BEDO",
  64. [MEM_SDR] = "SDR",
  65. [MEM_RDR] = "RDR",
  66. [MEM_DDR] = "DDR",
  67. [MEM_RDDR] = "RDDR",
  68. [MEM_RMBS] = "RMBS",
  69. [MEM_DDR2] = "DDR2",
  70. [MEM_FB_DDR2] = "FB_DDR2",
  71. [MEM_RDDR2] = "RDDR2",
  72. [MEM_XDR] = "XDR",
  73. [MEM_DDR3] = "DDR3",
  74. [MEM_RDDR3] = "RDDR3",
  75. };
  76. static void ghes_edac_count_dimms(const struct dmi_header *dh, void *arg)
  77. {
  78. int *num_dimm = arg;
  79. if (dh->type == DMI_ENTRY_MEM_DEVICE)
  80. (*num_dimm)++;
  81. }
  82. static void ghes_edac_dmidecode(const struct dmi_header *dh, void *arg)
  83. {
  84. struct ghes_edac_dimm_fill *dimm_fill = arg;
  85. struct mem_ctl_info *mci = dimm_fill->mci;
  86. if (dh->type == DMI_ENTRY_MEM_DEVICE) {
  87. struct memdev_dmi_entry *entry = (struct memdev_dmi_entry *)dh;
  88. struct dimm_info *dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
  89. mci->n_layers,
  90. dimm_fill->count, 0, 0);
  91. if (entry->size == 0xffff) {
  92. pr_info("Can't get DIMM%i size\n",
  93. dimm_fill->count);
  94. dimm->nr_pages = MiB_TO_PAGES(32);/* Unknown */
  95. } else if (entry->size == 0x7fff) {
  96. dimm->nr_pages = MiB_TO_PAGES(entry->extended_size);
  97. } else {
  98. if (entry->size & 1 << 15)
  99. dimm->nr_pages = MiB_TO_PAGES((entry->size &
  100. 0x7fff) << 10);
  101. else
  102. dimm->nr_pages = MiB_TO_PAGES(entry->size);
  103. }
  104. switch (entry->memory_type) {
  105. case 0x12:
  106. if (entry->type_detail & 1 << 13)
  107. dimm->mtype = MEM_RDDR;
  108. else
  109. dimm->mtype = MEM_DDR;
  110. break;
  111. case 0x13:
  112. if (entry->type_detail & 1 << 13)
  113. dimm->mtype = MEM_RDDR2;
  114. else
  115. dimm->mtype = MEM_DDR2;
  116. break;
  117. case 0x14:
  118. dimm->mtype = MEM_FB_DDR2;
  119. break;
  120. case 0x18:
  121. if (entry->type_detail & 1 << 13)
  122. dimm->mtype = MEM_RDDR3;
  123. else
  124. dimm->mtype = MEM_DDR3;
  125. break;
  126. default:
  127. if (entry->type_detail & 1 << 6)
  128. dimm->mtype = MEM_RMBS;
  129. else if ((entry->type_detail & ((1 << 7) | (1 << 13)))
  130. == ((1 << 7) | (1 << 13)))
  131. dimm->mtype = MEM_RDR;
  132. else if (entry->type_detail & 1 << 7)
  133. dimm->mtype = MEM_SDR;
  134. else if (entry->type_detail & 1 << 9)
  135. dimm->mtype = MEM_EDO;
  136. else
  137. dimm->mtype = MEM_UNKNOWN;
  138. }
  139. /*
  140. * Actually, we can only detect if the memory has bits for
  141. * checksum or not
  142. */
  143. if (entry->total_width == entry->data_width)
  144. dimm->edac_mode = EDAC_NONE;
  145. else
  146. dimm->edac_mode = EDAC_SECDED;
  147. dimm->dtype = DEV_UNKNOWN;
  148. dimm->grain = 128; /* Likely, worse case */
  149. /*
  150. * FIXME: It shouldn't be hard to also fill the DIMM labels
  151. */
  152. if (dimm->nr_pages) {
  153. edac_dbg(1, "DIMM%i: %s size = %d MB%s\n",
  154. dimm_fill->count, memory_type[dimm->mtype],
  155. PAGES_TO_MiB(dimm->nr_pages),
  156. (dimm->edac_mode != EDAC_NONE) ? "(ECC)" : "");
  157. edac_dbg(2, "\ttype %d, detail 0x%02x, width %d(total %d)\n",
  158. entry->memory_type, entry->type_detail,
  159. entry->total_width, entry->data_width);
  160. }
  161. dimm_fill->count++;
  162. }
  163. }
  164. void ghes_edac_report_mem_error(struct ghes *ghes, int sev,
  165. struct cper_sec_mem_err *mem_err)
  166. {
  167. enum hw_event_mc_err_type type;
  168. struct edac_raw_error_desc *e;
  169. struct mem_ctl_info *mci;
  170. struct ghes_edac_pvt *pvt = NULL;
  171. char *p;
  172. list_for_each_entry(pvt, &ghes_reglist, list) {
  173. if (ghes == pvt->ghes)
  174. break;
  175. }
  176. if (!pvt) {
  177. pr_err("Internal error: Can't find EDAC structure\n");
  178. return;
  179. }
  180. mci = pvt->mci;
  181. e = &mci->error_desc;
  182. /* Cleans the error report buffer */
  183. memset(e, 0, sizeof (*e));
  184. e->error_count = 1;
  185. strcpy(e->label, "unknown label");
  186. e->msg = pvt->msg;
  187. e->other_detail = pvt->other_detail;
  188. e->top_layer = -1;
  189. e->mid_layer = -1;
  190. e->low_layer = -1;
  191. *pvt->other_detail = '\0';
  192. *pvt->msg = '\0';
  193. switch (sev) {
  194. case GHES_SEV_CORRECTED:
  195. type = HW_EVENT_ERR_CORRECTED;
  196. break;
  197. case GHES_SEV_RECOVERABLE:
  198. type = HW_EVENT_ERR_UNCORRECTED;
  199. break;
  200. case GHES_SEV_PANIC:
  201. type = HW_EVENT_ERR_FATAL;
  202. break;
  203. default:
  204. case GHES_SEV_NO:
  205. type = HW_EVENT_ERR_INFO;
  206. }
  207. edac_dbg(1, "error validation_bits: 0x%08llx\n",
  208. (long long)mem_err->validation_bits);
  209. /* Error type, mapped on e->msg */
  210. if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_TYPE) {
  211. p = pvt->msg;
  212. switch (mem_err->error_type) {
  213. case 0:
  214. p += sprintf(p, "Unknown");
  215. break;
  216. case 1:
  217. p += sprintf(p, "No error");
  218. break;
  219. case 2:
  220. p += sprintf(p, "Single-bit ECC");
  221. break;
  222. case 3:
  223. p += sprintf(p, "Multi-bit ECC");
  224. break;
  225. case 4:
  226. p += sprintf(p, "Single-symbol ChipKill ECC");
  227. break;
  228. case 5:
  229. p += sprintf(p, "Multi-symbol ChipKill ECC");
  230. break;
  231. case 6:
  232. p += sprintf(p, "Master abort");
  233. break;
  234. case 7:
  235. p += sprintf(p, "Target abort");
  236. break;
  237. case 8:
  238. p += sprintf(p, "Parity Error");
  239. break;
  240. case 9:
  241. p += sprintf(p, "Watchdog timeout");
  242. break;
  243. case 10:
  244. p += sprintf(p, "Invalid address");
  245. break;
  246. case 11:
  247. p += sprintf(p, "Mirror Broken");
  248. break;
  249. case 12:
  250. p += sprintf(p, "Memory Sparing");
  251. break;
  252. case 13:
  253. p += sprintf(p, "Scrub corrected error");
  254. break;
  255. case 14:
  256. p += sprintf(p, "Scrub uncorrected error");
  257. break;
  258. case 15:
  259. p += sprintf(p, "Physical Memory Map-out event");
  260. break;
  261. default:
  262. p += sprintf(p, "reserved error (%d)",
  263. mem_err->error_type);
  264. }
  265. } else {
  266. strcpy(pvt->msg, "unknown error");
  267. }
  268. /* Error address */
  269. if (mem_err->validation_bits & CPER_MEM_VALID_PHYSICAL_ADDRESS) {
  270. e->page_frame_number = mem_err->physical_addr >> PAGE_SHIFT;
  271. e->offset_in_page = mem_err->physical_addr & ~PAGE_MASK;
  272. }
  273. /* Error grain */
  274. if (mem_err->validation_bits & CPER_MEM_VALID_PHYSICAL_ADDRESS_MASK) {
  275. e->grain = ~(mem_err->physical_addr_mask & ~PAGE_MASK);
  276. }
  277. /* Memory error location, mapped on e->location */
  278. p = e->location;
  279. if (mem_err->validation_bits & CPER_MEM_VALID_NODE)
  280. p += sprintf(p, "node:%d ", mem_err->node);
  281. if (mem_err->validation_bits & CPER_MEM_VALID_CARD)
  282. p += sprintf(p, "card:%d ", mem_err->card);
  283. if (mem_err->validation_bits & CPER_MEM_VALID_MODULE)
  284. p += sprintf(p, "module:%d ", mem_err->module);
  285. if (mem_err->validation_bits & CPER_MEM_VALID_BANK)
  286. p += sprintf(p, "bank:%d ", mem_err->bank);
  287. if (mem_err->validation_bits & CPER_MEM_VALID_ROW)
  288. p += sprintf(p, "row:%d ", mem_err->row);
  289. if (mem_err->validation_bits & CPER_MEM_VALID_COLUMN)
  290. p += sprintf(p, "col:%d ", mem_err->column);
  291. if (mem_err->validation_bits & CPER_MEM_VALID_BIT_POSITION)
  292. p += sprintf(p, "bit_pos:%d ", mem_err->bit_pos);
  293. if (p > e->location)
  294. *(p - 1) = '\0';
  295. /* All other fields are mapped on e->other_detail */
  296. p = pvt->other_detail;
  297. if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_STATUS) {
  298. u64 status = mem_err->error_status;
  299. p += sprintf(p, "status(0x%016llx): ", (long long)status);
  300. switch ((status >> 8) & 0xff) {
  301. case 1:
  302. p += sprintf(p, "Error detected internal to the component ");
  303. break;
  304. case 16:
  305. p += sprintf(p, "Error detected in the bus ");
  306. break;
  307. case 4:
  308. p += sprintf(p, "Storage error in DRAM memory ");
  309. break;
  310. case 5:
  311. p += sprintf(p, "Storage error in TLB ");
  312. break;
  313. case 6:
  314. p += sprintf(p, "Storage error in cache ");
  315. break;
  316. case 7:
  317. p += sprintf(p, "Error in one or more functional units ");
  318. break;
  319. case 8:
  320. p += sprintf(p, "component failed self test ");
  321. break;
  322. case 9:
  323. p += sprintf(p, "Overflow or undervalue of internal queue ");
  324. break;
  325. case 17:
  326. p += sprintf(p, "Virtual address not found on IO-TLB or IO-PDIR ");
  327. break;
  328. case 18:
  329. p += sprintf(p, "Improper access error ");
  330. break;
  331. case 19:
  332. p += sprintf(p, "Access to a memory address which is not mapped to any component ");
  333. break;
  334. case 20:
  335. p += sprintf(p, "Loss of Lockstep ");
  336. break;
  337. case 21:
  338. p += sprintf(p, "Response not associated with a request ");
  339. break;
  340. case 22:
  341. p += sprintf(p, "Bus parity error - must also set the A, C, or D Bits ");
  342. break;
  343. case 23:
  344. p += sprintf(p, "Detection of a PATH_ERROR ");
  345. break;
  346. case 25:
  347. p += sprintf(p, "Bus operation timeout ");
  348. break;
  349. case 26:
  350. p += sprintf(p, "A read was issued to data that has been poisoned ");
  351. break;
  352. default:
  353. p += sprintf(p, "reserved ");
  354. break;
  355. }
  356. }
  357. if (mem_err->validation_bits & CPER_MEM_VALID_REQUESTOR_ID)
  358. p += sprintf(p, "requestorID: 0x%016llx ",
  359. (long long)mem_err->requestor_id);
  360. if (mem_err->validation_bits & CPER_MEM_VALID_RESPONDER_ID)
  361. p += sprintf(p, "responderID: 0x%016llx ",
  362. (long long)mem_err->responder_id);
  363. if (mem_err->validation_bits & CPER_MEM_VALID_TARGET_ID)
  364. p += sprintf(p, "targetID: 0x%016llx ",
  365. (long long)mem_err->responder_id);
  366. if (p > pvt->other_detail)
  367. *(p - 1) = '\0';
  368. edac_raw_mc_handle_error(type, mci, e);
  369. }
  370. EXPORT_SYMBOL_GPL(ghes_edac_report_mem_error);
  371. int ghes_edac_register(struct ghes *ghes, struct device *dev)
  372. {
  373. bool fake = false;
  374. int rc, num_dimm = 0;
  375. struct mem_ctl_info *mci;
  376. struct edac_mc_layer layers[1];
  377. struct ghes_edac_pvt *pvt;
  378. struct ghes_edac_dimm_fill dimm_fill;
  379. /* Get the number of DIMMs */
  380. dmi_walk(ghes_edac_count_dimms, &num_dimm);
  381. /* Check if we've got a bogus BIOS */
  382. if (num_dimm == 0) {
  383. fake = true;
  384. num_dimm = 1;
  385. }
  386. layers[0].type = EDAC_MC_LAYER_ALL_MEM;
  387. layers[0].size = num_dimm;
  388. layers[0].is_virt_csrow = true;
  389. /*
  390. * We need to serialize edac_mc_alloc() and edac_mc_add_mc(),
  391. * to avoid duplicated memory controller numbers
  392. */
  393. mutex_lock(&ghes_edac_lock);
  394. mci = edac_mc_alloc(ghes_edac_mc_num, ARRAY_SIZE(layers), layers,
  395. sizeof(*pvt));
  396. if (!mci) {
  397. pr_info("Can't allocate memory for EDAC data\n");
  398. mutex_unlock(&ghes_edac_lock);
  399. return -ENOMEM;
  400. }
  401. pvt = mci->pvt_info;
  402. memset(pvt, 0, sizeof(*pvt));
  403. list_add_tail(&pvt->list, &ghes_reglist);
  404. pvt->ghes = ghes;
  405. pvt->mci = mci;
  406. mci->pdev = dev;
  407. mci->mtype_cap = MEM_FLAG_EMPTY;
  408. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  409. mci->edac_cap = EDAC_FLAG_NONE;
  410. mci->mod_name = "ghes_edac.c";
  411. mci->mod_ver = GHES_EDAC_REVISION;
  412. mci->ctl_name = "ghes_edac";
  413. mci->dev_name = "ghes";
  414. if (!ghes_edac_mc_num) {
  415. if (!fake) {
  416. pr_info("This EDAC driver relies on BIOS to enumerate memory and get error reports.\n");
  417. pr_info("Unfortunately, not all BIOSes reflect the memory layout correctly.\n");
  418. pr_info("So, the end result of using this driver varies from vendor to vendor.\n");
  419. pr_info("If you find incorrect reports, please contact your hardware vendor\n");
  420. pr_info("to correct its BIOS.\n");
  421. pr_info("This system has %d DIMM sockets.\n",
  422. num_dimm);
  423. } else {
  424. pr_info("This system has a very crappy BIOS: It doesn't even list the DIMMS.\n");
  425. pr_info("Its SMBIOS info is wrong. It is doubtful that the error report would\n");
  426. pr_info("work on such system. Use this driver with caution\n");
  427. }
  428. }
  429. if (!fake) {
  430. /*
  431. * Fill DIMM info from DMI for the memory controller #0
  432. *
  433. * Keep it in blank for the other memory controllers, as
  434. * there's no reliable way to properly credit each DIMM to
  435. * the memory controller, as different BIOSes fill the
  436. * DMI bank location fields on different ways
  437. */
  438. if (!ghes_edac_mc_num) {
  439. dimm_fill.count = 0;
  440. dimm_fill.mci = mci;
  441. dmi_walk(ghes_edac_dmidecode, &dimm_fill);
  442. }
  443. } else {
  444. struct dimm_info *dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
  445. mci->n_layers, 0, 0, 0);
  446. dimm->nr_pages = 1;
  447. dimm->grain = 128;
  448. dimm->mtype = MEM_UNKNOWN;
  449. dimm->dtype = DEV_UNKNOWN;
  450. dimm->edac_mode = EDAC_SECDED;
  451. }
  452. rc = edac_mc_add_mc(mci);
  453. if (rc < 0) {
  454. pr_info("Can't register at EDAC core\n");
  455. edac_mc_free(mci);
  456. mutex_unlock(&ghes_edac_lock);
  457. return -ENODEV;
  458. }
  459. ghes_edac_mc_num++;
  460. mutex_unlock(&ghes_edac_lock);
  461. return 0;
  462. }
  463. EXPORT_SYMBOL_GPL(ghes_edac_register);
  464. void ghes_edac_unregister(struct ghes *ghes)
  465. {
  466. struct mem_ctl_info *mci;
  467. struct ghes_edac_pvt *pvt;
  468. list_for_each_entry(pvt, &ghes_reglist, list) {
  469. if (ghes == pvt->ghes) {
  470. mci = pvt->mci;
  471. edac_mc_del_mc(mci->pdev);
  472. edac_mc_free(mci);
  473. list_del(&pvt->list);
  474. }
  475. }
  476. }
  477. EXPORT_SYMBOL_GPL(ghes_edac_unregister);