Skip to content

Commit d95cf4d

Browse files
author
Borislav Petkov
committed
amd64_edac: Simplify ECC override handling
No need for clearing ecc_enable_override and checking it in two places. Instead, simply check it during probing and act accordingly. Also, rename the flag bitfields according to the functionality they actually represent. What is more, make sure original BIOS ECC settings are restored when the module is unloaded. Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
1 parent 60b341b commit d95cf4d

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

drivers/edac/amd64_edac.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,14 +2553,14 @@ static int amd64_toggle_ecc_err_reporting(struct amd64_pvt *pvt, bool on)
25532553

25542554
if (on) {
25552555
if (reg->l & K8_MSR_MCGCTL_NBE)
2556-
pvt->flags.ecc_report = 1;
2556+
pvt->flags.nb_mce_enable = 1;
25572557

25582558
reg->l |= K8_MSR_MCGCTL_NBE;
25592559
} else {
25602560
/*
2561-
* Turn off ECC reporting only when it was off before
2561+
* Turn off NB MCE reporting only when it was off before
25622562
*/
2563-
if (!pvt->flags.ecc_report)
2563+
if (!pvt->flags.nb_mce_enable)
25642564
reg->l &= ~K8_MSR_MCGCTL_NBE;
25652565
}
25662566
}
@@ -2571,22 +2571,11 @@ static int amd64_toggle_ecc_err_reporting(struct amd64_pvt *pvt, bool on)
25712571
return 0;
25722572
}
25732573

2574-
/*
2575-
* Only if 'ecc_enable_override' is set AND BIOS had ECC disabled, do "we"
2576-
* enable it.
2577-
*/
25782574
static void amd64_enable_ecc_error_reporting(struct mem_ctl_info *mci)
25792575
{
25802576
struct amd64_pvt *pvt = mci->pvt_info;
25812577
u32 value, mask = K8_NBCTL_CECCEn | K8_NBCTL_UECCEn;
25822578

2583-
if (!ecc_enable_override)
2584-
return;
2585-
2586-
amd64_printk(KERN_WARNING,
2587-
"'ecc_enable_override' parameter is active, "
2588-
"Enabling AMD ECC hardware now: CAUTION\n");
2589-
25902579
amd64_read_pci_cfg(pvt->misc_f3_ctl, K8_NBCTL, &value);
25912580

25922581
/* turn on UECCn and CECCEn bits */
@@ -2611,6 +2600,8 @@ static void amd64_enable_ecc_error_reporting(struct mem_ctl_info *mci)
26112600
"This node reports that DRAM ECC is "
26122601
"currently Disabled; ENABLING now\n");
26132602

2603+
pvt->flags.nb_ecc_prev = 0;
2604+
26142605
/* Attempt to turn on DRAM ECC Enable */
26152606
value |= K8_NBCFG_ECC_ENABLE;
26162607
pci_write_config_dword(pvt->misc_f3_ctl, K8_NBCFG, value);
@@ -2625,7 +2616,10 @@ static void amd64_enable_ecc_error_reporting(struct mem_ctl_info *mci)
26252616
amd64_printk(KERN_DEBUG,
26262617
"Hardware accepted DRAM ECC Enable\n");
26272618
}
2619+
} else {
2620+
pvt->flags.nb_ecc_prev = 1;
26282621
}
2622+
26292623
debugf0("NBCFG(2)= 0x%x CHIPKILL= %s ECC_ENABLE= %s\n", value,
26302624
(value & K8_NBCFG_CHIPKILL) ? "Enabled" : "Disabled",
26312625
(value & K8_NBCFG_ECC_ENABLE) ? "Enabled" : "Disabled");
@@ -2644,12 +2638,18 @@ static void amd64_restore_ecc_error_reporting(struct amd64_pvt *pvt)
26442638
value &= ~mask;
26452639
value |= pvt->old_nbctl;
26462640

2647-
/* restore the NB Enable MCGCTL bit */
26482641
pci_write_config_dword(pvt->misc_f3_ctl, K8_NBCTL, value);
26492642

2643+
/* restore previous BIOS DRAM ECC "off" setting which we force-enabled */
2644+
if (!pvt->flags.nb_ecc_prev) {
2645+
amd64_read_pci_cfg(pvt->misc_f3_ctl, K8_NBCFG, &value);
2646+
value &= ~K8_NBCFG_ECC_ENABLE;
2647+
pci_write_config_dword(pvt->misc_f3_ctl, K8_NBCFG, value);
2648+
}
2649+
2650+
/* restore the NB Enable MCGCTL bit */
26502651
if (amd64_toggle_ecc_err_reporting(pvt, OFF))
2651-
amd64_printk(KERN_WARNING, "Error restoring ECC reporting over "
2652-
"MCGCTL!\n");
2652+
amd64_printk(KERN_WARNING, "Error restoring NB MCGCTL settings!\n");
26532653
}
26542654

26552655
/*
@@ -2690,8 +2690,9 @@ static int amd64_check_ecc_enabled(struct amd64_pvt *pvt)
26902690
if (!ecc_enable_override) {
26912691
amd64_printk(KERN_NOTICE, "%s", ecc_msg);
26922692
return -ENODEV;
2693+
} else {
2694+
amd64_printk(KERN_WARNING, "Forcing ECC checking on!\n");
26932695
}
2694-
ecc_enable_override = 0;
26952696
}
26962697

26972698
return 0;

drivers/edac/amd64_edac.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ struct amd64_pvt {
487487
/* misc settings */
488488
struct flags {
489489
unsigned long cf8_extcfg:1;
490-
unsigned long ecc_report:1;
490+
unsigned long nb_mce_enable:1;
491+
unsigned long nb_ecc_prev:1;
491492
} flags;
492493
};
493494

0 commit comments

Comments
 (0)