Skip to content

Commit 5e89191

Browse files
committed
Merge tag 'edac_updates_for_v5.18_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ras/ras
Pull EDAC updates from Borislav Petkov: - Add support for newer AMD family 0x19, models 0x10-... CPUs to amd64_edac - The usual amount of improvements and fixes * tag 'edac_updates_for_v5.18_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/ras/ras: EDAC/altera: Add SDRAM ECC check for U-Boot EDAC/amd64: Add new register offset support and related changes EDAC/amd64: Set memory type per DIMM EDAC/mc: Remove unnecessary cast to char * in edac_align_ptr() EDAC: Use default_groups in kobj_type EDAC: Use proper list of struct attribute for attributes
2 parents 1b74b46 + 1422df5 commit 5e89191

6 files changed

Lines changed: 183 additions & 51 deletions

File tree

drivers/edac/altera_edac.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,46 @@ static int __init __maybe_unused altr_init_a10_ecc_device_type(char *compat)
10831083

10841084
#ifdef CONFIG_EDAC_ALTERA_SDRAM
10851085

1086+
/*
1087+
* A legacy U-Boot bug only enabled memory mapped access to the ECC Enable
1088+
* register if ECC is enabled. Linux checks the ECC Enable register to
1089+
* determine ECC status.
1090+
* Use an SMC call (which always works) to determine ECC enablement.
1091+
*/
1092+
static int altr_s10_sdram_check_ecc_deps(struct altr_edac_device_dev *device)
1093+
{
1094+
const struct edac_device_prv_data *prv = device->data;
1095+
unsigned long sdram_ecc_addr;
1096+
struct arm_smccc_res result;
1097+
struct device_node *np;
1098+
phys_addr_t sdram_addr;
1099+
u32 read_reg;
1100+
int ret;
1101+
1102+
np = of_find_compatible_node(NULL, NULL, "altr,sdr-ctl");
1103+
if (!np)
1104+
goto sdram_err;
1105+
1106+
sdram_addr = of_translate_address(np, of_get_address(np, 0,
1107+
NULL, NULL));
1108+
of_node_put(np);
1109+
sdram_ecc_addr = (unsigned long)sdram_addr + prv->ecc_en_ofst;
1110+
arm_smccc_smc(INTEL_SIP_SMC_REG_READ, sdram_ecc_addr,
1111+
0, 0, 0, 0, 0, 0, &result);
1112+
read_reg = (unsigned int)result.a1;
1113+
ret = (int)result.a0;
1114+
if (!ret && (read_reg & prv->ecc_enable_mask))
1115+
return 0;
1116+
1117+
sdram_err:
1118+
edac_printk(KERN_ERR, EDAC_DEVICE,
1119+
"%s: No ECC present or ECC disabled.\n",
1120+
device->edac_dev_name);
1121+
return -ENODEV;
1122+
}
1123+
10861124
static const struct edac_device_prv_data s10_sdramecc_data = {
1087-
.setup = altr_check_ecc_deps,
1125+
.setup = altr_s10_sdram_check_ecc_deps,
10881126
.ce_clear_mask = ALTR_S10_ECC_SERRPENA,
10891127
.ue_clear_mask = ALTR_S10_ECC_DERRPENA,
10901128
.ecc_enable_mask = ALTR_S10_ECC_EN,

drivers/edac/amd64_edac.c

Lines changed: 88 additions & 21 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 (pvt->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];
@@ -1616,19 +1633,49 @@ static void read_dct_base_mask(struct amd64_pvt *pvt)
16161633
}
16171634
}
16181635

