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 | * |
Mauro Carvalho Chehab | 37e59f8 | 2014-02-07 08:03:07 -0200 | [diff] [blame] | 7 | * Copyright (c) 2013 by Mauro Carvalho Chehab |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 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 | 78d88e8 | 2016-10-29 15:16:34 -0200 | [diff] [blame] | 17 | #include "edac_module.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 | struct ghes_edac_pvt { |
| 21 | struct list_head list; |
| 22 | struct ghes *ghes; |
| 23 | struct mem_ctl_info *mci; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 24 | |
| 25 | /* Buffers for the error handling routine */ |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 26 | char detail_location[240]; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 27 | char other_detail[160]; |
| 28 | char msg[80]; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 29 | }; |
| 30 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 31 | static atomic_t ghes_init = ATOMIC_INIT(0); |
| 32 | static struct ghes_edac_pvt *ghes_pvt; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 33 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 34 | /* |
| 35 | * Sync with other, potentially concurrent callers of |
| 36 | * ghes_edac_report_mem_error(). We don't know what the |
| 37 | * "inventive" firmware would do. |
| 38 | */ |
| 39 | static DEFINE_SPINLOCK(ghes_lock); |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 40 | |
Toshi Kani | 5deed6b | 2017-08-23 16:54:45 -0600 | [diff] [blame] | 41 | /* "ghes_edac.force_load=1" skips the platform check */ |
| 42 | static bool __read_mostly force_load; |
| 43 | module_param(force_load, bool, 0); |
| 44 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 45 | /* Memory Device - Type 17 of SMBIOS spec */ |
| 46 | struct memdev_dmi_entry { |
| 47 | u8 type; |
| 48 | u8 length; |
| 49 | u16 handle; |
| 50 | u16 phys_mem_array_handle; |
| 51 | u16 mem_err_info_handle; |
| 52 | u16 total_width; |
| 53 | u16 data_width; |
| 54 | u16 size; |
| 55 | u8 form_factor; |
| 56 | u8 device_set; |
| 57 | u8 device_locator; |
| 58 | u8 bank_locator; |
| 59 | u8 memory_type; |
| 60 | u16 type_detail; |
| 61 | u16 speed; |
| 62 | u8 manufacturer; |
| 63 | u8 serial_number; |
| 64 | u8 asset_tag; |
| 65 | u8 part_number; |
| 66 | u8 attributes; |
| 67 | u32 extended_size; |
| 68 | u16 conf_mem_clk_speed; |
| 69 | } __attribute__((__packed__)); |
| 70 | |
| 71 | struct ghes_edac_dimm_fill { |
| 72 | struct mem_ctl_info *mci; |
| 73 | unsigned count; |
| 74 | }; |
| 75 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 76 | static void ghes_edac_count_dimms(const struct dmi_header *dh, void *arg) |
| 77 | { |
| 78 | int *num_dimm = arg; |
| 79 | |
| 80 | if (dh->type == DMI_ENTRY_MEM_DEVICE) |
| 81 | (*num_dimm)++; |
| 82 | } |
| 83 | |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 84 | static int get_dimm_smbios_index(u16 handle) |
| 85 | { |
| 86 | struct mem_ctl_info *mci = ghes_pvt->mci; |
| 87 | int i; |
| 88 | |
| 89 | for (i = 0; i < mci->tot_dimms; i++) { |
| 90 | if (mci->dimms[i]->smbios_handle == handle) |
| 91 | return i; |
| 92 | } |
| 93 | return -1; |
| 94 | } |
| 95 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 96 | static void ghes_edac_dmidecode(const struct dmi_header *dh, void *arg) |
| 97 | { |
| 98 | struct ghes_edac_dimm_fill *dimm_fill = arg; |
| 99 | struct mem_ctl_info *mci = dimm_fill->mci; |
| 100 | |
| 101 | if (dh->type == DMI_ENTRY_MEM_DEVICE) { |
| 102 | struct memdev_dmi_entry *entry = (struct memdev_dmi_entry *)dh; |
| 103 | struct dimm_info *dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, |
| 104 | mci->n_layers, |
| 105 | dimm_fill->count, 0, 0); |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 106 | u16 rdr_mask = BIT(7) | BIT(13); |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 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 { |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 115 | if (entry->size & BIT(15)) |
| 116 | dimm->nr_pages = MiB_TO_PAGES((entry->size & 0x7fff) << 10); |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 117 | else |
| 118 | dimm->nr_pages = MiB_TO_PAGES(entry->size); |
| 119 | } |
| 120 | |
| 121 | switch (entry->memory_type) { |
| 122 | case 0x12: |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 123 | if (entry->type_detail & BIT(13)) |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 124 | dimm->mtype = MEM_RDDR; |
| 125 | else |
| 126 | dimm->mtype = MEM_DDR; |
| 127 | break; |
| 128 | case 0x13: |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 129 | if (entry->type_detail & BIT(13)) |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 130 | dimm->mtype = MEM_RDDR2; |
| 131 | else |
| 132 | dimm->mtype = MEM_DDR2; |
| 133 | break; |
| 134 | case 0x14: |
| 135 | dimm->mtype = MEM_FB_DDR2; |
| 136 | break; |
| 137 | case 0x18: |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 138 | if (entry->type_detail & BIT(12)) |
Toshi Kani | ad0d73b | 2018-05-09 16:20:30 -0600 | [diff] [blame] | 139 | dimm->mtype = MEM_NVDIMM; |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 140 | else if (entry->type_detail & BIT(13)) |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 141 | dimm->mtype = MEM_RDDR3; |
| 142 | else |
| 143 | dimm->mtype = MEM_DDR3; |
| 144 | break; |
Toshi Kani | ad0d73b | 2018-05-09 16:20:30 -0600 | [diff] [blame] | 145 | case 0x1a: |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 146 | if (entry->type_detail & BIT(12)) |
Toshi Kani | ad0d73b | 2018-05-09 16:20:30 -0600 | [diff] [blame] | 147 | dimm->mtype = MEM_NVDIMM; |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 148 | else if (entry->type_detail & BIT(13)) |
Toshi Kani | ad0d73b | 2018-05-09 16:20:30 -0600 | [diff] [blame] | 149 | dimm->mtype = MEM_RDDR4; |
| 150 | else |
| 151 | dimm->mtype = MEM_DDR4; |
| 152 | break; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 153 | default: |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 154 | if (entry->type_detail & BIT(6)) |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 155 | dimm->mtype = MEM_RMBS; |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 156 | else if ((entry->type_detail & rdr_mask) == rdr_mask) |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 157 | dimm->mtype = MEM_RDR; |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 158 | else if (entry->type_detail & BIT(7)) |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 159 | dimm->mtype = MEM_SDR; |
Borislav Petkov | a0671c3 | 2018-05-12 14:32:43 +0200 | [diff] [blame] | 160 | else if (entry->type_detail & BIT(9)) |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 161 | dimm->mtype = MEM_EDO; |
| 162 | else |
| 163 | dimm->mtype = MEM_UNKNOWN; |
| 164 | } |
| 165 | |
| 166 | /* |
| 167 | * Actually, we can only detect if the memory has bits for |
| 168 | * checksum or not |
| 169 | */ |
| 170 | if (entry->total_width == entry->data_width) |
| 171 | dimm->edac_mode = EDAC_NONE; |
| 172 | else |
| 173 | dimm->edac_mode = EDAC_SECDED; |
| 174 | |
| 175 | dimm->dtype = DEV_UNKNOWN; |
| 176 | dimm->grain = 128; /* Likely, worse case */ |
| 177 | |
| 178 | /* |
| 179 | * FIXME: It shouldn't be hard to also fill the DIMM labels |
| 180 | */ |
| 181 | |
| 182 | if (dimm->nr_pages) { |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 183 | edac_dbg(1, "DIMM%i: %s size = %d MB%s\n", |
Aravind Gopalakrishnan | 58a9c25 | 2015-09-16 15:53:29 -0500 | [diff] [blame] | 184 | dimm_fill->count, edac_mem_types[dimm->mtype], |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 185 | PAGES_TO_MiB(dimm->nr_pages), |
| 186 | (dimm->edac_mode != EDAC_NONE) ? "(ECC)" : ""); |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 187 | 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] | 188 | entry->memory_type, entry->type_detail, |
| 189 | entry->total_width, entry->data_width); |
| 190 | } |
| 191 | |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 192 | dimm->smbios_handle = entry->handle; |
| 193 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 194 | dimm_fill->count++; |
| 195 | } |
| 196 | } |
| 197 | |
Alexandru Gagniuc | 305d0e0 | 2018-04-30 16:33:50 -0500 | [diff] [blame] | 198 | void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err) |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 199 | { |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 200 | enum hw_event_mc_err_type type; |
| 201 | struct edac_raw_error_desc *e; |
| 202 | struct mem_ctl_info *mci; |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 203 | struct ghes_edac_pvt *pvt = ghes_pvt; |
| 204 | unsigned long flags; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 205 | char *p; |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 206 | u8 grain_bits; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 207 | |
Borislav Petkov | cc7f3f1 | 2018-04-23 14:16:46 +0200 | [diff] [blame] | 208 | if (!pvt) |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 209 | return; |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 210 | |
| 211 | /* |
| 212 | * We can do the locking below because GHES defers error processing |
| 213 | * from NMI to IRQ context. Whenever that changes, we'd at least |
| 214 | * know. |
| 215 | */ |
| 216 | if (WARN_ON_ONCE(in_nmi())) |
| 217 | return; |
| 218 | |
| 219 | spin_lock_irqsave(&ghes_lock, flags); |
| 220 | |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 221 | mci = pvt->mci; |
| 222 | e = &mci->error_desc; |
| 223 | |
| 224 | /* Cleans the error report buffer */ |
| 225 | memset(e, 0, sizeof (*e)); |
| 226 | e->error_count = 1; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 227 | strcpy(e->label, "unknown label"); |
| 228 | e->msg = pvt->msg; |
| 229 | e->other_detail = pvt->other_detail; |
| 230 | e->top_layer = -1; |
| 231 | e->mid_layer = -1; |
| 232 | e->low_layer = -1; |
| 233 | *pvt->other_detail = '\0'; |
| 234 | *pvt->msg = '\0'; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 235 | |
| 236 | switch (sev) { |
| 237 | case GHES_SEV_CORRECTED: |
| 238 | type = HW_EVENT_ERR_CORRECTED; |
| 239 | break; |
| 240 | case GHES_SEV_RECOVERABLE: |
| 241 | type = HW_EVENT_ERR_UNCORRECTED; |
| 242 | break; |
| 243 | case GHES_SEV_PANIC: |
| 244 | type = HW_EVENT_ERR_FATAL; |
| 245 | break; |
| 246 | default: |
| 247 | case GHES_SEV_NO: |
| 248 | type = HW_EVENT_ERR_INFO; |
| 249 | } |
| 250 | |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 251 | edac_dbg(1, "error validation_bits: 0x%08llx\n", |
| 252 | (long long)mem_err->validation_bits); |
| 253 | |
| 254 | /* Error type, mapped on e->msg */ |
| 255 | if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_TYPE) { |
| 256 | p = pvt->msg; |
| 257 | switch (mem_err->error_type) { |
| 258 | case 0: |
| 259 | p += sprintf(p, "Unknown"); |
| 260 | break; |
| 261 | case 1: |
| 262 | p += sprintf(p, "No error"); |
| 263 | break; |
| 264 | case 2: |
| 265 | p += sprintf(p, "Single-bit ECC"); |
| 266 | break; |
| 267 | case 3: |
| 268 | p += sprintf(p, "Multi-bit ECC"); |
| 269 | break; |
| 270 | case 4: |
| 271 | p += sprintf(p, "Single-symbol ChipKill ECC"); |
| 272 | break; |
| 273 | case 5: |
| 274 | p += sprintf(p, "Multi-symbol ChipKill ECC"); |
| 275 | break; |
| 276 | case 6: |
| 277 | p += sprintf(p, "Master abort"); |
| 278 | break; |
| 279 | case 7: |
| 280 | p += sprintf(p, "Target abort"); |
| 281 | break; |
| 282 | case 8: |
| 283 | p += sprintf(p, "Parity Error"); |
| 284 | break; |
| 285 | case 9: |
| 286 | p += sprintf(p, "Watchdog timeout"); |
| 287 | break; |
| 288 | case 10: |
| 289 | p += sprintf(p, "Invalid address"); |
| 290 | break; |
| 291 | case 11: |
| 292 | p += sprintf(p, "Mirror Broken"); |
| 293 | break; |
| 294 | case 12: |
| 295 | p += sprintf(p, "Memory Sparing"); |
| 296 | break; |
| 297 | case 13: |
| 298 | p += sprintf(p, "Scrub corrected error"); |
| 299 | break; |
| 300 | case 14: |
| 301 | p += sprintf(p, "Scrub uncorrected error"); |
| 302 | break; |
| 303 | case 15: |
| 304 | p += sprintf(p, "Physical Memory Map-out event"); |
| 305 | break; |
| 306 | default: |
| 307 | p += sprintf(p, "reserved error (%d)", |
| 308 | mem_err->error_type); |
| 309 | } |
| 310 | } else { |
| 311 | strcpy(pvt->msg, "unknown error"); |
| 312 | } |
| 313 | |
| 314 | /* Error address */ |
Chen, Gong | 147de14 | 2013-10-18 14:30:13 -0700 | [diff] [blame] | 315 | if (mem_err->validation_bits & CPER_MEM_VALID_PA) { |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 316 | e->page_frame_number = mem_err->physical_addr >> PAGE_SHIFT; |
| 317 | e->offset_in_page = mem_err->physical_addr & ~PAGE_MASK; |
| 318 | } |
| 319 | |
| 320 | /* Error grain */ |
Chen, Gong | 147de14 | 2013-10-18 14:30:13 -0700 | [diff] [blame] | 321 | if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK) |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 322 | e->grain = ~(mem_err->physical_addr_mask & ~PAGE_MASK); |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 323 | |
| 324 | /* Memory error location, mapped on e->location */ |
| 325 | p = e->location; |
| 326 | if (mem_err->validation_bits & CPER_MEM_VALID_NODE) |
| 327 | p += sprintf(p, "node:%d ", mem_err->node); |
| 328 | if (mem_err->validation_bits & CPER_MEM_VALID_CARD) |
| 329 | p += sprintf(p, "card:%d ", mem_err->card); |
| 330 | if (mem_err->validation_bits & CPER_MEM_VALID_MODULE) |
| 331 | p += sprintf(p, "module:%d ", mem_err->module); |
Chen, Gong | 5650769 | 2013-10-18 14:30:38 -0700 | [diff] [blame] | 332 | if (mem_err->validation_bits & CPER_MEM_VALID_RANK_NUMBER) |
| 333 | p += sprintf(p, "rank:%d ", mem_err->rank); |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 334 | if (mem_err->validation_bits & CPER_MEM_VALID_BANK) |
| 335 | p += sprintf(p, "bank:%d ", mem_err->bank); |
| 336 | if (mem_err->validation_bits & CPER_MEM_VALID_ROW) |
| 337 | p += sprintf(p, "row:%d ", mem_err->row); |
| 338 | if (mem_err->validation_bits & CPER_MEM_VALID_COLUMN) |
| 339 | p += sprintf(p, "col:%d ", mem_err->column); |
| 340 | if (mem_err->validation_bits & CPER_MEM_VALID_BIT_POSITION) |
| 341 | p += sprintf(p, "bit_pos:%d ", mem_err->bit_pos); |
Chen, Gong | 5650769 | 2013-10-18 14:30:38 -0700 | [diff] [blame] | 342 | if (mem_err->validation_bits & CPER_MEM_VALID_MODULE_HANDLE) { |
| 343 | const char *bank = NULL, *device = NULL; |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 344 | int index = -1; |
| 345 | |
Chen, Gong | 5650769 | 2013-10-18 14:30:38 -0700 | [diff] [blame] | 346 | dmi_memdev_name(mem_err->mem_dev_handle, &bank, &device); |
| 347 | if (bank != NULL && device != NULL) |
| 348 | p += sprintf(p, "DIMM location:%s %s ", bank, device); |
| 349 | else |
| 350 | p += sprintf(p, "DIMM DMI handle: 0x%.4x ", |
| 351 | mem_err->mem_dev_handle); |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 352 | |
| 353 | index = get_dimm_smbios_index(mem_err->mem_dev_handle); |
| 354 | if (index >= 0) { |
| 355 | e->top_layer = index; |
| 356 | e->enable_per_layer_report = true; |
| 357 | } |
| 358 | |
Chen, Gong | 5650769 | 2013-10-18 14:30:38 -0700 | [diff] [blame] | 359 | } |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 360 | if (p > e->location) |
| 361 | *(p - 1) = '\0'; |
| 362 | |
| 363 | /* All other fields are mapped on e->other_detail */ |
| 364 | p = pvt->other_detail; |
| 365 | if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_STATUS) { |
| 366 | u64 status = mem_err->error_status; |
| 367 | |
| 368 | p += sprintf(p, "status(0x%016llx): ", (long long)status); |
| 369 | switch ((status >> 8) & 0xff) { |
| 370 | case 1: |
| 371 | p += sprintf(p, "Error detected internal to the component "); |
| 372 | break; |
| 373 | case 16: |
| 374 | p += sprintf(p, "Error detected in the bus "); |
| 375 | break; |
| 376 | case 4: |
| 377 | p += sprintf(p, "Storage error in DRAM memory "); |
| 378 | break; |
| 379 | case 5: |
| 380 | p += sprintf(p, "Storage error in TLB "); |
| 381 | break; |
| 382 | case 6: |
| 383 | p += sprintf(p, "Storage error in cache "); |
| 384 | break; |
| 385 | case 7: |
| 386 | p += sprintf(p, "Error in one or more functional units "); |
| 387 | break; |
| 388 | case 8: |
| 389 | p += sprintf(p, "component failed self test "); |
| 390 | break; |
| 391 | case 9: |
| 392 | p += sprintf(p, "Overflow or undervalue of internal queue "); |
| 393 | break; |
| 394 | case 17: |
| 395 | p += sprintf(p, "Virtual address not found on IO-TLB or IO-PDIR "); |
| 396 | break; |
| 397 | case 18: |
| 398 | p += sprintf(p, "Improper access error "); |
| 399 | break; |
| 400 | case 19: |
| 401 | p += sprintf(p, "Access to a memory address which is not mapped to any component "); |
| 402 | break; |
| 403 | case 20: |
| 404 | p += sprintf(p, "Loss of Lockstep "); |
| 405 | break; |
| 406 | case 21: |
| 407 | p += sprintf(p, "Response not associated with a request "); |
| 408 | break; |
| 409 | case 22: |
| 410 | p += sprintf(p, "Bus parity error - must also set the A, C, or D Bits "); |
| 411 | break; |
| 412 | case 23: |
| 413 | p += sprintf(p, "Detection of a PATH_ERROR "); |
| 414 | break; |
| 415 | case 25: |
| 416 | p += sprintf(p, "Bus operation timeout "); |
| 417 | break; |
| 418 | case 26: |
| 419 | p += sprintf(p, "A read was issued to data that has been poisoned "); |
| 420 | break; |
| 421 | default: |
| 422 | p += sprintf(p, "reserved "); |
| 423 | break; |
| 424 | } |
| 425 | } |
| 426 | if (mem_err->validation_bits & CPER_MEM_VALID_REQUESTOR_ID) |
| 427 | p += sprintf(p, "requestorID: 0x%016llx ", |
| 428 | (long long)mem_err->requestor_id); |
| 429 | if (mem_err->validation_bits & CPER_MEM_VALID_RESPONDER_ID) |
| 430 | p += sprintf(p, "responderID: 0x%016llx ", |
| 431 | (long long)mem_err->responder_id); |
| 432 | if (mem_err->validation_bits & CPER_MEM_VALID_TARGET_ID) |
| 433 | p += sprintf(p, "targetID: 0x%016llx ", |
| 434 | (long long)mem_err->responder_id); |
| 435 | if (p > pvt->other_detail) |
| 436 | *(p - 1) = '\0'; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 437 | |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 438 | /* Generate the trace event */ |
| 439 | grain_bits = fls_long(e->grain); |
Dan Carpenter | 665aa8c | 2014-08-01 11:25:14 +0300 | [diff] [blame] | 440 | snprintf(pvt->detail_location, sizeof(pvt->detail_location), |
| 441 | "APEI location: %s %s", e->location, e->other_detail); |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 442 | trace_mc_event(type, e->msg, e->label, e->error_count, |
| 443 | mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer, |
Tan Xiaojun | 990995b | 2015-10-20 19:45:38 +0800 | [diff] [blame] | 444 | (e->page_frame_number << PAGE_SHIFT) | e->offset_in_page, |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 445 | grain_bits, e->syndrome, pvt->detail_location); |
| 446 | |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 447 | edac_raw_mc_handle_error(type, mci, e); |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 448 | spin_unlock_irqrestore(&ghes_lock, flags); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 449 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 450 | |
Toshi Kani | 5deed6b | 2017-08-23 16:54:45 -0600 | [diff] [blame] | 451 | /* |
| 452 | * Known systems that are safe to enable this module. |
| 453 | */ |
| 454 | static struct acpi_platform_list plat_list[] = { |
| 455 | {"HPE ", "Server ", 0, ACPI_SIG_FADT, all_versions}, |
| 456 | { } /* End */ |
| 457 | }; |
| 458 | |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 459 | int ghes_edac_register(struct ghes *ghes, struct device *dev) |
| 460 | { |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 461 | bool fake = false; |
| 462 | int rc, num_dimm = 0; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 463 | struct mem_ctl_info *mci; |
| 464 | struct edac_mc_layer layers[1]; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 465 | struct ghes_edac_dimm_fill dimm_fill; |
Borislav Petkov | eaa3a1d | 2018-05-18 13:13:31 +0200 | [diff] [blame] | 466 | int idx = -1; |
Toshi Kani | 5deed6b | 2017-08-23 16:54:45 -0600 | [diff] [blame] | 467 | |
Borislav Petkov | eaa3a1d | 2018-05-18 13:13:31 +0200 | [diff] [blame] | 468 | if (IS_ENABLED(CONFIG_X86)) { |
| 469 | /* Check if safe to enable on this system */ |
| 470 | idx = acpi_match_platform_list(plat_list); |
| 471 | if (!force_load && idx < 0) |
| 472 | return -ENODEV; |
| 473 | } else { |
| 474 | idx = 0; |
| 475 | } |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 476 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 477 | /* |
| 478 | * We have only one logical memory controller to which all DIMMs belong. |
| 479 | */ |
| 480 | if (atomic_inc_return(&ghes_init) > 1) |
| 481 | return 0; |
| 482 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 483 | /* Get the number of DIMMs */ |
| 484 | dmi_walk(ghes_edac_count_dimms, &num_dimm); |
| 485 | |
| 486 | /* Check if we've got a bogus BIOS */ |
| 487 | if (num_dimm == 0) { |
| 488 | fake = true; |
| 489 | num_dimm = 1; |
| 490 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 491 | |
| 492 | layers[0].type = EDAC_MC_LAYER_ALL_MEM; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 493 | layers[0].size = num_dimm; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 494 | layers[0].is_virt_csrow = true; |
| 495 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 496 | mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(struct ghes_edac_pvt)); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 497 | if (!mci) { |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 498 | pr_info("Can't allocate memory for EDAC data\n"); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 499 | return -ENOMEM; |
| 500 | } |
| 501 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 502 | ghes_pvt = mci->pvt_info; |
| 503 | ghes_pvt->ghes = ghes; |
| 504 | ghes_pvt->mci = mci; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 505 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 506 | mci->pdev = dev; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 507 | mci->mtype_cap = MEM_FLAG_EMPTY; |
| 508 | mci->edac_ctl_cap = EDAC_FLAG_NONE; |
| 509 | mci->edac_cap = EDAC_FLAG_NONE; |
| 510 | mci->mod_name = "ghes_edac.c"; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 511 | mci->ctl_name = "ghes_edac"; |
| 512 | mci->dev_name = "ghes"; |
| 513 | |
Toshi Kani | 5deed6b | 2017-08-23 16:54:45 -0600 | [diff] [blame] | 514 | if (fake) { |
| 515 | pr_info("This system has a very crappy BIOS: It doesn't even list the DIMMS.\n"); |
| 516 | pr_info("Its SMBIOS info is wrong. It is doubtful that the error report would\n"); |
| 517 | pr_info("work on such system. Use this driver with caution\n"); |
| 518 | } else if (idx < 0) { |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 519 | pr_info("This EDAC driver relies on BIOS to enumerate memory and get error reports.\n"); |
| 520 | pr_info("Unfortunately, not all BIOSes reflect the memory layout correctly.\n"); |
| 521 | pr_info("So, the end result of using this driver varies from vendor to vendor.\n"); |
| 522 | pr_info("If you find incorrect reports, please contact your hardware vendor\n"); |
| 523 | pr_info("to correct its BIOS.\n"); |
| 524 | pr_info("This system has %d DIMM sockets.\n", num_dimm); |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 525 | } |
| 526 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 527 | if (!fake) { |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 528 | dimm_fill.count = 0; |
| 529 | dimm_fill.mci = mci; |
| 530 | dmi_walk(ghes_edac_dmidecode, &dimm_fill); |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 531 | } else { |
| 532 | struct dimm_info *dimm = EDAC_DIMM_PTR(mci->layers, mci->dimms, |
| 533 | mci->n_layers, 0, 0, 0); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 534 | |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 535 | dimm->nr_pages = 1; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 536 | dimm->grain = 128; |
| 537 | dimm->mtype = MEM_UNKNOWN; |
| 538 | dimm->dtype = DEV_UNKNOWN; |
| 539 | dimm->edac_mode = EDAC_SECDED; |
| 540 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 541 | |
| 542 | rc = edac_mc_add_mc(mci); |
| 543 | if (rc < 0) { |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 544 | pr_info("Can't register at EDAC core\n"); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 545 | edac_mc_free(mci); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 546 | return -ENODEV; |
| 547 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 548 | return 0; |
| 549 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 550 | |
| 551 | void ghes_edac_unregister(struct ghes *ghes) |
| 552 | { |
| 553 | struct mem_ctl_info *mci; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 554 | |
Sughosh Ganu | a66bdf5 | 2018-04-26 15:46:49 +0530 | [diff] [blame] | 555 | if (!ghes_pvt) |
| 556 | return; |
| 557 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 558 | mci = ghes_pvt->mci; |
| 559 | edac_mc_del_mc(mci->pdev); |
| 560 | edac_mc_free(mci); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 561 | } |