Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Watchdog driver for z/VM and LPAR using the diag 288 interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Under z/VM, expiration of the watchdog will send a "system restart" command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * to CP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * The command can be altered using the module parameter "cmd". This is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * not recommended because it's only supported on z/VM but not whith LPAR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * On LPAR, the watchdog will always trigger a system restart. the module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * paramter cmd is meaningless here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * Copyright IBM Corp. 2004, 2013
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * Author(s): Arnd Bergmann (arndb@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *	      Philipp Hachtmann (phacht@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define KMSG_COMPONENT "diag288_wdt"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/watchdog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/ebcdic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/diag.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define MAX_CMDLEN 240
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define DEFAULT_CMD "SYSTEM RESTART"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define MIN_INTERVAL 15     /* Minimal time supported by diag88 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define MAX_INTERVAL 3600   /* One hour should be enough - pure estimation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define WDT_DEFAULT_TIMEOUT 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) /* Function codes - init, change, cancel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define WDT_FUNC_INIT 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define WDT_FUNC_CHANGE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define WDT_FUNC_CANCEL 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define WDT_FUNC_CONCEAL 0x80000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /* Action codes for LPAR watchdog */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define LPARWDT_RESTART 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static char wdt_cmd[MAX_CMDLEN] = DEFAULT_CMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static bool conceal_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static bool nowayout_info = WATCHDOG_NOWAYOUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) MODULE_AUTHOR("Philipp Hachtmann <phacht@de.ibm.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) MODULE_DESCRIPTION("System z diag288  Watchdog Timer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) module_param_string(cmd, wdt_cmd, MAX_CMDLEN, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) MODULE_PARM_DESC(cmd, "CP command that is run when the watchdog triggers (z/VM only)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) module_param_named(conceal, conceal_on, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) MODULE_PARM_DESC(conceal, "Enable the CONCEAL CP option while the watchdog is active (z/VM only)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) module_param_named(nowayout, nowayout_info, bool, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default = CONFIG_WATCHDOG_NOWAYOUT)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) MODULE_ALIAS("vmwatchdog");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static int __diag288(unsigned int func, unsigned int timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		     unsigned long action, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	register unsigned long __func asm("2") = func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	register unsigned long __timeout asm("3") = timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	register unsigned long __action asm("4") = action;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	register unsigned long __len asm("5") = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	asm volatile(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		"	diag	%1, %3, 0x288\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		"0:	la	%0, 0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		"1:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		EX_TABLE(0b, 1b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		: "+d" (err) : "d"(__func), "d"(__timeout),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		  "d"(__action), "d"(__len) : "1", "cc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static int __diag288_vm(unsigned int  func, unsigned int timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			char *cmd, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	diag_stat_inc(DIAG_STAT_X288);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return __diag288(func, timeout, virt_to_phys(cmd), len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int __diag288_lpar(unsigned int func, unsigned int timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			  unsigned long action)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	diag_stat_inc(DIAG_STAT_X288);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	return __diag288(func, timeout, action, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static unsigned long wdt_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #define DIAG_WDOG_BUSY	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int wdt_start(struct watchdog_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	char *ebc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	unsigned int func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (test_and_set_bit(DIAG_WDOG_BUSY, &wdt_status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (MACHINE_IS_VM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		ebc_cmd = kmalloc(MAX_CMDLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		if (!ebc_cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			clear_bit(DIAG_WDOG_BUSY, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		len = strlcpy(ebc_cmd, wdt_cmd, MAX_CMDLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		ASCEBC(ebc_cmd, MAX_CMDLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		EBC_TOUPPER(ebc_cmd, MAX_CMDLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		func = conceal_on ? (WDT_FUNC_INIT | WDT_FUNC_CONCEAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			: WDT_FUNC_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		ret = __diag288_vm(func, dev->timeout, ebc_cmd, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		WARN_ON(ret != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		kfree(ebc_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		ret = __diag288_lpar(WDT_FUNC_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				     dev->timeout, LPARWDT_RESTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		pr_err("The watchdog cannot be activated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		clear_bit(DIAG_WDOG_BUSY, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int wdt_stop(struct watchdog_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	diag_stat_inc(DIAG_STAT_X288);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	ret = __diag288(WDT_FUNC_CANCEL, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	clear_bit(DIAG_WDOG_BUSY, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int wdt_ping(struct watchdog_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	char *ebc_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	unsigned int func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (MACHINE_IS_VM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		ebc_cmd = kmalloc(MAX_CMDLEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		if (!ebc_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		len = strlcpy(ebc_cmd, wdt_cmd, MAX_CMDLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		ASCEBC(ebc_cmd, MAX_CMDLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		EBC_TOUPPER(ebc_cmd, MAX_CMDLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		 * It seems to be ok to z/VM to use the init function to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		 * retrigger the watchdog. On LPAR WDT_FUNC_CHANGE must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		 * be used when the watchdog is running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		func = conceal_on ? (WDT_FUNC_INIT | WDT_FUNC_CONCEAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 			: WDT_FUNC_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		ret = __diag288_vm(func, dev->timeout, ebc_cmd, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		WARN_ON(ret != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		kfree(ebc_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		ret = __diag288_lpar(WDT_FUNC_CHANGE, dev->timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		pr_err("The watchdog timer cannot be started or reset\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int wdt_set_timeout(struct watchdog_device * dev, unsigned int new_to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	dev->timeout = new_to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	return wdt_ping(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static const struct watchdog_ops wdt_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	.start = wdt_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	.stop = wdt_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	.ping = wdt_ping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	.set_timeout = wdt_set_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static const struct watchdog_info wdt_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	.firmware_version = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	.identity = "z Watchdog",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static struct watchdog_device wdt_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	.parent = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	.info = &wdt_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	.ops = &wdt_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	.bootstatus = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.timeout = WDT_DEFAULT_TIMEOUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	.min_timeout = MIN_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	.max_timeout = MAX_INTERVAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * It makes no sense to go into suspend while the watchdog is running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * Depending on the memory size, the watchdog might trigger, while we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * are still saving the memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int wdt_suspend(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (test_and_set_bit(DIAG_WDOG_BUSY, &wdt_status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		pr_err("Linux cannot be suspended while the watchdog is in use\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return notifier_from_errno(-EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static int wdt_resume(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	clear_bit(DIAG_WDOG_BUSY, &wdt_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int wdt_power_event(struct notifier_block *this, unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			   void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	case PM_POST_HIBERNATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	case PM_POST_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return wdt_resume();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	case PM_HIBERNATION_PREPARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	case PM_SUSPEND_PREPARE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		return wdt_suspend();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static struct notifier_block wdt_power_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	.notifier_call = wdt_power_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int __init diag288_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	char ebc_begin[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		194, 197, 199, 201, 213
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	watchdog_set_nowayout(&wdt_dev, nowayout_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (MACHINE_IS_VM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		if (__diag288_vm(WDT_FUNC_INIT, 15,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				 ebc_begin, sizeof(ebc_begin)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			pr_err("The watchdog cannot be initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		if (__diag288_lpar(WDT_FUNC_INIT, 30, LPARWDT_RESTART)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			pr_err("The watchdog cannot be initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (__diag288_lpar(WDT_FUNC_CANCEL, 0, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		pr_err("The watchdog cannot be deactivated\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	ret = register_pm_notifier(&wdt_power_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	ret = watchdog_register_device(&wdt_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		unregister_pm_notifier(&wdt_power_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static void __exit diag288_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	watchdog_unregister_device(&wdt_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	unregister_pm_notifier(&wdt_power_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) module_init(diag288_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) module_exit(diag288_exit);