Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Chen, Gong and committed by
Tony Luck
3760cd20 0a2409aa

+112 -58
+103 -58
drivers/firmware/efi/cper.c
··· 34 34 #include <linux/aer.h> 35 35 36 36 #define INDENT_SP " " 37 + 38 + static char rcd_decode_str[CPER_REC_LEN]; 39 + 37 40 /* 38 41 * CPER record ID need to be unique even after reboot, because record 39 42 * ID is used as index for ERST storage, while CPER records from ··· 53 50 } 54 51 EXPORT_SYMBOL_GPL(cper_next_record_id); 55 52 56 - static const char *cper_severity_strs[] = { 53 + static const char * const severity_strs[] = { 57 54 "recoverable", 58 55 "fatal", 59 56 "corrected", 60 57 "info", 61 58 }; 62 59 63 - static const char *cper_severity_str(unsigned int severity) 60 + const char *cper_severity_str(unsigned int severity) 64 61 { 65 - return severity < ARRAY_SIZE(cper_severity_strs) ? 66 - cper_severity_strs[severity] : "unknown"; 62 + return severity < ARRAY_SIZE(severity_strs) ? 63 + severity_strs[severity] : "unknown"; 67 64 } 65 + EXPORT_SYMBOL_GPL(cper_severity_str); 68 66 69 67 /* 70 68 * cper_print_bits - print strings for set bits ··· 104 100 printk("%s\n", buf); 105 101 } 106 102 107 - static const char * const cper_proc_type_strs[] = { 103 + static const char * const proc_type_strs[] = { 108 104 "IA32/X64", 109 105 "IA64", 110 106 }; 111 107 112 - static const char * const cper_proc_isa_strs[] = { 108 + static const char * const proc_isa_strs[] = { 113 109 "IA32", 114 110 "IA64", 115 111 "X64", 116 112 }; 117 113 118 - static const char * const cper_proc_error_type_strs[] = { 114 + static const char * const proc_error_type_strs[] = { 119 115 "cache error", 120 116 "TLB error", 121 117 "bus error", 122 118 "micro-architectural error", 123 119 }; 124 120 125 - static const char * const cper_proc_op_strs[] = { 121 + static const char * const proc_op_strs[] = { 126 122 "unknown or generic", 127 123 "data read", 128 124 "data write", 129 125 "instruction execution", 130 126 }; 131 127 132 - static const char * const cper_proc_flag_strs[] = { 128 + static const char * const proc_flag_strs[] = { 133 129 "restartable", 134 130 "precise IP", 135 131 "overflow", ··· 141 137 { 142 138 if (proc->validation_bits & CPER_PROC_VALID_TYPE) 143 139 printk("%s""processor_type: %d, %s\n", pfx, proc->proc_type, 144 - proc->proc_type < ARRAY_SIZE(cper_proc_type_strs) ? 145 - cper_proc_type_strs[proc->proc_type] : "unknown"); 140 + proc->proc_type < ARRAY_SIZE(proc_type_strs) ? 141 + proc_type_strs[proc->proc_type] : "unknown"); 146 142 if (proc->validation_bits & CPER_PROC_VALID_ISA) 147 143 printk("%s""processor_isa: %d, %s\n", pfx, proc->proc_isa, 148 - proc->proc_isa < ARRAY_SIZE(cper_proc_isa_strs) ? 149 - cper_proc_isa_strs[proc->proc_isa] : "unknown"); 144 + proc->proc_isa < ARRAY_SIZE(proc_isa_strs) ? 145 + proc_isa_strs[proc->proc_isa] : "unknown"); 150 146 if (proc->validation_bits & CPER_PROC_VALID_ERROR_TYPE) { 151 147 printk("%s""error_type: 0x%02x\n", pfx, proc->proc_error_type); 152 148 cper_print_bits(pfx, proc->proc_error_type, 153 - cper_proc_error_type_strs, 154 - ARRAY_SIZE(cper_proc_error_type_strs)); 149 + proc_error_type_strs, 150 + ARRAY_SIZE(proc_error_type_strs)); 155 151 } 156 152 if (proc->validation_bits & CPER_PROC_VALID_OPERATION) 157 153 printk("%s""operation: %d, %s\n", pfx, proc->operation, 158 - proc->operation < ARRAY_SIZE(cper_proc_op_strs) ? 159 - cper_proc_op_strs[proc->operation] : "unknown"); 154 + proc->operation < ARRAY_SIZE(proc_op_strs) ? 155 + proc_op_strs[proc->operation] : "unknown"); 160 156 if (proc->validation_bits & CPER_PROC_VALID_FLAGS) { 161 157 printk("%s""flags: 0x%02x\n", pfx, proc->flags); 162 - cper_print_bits(pfx, proc->flags, cper_proc_flag_strs, 163 - ARRAY_SIZE(cper_proc_flag_strs)); 158 + cper_print_bits(pfx, proc->flags, proc_flag_strs, 159 + ARRAY_SIZE(proc_flag_strs)); 164 160 } 165 161 if (proc->validation_bits & CPER_PROC_VALID_LEVEL) 166 162 printk("%s""level: %d\n", pfx, proc->level); ··· 181 177 printk("%s""IP: 0x%016llx\n", pfx, proc->ip); 182 178 } 183 179 184 - static const char *cper_mem_err_type_strs[] = { 180 + static const char * const mem_err_type_strs[] = { 185 181 "unknown", 186 182 "no error", 187 183 "single-bit ECC", ··· 200 196 "physical memory map-out event", 201 197 }; 202 198 199 + const char *cper_mem_err_type_str(unsigned int etype) 200 + { 201 + return etype < ARRAY_SIZE(mem_err_type_strs) ? 202 + mem_err_type_strs[etype] : "unknown"; 203 + } 204 + EXPORT_SYMBOL_GPL(cper_mem_err_type_str); 205 + 206 + static int cper_mem_err_location(const struct cper_sec_mem_err *mem, char *msg) 207 + { 208 + u32 len, n; 209 + 210 + if (!msg) 211 + return 0; 212 + 213 + n = 0; 214 + len = CPER_REC_LEN - 1; 215 + if (mem->validation_bits & CPER_MEM_VALID_NODE) 216 + n += scnprintf(msg + n, len - n, "node: %d ", mem->node); 217 + if (mem->validation_bits & CPER_MEM_VALID_CARD) 218 + n += scnprintf(msg + n, len - n, "card: %d ", mem->card); 219 + if (mem->validation_bits & CPER_MEM_VALID_MODULE) 220 + n += scnprintf(msg + n, len - n, "module: %d ", mem->module); 221 + if (mem->validation_bits & CPER_MEM_VALID_RANK_NUMBER) 222 + n += scnprintf(msg + n, len - n, "rank: %d ", mem->rank); 223 + if (mem->validation_bits & CPER_MEM_VALID_BANK) 224 + n += scnprintf(msg + n, len - n, "bank: %d ", mem->bank); 225 + if (mem->validation_bits & CPER_MEM_VALID_DEVICE) 226 + n += scnprintf(msg + n, len - n, "device: %d ", mem->device); 227 + if (mem->validation_bits & CPER_MEM_VALID_ROW) 228 + n += scnprintf(msg + n, len - n, "row: %d ", mem->row); 229 + if (mem->validation_bits & CPER_MEM_VALID_COLUMN) 230 + n += scnprintf(msg + n, len - n, "column: %d ", mem->column); 231 + if (mem->validation_bits & CPER_MEM_VALID_BIT_POSITION) 232 + n += scnprintf(msg + n, len - n, "bit_position: %d ", 233 + mem->bit_pos); 234 + if (mem->validation_bits & CPER_MEM_VALID_REQUESTOR_ID) 235 + n += scnprintf(msg + n, len - n, "requestor_id: 0x%016llx ", 236 + mem->requestor_id); 237 + if (mem->validation_bits & CPER_MEM_VALID_RESPONDER_ID) 238 + n += scnprintf(msg + n, len - n, "responder_id: 0x%016llx ", 239 + mem->responder_id); 240 + if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID) 241 + scnprintf(msg + n, len - n, "target_id: 0x%016llx ", 242 + mem->target_id); 243 + 244 + msg[n] = '\0'; 245 + return n; 246 + } 247 + 248 + static int cper_dimm_err_location(const struct cper_sec_mem_err *mem, char *msg) 249 + { 250 + u32 len, n; 251 + const char *bank = NULL, *device = NULL; 252 + 253 + if (!msg || !(mem->validation_bits & CPER_MEM_VALID_MODULE_HANDLE)) 254 + return 0; 255 + 256 + n = 0; 257 + len = CPER_REC_LEN - 1; 258 + dmi_memdev_name(mem->mem_dev_handle, &bank, &device); 259 + if (bank && device) 260 + n = snprintf(msg, len, "DIMM location: %s %s ", bank, device); 261 + else 262 + n = snprintf(msg, len, 263 + "DIMM location: not present. DMI handle: 0x%.4x ", 264 + mem->mem_dev_handle); 265 + 266 + msg[n] = '\0'; 267 + return n; 268 + } 269 + 203 270 static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem) 204 271 { 205 272 if (mem->validation_bits & CPER_MEM_VALID_ERROR_STATUS) ··· 281 206 if (mem->validation_bits & CPER_MEM_VALID_PA_MASK) 282 207 printk("%s""physical_address_mask: 0x%016llx\n", 283 208 pfx, mem->physical_addr_mask); 284 - if (mem->validation_bits & CPER_MEM_VALID_NODE) 285 - pr_debug("node: %d\n", mem->node); 286 - if (mem->validation_bits & CPER_MEM_VALID_CARD) 287 - pr_debug("card: %d\n", mem->card); 288 - if (mem->validation_bits & CPER_MEM_VALID_MODULE) 289 - pr_debug("module: %d\n", mem->module); 290 - if (mem->validation_bits & CPER_MEM_VALID_RANK_NUMBER) 291 - pr_debug("rank: %d\n", mem->rank); 292 - if (mem->validation_bits & CPER_MEM_VALID_BANK) 293 - pr_debug("bank: %d\n", mem->bank); 294 - if (mem->validation_bits & CPER_MEM_VALID_DEVICE) 295 - pr_debug("device: %d\n", mem->device); 296 - if (mem->validation_bits & CPER_MEM_VALID_ROW) 297 - pr_debug("row: %d\n", mem->row); 298 - if (mem->validation_bits & CPER_MEM_VALID_COLUMN) 299 - pr_debug("column: %d\n", mem->column); 300 - if (mem->validation_bits & CPER_MEM_VALID_BIT_POSITION) 301 - pr_debug("bit_position: %d\n", mem->bit_pos); 302 - if (mem->validation_bits & CPER_MEM_VALID_REQUESTOR_ID) 303 - pr_debug("requestor_id: 0x%016llx\n", mem->requestor_id); 304 - if (mem->validation_bits & CPER_MEM_VALID_RESPONDER_ID) 305 - pr_debug("responder_id: 0x%016llx\n", mem->responder_id); 306 - if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID) 307 - pr_debug("target_id: 0x%016llx\n", mem->target_id); 209 + if (cper_mem_err_location(mem, rcd_decode_str)) 210 + printk("%s%s\n", pfx, rcd_decode_str); 308 211 if (mem->validation_bits & CPER_MEM_VALID_ERROR_TYPE) { 309 212 u8 etype = mem->error_type; 310 213 printk("%s""error_type: %d, %s\n", pfx, etype, 311 - etype < ARRAY_SIZE(cper_mem_err_type_strs) ? 312 - cper_mem_err_type_strs[etype] : "unknown"); 214 + cper_mem_err_type_str(etype)); 313 215 } 314 - if (mem->validation_bits & CPER_MEM_VALID_MODULE_HANDLE) { 315 - const char *bank = NULL, *device = NULL; 316 - dmi_memdev_name(mem->mem_dev_handle, &bank, &device); 317 - if (bank != NULL && device != NULL) 318 - printk("%s""DIMM location: %s %s", pfx, bank, device); 319 - else 320 - printk("%s""DIMM DMI handle: 0x%.4x", 321 - pfx, mem->mem_dev_handle); 322 - } 216 + if (cper_dimm_err_location(mem, rcd_decode_str)) 217 + printk("%s%s\n", pfx, rcd_decode_str); 323 218 } 324 219 325 - static const char *cper_pcie_port_type_strs[] = { 220 + static const char * const pcie_port_type_strs[] = { 326 221 "PCIe end point", 327 222 "legacy PCI end point", 328 223 "unknown", ··· 311 266 { 312 267 if (pcie->validation_bits & CPER_PCIE_VALID_PORT_TYPE) 313 268 printk("%s""port_type: %d, %s\n", pfx, pcie->port_type, 314 - pcie->port_type < ARRAY_SIZE(cper_pcie_port_type_strs) ? 315 - cper_pcie_port_type_strs[pcie->port_type] : "unknown"); 269 + pcie->port_type < ARRAY_SIZE(pcie_port_type_strs) ? 270 + pcie_port_type_strs[pcie->port_type] : "unknown"); 316 271 if (pcie->validation_bits & CPER_PCIE_VALID_VERSION) 317 272 printk("%s""version: %d.%d\n", pfx, 318 273 pcie->version.major, pcie->version.minor);
+9
include/linux/cper.h
··· 36 36 #define CPER_RECORD_REV 0x0100 37 37 38 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 45 + /* 39 46 * Severity difinition for error_severity in struct cper_record_header 40 47 * and section_severity in struct cper_section_descriptor 41 48 */ ··· 402 395 #pragma pack() 403 396 404 397 u64 cper_next_record_id(void); 398 + const char *cper_severity_str(unsigned int); 399 + const char *cper_mem_err_type_str(unsigned int); 405 400 void cper_print_bits(const char *prefix, unsigned int bits, 406 401 const char * const strs[], unsigned int strs_size); 407 402