From patchwork Mon Nov 11 06:09:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qunqin Zhao X-Patchwork-Id: 13870263 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C66FF149DF4; Mon, 11 Nov 2024 06:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731305426; cv=none; b=F8AVd7q+hVWyFpj0vkgNnMl2Q693Dnyc+1W0uD3n0xuxr3RSqH7vUF29K3wWZU0LXLhkX95p3BuhtcBMK1iT5972UCrlAUFpU8Ax1MLwENJwPe+An8wF1v9GDKwVufTgvPQiVugpP89XTh4AhzOG/5PHV3FUYP62/CbPDWKaF3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731305426; c=relaxed/simple; bh=WdfK2DNMyRJuYkEYLMsteO/EXTHS05aKeXWdEzSu+BM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V+ItfIEF6Og6j5klMebhbhTQOUe2cra9vMkxx1VSXhx5Uc7kLrJfdEt+/onZrKwPnoHyFjo1as7IfAnBfVYAFseEYoJ7XQI2Y4CoOWS97h9OfMFNDa+SW1DSSZAtbWYKjJTnx7X38hpHIwR93czkXI2tZIxQpoTEA6umrb5lk9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.40.54.90]) by gateway (Coremail) with SMTP id _____8BxeeHGnzFnpzw7AA--.52796S3; Mon, 11 Nov 2024 14:10:14 +0800 (CST) Received: from localhost.localdomain (unknown [10.40.54.90]) by front1 (Coremail) with SMTP id qMiowMBxnkfDnzFn0ABRAA--.10185S3; Mon, 11 Nov 2024 14:10:12 +0800 (CST) From: Zhao Qunqin To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, chenhuacai@kernel.org, bp@alien8.de Cc: linux-edac@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@xen0n.name, tony.luck@intel.com, james.morse@arm.com, mchehab@kernel.org, rric@kernel.org, loongarch@lists.linux.dev, Zhao Qunqin , Krzysztof Kozlowski Subject: [PATCH v7 1/2] dt-bindings: EDAC for ls3a5000 memory controller Date: Mon, 11 Nov 2024 14:09:38 +0800 Message-Id: <20241111060939.5349-2-zhaoqunqin@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241111060939.5349-1-zhaoqunqin@loongson.cn> References: <20241111060939.5349-1-zhaoqunqin@loongson.cn> Precedence: bulk X-Mailing-List: linux-edac@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: qMiowMBxnkfDnzFn0ABRAA--.10185S3 X-CM-SenderInfo: 52kd01pxqtx0o6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBj93XoWxWw17Cr1rWr1rur15Ww1xZwc_yoW5GFWrpr s3A3Z3Kr1xK3W7AanYqa4IyF1Fq3s5Z3W7XFs7Kw13KryDWa4FvFyYkryUXan8JrykXFW5 ZFySgr42kFsFkwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU3529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q 6rW5McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41lc7CjxVAaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU4YLvDUUUU Add device tree bindings for ls3a5000 EDAC driver. Signed-off-by: Zhao Qunqin Reviewed-by: Krzysztof Kozlowski --- Changes form v5 to v7: - None Changes in v4: - Added tag from Krzysztof (thanks!) Changes in v3: - None Changes in v2: - Fixed the errors raised by Rob - Addressed review comments raised by Krzysztof and Conor .../edac/loongson,ls3a5000-mc-edac.yaml | 44 +++++++++++++++++++ MAINTAINERS | 6 +++ 2 files changed, 50 insertions(+) create mode 100644 Documentation/devicetree/bindings/edac/loongson,ls3a5000-mc-edac.yaml diff --git a/Documentation/devicetree/bindings/edac/loongson,ls3a5000-mc-edac.yaml b/Documentation/devicetree/bindings/edac/loongson,ls3a5000-mc-edac.yaml new file mode 100644 index 000000000..52f10bc94 --- /dev/null +++ b/Documentation/devicetree/bindings/edac/loongson,ls3a5000-mc-edac.yaml @@ -0,0 +1,44 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/edac/loongson,ls3a5000-mc-edac.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Loongson Memory Controller EDAC + +maintainers: + - Zhao Qunqin + +description: | + EDAC node is defined to describe on-chip error detection and correction for + Loongson Memory Controller. + +properties: + compatible: + oneOf: + - enum: + - loongson,ls3a5000-mc-edac + - items: + - enum: + - loongson,ls3c5000l-mc-edac + - loongson,ls3c5000-mc-edac + - loongson,ls3d5000-mc-edac + - loongson,ls3a6000-mc-edac + - loongson,ls3c6000-mc-edac + - const: loongson,ls3a5000-mc-edac + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + memory-controller@1fe00600 { + compatible = "loongson,ls3a5000-mc-edac"; + reg = <0x1fe00600 0x50>; + }; diff --git a/MAINTAINERS b/MAINTAINERS index e9659a5a7..8c7d565b3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13397,6 +13397,12 @@ S: Maintained F: Documentation/devicetree/bindings/thermal/loongson,ls2k-thermal.yaml F: drivers/thermal/loongson2_thermal.c +LOONGSON EDAC DRIVER +M: Zhao Qunqin +L: linux-edac@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/edac/loongson,ls3a5000-mc-edac.yaml + LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI) M: Sathya Prakash M: Sreekanth Reddy From patchwork Mon Nov 11 06:09:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qunqin Zhao X-Patchwork-Id: 13870264 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5594614AD2B; Mon, 11 Nov 2024 06:10:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731305427; cv=none; b=iKJT9FWhqXZn8hGuGiK04EyH/c0zLHPtEmo5410MBlNNaybO+pAM9v7xLlVqXvD/BCnIMiopWg+D6fKcEMYsk8RHz5U3mttbuAuLs4PsbmZnSviGQd+H6HsN+FUK784/0jnZHNoeUos84wc9pF0NyrQ9SVHK8cvkqMKT/wl7Nj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731305427; c=relaxed/simple; bh=f2NbwPXqxW63uyCT1gVOEA09X0GWSykxyW3//sCUmBs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=J/rBnc1Ep4vtEqNgRaGiHm4RsKIgdkLgiePQdo1fZY10pmn3uCZEcrO7K45f4aJ6D08t4p0ybb7fo4mcbA8VX45LA8SVO52NADiwaYqNHXPgpAFVpEGFiwC0xsdAKcfyPa1B+fbI25xX3daAgU0wkLd2lZICbWiXDyCQBOvF+8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.40.54.90]) by gateway (Coremail) with SMTP id _____8BxeeDHnzFnrjw7AA--.50736S3; Mon, 11 Nov 2024 14:10:15 +0800 (CST) Received: from localhost.localdomain (unknown [10.40.54.90]) by front1 (Coremail) with SMTP id qMiowMBxnkfDnzFn0ABRAA--.10185S4; Mon, 11 Nov 2024 14:10:14 +0800 (CST) From: Zhao Qunqin To: robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, chenhuacai@kernel.org, bp@alien8.de Cc: linux-edac@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@xen0n.name, tony.luck@intel.com, james.morse@arm.com, mchehab@kernel.org, rric@kernel.org, loongarch@lists.linux.dev, Zhao Qunqin Subject: [PATCH v7 2/2] EDAC: Add EDAC driver for loongson memory controller Date: Mon, 11 Nov 2024 14:09:39 +0800 Message-Id: <20241111060939.5349-3-zhaoqunqin@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20241111060939.5349-1-zhaoqunqin@loongson.cn> References: <20241111060939.5349-1-zhaoqunqin@loongson.cn> Precedence: bulk X-Mailing-List: linux-edac@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: qMiowMBxnkfDnzFn0ABRAA--.10185S4 X-CM-SenderInfo: 52kd01pxqtx0o6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBj93XoW3ArW8AF4xWF4xXFyrtr1rKrX_yoWxZw1kpF n8Aw1fGr48tr43CwsayrWUuF15Cwn2ga42yay7A3ya93srAryDZr95tFW2yF1DCrykJrW3 Xa4rKwsrCF4DCwcCm3ZEXasCq-sJn29KB7ZKAUJUUUUx529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUB2b4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6r4UJVWxJr1ln4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12 xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q 6rW5McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64 vIr41lc7CjxVAaw2AFwI0_Jw0_GFyl42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_ Jr0_Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8Gjc xK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0 cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8V AvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E 14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxU4YLvDUUUU Reports single bit errors (CE) only. Signed-off-by: Zhao Qunqin --- Changes in v7: - Fix sparse's "incorrect type in assignment" - Clean up coding style Changes in v6: - Change the Kconfig name to CONFIG_EDAC_LOONGSON Changes in v5: - Drop the loongson_ prefix from all static functions. - Align function arguments on the opening brace. - Drop useless comments and useless wrapper. Drop side comments. - Reorder variable declarations. Changes in v4: - None Changes in v3: - Addressed review comments raised by Krzysztof and Huacai Changes in v2: - Addressed review comments raised by Krzysztof MAINTAINERS | 1 + arch/loongarch/Kconfig | 1 + drivers/edac/Kconfig | 8 ++ drivers/edac/Makefile | 1 + drivers/edac/loongson_edac.c | 156 +++++++++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 drivers/edac/loongson_edac.c diff --git a/MAINTAINERS b/MAINTAINERS index 8c7d565b3..cd47c63e0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13402,6 +13402,7 @@ M: Zhao Qunqin L: linux-edac@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/edac/loongson,ls3a5000-mc-edac.yaml +F: drivers/edac/loongson_edac.c LSILOGIC MPT FUSION DRIVERS (FC/SAS/SPI) M: Sathya Prakash diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index bb35c34f8..10b9ba587 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -185,6 +185,7 @@ config LOONGARCH select PCI_MSI_ARCH_FALLBACKS select PCI_QUIRKS select PERF_USE_VMALLOC + select EDAC_SUPPORT select RTC_LIB select SPARSE_IRQ select SYSCTL_ARCH_UNALIGN_ALLOW diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig index 81af6c344..1cf432102 100644 --- a/drivers/edac/Kconfig +++ b/drivers/edac/Kconfig @@ -564,5 +564,13 @@ config EDAC_VERSAL Support injecting both correctable and uncorrectable errors for debugging purposes. +config EDAC_LOONGSON + tristate "Loongson Memory Controller" + depends on LOONGARCH || COMPILE_TEST + help + Support for error detection and correction on the Loongson + family memory controller. This driver reports single bit + errors (CE) only. Loongson-3A5000/3C5000/3D5000/3C5000L/3A6000/3C6000 + are compatible. endif # EDAC diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile index faf310eec..f8bdbc895 100644 --- a/drivers/edac/Makefile +++ b/drivers/edac/Makefile @@ -88,3 +88,4 @@ obj-$(CONFIG_EDAC_DMC520) += dmc520_edac.o obj-$(CONFIG_EDAC_NPCM) += npcm_edac.o obj-$(CONFIG_EDAC_ZYNQMP) += zynqmp_edac.o obj-$(CONFIG_EDAC_VERSAL) += versal_edac.o +obj-$(CONFIG_EDAC_LOONGSON) += loongson_edac.o diff --git a/drivers/edac/loongson_edac.c b/drivers/edac/loongson_edac.c new file mode 100644 index 000000000..0a062a008 --- /dev/null +++ b/drivers/edac/loongson_edac.c @@ -0,0 +1,154 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2024 Loongson Technology Corporation Limited. + */ + +#include +#include +#include +#include +#include "edac_module.h" + +#define ECC_CS_COUNT_REG 0x18 + +struct loongson_edac_pvt { + void __iomem *ecc_base; + int last_ce_count; +}; + +static int read_ecc(struct mem_ctl_info *mci) +{ + struct loongson_edac_pvt *pvt = mci->pvt_info; + u64 ecc; + int cs; + + if (!pvt->ecc_base) + return pvt->last_ce_count; + + ecc = readq(pvt->ecc_base + ECC_CS_COUNT_REG); + /* cs0 -- cs3 */ + cs = ecc & 0xff; + cs += (ecc >> 8) & 0xff; + cs += (ecc >> 16) & 0xff; + cs += (ecc >> 24) & 0xff; + + return cs; +} + +static void edac_check(struct mem_ctl_info *mci) +{ + struct loongson_edac_pvt *pvt = mci->pvt_info; + int new, add; + + new = read_ecc(mci); + add = new - pvt->last_ce_count; + pvt->last_ce_count = new; + if (add <= 0) + return; + + edac_mc_handle_error(HW_EVENT_ERR_CORRECTED, mci, add, + 0, 0, 0, 0, 0, -1, "error", ""); + edac_mc_printk(mci, KERN_INFO, "add: %d", add); +} + +static void dimm_config_init(struct mem_ctl_info *mci) +{ + struct dimm_info *dimm; + u32 size, npages; + + /* size not used */ + size = -1; + npages = MiB_TO_PAGES(size); + + dimm = edac_get_dimm(mci, 0, 0, 0); + dimm->nr_pages = npages; + snprintf(dimm->label, sizeof(dimm->label), + "MC#%uChannel#%u_DIMM#%u", mci->mc_idx, 0, 0); + dimm->grain = 8; +} + +static void pvt_init(struct mem_ctl_info *mci, void __iomem *vbase) +{ + struct loongson_edac_pvt *pvt = mci->pvt_info; + + pvt->ecc_base = vbase; + pvt->last_ce_count = read_ecc(mci); +} + +static int edac_probe(struct platform_device *pdev) +{ + struct edac_mc_layer layers[2]; + struct mem_ctl_info *mci; + void __iomem *vbase; + int ret; + + vbase = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(vbase)) + return PTR_ERR(vbase); + + /* allocate a new MC control structure */ + layers[0].type = EDAC_MC_LAYER_CHANNEL; + layers[0].size = 1; + layers[0].is_virt_csrow = false; + layers[1].type = EDAC_MC_LAYER_SLOT; + layers[1].size = 1; + layers[1].is_virt_csrow = true; + mci = edac_mc_alloc(0, ARRAY_SIZE(layers), layers, + sizeof(struct loongson_edac_pvt)); + if (mci == NULL) + return -ENOMEM; + + mci->mc_idx = edac_device_alloc_index(); + mci->mtype_cap = MEM_FLAG_RDDR4; + mci->edac_ctl_cap = EDAC_FLAG_NONE; + mci->edac_cap = EDAC_FLAG_NONE; + mci->mod_name = "loongson_edac.c"; + mci->ctl_name = "loongson_edac_ctl"; + mci->dev_name = "loongson_edac_dev"; + mci->ctl_page_to_phys = NULL; + mci->pdev = &pdev->dev; + mci->error_desc.grain = 8; + /* Set the function pointer to an actual operation function */ + mci->edac_check = edac_check; + + pvt_init(mci, vbase); + dimm_config_init(mci); + + ret = edac_mc_add_mc(mci); + if (ret) { + edac_dbg(0, "MC: failed edac_mc_add_mc()\n"); + edac_mc_free(mci); + return ret; + } + edac_op_state = EDAC_OPSTATE_POLL; + + return 0; +} + +static void edac_remove(struct platform_device *pdev) +{ + struct mem_ctl_info *mci = edac_mc_del_mc(&pdev->dev); + + if (mci) + edac_mc_free(mci); +} + +static const struct of_device_id loongson_edac_of_match[] = { + { .compatible = "loongson,ls3a5000-mc-edac", }, + {} +}; +MODULE_DEVICE_TABLE(of, loongson_edac_of_match); + +static struct platform_driver loongson_edac_driver = { + .probe = edac_probe, + .remove = edac_remove, + .driver = { + .name = "loongson-mc-edac", + .of_match_table = loongson_edac_of_match, + }, +}; +module_platform_driver(loongson_edac_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Zhao Qunqin "); +MODULE_DESCRIPTION("EDAC driver for loongson memory controller");