.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
1 | 2 | /* |
---|
2 | 3 | * watchdog_core.c |
---|
3 | 4 | * |
---|
.. | .. |
---|
15 | 16 | * Rusty Lynch <rusty@linux.co.intel.com> |
---|
16 | 17 | * Satyam Sharma <satyam@infradead.org> |
---|
17 | 18 | * Randy Dunlap <randy.dunlap@oracle.com> |
---|
18 | | - * |
---|
19 | | - * This program is free software; you can redistribute it and/or |
---|
20 | | - * modify it under the terms of the GNU General Public License |
---|
21 | | - * as published by the Free Software Foundation; either version |
---|
22 | | - * 2 of the License, or (at your option) any later version. |
---|
23 | 19 | * |
---|
24 | 20 | * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw. |
---|
25 | 21 | * admit liability nor provide warranty for any of this software. |
---|
.. | .. |
---|
43 | 39 | |
---|
44 | 40 | static DEFINE_IDA(watchdog_ida); |
---|
45 | 41 | |
---|
| 42 | +static int stop_on_reboot = -1; |
---|
| 43 | +module_param(stop_on_reboot, int, 0444); |
---|
| 44 | +MODULE_PARM_DESC(stop_on_reboot, "Stop watchdogs on reboot (0=keep watching, 1=stop)"); |
---|
| 45 | + |
---|
46 | 46 | /* |
---|
47 | 47 | * Deferred Registration infrastructure. |
---|
48 | 48 | * |
---|
.. | .. |
---|
60 | 60 | static LIST_HEAD(wtd_deferred_reg_list); |
---|
61 | 61 | static bool wtd_deferred_reg_done; |
---|
62 | 62 | |
---|
63 | | -static int watchdog_deferred_registration_add(struct watchdog_device *wdd) |
---|
| 63 | +static void watchdog_deferred_registration_add(struct watchdog_device *wdd) |
---|
64 | 64 | { |
---|
65 | 65 | list_add_tail(&wdd->deferred, |
---|
66 | 66 | &wtd_deferred_reg_list); |
---|
67 | | - return 0; |
---|
68 | 67 | } |
---|
69 | 68 | |
---|
70 | 69 | static void watchdog_deferred_registration_del(struct watchdog_device *wdd) |
---|
.. | .. |
---|
105 | 104 | * timeout module parameter (if it is valid value) or the timeout-sec property |
---|
106 | 105 | * (only if it is a valid value and the timeout_parm is out of bounds). |
---|
107 | 106 | * If none of them are valid then we keep the old value (which should normally |
---|
108 | | - * be the default timeout value). |
---|
| 107 | + * be the default timeout value). Note that for the module parameter, '0' means |
---|
| 108 | + * 'use default' while it is an invalid value for the timeout-sec property. |
---|
| 109 | + * It should simply be dropped if you want to use the default value then. |
---|
109 | 110 | * |
---|
110 | | - * A zero is returned on success and -EINVAL for failure. |
---|
| 111 | + * A zero is returned on success or -EINVAL if all provided values are out of |
---|
| 112 | + * bounds. |
---|
111 | 113 | */ |
---|
112 | 114 | int watchdog_init_timeout(struct watchdog_device *wdd, |
---|
113 | 115 | unsigned int timeout_parm, struct device *dev) |
---|
114 | 116 | { |
---|
| 117 | + const char *dev_str = wdd->parent ? dev_name(wdd->parent) : |
---|
| 118 | + (const char *)wdd->info->identity; |
---|
115 | 119 | unsigned int t = 0; |
---|
116 | 120 | int ret = 0; |
---|
117 | 121 | |
---|
118 | 122 | watchdog_check_min_max_timeout(wdd); |
---|
119 | 123 | |
---|
120 | | - /* try to get the timeout module parameter first */ |
---|
121 | | - if (!watchdog_timeout_invalid(wdd, timeout_parm) && timeout_parm) { |
---|
122 | | - wdd->timeout = timeout_parm; |
---|
123 | | - return ret; |
---|
124 | | - } |
---|
125 | | - if (timeout_parm) |
---|
| 124 | + /* check the driver supplied value (likely a module parameter) first */ |
---|
| 125 | + if (timeout_parm) { |
---|
| 126 | + if (!watchdog_timeout_invalid(wdd, timeout_parm)) { |
---|
| 127 | + wdd->timeout = timeout_parm; |
---|
| 128 | + return 0; |
---|
| 129 | + } |
---|
| 130 | + pr_err("%s: driver supplied timeout (%u) out of range\n", |
---|
| 131 | + dev_str, timeout_parm); |
---|
126 | 132 | ret = -EINVAL; |
---|
| 133 | + } |
---|
127 | 134 | |
---|
128 | 135 | /* try to get the timeout_sec property */ |
---|
129 | | - if (dev == NULL || dev->of_node == NULL) |
---|
130 | | - return ret; |
---|
131 | | - of_property_read_u32(dev->of_node, "timeout-sec", &t); |
---|
132 | | - if (!watchdog_timeout_invalid(wdd, t) && t) |
---|
133 | | - wdd->timeout = t; |
---|
134 | | - else |
---|
| 136 | + if (dev && dev->of_node && |
---|
| 137 | + of_property_read_u32(dev->of_node, "timeout-sec", &t) == 0) { |
---|
| 138 | + if (t && !watchdog_timeout_invalid(wdd, t)) { |
---|
| 139 | + wdd->timeout = t; |
---|
| 140 | + return 0; |
---|
| 141 | + } |
---|
| 142 | + pr_err("%s: DT supplied timeout (%u) out of range\n", dev_str, t); |
---|
135 | 143 | ret = -EINVAL; |
---|
| 144 | + } |
---|
| 145 | + |
---|
| 146 | + if (ret < 0 && wdd->timeout) |
---|
| 147 | + pr_warn("%s: falling back to default timeout (%u)\n", dev_str, |
---|
| 148 | + wdd->timeout); |
---|
136 | 149 | |
---|
137 | 150 | return ret; |
---|
138 | 151 | } |
---|
.. | .. |
---|
245 | 258 | } |
---|
246 | 259 | } |
---|
247 | 260 | |
---|
| 261 | + /* Module parameter to force watchdog policy on reboot. */ |
---|
| 262 | + if (stop_on_reboot != -1) { |
---|
| 263 | + if (stop_on_reboot) |
---|
| 264 | + set_bit(WDOG_STOP_ON_REBOOT, &wdd->status); |
---|
| 265 | + else |
---|
| 266 | + clear_bit(WDOG_STOP_ON_REBOOT, &wdd->status); |
---|
| 267 | + } |
---|
| 268 | + |
---|
248 | 269 | if (test_bit(WDOG_STOP_ON_REBOOT, &wdd->status)) { |
---|
249 | 270 | if (!wdd->ops->stop) |
---|
250 | 271 | pr_warn("watchdog%d: stop_on_reboot not supported\n", wdd->id); |
---|
.. | .. |
---|
287 | 308 | |
---|
288 | 309 | int watchdog_register_device(struct watchdog_device *wdd) |
---|
289 | 310 | { |
---|
290 | | - int ret; |
---|
| 311 | + const char *dev_str; |
---|
| 312 | + int ret = 0; |
---|
291 | 313 | |
---|
292 | 314 | mutex_lock(&wtd_deferred_reg_mutex); |
---|
293 | 315 | if (wtd_deferred_reg_done) |
---|
294 | 316 | ret = __watchdog_register_device(wdd); |
---|
295 | 317 | else |
---|
296 | | - ret = watchdog_deferred_registration_add(wdd); |
---|
| 318 | + watchdog_deferred_registration_add(wdd); |
---|
297 | 319 | mutex_unlock(&wtd_deferred_reg_mutex); |
---|
| 320 | + |
---|
| 321 | + if (ret) { |
---|
| 322 | + dev_str = wdd->parent ? dev_name(wdd->parent) : |
---|
| 323 | + (const char *)wdd->info->identity; |
---|
| 324 | + pr_err("%s: failed to register watchdog device (err = %d)\n", |
---|
| 325 | + dev_str, ret); |
---|
| 326 | + } |
---|
| 327 | + |
---|
298 | 328 | return ret; |
---|
299 | 329 | } |
---|
300 | 330 | EXPORT_SYMBOL_GPL(watchdog_register_device); |
---|