Skip to content

Commit 2151c84

Browse files
yghannamsuryasaimadhu
authored andcommitted
EDAC/amd64: Add new register offset support and related changes
Introduce a "family flags" bitmask that can be used to indicate any special behavior needed on a per-family basis. Add a flag to indicate a system uses the new register offsets introduced with Family 19h Model 10h. Use this flag to account for register offset changes, a new bitfield indicating DDR5 use on a memory controller, and to set the proper number of chip select masks. Rework f17_addr_mask_to_cs_size() to properly handle the change in chip select masks. And update code comments to reflect the updated Chip Select, DIMM, and Mask relationships. [uninitialized variable warning] Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Yazen Ghannam <yazen.ghannam@amd.com> Signed-off-by: Borislav Petkov <bp@suse.de> Reviewed-by: William Roche <william.roche@oracle.com> Link: https://lore.kernel.org/r/20220202144307.2678405-3-yazen.ghannam@amd.com
1 parent 75aeaaf commit 2151c84

2 files changed

Lines changed: 78 additions & 16 deletions

File tree

drivers/edac/amd64_edac.c

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ static struct msr __percpu *msrs;
1515

1616
static struct amd64_family_type *fam_type;
1717

18+
static inline u32 get_umc_reg(u32 reg)
19+
{
20+
if (!fam_type->flags.zn_regs_v2)
21+
return reg;
22+
23+
switch (reg) {
24+
case UMCCH_ADDR_CFG: return UMCCH_ADDR_CFG_DDR5;
25+
case UMCCH_ADDR_MASK_SEC: return UMCCH_ADDR_MASK_SEC_DDR5;
26+
case UMCCH_DIMM_CFG: return UMCCH_DIMM_CFG_DDR5;
27+
}
28+
29+
WARN_ONCE(1, "%s: unknown register 0x%x", __func__, reg);
30+
return 0;
31+
}
32+
1833
/* Per-node stuff */
1934
static struct ecc_settings **ecc_stngs;
2035

@@ -1429,8 +1444,10 @@ static void __dump_misc_regs_df(struct amd64_pvt *pvt)
14291444
edac_dbg(1, "UMC%d x16 DIMMs present: %s\n",
14301445
i, (umc->dimm_cfg & BIT(7)) ? "yes" : "no");
14311446

1432-
if (umc->dram_type == MEM_LRDDR4) {
1433-
amd_smn_read(pvt->mc_node_id, umc_base + UMCCH_ADDR_CFG, &tmp);
1447+
if (umc->dram_type == MEM_LRDDR4 || umc->dram_type == MEM_LRDDR5) {
1448+
amd_smn_read(pvt->mc_node_id,
1449+
umc_base + get_umc_reg(UMCCH_ADDR_CFG),
1450+
&tmp);
14341451
edac_dbg(1, "UMC%d LRDIMM %dx rank multiply\n",
14351452
i, 1 << ((tmp >> 4) & 0x3));
14361453
}
@@ -1505,7 +1522,7 @@ static void prep_chip_selects(struct amd64_pvt *pvt)
15051522

15061523
for_each_umc(umc) {
15071524
pvt->csels[umc].b_cnt = 4;
1508-
pvt->csels[umc].m_cnt = 2;
1525+
pvt->csels[umc].m_cnt = fam_type->flags.zn_regs_v2 ? 4 : 2;
15091526
}
15101527

15111528
} else {
@@ -1545,7 +1562,7 @@ static void read_umc_base_mask(struct amd64_pvt *pvt)
15451562
}
15461563

15471564
umc_mask_reg = get_umc_base(umc) + UMCCH_ADDR_MASK;
1548-
umc_mask_reg_sec = get_umc_base(umc) + UMCCH_ADDR_MASK_SEC;
1565+
umc_mask_reg_sec = get_umc_base(umc) + get_umc_reg(UMCCH_ADDR_MASK_SEC);
15491566

15501567
for_each_chip_select_mask(cs, umc, pvt) {
15511568
mask = &pvt->csels[umc].csmasks[cs];
@@ -1629,12 +1646,25 @@ static void determine_memory_type_df(struct amd64_pvt *pvt)
16291646
continue;
16301647
}
16311648

1632-
if (umc->dimm_cfg & BIT(5))
1633-
umc->dram_type = MEM_LRDDR4;
1634-
else if (umc->dimm_cfg & BIT(4))
1635-
umc->dram_type = MEM_RDDR4;
1636-
else
1637-
umc->dram_type = MEM_DDR4;
1649+
/*
1650+
* Check if the system supports the "DDR Type" field in UMC Config
1651+
* and has DDR5 DIMMs in use.
1652+
*/
1653+
if (fam_type->flags.zn_regs_v2 && ((umc->umc_cfg & GENMASK(2, 0)) == 0x1)) {
1654+
if (umc->dimm_cfg & BIT(5))
1655+
umc->dram_type = MEM_LRDDR5;
1656+
else if (umc->dimm_cfg & BIT(4))
1657+
umc->dram_type = MEM_RDDR5;
1658+
else
1659+
umc->dram_type = MEM_DDR5;
1660+
} else {
1661+
if (umc->dimm_cfg & BIT(5))
1662+
umc->dram_type = MEM_LRDDR4;
1663+
else if (umc->dimm_cfg & BIT(4))
1664+
umc->dram_type = MEM_RDDR4;
1665+
else
1666+
umc->dram_type = MEM_DDR4;
1667+
}
16381668

