powerpc/fadump: add fadump support on powernv
authorHari Bathini <hbathini@linux.ibm.com>
Wed, 11 Sep 2019 14:50:26 +0000 (20:20 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 13 Sep 2019 14:04:43 +0000 (00:04 +1000)
Add basic callback functions for FADump on PowerNV platform.

Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/156821342072.5656.4346362203141486452.stgit@hbathini.in.ibm.com
arch/powerpc/Kconfig
arch/powerpc/include/asm/fadump-internal.h
arch/powerpc/kernel/fadump.c
arch/powerpc/platforms/powernv/Makefile
arch/powerpc/platforms/powernv/opal-fadump.c [new file with mode: 0644]

index edc1936..375ff89 100644 (file)
@@ -569,7 +569,7 @@ config CRASH_DUMP
 
 config FA_DUMP
        bool "Firmware-assisted dump"
-       depends on PPC64 && PPC_RTAS
+       depends on PPC64 && (PPC_RTAS || PPC_POWERNV)
        select CRASH_CORE
        select CRASH_DUMP
        help
@@ -580,7 +580,8 @@ config FA_DUMP
          is meant to be a kdump replacement offering robustness and
          speed not possible without system firmware assistance.
 
-         If unsure, say "N"
+         If unsure, say "y". Only special kernels like petitboot may
+         need to say "N" here.
 
 config IRQ_ALL_CPUS
        bool "Distribute interrupts on all CPUs by default"
index 8c0eb0f..8046fe0 100644 (file)
@@ -135,4 +135,11 @@ static inline void
 rtas_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
 #endif
 
+#ifdef CONFIG_PPC_POWERNV
+extern void opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node);
+#else
+static inline void
+opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node) { }
+#endif
+
 #endif /* _ASM_POWERPC_FADUMP_INTERNAL_H */
index 9d9f7c3..b17673d 100644 (file)
@@ -107,11 +107,20 @@ static int __init fadump_cma_init(void) { return 1; }
 int __init early_init_dt_scan_fw_dump(unsigned long node, const char *uname,
                                      int depth, void *data)
 {
-       if (depth != 1 || strcmp(uname, "rtas") != 0)
+       if (depth != 1)
                return 0;
 
-       rtas_fadump_dt_scan(&fw_dump, node);
-       return 1;
+       if (strcmp(uname, "rtas") == 0) {
+               rtas_fadump_dt_scan(&fw_dump, node);
+               return 1;
+       }
+
+       if (strcmp(uname, "ibm,opal") == 0) {
+               opal_fadump_dt_scan(&fw_dump, node);
+               return 1;
+       }
+
+       return 0;
 }
 
 /*
index 49186f0..3e6d6d6 100644 (file)
@@ -7,6 +7,7 @@ obj-y                   += opal-kmsg.o opal-powercap.o opal-psr.o opal-sensor-groups.o
 obj-y                  += ultravisor.o
 
 obj-$(CONFIG_SMP)      += smp.o subcore.o subcore-asm.o
+obj-$(CONFIG_FA_DUMP)  += opal-fadump.o
 obj-$(CONFIG_PCI)      += pci.o pci-ioda.o npu-dma.o pci-ioda-tce.o
 obj-$(CONFIG_CXL_BASE) += pci-cxl.o
 obj-$(CONFIG_EEH)      += eeh-powernv.o
diff --git a/arch/powerpc/platforms/powernv/opal-fadump.c b/arch/powerpc/platforms/powernv/opal-fadump.c
new file mode 100644 (file)
index 0000000..bbc5356
--- /dev/null
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Firmware-Assisted Dump support on POWER platform (OPAL).
+ *
+ * Copyright 2019, Hari Bathini, IBM Corporation.
+ */
+
+#define pr_fmt(fmt) "opal fadump: " fmt
+
+#include <linux/string.h>
+#include <linux/seq_file.h>
+#include <linux/of_fdt.h>
+#include <linux/libfdt.h>
+
+#include <asm/opal.h>
+#include <asm/fadump-internal.h>
+
+static u64 opal_fadump_init_mem_struct(struct fw_dump *fadump_conf)
+{
+       return fadump_conf->reserve_dump_area_start;
+}
+
+static int opal_fadump_register(struct fw_dump *fadump_conf)
+{
+       return -EIO;
+}
+
+static int opal_fadump_unregister(struct fw_dump *fadump_conf)
+{
+       return -EIO;
+}
+
+static int opal_fadump_invalidate(struct fw_dump *fadump_conf)
+{
+       return -EIO;
+}
+
+static int __init opal_fadump_process(struct fw_dump *fadump_conf)
+{
+       return -EINVAL;
+}
+
+static void opal_fadump_region_show(struct fw_dump *fadump_conf,
+                                   struct seq_file *m)
+{
+}
+
+static void opal_fadump_trigger(struct fadump_crash_info_header *fdh,
+                               const char *msg)
+{
+       int rc;
+
+       rc = opal_cec_reboot2(OPAL_REBOOT_MPIPL, msg);
+       if (rc == OPAL_UNSUPPORTED) {
+               pr_emerg("Reboot type %d not supported.\n",
+                        OPAL_REBOOT_MPIPL);
+       } else if (rc == OPAL_HARDWARE)
+               pr_emerg("No backend support for MPIPL!\n");
+}
+
+static struct fadump_ops opal_fadump_ops = {
+       .fadump_init_mem_struct         = opal_fadump_init_mem_struct,
+       .fadump_register                = opal_fadump_register,
+       .fadump_unregister              = opal_fadump_unregister,
+       .fadump_invalidate              = opal_fadump_invalidate,
+       .fadump_process                 = opal_fadump_process,
+       .fadump_region_show             = opal_fadump_region_show,
+       .fadump_trigger                 = opal_fadump_trigger,
+};
+
+void __init opal_fadump_dt_scan(struct fw_dump *fadump_conf, u64 node)
+{
+       unsigned long dn;
+
+       /*
+        * Check if Firmware-Assisted Dump is supported. if yes, check
+        * if dump has been initiated on last reboot.
+        */
+       dn = of_get_flat_dt_subnode_by_name(node, "dump");
+       if (dn == -FDT_ERR_NOTFOUND) {
+               pr_debug("FADump support is missing!\n");
+               return;
+       }
+
+       if (!of_flat_dt_is_compatible(dn, "ibm,opal-dump")) {
+               pr_err("Support missing for this f/w version!\n");
+               return;
+       }
+
+       fadump_conf->ops                = &opal_fadump_ops;
+       fadump_conf->fadump_supported   = 1;
+}