From: santino.wang <santino.wang@mediatek.com>
To: Matthias Brugger <matthias.bgg@gmail.com>,
AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>
Cc: <linux-mediatek@lists.infradead.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <light.chen@mediatek.com>,
<Fred-WY.Chen@mediatek.com>, <arnab.layek@mediatek.com>,
Santino Wang <santino.wang@mediatek.com>
Subject: [RFC PATCH 09/11] soc: mediatek: dram-ecc: add a generic netlink event interface
Date: Mon, 2 Nov 2026 17:23:31 +0800 [thread overview]
Message-ID: <20261102092334.138759-10-santino.wang@mediatek.com> (raw)
In-Reply-To: <20261102092334.138759-1-santino.wang@mediatek.com>
From: Santino Wang <santino.wang@mediatek.com>
Multicast every decoded corrected and uncorrectable error to user
space through a generic netlink family, so a monitoring daemon can
subscribe to events instead of polling the counters.
Signed-off-by: Santino Wang <santino.wang@mediatek.com>
---
drivers/soc/mediatek/dram-ecc/core/Makefile | 1 +
.../mediatek/dram-ecc/core/ghes_notifier.c | 3 +
drivers/soc/mediatek/dram-ecc/core/main.c | 10 ++-
drivers/soc/mediatek/dram-ecc/core/netlink.c | 83 +++++++++++++++++++
drivers/soc/mediatek/dram-ecc/core/netlink.h | 14 ++++
include/uapi/linux/mtk_dram_ecc_netlink.h | 44 ++++++++++
6 files changed, 154 insertions(+), 1 deletion(-)
create mode 100644 drivers/soc/mediatek/dram-ecc/core/netlink.c
create mode 100644 drivers/soc/mediatek/dram-ecc/core/netlink.h
create mode 100644 include/uapi/linux/mtk_dram_ecc_netlink.h
diff --git a/drivers/soc/mediatek/dram-ecc/core/Makefile b/drivers/soc/mediatek/dram-ecc/core/Makefile
index 7c973831c9ef..1e2764914e9c 100644
--- a/drivers/soc/mediatek/dram-ecc/core/Makefile
+++ b/drivers/soc/mediatek/dram-ecc/core/Makefile
@@ -6,6 +6,7 @@ mtk_dram_ecc-y := \
main.o \
smc.o \
ghes_notifier.o \
+ netlink.o \
trace.o \
counters.o \
addresses.o \
diff --git a/drivers/soc/mediatek/dram-ecc/core/ghes_notifier.c b/drivers/soc/mediatek/dram-ecc/core/ghes_notifier.c
index a010ca652e86..701b0b28d358 100644
--- a/drivers/soc/mediatek/dram-ecc/core/ghes_notifier.c
+++ b/drivers/soc/mediatek/dram-ecc/core/ghes_notifier.c
@@ -28,6 +28,7 @@
#include "mtk_dram_ecc_event.h"
#include "ghes_notifier.h"
#include "counters.h"
+#include "netlink.h"
#include "policy/policy.h"
#include "trace.h"
@@ -256,6 +257,7 @@ static int mtk_ghes_vendor_cb(struct notifier_block *nb, unsigned long severity,
if (ret == NOTIFY_BAD)
pr_warn_ratelimited("mtk-dram-ecc: kernel client rejected CE event for spa=0x%llx\n",
evt.spa);
+ mtk_dram_ecc_netlink_notify(&evt);
} else {
unsigned long pfn = evt.spa >> PAGE_SHIFT;
@@ -305,6 +307,7 @@ static int mtk_ghes_vendor_cb(struct notifier_block *nb, unsigned long severity,
if (ret == NOTIFY_BAD)
pr_warn_ratelimited("mtk-dram-ecc: kernel client rejected UCE event for spa=0x%llx\n",
evt.spa);
+ mtk_dram_ecc_netlink_notify(&evt);
}
return NOTIFY_OK;
diff --git a/drivers/soc/mediatek/dram-ecc/core/main.c b/drivers/soc/mediatek/dram-ecc/core/main.c
index 315bdcbd650a..320631b3a044 100644
--- a/drivers/soc/mediatek/dram-ecc/core/main.c
+++ b/drivers/soc/mediatek/dram-ecc/core/main.c
@@ -10,6 +10,7 @@
#include "ghes_notifier.h"
#include "counters.h"
#include "addresses.h"
+#include "netlink.h"
#include "trace.h"
static struct class *mtk_dram_ecc_class;
@@ -37,10 +38,14 @@ static int __init mtk_dram_ecc_init(void)
goto err_class;
}
- ret = mtk_dram_ecc_policy_init(mtk_dram_ecc_dev);
+ ret = mtk_dram_ecc_netlink_init();
if (ret)
goto err_dev;
+ ret = mtk_dram_ecc_policy_init(mtk_dram_ecc_dev);
+ if (ret)
+ goto err_netlink;
+
ret = mtk_dram_ecc_counters_init(&mtk_dram_ecc_dev->kobj);
if (ret)
goto err_policy;
@@ -68,6 +73,8 @@ static int __init mtk_dram_ecc_init(void)
mtk_dram_ecc_counters_exit();
err_policy:
mtk_dram_ecc_policy_exit(mtk_dram_ecc_dev);
+err_netlink:
+ mtk_dram_ecc_netlink_exit();
err_dev:
device_destroy(mtk_dram_ecc_class, MKDEV(0, 0));
err_class:
@@ -86,6 +93,7 @@ static void __exit mtk_dram_ecc_exit(void)
mtk_dram_ecc_addresses_exit();
mtk_dram_ecc_counters_exit();
mtk_dram_ecc_policy_exit(mtk_dram_ecc_dev);
+ mtk_dram_ecc_netlink_exit();
device_destroy(mtk_dram_ecc_class, MKDEV(0, 0));
class_destroy(mtk_dram_ecc_class);
trace_mtk_dram_ecc_lifecycle(1);
diff --git a/drivers/soc/mediatek/dram-ecc/core/netlink.c b/drivers/soc/mediatek/dram-ecc/core/netlink.c
new file mode 100644
index 000000000000..bad96bbe4ed6
--- /dev/null
+++ b/drivers/soc/mediatek/dram-ecc/core/netlink.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ */
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/netlink.h>
+#include <linux/printk.h>
+#include <net/genetlink.h>
+#include <uapi/linux/mtk_dram_ecc_netlink.h>
+
+#include "mtk_dram_ecc_event.h"
+#include "netlink.h"
+
+static const struct genl_multicast_group mtk_dram_ecc_mcgrps[] = {
+ { .name = MTK_DRAM_ECC_MCAST_GRP },
+};
+
+static struct genl_family mtk_dram_ecc_genl_family = {
+ .name = MTK_DRAM_ECC_GENL_NAME,
+ .version = MTK_DRAM_ECC_GENL_VERSION,
+ .maxattr = MTK_DRAM_ECC_ATTR_MAX,
+ .mcgrps = mtk_dram_ecc_mcgrps,
+ .n_mcgrps = ARRAY_SIZE(mtk_dram_ecc_mcgrps),
+ .module = THIS_MODULE,
+};
+
+int mtk_dram_ecc_netlink_init(void)
+{
+ return genl_register_family(&mtk_dram_ecc_genl_family);
+}
+
+void mtk_dram_ecc_netlink_exit(void)
+{
+ genl_unregister_family(&mtk_dram_ecc_genl_family);
+}
+
+void mtk_dram_ecc_netlink_notify(const struct mtk_dram_ecc_event *evt)
+{
+ struct sk_buff *skb;
+ void *hdr;
+ int ret;
+ u8 severity;
+
+ skb = genlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
+ if (!skb) {
+ pr_warn_ratelimited("mtk-dram-ecc: failed to allocate netlink event for spa=0x%llx\n",
+ evt->spa);
+ return;
+ }
+
+ hdr = genlmsg_put(skb, 0, 0, &mtk_dram_ecc_genl_family, 0,
+ MTK_DRAM_ECC_CMD_EVENT);
+ if (!hdr)
+ goto err;
+
+ severity = (evt->severity == MTK_DRAM_ECC_NOTIFY_CE) ?
+ MTK_DRAM_ECC_SEV_CE : MTK_DRAM_ECC_SEV_UCE;
+
+ if (nla_put_u64_64bit(skb, MTK_DRAM_ECC_ATTR_SPA, evt->spa,
+ MTK_DRAM_ECC_ATTR_UNSPEC) ||
+ nla_put_u8(skb, MTK_DRAM_ECC_ATTR_SEVERITY, severity) ||
+ nla_put_u8(skb, MTK_DRAM_ECC_ATTR_CHANNEL, evt->channel) ||
+ nla_put_u8(skb, MTK_DRAM_ECC_ATTR_SUBCHANNEL, evt->subchannel) ||
+ nla_put_u16(skb, MTK_DRAM_ECC_ATTR_RANK, evt->rank) ||
+ nla_put_u16(skb, MTK_DRAM_ECC_ATTR_BANK, evt->bank) ||
+ nla_put_u32(skb, MTK_DRAM_ECC_ATTR_ROW, evt->row) ||
+ nla_put_u16(skb, MTK_DRAM_ECC_ATTR_COLUMN, evt->column))
+ goto err;
+
+ genlmsg_end(skb, hdr);
+ ret = genlmsg_multicast(&mtk_dram_ecc_genl_family, skb, 0, 0,
+ GFP_ATOMIC);
+ if (ret && ret != -ESRCH)
+ pr_warn_ratelimited("mtk-dram-ecc: failed to publish netlink event for spa=0x%llx: %d\n",
+ evt->spa, ret);
+ return;
+
+err:
+ pr_warn_ratelimited("mtk-dram-ecc: failed to build netlink event for spa=0x%llx\n",
+ evt->spa);
+ nlmsg_free(skb);
+}
diff --git a/drivers/soc/mediatek/dram-ecc/core/netlink.h b/drivers/soc/mediatek/dram-ecc/core/netlink.h
new file mode 100644
index 000000000000..a2e64789d7d7
--- /dev/null
+++ b/drivers/soc/mediatek/dram-ecc/core/netlink.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ */
+#ifndef _MTK_DRAM_ECC_NETLINK_H_
+#define _MTK_DRAM_ECC_NETLINK_H_
+
+#include "mtk_dram_ecc_event.h"
+
+int mtk_dram_ecc_netlink_init(void);
+void mtk_dram_ecc_netlink_exit(void);
+void mtk_dram_ecc_netlink_notify(const struct mtk_dram_ecc_event *evt);
+
+#endif /* _MTK_DRAM_ECC_NETLINK_H_ */
diff --git a/include/uapi/linux/mtk_dram_ecc_netlink.h b/include/uapi/linux/mtk_dram_ecc_netlink.h
new file mode 100644
index 000000000000..8b4a77722bdb
--- /dev/null
+++ b/include/uapi/linux/mtk_dram_ecc_netlink.h
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+/*
+ * Copyright (c) 2026 MediaTek Inc.
+ */
+#ifndef _UAPI_MTK_DRAM_ECC_NETLINK_H_
+#define _UAPI_MTK_DRAM_ECC_NETLINK_H_
+
+#define MTK_DRAM_ECC_GENL_NAME "mtk_dram_ecc"
+#define MTK_DRAM_ECC_GENL_VERSION 1
+#define MTK_DRAM_ECC_MCAST_GRP "events"
+
+/* Commands */
+enum mtk_dram_ecc_cmd {
+ MTK_DRAM_ECC_CMD_UNSPEC,
+ MTK_DRAM_ECC_CMD_EVENT,
+ __MTK_DRAM_ECC_CMD_MAX,
+};
+
+#define MTK_DRAM_ECC_CMD_MAX (__MTK_DRAM_ECC_CMD_MAX - 1)
+
+/*
+ * Attributes. rank, bank, row and column are the DRAM controller address
+ * fields of the error.
+ */
+enum mtk_dram_ecc_attr {
+ MTK_DRAM_ECC_ATTR_UNSPEC,
+ MTK_DRAM_ECC_ATTR_SPA, /* u64 - System Physical Address */
+ MTK_DRAM_ECC_ATTR_SEVERITY, /* u8 - 0=CE, 1=UCE */
+ MTK_DRAM_ECC_ATTR_CHANNEL, /* u8 - DRAM channel index */
+ MTK_DRAM_ECC_ATTR_SUBCHANNEL, /* u8 - DRAM sub-channel, 0 or 1 */
+ MTK_DRAM_ECC_ATTR_RANK, /* u16 - DRAMC rank address */
+ MTK_DRAM_ECC_ATTR_BANK, /* u16 - DRAMC bank address */
+ MTK_DRAM_ECC_ATTR_ROW, /* u32 - DRAMC row address */
+ MTK_DRAM_ECC_ATTR_COLUMN, /* u16 - DRAMC column address */
+ __MTK_DRAM_ECC_ATTR_MAX,
+};
+
+#define MTK_DRAM_ECC_ATTR_MAX (__MTK_DRAM_ECC_ATTR_MAX - 1)
+
+/* Severity values for MTK_DRAM_ECC_ATTR_SEVERITY */
+#define MTK_DRAM_ECC_SEV_CE 0
+#define MTK_DRAM_ECC_SEV_UCE 1
+
+#endif /* _UAPI_MTK_DRAM_ECC_NETLINK_H_ */
--
2.45.2
next prev parent reply other threads:[~2026-11-02 9:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 9:23 [RFC PATCH 00/11] soc: mediatek: add a DRAM ECC error handling driver santino.wang
2026-11-02 9:23 ` [RFC PATCH 01/11] soc: mediatek: dram-ecc: add the DRAM ECC driver skeleton santino.wang
2026-11-02 13:41 ` Krzysztof Kozlowski
2026-11-02 9:23 ` [RFC PATCH 02/11] soc: mediatek: dram-ecc: add the SMC interface to the secure firmware santino.wang
2026-11-02 9:23 ` [RFC PATCH 03/11] soc: mediatek: dram-ecc: add tracepoints santino.wang
2026-11-02 9:23 ` [RFC PATCH 04/11] soc: mediatek: dram-ecc: handle GHES vendor records from the firmware santino.wang
2026-11-02 9:23 ` [RFC PATCH 05/11] soc: mediatek: dram-ecc: add error counters and the address lists santino.wang
2026-11-02 13:42 ` Krzysztof Kozlowski
2026-11-02 9:23 ` [RFC PATCH 06/11] soc: mediatek: dram-ecc: keep error counters across boots santino.wang
2026-11-02 9:23 ` [RFC PATCH 07/11] soc: mediatek: dram-ecc: add containment policy and storm protection santino.wang
2026-11-02 9:23 ` [RFC PATCH 08/11] soc: mediatek: dram-ecc: add the corrected error leaky bucket santino.wang
2026-11-02 9:23 ` santino.wang [this message]
2026-11-02 9:23 ` [RFC PATCH 10/11] soc: mediatek: dram-ecc: report an uncorrectable error of the previous boot santino.wang
2026-11-02 13:44 ` Krzysztof Kozlowski
2026-11-02 9:23 ` [RFC PATCH 11/11] Documentation: ABI: add the sysfs attributes of the MediaTek DRAM ECC driver santino.wang
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=20261102092334.138759-10-santino.wang@mediatek.com \
--to=santino.wang@mediatek.com \
--cc=Fred-WY.Chen@mediatek.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=arnab.layek@mediatek.com \
--cc=light.chen@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.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
all inboxes | Powered by JetHome®