Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 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 <mchehab@redhat.com> |
| 8 | * |
| 9 | * Red Hat Inc. http://www.redhat.com |
| 10 | */ |
| 11 | |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 14 | #include <acpi/ghes.h> |
| 15 | #include <linux/edac.h> |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 16 | #include <linux/dmi.h> |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 17 | #include "edac_core.h" |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 18 | #include <ras/ras_event.h> |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 19 | |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 20 | #define GHES_EDAC_REVISION " Ver: 1.0.0" |
| 21 | |
| 22 | struct ghes_edac_pvt { |
| 23 | struct list_head list; |
| 24 | struct ghes *ghes; |
| 25 | struct mem_ctl_info *mci; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 26 | |
| 27 | /* Buffers for the error handling routine */ |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 28 | char detail_location[240]; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 29 | char other_detail[160]; |
| 30 | char msg[80]; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | static LIST_HEAD(ghes_reglist); |
| 34 | static DEFINE_MUTEX(ghes_edac_lock); |
| 35 | static int ghes_edac_mc_num; |
| 36 | |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 37 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 38 | /* Memory Device - Type 17 of SMBIOS spec */ |
| 39 | struct memdev_dmi_entry { |
| 40 | u8 type; |
| 41 | u8 length; |
| 42 | u16 handle; |
| 43 | u16 phys_mem_array_handle; |
| 44 | u16 mem_err_info_handle; |
| 45 | u16 total_width; |
| 46 | u16 data_width; |
| 47 | u16 size; |
| 48 | u8 form_factor; |
| 49 | u8 device_set; |
| 50 | u8 device_locator; |
| 51 | u8 bank_locator; |
| 52 | u8 memory_type; |
| 53 | u16 type_detail; |
| 54 | u16 speed; |
| 55 | u8 manufacturer; |
| 56 | u8 serial_number; |
| 57 | u8 asset_tag; |
| 58 | u8 part_number; |
| 59 | u8 attributes; |
| 60 | u32 extended_size; |
| 61 | u16 conf_mem_clk_speed; |
| 62 | } __attribute__((__packed__)); |
| 63 | |
| 64 | struct ghes_edac_dimm_fill { |
| 65 | struct mem_ctl_info *mci; |
| 66 | unsigned count; |
| 67 | }; |
| 68 | |
| 69 | char *memory_type[] = { |
| 70 | [MEM_EMPTY] = "EMPTY", |
| 71 | [MEM_RESERVED] = "RESERVED", |
| 72 | [MEM_UNKNOWN] = "UNKNOWN", |
| 73 | [MEM_FPM] = "FPM", |
| 74 | [MEM_EDO] = "EDO", |
| 75 | [MEM_BEDO] = "BEDO", |
| 76 | [MEM_SDR] = "SDR", |
| 77 | [MEM_RDR] = "RDR", |
| 78 | [MEM_DDR] = "DDR", |
| 79 | [MEM_RDDR] = "RDDR", |
| 80 | [MEM_RMBS] = "RMBS", |
| 81 | [MEM_DDR2] = "DDR2", |
| 82 | [MEM_FB_DDR2] = "FB_DDR2", |
| 83 | [MEM_RDDR2] = "RDDR2", |
| 84 | [MEM_XDR] = "XDR", |
| 85 | [MEM_DDR3] = "DDR3", |
| 86 | [MEM_RDDR3] = "RDDR3", |
| 87 | }; |
| 88 | |
| 89 | static void ghes_edac_count_dimms(const struct dmi_header *dh, void *arg) |
| 90 | { |
| 91 | int *num_dimm = arg; |
| 92 | |
| 93 | if (dh->type == DMI_ENTRY_MEM_DEVICE) |
| 94 | (*num_dimm)++; |
| 95 | } |
| 96 | |
| 97 | static void ghes_edac_dmidecode(const struct dmi_header *dh, void *arg) |
| 98 | { |
| 99 | struct ghes_edac_dimm_fill *dimm_fill = arg; |
| 100 | struct mem_ctl_info *mci = dimm_fill->mci; |
| 101 | |
| 102 | if (dh->type == DMI_ENTRY_MEM_DEVICE) { |
| 103 | struct memdev_dmi_entry *entry = (struct memdev_dmi_entry *)dh; |
| 104 | struct dimm_info *dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, |
| 105 | mci->n_layers, |
| 106 | dimm_fill->count, 0, 0); |
| 107 | |
| 108 | if (entry->size == 0xffff) { |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 109 | pr_info("Can't get DIMM%i size\n", |
| 110 | dimm_fill->count); |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 111 | dimm->nr_pages = MiB_TO_PAGES(32);/* Unknown */ |
| 112 | } else if (entry->size == 0x7fff) { |
| 113 | dimm->nr_pages = MiB_TO_PAGES(entry->extended_size); |
| 114 | } else { |
| 115 | if (entry->size & 1 << 15) |
| 116 | dimm->nr_pages = MiB_TO_PAGES((entry->size & |
| 117 | 0x7fff) << 10); |
| 118 | else |
| 119 | dimm->nr_pages = MiB_TO_PAGES(entry->size); |
| 120 | } |
| 121 | |
| 122 | switch (entry->memory_type) { |
| 123 | case 0x12: |
| 124 | if (entry->type_detail & 1 << 13) |
| 125 | dimm->mtype = MEM_RDDR; |
| 126 | else |
| 127 | dimm->mtype = MEM_DDR; |
| 128 | break; |
| 129 | case 0x13: |
| 130 | if (entry->type_detail & 1 << 13) |
| 131 | dimm->mtype = MEM_RDDR2; |
| 132 | else |
| 133 | dimm->mtype = MEM_DDR2; |
| 134 | break; |
| 135 | case 0x14: |
| 136 | dimm->mtype = MEM_FB_DDR2; |
| 137 | break; |
| 138 | case 0x18: |
| 139 | if (entry->type_detail & 1 << 13) |
| 140 | dimm->mtype = MEM_RDDR3; |
| 141 | else |
| 142 | dimm->mtype = MEM_DDR3; |
| 143 | break; |
| 144 | default: |
| 145 | if (entry->type_detail & 1 << 6) |
| 146 | dimm->mtype = MEM_RMBS; |
| 147 | else if ((entry->type_detail & ((1 << 7) | (1 << 13))) |
| 148 | == ((1 << 7) | (1 << 13))) |
| 149 | dimm->mtype = MEM_RDR; |
| 150 | else if (entry->type_detail & 1 << 7) |
| 151 | dimm->mtype = MEM_SDR; |
| 152 | else if (entry->type_detail & 1 << 9) |
| 153 | dimm->mtype = MEM_EDO; |
| 154 | else |
| 155 | dimm->mtype = MEM_UNKNOWN; |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * Actually, we can only detect if the memory has bits for |
| 160 | * checksum or not |
| 161 | */ |
| 162 | if (entry->total_width == entry->data_width) |
| 163 | dimm->edac_mode = EDAC_NONE; |
| 164 | else |
| 165 | dimm->edac_mode = EDAC_SECDED; |
| 166 | |
| 167 | dimm->dtype = DEV_UNKNOWN; |
| 168 | dimm->grain = 128; /* Likely, worse case */ |
| 169 | |
| 170 | /* |
| 171 | * FIXME: It shouldn't be hard to also fill the DIMM labels |
| 172 | */ |
| 173 | |
| 174 | if (dimm->nr_pages) { |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 175 | edac_dbg(1, "DIMM%i: %s size = %d MB%s\n", |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 176 | dimm_fill->count, memory_type[dimm->mtype], |
| 177 | PAGES_TO_MiB(dimm->nr_pages), |
| 178 | (dimm->edac_mode != EDAC_NONE) ? "(ECC)" : ""); |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 179 | edac_dbg(2, "\ttype %d, detail 0x%02x, width %d(total %d)\n", |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 180 | entry->memory_type, entry->type_detail, |
| 181 | entry->total_width, entry->data_width); |
| 182 | } |
| 183 | |
| 184 | dimm_fill->count++; |
| 185 | } |
| 186 | } |
| 187 | |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 188 | void ghes_edac_report_mem_error(struct ghes *ghes, int sev, |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 189 | struct cper_sec_mem_err *mem_err) |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 190 | { |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 191 | enum hw_event_mc_err_type type; |
| 192 | struct edac_raw_error_desc *e; |
| 193 | struct mem_ctl_info *mci; |
| 194 | struct ghes_edac_pvt *pvt = NULL; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 195 | char *p; |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 196 | u8 grain_bits; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 197 | |
| 198 | list_for_each_entry(pvt, &ghes_reglist, list) { |
| 199 | if (ghes == pvt->ghes) |
| 200 | break; |
| 201 | } |
| 202 | if (!pvt) { |
| 203 | pr_err("Internal error: Can't find EDAC structure\n"); |
| 204 | return; |
| 205 | } |
| 206 | mci = pvt->mci; |
| 207 | e = &mci->error_desc; |
| 208 | |
| 209 | /* Cleans the error report buffer */ |
| 210 | memset(e, 0, sizeof (*e)); |
| 211 | e->error_count = 1; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 212 | strcpy(e->label, "unknown label"); |
| 213 | e->msg = pvt->msg; |
| 214 | e->other_detail = pvt->other_detail; |
| 215 | e->top_layer = -1; |
| 216 | e->mid_layer = -1; |
| 217 | e->low_layer = -1; |
| 218 | *pvt->other_detail = '\0'; |
| 219 | *pvt->msg = '\0'; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 220 | |
| 221 | switch (sev) { |
| 222 | case GHES_SEV_CORRECTED: |
| 223 | type = HW_EVENT_ERR_CORRECTED; |
| 224 | break; |
| 225 | case GHES_SEV_RECOVERABLE: |
| 226 | type = HW_EVENT_ERR_UNCORRECTED; |
| 227 | break; |
| 228 | case GHES_SEV_PANIC: |
| 229 | type = HW_EVENT_ERR_FATAL; |
| 230 | break; |
| 231 | default: |
| 232 | case GHES_SEV_NO: |
| 233 | type = HW_EVENT_ERR_INFO; |
| 234 | } |
| 235 | |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 236 | edac_dbg(1, "error validation_bits: 0x%08llx\n", |
| 237 | (long long)mem_err->validation_bits); |
| 238 | |
| 239 | /* Error type, mapped on e->msg */ |
| 240 | if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_TYPE) { |
| 241 | p = pvt->msg; |
| 242 | switch (mem_err->error_type) { |
| 243 | case 0: |
| 244 | p += sprintf(p, "Unknown"); |
| 245 | break; |
| 246 | case 1: |
| 247 | p += sprintf(p, "No error"); |
| 248 | break; |
| 249 | case 2: |
| 250 | p += sprintf(p, "Single-bit ECC"); |
| 251 | break; |
| 252 | case 3: |
| 253 | p += sprintf(p, "Multi-bit ECC"); |
| 254 | break; |
| 255 | case 4: |
| 256 | p += sprintf(p, "Single-symbol ChipKill ECC"); |
| 257 | break; |
| 258 | case 5: |
| 259 | p += sprintf(p, "Multi-symbol ChipKill ECC"); |
| 260 | break; |
| 261 | case 6: |
| 262 | p += sprintf(p, "Master abort"); |
| 263 | break; |
| 264 | case 7: |
| 265 | p += sprintf(p, "Target abort"); |
| 266 | break; |
| 267 | case 8: |
| 268 | p += sprintf(p, "Parity Error"); |
| 269 | break; |
| 270 | case 9: |
| 271 | p += sprintf(p, "Watchdog timeout"); |
| 272 | break; |
| 273 | case 10: |
| 274 | p += sprintf(p, "Invalid address"); |
| 275 | break; |
| 276 | case 11: |
| 277 | p += sprintf(p, "Mirror Broken"); |
| 278 | break; |
| 279 | case 12: |
| 280 | p += sprintf(p, "Memory Sparing"); |
| 281 | break; |
| 282 | case 13: |
| 283 | p += sprintf(p, "Scrub corrected error"); |
| 284 | break; |
| 285 | case 14: |
| 286 | p += sprintf(p, "Scrub uncorrected error"); |
| 287 | break; |
| 288 | case 15: |
| 289 | p += sprintf(p, "Physical Memory Map-out event"); |
| 290 | break; |
| 291 | default: |
| 292 | p += sprintf(p, "reserved error (%d)", |
| 293 | mem_err->error_type); |
| 294 | } |
| 295 | } else { |
| 296 | strcpy(pvt->msg, "unknown error"); |
| 297 | } |
| 298 | |
| 299 | /* Error address */ |
Chen, Gong | 147de14 | 2013-10-18 14:30:13 -0700 | [diff] [blame^] | 300 | if (mem_err->validation_bits & CPER_MEM_VALID_PA) { |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 301 | e->page_frame_number = mem_err->physical_addr >> PAGE_SHIFT; |
| 302 | e->offset_in_page = mem_err->physical_addr & ~PAGE_MASK; |
| 303 | } |
| 304 | |
| 305 | /* Error grain */ |
Chen, Gong | 147de14 | 2013-10-18 14:30:13 -0700 | [diff] [blame^] | 306 | if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK) |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 307 | e->grain = ~(mem_err->physical_addr_mask & ~PAGE_MASK); |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 308 | |
| 309 | /* Memory error location, mapped on e->location */ |
| 310 | p = e->location; |
| 311 | if (mem_err->validation_bits & CPER_MEM_VALID_NODE) |
| 312 | p += sprintf(p, "node:%d ", mem_err->node); |
| 313 | if (mem_err->validation_bits & CPER_MEM_VALID_CARD) |
| 314 | p += sprintf(p, "card:%d ", mem_err->card); |
| 315 | if (mem_err->validation_bits & CPER_MEM_VALID_MODULE) |
| 316 | p += sprintf(p, "module:%d ", mem_err->module); |
| 317 | if (mem_err->validation_bits & CPER_MEM_VALID_BANK) |
| 318 | p += sprintf(p, "bank:%d ", mem_err->bank); |
| 319 | if (mem_err->validation_bits & CPER_MEM_VALID_ROW) |
| 320 | p += sprintf(p, "row:%d ", mem_err->row); |
| 321 | if (mem_err->validation_bits & CPER_MEM_VALID_COLUMN) |
| 322 | p += sprintf(p, "col:%d ", mem_err->column); |
| 323 | if (mem_err->validation_bits & CPER_MEM_VALID_BIT_POSITION) |
| 324 | p += sprintf(p, "bit_pos:%d ", mem_err->bit_pos); |
| 325 | if (p > e->location) |
| 326 | *(p - 1) = '\0'; |
| 327 | |
| 328 | /* All other fields are mapped on e->other_detail */ |
| 329 | p = pvt->other_detail; |
| 330 | if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_STATUS) { |
| 331 | u64 status = mem_err->error_status; |
| 332 | |
| 333 | p += sprintf(p, "status(0x%016llx): ", (long long)status); |
| 334 | switch ((status >> 8) & 0xff) { |
| 335 | case 1: |
| 336 | p += sprintf(p, "Error detected internal to the component "); |
| 337 | break; |
| 338 | case 16: |
| 339 | p += sprintf(p, "Error detected in the bus "); |
| 340 | break; |
| 341 | case 4: |
| 342 | p += sprintf(p, "Storage error in DRAM memory "); |
| 343 | break; |
| 344 | case 5: |
| 345 | p += sprintf(p, "Storage error in TLB "); |
| 346 | break; |
| 347 | case 6: |
| 348 | p += sprintf(p, "Storage error in cache "); |
| 349 | break; |
| 350 | case 7: |
| 351 | p += sprintf(p, "Error in one or more functional units "); |
| 352 | break; |
| 353 | case 8: |
| 354 | p += sprintf(p, "component failed self test "); |
| 355 | break; |
| 356 | case 9: |
| 357 | p += sprintf(p, "Overflow or undervalue of internal queue "); |
| 358 | break; |
| 359 | case 17: |
| 360 | p += sprintf(p, "Virtual address not found on IO-TLB or IO-PDIR "); |
| 361 | break; |
| 362 | case 18: |
| 363 | p += sprintf(p, "Improper access error "); |
| 364 | break; |
| 365 | case 19: |
| 366 | p += sprintf(p, "Access to a memory address which is not mapped to any component "); |
| 367 | break; |
| 368 | case 20: |
| 369 | p += sprintf(p, "Loss of Lockstep "); |
| 370 | break; |
| 371 | case 21: |
| 372 | p += sprintf(p, "Response not associated with a request "); |
| 373 | break; |
| 374 | case 22: |
| 375 | p += sprintf(p, "Bus parity error - must also set the A, C, or D Bits "); |
| 376 | break; |
| 377 | case 23: |
| 378 | p += sprintf(p, "Detection of a PATH_ERROR "); |
| 379 | break; |
| 380 | case 25: |
| 381 | p += sprintf(p, "Bus operation timeout "); |
| 382 | break; |
| 383 | case 26: |
| 384 | p += sprintf(p, "A read was issued to data that has been poisoned "); |
| 385 | break; |
| 386 | default: |
| 387 | p += sprintf(p, "reserved "); |
| 388 | break; |
| 389 | } |
| 390 | } |
| 391 | if (mem_err->validation_bits & CPER_MEM_VALID_REQUESTOR_ID) |
| 392 | p += sprintf(p, "requestorID: 0x%016llx ", |
| 393 | (long long)mem_err->requestor_id); |
| 394 | if (mem_err->validation_bits & CPER_MEM_VALID_RESPONDER_ID) |
| 395 | p += sprintf(p, "responderID: 0x%016llx ", |
| 396 | (long long)mem_err->responder_id); |
| 397 | if (mem_err->validation_bits & CPER_MEM_VALID_TARGET_ID) |
| 398 | p += sprintf(p, "targetID: 0x%016llx ", |
| 399 | (long long)mem_err->responder_id); |
| 400 | if (p > pvt->other_detail) |
| 401 | *(p - 1) = '\0'; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 402 | |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 403 | /* Generate the trace event */ |
| 404 | grain_bits = fls_long(e->grain); |
| 405 | sprintf(pvt->detail_location, "APEI location: %s %s", |
| 406 | e->location, e->other_detail); |
| 407 | trace_mc_event(type, e->msg, e->label, e->error_count, |
| 408 | mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer, |
| 409 | PAGES_TO_MiB(e->page_frame_number) | e->offset_in_page, |
| 410 | grain_bits, e->syndrome, pvt->detail_location); |
| 411 | |
| 412 | /* Report the error via EDAC API */ |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 413 | edac_raw_mc_handle_error(type, mci, e); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 414 | } |
| 415 | EXPORT_SYMBOL_GPL(ghes_edac_report_mem_error); |
| 416 | |
| 417 | int ghes_edac_register(struct ghes *ghes, struct device *dev) |
| 418 | { |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 419 | bool fake = false; |
| 420 | int rc, num_dimm = 0; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 421 | struct mem_ctl_info *mci; |
| 422 | struct edac_mc_layer layers[1]; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 423 | struct ghes_edac_pvt *pvt; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 424 | struct ghes_edac_dimm_fill dimm_fill; |
| 425 | |
| 426 | /* Get the number of DIMMs */ |
| 427 | dmi_walk(ghes_edac_count_dimms, &num_dimm); |
| 428 | |
| 429 | /* Check if we've got a bogus BIOS */ |
| 430 | if (num_dimm == 0) { |
| 431 | fake = true; |
| 432 | num_dimm = 1; |
| 433 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 434 | |
| 435 | layers[0].type = EDAC_MC_LAYER_ALL_MEM; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 436 | layers[0].size = num_dimm; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 437 | layers[0].is_virt_csrow = true; |
| 438 | |
| 439 | /* |
| 440 | * We need to serialize edac_mc_alloc() and edac_mc_add_mc(), |
| 441 | * to avoid duplicated memory controller numbers |
| 442 | */ |
| 443 | mutex_lock(&ghes_edac_lock); |
| 444 | mci = edac_mc_alloc(ghes_edac_mc_num, ARRAY_SIZE(layers), layers, |
| 445 | sizeof(*pvt)); |
| 446 | if (!mci) { |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 447 | pr_info("Can't allocate memory for EDAC data\n"); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 448 | mutex_unlock(&ghes_edac_lock); |
| 449 | return -ENOMEM; |
| 450 | } |
| 451 | |
| 452 | pvt = mci->pvt_info; |
| 453 | memset(pvt, 0, sizeof(*pvt)); |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 454 | list_add_tail(&pvt->list, &ghes_reglist); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 455 | pvt->ghes = ghes; |
| 456 | pvt->mci = mci; |
| 457 | mci->pdev = dev; |
| 458 | |
| 459 | mci->mtype_cap = MEM_FLAG_EMPTY; |
| 460 | mci->edac_ctl_cap = EDAC_FLAG_NONE; |
| 461 | mci->edac_cap = EDAC_FLAG_NONE; |
| 462 | mci->mod_name = "ghes_edac.c"; |
| 463 | mci->mod_ver = GHES_EDAC_REVISION; |
| 464 | mci->ctl_name = "ghes_edac"; |
| 465 | mci->dev_name = "ghes"; |
| 466 | |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 467 | if (!ghes_edac_mc_num) { |
| 468 | if (!fake) { |
| 469 | pr_info("This EDAC driver relies on BIOS to enumerate memory and get error reports.\n"); |
| 470 | pr_info("Unfortunately, not all BIOSes reflect the memory layout correctly.\n"); |
| 471 | pr_info("So, the end result of using this driver varies from vendor to vendor.\n"); |
| 472 | pr_info("If you find incorrect reports, please contact your hardware vendor\n"); |
| 473 | pr_info("to correct its BIOS.\n"); |
| 474 | pr_info("This system has %d DIMM sockets.\n", |
| 475 | num_dimm); |
| 476 | } else { |
| 477 | pr_info("This system has a very crappy BIOS: It doesn't even list the DIMMS.\n"); |
| 478 | pr_info("Its SMBIOS info is wrong. It is doubtful that the error report would\n"); |
| 479 | pr_info("work on such system. Use this driver with caution\n"); |
| 480 | } |
| 481 | } |
| 482 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 483 | if (!fake) { |
Mauro Carvalho Chehab | 5ee726d | 2013-02-15 08:45:00 -0300 | [diff] [blame] | 484 | /* |
| 485 | * Fill DIMM info from DMI for the memory controller #0 |
| 486 | * |
| 487 | * Keep it in blank for the other memory controllers, as |
| 488 | * there's no reliable way to properly credit each DIMM to |
| 489 | * the memory controller, as different BIOSes fill the |
| 490 | * DMI bank location fields on different ways |
| 491 | */ |
| 492 | if (!ghes_edac_mc_num) { |
| 493 | dimm_fill.count = 0; |
| 494 | dimm_fill.mci = mci; |
| 495 | dmi_walk(ghes_edac_dmidecode, &dimm_fill); |
| 496 | } |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 497 | } else { |
| 498 | struct dimm_info *dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, |
| 499 | mci->n_layers, 0, 0, 0); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 500 | |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 501 | dimm->nr_pages = 1; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 502 | dimm->grain = 128; |
| 503 | dimm->mtype = MEM_UNKNOWN; |
| 504 | dimm->dtype = DEV_UNKNOWN; |
| 505 | dimm->edac_mode = EDAC_SECDED; |
| 506 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 507 | |
| 508 | rc = edac_mc_add_mc(mci); |
| 509 | if (rc < 0) { |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 510 | pr_info("Can't register at EDAC core\n"); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 511 | edac_mc_free(mci); |
| 512 | mutex_unlock(&ghes_edac_lock); |
| 513 | return -ENODEV; |
| 514 | } |
| 515 | |
| 516 | ghes_edac_mc_num++; |
| 517 | mutex_unlock(&ghes_edac_lock); |
| 518 | return 0; |
| 519 | } |
| 520 | EXPORT_SYMBOL_GPL(ghes_edac_register); |
| 521 | |
| 522 | void ghes_edac_unregister(struct ghes *ghes) |
| 523 | { |
| 524 | struct mem_ctl_info *mci; |
Wei Yongjun | 5dae92a | 2013-02-26 16:39:14 +0800 | [diff] [blame] | 525 | struct ghes_edac_pvt *pvt, *tmp; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 526 | |
Wei Yongjun | 5dae92a | 2013-02-26 16:39:14 +0800 | [diff] [blame] | 527 | list_for_each_entry_safe(pvt, tmp, &ghes_reglist, list) { |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 528 | if (ghes == pvt->ghes) { |
| 529 | mci = pvt->mci; |
| 530 | edac_mc_del_mc(mci->pdev); |
| 531 | edac_mc_free(mci); |
| 532 | list_del(&pvt->list); |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | EXPORT_SYMBOL_GPL(ghes_edac_unregister); |