ghes_edac.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. e->grain = 1;
  188. strcpy(e->label, "unknown label");
  189. e->msg = pvt->msg;
  190. e->other_detail = pvt->other_detail;
  191. e->top_layer = -1;
  192. e->mid_layer = -1;
  193. e->low_layer = -1;
  194. *pvt->other_detail = '\0';
  195. *pvt->msg = '\0';
  196. switch (sev) {
  197. case GHES_SEV_CORRECTED:
  198. type = HW_EVENT_ERR_CORRECTED;
  199. break;
  200. case GHES_SEV_RECOVERABLE:
  201. type = HW_EVENT_ERR_UNCORRECTED;
  202. break;
  203. case GHES_SEV_PANIC:
  204. type = HW_EVENT_ERR_FATAL;
  205. break;
  206. default:
  207. case GHES_SEV_NO:
  208. type = HW_EVENT_ERR_INFO;
  209. }
  210. edac_dbg(1, "error validation_bits: 0x%08llx\n",
  211. (long long)mem_err->validation_bits);
  212. /* Error type, mapped on e->msg */
  213. if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_TYPE) {
  214. p = pvt->msg;
  215. switch (mem_err->error_type) {
  216. case 0:
  217. p += sprintf(p, "Unknown");
  218. break;
  219. case 1:
  220. p += sprintf(p, "No error");
  221. break;
  222. case 2:
  223. p += sprintf(p, "Single-bit ECC");
  224. break;
  225. case 3:
  226. p += sprintf(p, "Multi-bit ECC");
  227. break;
  228. case 4:
  229. p += sprintf(p, "Single-symbol ChipKill ECC");
  230. break;
  231. case 5:
  232. p += sprintf(p, "Multi-symbol ChipKill ECC");
  233. break;
  234. case 6:
  235. p += sprintf(p, "Master abort");
  236. break;
  237. case 7:
  238. p += sprintf(p, "Target abort");
  239. break;
  240. case 8:
  241. p += sprintf(p, "Parity Error");
  242. break;
  243. case 9:
  244. p += sprintf(p, "Watchdog timeout");
  245. break;
  246. case 10:
  247. p += sprintf(p, "Invalid address");
  248. break;
  249. case 11:
  250. p += sprintf(p, "Mirror Broken");
  251. break;
  252. case 12:
  253. p += sprintf(p, "Memory Sparing");
  254. break;
  255. case 13:
  256. p += sprintf(p, "Scrub corrected error");
  257. break;
  258. case 14:
  259. p += sprintf(p, "Scrub uncorrected error");
  260. break;
  261. case 15:
  262. p += sprintf(p, "Physical Memory Map-out event");
  263. break;
  264. default:
  265. p += sprintf(p, "reserved error (%d)",
  266. mem_err->error_type);
  267. }
  268. } else {
  269. strcpy(pvt->msg, "unknown error");
  270. }
  271. /* Error address */
  272. if (mem_err->validation_bits & CPER_MEM_VALID_PA) {
  273. e->page_frame_number = mem_err->physical_addr >> PAGE_SHIFT;
  274. e->offset_in_page = mem_err->physical_addr & ~PAGE_MASK;
  275. }
  276. /* Error grain */
  277. if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK)
  278. e->grain = ~mem_err->physical_addr_mask + 1;
  279. /* Memory error location, mapped on e->location */
  280. p = e->location;
  281. if (mem_err->validation_bits & CPER_MEM_VALID_NODE)
  282. p += sprintf(p, "node:%d ", mem_err->node);
  283. if (mem_err->validation_bits & CPER_MEM_VALID_CARD)
  284. p += sprintf(p, "card:%d ", mem_err->card);
  285. if (mem_err->validation_bits & CPER_MEM_VALID_MODULE)
  286. p += sprintf(p, "module:%d ", mem_err->module);
  287. if (mem_err->validation_bits & CPER_MEM_VALID_RANK_NUMBER)
  288. p += sprintf(p, "rank:%d ", mem_err->rank);
  289. if (mem_err->validation_bits & CPER_MEM_VALID_BANK)
  290. p += sprintf(p, "bank:%d ", mem_err->bank);
  291. if (mem_err->validation_bits & CPER_MEM_VALID_ROW)
  292. p += sprintf(p, "row:%d ", mem_err->row);
  293. if (mem_err->validation_bits & CPER_MEM_VALID_COLUMN)
  294. p += sprintf(p, "col:%d ", mem_err->column);
  295. if (mem_err->validation_bits & CPER_MEM_VALID_BIT_POSITION)
  296. p += sprintf(p, "bit_pos:%d ", mem_err->bit_pos);
  297. if (mem_err->validation_bits & CPER_MEM_VALID_MODULE_HANDLE) {
  298. const char *bank = NULL, *device = NULL;
  299. dmi_memdev_name(mem_err->mem_dev_handle, &bank, &device);
  300. if (bank != NULL && device != NULL)
  301. p += sprintf(p, "DIMM location:%s %s ", bank, device);
  302. else
  303. p += sprintf(p, "DIMM DMI handle: 0x%.4x ",
  304. mem_err->mem_dev_handle);
  305. }
  306. if (p > e->location)
  307. *(p - 1) = '\0';
  308. /* All other fields are mapped on e->other_detail */
  309. p = pvt->other_detail;
  310. if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_STATUS) {
  311. u64 status = mem_err->error_status;
  312. p += sprintf(p, "status(0x%016llx): ", (long long)status);
  313. switch ((status >> 8) & 0xff) {
  314. case 1:
  315. p += sprintf(p, "Error detected internal to the component ");
  316. break;
  317. case 16:
  318. p += sprintf(p, "Error detected in the bus ");
  319. break;
  320. case 4:
  321. p += sprintf(p, "Storage error in DRAM memory ");
  322. break;
  323. case 5:
  324. p += sprintf(p, "Storage error in TLB ");
  325. break;
  326. case 6:
  327. p += sprintf(p, "Storage error in cache ");
  328. break;
  329. case 7:
  330. p += sprintf(p, "Error in one or more functional units ");
  331. break;
  332. case 8:
  333. p += sprintf(p, "component failed self test ");
  334. break;
  335. case 9:
  336. p += sprintf(p, "Overflow or undervalue of internal queue ");
  337. break;
  338. case 17:
  339. p += sprintf(p, "Virtual address not found on IO-TLB or IO-PDIR ");
  340. break;
  341. case 18:
  342. p += sprintf(p, "Improper access error ");
  343. break;
  344. case 19:
  345. p += sprintf(p, "Access to a memory address which is not mapped to any component ");
  346. break;
  347. case 20:
  348. p += sprintf(p, "Loss of Lockstep ");
  349. break;
  350. case 21:
  351. p += sprintf(p, "Response not associated with a request ");
  352. break;
  353. case 22:
  354. p += sprintf(p, "Bus parity error - must also set the A, C, or D Bits ");
  355. break;
  356. case 23:
  357. p += sprintf(p, "Detection of a PATH_ERROR ");
  358. break;
  359. case 25:
  360. p += sprintf(p, "Bus operation timeout ");
  361. break;
  362. case 26:
  363. p += sprintf(p, "A read was issued to data that has been poisoned ");
  364. break;
  365. default:
  366. p += sprintf(p, "reserved ");
  367. break;
  368. }
  369. }
  370. if (mem_err->validation_bits & CPER_MEM_VALID_REQUESTOR_ID)
  371. p += sprintf(p, "requestorID: 0x%016llx ",
  372. (long long)mem_err->requestor_id);
  373. if (mem_err->validation_bits & CPER_MEM_VALID_RESPONDER_ID)
  374. p += sprintf(p, "responderID: 0x%016llx ",
  375. (long long)mem_err->responder_id);
  376. if (mem_err->validation_bits & CPER_MEM_VALID_TARGET_ID)
  377. p += sprintf(p, "targetID: 0x%016llx ",
  378. (long long)mem_err->responder_id);
  379. if (p > pvt->other_detail)
  380. *(p - 1) = '\0';
  381. /* Sanity-check driver-supplied grain value. */
  382. if (WARN_ON_ONCE(!e->grain))
  383. e->grain = 1;
  384. grain_bits = fls_long(e->grain - 1);
  385. /* Generate the trace event */
  386. snprintf(pvt->detail_location, sizeof(pvt->detail_location),
  387. "APEI location: %s %s", e->location, e->other_detail);
  388. trace_mc_event(type, e->msg, e->label, e->error_count,
  389. mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer,
  390. (e->page_frame_number << PAGE_SHIFT) | e->offset_in_page,
  391. grain_bits, e->syndrome, pvt->detail_location);
  392. edac_raw_mc_handle_error(type, mci, e);
  393. spin_unlock_irqrestore(&ghes_lock, flags);
  394. }
  395. /*
  396. * Known systems that are safe to enable this module.
  397. */
  398. static struct acpi_platform_list plat_list[] = {
  399. {"HPE ", "Server ", 0, ACPI_SIG_FADT, all_versions},
  400. { } /* End */
  401. };
  402. int ghes_edac_register(struct ghes *ghes, struct device *dev)
  403. {
  404. bool fake = false;
  405. int rc, num_dimm = 0;
  406. struct mem_ctl_info *mci;
  407. struct edac_mc_layer layers[1];
  408. struct ghes_edac_dimm_fill dimm_fill;
  409. int idx = -1;
  410. if (IS_ENABLED(CONFIG_X86)) {
  411. /* Check if safe to enable on this system */
  412. idx = acpi_match_platform_list(plat_list);
  413. if (!force_load && idx < 0)
  414. return -ENODEV;
  415. } else {
  416. idx = 0;
  417. }
  418. /*
  419. * We have only one logical memory controller to which all DIMMs belong.
  420. */
  421. if (atomic_inc_return(&ghes_init) > 1)
  422. return 0;
  423. /* Get the number of DIMMs */
  424. dmi_walk(ghes_edac_count_dimms, &num_dimm);
  425. /* Check if we've got a bogus BIOS */
  426. if (num_dimm == 0) {
  427. fake = true;
  428. num_dimm = 1;
  429. }
  430. layers[0].type = EDAC_MC_LAYER_ALL_MEM;
  431. layers[0].size = num_dimm;
  432. layers[0].is_virt_csrow = true;
  433. mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(struct ghes_edac_pvt));
  434. if (!mci) {
  435. pr_info("Can't allocate memory for EDAC data\n");
  436. return -ENOMEM;
  437. }
  438. ghes_pvt = mci->pvt_info;
  439. ghes_pvt->ghes = ghes;
  440. ghes_pvt->mci = mci;
  441. mci->pdev = dev;
  442. mci->mtype_cap = MEM_FLAG_EMPTY;
  443. mci->edac_ctl_cap = EDAC_FLAG_NONE;
  444. mci->edac_cap = EDAC_FLAG_NONE;
  445. mci->mod_name = "ghes_edac.c";
  446. mci->ctl_name = "ghes_edac";
  447. mci->dev_name = "ghes";
  448. if (fake) {
  449. pr_info("This system has a very crappy BIOS: It doesn't even list the DIMMS.\n");
  450. pr_info("Its SMBIOS info is wrong. It is doubtful that the error report would\n");
  451. pr_info("work on such system. Use this driver with caution\n");
  452. } else if (idx < 0) {
  453. pr_info("This EDAC driver relies on BIOS to enumerate memory and get error reports.\n");
  454. pr_info("Unfortunately, not all BIOSes reflect the memory layout correctly.\n");
  455. pr_info("So, the end result of using this driver varies from vendor to vendor.\n");
  456. pr_info("If you find incorrect reports, please contact your hardware vendor\n");
  457. pr_info("to correct its BIOS.\n");
  458. pr_info("This system has %d DIMM sockets.\n", num_dimm);
  459. }
  460. if (!fake) {
  461. dimm_fill.count = 0;
  462. dimm_fill.mci = mci;
  463. dmi_walk(ghes_edac_dmidecode, &dimm_fill);
  464. } else {
  465. struct dimm_info *dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms,
  466. mci->n_layers, 0, 0, 0);
  467. dimm->nr_pages = 1;
  468. dimm->grain = 128;
  469. dimm->mtype = MEM_UNKNOWN;
  470. dimm->dtype = DEV_UNKNOWN;
  471. dimm->edac_mode = EDAC_SECDED;
  472. }
  473. rc = edac_mc_add_mc(mci);
  474. if (rc < 0) {
  475. pr_info("Can't register at EDAC core\n");
  476. edac_mc_free(mci);
  477. return -ENODEV;
  478. }
  479. return 0;
  480. }
  481. void ghes_edac_unregister(struct ghes *ghes)
  482. {
  483. struct mem_ctl_info *mci;
  484. if (!ghes_pvt)
  485. return;
  486. if (atomic_dec_return(&ghes_init))
  487. return;
  488. mci = ghes_pvt->mci;
  489. ghes_pvt = NULL;
  490. edac_mc_del_mc(mci->pdev);
  491. edac_mc_free(mci);
  492. }