ghes_edac.c 13 KB

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