Report MPC7448 L2 errors through EDAC, with one instance per CPU. Single-bit errors are corrected by the hardware and only counted, so poll L2ERRCTL[L2CCOUNT] and L2ERRDET and report the count as correctable errors. Report the L2 machine checks counted by the arch code as uncorrectable errors, along with any multi-bit ECC or tag parity error found in L2ERRDET without one, since clearing L2ERRDET would otherwise lose it.
PowerMacs have no device tree node for the L2, so bind to a faux device. Signed-off-by: Matt Turner <[email protected]> --- MAINTAINERS | 1 + drivers/edac/Kconfig | 9 +++ drivers/edac/Makefile | 1 + drivers/edac/mpc7448_l2_edac.c | 160 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 171 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 4ea66ea2be2d..0d02f0a7316c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9754,6 +9754,7 @@ L: [email protected] S: Maintained F: arch/powerpc/include/asm/mpc7448_l2.h F: arch/powerpc/kernel/mpc7448_l2.c +F: drivers/edac/mpc7448_l2_edac.c EDAC-MPC85XX L: [email protected] diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig index 4c70729b0d3a..c3256da3d6fd 100644 --- a/drivers/edac/Kconfig +++ b/drivers/edac/Kconfig @@ -320,6 +320,15 @@ config EDAC_MPC85XX Support for error detection and correction on the Freescale MPC8349, MPC8560, MPC8540, MPC8548, T4240 +config EDAC_MPC7448_L2 + tristate "Freescale MPC7448 L2 cache" + depends on PPC_BOOK3S_32 + help + Support for error detection and correction on the L2 cache of + the Freescale MPC7448 processor. Correctable errors are found + by polling the L2 error counter, and uncorrectable errors are + reported by the machine check handler. + config EDAC_LAYERSCAPE tristate "Freescale Layerscape DDR" depends on ARCH_LAYERSCAPE || SOC_LS1021A diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile index 4020ea60738a..06c951d680f7 100644 --- a/drivers/edac/Makefile +++ b/drivers/edac/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_EDAC_PASEMI) += pasemi_edac.o mpc85xx_edac_mod-y := fsl_ddr_edac.o mpc85xx_edac.o obj-$(CONFIG_EDAC_MPC85XX) += mpc85xx_edac_mod.o +obj-$(CONFIG_EDAC_MPC7448_L2) += mpc7448_l2_edac.o layerscape_edac_mod-y := fsl_ddr_edac.o layerscape_edac.o obj-$(CONFIG_EDAC_LAYERSCAPE) += layerscape_edac_mod.o diff --git a/drivers/edac/mpc7448_l2_edac.c b/drivers/edac/mpc7448_l2_edac.c new file mode 100644 index 000000000000..a62c7a2e7147 --- /dev/null +++ b/drivers/edac/mpc7448_l2_edac.c @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * EDAC driver for the MPC7448 on-chip L2 cache. + * + * Single-bit ECC errors are corrected by the hardware and only counted in + * L2ERRCTL[L2CCOUNT], so they are found by polling. Multi-bit ECC and tag + * parity errors raise a machine check (arch/powerpc/kernel/mpc7448_l2.c) + * and are reported here at the next poll, if the system survived it. + * Errors latched in L2ERRDET without a machine check are reported as + * uncorrectable too. + */ + +#include <linux/bitfield.h> +#include <linux/cpu.h> +#include <linux/device/faux.h> +#include <linux/edac.h> +#include <linux/module.h> +#include <linux/smp.h> +#include <linux/sprintf.h> + +#include <asm/mpc7448_l2.h> +#include <asm/reg.h> + +#include "edac_module.h" + +#define DRV_NAME "mpc7448_l2_edac" + +static struct faux_device *mpc7448_l2_fdev; + +struct mpc7448_l2_poll { + struct mpc7448_l2_err err; + u32 ctl; + unsigned int mce_ue; +}; + +static void mpc7448_l2_poll_cpu(void *info) +{ + struct mpc7448_l2_poll *p = info; + + p->ctl = mfspr(SPRN_L2ERRCTL); + if (p->ctl & L2ERRCTL_L2CCOUNT) + mtspr(SPRN_L2ERRCTL, p->ctl & ~L2ERRCTL_L2CCOUNT); + + mpc7448_l2_err_capture(&p->err); + + p->mce_ue = mpc7448_l2_mce_take(); +} + +static void mpc7448_l2_report(struct edac_device_ctl_info *edac_dev, + unsigned int cpu, const struct mpc7448_l2_poll *p) +{ + unsigned int ce, ue; + char msg[64]; + + ce = FIELD_GET(L2ERRCTL_L2CCOUNT, p->ctl) ?: + !!(p->err.det & L2ERR_SBECCERR); + if (ce) { + if (p->err.det & L2ERR_SBECCERR) + snprintf(msg, sizeof(msg), "single-bit ECC at 0x%09llx", + mpc7448_l2_err_paddr(&p->err)); + else + snprintf(msg, sizeof(msg), "single-bit ECC"); + edac_device_handle_ce_count(edac_dev, ce, cpu, 0, msg); + } + + /* Errors latched without a machine check */ + ue = !!(p->err.det & L2ERR_MBECCERR) + !!(p->err.det & L2ERR_TPARERR); + if (ue) { + mpc7448_l2_err_print(&p->err); + snprintf(msg, sizeof(msg), "%s at 0x%09llx", + p->err.det & L2ERR_TPARERR ? "tag parity" : "multi-bit ECC", + mpc7448_l2_err_paddr(&p->err)); + edac_device_handle_ue_count(edac_dev, ue, cpu, 0, msg); + } + + /* The machine check handler has already printed the details */ + if (p->mce_ue) + edac_device_handle_ue_count(edac_dev, p->mce_ue, cpu, 0, + "machine check"); +} + +static void mpc7448_l2_check_cpu(struct edac_device_ctl_info *edac_dev, + unsigned int cpu) +{ + struct mpc7448_l2_poll p; + + if (!smp_call_function_single(cpu, mpc7448_l2_poll_cpu, &p, 1)) + mpc7448_l2_report(edac_dev, cpu, &p); +} + +static void mpc7448_l2_check(struct edac_device_ctl_info *edac_dev) +{ + unsigned int cpu; + + cpus_read_lock(); + for_each_online_cpu(cpu) + mpc7448_l2_check_cpu(edac_dev, cpu); + cpus_read_unlock(); +} + +static int mpc7448_l2_probe(struct faux_device *fdev) +{ + struct edac_device_ctl_info *edac_dev; + + edac_dev = edac_device_alloc_ctl_info(0, "cpu", nr_cpu_ids, "L", 1, 2, + edac_device_alloc_index()); + if (!edac_dev) + return -ENOMEM; + + edac_dev->dev = &fdev->dev; + edac_dev->mod_name = DRV_NAME; + edac_dev->ctl_name = "MPC7448_L2"; + edac_dev->dev_name = dev_name(&fdev->dev); + edac_dev->edac_check = mpc7448_l2_check; + + if (edac_device_add_device(edac_dev)) { + edac_device_free_ctl_info(edac_dev); + return -ENXIO; + } + + faux_device_set_drvdata(fdev, edac_dev); + return 0; +} + +static void mpc7448_l2_remove(struct faux_device *fdev) +{ + struct edac_device_ctl_info *edac_dev = faux_device_get_drvdata(fdev); + + edac_device_del_device(&fdev->dev); + edac_device_free_ctl_info(edac_dev); +} + +static const struct faux_device_ops mpc7448_l2_ops = { + .probe = mpc7448_l2_probe, + .remove = mpc7448_l2_remove, +}; + +static int __init mpc7448_l2_edac_init(void) +{ + if (PVR_VER(mfspr(SPRN_PVR)) != PVR_VER_7448) + return -ENODEV; + + opstate_init(); + + mpc7448_l2_fdev = faux_device_create(DRV_NAME, NULL, &mpc7448_l2_ops); + if (!mpc7448_l2_fdev) + return -ENODEV; + + return 0; +} +module_init(mpc7448_l2_edac_init); + +static void __exit mpc7448_l2_edac_exit(void) +{ + faux_device_destroy(mpc7448_l2_fdev); +} +module_exit(mpc7448_l2_edac_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("MPC7448 L2 cache EDAC driver"); -- 2.56.1
