Thomas Gleixner | 1223755 | 2019-05-27 08:55:19 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 2 | /* |
| 3 | * GHES/EDAC Linux driver |
| 4 | * |
Mauro Carvalho Chehab | 37e59f8 | 2014-02-07 08:03:07 -0200 | [diff] [blame] | 5 | * Copyright (c) 2013 by Mauro Carvalho Chehab |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 6 | * |
| 7 | * Red Hat Inc. http://www.redhat.com |
| 8 | */ |
| 9 | |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 12 | #include <acpi/ghes.h> |
| 13 | #include <linux/edac.h> |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 14 | #include <linux/dmi.h> |
Mauro Carvalho Chehab | 78d88e8 | 2016-10-29 15:16:34 -0200 | [diff] [blame] | 15 | #include "edac_module.h" |
Mauro Carvalho Chehab | 8ae8f50 | 2013-02-19 21:35:41 -0300 | [diff] [blame] | 16 | #include <ras/ras_event.h> |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 17 | |
Robert Richter | b001694 | 2020-05-19 12:44:39 +0200 | [diff] [blame] | 18 | struct ghes_pvt { |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 19 | struct mem_ctl_info *mci; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 20 | |
| 21 | /* Buffers for the error handling routine */ |
Robert Richter | 501eb40 | 2019-11-06 09:33:25 +0000 | [diff] [blame] | 22 | char other_detail[400]; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 23 | char msg[80]; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 24 | }; |
| 25 | |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 26 | static refcount_t ghes_refcount = REFCOUNT_INIT(0); |
| 27 | |
| 28 | /* |
| 29 | * Access to ghes_pvt must be protected by ghes_lock. The spinlock |
| 30 | * also provides the necessary (implicit) memory barrier for the SMP |
| 31 | * case to make the pointer visible on another CPU. |
| 32 | */ |
Robert Richter | b001694 | 2020-05-19 12:44:39 +0200 | [diff] [blame] | 33 | static struct ghes_pvt *ghes_pvt; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 34 | |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 35 | /* |
| 36 | * This driver's representation of the system hardware, as collected |
| 37 | * from DMI. |
| 38 | */ |
| 39 | struct ghes_hw_desc { |
| 40 | int num_dimms; |
| 41 | struct dimm_info *dimms; |
| 42 | } ghes_hw; |
| 43 | |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 44 | /* GHES registration mutex */ |
| 45 | static DEFINE_MUTEX(ghes_reg_mutex); |
| 46 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 47 | /* |
| 48 | * Sync with other, potentially concurrent callers of |
| 49 | * ghes_edac_report_mem_error(). We don't know what the |
| 50 | * "inventive" firmware would do. |
| 51 | */ |
| 52 | static DEFINE_SPINLOCK(ghes_lock); |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 53 | |
Toshi Kani | 5deed6b | 2017-08-23 16:54:45 -0600 | [diff] [blame] | 54 | /* "ghes_edac.force_load=1" skips the platform check */ |
| 55 | static bool __read_mostly force_load; |
| 56 | module_param(force_load, bool, 0); |
| 57 | |
Shiju Jose | b972fdb | 2020-08-27 15:04:50 +0100 | [diff] [blame^] | 58 | static bool system_scanned; |
| 59 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 60 | /* Memory Device - Type 17 of SMBIOS spec */ |
| 61 | struct memdev_dmi_entry { |
| 62 | u8 type; |
| 63 | u8 length; |
| 64 | u16 handle; |
| 65 | u16 phys_mem_array_handle; |
| 66 | u16 mem_err_info_handle; |
| 67 | u16 total_width; |
| 68 | u16 data_width; |
| 69 | u16 size; |
| 70 | u8 form_factor; |
| 71 | u8 device_set; |
| 72 | u8 device_locator; |
| 73 | u8 bank_locator; |
| 74 | u8 memory_type; |
| 75 | u16 type_detail; |
| 76 | u16 speed; |
| 77 | u8 manufacturer; |
| 78 | u8 serial_number; |
| 79 | u8 asset_tag; |
| 80 | u8 part_number; |
| 81 | u8 attributes; |
| 82 | u32 extended_size; |
| 83 | u16 conf_mem_clk_speed; |
| 84 | } __attribute__((__packed__)); |
| 85 | |
Robert Richter | cb51a37 | 2020-05-28 12:13:06 +0200 | [diff] [blame] | 86 | static struct dimm_info *find_dimm_by_handle(struct mem_ctl_info *mci, u16 handle) |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 87 | { |
Robert Richter | c498afa | 2019-11-06 09:33:07 +0000 | [diff] [blame] | 88 | struct dimm_info *dimm; |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 89 | |
Robert Richter | c498afa | 2019-11-06 09:33:07 +0000 | [diff] [blame] | 90 | mci_for_each_dimm(mci, dimm) { |
| 91 | if (dimm->smbios_handle == handle) |
Robert Richter | cb51a37 | 2020-05-28 12:13:06 +0200 | [diff] [blame] | 92 | return dimm; |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 93 | } |
Robert Richter | c498afa | 2019-11-06 09:33:07 +0000 | [diff] [blame] | 94 | |
Robert Richter | cb51a37 | 2020-05-28 12:13:06 +0200 | [diff] [blame] | 95 | return NULL; |
| 96 | } |
| 97 | |
| 98 | static void dimm_setup_label(struct dimm_info *dimm, u16 handle) |
| 99 | { |
| 100 | const char *bank = NULL, *device = NULL; |
| 101 | |
| 102 | dmi_memdev_name(handle, &bank, &device); |
| 103 | |
| 104 | /* both strings must be non-zero */ |
| 105 | if (bank && *bank && device && *device) |
| 106 | snprintf(dimm->label, sizeof(dimm->label), "%s %s", bank, device); |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 109 | static void assign_dmi_dimm_info(struct dimm_info *dimm, struct memdev_dmi_entry *entry) |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 110 | { |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 111 | u16 rdr_mask = BIT(7) | BIT(13); |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 112 | |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 113 | if (entry->size == 0xffff) { |
| 114 | pr_info("Can't get DIMM%i size\n", dimm->idx); |
| 115 | dimm->nr_pages = MiB_TO_PAGES(32);/* Unknown */ |
| 116 | } else if (entry->size == 0x7fff) { |
| 117 | dimm->nr_pages = MiB_TO_PAGES(entry->extended_size); |
| 118 | } else { |
| 119 | if (entry->size & BIT(15)) |
| 120 | dimm->nr_pages = MiB_TO_PAGES((entry->size & 0x7fff) << 10); |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 121 | else |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 122 | dimm->nr_pages = MiB_TO_PAGES(entry->size); |
| 123 | } |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 124 | |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 125 | switch (entry->memory_type) { |
| 126 | case 0x12: |
| 127 | if (entry->type_detail & BIT(13)) |
| 128 | dimm->mtype = MEM_RDDR; |
| 129 | else |
| 130 | dimm->mtype = MEM_DDR; |
| 131 | break; |
| 132 | case 0x13: |
| 133 | if (entry->type_detail & BIT(13)) |
| 134 | dimm->mtype = MEM_RDDR2; |
| 135 | else |
| 136 | dimm->mtype = MEM_DDR2; |
| 137 | break; |
| 138 | case 0x14: |
| 139 | dimm->mtype = MEM_FB_DDR2; |
| 140 | break; |
| 141 | case 0x18: |
| 142 | if (entry->type_detail & BIT(12)) |
| 143 | dimm->mtype = MEM_NVDIMM; |
| 144 | else if (entry->type_detail & BIT(13)) |
| 145 | dimm->mtype = MEM_RDDR3; |
| 146 | else |
| 147 | dimm->mtype = MEM_DDR3; |
| 148 | break; |
| 149 | case 0x1a: |
| 150 | if (entry->type_detail & BIT(12)) |
| 151 | dimm->mtype = MEM_NVDIMM; |
| 152 | else if (entry->type_detail & BIT(13)) |
| 153 | dimm->mtype = MEM_RDDR4; |
| 154 | else |
| 155 | dimm->mtype = MEM_DDR4; |
| 156 | break; |
| 157 | default: |
| 158 | if (entry->type_detail & BIT(6)) |
| 159 | dimm->mtype = MEM_RMBS; |
| 160 | else if ((entry->type_detail & rdr_mask) == rdr_mask) |
| 161 | dimm->mtype = MEM_RDR; |
| 162 | else if (entry->type_detail & BIT(7)) |
| 163 | dimm->mtype = MEM_SDR; |
| 164 | else if (entry->type_detail & BIT(9)) |
| 165 | dimm->mtype = MEM_EDO; |
| 166 | else |
| 167 | dimm->mtype = MEM_UNKNOWN; |
| 168 | } |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 169 | |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 170 | /* |
| 171 | * Actually, we can only detect if the memory has bits for |
| 172 | * checksum or not |
| 173 | */ |
| 174 | if (entry->total_width == entry->data_width) |
| 175 | dimm->edac_mode = EDAC_NONE; |
| 176 | else |
| 177 | dimm->edac_mode = EDAC_SECDED; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 178 | |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 179 | dimm->dtype = DEV_UNKNOWN; |
| 180 | dimm->grain = 128; /* Likely, worse case */ |
| 181 | |
| 182 | dimm_setup_label(dimm, entry->handle); |
| 183 | |
| 184 | if (dimm->nr_pages) { |
| 185 | edac_dbg(1, "DIMM%i: %s size = %d MB%s\n", |
| 186 | dimm->idx, edac_mem_types[dimm->mtype], |
| 187 | PAGES_TO_MiB(dimm->nr_pages), |
| 188 | (dimm->edac_mode != EDAC_NONE) ? "(ECC)" : ""); |
| 189 | edac_dbg(2, "\ttype %d, detail 0x%02x, width %d(total %d)\n", |
| 190 | entry->memory_type, entry->type_detail, |
| 191 | entry->total_width, entry->data_width); |
| 192 | } |
| 193 | |
| 194 | dimm->smbios_handle = entry->handle; |
| 195 | } |
| 196 | |
| 197 | static void enumerate_dimms(const struct dmi_header *dh, void *arg) |
| 198 | { |
| 199 | struct memdev_dmi_entry *entry = (struct memdev_dmi_entry *)dh; |
| 200 | struct ghes_hw_desc *hw = (struct ghes_hw_desc *)arg; |
| 201 | struct dimm_info *d; |
| 202 | |
| 203 | if (dh->type != DMI_ENTRY_MEM_DEVICE) |
| 204 | return; |
| 205 | |
| 206 | /* Enlarge the array with additional 16 */ |
| 207 | if (!hw->num_dimms || !(hw->num_dimms % 16)) { |
| 208 | struct dimm_info *new; |
| 209 | |
| 210 | new = krealloc(hw->dimms, (hw->num_dimms + 16) * sizeof(struct dimm_info), |
| 211 | GFP_KERNEL); |
| 212 | if (!new) { |
| 213 | WARN_ON_ONCE(1); |
| 214 | return; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 215 | } |
| 216 | |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 217 | hw->dimms = new; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 218 | } |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 219 | |
| 220 | d = &hw->dimms[hw->num_dimms]; |
| 221 | d->idx = hw->num_dimms; |
| 222 | |
| 223 | assign_dmi_dimm_info(d, entry); |
| 224 | |
| 225 | hw->num_dimms++; |
| 226 | } |
| 227 | |
| 228 | static void ghes_scan_system(void) |
| 229 | { |
Shiju Jose | b972fdb | 2020-08-27 15:04:50 +0100 | [diff] [blame^] | 230 | if (system_scanned) |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 231 | return; |
| 232 | |
| 233 | dmi_walk(enumerate_dimms, &ghes_hw); |
| 234 | |
Shiju Jose | b972fdb | 2020-08-27 15:04:50 +0100 | [diff] [blame^] | 235 | system_scanned = true; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 236 | } |
| 237 | |
Alexandru Gagniuc | 305d0e0 | 2018-04-30 16:33:50 -0500 | [diff] [blame] | 238 | 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] | 239 | { |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 240 | struct edac_raw_error_desc *e; |
| 241 | struct mem_ctl_info *mci; |
Robert Richter | b001694 | 2020-05-19 12:44:39 +0200 | [diff] [blame] | 242 | struct ghes_pvt *pvt; |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 243 | unsigned long flags; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 244 | char *p; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 245 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 246 | /* |
| 247 | * We can do the locking below because GHES defers error processing |
| 248 | * from NMI to IRQ context. Whenever that changes, we'd at least |
| 249 | * know. |
| 250 | */ |
| 251 | if (WARN_ON_ONCE(in_nmi())) |
| 252 | return; |
| 253 | |
| 254 | spin_lock_irqsave(&ghes_lock, flags); |
| 255 | |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 256 | pvt = ghes_pvt; |
| 257 | if (!pvt) |
| 258 | goto unlock; |
| 259 | |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 260 | mci = pvt->mci; |
| 261 | e = &mci->error_desc; |
| 262 | |
| 263 | /* Cleans the error report buffer */ |
| 264 | memset(e, 0, sizeof (*e)); |
| 265 | e->error_count = 1; |
Robert Richter | 7088e29 | 2019-11-06 09:33:23 +0000 | [diff] [blame] | 266 | e->grain = 1; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 267 | e->msg = pvt->msg; |
| 268 | e->other_detail = pvt->other_detail; |
| 269 | e->top_layer = -1; |
| 270 | e->mid_layer = -1; |
| 271 | e->low_layer = -1; |
| 272 | *pvt->other_detail = '\0'; |
| 273 | *pvt->msg = '\0'; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 274 | |
| 275 | switch (sev) { |
| 276 | case GHES_SEV_CORRECTED: |
Robert Richter | 672ef0e | 2020-01-23 09:02:54 +0000 | [diff] [blame] | 277 | e->type = HW_EVENT_ERR_CORRECTED; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 278 | break; |
| 279 | case GHES_SEV_RECOVERABLE: |
Robert Richter | 672ef0e | 2020-01-23 09:02:54 +0000 | [diff] [blame] | 280 | e->type = HW_EVENT_ERR_UNCORRECTED; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 281 | break; |
| 282 | case GHES_SEV_PANIC: |
Robert Richter | 672ef0e | 2020-01-23 09:02:54 +0000 | [diff] [blame] | 283 | e->type = HW_EVENT_ERR_FATAL; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 284 | break; |
| 285 | default: |
| 286 | case GHES_SEV_NO: |
Robert Richter | 672ef0e | 2020-01-23 09:02:54 +0000 | [diff] [blame] | 287 | e->type = HW_EVENT_ERR_INFO; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 288 | } |
| 289 | |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 290 | edac_dbg(1, "error validation_bits: 0x%08llx\n", |
| 291 | (long long)mem_err->validation_bits); |
| 292 | |
| 293 | /* Error type, mapped on e->msg */ |
| 294 | if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_TYPE) { |
| 295 | p = pvt->msg; |
| 296 | switch (mem_err->error_type) { |
| 297 | case 0: |
| 298 | p += sprintf(p, "Unknown"); |
| 299 | break; |
| 300 | case 1: |
| 301 | p += sprintf(p, "No error"); |
| 302 | break; |
| 303 | case 2: |
| 304 | p += sprintf(p, "Single-bit ECC"); |
| 305 | break; |
| 306 | case 3: |
| 307 | p += sprintf(p, "Multi-bit ECC"); |
| 308 | break; |
| 309 | case 4: |
| 310 | p += sprintf(p, "Single-symbol ChipKill ECC"); |
| 311 | break; |
| 312 | case 5: |
| 313 | p += sprintf(p, "Multi-symbol ChipKill ECC"); |
| 314 | break; |
| 315 | case 6: |
| 316 | p += sprintf(p, "Master abort"); |
| 317 | break; |
| 318 | case 7: |
| 319 | p += sprintf(p, "Target abort"); |
| 320 | break; |
| 321 | case 8: |
| 322 | p += sprintf(p, "Parity Error"); |
| 323 | break; |
| 324 | case 9: |
| 325 | p += sprintf(p, "Watchdog timeout"); |
| 326 | break; |
| 327 | case 10: |
| 328 | p += sprintf(p, "Invalid address"); |
| 329 | break; |
| 330 | case 11: |
| 331 | p += sprintf(p, "Mirror Broken"); |
| 332 | break; |
| 333 | case 12: |
| 334 | p += sprintf(p, "Memory Sparing"); |
| 335 | break; |
| 336 | case 13: |
| 337 | p += sprintf(p, "Scrub corrected error"); |
| 338 | break; |
| 339 | case 14: |
| 340 | p += sprintf(p, "Scrub uncorrected error"); |
| 341 | break; |
| 342 | case 15: |
| 343 | p += sprintf(p, "Physical Memory Map-out event"); |
| 344 | break; |
| 345 | default: |
| 346 | p += sprintf(p, "reserved error (%d)", |
| 347 | mem_err->error_type); |
| 348 | } |
| 349 | } else { |
| 350 | strcpy(pvt->msg, "unknown error"); |
| 351 | } |
| 352 | |
| 353 | /* Error address */ |
Chen, Gong | 147de14 | 2013-10-18 14:30:13 -0700 | [diff] [blame] | 354 | if (mem_err->validation_bits & CPER_MEM_VALID_PA) { |
Robert Richter | 7c10493 | 2019-11-06 09:33:20 +0000 | [diff] [blame] | 355 | e->page_frame_number = PHYS_PFN(mem_err->physical_addr); |
| 356 | e->offset_in_page = offset_in_page(mem_err->physical_addr); |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /* Error grain */ |
Chen, Gong | 147de14 | 2013-10-18 14:30:13 -0700 | [diff] [blame] | 360 | if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK) |
Robert Richter | 7088e29 | 2019-11-06 09:33:23 +0000 | [diff] [blame] | 361 | e->grain = ~mem_err->physical_addr_mask + 1; |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 362 | |
| 363 | /* Memory error location, mapped on e->location */ |
| 364 | p = e->location; |
| 365 | if (mem_err->validation_bits & CPER_MEM_VALID_NODE) |
| 366 | p += sprintf(p, "node:%d ", mem_err->node); |
| 367 | if (mem_err->validation_bits & CPER_MEM_VALID_CARD) |
| 368 | p += sprintf(p, "card:%d ", mem_err->card); |
| 369 | if (mem_err->validation_bits & CPER_MEM_VALID_MODULE) |
| 370 | p += sprintf(p, "module:%d ", mem_err->module); |
Chen, Gong | 5650769 | 2013-10-18 14:30:38 -0700 | [diff] [blame] | 371 | if (mem_err->validation_bits & CPER_MEM_VALID_RANK_NUMBER) |
| 372 | p += sprintf(p, "rank:%d ", mem_err->rank); |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 373 | if (mem_err->validation_bits & CPER_MEM_VALID_BANK) |
| 374 | p += sprintf(p, "bank:%d ", mem_err->bank); |
| 375 | if (mem_err->validation_bits & CPER_MEM_VALID_ROW) |
| 376 | p += sprintf(p, "row:%d ", mem_err->row); |
| 377 | if (mem_err->validation_bits & CPER_MEM_VALID_COLUMN) |
| 378 | p += sprintf(p, "col:%d ", mem_err->column); |
| 379 | if (mem_err->validation_bits & CPER_MEM_VALID_BIT_POSITION) |
| 380 | p += sprintf(p, "bit_pos:%d ", mem_err->bit_pos); |
Chen, Gong | 5650769 | 2013-10-18 14:30:38 -0700 | [diff] [blame] | 381 | if (mem_err->validation_bits & CPER_MEM_VALID_MODULE_HANDLE) { |
| 382 | const char *bank = NULL, *device = NULL; |
Robert Richter | cb51a37 | 2020-05-28 12:13:06 +0200 | [diff] [blame] | 383 | struct dimm_info *dimm; |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 384 | |
Chen, Gong | 5650769 | 2013-10-18 14:30:38 -0700 | [diff] [blame] | 385 | dmi_memdev_name(mem_err->mem_dev_handle, &bank, &device); |
| 386 | if (bank != NULL && device != NULL) |
| 387 | p += sprintf(p, "DIMM location:%s %s ", bank, device); |
| 388 | else |
| 389 | p += sprintf(p, "DIMM DMI handle: 0x%.4x ", |
| 390 | mem_err->mem_dev_handle); |
Fan Wu | c798c88 | 2018-09-19 01:59:00 +0000 | [diff] [blame] | 391 | |
Robert Richter | cb51a37 | 2020-05-28 12:13:06 +0200 | [diff] [blame] | 392 | dimm = find_dimm_by_handle(mci, mem_err->mem_dev_handle); |
| 393 | if (dimm) { |
| 394 | e->top_layer = dimm->idx; |
| 395 | strcpy(e->label, dimm->label); |
| 396 | } |
Chen, Gong | 5650769 | 2013-10-18 14:30:38 -0700 | [diff] [blame] | 397 | } |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 398 | if (p > e->location) |
| 399 | *(p - 1) = '\0'; |
| 400 | |
Robert Richter | cb51a37 | 2020-05-28 12:13:06 +0200 | [diff] [blame] | 401 | if (!*e->label) |
| 402 | strcpy(e->label, "unknown memory"); |
| 403 | |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 404 | /* All other fields are mapped on e->other_detail */ |
| 405 | p = pvt->other_detail; |
Robert Richter | 501eb40 | 2019-11-06 09:33:25 +0000 | [diff] [blame] | 406 | p += snprintf(p, sizeof(pvt->other_detail), |
| 407 | "APEI location: %s ", e->location); |
Mauro Carvalho Chehab | 689c9cd | 2013-02-19 19:24:12 -0300 | [diff] [blame] | 408 | if (mem_err->validation_bits & CPER_MEM_VALID_ERROR_STATUS) { |
| 409 | u64 status = mem_err->error_status; |
| 410 | |
| 411 | p += sprintf(p, "status(0x%016llx): ", (long long)status); |
| 412 | switch ((status >> 8) & 0xff) { |
| 413 | case 1: |
| 414 | p += sprintf(p, "Error detected internal to the component "); |
| 415 | break; |
| 416 | case 16: |
| 417 | p += sprintf(p, "Error detected in the bus "); |
| 418 | break; |
| 419 | case 4: |
| 420 | p += sprintf(p, "Storage error in DRAM memory "); |
| 421 | break; |
| 422 | case 5: |
| 423 | p += sprintf(p, "Storage error in TLB "); |
| 424 | break; |
| 425 | case 6: |
| 426 | p += sprintf(p, "Storage error in cache "); |
| 427 | break; |
| 428 | case 7: |
| 429 | p += sprintf(p, "Error in one or more functional units "); |
| 430 | break; |
| 431 | case 8: |
| 432 | p += sprintf(p, "component failed self test "); |
| 433 | break; |
| 434 | case 9: |
| 435 | p += sprintf(p, "Overflow or undervalue of internal queue "); |
| 436 | break; |
| 437 | case 17: |
| 438 | p += sprintf(p, "Virtual address not found on IO-TLB or IO-PDIR "); |
| 439 | break; |
| 440 | case 18: |
| 441 | p += sprintf(p, "Improper access error "); |
| 442 | break; |
| 443 | case 19: |
| 444 | p += sprintf(p, "Access to a memory address which is not mapped to any component "); |
| 445 | break; |
| 446 | case 20: |
| 447 | p += sprintf(p, "Loss of Lockstep "); |
| 448 | break; |
| 449 | case 21: |
| 450 | p += sprintf(p, "Response not associated with a request "); |
| 451 | break; |
| 452 | case 22: |
| 453 | p += sprintf(p, "Bus parity error - must also set the A, C, or D Bits "); |
| 454 | break; |
| 455 | case 23: |
| 456 | p += sprintf(p, "Detection of a PATH_ERROR "); |
| 457 | break; |
| 458 | case 25: |
| 459 | p += sprintf(p, "Bus operation timeout "); |
| 460 | break; |
| 461 | case 26: |
| 462 | p += sprintf(p, "A read was issued to data that has been poisoned "); |
| 463 | break; |
| 464 | default: |
| 465 | p += sprintf(p, "reserved "); |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | if (mem_err->validation_bits & CPER_MEM_VALID_REQUESTOR_ID) |
| 470 | p += sprintf(p, "requestorID: 0x%016llx ", |
| 471 | (long long)mem_err->requestor_id); |
| 472 | if (mem_err->validation_bits & CPER_MEM_VALID_RESPONDER_ID) |
| 473 | p += sprintf(p, "responderID: 0x%016llx ", |
| 474 | (long long)mem_err->responder_id); |
| 475 | if (mem_err->validation_bits & CPER_MEM_VALID_TARGET_ID) |
| 476 | p += sprintf(p, "targetID: 0x%016llx ", |
| 477 | (long long)mem_err->responder_id); |
| 478 | if (p > pvt->other_detail) |
| 479 | *(p - 1) = '\0'; |
Mauro Carvalho Chehab | f04c62a | 2013-02-15 06:36:27 -0300 | [diff] [blame] | 480 | |
Robert Richter | 91b327f | 2020-01-23 09:02:56 +0000 | [diff] [blame] | 481 | edac_raw_mc_handle_error(e); |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 482 | |
| 483 | unlock: |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 484 | spin_unlock_irqrestore(&ghes_lock, flags); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 485 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 486 | |
Toshi Kani | 5deed6b | 2017-08-23 16:54:45 -0600 | [diff] [blame] | 487 | /* |
| 488 | * Known systems that are safe to enable this module. |
| 489 | */ |
| 490 | static struct acpi_platform_list plat_list[] = { |
| 491 | {"HPE ", "Server ", 0, ACPI_SIG_FADT, all_versions}, |
| 492 | { } /* End */ |
| 493 | }; |
| 494 | |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 495 | int ghes_edac_register(struct ghes *ghes, struct device *dev) |
| 496 | { |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 497 | bool fake = false; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 498 | struct mem_ctl_info *mci; |
Robert Richter | b001694 | 2020-05-19 12:44:39 +0200 | [diff] [blame] | 499 | struct ghes_pvt *pvt; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 500 | struct edac_mc_layer layers[1]; |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 501 | unsigned long flags; |
Borislav Petkov | eaa3a1d | 2018-05-18 13:13:31 +0200 | [diff] [blame] | 502 | int idx = -1; |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 503 | int rc = 0; |
Toshi Kani | 5deed6b | 2017-08-23 16:54:45 -0600 | [diff] [blame] | 504 | |
Borislav Petkov | eaa3a1d | 2018-05-18 13:13:31 +0200 | [diff] [blame] | 505 | if (IS_ENABLED(CONFIG_X86)) { |
| 506 | /* Check if safe to enable on this system */ |
| 507 | idx = acpi_match_platform_list(plat_list); |
| 508 | if (!force_load && idx < 0) |
| 509 | return -ENODEV; |
| 510 | } else { |
| 511 | idx = 0; |
| 512 | } |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 513 | |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 514 | /* finish another registration/unregistration instance first */ |
| 515 | mutex_lock(&ghes_reg_mutex); |
| 516 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 517 | /* |
| 518 | * We have only one logical memory controller to which all DIMMs belong. |
| 519 | */ |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 520 | if (refcount_inc_not_zero(&ghes_refcount)) |
| 521 | goto unlock; |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 522 | |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 523 | ghes_scan_system(); |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 524 | |
| 525 | /* Check if we've got a bogus BIOS */ |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 526 | if (!ghes_hw.num_dimms) { |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 527 | fake = true; |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 528 | ghes_hw.num_dimms = 1; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 529 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 530 | |
| 531 | layers[0].type = EDAC_MC_LAYER_ALL_MEM; |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 532 | layers[0].size = ghes_hw.num_dimms; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 533 | layers[0].is_virt_csrow = true; |
| 534 | |
Robert Richter | b001694 | 2020-05-19 12:44:39 +0200 | [diff] [blame] | 535 | mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, sizeof(struct ghes_pvt)); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 536 | if (!mci) { |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 537 | pr_info("Can't allocate memory for EDAC data\n"); |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 538 | rc = -ENOMEM; |
| 539 | goto unlock; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 540 | } |
| 541 | |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 542 | pvt = mci->pvt_info; |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 543 | pvt->mci = mci; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 544 | |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 545 | mci->pdev = dev; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 546 | mci->mtype_cap = MEM_FLAG_EMPTY; |
| 547 | mci->edac_ctl_cap = EDAC_FLAG_NONE; |
| 548 | mci->edac_cap = EDAC_FLAG_NONE; |
| 549 | mci->mod_name = "ghes_edac.c"; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 550 | mci->ctl_name = "ghes_edac"; |
| 551 | mci->dev_name = "ghes"; |
| 552 | |
Toshi Kani | 5deed6b | 2017-08-23 16:54:45 -0600 | [diff] [blame] | 553 | if (fake) { |
| 554 | pr_info("This system has a very crappy BIOS: It doesn't even list the DIMMS.\n"); |
| 555 | pr_info("Its SMBIOS info is wrong. It is doubtful that the error report would\n"); |
| 556 | pr_info("work on such system. Use this driver with caution\n"); |
| 557 | } else if (idx < 0) { |
Borislav Petkov | 0fe5f28 | 2017-08-16 10:33:44 +0200 | [diff] [blame] | 558 | pr_info("This EDAC driver relies on BIOS to enumerate memory and get error reports.\n"); |
| 559 | pr_info("Unfortunately, not all BIOSes reflect the memory layout correctly.\n"); |
| 560 | pr_info("So, the end result of using this driver varies from vendor to vendor.\n"); |
| 561 | pr_info("If you find incorrect reports, please contact your hardware vendor\n"); |
| 562 | pr_info("to correct its BIOS.\n"); |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 563 | pr_info("This system has %d DIMM sockets.\n", ghes_hw.num_dimms); |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 564 | } |
| 565 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 566 | if (!fake) { |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 567 | struct dimm_info *src, *dst; |
| 568 | int i = 0; |
| 569 | |
| 570 | mci_for_each_dimm(mci, dst) { |
| 571 | src = &ghes_hw.dimms[i]; |
| 572 | |
| 573 | dst->idx = src->idx; |
| 574 | dst->smbios_handle = src->smbios_handle; |
| 575 | dst->nr_pages = src->nr_pages; |
| 576 | dst->mtype = src->mtype; |
| 577 | dst->edac_mode = src->edac_mode; |
| 578 | dst->dtype = src->dtype; |
| 579 | dst->grain = src->grain; |
| 580 | |
| 581 | /* |
| 582 | * If no src->label, preserve default label assigned |
| 583 | * from EDAC core. |
| 584 | */ |
| 585 | if (strlen(src->label)) |
| 586 | memcpy(dst->label, src->label, sizeof(src->label)); |
| 587 | |
| 588 | i++; |
| 589 | } |
| 590 | |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 591 | } else { |
Robert Richter | bc9ad9e | 2019-11-06 09:33:02 +0000 | [diff] [blame] | 592 | struct dimm_info *dimm = edac_get_dimm(mci, 0, 0, 0); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 593 | |
Mauro Carvalho Chehab | d2a6856 | 2013-02-15 09:06:38 -0300 | [diff] [blame] | 594 | dimm->nr_pages = 1; |
Mauro Carvalho Chehab | 32fa1f5 | 2013-02-14 09:11:08 -0300 | [diff] [blame] | 595 | dimm->grain = 128; |
| 596 | dimm->mtype = MEM_UNKNOWN; |
| 597 | dimm->dtype = DEV_UNKNOWN; |
| 598 | dimm->edac_mode = EDAC_SECDED; |
| 599 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 600 | |
| 601 | rc = edac_mc_add_mc(mci); |
| 602 | if (rc < 0) { |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 603 | pr_info("Can't register with the EDAC core\n"); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 604 | edac_mc_free(mci); |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 605 | rc = -ENODEV; |
| 606 | goto unlock; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 607 | } |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 608 | |
| 609 | spin_lock_irqsave(&ghes_lock, flags); |
| 610 | ghes_pvt = pvt; |
| 611 | spin_unlock_irqrestore(&ghes_lock, flags); |
| 612 | |
Robert Richter | 16214bd | 2019-11-21 21:36:57 +0000 | [diff] [blame] | 613 | /* only set on success */ |
| 614 | refcount_set(&ghes_refcount, 1); |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 615 | |
| 616 | unlock: |
Borislav Petkov | b9cae27 | 2020-06-03 21:19:21 +0200 | [diff] [blame] | 617 | |
| 618 | /* Not needed anymore */ |
| 619 | kfree(ghes_hw.dimms); |
| 620 | ghes_hw.dimms = NULL; |
| 621 | |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 622 | mutex_unlock(&ghes_reg_mutex); |
| 623 | |
| 624 | return rc; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 625 | } |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 626 | |
| 627 | void ghes_edac_unregister(struct ghes *ghes) |
| 628 | { |
| 629 | struct mem_ctl_info *mci; |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 630 | unsigned long flags; |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 631 | |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 632 | mutex_lock(&ghes_reg_mutex); |
Sughosh Ganu | a66bdf5 | 2018-04-26 15:46:49 +0530 | [diff] [blame] | 633 | |
Shiju Jose | b972fdb | 2020-08-27 15:04:50 +0100 | [diff] [blame^] | 634 | system_scanned = false; |
| 635 | |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 636 | if (!refcount_dec_and_test(&ghes_refcount)) |
| 637 | goto unlock; |
James Morse | 1e72e67 | 2019-10-14 18:19:18 +0100 | [diff] [blame] | 638 | |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 639 | /* |
| 640 | * Wait for the irq handler being finished. |
| 641 | */ |
| 642 | spin_lock_irqsave(&ghes_lock, flags); |
| 643 | mci = ghes_pvt ? ghes_pvt->mci : NULL; |
James Morse | 1e72e67 | 2019-10-14 18:19:18 +0100 | [diff] [blame] | 644 | ghes_pvt = NULL; |
Robert Richter | 23f61b9 | 2019-11-05 20:07:51 +0000 | [diff] [blame] | 645 | spin_unlock_irqrestore(&ghes_lock, flags); |
| 646 | |
| 647 | if (!mci) |
| 648 | goto unlock; |
| 649 | |
| 650 | mci = edac_mc_del_mc(mci->pdev); |
| 651 | if (mci) |
| 652 | edac_mc_free(mci); |
| 653 | |
| 654 | unlock: |
| 655 | mutex_unlock(&ghes_reg_mutex); |
Mauro Carvalho Chehab | 77c5f5d | 2013-02-15 06:11:57 -0300 | [diff] [blame] | 656 | } |