cper.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /*
  2. * UEFI Common Platform Error Record (CPER) support
  3. *
  4. * Copyright (C) 2010, Intel Corp.
  5. * Author: Huang Ying <ying.huang@intel.com>
  6. *
  7. * CPER is the format used to describe platform hardware error by
  8. * various APEI tables, such as ERST, BERT and HEST etc.
  9. *
  10. * For more information about CPER, please refer to Appendix N of UEFI
  11. * Specification version 2.3.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License version
  15. * 2 as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/time.h>
  29. #include <linux/cper.h>
  30. #include <linux/acpi.h>
  31. #include <linux/aer.h>
  32. /*
  33. * CPER record ID need to be unique even after reboot, because record
  34. * ID is used as index for ERST storage, while CPER records from
  35. * multiple boot may co-exist in ERST.
  36. */
  37. u64 cper_next_record_id(void)
  38. {
  39. static atomic64_t seq;
  40. if (!atomic64_read(&seq))
  41. atomic64_set(&seq, ((u64)get_seconds()) << 32);
  42. return atomic64_inc_return(&seq);
  43. }
  44. EXPORT_SYMBOL_GPL(cper_next_record_id);
  45. static const char *cper_severity_strs[] = {
  46. "recoverable",
  47. "fatal",
  48. "corrected",
  49. "info",
  50. };
  51. static const char *cper_severity_str(unsigned int severity)
  52. {
  53. return severity < ARRAY_SIZE(cper_severity_strs) ?
  54. cper_severity_strs[severity] : "unknown";
  55. }
  56. /*
  57. * cper_print_bits - print strings for set bits
  58. * @pfx: prefix for each line, including log level and prefix string
  59. * @bits: bit mask
  60. * @strs: string array, indexed by bit position
  61. * @strs_size: size of the string array: @strs
  62. *
  63. * For each set bit in @bits, print the corresponding string in @strs.
  64. * If the output length is longer than 80, multiple line will be
  65. * printed, with @pfx is printed at the beginning of each line.
  66. */
  67. void cper_print_bits(const char *pfx, unsigned int bits,
  68. const char *strs[], unsigned int strs_size)
  69. {
  70. int i, len = 0;
  71. const char *str;
  72. char buf[84];
  73. for (i = 0; i < strs_size; i++) {
  74. if (!(bits & (1U << i)))
  75. continue;
  76. str = strs[i];
  77. if (!str)
  78. continue;
  79. if (len && len + strlen(str) + 2 > 80) {
  80. printk("%s\n", buf);
  81. len = 0;
  82. }
  83. if (!len)
  84. len = snprintf(buf, sizeof(buf), "%s%s", pfx, str);
  85. else
  86. len += snprintf(buf+len, sizeof(buf)-len, ", %s", str);
  87. }
  88. if (len)
  89. printk("%s\n", buf);
  90. }
  91. static const char *cper_proc_type_strs[] = {
  92. "IA32/X64",
  93. "IA64",
  94. };
  95. static const char *cper_proc_isa_strs[] = {
  96. "IA32",
  97. "IA64",
  98. "X64",
  99. };
  100. static const char *cper_proc_error_type_strs[] = {
  101. "cache error",
  102. "TLB error",
  103. "bus error",
  104. "micro-architectural error",
  105. };
  106. static const char *cper_proc_op_strs[] = {
  107. "unknown or generic",
  108. "data read",
  109. "data write",
  110. "instruction execution",
  111. };
  112. static const char *cper_proc_flag_strs[] = {
  113. "restartable",
  114. "precise IP",
  115. "overflow",
  116. "corrected",
  117. };
  118. static void cper_print_proc_generic(const char *pfx,
  119. const struct cper_sec_proc_generic *proc)
  120. {
  121. if (proc->validation_bits & CPER_PROC_VALID_TYPE)
  122. printk("%s""processor_type: %d, %s\n", pfx, proc->proc_type,
  123. proc->proc_type < ARRAY_SIZE(cper_proc_type_strs) ?
  124. cper_proc_type_strs[proc->proc_type] : "unknown");
  125. if (proc->validation_bits & CPER_PROC_VALID_ISA)
  126. printk("%s""processor_isa: %d, %s\n", pfx, proc->proc_isa,
  127. proc->proc_isa < ARRAY_SIZE(cper_proc_isa_strs) ?
  128. cper_proc_isa_strs[proc->proc_isa] : "unknown");
  129. if (proc->validation_bits & CPER_PROC_VALID_ERROR_TYPE) {
  130. printk("%s""error_type: 0x%02x\n", pfx, proc->proc_error_type);
  131. cper_print_bits(pfx, proc->proc_error_type,
  132. cper_proc_error_type_strs,
  133. ARRAY_SIZE(cper_proc_error_type_strs));
  134. }
  135. if (proc->validation_bits & CPER_PROC_VALID_OPERATION)
  136. printk("%s""operation: %d, %s\n", pfx, proc->operation,
  137. proc->operation < ARRAY_SIZE(cper_proc_op_strs) ?
  138. cper_proc_op_strs[proc->operation] : "unknown");
  139. if (proc->validation_bits & CPER_PROC_VALID_FLAGS) {
  140. printk("%s""flags: 0x%02x\n", pfx, proc->flags);
  141. cper_print_bits(pfx, proc->flags, cper_proc_flag_strs,
  142. ARRAY_SIZE(cper_proc_flag_strs));
  143. }
  144. if (proc->validation_bits & CPER_PROC_VALID_LEVEL)
  145. printk("%s""level: %d\n", pfx, proc->level);
  146. if (proc->validation_bits & CPER_PROC_VALID_VERSION)
  147. printk("%s""version_info: 0x%016llx\n", pfx, proc->cpu_version);
  148. if (proc->validation_bits & CPER_PROC_VALID_ID)
  149. printk("%s""processor_id: 0x%016llx\n", pfx, proc->proc_id);
  150. if (proc->validation_bits & CPER_PROC_VALID_TARGET_ADDRESS)
  151. printk("%s""target_address: 0x%016llx\n",
  152. pfx, proc->target_addr);
  153. if (proc->validation_bits & CPER_PROC_VALID_REQUESTOR_ID)
  154. printk("%s""requestor_id: 0x%016llx\n",
  155. pfx, proc->requestor_id);
  156. if (proc->validation_bits & CPER_PROC_VALID_RESPONDER_ID)
  157. printk("%s""responder_id: 0x%016llx\n",
  158. pfx, proc->responder_id);
  159. if (proc->validation_bits & CPER_PROC_VALID_IP)
  160. printk("%s""IP: 0x%016llx\n", pfx, proc->ip);
  161. }
  162. static const char *cper_mem_err_type_strs[] = {
  163. "unknown",
  164. "no error",
  165. "single-bit ECC",
  166. "multi-bit ECC",
  167. "single-symbol chipkill ECC",
  168. "multi-symbol chipkill ECC",
  169. "master abort",
  170. "target abort",
  171. "parity error",
  172. "watchdog timeout",
  173. "invalid address",
  174. "mirror Broken",
  175. "memory sparing",
  176. "scrub corrected error",
  177. "scrub uncorrected error",
  178. };
  179. static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem)
  180. {
  181. if (mem->validation_bits & CPER_MEM_VALID_ERROR_STATUS)
  182. printk("%s""error_status: 0x%016llx\n", pfx, mem->error_status);
  183. if (mem->validation_bits & CPER_MEM_VALID_PHYSICAL_ADDRESS)
  184. printk("%s""physical_address: 0x%016llx\n",
  185. pfx, mem->physical_addr);
  186. if (mem->validation_bits & CPER_MEM_VALID_PHYSICAL_ADDRESS_MASK)
  187. printk("%s""physical_address_mask: 0x%016llx\n",
  188. pfx, mem->physical_addr_mask);
  189. if (mem->validation_bits & CPER_MEM_VALID_NODE)
  190. printk("%s""node: %d\n", pfx, mem->node);
  191. if (mem->validation_bits & CPER_MEM_VALID_CARD)
  192. printk("%s""card: %d\n", pfx, mem->card);
  193. if (mem->validation_bits & CPER_MEM_VALID_MODULE)
  194. printk("%s""module: %d\n", pfx, mem->module);
  195. if (mem->validation_bits & CPER_MEM_VALID_BANK)
  196. printk("%s""bank: %d\n", pfx, mem->bank);
  197. if (mem->validation_bits & CPER_MEM_VALID_DEVICE)
  198. printk("%s""device: %d\n", pfx, mem->device);
  199. if (mem->validation_bits & CPER_MEM_VALID_ROW)
  200. printk("%s""row: %d\n", pfx, mem->row);
  201. if (mem->validation_bits & CPER_MEM_VALID_COLUMN)
  202. printk("%s""column: %d\n", pfx, mem->column);
  203. if (mem->validation_bits & CPER_MEM_VALID_BIT_POSITION)
  204. printk("%s""bit_position: %d\n", pfx, mem->bit_pos);
  205. if (mem->validation_bits & CPER_MEM_VALID_REQUESTOR_ID)
  206. printk("%s""requestor_id: 0x%016llx\n", pfx, mem->requestor_id);
  207. if (mem->validation_bits & CPER_MEM_VALID_RESPONDER_ID)
  208. printk("%s""responder_id: 0x%016llx\n", pfx, mem->responder_id);
  209. if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID)
  210. printk("%s""target_id: 0x%016llx\n", pfx, mem->target_id);
  211. if (mem->validation_bits & CPER_MEM_VALID_ERROR_TYPE) {
  212. u8 etype = mem->error_type;
  213. printk("%s""error_type: %d, %s\n", pfx, etype,
  214. etype < ARRAY_SIZE(cper_mem_err_type_strs) ?
  215. cper_mem_err_type_strs[etype] : "unknown");
  216. }
  217. }
  218. static const char *cper_pcie_port_type_strs[] = {
  219. "PCIe end point",
  220. "legacy PCI end point",
  221. "unknown",
  222. "unknown",
  223. "root port",
  224. "upstream switch port",
  225. "downstream switch port",
  226. "PCIe to PCI/PCI-X bridge",
  227. "PCI/PCI-X to PCIe bridge",
  228. "root complex integrated endpoint device",
  229. "root complex event collector",
  230. };
  231. static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
  232. const struct acpi_hest_generic_data *gdata)
  233. {
  234. if (pcie->validation_bits & CPER_PCIE_VALID_PORT_TYPE)
  235. printk("%s""port_type: %d, %s\n", pfx, pcie->port_type,
  236. pcie->port_type < ARRAY_SIZE(cper_pcie_port_type_strs) ?
  237. cper_pcie_port_type_strs[pcie->port_type] : "unknown");
  238. if (pcie->validation_bits & CPER_PCIE_VALID_VERSION)
  239. printk("%s""version: %d.%d\n", pfx,
  240. pcie->version.major, pcie->version.minor);
  241. if (pcie->validation_bits & CPER_PCIE_VALID_COMMAND_STATUS)
  242. printk("%s""command: 0x%04x, status: 0x%04x\n", pfx,
  243. pcie->command, pcie->status);
  244. if (pcie->validation_bits & CPER_PCIE_VALID_DEVICE_ID) {
  245. const __u8 *p;
  246. printk("%s""device_id: %04x:%02x:%02x.%x\n", pfx,
  247. pcie->device_id.segment, pcie->device_id.bus,
  248. pcie->device_id.device, pcie->device_id.function);
  249. printk("%s""slot: %d\n", pfx,
  250. pcie->device_id.slot >> CPER_PCIE_SLOT_SHIFT);
  251. printk("%s""secondary_bus: 0x%02x\n", pfx,
  252. pcie->device_id.secondary_bus);
  253. printk("%s""vendor_id: 0x%04x, device_id: 0x%04x\n", pfx,
  254. pcie->device_id.vendor_id, pcie->device_id.device_id);
  255. p = pcie->device_id.class_code;
  256. printk("%s""class_code: %02x%02x%02x\n", pfx, p[0], p[1], p[2]);
  257. }
  258. if (pcie->validation_bits & CPER_PCIE_VALID_SERIAL_NUMBER)
  259. printk("%s""serial number: 0x%04x, 0x%04x\n", pfx,
  260. pcie->serial_number.lower, pcie->serial_number.upper);
  261. if (pcie->validation_bits & CPER_PCIE_VALID_BRIDGE_CONTROL_STATUS)
  262. printk(
  263. "%s""bridge: secondary_status: 0x%04x, control: 0x%04x\n",
  264. pfx, pcie->bridge.secondary_status, pcie->bridge.control);
  265. #ifdef CONFIG_ACPI_APEI_PCIEAER
  266. if (pcie->validation_bits & CPER_PCIE_VALID_AER_INFO) {
  267. struct aer_capability_regs *aer_regs = (void *)pcie->aer_info;
  268. cper_print_aer(pfx, gdata->error_severity, aer_regs);
  269. }
  270. #endif
  271. }
  272. static const char *apei_estatus_section_flag_strs[] = {
  273. "primary",
  274. "containment warning",
  275. "reset",
  276. "threshold exceeded",
  277. "resource not accessible",
  278. "latent error",
  279. };
  280. static void apei_estatus_print_section(
  281. const char *pfx, const struct acpi_hest_generic_data *gdata, int sec_no)
  282. {
  283. uuid_le *sec_type = (uuid_le *)gdata->section_type;
  284. __u16 severity;
  285. severity = gdata->error_severity;
  286. printk("%s""section: %d, severity: %d, %s\n", pfx, sec_no, severity,
  287. cper_severity_str(severity));
  288. printk("%s""flags: 0x%02x\n", pfx, gdata->flags);
  289. cper_print_bits(pfx, gdata->flags, apei_estatus_section_flag_strs,
  290. ARRAY_SIZE(apei_estatus_section_flag_strs));
  291. if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID)
  292. printk("%s""fru_id: %pUl\n", pfx, (uuid_le *)gdata->fru_id);
  293. if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT)
  294. printk("%s""fru_text: %.20s\n", pfx, gdata->fru_text);
  295. if (!uuid_le_cmp(*sec_type, CPER_SEC_PROC_GENERIC)) {
  296. struct cper_sec_proc_generic *proc_err = (void *)(gdata + 1);
  297. printk("%s""section_type: general processor error\n", pfx);
  298. if (gdata->error_data_length >= sizeof(*proc_err))
  299. cper_print_proc_generic(pfx, proc_err);
  300. else
  301. goto err_section_too_small;
  302. } else if (!uuid_le_cmp(*sec_type, CPER_SEC_PLATFORM_MEM)) {
  303. struct cper_sec_mem_err *mem_err = (void *)(gdata + 1);
  304. printk("%s""section_type: memory error\n", pfx);
  305. if (gdata->error_data_length >= sizeof(*mem_err))
  306. cper_print_mem(pfx, mem_err);
  307. else
  308. goto err_section_too_small;
  309. } else if (!uuid_le_cmp(*sec_type, CPER_SEC_PCIE)) {
  310. struct cper_sec_pcie *pcie = (void *)(gdata + 1);
  311. printk("%s""section_type: PCIe error\n", pfx);
  312. if (gdata->error_data_length >= sizeof(*pcie))
  313. cper_print_pcie(pfx, pcie, gdata);
  314. else
  315. goto err_section_too_small;
  316. } else
  317. printk("%s""section type: unknown, %pUl\n", pfx, sec_type);
  318. return;
  319. err_section_too_small:
  320. pr_err(FW_WARN "error section length is too small\n");
  321. }
  322. void apei_estatus_print(const char *pfx,
  323. const struct acpi_hest_generic_status *estatus)
  324. {
  325. struct acpi_hest_generic_data *gdata;
  326. unsigned int data_len, gedata_len;
  327. int sec_no = 0;
  328. __u16 severity;
  329. printk("%s""APEI generic hardware error status\n", pfx);
  330. severity = estatus->error_severity;
  331. printk("%s""severity: %d, %s\n", pfx, severity,
  332. cper_severity_str(severity));
  333. data_len = estatus->data_length;
  334. gdata = (struct acpi_hest_generic_data *)(estatus + 1);
  335. while (data_len > sizeof(*gdata)) {
  336. gedata_len = gdata->error_data_length;
  337. apei_estatus_print_section(pfx, gdata, sec_no);
  338. data_len -= gedata_len + sizeof(*gdata);
  339. sec_no++;
  340. }
  341. }
  342. EXPORT_SYMBOL_GPL(apei_estatus_print);
  343. int apei_estatus_check_header(const struct acpi_hest_generic_status *estatus)
  344. {
  345. if (estatus->data_length &&
  346. estatus->data_length < sizeof(struct acpi_hest_generic_data))
  347. return -EINVAL;
  348. if (estatus->raw_data_length &&
  349. estatus->raw_data_offset < sizeof(*estatus) + estatus->data_length)
  350. return -EINVAL;
  351. return 0;
  352. }
  353. EXPORT_SYMBOL_GPL(apei_estatus_check_header);
  354. int apei_estatus_check(const struct acpi_hest_generic_status *estatus)
  355. {
  356. struct acpi_hest_generic_data *gdata;
  357. unsigned int data_len, gedata_len;
  358. int rc;
  359. rc = apei_estatus_check_header(estatus);
  360. if (rc)
  361. return rc;
  362. data_len = estatus->data_length;
  363. gdata = (struct acpi_hest_generic_data *)(estatus + 1);
  364. while (data_len > sizeof(*gdata)) {
  365. gedata_len = gdata->error_data_length;
  366. if (gedata_len > data_len - sizeof(*gdata))
  367. return -EINVAL;
  368. data_len -= gedata_len + sizeof(*gdata);
  369. }
  370. if (data_len)
  371. return -EINVAL;
  372. return 0;
  373. }
  374. EXPORT_SYMBOL_GPL(apei_estatus_check);