2 * GHES/EDAC Linux driver
4 * This file may be distributed under the terms of the GNU General Public
7 * Copyright (c) 2013 by Mauro Carvalho Chehab <mchehab@redhat.com>
9 * Red Hat Inc. http://www.redhat.com
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #include <acpi/ghes.h>
15 #include <linux/edac.h>
16 #include <linux/dmi.h>
17 #include "edac_core.h"
18 #include <ras/ras_event.h>
20 #define GHES_EDAC_REVISION " Ver: 1.0.0"
22 struct ghes_edac_pvt
{
23 struct list_head list
;
25 struct mem_ctl_info
*mci
;
27 /* Buffers for the error handling routine */
28 char detail_location
[240];
29 char other_detail
[160];
33 static LIST_HEAD(ghes_reglist
);
34 static DEFINE_MUTEX(ghes_edac_lock
);
35 static int ghes_edac_mc_num
;
38 /* Memory Device - Type 17 of SMBIOS spec */
39 struct memdev_dmi_entry
{
43 u16 phys_mem_array_handle
;
44 u16 mem_err_info_handle
;
61 u16 conf_mem_clk_speed
;
62 } __attribute__((__packed__
));
64 struct ghes_edac_dimm_fill
{
65 struct mem_ctl_info
*mci
;
69 char *memory_type
[] = {
70 [MEM_EMPTY
] = "EMPTY",
71 [MEM_RESERVED
] = "RESERVED",
72 [MEM_UNKNOWN
] = "UNKNOWN",
82 [MEM_FB_DDR2
] = "FB_DDR2",
83 [MEM_RDDR2
] = "RDDR2",
86 [MEM_RDDR3
] = "RDDR3",
89 static void ghes_edac_count_dimms(const struct dmi_header
*dh
, void *arg
)
93 if (dh
->type
== DMI_ENTRY_MEM_DEVICE
)
97 static void ghes_edac_dmidecode(const struct dmi_header
*dh
, void *arg
)
99 struct ghes_edac_dimm_fill
*dimm_fill
= arg
;
100 struct mem_ctl_info
*mci
= dimm_fill
->mci
;
102 if (dh
->type
== DMI_ENTRY_MEM_DEVICE
) {
103 struct memdev_dmi_entry
*entry
= (struct memdev_dmi_entry
*)dh
;
104 struct dimm_info
*dimm
= EDAC_DIMM_PTR(mci
->layers
, mci
->dimms
,
106 dimm_fill
->count
, 0, 0);
108 if (entry
->size
== 0xffff) {
109 pr_info("Can't get DIMM%i size\n",
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
);
115 if (entry
->size
& 1 << 15)
116 dimm
->nr_pages
= MiB_TO_PAGES((entry
->size
&
119 dimm
->nr_pages
= MiB_TO_PAGES(entry
->size
);
122 switch (entry
->memory_type
) {
124 if (entry
->type_detail
& 1 << 13)
125 dimm
->mtype
= MEM_RDDR
;
127 dimm
->mtype
= MEM_DDR
;
130 if (entry
->type_detail
& 1 << 13)
131 dimm
->mtype
= MEM_RDDR2
;
133 dimm
->mtype
= MEM_DDR2
;
136 dimm
->mtype
= MEM_FB_DDR2
;
139 if (entry
->type_detail
& 1 << 13)
140 dimm
->mtype
= MEM_RDDR3
;
142 dimm
->mtype
= MEM_DDR3
;
145 if (entry
->type_detail
& 1 << 6)
146 dimm
->mtype
= MEM_RMBS
;
147 else if ((entry
->type_detail
& ((1 << 7) | (1 << 13)))
148 == ((1 << 7) | (1 << 13)))
149 dimm
->mtype
= MEM_RDR
;
150 else if (entry
->type_detail
& 1 << 7)
151 dimm
->mtype
= MEM_SDR
;
152 else if (entry
->type_detail
& 1 << 9)
153 dimm
->mtype
= MEM_EDO
;
155 dimm
->mtype
= MEM_UNKNOWN
;
159 * Actually, we can only detect if the memory has bits for
162 if (entry
->total_width
== entry
->data_width
)
163 dimm
->edac_mode
= EDAC_NONE
;
165 dimm
->edac_mode
= EDAC_SECDED
;
167 dimm
->dtype
= DEV_UNKNOWN
;
168 dimm
->grain
= 128; /* Likely, worse case */
171 * FIXME: It shouldn't be hard to also fill the DIMM labels
174 if (dimm
->nr_pages
) {
175 edac_dbg(1, "DIMM%i: %s size = %d MB%s\n",
176 dimm_fill
->count
, memory_type
[dimm
->mtype
],
177 PAGES_TO_MiB(dimm
->nr_pages
),
178 (dimm
->edac_mode
!= EDAC_NONE
) ? "(ECC)" : "");
179 edac_dbg(2, "\ttype %d, detail 0x%02x, width %d(total %d)\n",
180 entry
->memory_type
, entry
->type_detail
,
181 entry
->total_width
, entry
->data_width
);
188 void ghes_edac_report_mem_error(struct ghes
*ghes
, int sev
,
189 struct cper_sec_mem_err
*mem_err
)
191 enum hw_event_mc_err_type type
;
192 struct edac_raw_error_desc
*e
;
193 struct mem_ctl_info
*mci
;
194 struct ghes_edac_pvt
*pvt
= NULL
;
198 list_for_each_entry(pvt
, &ghes_reglist
, list
) {
199 if (ghes
== pvt
->ghes
)
203 pr_err("Internal error: Can't find EDAC structure\n");
207 e
= &mci
->error_desc
;
209 /* Cleans the error report buffer */
210 memset(e
, 0, sizeof (*e
));
212 strcpy(e
->label
, "unknown label");
214 e
->other_detail
= pvt
->other_detail
;
218 *pvt
->other_detail
= '\0';
222 case GHES_SEV_CORRECTED
:
223 type
= HW_EVENT_ERR_CORRECTED
;
225 case GHES_SEV_RECOVERABLE
:
226 type
= HW_EVENT_ERR_UNCORRECTED
;
229 type
= HW_EVENT_ERR_FATAL
;
233 type
= HW_EVENT_ERR_INFO
;
236 edac_dbg(1, "error validation_bits: 0x%08llx\n",
237 (long long)mem_err
->validation_bits
);
239 /* Error type, mapped on e->msg */
240 if (mem_err
->validation_bits
& CPER_MEM_VALID_ERROR_TYPE
) {
242 switch (mem_err
->error_type
) {
244 p
+= sprintf(p
, "Unknown");
247 p
+= sprintf(p
, "No error");
250 p
+= sprintf(p
, "Single-bit ECC");
253 p
+= sprintf(p
, "Multi-bit ECC");
256 p
+= sprintf(p
, "Single-symbol ChipKill ECC");
259 p
+= sprintf(p
, "Multi-symbol ChipKill ECC");
262 p
+= sprintf(p
, "Master abort");
265 p
+= sprintf(p
, "Target abort");
268 p
+= sprintf(p
, "Parity Error");
271 p
+= sprintf(p
, "Watchdog timeout");
274 p
+= sprintf(p
, "Invalid address");
277 p
+= sprintf(p
, "Mirror Broken");
280 p
+= sprintf(p
, "Memory Sparing");
283 p
+= sprintf(p
, "Scrub corrected error");
286 p
+= sprintf(p
, "Scrub uncorrected error");
289 p
+= sprintf(p
, "Physical Memory Map-out event");
292 p
+= sprintf(p
, "reserved error (%d)",
293 mem_err
->error_type
);
296 strcpy(pvt
->msg
, "unknown error");
300 if (mem_err
->validation_bits
& CPER_MEM_VALID_PHYSICAL_ADDRESS
) {
301 e
->page_frame_number
= mem_err
->physical_addr
>> PAGE_SHIFT
;
302 e
->offset_in_page
= mem_err
->physical_addr
& ~PAGE_MASK
;
306 if (mem_err
->validation_bits
& CPER_MEM_VALID_PHYSICAL_ADDRESS_MASK
) {
307 e
->grain
= ~(mem_err
->physical_addr_mask
& ~PAGE_MASK
);
310 /* Memory error location, mapped on e->location */
312 if (mem_err
->validation_bits
& CPER_MEM_VALID_NODE
)
313 p
+= sprintf(p
, "node:%d ", mem_err
->node
);
314 if (mem_err
->validation_bits
& CPER_MEM_VALID_CARD
)
315 p
+= sprintf(p
, "card:%d ", mem_err
->card
);
316 if (mem_err
->validation_bits
& CPER_MEM_VALID_MODULE
)
317 p
+= sprintf(p
, "module:%d ", mem_err
->module
);
318 if (mem_err
->validation_bits
& CPER_MEM_VALID_BANK
)
319 p
+= sprintf(p
, "bank:%d ", mem_err
->bank
);
320 if (mem_err
->validation_bits
& CPER_MEM_VALID_ROW
)
321 p
+= sprintf(p
, "row:%d ", mem_err
->row
);
322 if (mem_err
->validation_bits
& CPER_MEM_VALID_COLUMN
)
323 p
+= sprintf(p
, "col:%d ", mem_err
->column
);
324 if (mem_err
->validation_bits
& CPER_MEM_VALID_BIT_POSITION
)
325 p
+= sprintf(p
, "bit_pos:%d ", mem_err
->bit_pos
);
329 /* All other fields are mapped on e->other_detail */
330 p
= pvt
->other_detail
;
331 if (mem_err
->validation_bits
& CPER_MEM_VALID_ERROR_STATUS
) {
332 u64 status
= mem_err
->error_status
;
334 p
+= sprintf(p
, "status(0x%016llx): ", (long long)status
);
335 switch ((status
>> 8) & 0xff) {
337 p
+= sprintf(p
, "Error detected internal to the component ");
340 p
+= sprintf(p
, "Error detected in the bus ");
343 p
+= sprintf(p
, "Storage error in DRAM memory ");
346 p
+= sprintf(p
, "Storage error in TLB ");
349 p
+= sprintf(p
, "Storage error in cache ");
352 p
+= sprintf(p
, "Error in one or more functional units ");
355 p
+= sprintf(p
, "component failed self test ");
358 p
+= sprintf(p
, "Overflow or undervalue of internal queue ");
361 p
+= sprintf(p
, "Virtual address not found on IO-TLB or IO-PDIR ");
364 p
+= sprintf(p
, "Improper access error ");
367 p
+= sprintf(p
, "Access to a memory address which is not mapped to any component ");
370 p
+= sprintf(p
, "Loss of Lockstep ");
373 p
+= sprintf(p
, "Response not associated with a request ");
376 p
+= sprintf(p
, "Bus parity error - must also set the A, C, or D Bits ");
379 p
+= sprintf(p
, "Detection of a PATH_ERROR ");
382 p
+= sprintf(p
, "Bus operation timeout ");
385 p
+= sprintf(p
, "A read was issued to data that has been poisoned ");
388 p
+= sprintf(p
, "reserved ");
392 if (mem_err
->validation_bits
& CPER_MEM_VALID_REQUESTOR_ID
)
393 p
+= sprintf(p
, "requestorID: 0x%016llx ",
394 (long long)mem_err
->requestor_id
);
395 if (mem_err
->validation_bits
& CPER_MEM_VALID_RESPONDER_ID
)
396 p
+= sprintf(p
, "responderID: 0x%016llx ",
397 (long long)mem_err
->responder_id
);
398 if (mem_err
->validation_bits
& CPER_MEM_VALID_TARGET_ID
)
399 p
+= sprintf(p
, "targetID: 0x%016llx ",
400 (long long)mem_err
->responder_id
);
401 if (p
> pvt
->other_detail
)
404 /* Generate the trace event */
405 grain_bits
= fls_long(e
->grain
);
406 sprintf(pvt
->detail_location
, "APEI location: %s %s",
407 e
->location
, e
->other_detail
);
408 trace_mc_event(type
, e
->msg
, e
->label
, e
->error_count
,
409 mci
->mc_idx
, e
->top_layer
, e
->mid_layer
, e
->low_layer
,
410 PAGES_TO_MiB(e
->page_frame_number
) | e
->offset_in_page
,
411 grain_bits
, e
->syndrome
, pvt
->detail_location
);
413 /* Report the error via EDAC API */
414 edac_raw_mc_handle_error(type
, mci
, e
);
416 EXPORT_SYMBOL_GPL(ghes_edac_report_mem_error
);
418 int ghes_edac_register(struct ghes
*ghes
, struct device
*dev
)
421 int rc
, num_dimm
= 0;
422 struct mem_ctl_info
*mci
;
423 struct edac_mc_layer layers
[1];
424 struct ghes_edac_pvt
*pvt
;
425 struct ghes_edac_dimm_fill dimm_fill
;
427 /* Get the number of DIMMs */
428 dmi_walk(ghes_edac_count_dimms
, &num_dimm
);
430 /* Check if we've got a bogus BIOS */
436 layers
[0].type
= EDAC_MC_LAYER_ALL_MEM
;
437 layers
[0].size
= num_dimm
;
438 layers
[0].is_virt_csrow
= true;
441 * We need to serialize edac_mc_alloc() and edac_mc_add_mc(),
442 * to avoid duplicated memory controller numbers
444 mutex_lock(&ghes_edac_lock
);
445 mci
= edac_mc_alloc(ghes_edac_mc_num
, ARRAY_SIZE(layers
), layers
,
448 pr_info("Can't allocate memory for EDAC data\n");
449 mutex_unlock(&ghes_edac_lock
);
454 memset(pvt
, 0, sizeof(*pvt
));
455 list_add_tail(&pvt
->list
, &ghes_reglist
);
460 mci
->mtype_cap
= MEM_FLAG_EMPTY
;
461 mci
->edac_ctl_cap
= EDAC_FLAG_NONE
;
462 mci
->edac_cap
= EDAC_FLAG_NONE
;
463 mci
->mod_name
= "ghes_edac.c";
464 mci
->mod_ver
= GHES_EDAC_REVISION
;
465 mci
->ctl_name
= "ghes_edac";
466 mci
->dev_name
= "ghes";
468 if (!ghes_edac_mc_num
) {
470 pr_info("This EDAC driver relies on BIOS to enumerate memory and get error reports.\n");
471 pr_info("Unfortunately, not all BIOSes reflect the memory layout correctly.\n");
472 pr_info("So, the end result of using this driver varies from vendor to vendor.\n");
473 pr_info("If you find incorrect reports, please contact your hardware vendor\n");
474 pr_info("to correct its BIOS.\n");
475 pr_info("This system has %d DIMM sockets.\n",
478 pr_info("This system has a very crappy BIOS: It doesn't even list the DIMMS.\n");
479 pr_info("Its SMBIOS info is wrong. It is doubtful that the error report would\n");
480 pr_info("work on such system. Use this driver with caution\n");
486 * Fill DIMM info from DMI for the memory controller #0
488 * Keep it in blank for the other memory controllers, as
489 * there's no reliable way to properly credit each DIMM to
490 * the memory controller, as different BIOSes fill the
491 * DMI bank location fields on different ways
493 if (!ghes_edac_mc_num
) {
496 dmi_walk(ghes_edac_dmidecode
, &dimm_fill
);
499 struct dimm_info
*dimm
= EDAC_DIMM_PTR(mci
->layers
, mci
->dimms
,
500 mci
->n_layers
, 0, 0, 0);
504 dimm
->mtype
= MEM_UNKNOWN
;
505 dimm
->dtype
= DEV_UNKNOWN
;
506 dimm
->edac_mode
= EDAC_SECDED
;
509 rc
= edac_mc_add_mc(mci
);
511 pr_info("Can't register at EDAC core\n");
513 mutex_unlock(&ghes_edac_lock
);
518 mutex_unlock(&ghes_edac_lock
);
521 EXPORT_SYMBOL_GPL(ghes_edac_register
);
523 void ghes_edac_unregister(struct ghes
*ghes
)
525 struct mem_ctl_info
*mci
;
526 struct ghes_edac_pvt
*pvt
, *tmp
;
528 list_for_each_entry_safe(pvt
, tmp
, &ghes_reglist
, list
) {
529 if (ghes
== pvt
->ghes
) {
531 edac_mc_del_mc(mci
->pdev
);
533 list_del(&pvt
->list
);
537 EXPORT_SYMBOL_GPL(ghes_edac_unregister
);