Skip to content

Commit eb2bcdf

Browse files
muralimk-amdbp3tk0v
authored andcommitted
EDAC/amd64: Split ecc_enabled() into dct/umc functions
Call them using a function pointer in pvt->ops. The "ECC enabled" check is done outside of the hardware information gathering done in hw_info_get(). So a high-level function pointer is needed to separate the legacy and modern paths. No functional change is intended. [Yazen: rebased/reworked patch and reworded commit message. ] Signed-off-by: Muralidhara M K <muralidhara.mk@amd.com> Co-developed-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com> Signed-off-by: Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com> Co-developed-by: Yazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20230127170419.1824692-17-yazen.ghannam@amd.com
1 parent 32ecdf8 commit eb2bcdf

2 files changed

Lines changed: 40 additions & 30 deletions

File tree

drivers/edac/amd64_edac.c

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3527,52 +3527,59 @@ static void restore_ecc_error_reporting(struct ecc_settings *s, u16 nid,
35273527
amd64_warn("Error restoring NB MCGCTL settings!\n");
35283528
}
35293529

3530-
static bool ecc_enabled(struct amd64_pvt *pvt)
3530+
static bool dct_ecc_enabled(struct amd64_pvt *pvt)
35313531
{
35323532
u16 nid = pvt->mc_node_id;
35333533
bool nb_mce_en = false;
3534-
u8 ecc_en = 0, i;
3534+
u8 ecc_en = 0;
35353535
u32 value;
35363536

3537-
if (boot_cpu_data.x86 >= 0x17) {
3538-
u8 umc_en_mask = 0, ecc_en_mask = 0;
3539-
struct amd64_umc *umc;
3537+
amd64_read_pci_cfg(pvt->F3, NBCFG, &value);
35403538

3541-
for_each_umc(i) {
3542-
umc = &pvt->umc[i];
3539+
ecc_en = !!(value & NBCFG_ECC_ENABLE);
35433540

3544-
/* Only check enabled UMCs. */
3545-
if (!(umc->sdp_ctrl & UMC_SDP_INIT))
3546-
continue;
3541+
nb_mce_en = nb_mce_bank_enabled_on_node(nid);
3542+
if (!nb_mce_en)
3543+
edac_dbg(0, "NB MCE bank disabled, set MSR 0x%08x[4] on node %d to enable.\n",
3544+
MSR_IA32_MCG_CTL, nid);
35473545

3548-
umc_en_mask |= BIT(i);
3546+
edac_dbg(3, "Node %d: DRAM ECC %s.\n", nid, (ecc_en ? "enabled" : "disabled"));
35493547

3550-
if (umc->umc_cap_hi & UMC_ECC_ENABLED)
3551-
ecc_en_mask |= BIT(i);
3552-
}
3548+
if (!ecc_en || !nb_mce_en)
3549+
return false;
3550+
else
3551+
return true;
3552+
}
35533553

3554-
/* Check whether at least one UMC is enabled: */
3555-
if (umc_en_mask)
3556-
ecc_en = umc_en_mask == ecc_en_mask;
3557-
else
3558-
edac_dbg(0, "Node %d: No enabled UMCs.\n", nid);
3554+
static bool umc_ecc_enabled(struct amd64_pvt *pvt)
3555+
{
3556+
u8 umc_en_mask = 0, ecc_en_mask = 0;
3557+
u16 nid = pvt->mc_node_id;
3558+
struct amd64_umc *umc;
3559+
u8 ecc_en = 0, i;
35593560

3560-
/* Assume UMC MCA banks are enabled. */
3561-
nb_mce_en = true;
3562-
} else {
3563-
amd64_read_pci_cfg(pvt->F3, NBCFG, &value);
3561+
for_each_umc(i) {
3562+
umc = &pvt->umc[i];
3563+
3564+
/* Only check enabled UMCs. */
3565+
if (!(umc->sdp_ctrl & UMC_SDP_INIT))
3566+
continue;
35643567

3565-
ecc_en = !!(value & NBCFG_ECC_ENABLE);
3568+
umc_en_mask |= BIT(i);
35663569

3567-
nb_mce_en = nb_mce_bank_enabled_on_node(nid);
3568-
if (!nb_mce_en)
3569-
edac_dbg(0, "NB MCE bank disabled, set MSR 0x%08x[4] on node %d to enable.\n",
3570-
MSR_IA32_MCG_CTL, nid);
3570+
if (umc->umc_cap_hi & UMC_ECC_ENABLED)
3571+
ecc_en_mask |= BIT(i);
35713572
}
35723573

3574+
/* Check whether at least one UMC is enabled: */
3575+
if (umc_en_mask)
3576+
ecc_en = umc_en_mask == ecc_en_mask;
3577+
else
3578+
edac_dbg(0, "Node %d: No enabled UMCs.\n", nid);
3579+
35733580
edac_dbg(3, "Node %d: DRAM ECC %s.\n", nid, (ecc_en ? "enabled" : "disabled"));
35743581

3575-
if (!ecc_en || !nb_mce_en)
3582+
if (!ecc_en)
35763583
return false;
35773584
else
35783585
return true;
@@ -3678,13 +3685,15 @@ static void hw_info_put(struct amd64_pvt *pvt)
36783685

36793686
static struct low_ops umc_ops = {
36803687
.hw_info_get = umc_hw_info_get,
3688+
.ecc_enabled = umc_ecc_enabled,
36813689
};
36823690

36833691
/* Use Family 16h versions for defaults and adjust as needed below. */
36843692
static struct low_ops dct_ops = {
36853693
.map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
36863694
.dbam_to_cs = f16_dbam_to_chip_select,
36873695
.hw_info_get = dct_hw_info_get,
3696+
.ecc_enabled = dct_ecc_enabled,
36883697
};
36893698

36903699
static int per_family_init(struct amd64_pvt *pvt)
@@ -3910,7 +3919,7 @@ static int probe_one_instance(unsigned int nid)
39103919
goto err_enable;
39113920
}
39123921

3913-
if (!ecc_enabled(pvt)) {
3922+
if (!pvt->ops->ecc_enabled(pvt)) {
39143923
ret = -ENODEV;
39153924

39163925
if (!ecc_enable_override)

drivers/edac/amd64_edac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ struct low_ops {
467467
int (*dbam_to_cs)(struct amd64_pvt *pvt, u8 dct,
468468
unsigned int cs_mode, int cs_mask_nr);
469469
int (*hw_info_get)(struct amd64_pvt *pvt);
470+
bool (*ecc_enabled)(struct amd64_pvt *pvt);
470471
};
471472

472473
int __amd64_read_pci_cfg_dword(struct pci_dev *pdev, int offset,

0 commit comments

Comments
 (0)