mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
To: <linux-edac@vger.kernel.org>
Cc: <git@amd.com>, <shubhrajyoti.datta@gmail.com>,
	<michal.simek@amd.com>,
	Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>,
	Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	"Borislav Petkov" <bp@alien8.de>, Tony Luck <tony.luck@intel.com>,
	<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>
Subject: [PATCH v2 11/12] EDAC/versalnet: use device tree property for number of controllers
Date: Wed, 18 Nov 2026 19:50:35 +0530	[thread overview]
Message-ID: <20261118142213.100581-12-shubhrajyoti.datta@amd.com> (raw)
In-Reply-To: <20261118142213.100581-1-shubhrajyoti.datta@amd.com>

Use the number of enabled controllers read from the "amd,num-ctrl"
device tree property for registering instead of all the controllers.
The enabled controllers are contiguous. Add a
num_ctrl field to mc_priv and use it in probe, init, remove,
error handling, and the rpmsg callback, allowing the driver to
support platforms with varying numbers of memory controllers enabled.

This keeps the old behaviour for older device trees. On a platform with
whose device tree lacks the property, the old iteration over all 8 indices,
remains in effect.

Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
---

Changes in v2:
Adding the device tree parameter was suggested in the review in v1
https://lore.kernel.org/all/34ffba5a-8e9a-49b9-9e36-c31d0e4369f8@amd.com/

 drivers/edac/versalnet_edac.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
