Message ID | 20220511062113.2645747-2-hasegawa-hitomi@fujitsu.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | soc: fujitsu: Add A64FX diagnostic interrupt driver | expand |
On 11. 05. 22, 8:21, Hitomi Hasegawa wrote: > Enable diagnostic interrupts for the Fujitsu A64FX. > > Register the NMI/IRQ corresponding to the A64FX's device definition > dedicated to diagnostic interrupts, so that when this interrupt is > sent using the BMC, it causes a panic. This can be used to obtain > a kernel dump. > > Signed-off-by: Hitomi Hasegawa <hasegawa-hitomi@fujitsu.com> Hi, I'm not sure why you cc linux-serial, but anyway, comments below :). > --- /dev/null > +++ b/drivers/soc/fujitsu/a64fx-diag.c > @@ -0,0 +1,155 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/* > + * A64FX diag driver. > + * Copyright (c) 2022 Fujitsu Ltd. > + */ > + > +#include <linux/acpi.h> > +#include <linux/interrupt.h> > +#include <linux/irq.h> > +#include <linux/module.h> > +#include <linux/platform_device.h> > + > +#define A64FX_DIAG_IRQ 1 > +#define BMC_DIAG_INTERRUPT_STATUS_OFFSET (0x0044) > +#define BMC_DIAG_INTERRUPT_ENABLE_OFFSET (0x0040) > +#define BMC_DIAG_INTERRUPT_MASK BIT(31) > + > +struct a64fx_diag_priv { > + int irq; > + void __iomem *mmsc_reg_base; > + bool has_nmi; There are unnecessary holes in the struct. If you reorder it, you drop some alignment. Like: pointer, int, bool. > +}; > + > +static irqreturn_t a64fx_diag_handler_nmi(int irq, void *dev_id) > +{ > + nmi_panic(NULL, "a64fx_diag: interrupt received\n"); > + > + return IRQ_HANDLED; > +} > + > +static irqreturn_t a64fx_diag_handler_irq(int irq, void *dev_id) > +{ > + panic("a64fx_diag: interrupt received\n"); > + > + return IRQ_HANDLED; > +} > + > +static void a64fx_diag_interrupt_clear(struct a64fx_diag_priv *priv) > +{ > + u32 mmsc; > + void __iomem *diag_status_reg_addr; I'm not sure what soc/ maintainers prefer, but inverted xmas tree would look/read better. > + > + diag_status_reg_addr = priv->mmsc_reg_base + BMC_DIAG_INTERRUPT_STATUS_OFFSET; > + mmsc = readl(diag_status_reg_addr); > + if (mmsc & BMC_DIAG_INTERRUPT_MASK) > + writel(BMC_DIAG_INTERRUPT_MASK, diag_status_reg_addr); > +} > + > +static void a64fx_diag_interrupt_enable(struct a64fx_diag_priv *priv) > +{ > + u32 mmsc; > + void __iomem *diag_enable_reg_addr; > + > + diag_enable_reg_addr = priv->mmsc_reg_base + BMC_DIAG_INTERRUPT_ENABLE_OFFSET; > + mmsc = readl(diag_enable_reg_addr); > + if (!(mmsc & BMC_DIAG_INTERRUPT_MASK)) { > + mmsc |= BMC_DIAG_INTERRUPT_MASK; > + writel(mmsc, diag_enable_reg_addr); > + } > +} > + > +static void a64fx_diag_interrupt_disable(struct a64fx_diag_priv *priv) > +{ > + u32 mmsc; > + void __iomem *diag_enable_reg_addr; > + > + diag_enable_reg_addr = priv->mmsc_reg_base + BMC_DIAG_INTERRUPT_ENABLE_OFFSET; > + mmsc = readl(diag_enable_reg_addr); > + if (mmsc & BMC_DIAG_INTERRUPT_MASK) { > + mmsc &= ~BMC_DIAG_INTERRUPT_MASK; > + writel(mmsc, diag_enable_reg_addr); > + } > +} > + > +static int a64fx_diag_probe(struct platform_device *pdev) > +{ > + int ret; > + unsigned long irq_flags; > + struct device *dev = &pdev->dev; > + struct a64fx_diag_priv *priv; > + > + priv = devm_kzalloc(dev, sizeof(struct a64fx_diag_priv), GFP_KERNEL); Don't we prefer sizeof(*priv)? > + if (priv == NULL) > + return -ENOMEM; > + > + priv->mmsc_reg_base = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(priv->mmsc_reg_base)) > + return PTR_ERR(priv->mmsc_reg_base); > + > + priv->irq = platform_get_irq(pdev, A64FX_DIAG_IRQ); > + if (priv->irq < 0) > + return priv->irq; > + > + platform_set_drvdata(pdev, priv); > + > + a64fx_diag_interrupt_clear(priv); > + a64fx_diag_interrupt_enable(priv); > + > + irq_flags = IRQF_PERCPU | IRQF_NOBALANCING | IRQF_NO_AUTOEN | > + IRQF_NO_THREAD; > + ret = request_nmi(priv->irq, &a64fx_diag_handler_nmi, irq_flags, > + "a64fx_diag_nmi", NULL); > + if (ret) { > + ret = request_irq(priv->irq, &a64fx_diag_handler_irq, > + irq_flags, "a64fx_diag_irq", NULL); > + if (ret) { > + dev_err(dev, "cannot register IRQ %d\n", ret); No a64fx_diag_interrupt_disable()? > + return ret; > + } > + enable_irq(priv->irq); Hmm... > + priv->has_nmi = false; No need to set zeroed priv member to zero. > + } else { > + enable_nmi(priv->irq); Provided the above, I don't immediatelly see, what's the purpose of IRQF_NO_AUTOEN then? > + priv->has_nmi = true; > + } > + > + return 0; > +} > + > +static int __exit a64fx_diag_remove(struct platform_device *pdev) Is __exit appropriate here at all -- I doubt that. > +{ > + struct a64fx_diag_priv *priv = platform_get_drvdata(pdev); > + > + a64fx_diag_interrupt_disable(priv); > + a64fx_diag_interrupt_clear(priv); > + > + if (priv->has_nmi) > + free_nmi(priv->irq, NULL); > + else > + free_irq(priv->irq, NULL); > + > + return 0; > +} > + > +static const struct acpi_device_id a64fx_diag_acpi_match[] = { > + { "FUJI2007", 0 }, > + { }, > +}; > +MODULE_DEVICE_TABLE(acpi, a64fx_diag_acpi_match); > + > + > +static struct platform_driver a64fx_diag_driver = { > + .driver = { > + .name = "a64fx_diag_driver", > + .acpi_match_table = ACPI_PTR(a64fx_diag_acpi_match), > + }, > + .probe = a64fx_diag_probe, > + .remove = a64fx_diag_remove, > +}; > + > +module_platform_driver(a64fx_diag_driver); > + > +MODULE_LICENSE("GPL v2"); > +MODULE_AUTHOR("Hitomi Hasegawa <hasegawa-hitomi@fujitsu.com>"); > +MODULE_DESCRIPTION("A64FX diag driver");
On Wed, May 11, 2022 at 03:21:13PM +0900, Hitomi Hasegawa wrote: > Enable diagnostic interrupts for the Fujitsu A64FX. > > Register the NMI/IRQ corresponding to the A64FX's device definition > dedicated to diagnostic interrupts, so that when this interrupt is > sent using the BMC, it causes a panic. This can be used to obtain > a kernel dump. > > Signed-off-by: Hitomi Hasegawa <hasegawa-hitomi@fujitsu.com> > --- > MAINTAINERS | 5 + > drivers/soc/Kconfig | 1 + > drivers/soc/Makefile | 1 + > drivers/soc/fujitsu/Kconfig | 13 +++ > drivers/soc/fujitsu/Makefile | 3 + > drivers/soc/fujitsu/a64fx-diag.c | 155 +++++++++++++++++++++++++++++++ > 6 files changed, 178 insertions(+) > create mode 100644 drivers/soc/fujitsu/Kconfig > create mode 100644 drivers/soc/fujitsu/Makefile > create mode 100644 drivers/soc/fujitsu/a64fx-diag.c > > diff --git a/MAINTAINERS b/MAINTAINERS > index cd0f68d4a34a..dc35c81ba917 100644 > --- a/MAINTAINERS > +++ b/MAINTAINERS > @@ -241,6 +241,11 @@ F: include/trace/events/9p.h > F: include/uapi/linux/virtio_9p.h > F: net/9p/ > > +A64FX DIAG DRIVER > +M: Hitomi Hasegawa <hasegawa-hitomi@fujitsu.com> > +S: Supported > +F: drivers/soc/fujitsu/a64fx-diag.c > + > A8293 MEDIA DRIVER > M: Antti Palosaari <crope@iki.fi> > L: linux-media@vger.kernel.org > diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig > index a8562678c437..e10eb27e1e7e 100644 > --- a/drivers/soc/Kconfig > +++ b/drivers/soc/Kconfig > @@ -9,6 +9,7 @@ source "drivers/soc/atmel/Kconfig" > source "drivers/soc/bcm/Kconfig" > source "drivers/soc/canaan/Kconfig" > source "drivers/soc/fsl/Kconfig" > +source "drivers/soc/fujitsu/Kconfig" > source "drivers/soc/imx/Kconfig" > source "drivers/soc/ixp4xx/Kconfig" > source "drivers/soc/litex/Kconfig" > diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile > index adb30c2d4fea..b12b0b03ad47 100644 > --- a/drivers/soc/Makefile > +++ b/drivers/soc/Makefile > @@ -12,6 +12,7 @@ obj-$(CONFIG_SOC_CANAAN) += canaan/ > obj-$(CONFIG_ARCH_DOVE) += dove/ > obj-$(CONFIG_MACH_DOVE) += dove/ > obj-y += fsl/ > +obj-y += fujitsu/ Why a sub directory for just one .c file? > obj-$(CONFIG_ARCH_GEMINI) += gemini/ > obj-y += imx/ > obj-y += ixp4xx/ > diff --git a/drivers/soc/fujitsu/Kconfig b/drivers/soc/fujitsu/Kconfig > new file mode 100644 > index 000000000000..e05c40725922 > --- /dev/null > +++ b/drivers/soc/fujitsu/Kconfig > @@ -0,0 +1,13 @@ > +# SPDX-License-Identifier: GPL-2.0-only > +menu "fujitsu SoC drivers" > + > +config A64FX_DIAG > + tristate "A64FX diag driver" > + depends on ARM64 > + depends on ACPI > + help > + Say Y here if you want to enable diag interrupt on Fujitsu A64FX. > + > + If unsure, say N. You need to provide more information about what this driver does and what it is here. thanks, greg k-h
On 11. 05. 22, 8:21, Hitomi Hasegawa wrote: > --- /dev/null > +++ b/drivers/soc/fujitsu/a64fx-diag.c > @@ -0,0 +1,155 @@ ... > +#define BMC_DIAG_INTERRUPT_STATUS_OFFSET (0x0044) > +#define BMC_DIAG_INTERRUPT_ENABLE_OFFSET (0x0040) And I noticed here, I would: * remove unneeded parentheses * drop the "_OFFSET" suffix * just write 8bit values (0x40, 0x44), given they fit * order them numerically, 0x40 goes first thanks,
On Wed, May 11, 2022 at 8:50 AM Greg KH <gregkh@linuxfoundation.org> wrote: > > --- a/drivers/soc/Makefile > > +++ b/drivers/soc/Makefile > > @@ -12,6 +12,7 @@ obj-$(CONFIG_SOC_CANAAN) += canaan/ > > obj-$(CONFIG_ARCH_DOVE) += dove/ > > obj-$(CONFIG_MACH_DOVE) += dove/ > > obj-y += fsl/ > > +obj-y += fujitsu/ > > Why a sub directory for just one .c file? All the other drivers/soc/ contents are in subdirectories, so I think I'd keep it like this. There are also other drivers that have been proposed for fujitsu a64fx. Arnd
Hi Jiri, > I'm not sure why you cc linux-serial, but anyway, comments below :). I used sysrq until the last version, so I still included kernel-serial in the destination. I am not planning to use sysrq now, so I will remove it from the destination from the next version. Thank you for your comment. > > +struct a64fx_diag_priv { > > + int irq; > > + void __iomem *mmsc_reg_base; > > + bool has_nmi; > > There are unnecessary holes in the struct. If you reorder it, you drop some > alignment. Like: pointer, int, bool. > > + u32 mmsc; > > + void __iomem *diag_status_reg_addr; > > I'm not sure what soc/ maintainers prefer, but inverted xmas tree would look/read > better. > > + priv = devm_kzalloc(dev, sizeof(struct a64fx_diag_priv), > > +GFP_KERNEL); > > Don't we prefer sizeof(*priv)? > > + ret = request_irq(priv->irq, &a64fx_diag_handler_irq, > > + irq_flags, "a64fx_diag_irq", NULL); > > + if (ret) { > > + dev_err(dev, "cannot register IRQ %d\n", ret); > > No a64fx_diag_interrupt_disable()? > > + priv->has_nmi = false; > > No need to set zeroed priv member to zero. I understand. I will fix it as per your comment. Thank you. > > + enable_nmi(priv->irq); > > Provided the above, I don't immediatelly see, what's the purpose of > IRQF_NO_AUTOEN then? It seems that request_nmi() requires IRQF_NO_AUTOEN. > > +static int __exit a64fx_diag_remove(struct platform_device *pdev) > > Is __exit appropriate here at all -- I doubt that. I will remove __exit as it seems unnecessary as you suggested. Also, I will correct BMC_DIAG_INTERRUPT_STATUS_OFFSET and BMC_DIAG_INTERRUPT_ENABLE_OFFSET. Thank you. Hitomi Hasegawa
Hi Greg, > > +obj-y += fujitsu/ > > Why a sub directory for just one .c file? As Arnd mentioned, I placed the sub directory following the convention of drivers/soc. > > + help > > + Say Y here if you want to enable diag interrupt on Fujitsu A64FX. > > + > > + If unsure, say N. > > You need to provide more information about what this driver does and what it is > here. OK, I will add a description. Thank you. Hitomi Hasegawa
diff --git a/MAINTAINERS b/MAINTAINERS index cd0f68d4a34a..dc35c81ba917 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -241,6 +241,11 @@ F: include/trace/events/9p.h F: include/uapi/linux/virtio_9p.h F: net/9p/ +A64FX DIAG DRIVER +M: Hitomi Hasegawa <hasegawa-hitomi@fujitsu.com> +S: Supported +F: drivers/soc/fujitsu/a64fx-diag.c + A8293 MEDIA DRIVER M: Antti Palosaari <crope@iki.fi> L: linux-media@vger.kernel.org diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index a8562678c437..e10eb27e1e7e 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -9,6 +9,7 @@ source "drivers/soc/atmel/Kconfig" source "drivers/soc/bcm/Kconfig" source "drivers/soc/canaan/Kconfig" source "drivers/soc/fsl/Kconfig" +source "drivers/soc/fujitsu/Kconfig" source "drivers/soc/imx/Kconfig" source "drivers/soc/ixp4xx/Kconfig" source "drivers/soc/litex/Kconfig" diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index adb30c2d4fea..b12b0b03ad47 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_SOC_CANAAN) += canaan/ obj-$(CONFIG_ARCH_DOVE) += dove/ obj-$(CONFIG_MACH_DOVE) += dove/ obj-y += fsl/ +obj-y += fujitsu/ obj-$(CONFIG_ARCH_GEMINI) += gemini/ obj-y += imx/ obj-y += ixp4xx/ diff --git a/drivers/soc/fujitsu/Kconfig b/drivers/soc/fujitsu/Kconfig new file mode 100644 index 000000000000..e05c40725922 --- /dev/null +++ b/drivers/soc/fujitsu/Kconfig @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +menu "fujitsu SoC drivers" + +config A64FX_DIAG + tristate "A64FX diag driver" + depends on ARM64 + depends on ACPI + help + Say Y here if you want to enable diag interrupt on Fujitsu A64FX. + + If unsure, say N. + +endmenu diff --git a/drivers/soc/fujitsu/Makefile b/drivers/soc/fujitsu/Makefile new file mode 100644 index 000000000000..945bc1c14ad0 --- /dev/null +++ b/drivers/soc/fujitsu/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_A64FX_DIAG) += a64fx-diag.o diff --git a/drivers/soc/fujitsu/a64fx-diag.c b/drivers/soc/fujitsu/a64fx-diag.c new file mode 100644 index 000000000000..0776c6de88c2 --- /dev/null +++ b/drivers/soc/fujitsu/a64fx-diag.c @@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * A64FX diag driver. + * Copyright (c) 2022 Fujitsu Ltd. + */ + +#include <linux/acpi.h> +#include <linux/interrupt.h> +#include <linux/irq.h> +#include <linux/module.h> +#include <linux/platform_device.h> + +#define A64FX_DIAG_IRQ 1 +#define BMC_DIAG_INTERRUPT_STATUS_OFFSET (0x0044) +#define BMC_DIAG_INTERRUPT_ENABLE_OFFSET (0x0040) +#define BMC_DIAG_INTERRUPT_MASK BIT(31) + +struct a64fx_diag_priv { + int irq; + void __iomem *mmsc_reg_base; + bool has_nmi; +}; + +static irqreturn_t a64fx_diag_handler_nmi(int irq, void *dev_id) +{ + nmi_panic(NULL, "a64fx_diag: interrupt received\n"); + + return IRQ_HANDLED; +} + +static irqreturn_t a64fx_diag_handler_irq(int irq, void *dev_id) +{ + panic("a64fx_diag: interrupt received\n"); + + return IRQ_HANDLED; +} + +static void a64fx_diag_interrupt_clear(struct a64fx_diag_priv *priv) +{ + u32 mmsc; + void __iomem *diag_status_reg_addr; + + diag_status_reg_addr = priv->mmsc_reg_base + BMC_DIAG_INTERRUPT_STATUS_OFFSET; + mmsc = readl(diag_status_reg_addr); + if (mmsc & BMC_DIAG_INTERRUPT_MASK) + writel(BMC_DIAG_INTERRUPT_MASK, diag_status_reg_addr); +} + +static void a64fx_diag_interrupt_enable(struct a64fx_diag_priv *priv) +{ + u32 mmsc; + void __iomem *diag_enable_reg_addr; + + diag_enable_reg_addr = priv->mmsc_reg_base + BMC_DIAG_INTERRUPT_ENABLE_OFFSET; + mmsc = readl(diag_enable_reg_addr); + if (!(mmsc & BMC_DIAG_INTERRUPT_MASK)) { + mmsc |= BMC_DIAG_INTERRUPT_MASK; + writel(mmsc, diag_enable_reg_addr); + } +} + +static void a64fx_diag_interrupt_disable(struct a64fx_diag_priv *priv) +{ + u32 mmsc; + void __iomem *diag_enable_reg_addr; + + diag_enable_reg_addr = priv->mmsc_reg_base + BMC_DIAG_INTERRUPT_ENABLE_OFFSET; + mmsc = readl(diag_enable_reg_addr); + if (mmsc & BMC_DIAG_INTERRUPT_MASK) { + mmsc &= ~BMC_DIAG_INTERRUPT_MASK; + writel(mmsc, diag_enable_reg_addr); + } +} + +static int a64fx_diag_probe(struct platform_device *pdev) +{ + int ret; + unsigned long irq_flags; + struct device *dev = &pdev->dev; + struct a64fx_diag_priv *priv; + + priv = devm_kzalloc(dev, sizeof(struct a64fx_diag_priv), GFP_KERNEL); + if (priv == NULL) + return -ENOMEM; + + priv->mmsc_reg_base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(priv->mmsc_reg_base)) + return PTR_ERR(priv->mmsc_reg_base); + + priv->irq = platform_get_irq(pdev, A64FX_DIAG_IRQ); + if (priv->irq < 0) + return priv->irq; + + platform_set_drvdata(pdev, priv); + + a64fx_diag_interrupt_clear(priv); + a64fx_diag_interrupt_enable(priv); + + irq_flags = IRQF_PERCPU | IRQF_NOBALANCING | IRQF_NO_AUTOEN | + IRQF_NO_THREAD; + ret = request_nmi(priv->irq, &a64fx_diag_handler_nmi, irq_flags, + "a64fx_diag_nmi", NULL); + if (ret) { + ret = request_irq(priv->irq, &a64fx_diag_handler_irq, + irq_flags, "a64fx_diag_irq", NULL); + if (ret) { + dev_err(dev, "cannot register IRQ %d\n", ret); + return ret; + } + enable_irq(priv->irq); + priv->has_nmi = false; + } else { + enable_nmi(priv->irq); + priv->has_nmi = true; + } + + return 0; +} + +static int __exit a64fx_diag_remove(struct platform_device *pdev) +{ + struct a64fx_diag_priv *priv = platform_get_drvdata(pdev); + + a64fx_diag_interrupt_disable(priv); + a64fx_diag_interrupt_clear(priv); + + if (priv->has_nmi) + free_nmi(priv->irq, NULL); + else + free_irq(priv->irq, NULL); + + return 0; +} + +static const struct acpi_device_id a64fx_diag_acpi_match[] = { + { "FUJI2007", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(acpi, a64fx_diag_acpi_match); + + +static struct platform_driver a64fx_diag_driver = { + .driver = { + .name = "a64fx_diag_driver", + .acpi_match_table = ACPI_PTR(a64fx_diag_acpi_match), + }, + .probe = a64fx_diag_probe, + .remove = a64fx_diag_remove, +}; + +module_platform_driver(a64fx_diag_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_AUTHOR("Hitomi Hasegawa <hasegawa-hitomi@fujitsu.com>"); +MODULE_DESCRIPTION("A64FX diag driver");
Enable diagnostic interrupts for the Fujitsu A64FX. Register the NMI/IRQ corresponding to the A64FX's device definition dedicated to diagnostic interrupts, so that when this interrupt is sent using the BMC, it causes a panic. This can be used to obtain a kernel dump. Signed-off-by: Hitomi Hasegawa <hasegawa-hitomi@fujitsu.com> --- MAINTAINERS | 5 + drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/fujitsu/Kconfig | 13 +++ drivers/soc/fujitsu/Makefile | 3 + drivers/soc/fujitsu/a64fx-diag.c | 155 +++++++++++++++++++++++++++++++ 6 files changed, 178 insertions(+) create mode 100644 drivers/soc/fujitsu/Kconfig create mode 100644 drivers/soc/fujitsu/Makefile create mode 100644 drivers/soc/fujitsu/a64fx-diag.c