Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ryan Chen <ryan_chen@aspeedtech.com>
To: Stefan Schaeckeler <sschaeck@cisco.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>, Joel Stanley <joel@jms.id.au>,
	Andrew Jeffery <andrew@codeconstruct.com.au>,
	Borislav Petkov <bp@alien8.de>, Tony Luck <tony.luck@intel.com>,
	Billy Tsai <billy_tsai@aspeedtech.com>
Cc: <devicetree@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-aspeed@lists.ozlabs.org>, <linux-kernel@vger.kernel.org>,
	<linux-edac@vger.kernel.org>,
	Ryan Chen <ryan_chen@aspeedtech.com>
Subject: [PATCH v7 09/10] EDAC/aspeed: Add AST2700 support
Date: Mon, 30 Nov 2026 15:24:36 +0800	[thread overview]
Message-ID: <20261130-edac-v7-9-3aaf6d243f07@aspeedtech.com> (raw)
In-Reply-To: <20261130-edac-v7-0-3aaf6d243f07@aspeedtech.com>

Add support for the memory controller in the Aspeed AST2700.

When corrected and uncorrected errors are pending at the same time,
give the failure address to the uncorrected ones, since they matter
more.

Unmask only the ECC interrupts and mask everything else, rather than
trust whatever mask was left set, since the driver doesn't handle the
other events on that line.

Signed-off-by: Ryan Chen <ryan_chen@aspeedtech.com>
---
Tested on an AST2700 by injecting a correctable error with the memory
controller's error injection; the failure address is above 4 GiB:

  # mw 12c00000 1688a8a8; mw 12c00080 31
  EDAC MC0: 1 CE on mc#0csrow#0channel#0 (csrow:0 channel:0 page:0x40ac10 offset:0xb10 grain:16 syndrome:0x0)
---
 drivers/edac/aspeed_edac.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/drivers/edac/aspeed_edac.c b/drivers/edac/aspeed_edac.c
index 36599ddf589a..ff92f36e0297 100644
--- a/drivers/edac/aspeed_edac.c
+++ b/drivers/edac/aspeed_edac.c
@@ -3,6 +3,7 @@
  * Copyright 2018, 2019 Cisco Systems
  */
 
+#include <linux/bitfield.h>
 #include <linux/edac.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
@@ -30,6 +31,22 @@
 #define ASPEED_MCR_INTR_CTRL_CNT_UNREC  GENMASK(15, 12)
 #define ASPEED_MCR_INTR_CTRL_ENABLE     (BIT(0) | BIT(1))
 
+#define AST2700_INT_STS			0x04
+#define AST2700_INT_CLR			0x08
+#define AST2700_INT_MASK		0x0c
+#define   AST2700_INT_ECC_RECOVERABLE	BIT(5)
+#define   AST2700_INT_ECC_UNRECOVERABLE	BIT(4)
+#define   AST2700_INT_ECC		(AST2700_INT_ECC_RECOVERABLE | \
+					 AST2700_INT_ECC_UNRECOVERABLE)
+#define   AST2700_INT_ALL		GENMASK(16, 0)
+#define AST2700_MCFG			0x10
+#define   AST2700_MCFG_ECC		BIT(6)
+#define   AST2700_MCFG_DRAM_TYPE	BIT(0) /* 0=DDR4, 1=DDR5 */
+#define AST2700_ECC_STS			0x78
+#define   AST2700_ECC_REC_CNT		GENMASK(15, 8)
+#define   AST2700_ECC_UNREC_CNT		GENMASK(7, 0)
+#define AST2700_ECC_FAIL_ADDR		0x7c
+
 struct aspeed_edac;
 
 struct aspeed_edac_chip {
@@ -198,6 +215,58 @@ static void mcr_set_irq(struct aspeed_edac *priv, bool enable)
 			enable ? ASPEED_MCR_INTR_CTRL_ENABLE : 0);
 }
 
