]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/firmware/efi/cper.c
cper: add timestamp print to CPER status printing
[mirror_ubuntu-zesty-kernel.git] / drivers / firmware / efi / cper.c
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 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.4.
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
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/time.h>
30 #include <linux/cper.h>
31 #include <linux/dmi.h>
32 #include <linux/acpi.h>
33 #include <linux/pci.h>
34 #include <linux/aer.h>
35 #include <linux/printk.h>
36 #include <linux/bcd.h>
37 #include <acpi/ghes.h>
38
39 #define INDENT_SP " "
40
41 static char rcd_decode_str[CPER_REC_LEN];
42
43 /*
44 * CPER record ID need to be unique even after reboot, because record
45 * ID is used as index for ERST storage, while CPER records from
46 * multiple boot may co-exist in ERST.
47 */
48 u64 cper_next_record_id(void)
49 {
50 static atomic64_t seq;
51
52 if (!atomic64_read(&seq))
53 atomic64_set(&seq, ((u64)get_seconds()) << 32);
54
55 return atomic64_inc_return(&seq);
56 }
57 EXPORT_SYMBOL_GPL(cper_next_record_id);
58
59 static const char * const severity_strs[] = {
60 "recoverable",
61 "fatal",
62 "corrected",
63 "info",
64 };
65
66 const char *cper_severity_str(unsigned int severity)
67 {
68 return severity < ARRAY_SIZE(severity_strs) ?
69 severity_strs[severity] : "unknown";
70 }
71 EXPORT_SYMBOL_GPL(cper_severity_str);
72
73 /*
74 * cper_print_bits - print strings for set bits
75 * @pfx: prefix for each line, including log level and prefix string
76 * @bits: bit mask
77 * @strs: string array, indexed by bit position
78 * @strs_size: size of the string array: @strs
79 *
80 * For each set bit in @bits, print the corresponding string in @strs.
81 * If the output length is longer than 80, multiple line will be
82 * printed, with @pfx is printed at the beginning of each line.
83 */
84 void cper_print_bits(const char *pfx, unsigned int bits,
85 const char * const strs[], unsigned int strs_size)
86 {
87 int i, len = 0;
88 const char *str;
89 char buf[84];
90
91 for (i = 0; i < strs_size; i++) {
92 if (!(bits & (1U << i)))
93 continue;
94 str = strs[i];
95 if (!str)
96 continue;
97 if (len && len + strlen(str) + 2 > 80) {
98 printk("%s\n", buf);
99 len = 0;
100 }
101 if (!len)
102 len = snprintf(buf, sizeof(buf), "%s%s", pfx, str);
103 else
104 len += snprintf(buf+len, sizeof(buf)-len, ", %s", str);
105 }
106 if (len)
107 printk("%s\n", buf);
108 }
109
110 static const char * const proc_type_strs[] = {
111 "IA32/X64",
112 "IA64",
113 };
114
115 static const char * const proc_isa_strs[] = {
116 "IA32",
117 "IA64",
118 "X64",
119 };
120
121 static const char * const proc_error_type_strs[] = {
122 "cache error",
123 "TLB error",
124 "bus error",
125 "micro-architectural error",
126 };
127
128 static const char * const proc_op_strs[] = {
129 "unknown or generic",
130 "data read",
131 "data write",
132 "instruction execution",
133 };
134
135 static const char * const proc_flag_strs[] = {
136 "restartable",
137 "precise IP",
138 "overflow",
139 "corrected",
140 };
141
142 static void cper_print_proc_generic(const char *pfx,
143 const struct cper_sec_proc_generic *proc)
144 {
145 if (proc->validation_bits & CPER_PROC_VALID_TYPE)
146 printk("%s""processor_type: %d, %s\n", pfx, proc->proc_type,
147 proc->proc_type < ARRAY_SIZE(proc_type_strs) ?
148 proc_type_strs[proc->proc_type] : "unknown");
149 if (proc->validation_bits & CPER_PROC_VALID_ISA)
150 printk("%s""processor_isa: %d, %s\n", pfx, proc->proc_isa,
151 proc->proc_isa < ARRAY_SIZE(proc_isa_strs) ?
152 proc_isa_strs[proc->proc_isa] : "unknown");
153 if (proc->validation_bits & CPER_PROC_VALID_ERROR_TYPE) {
154 printk("%s""error_type: 0x%02x\n", pfx, proc->proc_error_type);
155 cper_print_bits(pfx, proc->proc_error_type,
156 proc_error_type_strs,
157 ARRAY_SIZE(proc_error_type_strs));
158 }
159 if (proc->validation_bits & CPER_PROC_VALID_OPERATION)
160 printk("%s""operation: %d, %s\n", pfx, proc->operation,
161 proc->operation < ARRAY_SIZE(proc_op_strs) ?
162 proc_op_strs[proc->operation] : "unknown");
163 if (proc->validation_bits & CPER_PROC_VALID_FLAGS) {
164 printk("%s""flags: 0x%02x\n", pfx, proc->flags);
165 cper_print_bits(pfx, proc->flags, proc_flag_strs,
166 ARRAY_SIZE(proc_flag_strs));
167 }
168 if (proc->validation_bits & CPER_PROC_VALID_LEVEL)
169 printk("%s""level: %d\n", pfx, proc->level);
170 if (proc->validation_bits & CPER_PROC_VALID_VERSION)
171 printk("%s""version_info: 0x%016llx\n", pfx, proc->cpu_version);
172 if (proc->validation_bits & CPER_PROC_VALID_ID)
173 printk("%s""processor_id: 0x%016llx\n", pfx, proc->proc_id);
174 if (proc->validation_bits & CPER_PROC_VALID_TARGET_ADDRESS)
175 printk("%s""target_address: 0x%016llx\n",
176 pfx, proc->target_addr);
177 if (proc->validation_bits & CPER_PROC_VALID_REQUESTOR_ID)
178 printk("%s""requestor_id: 0x%016llx\n",
179 pfx, proc->requestor_id);
180 if (proc->validation_bits & CPER_PROC_VALID_RESPONDER_ID)
181 printk("%s""responder_id: 0x%016llx\n",
182 pfx, proc->responder_id);
183 if (proc->validation_bits & CPER_PROC_VALID_IP)
184 printk("%s""IP: 0x%016llx\n", pfx, proc->ip);
185 }
186
187 static const char * const mem_err_type_strs[] = {
188 "unknown",
189 "no error",
190 "single-bit ECC",
191 "multi-bit ECC",
192 "single-symbol chipkill ECC",
193 "multi-symbol chipkill ECC",
194 "master abort",
195 "target abort",
196 "parity error",
197 "watchdog timeout",
198 "invalid address",
199 "mirror Broken",
200 "memory sparing",
201 "scrub corrected error",
202 "scrub uncorrected error",
203 "physical memory map-out event",
204 };
205
206 const char *cper_mem_err_type_str(unsigned int etype)
207 {
208 return etype < ARRAY_SIZE(mem_err_type_strs) ?
209 mem_err_type_strs[etype] : "unknown";
210 }
211 EXPORT_SYMBOL_GPL(cper_mem_err_type_str);
212
213 static int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg)
214 {
215 u32 len, n;
216
217 if (!msg)
218 return 0;
219
220 n = 0;
221 len = CPER_REC_LEN - 1;
222 if (mem->validation_bits & CPER_MEM_VALID_NODE)
223 n += scnprintf(msg + n, len - n, "node: %d ", mem->node);
224 if (mem->validation_bits & CPER_MEM_VALID_CARD)
225 n += scnprintf(msg + n, len - n, "card: %d ", mem->card);
226 if (mem->validation_bits & CPER_MEM_VALID_MODULE)
227 n += scnprintf(msg + n, len - n, "module: %d ", mem->module);
228 if (mem->validation_bits & CPER_MEM_VALID_RANK_NUMBER)
229 n += scnprintf(msg + n, len - n, "rank: %d ", mem->rank);
230 if (mem->validation_bits & CPER_MEM_VALID_BANK)
231 n += scnprintf(msg + n, len - n, "bank: %d ", mem->bank);
232 if (mem->validation_bits & CPER_MEM_VALID_DEVICE)
233 n += scnprintf(msg + n, len - n, "device: %d ", mem->device);
234 if (mem->validation_bits & CPER_MEM_VALID_ROW)
235 n += scnprintf(msg + n, len - n, "row: %d ", mem->row);
236 if (mem->validation_bits & CPER_MEM_VALID_COLUMN)
237 n += scnprintf(msg + n, len - n, "column: %d ", mem->column);
238 if (mem->validation_bits & CPER_MEM_VALID_BIT_POSITION)
239 n += scnprintf(msg + n, len - n, "bit_position: %d ",
240 mem->bit_pos);
241 if (mem->validation_bits & CPER_MEM_VALID_REQUESTOR_ID)
242 n += scnprintf(msg + n, len - n, "requestor_id: 0x%016llx ",
243 mem->requestor_id);
244 if (mem->validation_bits & CPER_MEM_VALID_RESPONDER_ID)
245 n += scnprintf(msg + n, len - n, "responder_id: 0x%016llx ",
246 mem->responder_id);
247 if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID)
248 scnprintf(msg + n, len - n, "target_id: 0x%016llx ",
249 mem->target_id);
250
251 msg[n] = '\0';
252 return n;
253 }
254
255 static int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg)
256 {
257 u32 len, n;
258 const char *bank = NULL, *device = NULL;
259
260 if (!msg || !(mem->validation_bits & CPER_MEM_VALID_MODULE_HANDLE))
261 return 0;
262
263 n = 0;
264 len = CPER_REC_LEN - 1;
265 dmi_memdev_name(mem->mem_dev_handle, &bank, &device);
266 if (bank && device)
267 n = snprintf(msg, len, "DIMM location: %s %s ", bank, device);
268 else
269 n = snprintf(msg, len,
270 "DIMM location: not present. DMI handle: 0x%.4x ",
271 mem->mem_dev_handle);
272
273 msg[n] = '\0';
274 return n;
275 }
276
277 void cper_mem_err_pack(const struct cper_sec_mem_err *mem,
278 struct cper_mem_err_compact *cmem)
279 {
280 cmem->validation_bits = mem->validation_bits;
281 cmem->node = mem->node;
282 cmem->card = mem->card;
283 cmem->module = mem->module;
284 cmem->bank = mem->bank;
285 cmem->device = mem->device;
286 cmem->row = mem->row;
287 cmem->column = mem->column;
288 cmem->bit_pos = mem->bit_pos;
289 cmem->requestor_id = mem->requestor_id;
290 cmem->responder_id = mem->responder_id;
291 cmem->target_id = mem->target_id;
292 cmem->rank = mem->rank;
293 cmem->mem_array_handle = mem->mem_array_handle;
294 cmem->mem_dev_handle = mem->mem_dev_handle;
295 }
296
297 const char *cper_mem_err_unpack(struct trace_seq *p,
298 struct cper_mem_err_compact *cmem)
299 {
300 const char *ret = trace_seq_buffer_ptr(p);
301
302 if (cper_mem_err_location(cmem, rcd_decode_str))
303 trace_seq_printf(p, "%s", rcd_decode_str);
304 if (cper_dimm_err_location(cmem, rcd_decode_str))
305 trace_seq_printf(p, "%s", rcd_decode_str);
306 trace_seq_putc(p, '\0');
307
308 return ret;
309 }
310
311 static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem,
312 int len)
313 {
314 struct cper_mem_err_compact cmem;
315
316 /* Don't trust UEFI 2.1/2.2 structure with bad validation bits */
317 if (len == sizeof(struct cper_sec_mem_err_old) &&
318 (mem->validation_bits & ~(CPER_MEM_VALID_RANK_NUMBER - 1))) {
319 pr_err(FW_WARN "valid bits set for fields beyond structure\n");
320 return;
321 }
322 if (mem->validation_bits & CPER_MEM_VALID_ERROR_STATUS)
323 printk("%s""error_status: 0x%016llx\n", pfx, mem->error_status);
324 if (mem->validation_bits & CPER_MEM_VALID_PA)
325 printk("%s""physical_address: 0x%016llx\n",
326 pfx, mem->physical_addr);
327 if (mem->validation_bits & CPER_MEM_VALID_PA_MASK)
328 printk("%s""physical_address_mask: 0x%016llx\n",
329 pfx, mem->physical_addr_mask);
330 cper_mem_err_pack(mem, &cmem);
331 if (cper_mem_err_location(&cmem, rcd_decode_str))
332 printk("%s%s\n", pfx, rcd_decode_str);
333 if (mem->validation_bits & CPER_MEM_VALID_ERROR_TYPE) {
334 u8 etype = mem->error_type;
335 printk("%s""error_type: %d, %s\n", pfx, etype,
336 cper_mem_err_type_str(etype));
337 }
338 if (cper_dimm_err_location(&cmem, rcd_decode_str))
339 printk("%s%s\n", pfx, rcd_decode_str);
340 }
341
342 static const char * const pcie_port_type_strs[] = {
343 "PCIe end point",
344 "legacy PCI end point",
345 "unknown",
346 "unknown",
347 "root port",
348 "upstream switch port",
349 "downstream switch port",
350 "PCIe to PCI/PCI-X bridge",
351 "PCI/PCI-X to PCIe bridge",
352 "root complex integrated endpoint device",
353 "root complex event collector",
354 };
355
356 static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
357 const struct acpi_hest_generic_data *gdata)
358 {
359 if (pcie->validation_bits & CPER_PCIE_VALID_PORT_TYPE)
360 printk("%s""port_type: %d, %s\n", pfx, pcie->port_type,
361 pcie->port_type < ARRAY_SIZE(pcie_port_type_strs) ?
362 pcie_port_type_strs[pcie->port_type] : "unknown");
363 if (pcie->validation_bits & CPER_PCIE_VALID_VERSION)
364 printk("%s""version: %d.%d\n", pfx,
365 pcie->version.major, pcie->version.minor);
366 if (pcie->validation_bits & CPER_PCIE_VALID_COMMAND_STATUS)
367 printk("%s""command: 0x%04x, status: 0x%04x\n", pfx,
368 pcie->command, pcie->status);
369 if (pcie->validation_bits & CPER_PCIE_VALID_DEVICE_ID) {
370 const __u8 *p;
371 printk("%s""device_id: %04x:%02x:%02x.%x\n", pfx,
372 pcie->device_id.segment, pcie->device_id.bus,
373 pcie->device_id.device, pcie->device_id.function);
374 printk("%s""slot: %d\n", pfx,
375 pcie->device_id.slot >> CPER_PCIE_SLOT_SHIFT);
376 printk("%s""secondary_bus: 0x%02x\n", pfx,
377 pcie->device_id.secondary_bus);
378 printk("%s""vendor_id: 0x%04x, device_id: 0x%04x\n", pfx,
379 pcie->device_id.vendor_id, pcie->device_id.device_id);
380 p = pcie->device_id.class_code;
381 printk("%s""class_code: %02x%02x%02x\n", pfx, p[0], p[1], p[2]);
382 }
383 if (pcie->validation_bits & CPER_PCIE_VALID_SERIAL_NUMBER)
384 printk("%s""serial number: 0x%04x, 0x%04x\n", pfx,
385 pcie->serial_number.lower, pcie->serial_number.upper);
386 if (pcie->validation_bits & CPER_PCIE_VALID_BRIDGE_CONTROL_STATUS)
387 printk(
388 "%s""bridge: secondary_status: 0x%04x, control: 0x%04x\n",
389 pfx, pcie->bridge.secondary_status, pcie->bridge.control);
390 }
391
392 static void cper_print_tstamp(const char *pfx,
393 struct acpi_hest_generic_data_v300 *gdata)
394 {
395 __u8 hour, min, sec, day, mon, year, century, *timestamp;
396
397 if (gdata->validation_bits & ACPI_HEST_GEN_VALID_TIMESTAMP) {
398 timestamp = (__u8 *)&(gdata->time_stamp);
399 sec = bcd2bin(timestamp[0]);
400 min = bcd2bin(timestamp[1]);
401 hour = bcd2bin(timestamp[2]);
402 day = bcd2bin(timestamp[4]);
403 mon = bcd2bin(timestamp[5]);
404 year = bcd2bin(timestamp[6]);
405 century = bcd2bin(timestamp[7]);
406
407 printk("%s%ststamp: %02d%02d-%02d-%02d %02d:%02d:%02d\n", pfx,
408 (timestamp[3] & 0x1 ? "precise " : "imprecise "),
409 century, year, mon, day, hour, min, sec);
410 }
411 }
412
413 static void
414 cper_estatus_print_section(const char *pfx, struct acpi_hest_generic_data *gdata,
415 int sec_no)
416 {
417 uuid_le *sec_type = (uuid_le *)gdata->section_type;
418 __u16 severity;
419 char newpfx[64];
420
421 if (acpi_hest_get_version(gdata) >= 3)
422 cper_print_tstamp(pfx, (struct acpi_hest_generic_data_v300 *)gdata);
423
424 severity = gdata->error_severity;
425 printk("%s""Error %d, type: %s\n", pfx, sec_no,
426 cper_severity_str(severity));
427 if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID)
428 printk("%s""fru_id: %pUl\n", pfx, (uuid_le *)gdata->fru_id);
429 if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT)
430 printk("%s""fru_text: %.20s\n", pfx, gdata->fru_text);
431
432 snprintf(newpfx, sizeof(newpfx), "%s%s", pfx, INDENT_SP);
433 if (!uuid_le_cmp(*sec_type, CPER_SEC_PROC_GENERIC)) {
434 struct cper_sec_proc_generic *proc_err = acpi_hest_get_payload(gdata);
435
436 printk("%s""section_type: general processor error\n", newpfx);
437 if (gdata->error_data_length >= sizeof(*proc_err))
438 cper_print_proc_generic(newpfx, proc_err);
439 else
440 goto err_section_too_small;
441 } else if (!uuid_le_cmp(*sec_type, CPER_SEC_PLATFORM_MEM)) {
442 struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);
443
444 printk("%s""section_type: memory error\n", newpfx);
445 if (gdata->error_data_length >=
446 sizeof(struct cper_sec_mem_err_old))
447 cper_print_mem(newpfx, mem_err,
448 gdata->error_data_length);
449 else
450 goto err_section_too_small;
451 } else if (!uuid_le_cmp(*sec_type, CPER_SEC_PCIE)) {
452 struct cper_sec_pcie *pcie = acpi_hest_get_payload(gdata);
453
454 printk("%s""section_type: PCIe error\n", newpfx);
455 if (gdata->error_data_length >= sizeof(*pcie))
456 cper_print_pcie(newpfx, pcie, gdata);
457 else
458 goto err_section_too_small;
459 } else
460 printk("%s""section type: unknown, %pUl\n", newpfx, sec_type);
461
462 return;
463
464 err_section_too_small:
465 pr_err(FW_WARN "error section length is too small\n");
466 }
467
468 void cper_estatus_print(const char *pfx,
469 const struct acpi_hest_generic_status *estatus)
470 {
471 struct acpi_hest_generic_data *gdata;
472 unsigned int data_len;
473 int sec_no = 0;
474 char newpfx[64];
475 __u16 severity;
476
477 severity = estatus->error_severity;
478 if (severity == CPER_SEV_CORRECTED)
479 printk("%s%s\n", pfx,
480 "It has been corrected by h/w "
481 "and requires no further action");
482 printk("%s""event severity: %s\n", pfx, cper_severity_str(severity));
483 data_len = estatus->data_length;
484 gdata = (struct acpi_hest_generic_data *)(estatus + 1);
485 snprintf(newpfx, sizeof(newpfx), "%s%s", pfx, INDENT_SP);
486
487 while (data_len >= acpi_hest_get_size(gdata)) {
488 cper_estatus_print_section(newpfx, gdata, sec_no);
489 data_len -= acpi_hest_get_record_size(gdata);
490 gdata = acpi_hest_get_next(gdata);
491 sec_no++;
492 }
493 }
494 EXPORT_SYMBOL_GPL(cper_estatus_print);
495
496 int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus)
497 {
498 if (estatus->data_length &&
499 estatus->data_length < sizeof(struct acpi_hest_generic_data))
500 return -EINVAL;
501 if (estatus->raw_data_length &&
502 estatus->raw_data_offset < sizeof(*estatus) + estatus->data_length)
503 return -EINVAL;
504
505 return 0;
506 }
507 EXPORT_SYMBOL_GPL(cper_estatus_check_header);
508
509 int cper_estatus_check(const struct acpi_hest_generic_status *estatus)
510 {
511 struct acpi_hest_generic_data *gdata;
512 unsigned int data_len, gedata_len;
513 int rc;
514
515 rc = cper_estatus_check_header(estatus);
516 if (rc)
517 return rc;
518 data_len = estatus->data_length;
519 gdata = (struct acpi_hest_generic_data *)(estatus + 1);
520
521 while (data_len >= acpi_hest_get_size(gdata)) {
522 gedata_len = acpi_hest_get_error_length(gdata);
523 if (gedata_len > data_len - acpi_hest_get_size(gdata))
524 return -EINVAL;
525
526 data_len -= acpi_hest_get_record_size(gdata);
527 gdata = acpi_hest_get_next(gdata);
528 }
529 if (data_len)
530 return -EINVAL;
531
532 return 0;
533 }
534 EXPORT_SYMBOL_GPL(cper_estatus_check);