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