ghes_edac.c 14 KB

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