+static irqreturn_t ast2700_isr(int irq, void *arg)
+{
+	struct mem_ctl_info *mci = arg;
+	struct aspeed_edac *priv = mci->pvt_info;
+	u32 int_sts, ecc_sts, fail_addr;
+	u8 rec_cnt, un_rec_cnt;
+	phys_addr_t addr;
+
+	int_sts = readl(priv->regs + AST2700_INT_STS);
+	if (!(int_sts & AST2700_INT_ECC))
+		return IRQ_NONE;
+
+	ecc_sts = readl(priv->regs + AST2700_ECC_STS);
+	fail_addr = readl(priv->regs + AST2700_ECC_FAIL_ADDR);
+
+	/* clear only the ECC interrupts */
+	writel(int_sts & AST2700_INT_ECC, priv->regs + AST2700_INT_CLR);
+
+	rec_cnt = FIELD_GET(AST2700_ECC_REC_CNT, ecc_sts);
+	un_rec_cnt = FIELD_GET(AST2700_ECC_UNREC_CNT, ecc_sts);
+
+	/* the register holds address bits [35:4], in units of 16 bytes */
+	addr = (phys_addr_t)fail_addr << 4;
+
+	/*
+	 * Only the address of the latest failure is recorded, shared by both
+	 * error types. When both occurred, attribute it to the uncorrectable
+	 * errors and report the corrected ones without an address.
+	 */
+	if (un_rec_cnt) {
+		count_un_rec(mci, un_rec_cnt, addr, true);
+		count_rec(mci, rec_cnt, 0, false);
+	} else if (rec_cnt) {
+		count_rec(mci, rec_cnt, addr, true);
+	} else {
+		dev_dbg_ratelimited(mci->pdev, "received interrupt with no ECC counters set\n");
+	}
+
+	return IRQ_HANDLED;
+}
+
+static void ast2700_set_irq(struct aspeed_edac *priv, bool enable)
+{
+	u32 val = AST2700_INT_ALL;
+
+	/* interrupts are enabled by clearing their mask bits */
+	if (enable)
+		val &= ~AST2700_INT_ECC;
+
+	writel(val, priv->regs + AST2700_INT_MASK);
+}
+
 static int config_irq(void *ctx, struct platform_device *pdev)
 {
 	struct mem_ctl_info *mci = ctx;
@@ -398,10 +467,21 @@ static const struct aspeed_edac_chip ast2600_edac = {
 	.set_irq = mcr_set_irq,
 };
 
+static const struct aspeed_edac_chip ast2700_edac = {
+	.conf_reg = AST2700_MCFG,
+	.conf_ecc = AST2700_MCFG_ECC,
+	.conf_dram_type = AST2700_MCFG_DRAM_TYPE,
+	.dram_type = { MEM_DDR4, MEM_DDR5 },
+	.mtype_cap = MEM_FLAG_DDR4 | MEM_FLAG_DDR5,
+	.isr = ast2700_isr,
+	.set_irq = ast2700_set_irq,
+};
+
 static const struct of_device_id aspeed_of_match[] = {
 	{ .compatible = "aspeed,ast2400-sdram-edac", .data = &ast2400_edac },
 	{ .compatible = "aspeed,ast2500-sdram-edac", .data = &ast2400_edac },
 	{ .compatible = "aspeed,ast2600-sdram-edac", .data = &ast2600_edac },
+	{ .compatible = "aspeed,ast2700-sdram-edac", .data = &ast2700_edac },
 	{},
 };
 

-- 
2.34.1



  parent reply	other threads:[~2026-11-30  7:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30  7:24 [PATCH v7 00/10] Add Aspeed AST2700 SDRAM EDAC support Ryan Chen
2026-11-30  7:24 ` [PATCH v7 01/10] EDAC/aspeed: Stop keeping driver state in global variables Ryan Chen
2026-11-30  7:24 ` [PATCH v7 02/10] EDAC/aspeed: Replace regmap with direct register access Ryan Chen
2026-11-30  7:24 ` [PATCH v7 03/10] EDAC/aspeed: Put the differences between chips in a table Ryan Chen
2026-11-30  7:24 ` [PATCH v7 05/10] EDAC/aspeed: Let each chip provide its own interrupt handling Ryan Chen
2026-11-30  7:24 ` [PATCH v7 06/10] EDAC/aspeed: Allow reporting an error without an address Ryan Chen
2026-11-30  7:24 ` [PATCH v7 07/10] EDAC/aspeed: Allow error addresses above 4 GiB Ryan Chen
2026-11-30  7:24 ` [PATCH v7 08/10] EDAC/aspeed: Disable interrupts before requesting the interrupt line Ryan Chen
2026-11-30  7:24 ` Ryan Chen [this message]
2026-11-30  7:24 ` [PATCH v7 10/10] MAINTAINERS: Step down as Aspeed AST2500 EDAC driver maintainer Ryan Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130-edac-v7-9-3aaf6d243f07@aspeedtech.com \
    --to=ryan_chen@aspeedtech.com \
    --cc=andrew@codeconstruct.com.au \
    --cc=billy_tsai@aspeedtech.com \
    --cc=bp@alien8.de \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=joel@jms.id.au \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-aspeed@lists.ozlabs.org \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sschaeck@cisco.com \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox