1 // SPDX-License-Identifier: GPL-2.0
4 * Shared code by both skx_edac and i10nm_edac. Originally split out
5 * from the skx_edac driver.
7 * This file is linked into both skx_edac and i10nm_edac drivers. In
8 * order to avoid link errors, this file must be like a pure library
9 * without including symbols and defines which would otherwise conflict,
10 * when linked once into a module and into a built-in object, at the
11 * same time. For example, __this_module symbol references when that
12 * file is being linked into a built-in object.
14 * Copyright (c) 2018, Intel Corporation.
17 #include <linux/acpi.h>
18 #include <linux/dmi.h>
19 #include <linux/adxl.h>
20 #include <acpi/nfit.h>
22 #include "edac_module.h"
23 #include "skx_common.h"
25 static const char * const component_names
[] = {
26 [INDEX_SOCKET
] = "ProcessorSocketId",
27 [INDEX_MEMCTRL
] = "MemoryControllerId",
28 [INDEX_CHANNEL
] = "ChannelId",
29 [INDEX_DIMM
] = "DimmSlotId",
30 [INDEX_CS
] = "ChipSelect",
31 [INDEX_NM_MEMCTRL
] = "NmMemoryControllerId",
32 [INDEX_NM_CHANNEL
] = "NmChannelId",
33 [INDEX_NM_DIMM
] = "NmDimmSlotId",
34 [INDEX_NM_CS
] = "NmChipSelect",
37 static int component_indices
[ARRAY_SIZE(component_names
)];
38 static int adxl_component_count
;
39 static const char * const *adxl_component_names
;
40 static u64
*adxl_values
;
41 static char *adxl_msg
;
42 static unsigned long adxl_nm_bitmap
;
44 static char skx_msg
[MSG_SIZE
];
45 static skx_decode_f driver_decode
;
46 static skx_show_retry_log_f skx_show_retry_rd_err_log
;
47 static u64 skx_tolm
, skx_tohm
;
48 static LIST_HEAD(dev_edac_list
);
49 static bool skx_mem_cfg_2lm
;
50 static struct res_config
*skx_res_cfg
;
52 int skx_adxl_get(void)
54 const char * const *names
;
57 names
= adxl_get_component_names();
59 skx_printk(KERN_NOTICE
, "No firmware support for address translation.\n");
63 for (i
= 0; i
< INDEX_MAX
; i
++) {
64 for (j
= 0; names
[j
]; j
++) {
65 if (!strcmp(component_names
[i
], names
[j
])) {
66 component_indices
[i
] = j
;
68 if (i
>= INDEX_NM_FIRST
)
69 adxl_nm_bitmap
|= 1 << i
;
75 if (!names
[j
] && i
< INDEX_NM_FIRST
)
79 if (skx_mem_cfg_2lm
) {
81 skx_printk(KERN_NOTICE
, "Not enough ADXL components for 2-level memory.\n");
83 edac_dbg(2, "adxl_nm_bitmap: 0x%lx\n", adxl_nm_bitmap
);
86 adxl_component_names
= names
;
88 adxl_component_count
++;
90 adxl_values
= kcalloc(adxl_component_count
, sizeof(*adxl_values
),
93 adxl_component_count
= 0;
97 adxl_msg
= kzalloc(MSG_SIZE
, GFP_KERNEL
);
99 adxl_component_count
= 0;
106 skx_printk(KERN_ERR
, "'%s' is not matched from DSM parameters: ",
108 for (j
= 0; names
[j
]; j
++)
109 skx_printk(KERN_CONT
, "%s ", names
[j
]);
110 skx_printk(KERN_CONT
, "\n");
114 EXPORT_SYMBOL_GPL(skx_adxl_get
);
116 void skx_adxl_put(void)
121 EXPORT_SYMBOL_GPL(skx_adxl_put
);
123 static bool skx_adxl_decode(struct decoded_addr
*res
, enum error_source err_src
)
128 if (res
->addr
>= skx_tohm
|| (res
->addr
>= skx_tolm
&&
129 res
->addr
< BIT_ULL(32))) {
130 edac_dbg(0, "Address 0x%llx out of range\n", res
->addr
);
134 if (adxl_decode(res
->addr
, adxl_values
)) {
135 edac_dbg(0, "Failed to decode 0x%llx\n", res
->addr
);
140 * GNR with a Flat2LM memory configuration may mistakenly classify
141 * a near-memory error(DDR5) as a far-memory error(CXL), resulting
142 * in the incorrect selection of decoded ADXL components.
143 * To address this, prefetch the decoded far-memory controller ID
144 * and adjust the error source to near-memory if the far-memory
145 * controller ID is invalid.
147 if (skx_res_cfg
&& skx_res_cfg
->type
== GNR
&& err_src
== ERR_SRC_2LM_FM
) {
148 res
->imc
= (int)adxl_values
[component_indices
[INDEX_MEMCTRL
]];
149 if (res
->imc
== -1) {
150 err_src
= ERR_SRC_2LM_NM
;
151 edac_dbg(0, "Adjust the error source to near-memory.\n");
155 res
->socket
= (int)adxl_values
[component_indices
[INDEX_SOCKET
]];
156 if (err_src
== ERR_SRC_2LM_NM
) {
157 res
->imc
= (adxl_nm_bitmap
& BIT_NM_MEMCTRL
) ?
158 (int)adxl_values
[component_indices
[INDEX_NM_MEMCTRL
]] : -1;
159 res
->channel
= (adxl_nm_bitmap
& BIT_NM_CHANNEL
) ?
160 (int)adxl_values
[component_indices
[INDEX_NM_CHANNEL
]] : -1;
161 res
->dimm
= (adxl_nm_bitmap
& BIT_NM_DIMM
) ?
162 (int)adxl_values
[component_indices
[INDEX_NM_DIMM
]] : -1;
163 res
->cs
= (adxl_nm_bitmap
& BIT_NM_CS
) ?
164 (int)adxl_values
[component_indices
[INDEX_NM_CS
]] : -1;
166 res
->imc
= (int)adxl_values
[component_indices
[INDEX_MEMCTRL
]];
167 res
->channel
= (int)adxl_values
[component_indices
[INDEX_CHANNEL
]];
168 res
->dimm
= (int)adxl_values
[component_indices
[INDEX_DIMM
]];
169 res
->cs
= (int)adxl_values
[component_indices
[INDEX_CS
]];
172 if (res
->imc
> NUM_IMC
- 1 || res
->imc
< 0) {
173 skx_printk(KERN_ERR
, "Bad imc %d\n", res
->imc
);
177 list_for_each_entry(d
, &dev_edac_list
, list
) {
178 if (d
->imc
[0].src_id
== res
->socket
) {
185 skx_printk(KERN_ERR
, "No device for src_id %d imc %d\n",
186 res
->socket
, res
->imc
);
190 for (i
= 0; i
< adxl_component_count
; i
++) {
191 if (adxl_values
[i
] == ~0x0ull
)
194 len
+= snprintf(adxl_msg
+ len
, MSG_SIZE
- len
, " %s:0x%llx",
195 adxl_component_names
[i
], adxl_values
[i
]);
196 if (MSG_SIZE
- len
<= 0)
200 res
->decoded_by_adxl
= true;
205 void skx_set_mem_cfg(bool mem_cfg_2lm
)
207 skx_mem_cfg_2lm
= mem_cfg_2lm
;
209 EXPORT_SYMBOL_GPL(skx_set_mem_cfg
);
211 void skx_set_res_cfg(struct res_config
*cfg
)
215 EXPORT_SYMBOL_GPL(skx_set_res_cfg
);
217 void skx_set_decode(skx_decode_f decode
, skx_show_retry_log_f show_retry_log
)
219 driver_decode
= decode
;
220 skx_show_retry_rd_err_log
= show_retry_log
;
222 EXPORT_SYMBOL_GPL(skx_set_decode
);
224 int skx_get_src_id(struct skx_dev
*d
, int off
, u8
*id
)
228 if (pci_read_config_dword(d
->util_all
, off
, ®
)) {
229 skx_printk(KERN_ERR
, "Failed to read src id\n");
233 *id
= GET_BITFIELD(reg
, 12, 14);
236 EXPORT_SYMBOL_GPL(skx_get_src_id
);
238 int skx_get_node_id(struct skx_dev
*d
, u8
*id
)
242 if (pci_read_config_dword(d
->util_all
, 0xf4, ®
)) {
243 skx_printk(KERN_ERR
, "Failed to read node id\n");
247 *id
= GET_BITFIELD(reg
, 0, 2);
250 EXPORT_SYMBOL_GPL(skx_get_node_id
);
252 static int get_width(u32 mtr
)
254 switch (GET_BITFIELD(mtr
, 8, 9)) {
266 * We use the per-socket device @cfg->did to count how many sockets are present,
267 * and to detemine which PCI buses are associated with each socket. Allocate
268 * and build the full list of all the skx_dev structures that we need here.
270 int skx_get_all_bus_mappings(struct res_config
*cfg
, struct list_head
**list
)
272 struct pci_dev
*pdev
, *prev
;
279 pdev
= pci_get_device(PCI_VENDOR_ID_INTEL
, cfg
->decs_did
, prev
);
283 d
= kzalloc(sizeof(*d
), GFP_KERNEL
);
289 if (pci_read_config_dword(pdev
, cfg
->busno_cfg_offset
, ®
)) {
292 skx_printk(KERN_ERR
, "Failed to read bus idx\n");
296 d
->bus
[0] = GET_BITFIELD(reg
, 0, 7);
297 d
->bus
[1] = GET_BITFIELD(reg
, 8, 15);
298 if (cfg
->type
== SKX
) {
299 d
->seg
= pci_domain_nr(pdev
->bus
);
300 d
->bus
[2] = GET_BITFIELD(reg
, 16, 23);
301 d
->bus
[3] = GET_BITFIELD(reg
, 24, 31);
303 d
->seg
= GET_BITFIELD(reg
, 16, 23);
306 edac_dbg(2, "busses: 0x%x, 0x%x, 0x%x, 0x%x\n",
307 d
->bus
[0], d
->bus
[1], d
->bus
[2], d
->bus
[3]);
308 list_add_tail(&d
->list
, &dev_edac_list
);
313 *list
= &dev_edac_list
;
316 EXPORT_SYMBOL_GPL(skx_get_all_bus_mappings
);
318 int skx_get_hi_lo(unsigned int did
, int off
[], u64
*tolm
, u64
*tohm
)
320 struct pci_dev
*pdev
;
323 pdev
= pci_get_device(PCI_VENDOR_ID_INTEL
, did
, NULL
);
325 edac_dbg(2, "Can't get tolm/tohm\n");
329 if (pci_read_config_dword(pdev
, off
[0], ®
)) {
330 skx_printk(KERN_ERR
, "Failed to read tolm\n");
335 if (pci_read_config_dword(pdev
, off
[1], ®
)) {
336 skx_printk(KERN_ERR
, "Failed to read lower tohm\n");
341 if (pci_read_config_dword(pdev
, off
[2], ®
)) {
342 skx_printk(KERN_ERR
, "Failed to read upper tohm\n");
345 skx_tohm
|= (u64
)reg
<< 32;
350 edac_dbg(2, "tolm = 0x%llx tohm = 0x%llx\n", skx_tolm
, skx_tohm
);
356 EXPORT_SYMBOL_GPL(skx_get_hi_lo
);
358 static int skx_get_dimm_attr(u32 reg
, int lobit
, int hibit
, int add
,
359 int minval
, int maxval
, const char *name
)
361 u32 val
= GET_BITFIELD(reg
, lobit
, hibit
);
363 if (val
< minval
|| val
> maxval
) {
364 edac_dbg(2, "bad %s = %d (raw=0x%x)\n", name
, val
, reg
);
370 #define numrank(reg) skx_get_dimm_attr(reg, 12, 13, 0, 0, 2, "ranks")
371 #define numrow(reg) skx_get_dimm_attr(reg, 2, 4, 12, 1, 6, "rows")
372 #define numcol(reg) skx_get_dimm_attr(reg, 0, 1, 10, 0, 2, "cols")
374 int skx_get_dimm_info(u32 mtr
, u32 mcmtr
, u32 amap
, struct dimm_info
*dimm
,
375 struct skx_imc
*imc
, int chan
, int dimmno
,
376 struct res_config
*cfg
)
378 int banks
, ranks
, rows
, cols
, npages
;
382 ranks
= numrank(mtr
);
384 cols
= imc
->hbm_mc
? 6 : numcol(mtr
);
389 } else if (cfg
->support_ddr5
) {
398 * Compute size in 8-byte (2^3) words, then shift to MiB (2^20)
400 size
= ((1ull << (rows
+ cols
+ ranks
)) * banks
) >> (20 - 3);
401 npages
= MiB_TO_PAGES(size
);
403 edac_dbg(0, "mc#%d: channel %d, dimm %d, %lld MiB (%d pages) bank: %d, rank: %d, row: 0x%x, col: 0x%x\n",
404 imc
->mc
, chan
, dimmno
, size
, npages
,
405 banks
, 1 << ranks
, rows
, cols
);
407 imc
->chan
[chan
].dimms
[dimmno
].close_pg
= GET_BITFIELD(mcmtr
, 0, 0);
408 imc
->chan
[chan
].dimms
[dimmno
].bank_xor_enable
= GET_BITFIELD(mcmtr
, 9, 9);
409 imc
->chan
[chan
].dimms
[dimmno
].fine_grain_bank
= GET_BITFIELD(amap
, 0, 0);
410 imc
->chan
[chan
].dimms
[dimmno
].rowbits
= rows
;
411 imc
->chan
[chan
].dimms
[dimmno
].colbits
= cols
;
413 dimm
->nr_pages
= npages
;
415 dimm
->dtype
= get_width(mtr
);
417 dimm
->edac_mode
= EDAC_SECDED
; /* likely better than this */
420 snprintf(dimm
->label
, sizeof(dimm
->label
), "CPU_SrcID#%u_HBMC#%u_Chan#%u",
421 imc
->src_id
, imc
->lmc
, chan
);
423 snprintf(dimm
->label
, sizeof(dimm
->label
), "CPU_SrcID#%u_MC#%u_Chan#%u_DIMM#%u",
424 imc
->src_id
, imc
->lmc
, chan
, dimmno
);
428 EXPORT_SYMBOL_GPL(skx_get_dimm_info
);
430 int skx_get_nvdimm_info(struct dimm_info
*dimm
, struct skx_imc
*imc
,
431 int chan
, int dimmno
, const char *mod_str
)
438 dev_handle
= ACPI_NFIT_BUILD_DEVICE_HANDLE(dimmno
, chan
, imc
->lmc
,
441 smbios_handle
= nfit_get_smbios_id(dev_handle
, &flags
);
442 if (smbios_handle
== -EOPNOTSUPP
) {
443 pr_warn_once("%s: Can't find size of NVDIMM. Try enabling CONFIG_ACPI_NFIT\n", mod_str
);
447 if (smbios_handle
< 0) {
448 skx_printk(KERN_ERR
, "Can't find handle for NVDIMM ADR=0x%x\n", dev_handle
);
452 if (flags
& ACPI_NFIT_MEM_MAP_FAILED
) {
453 skx_printk(KERN_ERR
, "NVDIMM ADR=0x%x is not mapped\n", dev_handle
);
457 size
= dmi_memdev_size(smbios_handle
);
459 skx_printk(KERN_ERR
, "Can't find size for NVDIMM ADR=0x%x/SMBIOS=0x%x\n",
460 dev_handle
, smbios_handle
);
463 dimm
->nr_pages
= size
>> PAGE_SHIFT
;
465 dimm
->dtype
= DEV_UNKNOWN
;
466 dimm
->mtype
= MEM_NVDIMM
;
467 dimm
->edac_mode
= EDAC_SECDED
; /* likely better than this */
469 edac_dbg(0, "mc#%d: channel %d, dimm %d, %llu MiB (%u pages)\n",
470 imc
->mc
, chan
, dimmno
, size
>> 20, dimm
->nr_pages
);
472 snprintf(dimm
->label
, sizeof(dimm
->label
), "CPU_SrcID#%u_MC#%u_Chan#%u_DIMM#%u",
473 imc
->src_id
, imc
->lmc
, chan
, dimmno
);
475 return (size
== 0 || size
== ~0ull) ? 0 : 1;
477 EXPORT_SYMBOL_GPL(skx_get_nvdimm_info
);
479 int skx_register_mci(struct skx_imc
*imc
, struct pci_dev
*pdev
,
480 const char *ctl_name
, const char *mod_str
,
481 get_dimm_config_f get_dimm_config
,
482 struct res_config
*cfg
)
484 struct mem_ctl_info
*mci
;
485 struct edac_mc_layer layers
[2];
489 /* Allocate a new MC control structure */
490 layers
[0].type
= EDAC_MC_LAYER_CHANNEL
;
491 layers
[0].size
= NUM_CHANNELS
;
492 layers
[0].is_virt_csrow
= false;
493 layers
[1].type
= EDAC_MC_LAYER_SLOT
;
494 layers
[1].size
= NUM_DIMMS
;
495 layers
[1].is_virt_csrow
= true;
496 mci
= edac_mc_alloc(imc
->mc
, ARRAY_SIZE(layers
), layers
,
497 sizeof(struct skx_pvt
));
502 edac_dbg(0, "MC#%d: mci = %p\n", imc
->mc
, mci
);
504 /* Associate skx_dev and mci for future usage */
509 mci
->ctl_name
= kasprintf(GFP_KERNEL
, "%s#%d IMC#%d", ctl_name
,
510 imc
->node_id
, imc
->lmc
);
511 if (!mci
->ctl_name
) {
516 mci
->mtype_cap
= MEM_FLAG_DDR4
| MEM_FLAG_NVDIMM
;
517 if (cfg
->support_ddr5
)
518 mci
->mtype_cap
|= MEM_FLAG_DDR5
;
519 mci
->edac_ctl_cap
= EDAC_FLAG_NONE
;
520 mci
->edac_cap
= EDAC_FLAG_NONE
;
521 mci
->mod_name
= mod_str
;
522 mci
->dev_name
= pci_name(pdev
);
523 mci
->ctl_page_to_phys
= NULL
;
525 rc
= get_dimm_config(mci
, cfg
);
529 /* Record ptr to the generic device */
530 mci
->pdev
= &pdev
->dev
;
532 /* Add this new MC control structure to EDAC's list of MCs */
533 if (unlikely(edac_mc_add_mc(mci
))) {
534 edac_dbg(0, "MC: failed edac_mc_add_mc()\n");
542 kfree(mci
->ctl_name
);
548 EXPORT_SYMBOL_GPL(skx_register_mci
);
550 static void skx_unregister_mci(struct skx_imc
*imc
)
552 struct mem_ctl_info
*mci
= imc
->mci
;
557 edac_dbg(0, "MC%d: mci = %p\n", imc
->mc
, mci
);
559 /* Remove MC sysfs nodes */
560 edac_mc_del_mc(mci
->pdev
);
562 edac_dbg(1, "%s: free mci struct\n", mci
->ctl_name
);
563 kfree(mci
->ctl_name
);
567 static void skx_mce_output_error(struct mem_ctl_info
*mci
,
569 struct decoded_addr
*res
)
571 enum hw_event_mc_err_type tp_event
;
573 bool ripv
= GET_BITFIELD(m
->mcgstatus
, 0, 0);
574 bool overflow
= GET_BITFIELD(m
->status
, 62, 62);
575 bool uncorrected_error
= GET_BITFIELD(m
->status
, 61, 61);
576 bool scrub_err
= false;
579 u32 core_err_cnt
= GET_BITFIELD(m
->status
, 38, 52);
580 u32 mscod
= GET_BITFIELD(m
->status
, 16, 31);
581 u32 errcode
= GET_BITFIELD(m
->status
, 0, 15);
582 u32 optypenum
= GET_BITFIELD(m
->status
, 4, 6);
584 recoverable
= GET_BITFIELD(m
->status
, 56, 56);
586 if (uncorrected_error
) {
589 tp_event
= HW_EVENT_ERR_UNCORRECTED
;
591 tp_event
= HW_EVENT_ERR_FATAL
;
594 tp_event
= HW_EVENT_ERR_CORRECTED
;
599 optype
= "generic undef request error";
602 optype
= "memory read error";
605 optype
= "memory write error";
608 optype
= "addr/cmd error";
611 optype
= "memory scrubbing error";
619 if (res
->decoded_by_adxl
) {
620 len
= snprintf(skx_msg
, MSG_SIZE
, "%s%s err_code:0x%04x:0x%04x %s",
621 overflow
? " OVERFLOW" : "",
622 (uncorrected_error
&& recoverable
) ? " recoverable" : "",
623 mscod
, errcode
, adxl_msg
);
625 len
= snprintf(skx_msg
, MSG_SIZE
,
626 "%s%s err_code:0x%04x:0x%04x ProcessorSocketId:0x%x MemoryControllerId:0x%x PhysicalRankId:0x%x Row:0x%x Column:0x%x Bank:0x%x BankGroup:0x%x",
627 overflow
? " OVERFLOW" : "",
628 (uncorrected_error
&& recoverable
) ? " recoverable" : "",
630 res
->socket
, res
->imc
, res
->rank
,
631 res
->row
, res
->column
, res
->bank_address
, res
->bank_group
);
634 if (skx_show_retry_rd_err_log
)
635 skx_show_retry_rd_err_log(res
, skx_msg
+ len
, MSG_SIZE
- len
, scrub_err
);
637 edac_dbg(0, "%s\n", skx_msg
);
639 /* Call the helper to output message */
640 edac_mc_handle_error(tp_event
, mci
, core_err_cnt
,
641 m
->addr
>> PAGE_SHIFT
, m
->addr
& ~PAGE_MASK
, 0,
642 res
->channel
, res
->dimm
, -1,
646 static enum error_source
skx_error_source(const struct mce
*m
)
648 u32 errcode
= GET_BITFIELD(m
->status
, 0, 15) & MCACOD_MEM_ERR_MASK
;
650 if (errcode
!= MCACOD_MEM_CTL_ERR
&& errcode
!= MCACOD_EXT_MEM_ERR
)
651 return ERR_SRC_NOT_MEMORY
;
653 if (!skx_mem_cfg_2lm
)
656 if (errcode
== MCACOD_EXT_MEM_ERR
)
657 return ERR_SRC_2LM_NM
;
659 return ERR_SRC_2LM_FM
;
662 int skx_mce_check_error(struct notifier_block
*nb
, unsigned long val
,
665 struct mce
*mce
= (struct mce
*)data
;
666 enum error_source err_src
;
667 struct decoded_addr res
;
668 struct mem_ctl_info
*mci
;
671 if (mce
->kflags
& MCE_HANDLED_CEC
)
674 err_src
= skx_error_source(mce
);
676 /* Ignore unless this is memory related with an address */
677 if (err_src
== ERR_SRC_NOT_MEMORY
|| !(mce
->status
& MCI_STATUS_ADDRV
))
680 memset(&res
, 0, sizeof(res
));
682 res
.addr
= mce
->addr
& MCI_ADDR_PHYSADDR
;
683 if (!pfn_to_online_page(res
.addr
>> PAGE_SHIFT
) && !arch_is_platform_page(res
.addr
)) {
684 pr_err("Invalid address 0x%llx in IA32_MC%d_ADDR\n", mce
->addr
, mce
->bank
);
688 /* Try driver decoder first */
689 if (!(driver_decode
&& driver_decode(&res
))) {
690 /* Then try firmware decoder (ACPI DSM methods) */
691 if (!(adxl_component_count
&& skx_adxl_decode(&res
, err_src
)))
695 mci
= res
.dev
->imc
[res
.imc
].mci
;
700 if (mce
->mcgstatus
& MCG_STATUS_MCIP
)
705 skx_mc_printk(mci
, KERN_DEBUG
, "HANDLING MCE MEMORY ERROR\n");
707 skx_mc_printk(mci
, KERN_DEBUG
, "CPU %d: Machine Check %s: 0x%llx "
708 "Bank %d: 0x%llx\n", mce
->extcpu
, type
,
709 mce
->mcgstatus
, mce
->bank
, mce
->status
);
710 skx_mc_printk(mci
, KERN_DEBUG
, "TSC 0x%llx ", mce
->tsc
);
711 skx_mc_printk(mci
, KERN_DEBUG
, "ADDR 0x%llx ", mce
->addr
);
712 skx_mc_printk(mci
, KERN_DEBUG
, "MISC 0x%llx ", mce
->misc
);
714 skx_mc_printk(mci
, KERN_DEBUG
, "PROCESSOR %u:0x%x TIME %llu SOCKET "
715 "%u APIC 0x%x\n", mce
->cpuvendor
, mce
->cpuid
,
716 mce
->time
, mce
->socketid
, mce
->apicid
);
718 skx_mce_output_error(mci
, mce
, &res
);
720 mce
->kflags
|= MCE_HANDLED_EDAC
;
723 EXPORT_SYMBOL_GPL(skx_mce_check_error
);
725 void skx_remove(void)
728 struct skx_dev
*d
, *tmp
;
732 list_for_each_entry_safe(d
, tmp
, &dev_edac_list
, list
) {
734 for (i
= 0; i
< NUM_IMC
; i
++) {
736 skx_unregister_mci(&d
->imc
[i
]);
739 pci_dev_put(d
->imc
[i
].mdev
);
742 iounmap(d
->imc
[i
].mbase
);
744 for (j
= 0; j
< NUM_CHANNELS
; j
++) {
745 if (d
->imc
[i
].chan
[j
].cdev
)
746 pci_dev_put(d
->imc
[i
].chan
[j
].cdev
);
750 pci_dev_put(d
->util_all
);
752 pci_dev_put(d
->pcu_cr3
);
754 pci_dev_put(d
->sad_all
);
756 pci_dev_put(d
->uracu
);
761 EXPORT_SYMBOL_GPL(skx_remove
);
763 #ifdef CONFIG_EDAC_DEBUG
766 * Exercise the address decode logic by writing an address to
767 * /sys/kernel/debug/edac/{skx,i10nm}_test/addr.
769 static struct dentry
*skx_test
;
771 static int debugfs_u64_set(void *data
, u64 val
)
775 pr_warn_once("Fake error to 0x%llx injected via debugfs\n", val
);
777 memset(&m
, 0, sizeof(m
));
778 /* ADDRV + MemRd + Unknown channel */
779 m
.status
= MCI_STATUS_ADDRV
+ 0x90;
780 /* One corrected error */
781 m
.status
|= BIT_ULL(MCI_STATUS_CEC_SHIFT
);
783 skx_mce_check_error(NULL
, 0, &m
);
787 DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo
, NULL
, debugfs_u64_set
, "%llu\n");
789 void skx_setup_debug(const char *name
)
791 skx_test
= edac_debugfs_create_dir(name
);
795 if (!edac_debugfs_create_file("addr", 0200, skx_test
,
796 NULL
, &fops_u64_wo
)) {
797 debugfs_remove(skx_test
);
801 EXPORT_SYMBOL_GPL(skx_setup_debug
);
803 void skx_teardown_debug(void)
805 debugfs_remove_recursive(skx_test
);
807 EXPORT_SYMBOL_GPL(skx_teardown_debug
);
808 #endif /*CONFIG_EDAC_DEBUG*/
810 MODULE_LICENSE("GPL v2");
811 MODULE_AUTHOR("Tony Luck");
812 MODULE_DESCRIPTION("MC Driver for Intel server processors");