Skip to content

Commit 3760cd2

Browse files
Chen, Gongaegl
authored andcommitted
CPER: Adjust code flow of some functions
Some codes can be reorganzied as a common function for other usages. Signed-off-by: Chen, Gong <gong.chen@linux.intel.com> Signed-off-by: Tony Luck <tony.luck@intel.com>
1 parent 0a2409a commit 3760cd2

2 files changed

Lines changed: 109 additions & 55 deletions

File tree

‎drivers/firmware/efi/cper.c‎

Lines changed: 100 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#include <linux/aer.h>
3535

3636
#define INDENT_SP " "
37+
38+
static char rcd_decode_str[CPER_REC_LEN];
39+
3740
/*
3841
* CPER record ID need to be unique even after reboot, because record
3942
* ID is used as index for ERST storage, while CPER records from
@@ -50,18 +53,19 @@ u64 cper_next_record_id(void)
5053
}
5154
EXPORT_SYMBOL_GPL(cper_next_record_id);
5255

53-
static const char *cper_severity_strs[] = {
56+
static const char * const severity_strs[] = {
5457
"recoverable",
5558
"fatal",
5659
"corrected",
5760
"info",
5861
};
5962

60-
static const char *cper_severity_str(unsigned int severity)
63+
const char *cper_severity_str(unsigned int severity)
6164
{
62-
return severity < ARRAY_SIZE(cper_severity_strs) ?
63-
cper_severity_strs[severity] : "unknown";
65+
return severity < ARRAY_SIZE(severity_strs) ?
66+
severity_strs[severity] : "unknown";
6467
}
68+
EXPORT_SYMBOL_GPL(cper_severity_str);
6569

6670
/*
6771
* cper_print_bits - print strings for set bits
@@ -100,32 +104,32 @@ void cper_print_bits(const char *pfx, unsigned int bits,
100104
printk("%s\n", buf);
101105
}
102106

103-
static const char * const cper_proc_type_strs[] = {
107+
static const char * const proc_type_strs[] = {
104108
"IA32/X64",
105109
"IA64",
106110
};
107111

108-
static const char * const cper_proc_isa_strs[] = {
112+
static const char * const proc_isa_strs[] = {
109113
"IA32",
110114
"IA64",
111115
"X64",
112116
};
113117

114-
static const char * const cper_proc_error_type_strs[] = {
118+
static const char * const proc_error_type_strs[] = {
115119
"cache error",
116120
"TLB error",
117121
"bus error",
118122
"micro-architectural error",
119123
};
120124

121-
static const char * const cper_proc_op_strs[] = {
125+
static const char * const proc_op_strs[] = {
122126
"unknown or generic",
123127
"data read",
124128
"data write",
125129
"instruction execution",
126130
};
127131

128-
static const char * const cper_proc_flag_strs[] = {
132+
static const char * const proc_flag_strs[] = {
129133
"restartable",
130134
"precise IP",
131135
"overflow",
@@ -137,26 +141,26 @@ static void cper_print_proc_generic(const char *pfx,
137141
{
138142
if (proc->validation_bits & CPER_PROC_VALID_TYPE)
139143
printk("%s""processor_type: %d, %s\n", pfx, proc->proc_type,
140-
proc->proc_type < ARRAY_SIZE(cper_proc_type_strs) ?
141-
cper_proc_type_strs[proc->proc_type] : "unknown");
144+
proc->proc_type < ARRAY_SIZE(proc_type_strs) ?
145+
proc_type_strs[proc->proc_type] : "unknown");
142146
if (proc->validation_bits & CPER_PROC_VALID_ISA)
143147
printk("%s""processor_isa: %d, %s\n", pfx, proc->proc_isa,
144-
proc->proc_isa < ARRAY_SIZE(cper_proc_isa_strs) ?
145-
cper_proc_isa_strs[proc->proc_isa] : "unknown");
148+
proc->proc_isa < ARRAY_SIZE(proc_isa_strs) ?
149+
proc_isa_strs[proc->proc_isa] : "unknown");
146150
if (proc->validation_bits & CPER_PROC_VALID_ERROR_TYPE) {
147151
printk("%s""error_type: 0x%02x\n", pfx, proc->proc_error_type);
148152
cper_print_bits(pfx, proc->proc_error_type,
149-
cper_proc_error_type_strs,
150-
ARRAY_SIZE(cper_proc_error_type_strs));
153+
proc_error_type_strs,
154+
ARRAY_SIZE(proc_error_type_strs));
151155
}
152156
if (proc->validation_bits & CPER_PROC_VALID_OPERATION)
153157
printk("%s""operation: %d, %s\n", pfx, proc->operation,
154-
proc->operation < ARRAY_SIZE(cper_proc_op_strs) ?
155-
cper_proc_op_strs[proc->operation] : "unknown");
158+
proc->operation < ARRAY_SIZE(proc_op_strs) ?
159+
proc_op_strs[proc->operation] : "unknown");
156160
if (proc->validation_bits & CPER_PROC_VALID_FLAGS) {
157161
printk("%s""flags: 0x%02x\n", pfx, proc->flags);
158-
cper_print_bits(pfx, proc->flags, cper_proc_flag_strs,
159-
ARRAY_SIZE(cper_proc_flag_strs));
162+
cper_print_bits(pfx, proc->flags, proc_flag_strs,
163+
ARRAY_SIZE(proc_flag_strs));
160164
}
161165
if (proc->validation_bits & CPER_PROC_VALID_LEVEL)
162166
printk("%s""level: %d\n", pfx, proc->level);
@@ -177,7 +181,7 @@ static void cper_print_proc_generic(const char *pfx,
177181
printk("%s""IP: 0x%016llx\n", pfx, proc->ip);
178182
}
179183

180-
static const char *cper_mem_err_type_strs[] = {
184+
static const char * const mem_err_type_strs[] = {
181185
"unknown",
182186
"no error",
183187
"single-bit ECC",
@@ -196,58 +200,99 @@ static const char *cper_mem_err_type_strs[] = {
196200
"physical memory map-out event",
197201
};
198202

199-
static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem)
203+
const char *cper_mem_err_type_str(unsigned int etype)
200204
{
201-
if (mem->validation_bits & CPER_MEM_VALID_ERROR_STATUS)
202-
printk("%s""error_status: 0x%016llx\n", pfx, mem->error_status);
203-
if (mem->validation_bits & CPER_MEM_VALID_PA)
204-
printk("%s""physical_address: 0x%016llx\n",
205-
pfx, mem->physical_addr);
206-
if (mem->validation_bits & CPER_MEM_VALID_PA_MASK)
207-
printk("%s""physical_address_mask: 0x%016llx\n",
208-
pfx, mem->physical_addr_mask);
205+
return etype < ARRAY_SIZE(mem_err_type_strs) ?
206+
mem_err_type_strs[etype] : "unknown";
207+
}
208+
EXPORT_SYMBOL_GPL(cper_mem_err_type_str);
209+
210+
static int cper_mem_err_location(const struct cper_sec_mem_err *mem, char *msg)
211+
{
212+
u32 len, n;
213+
214+
if (!msg)
215+
return 0;
216+
217+
n = 0;
218+
len = CPER_REC_LEN - 1;
209219
if (mem->validation_bits & CPER_MEM_VALID_NODE)
210-
pr_debug("node: %d\n", mem->node);
220+
n += scnprintf(msg + n, len - n, "node: %d ", mem->node);
211221
if (mem->validation_bits & CPER_MEM_VALID_CARD)
212-
pr_debug("card: %d\n", mem->card);
222+
n += scnprintf(msg + n, len - n, "card: %d ", mem->card);
213223
if (mem->validation_bits & CPER_MEM_VALID_MODULE)
214-
pr_debug("module: %d\n", mem->module);
224+
n += scnprintf(msg + n, len - n, "module: %d ", mem->module);
215225
if (mem->validation_bits & CPER_MEM_VALID_RANK_NUMBER)
216-
pr_debug("rank: %d\n", mem->rank);
226+
n += scnprintf(msg + n, len - n, "rank: %d ", mem->rank);
217227
if (mem->validation_bits & CPER_MEM_VALID_BANK)
218-
pr_debug("bank: %d\n", mem->bank);
228+
n += scnprintf(msg + n, len - n, "bank: %d ", mem->bank);
219229
if (mem->validation_bits & CPER_MEM_VALID_DEVICE)
220-
pr_debug("device: %d\n", mem->device);
230+
n += scnprintf(msg + n, len - n, "device: %d ", mem->device);
221231
if (mem->validation_bits & CPER_MEM_VALID_ROW)
222-
pr_debug("row: %d\n", mem->row);
232+
n += scnprintf(msg + n, len - n, "row: %d ", mem->row);
223233
if (mem->validation_bits & CPER_MEM_VALID_COLUMN)
224-
pr_debug("column: %d\n", mem->column);
234+
n += scnprintf(msg + n, len - n, "column: %d ", mem->column);
225235
if (mem->validation_bits & CPER_MEM_VALID_BIT_POSITION)
226-
pr_debug("bit_position: %d\n", mem->bit_pos);
236+
n += scnprintf(msg + n, len - n, "bit_position: %d ",
237+
mem->bit_pos);
227238
if (mem->validation_bits & CPER_MEM_VALID_REQUESTOR_ID)
228-
pr_debug("requestor_id: 0x%016llx\n", mem->requestor_id);
239+
n += scnprintf(msg + n, len - n, "requestor_id: 0x%016llx ",
240+
mem->requestor_id);
229241
if (mem->validation_bits & CPER_MEM_VALID_RESPONDER_ID)
230-
pr_debug("responder_id: 0x%016llx\n", mem->responder_id);
242+
n += scnprintf(msg + n, len - n, "responder_id: 0x%016llx ",
243+
mem->responder_id);
231244
if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID)
232-
pr_debug("target_id: 0x%016llx\n", mem->target_id);
245+
scnprintf(msg + n, len - n, "target_id: 0x%016llx ",
246+
mem->target_id);
247+
248+
msg[n] = '\0';
249+
return n;
250+
}
251+
252+
static int cper_dimm_err_location(const struct cper_sec_mem_err *mem, char *msg)
253+
{
254+
u32 len, n;
255+
const char *bank = NULL, *device = NULL;
256+
257+
if (!msg || !(mem->validation_bits & CPER_MEM_VALID_MODULE_HANDLE))
258+
return 0;
259+
260+
n = 0;
261+
len = CPER_REC_LEN - 1;
262+
dmi_memdev_name(mem->mem_dev_handle, &bank, &device);
263+
if (bank && device)
264+
n = snprintf(msg, len, "DIMM location: %s %s ", bank, device);
265+
else
266+
n = snprintf(msg, len,
267+
"DIMM location: not present. DMI handle: 0x%.4x ",
268+
mem->mem_dev_handle);
269+
270+
msg[n] = '\0';
271+
return n;
272+
}
273+
274+
static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem)
275+
{
276+
if (mem->validation_bits & CPER_MEM_VALID_ERROR_STATUS)
277+
printk("%s""error_status: 0x%016llx\n", pfx, mem->error_status);
278+
if (mem->validation_bits & CPER_MEM_VALID_PA)
279+
printk("%s""physical_address: 0x%016llx\n",
280+
pfx, mem->physical_addr);
281+
if (mem->validation_bits & CPER_MEM_VALID_PA_MASK)
282+
printk("%s""physical_address_mask: 0x%016llx\n",
283+
pfx, mem->physical_addr_mask);
284+
if (cper_mem_err_location(mem, rcd_decode_str))
285+
printk("%s%s\n", pfx, rcd_decode_str);
233286
if (mem->validation_bits & CPER_MEM_VALID_ERROR_TYPE) {
234287
u8 etype = mem->error_type;
235288
printk("%s""error_type: %d, %s\n", pfx, etype,
236-
etype < ARRAY_SIZE(cper_mem_err_type_strs) ?
237-
cper_mem_err_type_strs[etype] : "unknown");
238-
}
239-
if (mem->validation_bits & CPER_MEM_VALID_MODULE_HANDLE) {
240-
const char *bank = NULL, *device = NULL;
241-
dmi_memdev_name(mem->mem_dev_handle, &bank, &device);
242-
if (bank != NULL && device != NULL)
243-
printk("%s""DIMM location: %s %s", pfx, bank, device);
244-
else
245-
printk("%s""DIMM DMI handle: 0x%.4x",
246-
pfx, mem->mem_dev_handle);
289+
cper_mem_err_type_str(etype));
247290
}
291+
if (cper_dimm_err_location(mem, rcd_decode_str))
292+
printk("%s%s\n", pfx, rcd_decode_str);
248293
}
249294

250-
static const char *cper_pcie_port_type_strs[] = {
295+
static const char * const pcie_port_type_strs[] = {
251296
"PCIe end point",
252297
"legacy PCI end point",
253298
"unknown",
@@ -266,8 +311,8 @@ static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
266311
{
267312
if (pcie->validation_bits & CPER_PCIE_VALID_PORT_TYPE)
268313
printk("%s""port_type: %d, %s\n", pfx, pcie->port_type,
269-
pcie->port_type < ARRAY_SIZE(cper_pcie_port_type_strs) ?
270-
cper_pcie_port_type_strs[pcie->port_type] : "unknown");
314+
pcie->port_type < ARRAY_SIZE(pcie_port_type_strs) ?
315+
pcie_port_type_strs[pcie->port_type] : "unknown");
271316
if (pcie->validation_bits & CPER_PCIE_VALID_VERSION)
272317
printk("%s""version: %d.%d\n", pfx,
273318
pcie->version.major, pcie->version.minor);

‎include/linux/cper.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
*/
3636
#define CPER_RECORD_REV 0x0100
3737

38+
/*
39+
* CPER record length contains the CPER fields which are relevant for further
40+
* handling of a memory error in userspace (we don't carry all the fields
41+
* defined in the UEFI spec because some of them don't make any sense.)
42+
* Currently, a length of 256 should be more than enough.
43+
*/
44+
#define CPER_REC_LEN 256
3845
/*
3946
* Severity difinition for error_severity in struct cper_record_header
4047
* and section_severity in struct cper_section_descriptor
@@ -395,6 +402,8 @@ struct cper_sec_pcie {
395402
#pragma pack()
396403

397404
u64 cper_next_record_id(void);
405+
const char *cper_severity_str(unsigned int);
406+
const char *cper_mem_err_type_str(unsigned int);
398407
void cper_print_bits(const char *prefix, unsigned int bits,
399408
const char * const strs[], unsigned int strs_size);
400409

0 commit comments

Comments
 (0)