Skip to content

Commit be3468e

Browse files
author
Borislav Petkov
committed
amd64_edac: cleanup amd64_check_ecc_enabled
Simplify code flow and make sure return value is always valid since further driver init depends on it. Carve out long warning string and make code more readable. Shorten some names, while at it. There should be no functional change resulting from this patch. Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
1 parent 6a81269 commit be3468e

File tree

1 file changed

+25
-51
lines changed

1 file changed

+25
-51
lines changed

drivers/edac/amd64_edac.c

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,7 +2783,7 @@ static void check_mcg_ctl(void *ret)
27832783
}
27842784

27852785
/* check MCG_CTL on all the cpus on this node */
2786-
static int amd64_mcg_ctl_enabled_on_cpus(const cpumask_t *mask)
2786+
static int mcg_ctl_enabled_on_node(const struct cpumask *mask)
27872787
{
27882788
int ret = 1;
27892789
preempt_disable();
@@ -2799,71 +2799,45 @@ static int amd64_mcg_ctl_enabled_on_cpus(const cpumask_t *mask)
27992799
* the memory system completely. A command line option allows to force-enable
28002800
* hardware ECC later in amd64_enable_ecc_error_reporting().
28012801
*/
2802+
static const char *ecc_warning =
2803+
"WARNING: ECC is disabled by BIOS. Module will NOT be loaded.\n"
2804+
" Either Enable ECC in the BIOS, or set 'ecc_enable_override'.\n"
2805+
" Also, use of the override can cause unknown side effects.\n";
2806+
28022807
static int amd64_check_ecc_enabled(struct amd64_pvt *pvt)
28032808
{
28042809
u32 value;
2805-
int err = 0, ret = 0;
2806-
u8 ecc_enabled = 0;
2810+
int err = 0;
2811+
u8 ecc_enabled = 0, mcg_ctl_en = 0;
28072812

28082813
err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCFG, &value);
28092814
if (err)
28102815
debugf0("Reading K8_NBCTL failed\n");
28112816

28122817
ecc_enabled = !!(value & K8_NBCFG_ECC_ENABLE);
2818+
if (!ecc_enabled)
2819+
amd64_printk(KERN_WARNING, "This node reports that Memory ECC "
2820+
"is currently disabled, set F3x%x[22] (%s).\n",
2821+
K8_NBCFG, pci_name(pvt->misc_f3_ctl));
2822+
else
2823+
amd64_printk(KERN_INFO, "ECC is enabled by BIOS.\n");
28132824

2814-
ret = amd64_mcg_ctl_enabled_on_cpus(cpumask_of_node(pvt->mc_node_id));
2815-
2816-
debugf0("K8_NBCFG=0x%x, DRAM ECC is %s\n", value,
2817-
(value & K8_NBCFG_ECC_ENABLE ? "enabled" : "disabled"));
2818-
2819-
if (!ecc_enabled || !ret) {
2820-
if (!ecc_enabled) {
2821-
amd64_printk(KERN_WARNING, "This node reports that "
2822-
"Memory ECC is currently "
2823-
"disabled.\n");
2825+
mcg_ctl_en = mcg_ctl_enabled_on_node(cpumask_of_node(pvt->mc_node_id));
2826+
if (!mcg_ctl_en)
2827+
amd64_printk(KERN_WARNING, "NB MCE bank disabled, set MSR "
2828+
"0x%08x[4] on node %d to enable.\n",
2829+
MSR_IA32_MCG_CTL, pvt->mc_node_id);
28242830

2825-
amd64_printk(KERN_WARNING, "bit 0x%lx in register "
2826-
"F3x%x of the MISC_CONTROL device (%s) "
2827-
"should be enabled\n", K8_NBCFG_ECC_ENABLE,
2828-
K8_NBCFG, pci_name(pvt->misc_f3_ctl));
2829-
}
2830-
if (!ret) {
2831-
amd64_printk(KERN_WARNING, "bit 0x%016lx in MSR 0x%08x "
2832-
"of node %d should be enabled\n",
2833-
K8_MSR_MCGCTL_NBE, MSR_IA32_MCG_CTL,
2834-
pvt->mc_node_id);
2835-
}
2831+
if (!ecc_enabled || !mcg_ctl_en) {
28362832
if (!ecc_enable_override) {
2837-
amd64_printk(KERN_WARNING, "WARNING: ECC is NOT "
2838-
"currently enabled by the BIOS. Module "
2839-
"will NOT be loaded.\n"
2840-
" Either Enable ECC in the BIOS, "
2841-
"or use the 'ecc_enable_override' "
2842-
"parameter.\n"
2843-
" Might be a BIOS bug, if BIOS says "
2844-
"ECC is enabled\n"
2845-
" Use of the override can cause "
2846-
"unknown side effects.\n");
2847-
ret = -ENODEV;
2848-
} else
2849-
/*
2850-
* enable further driver loading if ECC enable is
2851-
* overridden.
2852-
*/
2853-
ret = 0;
2854-
} else {
2855-
amd64_printk(KERN_INFO,
2856-
"ECC is enabled by BIOS, Proceeding "
2857-
"with EDAC module initialization\n");
2858-
2859-
/* Signal good ECC status */
2860-
ret = 0;
2861-
2833+
amd64_printk(KERN_WARNING, "%s", ecc_warning);
2834+
return -ENODEV;
2835+
}
2836+
} else
28622837
/* CLEAR the override, since BIOS controlled it */
28632838
ecc_enable_override = 0;
2864-
}
28652839

2866-
return ret;
2840+
return 0;
28672841
}
28682842

28692843
struct mcidev_sysfs_attribute sysfs_attrs[ARRAY_SIZE(amd64_dbg_attrs) +

0 commit comments

Comments
 (0)