]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Add sun4v_wdt watchdog driver
authorWim Coekaerts <wim.coekaerts@oracle.com>
Sun, 24 Jan 2016 23:59:22 +0000 (15:59 -0800)
committerAllen Pais <allen.pais@oracle.com>
Tue, 26 Jan 2016 18:18:55 +0000 (23:48 +0530)
This driver adds sparc hypervisor watchdog support. Timeout is set in
milliseconds since that is the granularity supported and it honors
the settings of both the watchdog-resolution and watchdog-max-timeout
MD properties.

Note that most watchdog drivers use timeout in seconds. This driver
requires timeout_ms as a module parameter and time in ms.

In this driver, the default is 60000ms or 60 seconds.

This driver also modifies hvcalls.S and changes sun4v_mach0_set_watchdog
such that it allows for NULL to be passed as 2nd parameter. This removes
the need to pass &time_remaining which is not useful.

Signed-off-by: Wim Coekaerts <wim.coekaerts@oracle.com>
Documentation/watchdog/watchdog-parameters.txt
arch/sparc/kernel/hvcalls.S
arch/sparc/kernel/sparc_ksyms_64.c
drivers/watchdog/Kconfig
drivers/watchdog/Makefile
drivers/watchdog/sun4v_wdt.c [new file with mode: 0644]

index 692791cc674c44f20398c8b8f64bd652d6ea9f12..23ad1ca5323f83a17b9576524ef16e03c5083e8f 100644 (file)
@@ -397,3 +397,7 @@ wm8350_wdt:
 nowayout: Watchdog cannot be stopped once started
        (default=kernel config parameter)
 -------------------------------------------------
+sun4v_wdt:
+timeout_ms: Watchdog timeout in milliseconds 1..180000, default=60000)
+nowayout: Watchdog cannot be stopped once started
+-------------------------------------------------
index 40f7e5e5da25f371bbb6eaa6400d32c2ef717755..cae3af12908b4bf2b173f4d5d76b2821666732c3 100644 (file)
@@ -338,8 +338,9 @@ ENTRY(sun4v_mach_set_watchdog)
        mov     %o1, %o4
        mov     HV_FAST_MACH_SET_WATCHDOG, %o5
        ta      HV_FAST_TRAP
+       brnz,a,pn %o4, 0f
        stx     %o1, [%o4]
-       retl
+0:     retl
         nop
 ENDPROC(sun4v_mach_set_watchdog)
 
index a92d5d2c46a3a6553bf13a57f95f65c6d61c334c..9e034f29dcc52208ca98a648e028f955f7c8f882 100644 (file)
@@ -37,6 +37,7 @@ EXPORT_SYMBOL(sun4v_niagara_getperf);
 EXPORT_SYMBOL(sun4v_niagara_setperf);
 EXPORT_SYMBOL(sun4v_niagara2_getperf);
 EXPORT_SYMBOL(sun4v_niagara2_setperf);
+EXPORT_SYMBOL(sun4v_mach_set_watchdog);
 
 /* from hweight.S */
 EXPORT_SYMBOL(__arch_hweight8);
index e5e7c5505de7dc8f289f3891013b0eac25399747..177f6c1ee43630a1d0e18a9c933cd7cad37ba3e6 100644 (file)
@@ -1426,6 +1426,17 @@ config WATCHDOG_RIO
          machines.  The watchdog timeout period is normally one minute but
          can be changed with a boot-time parameter.
 
+config WATCHDOG_SUN4V
+       tristate "Sun4v Watchdog support"
+       select WATCHDOG_CORE
+       depends on SPARC64
+       help
+         Say Y here to support the hypervisor watchdog capability provided
+         by Oracle VM for SPARC.
+
+         To compile this driver as a module, choose M here. The module will
+         be called sun4v_wdt.
+
 # XTENSA Architecture
 
 # Xen Architecture
index 5c19294d1c3015acaf14e4a52734f0c82ae798db..5ec0f49fa167d653e818e3e1b1cb46a55720fef6 100644 (file)
@@ -170,6 +170,7 @@ obj-$(CONFIG_SH_WDT) += shwdt.o
 
 obj-$(CONFIG_WATCHDOG_RIO)             += riowd.o
 obj-$(CONFIG_WATCHDOG_CP1XXX)          += cpwd.o
+obj-$(CONFIG_WATCHDOG_SUN4V)           += sun4v_wdt.o
 
 # XTENSA Architecture
 