index 7c14f1e78da1..c2025f5744cc 100644
--- a/drivers/edac/versalnet_edac.c
+++ b/drivers/edac/versalnet_edac.c
@@ -140,6 +140,7 @@ struct ecc_status {
  * struct mc_priv - DDR memory controller private instance data.
  * @message:		Buffer for framing the event specific info.
  * @stat:		ECC status information.
+ * @num_ctrl:		Number of DDR memory controllers.
  * @error_id:		The error id.
  * @error_level:	The error level.
  * @dwidth:		Per-controller width of data bus excluding ECC bits.
@@ -168,6 +169,7 @@ struct ecc_status {
 struct mc_priv {
 	char message[256];
 	struct ecc_status stat;
+	u32 num_ctrl;
 	u32 error_id;
 	u32 error_level;
 	enum dev_type dwidth[NUM_CONTROLLERS];
@@ -456,7 +458,7 @@ static void handle_error(struct mc_priv  *priv, struct ecc_status *stat,
 	phys_addr_t pfn;
 	int err;
 
-	if (WARN_ON_ONCE(ctl_num >= NUM_CONTROLLERS))
+	if (WARN_ON_ONCE(ctl_num >= priv->num_ctrl))
 		return;
 
 	mci = priv->mci[ctl_num];
@@ -713,7 +715,7 @@ static int rpmsg_cb(struct rpmsg_device *rpdev, void *data,
 		p = &mc_priv->stat;
 		memset(p, 0, sizeof(struct ecc_status));
 		p->error_type = MC5_ERR_TYPE_CE;
-		for (i = 0 ; i < NUM_CONTROLLERS; i++) {
+		for (i = 0 ; i < mc_priv->num_ctrl; i++) {
 			if (get_ddr_info(&mc_priv->regs[i * REGS_PER_CONTROLLER], mc_priv)) {
 				adec_data = mc_priv->adec + ADEC_NUM * i;
 				handle_error(mc_priv, &mc_priv->stat, i, adec_data);
@@ -724,7 +726,7 @@ static int rpmsg_cb(struct rpmsg_device *rpdev, void *data,
 		p = &mc_priv->stat;
 		memset(p, 0, sizeof(struct ecc_status));
 		p->error_type = MC5_ERR_TYPE_UE;
-		for (i = 0 ; i < NUM_CONTROLLERS; i++) {
+		for (i = 0 ; i < mc_priv->num_ctrl; i++) {
 			if (get_ddr_info(&mc_priv->regs[i * REGS_PER_CONTROLLER], mc_priv)) {
 				adec_data = mc_priv->adec + ADEC_NUM * i;
 				handle_error(mc_priv, &mc_priv->stat, i, adec_data);
@@ -956,7 +958,7 @@ static int init_versalnet(struct mc_priv *priv)
 {
 	int rc, i;
 
-	for (i = 0; i < NUM_CONTROLLERS; i++) {
+	for (i = 0; i < priv->num_ctrl; i++) {
 		rc = init_one_mc(priv, i);
 		if (rc) {
 			while (i--)
@@ -970,7 +972,7 @@ static int init_versalnet(struct mc_priv *priv)
 
 static void remove_versalnet(struct mc_priv *priv)
 {
-	for (int i = 0; i < NUM_CONTROLLERS; i++)
+	for (int i = 0; i < priv->num_ctrl; i++)
 		remove_one_mc(priv, i);
 }
 
@@ -978,6 +980,7 @@ static int mc_probe(struct platform_device *pdev)
 {
 	struct mc_priv *priv;
 	struct rproc *rp;
+	u32 num_ctrl;
 	int rc, i;
 
 	struct device_node *r5_core_node __free(device_node) =
@@ -987,6 +990,18 @@ static int mc_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
+	rc = of_property_read_u32(pdev->dev.of_node, "amd,num-ctrl", &num_ctrl);
+	if (rc == -EINVAL) {
+		num_ctrl = NUM_CONTROLLERS;
+	} else if (rc) {
+		dev_err(&pdev->dev, "amd,num-ctrl: failed to read property: %d\n", rc);
+		return rc;
+	}
+
+	if (!num_ctrl || num_ctrl > NUM_CONTROLLERS)
+		return dev_err_probe(&pdev->dev, -EINVAL,
+			      "amd,num-ctrl: invalid value %u\n", num_ctrl);
+
 	rp = rproc_get_by_phandle(r5_core_node->phandle);
 	if (!rp)
 		return -EPROBE_DEFER;
@@ -1003,6 +1018,7 @@ static int mc_probe(struct platform_device *pdev)
 		goto err_alloc;
 	}
 
+	priv->num_ctrl = num_ctrl;
 	priv->dev = &pdev->dev;
 	platform_set_drvdata(pdev, priv);
 	mutex_init(&priv->ept_lock);
@@ -1027,7 +1043,7 @@ static int mc_probe(struct platform_device *pdev)
 
 	priv->mcdi->r5_rproc = rp;
 
-	for (i = 0; i < NUM_CONTROLLERS; i++)
+	for (i = 0; i < priv->num_ctrl; i++)
 		get_ddr_config(i, &priv->adec[ADEC_NUM * i], priv->mcdi);
 
 	rc = init_versalnet(priv);
-- 
2.44.4


  parent reply	other threads:[~2026-11-18 14:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 14:20 [PATCH v2 00/12] EDAC/versalnet: Fix error handling, teardown, and robustness Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 01/12] EDAC/versalnet: Fix device_register() error handling in init_one_mc() Shubhrajyoti Datta
2026-11-20 13:38   ` Pandey, Radhey Shyam
2026-11-18 14:20 ` [PATCH v2 02/12] EDAC/versalnet: Use designated initializer for rpmsg_channel_info Shubhrajyoti Datta
2026-11-20 13:39   ` Pandey, Radhey Shyam
2026-11-18 14:20 ` [PATCH v2 03/12] EDAC/versalnet: Fix use-after-free in remove_one_mc() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 04/12] EDAC/versalnet: Add bounds validation in rpmsg_cb() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 05/12] EDAC/versalnet: Make dwidth per-controller Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 06/12] EDAC/versalnet: Wait for RPMsg endpoint initialization Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 07/12] EDAC/versalnet: Initialize MCDI before RPMsg registration Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 08/12] EDAC/versalnet: Guard against NULL drvdata in rpmsg_cb() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 09/12] EDAC/versalnet: Move platform_set_drvdata() to mc_probe() Shubhrajyoti Datta
2026-11-18 14:20 ` [PATCH v2 10/12] dt-bindings: memory: xlnx,versal-net-ddrmc5: Add amd,num-ctrl property Shubhrajyoti Datta
2026-11-18 14:20 ` Shubhrajyoti Datta [this message]
2026-11-18 14:20 ` [PATCH v2 12/12] EDAC/versalnet: Make get_ddr_config() return errors Shubhrajyoti Datta

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=20261118142213.100581-12-shubhrajyoti.datta@amd.com \
    --to=shubhrajyoti.datta@amd.com \
    --cc=bp@alien8.de \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=git@amd.com \
    --cc=krzk@kernel.org \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@amd.com \
    --cc=radhey.shyam.pandey@amd.com \
    --cc=robh@kernel.org \
    --cc=shubhrajyoti.datta@gmail.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

all inboxes | Powered by JetHome®