Lines Matching full:wdd

75 static inline bool watchdog_need_worker(struct watchdog_device *wdd)  in watchdog_need_worker()  argument
78 unsigned int hm = wdd->max_hw_heartbeat_ms; in watchdog_need_worker()
79 unsigned int t = wdd->timeout * 1000; in watchdog_need_worker()
94 return (hm && watchdog_active(wdd) && t > hm) || in watchdog_need_worker()
95 (t && !watchdog_active(wdd) && watchdog_hw_running(wdd)); in watchdog_need_worker()
98 static ktime_t watchdog_next_keepalive(struct watchdog_device *wdd) in watchdog_next_keepalive() argument
100 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_next_keepalive()
101 unsigned int timeout_ms = wdd->timeout * 1000; in watchdog_next_keepalive()
107 if (watchdog_active(wdd)) in watchdog_next_keepalive()
113 hw_heartbeat_ms = min_not_zero(timeout_ms, wdd->max_hw_heartbeat_ms); in watchdog_next_keepalive()
117 * To ensure that the watchdog times out wdd->timeout seconds in watchdog_next_keepalive()
128 static inline void watchdog_update_worker(struct watchdog_device *wdd) in watchdog_update_worker() argument
130 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_update_worker()
132 if (watchdog_need_worker(wdd)) { in watchdog_update_worker()
133 ktime_t t = watchdog_next_keepalive(wdd); in watchdog_update_worker()
143 static int __watchdog_ping(struct watchdog_device *wdd) in __watchdog_ping() argument
145 struct watchdog_core_data *wd_data = wdd->wd_data; in __watchdog_ping()
150 ms_to_ktime(wdd->min_hw_heartbeat_ms)); in __watchdog_ping()
162 if (wdd->ops->ping) { in __watchdog_ping()
163 err = wdd->ops->ping(wdd); /* ping the watchdog */ in __watchdog_ping()
164 trace_watchdog_ping(wdd, err); in __watchdog_ping()
166 err = wdd->ops->start(wdd); /* restart watchdog */ in __watchdog_ping()
167 trace_watchdog_start(wdd, err); in __watchdog_ping()
171 watchdog_hrtimer_pretimeout_start(wdd); in __watchdog_ping()
173 watchdog_update_worker(wdd); in __watchdog_ping()
180 * @wdd: The watchdog device to ping
190 static int watchdog_ping(struct watchdog_device *wdd) in watchdog_ping() argument
192 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_ping()
194 if (!watchdog_active(wdd) && !watchdog_hw_running(wdd)) in watchdog_ping()
200 return __watchdog_ping(wdd); in watchdog_ping()
205 struct watchdog_device *wdd = wd_data->wdd; in watchdog_worker_should_ping() local
207 if (!wdd) in watchdog_worker_should_ping()
210 if (watchdog_active(wdd)) in watchdog_worker_should_ping()
213 return watchdog_hw_running(wdd) && !watchdog_past_open_deadline(wd_data); in watchdog_worker_should_ping()
224 __watchdog_ping(wd_data->wdd); in watchdog_ping_work()
240 * @wdd: The watchdog device to start
247 static int watchdog_start(struct watchdog_device *wdd) in watchdog_start() argument
249 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_start()
253 if (watchdog_active(wdd)) in watchdog_start()
259 if (watchdog_hw_running(wdd) && wdd->ops->ping) { in watchdog_start()
260 err = __watchdog_ping(wdd); in watchdog_start()
262 set_bit(WDOG_ACTIVE, &wdd->status); in watchdog_start()
263 watchdog_hrtimer_pretimeout_start(wdd); in watchdog_start()
266 err = wdd->ops->start(wdd); in watchdog_start()
267 trace_watchdog_start(wdd, err); in watchdog_start()
269 set_bit(WDOG_ACTIVE, &wdd->status); in watchdog_start()
272 watchdog_update_worker(wdd); in watchdog_start()
273 watchdog_hrtimer_pretimeout_start(wdd); in watchdog_start()
282 * @wdd: The watchdog device to stop
290 static int watchdog_stop(struct watchdog_device *wdd) in watchdog_stop() argument
294 if (!watchdog_active(wdd)) in watchdog_stop()
297 if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) { in watchdog_stop()
299 wdd->id); in watchdog_stop()
303 if (wdd->ops->stop) { in watchdog_stop()
304 clear_bit(WDOG_HW_RUNNING, &wdd->status); in watchdog_stop()
305 err = wdd->ops->stop(wdd); in watchdog_stop()
306 trace_watchdog_stop(wdd, err); in watchdog_stop()
308 set_bit(WDOG_HW_RUNNING, &wdd->status); in watchdog_stop()
312 clear_bit(WDOG_ACTIVE, &wdd->status); in watchdog_stop()
313 watchdog_update_worker(wdd); in watchdog_stop()
314 watchdog_hrtimer_pretimeout_stop(wdd); in watchdog_stop()
322 * @wdd: The watchdog device to get the status from
329 static unsigned int watchdog_get_status(struct watchdog_device *wdd) in watchdog_get_status() argument
331 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_get_status()
334 if (wdd->ops->status) in watchdog_get_status()
335 status = wdd->ops->status(wdd); in watchdog_get_status()
337 status = wdd->bootstatus & (WDIOF_CARDRESET | in watchdog_get_status()
359 * @wdd: The watchdog device to set the timeout for
366 static int watchdog_set_timeout(struct watchdog_device *wdd, in watchdog_set_timeout() argument
371 if (!(wdd->info->options & WDIOF_SETTIMEOUT)) in watchdog_set_timeout()
374 if (watchdog_timeout_invalid(wdd, timeout)) in watchdog_set_timeout()
377 if (wdd->ops->set_timeout) { in watchdog_set_timeout()
378 err = wdd->ops->set_timeout(wdd, timeout); in watchdog_set_timeout()
379 trace_watchdog_set_timeout(wdd, timeout, err); in watchdog_set_timeout()
381 wdd->timeout = timeout; in watchdog_set_timeout()
383 if (wdd->pretimeout >= wdd->timeout) in watchdog_set_timeout()
384 wdd->pretimeout = 0; in watchdog_set_timeout()
387 watchdog_update_worker(wdd); in watchdog_set_timeout()
394 * @wdd: The watchdog device to set the timeout for
399 static int watchdog_set_pretimeout(struct watchdog_device *wdd, in watchdog_set_pretimeout() argument
404 if (!watchdog_have_pretimeout(wdd)) in watchdog_set_pretimeout()
407 if (watchdog_pretimeout_invalid(wdd, timeout)) in watchdog_set_pretimeout()
410 if (wdd->ops->set_pretimeout && (wdd->info->options & WDIOF_PRETIMEOUT)) in watchdog_set_pretimeout()
411 err = wdd->ops->set_pretimeout(wdd, timeout); in watchdog_set_pretimeout()
413 wdd->pretimeout = timeout; in watchdog_set_pretimeout()
420 * @wdd: The watchdog device to get the remaining time from
428 static int watchdog_get_timeleft(struct watchdog_device *wdd, in watchdog_get_timeleft() argument
433 if (!wdd->ops->get_timeleft) in watchdog_get_timeleft()
436 *timeleft = wdd->ops->get_timeleft(wdd); in watchdog_get_timeleft()
445 struct watchdog_device *wdd = dev_get_drvdata(dev); in nowayout_show() local
448 &wdd->status)); in nowayout_show()
454 struct watchdog_device *wdd = dev_get_drvdata(dev); in nowayout_store() local
464 if (test_bit(WDOG_NO_WAY_OUT, &wdd->status) && !value) in nowayout_store()
466 watchdog_set_nowayout(wdd, value); in nowayout_store()
474 struct watchdog_device *wdd = dev_get_drvdata(dev); in status_show() local
475 struct watchdog_core_data *wd_data = wdd->wd_data; in status_show()
479 status = watchdog_get_status(wdd); in status_show()
489 struct watchdog_device *wdd = dev_get_drvdata(dev); in bootstatus_show() local
491 return sysfs_emit(buf, "%u\n", wdd->bootstatus); in bootstatus_show()
498 struct watchdog_device *wdd = dev_get_drvdata(dev); in timeleft_show() local
499 struct watchdog_core_data *wd_data = wdd->wd_data; in timeleft_show()
504 status = watchdog_get_timeleft(wdd, &val); in timeleft_show()
516 struct watchdog_device *wdd = dev_get_drvdata(dev); in timeout_show() local
518 return sysfs_emit(buf, "%u\n", wdd->timeout); in timeout_show()
525 struct watchdog_device *wdd = dev_get_drvdata(dev); in min_timeout_show() local
527 return sysfs_emit(buf, "%u\n", wdd->min_timeout); in min_timeout_show()
534 struct watchdog_device *wdd = dev_get_drvdata(dev); in max_timeout_show() local
536 return sysfs_emit(buf, "%u\n", wdd->max_timeout); in max_timeout_show()
543 struct watchdog_device *wdd = dev_get_drvdata(dev); in pretimeout_show() local
545 return sysfs_emit(buf, "%u\n", wdd->pretimeout); in pretimeout_show()
552 struct watchdog_device *wdd = dev_get_drvdata(dev); in identity_show() local
554 return sysfs_emit(buf, "%s\n", wdd->info->identity); in identity_show()
561 struct watchdog_device *wdd = dev_get_drvdata(dev); in state_show() local
563 if (watchdog_active(wdd)) in state_show()
581 struct watchdog_device *wdd = dev_get_drvdata(dev); in pretimeout_governor_show() local
583 return watchdog_pretimeout_governor_get(wdd, buf); in pretimeout_governor_show()
590 struct watchdog_device *wdd = dev_get_drvdata(dev); in pretimeout_governor_store() local
591 int ret = watchdog_pretimeout_governor_set(wdd, buf); in pretimeout_governor_store()
604 struct watchdog_device *wdd = dev_get_drvdata(dev); in wdt_is_visible() local
607 if (attr == &dev_attr_timeleft.attr && !wdd->ops->get_timeleft) in wdt_is_visible()
609 else if (attr == &dev_attr_pretimeout.attr && !watchdog_have_pretimeout(wdd)) in wdt_is_visible()
613 (!watchdog_have_pretimeout(wdd) || !IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_GOV))) in wdt_is_visible()
645 * @wdd: The watchdog device to do the ioctl on
653 static int watchdog_ioctl_op(struct watchdog_device *wdd, unsigned int cmd, in watchdog_ioctl_op() argument
656 if (!wdd->ops->ioctl) in watchdog_ioctl_op()
659 return wdd->ops->ioctl(wdd, cmd, arg); in watchdog_ioctl_op()
679 struct watchdog_device *wdd; in watchdog_write() local
705 wdd = wd_data->wdd; in watchdog_write()
706 if (wdd) in watchdog_write()
707 err = watchdog_ping(wdd); in watchdog_write()
733 struct watchdog_device *wdd; in watchdog_ioctl() local
740 wdd = wd_data->wdd; in watchdog_ioctl()
741 if (!wdd) { in watchdog_ioctl()
746 err = watchdog_ioctl_op(wdd, cmd, arg); in watchdog_ioctl()
752 err = copy_to_user(argp, wdd->info, in watchdog_ioctl()
756 val = watchdog_get_status(wdd); in watchdog_ioctl()
760 err = put_user(wdd->bootstatus, p); in watchdog_ioctl()
768 err = watchdog_stop(wdd); in watchdog_ioctl()
773 err = watchdog_start(wdd); in watchdog_ioctl()
776 if (!(wdd->info->options & WDIOF_KEEPALIVEPING)) { in watchdog_ioctl()
780 err = watchdog_ping(wdd); in watchdog_ioctl()
787 err = watchdog_set_timeout(wdd, val); in watchdog_ioctl()
793 err = watchdog_ping(wdd); in watchdog_ioctl()
799 if (wdd->timeout == 0) { in watchdog_ioctl()
803 err = put_user(wdd->timeout, p); in watchdog_ioctl()
806 err = watchdog_get_timeleft(wdd, &val); in watchdog_ioctl()
816 err = watchdog_set_pretimeout(wdd, val); in watchdog_ioctl()
819 err = put_user(wdd->pretimeout, p); in watchdog_ioctl()
845 struct watchdog_device *wdd; in watchdog_open() local
860 wdd = wd_data->wdd; in watchdog_open()
866 hw_running = watchdog_hw_running(wdd); in watchdog_open()
867 if (!hw_running && !try_module_get(wdd->ops->owner)) { in watchdog_open()
872 err = watchdog_start(wdd); in watchdog_open()
894 module_put(wd_data->wdd->ops->owner); in watchdog_open()
923 struct watchdog_device *wdd; in watchdog_release() local
929 wdd = wd_data->wdd; in watchdog_release()
930 if (!wdd) in watchdog_release()
938 if (!watchdog_active(wdd)) in watchdog_release()
941 !(wdd->info->options & WDIOF_MAGICCLOSE)) in watchdog_release()
942 err = watchdog_stop(wdd); in watchdog_release()
946 pr_crit("watchdog%d: watchdog did not stop!\n", wdd->id); in watchdog_release()
947 watchdog_ping(wdd); in watchdog_release()
950 watchdog_update_worker(wdd); in watchdog_release()
956 running = wdd && watchdog_hw_running(wdd); in watchdog_release()
993 * @wdd: Watchdog device
1001 static int watchdog_cdev_register(struct watchdog_device *wdd) in watchdog_cdev_register() argument
1011 wd_data->wdd = wdd; in watchdog_cdev_register()
1012 wdd->wd_data = wd_data; in watchdog_cdev_register()
1020 wd_data->dev.devt = MKDEV(MAJOR(watchdog_devt), wdd->id); in watchdog_cdev_register()
1022 wd_data->dev.parent = wdd->parent; in watchdog_cdev_register()
1023 wd_data->dev.groups = wdd->groups; in watchdog_cdev_register()
1025 dev_set_drvdata(&wd_data->dev, wdd); in watchdog_cdev_register()
1026 err = dev_set_name(&wd_data->dev, "watchdog%d", wdd->id); in watchdog_cdev_register()
1035 watchdog_hrtimer_pretimeout_init(wdd); in watchdog_cdev_register()
1037 if (wdd->id == 0) { in watchdog_cdev_register()
1039 watchdog_miscdev.parent = wdd->parent; in watchdog_cdev_register()
1043 wdd->info->identity, WATCHDOG_MINOR, err); in watchdog_cdev_register()
1046 wdd->info->identity); in watchdog_cdev_register()
1060 wdd->id, MAJOR(watchdog_devt), wdd->id); in watchdog_cdev_register()
1061 if (wdd->id == 0) { in watchdog_cdev_register()
1069 wd_data->cdev.owner = wdd->ops->owner; in watchdog_cdev_register()
1079 if (watchdog_hw_running(wdd)) { in watchdog_cdev_register()
1080 __module_get(wdd->ops->owner); in watchdog_cdev_register()
1087 wdd->id); in watchdog_cdev_register()
1095 * @wdd: Watchdog device
1100 static void watchdog_cdev_unregister(struct watchdog_device *wdd) in watchdog_cdev_unregister() argument
1102 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_cdev_unregister()
1105 if (wdd->id == 0) { in watchdog_cdev_unregister()
1110 if (watchdog_active(wdd) && in watchdog_cdev_unregister()
1111 test_bit(WDOG_STOP_ON_UNREGISTER, &wdd->status)) { in watchdog_cdev_unregister()
1112 watchdog_stop(wdd); in watchdog_cdev_unregister()
1115 watchdog_hrtimer_pretimeout_stop(wdd); in watchdog_cdev_unregister()
1118 wd_data->wdd = NULL; in watchdog_cdev_unregister()
1119 wdd->wd_data = NULL; in watchdog_cdev_unregister()
1130 * @wdd: Watchdog device
1138 int watchdog_dev_register(struct watchdog_device *wdd) in watchdog_dev_register() argument
1142 ret = watchdog_cdev_register(wdd); in watchdog_dev_register()
1146 ret = watchdog_register_pretimeout(wdd); in watchdog_dev_register()
1148 watchdog_cdev_unregister(wdd); in watchdog_dev_register()
1155 * @wdd: watchdog device
1160 void watchdog_dev_unregister(struct watchdog_device *wdd) in watchdog_dev_unregister() argument
1162 watchdog_unregister_pretimeout(wdd); in watchdog_dev_unregister()
1163 watchdog_cdev_unregister(wdd); in watchdog_dev_unregister()
1168 * @wdd: Watchdog device
1179 int watchdog_set_last_hw_keepalive(struct watchdog_device *wdd, in watchdog_set_last_hw_keepalive() argument
1185 if (!wdd) in watchdog_set_last_hw_keepalive()
1188 wd_data = wdd->wd_data; in watchdog_set_last_hw_keepalive()
1194 if (watchdog_hw_running(wdd) && handle_boot_enabled) in watchdog_set_last_hw_keepalive()
1195 return __watchdog_ping(wdd); in watchdog_set_last_hw_keepalive()
1252 int watchdog_dev_suspend(struct watchdog_device *wdd) in watchdog_dev_suspend() argument
1254 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_dev_suspend()
1257 if (!wdd->wd_data) in watchdog_dev_suspend()
1263 ret = __watchdog_ping(wd_data->wdd); in watchdog_dev_suspend()
1279 int watchdog_dev_resume(struct watchdog_device *wdd) in watchdog_dev_resume() argument
1281 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_dev_resume()
1284 if (!wdd->wd_data) in watchdog_dev_resume()
1293 ret = __watchdog_ping(wd_data->wdd); in watchdog_dev_resume()