diff --git a/drivers/watchdog/sun4v_wdt.c b/drivers/watchdog/sun4v_wdt.c
new file mode 100644 (file)
index 0000000..f19c544
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ *     sun4v watchdog timer
+ *     (c) Copyright 2016 Oracle Corporation
+ *
+ *     Implement a simple watchdog driver using the built-in sun4v hypervisor
+ *     watchdog support. If time expires, the hypervisor stops or bounces
+ *     the guest domain.
+ *
+ *     This program is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License
+ *     as published by the Free Software Foundation; either version
+ *     2 of the License, or (at your option) any later version.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/watchdog.h>
+#include <asm/hypervisor.h>
+#include <asm/mdesc.h>
+
+#define WDT_TIMEOUT_MS                 60000   /* 60 seconds */
+#define WDT_MAX_TIMEOUT_MS             180000  /* 180 seconds */
+#define WDT_MIN_TIMEOUT_MS             1000    /* 1 second */
+#define WDT_DEFAULT_RESOLUTION_MS      1000    /* 1 second */
+
+static unsigned int wdt_max_timeout_ms = WDT_MAX_TIMEOUT_MS;
+static unsigned int wdt_resolution_ms = WDT_DEFAULT_RESOLUTION_MS;
+
+static unsigned int timeout_ms = WDT_TIMEOUT_MS;
+module_param(timeout_ms, uint, S_IRUGO);
+MODULE_PARM_DESC(timeout_ms, "Watchdog timeout in ms (default="
+       __MODULE_STRING(WDT_TIMEOUT_MS) ")");
+
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, S_IRUGO);
+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
+       __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
+
+static int sun4v_wdt_stop(struct watchdog_device *wdd)
+{
+       sun4v_mach_set_watchdog(0, NULL);
+
+       return 0;
+}
+
+static int sun4v_wdt_ping(struct watchdog_device *wdd)
+{
+       int hverr;
+
+       hverr = sun4v_mach_set_watchdog(wdd->timeout, NULL);
+       if (hverr == HV_EINVAL)
+               return -EINVAL;
+
+       return 0;
+}
+
+static int sun4v_wdt_set_timeout(struct watchdog_device *wdd,
+                                unsigned int timeout)
+{
+       wdd->timeout = timeout - (timeout % wdt_resolution_ms);
+
+       return 0;
+}
+
+static const struct watchdog_info sun4v_wdt_ident = {
+       .options =      WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,
+       .identity =     "sun4v hypervisor watchdog",
+       .firmware_version = 0,
+};
+
+static struct watchdog_ops sun4v_wdt_ops = {
+       .owner =        THIS_MODULE,
+       .start =        sun4v_wdt_ping,
+       .stop =         sun4v_wdt_stop,
+       .ping =         sun4v_wdt_ping,
+       .set_timeout =  sun4v_wdt_set_timeout,
+};
+
+static struct watchdog_device wdd = {
+       .info = &sun4v_wdt_ident,
+       .ops = &sun4v_wdt_ops,
+       .min_timeout = WDT_MIN_TIMEOUT_MS,
+};
+
+static int hvapi_registered;
+
+static int __init sun4v_wdt_init(void)
+{
+       struct mdesc_handle *handle;
+       u64 node;
+       const u64 *value;
+       int ret = 0;
+       unsigned long major = 1, minor = 1;
+
+       if (sun4v_hvapi_register(HV_GRP_CORE, major, &minor) != 0)
+               return -ENODEV;
+       if (minor < 1) {
+               sun4v_hvapi_unregister(HV_GRP_CORE);
+               return -ENODEV;
+       }
+       hvapi_registered = 1;
+
+       /*
+        * There are 2 properties that can be set from the control
+        * domain for the watchdog.
+        * watchdog-resolution
+        * watchdog-max-timeout
+        *
+        * If there is no handle returned, this is no sun4v system
+        * so it's correct to return -ENODEV. Same for missing of the
+        * platform node.
+        */
+
+       handle = mdesc_grab();
+       if (!handle)
+               return -ENODEV;
+
+       node = mdesc_node_by_name(handle, MDESC_NODE_NULL, "platform");
+       if (node == MDESC_NODE_NULL) {
+               mdesc_release(handle);
+               return -ENODEV;
+       }
+
+       value = mdesc_get_property(handle, node, "watchdog-resolution", NULL);
+       if (value) {
+               wdt_resolution_ms = *value;
+               if (wdt_resolution_ms == 0 ||
+                   wdt_resolution_ms > WDT_DEFAULT_RESOLUTION_MS)
+                       wdt_resolution_ms = WDT_DEFAULT_RESOLUTION_MS;
+       }
+
+       value = mdesc_get_property(handle, node, "watchdog-max-timeout", NULL);
+       if (value) {
+               wdt_max_timeout_ms = *value;
+               /*
+                * If the property is defined to be smaller than default
+                * then set it to default.
+                */
+               if (wdt_max_timeout_ms < WDT_MIN_TIMEOUT_MS) {
+                       mdesc_release(handle);
+                       return -EINVAL;
+               }
+       }
+
+       mdesc_release(handle);
+
+       if (timeout_ms < WDT_MIN_TIMEOUT_MS)
+               timeout_ms = WDT_MIN_TIMEOUT_MS;
+       if (timeout_ms > WDT_MAX_TIMEOUT_MS)
+               timeout_ms = WDT_MAX_TIMEOUT_MS;
+       if (timeout_ms > wdt_max_timeout_ms)
+               timeout_ms = wdt_max_timeout_ms;
+
+       /*
+        * round to nearest smaller value
+        */
+       wdt_max_timeout_ms -= wdt_max_timeout_ms % wdt_resolution_ms;
+       timeout_ms -= timeout_ms % wdt_resolution_ms;
+
+       wdd.max_timeout = wdt_max_timeout_ms;
+       wdd.timeout = timeout_ms;
+
+       watchdog_set_nowayout(&wdd, nowayout);
+
+       ret = watchdog_register_device(&wdd);
+       if (ret) {
+               pr_err("Failed to register watchdog device\n");
+               return ret;
+       }
+
+       pr_info("initialized (timeout_ms=%dms, nowayout=%d)\n",
+                wdd.timeout, nowayout);
+
+       return 0;
+}
+
+
+static void __exit sun4v_wdt_exit(void)
+{
+       if (hvapi_registered)
+               sun4v_hvapi_unregister(HV_GRP_CORE);
+       sun4v_wdt_stop(&wdd);
+       watchdog_unregister_device(&wdd);
+}
+
+module_init(sun4v_wdt_init);
+module_exit(sun4v_wdt_exit);
+
+MODULE_AUTHOR("Wim Coekaerts <wim.coekaerts@oracle.com>");
+MODULE_DESCRIPTION("sun4v watchdog driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("sun4v_wdt");