[PATCH RFC] powerpc/powernv: sysfs entry to force full IPL reboot

Andrew Donnellan andrew.donnellan at au1.ibm.com
Tue Nov 22 20:22:58 AEDT 2016


skiboot now supports "fast reboot", a reboot procedure where skiboot
reinitialises hardware and loads a new kernel without re-IPLing the
machine. At present, fast reboot support is still experimental and is not
enabled by default, however it is intended that it will be enabled by
default in a near-future release.

There may be some circumstances where the user wants to force a full IPL
reboot rather than using fast reboot. Add support for the
OPAL_REBOOT_FULL_IPL reboot type, enabled by writing 1 to
/sys/firmware/opal/force_full_ipl_reboot. On versions of skiboot that
implement the OPAL_REBOOT_FULL_IPL reboot type, this will force an IPL. On
versions that do not, print an error message on reboot and proceed with a
regular reboot (which could be a full IPL or a fast reboot).

Cc: Stewart Smith <stewart at linux.vnet.ibm.com>
Cc: Benjamin Herrenschmidt <benh at kernel.crashing.org>
Signed-off-by: Andrew Donnellan <andrew.donnellan at au1.ibm.com>

---

Corresponding skiboot patch: http://patchwork.ozlabs.org/patch/697601/

This seemed like a good idea at the time. A sysfs-based flag was the best 
option that came to mind; other suggestions are welcome. Is "full IPL" a 
reasonable term to use or should I try to think of something a bit less 
IBM-ese?

---
 arch/powerpc/include/asm/opal-api.h    |  1 +
 arch/powerpc/include/asm/opal.h        |  1 +
 arch/powerpc/platforms/powernv/opal.c  |  2 ++
 arch/powerpc/platforms/powernv/setup.c | 63 +++++++++++++++++++++++++++++++++-
 4 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/opal-api.h b/arch/powerpc/include/asm/opal-api.h
index 0e2e57b..4de1f63 100644
--- a/arch/powerpc/include/asm/opal-api.h
+++ b/arch/powerpc/include/asm/opal-api.h
@@ -918,6 +918,7 @@ enum OpalSysCooling {
 enum {
 	OPAL_REBOOT_NORMAL		= 0,
 	OPAL_REBOOT_PLATFORM_ERROR	= 1,
+	OPAL_REBOOT_FULL_IPL		= 2,
 };
 
 /* Argument to OPAL_PCI_TCE_KILL */
diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h
index e958b70..a5e4065 100644
--- a/arch/powerpc/include/asm/opal.h
+++ b/arch/powerpc/include/asm/opal.h
@@ -270,6 +270,7 @@ extern void opal_platform_dump_init(void);
 extern void opal_sys_param_init(void);
 extern void opal_msglog_init(void);
 extern void opal_msglog_sysfs_init(void);
+extern void opal_reboot_sysfs_init(void);
 extern int opal_async_comp_init(void);
 extern int opal_sensor_init(void);
 extern int opal_hmi_handler_init(void);
diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c
index 6c9a65b..c619d8d 100644
--- a/arch/powerpc/platforms/powernv/opal.c
+++ b/arch/powerpc/platforms/powernv/opal.c
@@ -750,6 +750,8 @@ static int __init opal_init(void)
 		opal_sys_param_init();
 		/* Setup message log sysfs interface. */
 		opal_msglog_sysfs_init();
+		/* Setup reboot sysfs interface. */
+		opal_reboot_sysfs_init();
 	}
 
 	/* Initialize platform devices: IPMI backend, PRD & flash interface */
diff --git a/arch/powerpc/platforms/powernv/setup.c b/arch/powerpc/platforms/powernv/setup.c
index efe8b6b..d2460fc 100644
--- a/arch/powerpc/platforms/powernv/setup.c
+++ b/arch/powerpc/platforms/powernv/setup.c
@@ -28,6 +28,7 @@
 #include <linux/bug.h>
 #include <linux/pci.h>
 #include <linux/cpufreq.h>
+#include <linux/sysfs.h>
 
 #include <asm/machdep.h>
 #include <asm/firmware.h>
@@ -118,6 +119,53 @@ static void pnv_prepare_going_down(void)
 	opal_flash_term_callback();
 }
 
+static bool force_full_ipl_reboot = false;
+
+static ssize_t force_full_ipl_reboot_show(struct kobject *k,
+					  struct kobj_attribute *attr,
+					  char *buf)
+{
+	return sprintf(buf, "%d\n", (int) force_full_ipl_reboot);
+}
+
+static ssize_t force_full_ipl_reboot_store(struct kobject *k,
+					   struct kobj_attribute *attr,
+					   const char *buf,
+					   size_t count)
+{
+	if (count != 2)  /* including trailing NUL */
+		return -EINVAL;
+
+	switch (buf[0]) {
+	case '0':
+		force_full_ipl_reboot = false;
+		return count;
+	case '1':
+		force_full_ipl_reboot = true;
+		return count;
+	default:
+		return -EINVAL;
+	}
+}
+
+static struct kobj_attribute opal_force_full_ipl_reboot_attr =
+	__ATTR(force_full_ipl_reboot, 0644, force_full_ipl_reboot_show,
+	       force_full_ipl_reboot_store);
+
+void opal_reboot_sysfs_init(void) {
+	int rc = 0;
+
+	if (!opal_kobj) {
+		pr_warn("setup: opal kobject is not available");
+		return;
+	}
+
+	rc = sysfs_create_file(opal_kobj, &opal_force_full_ipl_reboot_attr.attr);
+	if (rc)
+		pr_err("setup: unable to create sysfs file "
+		       "force_full_ipl_reboot (%d)", rc);
+}
+
 static void  __noreturn pnv_restart(char *cmd)
 {
 	long rc = OPAL_BUSY;
@@ -125,7 +173,20 @@ static void  __noreturn pnv_restart(char *cmd)
 	pnv_prepare_going_down();
 
 	while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT) {
-		rc = opal_cec_reboot();
+		if (force_full_ipl_reboot && opal_check_token(OPAL_CEC_REBOOT2)) {
+			rc = opal_cec_reboot2(OPAL_REBOOT_FULL_IPL,
+					      "Full IPL reboot requested");
+
+			if (rc == OPAL_UNSUPPORTED) {
+				pr_err("Firmware doesn't support forcing full "
+				       "IPL reboot");
+				force_full_ipl_reboot = false;
+				rc = opal_cec_reboot();
+			}
+		} else {
+			rc = opal_cec_reboot();
+		}
+
 		if (rc == OPAL_BUSY_EVENT)
 			opal_poll_events(NULL);
 		else
-- 
Andrew Donnellan              OzLabs, ADL Canberra
andrew.donnellan at au1.ibm.com  IBM Australia Limited



More information about the Linuxppc-dev mailing list