16391669
edac_dbg(1, " UMC%d DIMM type: %s\n", i, edac_mem_types[umc->dram_type]);
16401670
}
@@ -2166,6 +2196,7 @@ static int f17_addr_mask_to_cs_size(struct amd64_pvt *pvt, u8 umc,
21662196
{
21672197
u32 addr_mask_orig, addr_mask_deinterleaved;
21682198
u32 msb, weight, num_zero_bits;
2199+
int cs_mask_nr = csrow_nr;
21692200
int dimm, size = 0;
21702201

21712202
/* No Chip Selects are enabled. */
@@ -2181,17 +2212,33 @@ static int f17_addr_mask_to_cs_size(struct amd64_pvt *pvt, u8 umc,
21812212
return size;
21822213

21832214
/*
2184-
* There is one mask per DIMM, and two Chip Selects per DIMM.
2185-
* CS0 and CS1 -> DIMM0
2186-
* CS2 and CS3 -> DIMM1
2215+
* Family 17h introduced systems with one mask per DIMM,
2216+
* and two Chip Selects per DIMM.
2217+
*
2218+
* CS0 and CS1 -> MASK0 / DIMM0
2219+
* CS2 and CS3 -> MASK1 / DIMM1
2220+
*
2221+
* Family 19h Model 10h introduced systems with one mask per Chip Select,
2222+
* and two Chip Selects per DIMM.
2223+
*
2224+
* CS0 -> MASK0 -> DIMM0
2225+
* CS1 -> MASK1 -> DIMM0
2226+
* CS2 -> MASK2 -> DIMM1
2227+
* CS3 -> MASK3 -> DIMM1
2228+
*
2229+
* Keep the mask number equal to the Chip Select number for newer systems,
2230+
* and shift the mask number for older systems.
21872231
*/
21882232
dimm = csrow_nr >> 1;
21892233

2234+
if (!fam_type->flags.zn_regs_v2)
2235+
cs_mask_nr >>= 1;
2236+
21902237
/* Asymmetric dual-rank DIMM support. */
21912238
if ((csrow_nr & 1) && (cs_mode & CS_ODD_SECONDARY))
2192-
addr_mask_orig = pvt->csels[umc].csmasks_sec[dimm];
2239+
addr_mask_orig = pvt->csels[umc].csmasks_sec[cs_mask_nr];
21932240
else
2194-
addr_mask_orig = pvt->csels[umc].csmasks[dimm];
2241+
addr_mask_orig = pvt->csels[umc].csmasks[cs_mask_nr];
21952242

21962243
/*
21972244
* The number of zero bits in the mask is equal to the number of bits
@@ -2947,6 +2994,7 @@ static struct amd64_family_type family_types[] = {
29472994
.f0_id = PCI_DEVICE_ID_AMD_19H_M10H_DF_F0,
29482995
.f6_id = PCI_DEVICE_ID_AMD_19H_M10H_DF_F6,
29492996
.max_mcs = 12,
2997+
.flags.zn_regs_v2 = 1,
29502998
.ops = {
29512999
.early_channel_count = f17_early_channel_count,
29523000
.dbam_to_cs = f17_addr_mask_to_cs_size,
@@ -3385,7 +3433,7 @@ static void __read_mc_regs_df(struct amd64_pvt *pvt)
33853433
umc_base = get_umc_base(i);
33863434
umc = &pvt->umc[i];
33873435

3388-
amd_smn_read(nid, umc_base + UMCCH_DIMM_CFG, &umc->dimm_cfg);
3436+
amd_smn_read(nid, umc_base + get_umc_reg(UMCCH_DIMM_CFG), &umc->dimm_cfg);
33893437
amd_smn_read(nid, umc_base + UMCCH_UMC_CFG, &umc->umc_cfg);
33903438
amd_smn_read(nid, umc_base + UMCCH_SDP_CTRL, &umc->sdp_ctrl);
33913439
amd_smn_read(nid, umc_base + UMCCH_ECC_CTRL, &umc->ecc_ctrl);

drivers/edac/amd64_edac.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,11 @@
273273
#define UMCCH_BASE_ADDR_SEC 0x10
274274
#define UMCCH_ADDR_MASK 0x20
275275
#define UMCCH_ADDR_MASK_SEC 0x28
276+
#define UMCCH_ADDR_MASK_SEC_DDR5 0x30
276277
#define UMCCH_ADDR_CFG 0x30
278+
#define UMCCH_ADDR_CFG_DDR5 0x40
277279
#define UMCCH_DIMM_CFG 0x80
280+
#define UMCCH_DIMM_CFG_DDR5 0x90
278281
#define UMCCH_UMC_CFG 0x100
279282
#define UMCCH_SDP_CTRL 0x104
280283
#define UMCCH_ECC_CTRL 0x14C
@@ -488,11 +491,22 @@ struct low_ops {
488491
unsigned cs_mode, int cs_mask_nr);
489492
};
490493

494+
struct amd64_family_flags {
495+
/*
496+
* Indicates that the system supports the new register offsets, etc.
497+
* first introduced with Family 19h Model 10h.
498+
*/
499+
__u64 zn_regs_v2 : 1,
500+
501+
__reserved : 63;
502+
};
503+
491504
struct amd64_family_type {
492505
const char *ctl_name;
493506
u16 f0_id, f1_id, f2_id, f6_id;
494507
/* Maximum number of memory controllers per die/node. */
495508
u8 max_mcs;
509+
struct amd64_family_flags flags;
496510
struct low_ops ops;
497511
};
498512

0 commit comments

Comments
 (0)