1636+
static void determine_memory_type_df(struct amd64_pvt *pvt)
1637+
{
1638+
struct amd64_umc *umc;
1639+
u32 i;
1640+
1641+
for_each_umc(i) {
1642+
umc = &pvt->umc[i];
1643+
1644+
if (!(umc->sdp_ctrl & UMC_SDP_INIT)) {
1645+
umc->dram_type = MEM_EMPTY;
1646+
continue;
1647+
}
1648+
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+
}
1668+
1669+
edac_dbg(1, " UMC%d DIMM type: %s\n", i, edac_mem_types[umc->dram_type]);
1670+
}
1671+
}
1672+
16191673
static void determine_memory_type(struct amd64_pvt *pvt)
16201674
{
16211675
u32 dram_ctrl, dcsm;
16221676

1623-
if (pvt->umc) {
1624-
if ((pvt->umc[0].dimm_cfg | pvt->umc[1].dimm_cfg) & BIT(5))
1625-
pvt->dram_type = MEM_LRDDR4;
1626-
else if ((pvt->umc[0].dimm_cfg | pvt->umc[1].dimm_cfg) & BIT(4))
1627-
pvt->dram_type = MEM_RDDR4;
1628-
else
1629-
pvt->dram_type = MEM_DDR4;
1630-
return;
1631-
}
1677+
if (pvt->umc)
1678+
return determine_memory_type_df(pvt);
16321679

16331680
switch (pvt->fam) {
16341681
case 0xf:
@@ -2149,6 +2196,7 @@ static int f17_addr_mask_to_cs_size(struct amd64_pvt *pvt, u8 umc,
21492196
{
21502197
u32 addr_mask_orig, addr_mask_deinterleaved;
21512198
u32 msb, weight, num_zero_bits;
2199+
int cs_mask_nr = csrow_nr;
21522200
int dimm, size = 0;
21532201

21542202
/* No Chip Selects are enabled. */
@@ -2164,17 +2212,33 @@ static int f17_addr_mask_to_cs_size(struct amd64_pvt *pvt, u8 umc,
21642212
return size;
21652213

21662214
/*
2167-
* There is one mask per DIMM, and two Chip Selects per DIMM.
2168-
* CS0 and CS1 -> DIMM0
2169-
* 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.
21702231
*/
21712232
dimm = csrow_nr >> 1;
21722233

2234+
if (!fam_type->flags.zn_regs_v2)
2235+
cs_mask_nr >>= 1;
2236+
21732237
/* Asymmetric dual-rank DIMM support. */
21742238
if ((csrow_nr & 1) && (cs_mode & CS_ODD_SECONDARY))
2175-
addr_mask_orig = pvt->csels[umc].csmasks_sec[dimm];
2239+
addr_mask_orig = pvt->csels[umc].csmasks_sec[cs_mask_nr];
21762240
else
2177-
addr_mask_orig = pvt->csels[umc].csmasks[dimm];
2241+
addr_mask_orig = pvt->csels[umc].csmasks[cs_mask_nr];
21782242

21792243
/*
21802244
* The number of zero bits in the mask is equal to the number of bits
@@ -2930,6 +2994,7 @@ static struct amd64_family_type family_types[] = {
29302994
.f0_id = PCI_DEVICE_ID_AMD_19H_M10H_DF_F0,
29312995
.f6_id = PCI_DEVICE_ID_AMD_19H_M10H_DF_F6,
29322996
.max_mcs = 12,
2997+
.flags.zn_regs_v2 = 1,
29332998
.ops = {
29342999
.early_channel_count = f17_early_channel_count,
29353000
.dbam_to_cs = f17_addr_mask_to_cs_size,
@@ -3368,7 +3433,7 @@ static void __read_mc_regs_df(struct amd64_pvt *pvt)
33683433
umc_base = get_umc_base(i);
33693434
umc = &pvt->umc[i];
33703435

3371-
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);
33723437
amd_smn_read(nid, umc_base + UMCCH_UMC_CFG, &umc->umc_cfg);
33733438
amd_smn_read(nid, umc_base + UMCCH_SDP_CTRL, &umc->sdp_ctrl);
33743439
amd_smn_read(nid, umc_base + UMCCH_ECC_CTRL, &umc->ecc_ctrl);
@@ -3452,7 +3517,9 @@ static void read_mc_regs(struct amd64_pvt *pvt)
34523517
read_dct_base_mask(pvt);
34533518

34543519
determine_memory_type(pvt);
3455-
edac_dbg(1, " DIMM type: %s\n", edac_mem_types[pvt->dram_type]);
3520+
3521+
if (!pvt->umc)
3522+
edac_dbg(1, " DIMM type: %s\n", edac_mem_types[pvt->dram_type]);
34563523

34573524
determine_ecc_sym_sz(pvt);
34583525
}
@@ -3548,7 +3615,7 @@ static int init_csrows_df(struct mem_ctl_info *mci)
35483615
pvt->mc_node_id, cs);
35493616

35503617
dimm->nr_pages = get_csrow_nr_pages(pvt, umc, cs);
3551-
dimm->mtype = pvt->dram_type;
3618+
dimm->mtype = pvt->umc[umc].dram_type;
35523619
dimm->edac_mode = edac_mode;
35533620
dimm->dtype = dev_type;
35543621
dimm->grain = 64;

drivers/edac/amd64_edac.h

Lines changed: 23 additions & 1 deletion
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
@@ -344,6 +347,9 @@ struct amd64_umc {
344347
u32 sdp_ctrl; /* SDP Control reg */
345348
u32 ecc_ctrl; /* DRAM ECC Control reg */
346349
u32 umc_cap_hi; /* Capabilities High reg */
350+
351+
/* cache the dram_type */
352+
enum mem_type dram_type;
347353
};
348354

349355
struct amd64_pvt {
@@ -391,7 +397,12 @@ struct amd64_pvt {
391397
/* place to store error injection parameters prior to issue */
392398
struct error_injection injection;
393399

394-
/* cache the dram_type */
400+
/*
401+
* cache the dram_type
402+
*
403+
* NOTE: Don't use this for Family 17h and later.
404+
* Use dram_type in struct amd64_umc instead.
405+
*/
395406
enum mem_type dram_type;
396407

397408
struct amd64_umc *umc; /* UMC registers */
@@ -480,11 +491,22 @@ struct low_ops {
480491
unsigned cs_mode, int cs_mask_nr);
481492
};
482493

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+
483504
struct amd64_family_type {
484505
const char *ctl_name;
485506
u16 f0_id, f1_id, f2_id, f6_id;
486507
/* Maximum number of memory controllers per die/node. */
487508
u8 max_mcs;
509+
struct amd64_family_flags flags;
488510
struct low_ops ops;
489511
};
490512

drivers/edac/edac_device_sysfs.c

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,14 @@ CTL_INFO_ATTR(poll_msec, S_IRUGO | S_IWUSR,
163163
edac_device_ctl_poll_msec_show, edac_device_ctl_poll_msec_store);
164164

165165
/* Base Attributes of the EDAC_DEVICE ECC object */
166-
static struct ctl_info_attribute *device_ctrl_attr[] = {
167-
&attr_ctl_info_panic_on_ue,
168-
&attr_ctl_info_log_ue,
169-
&attr_ctl_info_log_ce,
170-
&attr_ctl_info_poll_msec,
166+
static struct attribute *device_ctrl_attrs[] = {
167+
&attr_ctl_info_panic_on_ue.attr,
168+
&attr_ctl_info_log_ue.attr,
169+
&attr_ctl_info_log_ce.attr,
170+
&attr_ctl_info_poll_msec.attr,
171171
NULL,
172172
};
173+
ATTRIBUTE_GROUPS(device_ctrl);
173174

174175
/*
175176
* edac_device_ctrl_master_release
@@ -217,7 +218,7 @@ static void edac_device_ctrl_master_release(struct kobject *kobj)
217218
static struct kobj_type ktype_device_ctrl = {
218219
.release = edac_device_ctrl_master_release,
219220
.sysfs_ops = &device_ctl_info_ops,
220-
.default_attrs = (struct attribute **)device_ctrl_attr,
221+
.default_groups = device_ctrl_groups,
221222
};
222223

223224
/*
@@ -389,17 +390,18 @@ INSTANCE_ATTR(ce_count, S_IRUGO, instance_ce_count_show, NULL);
389390
INSTANCE_ATTR(ue_count, S_IRUGO, instance_ue_count_show, NULL);
390391

391392
/* list of edac_dev 'instance' attributes */
392-
static struct instance_attribute *device_instance_attr[] = {
393-
&attr_instance_ce_count,
394-
&attr_instance_ue_count,
393+
static struct attribute *device_instance_attrs[] = {
394+
&attr_instance_ce_count.attr,
395+
&attr_instance_ue_count.attr,
395396
NULL,
396397
};
398+
ATTRIBUTE_GROUPS(device_instance);
397399

398400
/* The 'ktype' for each edac_dev 'instance' */
399401
static struct kobj_type ktype_instance_ctrl = {
400402
.release = edac_device_ctrl_instance_release,
401403
.sysfs_ops = &device_instance_ops,
402-
.default_attrs = (struct attribute **)device_instance_attr,
404+
.default_groups = device_instance_groups,
403405
};
404406

405407
/* edac_dev -> instance -> block information */
@@ -487,17 +489,18 @@ BLOCK_ATTR(ce_count, S_IRUGO, block_ce_count_show, NULL);
487489
BLOCK_ATTR(ue_count, S_IRUGO, block_ue_count_show, NULL);
488490

489491
/* list of edac_dev 'block' attributes */
490-
static struct edac_dev_sysfs_block_attribute *device_block_attr[] = {
491-
&attr_block_ce_count,
492-
&attr_block_ue_count,
492+
static struct attribute *device_block_attrs[] = {
493+
&attr_block_ce_count.attr,
494+
&attr_block_ue_count.attr,
493495
NULL,
494496
};
497+
ATTRIBUTE_GROUPS(device_block);
495498

496499
/* The 'ktype' for each edac_dev 'block' */
497500
static struct kobj_type ktype_block_ctrl = {
498501
.release = edac_device_ctrl_block_release,
499502
.sysfs_ops = &device_block_ops,
500-
.default_attrs = (struct attribute **)device_block_attr,
503+
.default_groups = device_block_groups,
501504
};
502505

503506
/* block ctor/dtor code */

drivers/edac/edac_mc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ void *edac_align_ptr(void **p, unsigned int size, int n_elems)
213213
else if (size > sizeof(char))
214214
align = sizeof(short);
215215
else
216-
return (char *)ptr;
216+
return ptr;
217217

218218
r = (unsigned long)ptr % align;
219219

220220
if (r == 0)
221-
return (char *)ptr;
221+
return ptr;
222222

223223
*p += align - r;
224224

0 commit comments

Comments
 (0)