diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-06-21 12:47:01 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-06-21 12:47:01 -0400 |
commit | 7a8e9c80889732891df50d44328f330316834eb1 (patch) | |
tree | 69796bb89360fbd90fb72724b00b4f803569619b /drivers/watchdog | |
parent | f1b35b83054cf2b581befd48d32517fadf0d9b16 (diff) | |
parent | fa73eb4738fc75317a481aa95cd472d0d6d057c3 (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
Pull s390 patches from Martin Schwidefsky:
"A couple of bug fixes, a debug change for qdio, an update for the
default config, and one small extension.
The watchdog module based on diagnose 0x288 is converted to the
watchdog API and it now works under LPAR as well"
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux:
s390/ccwgroup: use ccwgroup_ungroup wrapper
s390/ccwgroup: fix an uninitialized return code
s390/ccwgroup: obtain extra reference for asynchronous processing
qdio: Keep device-specific dbf entries
s390/compat: correct ucontext layout for high gprs
s390/cio: set device name as early as possible
s390: update default configuration
s390: avoid format strings leaking into names
s390/airq: silence lockdep warning
s390/watchdog: add support for LPAR operation (diag288)
s390/watchdog: use watchdog API
s390/sclp_vt220: Enable ASCII console per default
s390/qdio: replace shift loop by ilog2
s390/cio: silence lockdep warning
s390/uaccess: always load the kernel ASCE after task switch
s390/ap_bus: Make modules parameters visible in sysfs
Diffstat (limited to 'drivers/watchdog')
-rw-r--r-- | drivers/watchdog/Kconfig | 7 | ||||
-rw-r--r-- | drivers/watchdog/Makefile | 1 | ||||
-rw-r--r-- | drivers/watchdog/diag288_wdt.c | 316 |
3 files changed, 322 insertions, 2 deletions
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index c845527b503a..76dd54122f76 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig | |||
@@ -1280,14 +1280,17 @@ config WATCHDOG_RTAS | |||
1280 | 1280 | ||
1281 | # S390 Architecture | 1281 | # S390 Architecture |
1282 | 1282 | ||
1283 | config ZVM_WATCHDOG | 1283 | config DIAG288_WATCHDOG |
1284 | tristate "z/VM Watchdog Timer" | 1284 | tristate "System z diag288 Watchdog" |
1285 | depends on S390 | 1285 | depends on S390 |
1286 | select WATCHDOG_CORE | ||
1286 | help | 1287 | help |
1287 | IBM s/390 and zSeries machines running under z/VM 5.1 or later | 1288 | IBM s/390 and zSeries machines running under z/VM 5.1 or later |
1288 | provide a virtual watchdog timer to their guest that cause a | 1289 | provide a virtual watchdog timer to their guest that cause a |
1289 | user define Control Program command to be executed after a | 1290 | user define Control Program command to be executed after a |
1290 | timeout. | 1291 | timeout. |
1292 | LPAR provides a very similar interface. This driver handles | ||
1293 | both. | ||
1291 | 1294 | ||
1292 | To compile this driver as a module, choose M here. The module | 1295 | To compile this driver as a module, choose M here. The module |
1293 | will be called vmwatchdog. | 1296 | will be called vmwatchdog. |
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 7b8a91ed20e7..468c3204c3b1 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile | |||
@@ -153,6 +153,7 @@ obj-$(CONFIG_MEN_A21_WDT) += mena21_wdt.o | |||
153 | obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o | 153 | obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o |
154 | 154 | ||
155 | # S390 Architecture | 155 | # S390 Architecture |
156 | obj-$(CONFIG_DIAG288_WATCHDOG) += diag288_wdt.o | ||
156 | 157 | ||
157 | # SUPERH (sh + sh64) Architecture | 158 | # SUPERH (sh + sh64) Architecture |
158 | obj-$(CONFIG_SH_WDT) += shwdt.o | 159 | obj-$(CONFIG_SH_WDT) += shwdt.o |
diff --git a/drivers/watchdog/diag288_wdt.c b/drivers/watchdog/diag288_wdt.c new file mode 100644 index 000000000000..429494b6c822 --- /dev/null +++ b/drivers/watchdog/diag288_wdt.c | |||
@@ -0,0 +1,316 @@ | |||
1 | /* | ||
2 | * Watchdog driver for z/VM and LPAR using the diag 288 interface. | ||
3 | * | ||
4 | * Under z/VM, expiration of the watchdog will send a "system restart" command | ||
5 | * to CP. | ||
6 | * | ||
7 | * The command can be altered using the module parameter "cmd". This is | ||
8 | * not recommended because it's only supported on z/VM but not whith LPAR. | ||
9 | * | ||
10 | * On LPAR, the watchdog will always trigger a system restart. the module | ||
11 | * paramter cmd is meaningless here. | ||
12 | * | ||
13 | * | ||
14 | * Copyright IBM Corp. 2004, 2013 | ||
15 | * Author(s): Arnd Bergmann (arndb@de.ibm.com) | ||
16 | * Philipp Hachtmann (phacht@de.ibm.com) | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | #define KMSG_COMPONENT "diag288_wdt" | ||
21 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | ||
22 | |||
23 | #include <linux/init.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/moduleparam.h> | ||
27 | #include <linux/slab.h> | ||
28 | #include <linux/miscdevice.h> | ||
29 | #include <linux/watchdog.h> | ||
30 | #include <linux/suspend.h> | ||
31 | #include <asm/ebcdic.h> | ||
32 | #include <linux/io.h> | ||
33 | #include <linux/uaccess.h> | ||
34 | |||
35 | #define MAX_CMDLEN 240 | ||
36 | #define DEFAULT_CMD "SYSTEM RESTART" | ||
37 | |||
38 | #define MIN_INTERVAL 15 /* Minimal time supported by diag88 */ | ||
39 | #define MAX_INTERVAL 3600 /* One hour should be enough - pure estimation */ | ||
40 | |||
41 | #define WDT_DEFAULT_TIMEOUT 30 | ||
42 | |||
43 | /* Function codes - init, change, cancel */ | ||
44 | #define WDT_FUNC_INIT 0 | ||
45 | #define WDT_FUNC_CHANGE 1 | ||
46 | #define WDT_FUNC_CANCEL 2 | ||
47 | #define WDT_FUNC_CONCEAL 0x80000000 | ||
48 | |||
49 | /* Action codes for LPAR watchdog */ | ||
50 | #define LPARWDT_RESTART 0 | ||
51 | |||
52 | static char wdt_cmd[MAX_CMDLEN] = DEFAULT_CMD; | ||
53 | static bool conceal_on; | ||
54 | static bool nowayout_info = WATCHDOG_NOWAYOUT; | ||
55 | |||
56 | MODULE_LICENSE("GPL"); | ||
57 | MODULE_AUTHOR("Arnd Bergmann <arndb@de.ibm.com>"); | ||
58 | MODULE_AUTHOR("Philipp Hachtmann <phacht@de.ibm.com>"); | ||
59 | |||
60 | MODULE_DESCRIPTION("System z diag288 Watchdog Timer"); | ||
61 | |||
62 | module_param_string(cmd, wdt_cmd, MAX_CMDLEN, 0644); | ||
63 | MODULE_PARM_DESC(cmd, "CP command that is run when the watchdog triggers (z/VM only)"); | ||
64 | |||
65 | module_param_named(conceal, conceal_on, bool, 0644); | ||
66 | MODULE_PARM_DESC(conceal, "Enable the CONCEAL CP option while the watchdog is active (z/VM only)"); | ||
67 | |||
68 | module_param_named(nowayout, nowayout_info, bool, 0444); | ||
69 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default = CONFIG_WATCHDOG_NOWAYOUT)"); | ||
70 | |||
71 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | ||
72 | MODULE_ALIAS("vmwatchdog"); | ||
73 | |||
74 | static int __diag288(unsigned int func, unsigned int timeout, | ||
75 | unsigned long action, unsigned int len) | ||
76 | { | ||
77 | register unsigned long __func asm("2") = func; | ||
78 | register unsigned long __timeout asm("3") = timeout; | ||
79 | register unsigned long __action asm("4") = action; | ||
80 | register unsigned long __len asm("5") = len; | ||
81 | int err; | ||
82 | |||
83 | err = -EINVAL; | ||
84 | asm volatile( | ||
85 | " diag %1, %3, 0x288\n" | ||
86 | "0: la %0, 0\n" | ||
87 | "1:\n" | ||
88 | EX_TABLE(0b, 1b) | ||
89 | : "+d" (err) : "d"(__func), "d"(__timeout), | ||
90 | "d"(__action), "d"(__len) : "1", "cc"); | ||
91 | return err; | ||
92 | } | ||
93 | |||
94 | static int __diag288_vm(unsigned int func, unsigned int timeout, | ||
95 | char *cmd, size_t len) | ||
96 | { | ||
97 | return __diag288(func, timeout, virt_to_phys(cmd), len); | ||
98 | } | ||
99 | |||
100 | static int __diag288_lpar(unsigned int func, unsigned int timeout, | ||
101 | unsigned long action) | ||
102 | { | ||
103 | return __diag288(func, timeout, action, 0); | ||
104 | } | ||
105 | |||
106 | static int wdt_start(struct watchdog_device *dev) | ||
107 | { | ||
108 | char *ebc_cmd; | ||
109 | size_t len; | ||
110 | int ret; | ||
111 | unsigned int func; | ||
112 | |||
113 | ret = -ENODEV; | ||
114 | |||
115 | if (MACHINE_IS_VM) { | ||
116 | ebc_cmd = kmalloc(MAX_CMDLEN, GFP_KERNEL); | ||
117 | if (!ebc_cmd) | ||
118 | return -ENOMEM; | ||
119 | len = strlcpy(ebc_cmd, wdt_cmd, MAX_CMDLEN); | ||
120 | ASCEBC(ebc_cmd, MAX_CMDLEN); | ||
121 | EBC_TOUPPER(ebc_cmd, MAX_CMDLEN); | ||
122 | |||
123 | func = conceal_on ? (WDT_FUNC_INIT | WDT_FUNC_CONCEAL) | ||
124 | : WDT_FUNC_INIT; | ||
125 | ret = __diag288_vm(func, dev->timeout, ebc_cmd, len); | ||
126 | WARN_ON(ret != 0); | ||
127 | kfree(ebc_cmd); | ||
128 | } | ||
129 | |||
130 | if (MACHINE_IS_LPAR) { | ||
131 | ret = __diag288_lpar(WDT_FUNC_INIT, | ||
132 | dev->timeout, LPARWDT_RESTART); | ||
133 | } | ||
134 | |||
135 | if (ret) { | ||
136 | pr_err("The watchdog cannot be activated\n"); | ||
137 | return ret; | ||
138 | } | ||
139 | pr_info("The watchdog was activated\n"); | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | static int wdt_stop(struct watchdog_device *dev) | ||
144 | { | ||
145 | int ret; | ||
146 | |||
147 | ret = __diag288(WDT_FUNC_CANCEL, 0, 0, 0); | ||
148 | pr_info("The watchdog was deactivated\n"); | ||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | static int wdt_ping(struct watchdog_device *dev) | ||
153 | { | ||
154 | char *ebc_cmd; | ||
155 | size_t len; | ||
156 | int ret; | ||
157 | unsigned int func; | ||
158 | |||
159 | ret = -ENODEV; | ||
160 | |||
161 | if (MACHINE_IS_VM) { | ||
162 | ebc_cmd = kmalloc(MAX_CMDLEN, GFP_KERNEL); | ||
163 | if (!ebc_cmd) | ||
164 | return -ENOMEM; | ||
165 | len = strlcpy(ebc_cmd, wdt_cmd, MAX_CMDLEN); | ||
166 | ASCEBC(ebc_cmd, MAX_CMDLEN); | ||
167 | EBC_TOUPPER(ebc_cmd, MAX_CMDLEN); | ||
168 | |||
169 | /* | ||
170 | * It seems to be ok to z/VM to use the init function to | ||
171 | * retrigger the watchdog. On LPAR WDT_FUNC_CHANGE must | ||
172 | * be used when the watchdog is running. | ||
173 | */ | ||
174 | func = conceal_on ? (WDT_FUNC_INIT | WDT_FUNC_CONCEAL) | ||
175 | : WDT_FUNC_INIT; | ||
176 | |||
177 | ret = __diag288_vm(func, dev->timeout, ebc_cmd, len); | ||
178 | WARN_ON(ret != 0); | ||
179 | kfree(ebc_cmd); | ||
180 | } | ||
181 | |||
182 | if (MACHINE_IS_LPAR) | ||
183 | ret = __diag288_lpar(WDT_FUNC_CHANGE, dev->timeout, 0); | ||
184 | |||
185 | if (ret) | ||
186 | pr_err("The watchdog timer cannot be started or reset\n"); | ||
187 | return ret; | ||
188 | } | ||
189 | |||
190 | static int wdt_set_timeout(struct watchdog_device * dev, unsigned int new_to) | ||
191 | { | ||
192 | dev->timeout = new_to; | ||
193 | return wdt_ping(dev); | ||
194 | } | ||
195 | |||
196 | static struct watchdog_ops wdt_ops = { | ||
197 | .owner = THIS_MODULE, | ||
198 | .start = wdt_start, | ||
199 | .stop = wdt_stop, | ||
200 | .ping = wdt_ping, | ||
201 | .set_timeout = wdt_set_timeout, | ||
202 | }; | ||
203 | |||
204 | static struct watchdog_info wdt_info = { | ||
205 | .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, | ||
206 | .firmware_version = 0, | ||
207 | .identity = "z Watchdog", | ||
208 | }; | ||
209 | |||
210 | static struct watchdog_device wdt_dev = { | ||
211 | .parent = NULL, | ||
212 | .info = &wdt_info, | ||
213 | .ops = &wdt_ops, | ||
214 | .bootstatus = 0, | ||
215 | .timeout = WDT_DEFAULT_TIMEOUT, | ||
216 | .min_timeout = MIN_INTERVAL, | ||
217 | .max_timeout = MAX_INTERVAL, | ||
218 | }; | ||
219 | |||
220 | /* | ||
221 | * It makes no sense to go into suspend while the watchdog is running. | ||
222 | * Depending on the memory size, the watchdog might trigger, while we | ||
223 | * are still saving the memory. | ||
224 | * We reuse the open flag to ensure that suspend and watchdog open are | ||
225 | * exclusive operations | ||
226 | */ | ||
227 | static int wdt_suspend(void) | ||
228 | { | ||
229 | if (test_and_set_bit(WDOG_DEV_OPEN, &wdt_dev.status)) { | ||
230 | pr_err("Linux cannot be suspended while the watchdog is in use\n"); | ||
231 | return notifier_from_errno(-EBUSY); | ||
232 | } | ||
233 | if (test_bit(WDOG_ACTIVE, &wdt_dev.status)) { | ||
234 | clear_bit(WDOG_DEV_OPEN, &wdt_dev.status); | ||
235 | pr_err("Linux cannot be suspended while the watchdog is in use\n"); | ||
236 | return notifier_from_errno(-EBUSY); | ||
237 | } | ||
238 | return NOTIFY_DONE; | ||
239 | } | ||
240 | |||
241 | static int wdt_resume(void) | ||
242 | { | ||
243 | clear_bit(WDOG_DEV_OPEN, &wdt_dev.status); | ||
244 | return NOTIFY_DONE; | ||
245 | } | ||
246 | |||
247 | static int wdt_power_event(struct notifier_block *this, unsigned long event, | ||
248 | void *ptr) | ||
249 | { | ||
250 | switch (event) { | ||
251 | case PM_POST_HIBERNATION: | ||
252 | case PM_POST_SUSPEND: | ||
253 | return wdt_resume(); | ||
254 | case PM_HIBERNATION_PREPARE: | ||
255 | case PM_SUSPEND_PREPARE: | ||
256 | return wdt_suspend(); | ||
257 | default: | ||
258 | return NOTIFY_DONE; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | static struct notifier_block wdt_power_notifier = { | ||
263 | .notifier_call = wdt_power_event, | ||
264 | }; | ||
265 | |||
266 | static int __init diag288_init(void) | ||
267 | { | ||
268 | int ret; | ||
269 | char ebc_begin[] = { | ||
270 | 194, 197, 199, 201, 213 | ||
271 | }; | ||
272 | |||
273 | watchdog_set_nowayout(&wdt_dev, nowayout_info); | ||
274 | |||
275 | if (MACHINE_IS_VM) { | ||
276 | pr_info("The watchdog device driver detected a z/VM environment\n"); | ||
277 | if (__diag288_vm(WDT_FUNC_INIT, 15, | ||
278 | ebc_begin, sizeof(ebc_begin)) != 0) { | ||
279 | pr_err("The watchdog cannot be initialized\n"); | ||
280 | return -EINVAL; | ||
281 | } | ||
282 | } else if (MACHINE_IS_LPAR) { | ||
283 | pr_info("The watchdog device driver detected an LPAR environment\n"); | ||
284 | if (__diag288_lpar(WDT_FUNC_INIT, 30, LPARWDT_RESTART)) { | ||
285 | pr_err("The watchdog cannot be initialized\n"); | ||
286 | return -EINVAL; | ||
287 | } | ||
288 | } else { | ||
289 | pr_err("Linux runs in an environment that does not support the diag288 watchdog\n"); | ||
290 | return -ENODEV; | ||
291 | } | ||
292 | |||
293 | if (__diag288_lpar(WDT_FUNC_CANCEL, 0, 0)) { | ||
294 | pr_err("The watchdog cannot be deactivated\n"); | ||
295 | return -EINVAL; | ||
296 | } | ||
297 | |||
298 | ret = register_pm_notifier(&wdt_power_notifier); | ||
299 | if (ret) | ||
300 | return ret; | ||
301 | |||
302 | ret = watchdog_register_device(&wdt_dev); | ||
303 | if (ret) | ||
304 | unregister_pm_notifier(&wdt_power_notifier); | ||
305 | |||
306 | return ret; | ||
307 | } | ||
308 | |||
309 | static void __exit diag288_exit(void) | ||
310 | { | ||
311 | watchdog_unregister_device(&wdt_dev); | ||
312 | unregister_pm_notifier(&wdt_power_notifier); | ||
313 | } | ||
314 | |||
315 | module_init(diag288_init); | ||
316 | module_exit(diag288_exit); | ||