Lines Matching refs:wdd

76 static inline bool watchdog_need_worker(struct watchdog_device *wdd)  in watchdog_need_worker()  argument
79 unsigned int hm = wdd->max_hw_heartbeat_ms; in watchdog_need_worker()
80 unsigned int t = wdd->timeout * 1000; in watchdog_need_worker()
95 return (hm && watchdog_active(wdd) && t > hm) || in watchdog_need_worker()
96 (t && !watchdog_active(wdd) && watchdog_hw_running(wdd)); in watchdog_need_worker()
99 static ktime_t watchdog_next_keepalive(struct watchdog_device *wdd) in watchdog_next_keepalive() argument
101 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_next_keepalive()
102 unsigned int timeout_ms = wdd->timeout * 1000; in watchdog_next_keepalive()
108 if (watchdog_active(wdd)) in watchdog_next_keepalive()
114 hw_heartbeat_ms = min_not_zero(timeout_ms, wdd->max_hw_heartbeat_ms); in watchdog_next_keepalive()
129 static inline void watchdog_update_worker(struct watchdog_device *wdd) in watchdog_update_worker() argument
131 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_update_worker()
133 if (watchdog_need_worker(wdd)) { in watchdog_update_worker()
134 ktime_t t = watchdog_next_keepalive(wdd); in watchdog_update_worker()
144 static int __watchdog_ping(struct watchdog_device *wdd) in __watchdog_ping() argument
146 struct watchdog_core_data *wd_data = wdd->wd_data; in __watchdog_ping()
151 ms_to_ktime(wdd->min_hw_heartbeat_ms)); in __watchdog_ping()
163 if (wdd->ops->ping) { in __watchdog_ping()
164 err = wdd->ops->ping(wdd); /* ping the watchdog */ in __watchdog_ping()
165 trace_watchdog_ping(wdd, err); in __watchdog_ping()
167 err = wdd->ops->start(wdd); /* restart watchdog */ in __watchdog_ping()
168 trace_watchdog_start(wdd, err); in __watchdog_ping()
172 watchdog_hrtimer_pretimeout_start(wdd); in __watchdog_ping()
174 watchdog_update_worker(wdd); in __watchdog_ping()
191 static int watchdog_ping(struct watchdog_device *wdd) in watchdog_ping() argument
193 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_ping()
195 if (!watchdog_hw_running(wdd)) in watchdog_ping()
201 return __watchdog_ping(wdd); in watchdog_ping()
206 struct watchdog_device *wdd = wd_data->wdd; in watchdog_worker_should_ping() local
208 if (!wdd) in watchdog_worker_should_ping()
211 if (watchdog_active(wdd)) in watchdog_worker_should_ping()
214 return watchdog_hw_running(wdd) && !watchdog_past_open_deadline(wd_data); in watchdog_worker_should_ping()
225 __watchdog_ping(wd_data->wdd); in watchdog_ping_work()
248 static int watchdog_start(struct watchdog_device *wdd) in watchdog_start() argument
250 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_start()
254 if (watchdog_active(wdd)) in watchdog_start()
260 if (watchdog_hw_running(wdd) && wdd->ops->ping) { in watchdog_start()
261 err = __watchdog_ping(wdd); in watchdog_start()
263 set_bit(WDOG_ACTIVE, &wdd->status); in watchdog_start()
264 watchdog_hrtimer_pretimeout_start(wdd); in watchdog_start()
267 err = wdd->ops->start(wdd); in watchdog_start()
268 trace_watchdog_start(wdd, err); in watchdog_start()
270 set_bit(WDOG_ACTIVE, &wdd->status); in watchdog_start()
271 set_bit(WDOG_HW_RUNNING, &wdd->status); in watchdog_start()
274 watchdog_update_worker(wdd); in watchdog_start()
275 watchdog_hrtimer_pretimeout_start(wdd); in watchdog_start()
292 static int watchdog_stop(struct watchdog_device *wdd) in watchdog_stop() argument
296 if (!watchdog_active(wdd)) in watchdog_stop()
299 if (test_bit(WDOG_NO_WAY_OUT, &wdd->status)) { in watchdog_stop()
301 wdd->id); in watchdog_stop()
305 if (wdd->ops->stop) { in watchdog_stop()
306 clear_bit(WDOG_HW_RUNNING, &wdd->status); in watchdog_stop()
307 err = wdd->ops->stop(wdd); in watchdog_stop()
308 trace_watchdog_stop(wdd, err); in watchdog_stop()
310 set_bit(WDOG_HW_RUNNING, &wdd->status); in watchdog_stop()
314 clear_bit(WDOG_ACTIVE, &wdd->status); in watchdog_stop()
315 watchdog_update_worker(wdd); in watchdog_stop()
316 watchdog_hrtimer_pretimeout_stop(wdd); in watchdog_stop()
331 static unsigned int watchdog_get_status(struct watchdog_device *wdd) in watchdog_get_status() argument
333 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_get_status()
336 if (wdd->ops->status) in watchdog_get_status()
337 status = wdd->ops->status(wdd); in watchdog_get_status()
339 status = wdd->bootstatus & (WDIOF_CARDRESET | in watchdog_get_status()
368 static int watchdog_set_timeout(struct watchdog_device *wdd, in watchdog_set_timeout() argument
373 if (!(wdd->info->options & WDIOF_SETTIMEOUT)) in watchdog_set_timeout()
376 if (watchdog_timeout_invalid(wdd, timeout)) in watchdog_set_timeout()
379 if (wdd->ops->set_timeout) { in watchdog_set_timeout()
380 err = wdd->ops->set_timeout(wdd, timeout); in watchdog_set_timeout()
381 trace_watchdog_set_timeout(wdd, timeout, err); in watchdog_set_timeout()
383 wdd->timeout = timeout; in watchdog_set_timeout()
385 if (wdd->pretimeout >= wdd->timeout) in watchdog_set_timeout()
386 wdd->pretimeout = 0; in watchdog_set_timeout()
389 watchdog_update_worker(wdd); in watchdog_set_timeout()
401 static int watchdog_set_pretimeout(struct watchdog_device *wdd, in watchdog_set_pretimeout() argument
406 if (!watchdog_have_pretimeout(wdd)) in watchdog_set_pretimeout()
409 if (watchdog_pretimeout_invalid(wdd, timeout)) in watchdog_set_pretimeout()
412 if (wdd->ops->set_pretimeout && (wdd->info->options & WDIOF_PRETIMEOUT)) in watchdog_set_pretimeout()
413 err = wdd->ops->set_pretimeout(wdd, timeout); in watchdog_set_pretimeout()
415 wdd->pretimeout = timeout; in watchdog_set_pretimeout()
430 static int watchdog_get_timeleft(struct watchdog_device *wdd, in watchdog_get_timeleft() argument
435 if (!wdd->ops->get_timeleft) in watchdog_get_timeleft()
438 *timeleft = wdd->ops->get_timeleft(wdd); in watchdog_get_timeleft()
447 struct watchdog_device *wdd = dev_get_drvdata(dev); in nowayout_show() local
450 &wdd->status)); in nowayout_show()
456 struct watchdog_device *wdd = dev_get_drvdata(dev); in nowayout_store() local
466 if (test_bit(WDOG_NO_WAY_OUT, &wdd->status) && !value) in nowayout_store()
468 watchdog_set_nowayout(wdd, value); in nowayout_store()
476 struct watchdog_device *wdd = dev_get_drvdata(dev); in status_show() local
477 struct watchdog_core_data *wd_data = wdd->wd_data; in status_show()
481 status = watchdog_get_status(wdd); in status_show()
491 struct watchdog_device *wdd = dev_get_drvdata(dev); in bootstatus_show() local
493 return sysfs_emit(buf, "%u\n", wdd->bootstatus); in bootstatus_show()
500 struct watchdog_device *wdd = dev_get_drvdata(dev); in timeleft_show() local
501 struct watchdog_core_data *wd_data = wdd->wd_data; in timeleft_show()
506 status = watchdog_get_timeleft(wdd, &val); in timeleft_show()
518 struct watchdog_device *wdd = dev_get_drvdata(dev); in timeout_show() local
520 return sysfs_emit(buf, "%u\n", wdd->timeout); in timeout_show()
527 struct watchdog_device *wdd = dev_get_drvdata(dev); in min_timeout_show() local
529 return sysfs_emit(buf, "%u\n", wdd->min_timeout); in min_timeout_show()
536 struct watchdog_device *wdd = dev_get_drvdata(dev); in max_timeout_show() local
538 return sysfs_emit(buf, "%u\n", wdd->max_timeout); in max_timeout_show()
545 struct watchdog_device *wdd = dev_get_drvdata(dev); in pretimeout_show() local
547 return sysfs_emit(buf, "%u\n", wdd->pretimeout); in pretimeout_show()
554 struct watchdog_device *wdd = dev_get_drvdata(dev); in options_show() local
556 return sysfs_emit(buf, "0x%x\n", wdd->info->options); in options_show()
563 struct watchdog_device *wdd = dev_get_drvdata(dev); in fw_version_show() local
565 return sysfs_emit(buf, "%d\n", wdd->info->firmware_version); in fw_version_show()
572 struct watchdog_device *wdd = dev_get_drvdata(dev); in identity_show() local
574 return sysfs_emit(buf, "%s\n", wdd->info->identity); in identity_show()
581 struct watchdog_device *wdd = dev_get_drvdata(dev); in state_show() local
583 if (watchdog_active(wdd)) in state_show()
601 struct watchdog_device *wdd = dev_get_drvdata(dev); in pretimeout_governor_show() local
603 return watchdog_pretimeout_governor_get(wdd, buf); in pretimeout_governor_show()
610 struct watchdog_device *wdd = dev_get_drvdata(dev); in pretimeout_governor_store() local
611 int ret = watchdog_pretimeout_governor_set(wdd, buf); in pretimeout_governor_store()
624 struct watchdog_device *wdd = dev_get_drvdata(dev); in wdt_is_visible() local
627 if (attr == &dev_attr_timeleft.attr && !wdd->ops->get_timeleft) in wdt_is_visible()
629 else if (attr == &dev_attr_pretimeout.attr && !watchdog_have_pretimeout(wdd)) in wdt_is_visible()
633 (!watchdog_have_pretimeout(wdd) || !IS_ENABLED(CONFIG_WATCHDOG_PRETIMEOUT_GOV))) in wdt_is_visible()
675 static int watchdog_ioctl_op(struct watchdog_device *wdd, unsigned int cmd, in watchdog_ioctl_op() argument
678 if (!wdd->ops->ioctl) in watchdog_ioctl_op()
681 return wdd->ops->ioctl(wdd, cmd, arg); in watchdog_ioctl_op()
701 struct watchdog_device *wdd; in watchdog_write() local
727 wdd = wd_data->wdd; in watchdog_write()
728 if (wdd) in watchdog_write()
729 err = watchdog_ping(wdd); in watchdog_write()
755 struct watchdog_device *wdd; in watchdog_ioctl() local
762 wdd = wd_data->wdd; in watchdog_ioctl()
763 if (!wdd) { in watchdog_ioctl()
768 err = watchdog_ioctl_op(wdd, cmd, arg); in watchdog_ioctl()
774 err = copy_to_user(argp, wdd->info, in watchdog_ioctl()
778 val = watchdog_get_status(wdd); in watchdog_ioctl()
782 err = put_user(wdd->bootstatus, p); in watchdog_ioctl()
790 err = watchdog_stop(wdd); in watchdog_ioctl()
795 err = watchdog_start(wdd); in watchdog_ioctl()
798 if (!(wdd->info->options & WDIOF_KEEPALIVEPING)) { in watchdog_ioctl()
802 err = watchdog_ping(wdd); in watchdog_ioctl()
809 err = watchdog_set_timeout(wdd, val); in watchdog_ioctl()
815 err = watchdog_ping(wdd); in watchdog_ioctl()
821 if (wdd->timeout == 0) { in watchdog_ioctl()
825 err = put_user(wdd->timeout, p); in watchdog_ioctl()
828 err = watchdog_get_timeleft(wdd, &val); in watchdog_ioctl()
838 err = watchdog_set_pretimeout(wdd, val); in watchdog_ioctl()
841 err = put_user(wdd->pretimeout, p); in watchdog_ioctl()
867 struct watchdog_device *wdd; in watchdog_open() local
882 wdd = wd_data->wdd; in watchdog_open()
888 hw_running = watchdog_hw_running(wdd); in watchdog_open()
889 if (!hw_running && !try_module_get(wdd->ops->owner)) { in watchdog_open()
894 err = watchdog_start(wdd); in watchdog_open()
916 module_put(wd_data->wdd->ops->owner); in watchdog_open()
945 struct watchdog_device *wdd; in watchdog_release() local
951 wdd = wd_data->wdd; in watchdog_release()
952 if (!wdd) in watchdog_release()
960 if (!watchdog_active(wdd)) in watchdog_release()
963 !(wdd->info->options & WDIOF_MAGICCLOSE)) in watchdog_release()
964 err = watchdog_stop(wdd); in watchdog_release()
968 pr_crit("watchdog%d: watchdog did not stop!\n", wdd->id); in watchdog_release()
969 watchdog_ping(wdd); in watchdog_release()
972 watchdog_update_worker(wdd); in watchdog_release()
978 running = wdd && watchdog_hw_running(wdd); in watchdog_release()
1022 static int watchdog_cdev_register(struct watchdog_device *wdd) in watchdog_cdev_register() argument
1032 wd_data->wdd = wdd; in watchdog_cdev_register()
1033 wdd->wd_data = wd_data; in watchdog_cdev_register()
1041 wd_data->dev.devt = MKDEV(MAJOR(watchdog_devt), wdd->id); in watchdog_cdev_register()
1043 wd_data->dev.parent = wdd->parent; in watchdog_cdev_register()
1044 wd_data->dev.groups = wdd->groups; in watchdog_cdev_register()
1046 dev_set_drvdata(&wd_data->dev, wdd); in watchdog_cdev_register()
1047 err = dev_set_name(&wd_data->dev, "watchdog%d", wdd->id); in watchdog_cdev_register()
1056 watchdog_hrtimer_pretimeout_init(wdd); in watchdog_cdev_register()
1058 if (wdd->id == 0) { in watchdog_cdev_register()
1060 watchdog_miscdev.parent = wdd->parent; in watchdog_cdev_register()
1064 wdd->info->identity, WATCHDOG_MINOR, err); in watchdog_cdev_register()
1067 wdd->info->identity); in watchdog_cdev_register()
1076 wd_data->cdev.owner = wdd->ops->owner; in watchdog_cdev_register()
1082 wdd->id, MAJOR(watchdog_devt), wdd->id); in watchdog_cdev_register()
1083 if (wdd->id == 0) { in watchdog_cdev_register()
1099 if (watchdog_hw_running(wdd)) { in watchdog_cdev_register()
1100 __module_get(wdd->ops->owner); in watchdog_cdev_register()
1107 wdd->id); in watchdog_cdev_register()
1120 static void watchdog_cdev_unregister(struct watchdog_device *wdd) in watchdog_cdev_unregister() argument
1122 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_cdev_unregister()
1125 if (wdd->id == 0) { in watchdog_cdev_unregister()
1130 if (watchdog_active(wdd) && in watchdog_cdev_unregister()
1131 test_bit(WDOG_STOP_ON_UNREGISTER, &wdd->status)) { in watchdog_cdev_unregister()
1132 watchdog_stop(wdd); in watchdog_cdev_unregister()
1135 watchdog_hrtimer_pretimeout_stop(wdd); in watchdog_cdev_unregister()
1138 wd_data->wdd = NULL; in watchdog_cdev_unregister()
1139 wdd->wd_data = NULL; in watchdog_cdev_unregister()
1158 int watchdog_dev_register(struct watchdog_device *wdd) in watchdog_dev_register() argument
1162 ret = watchdog_cdev_register(wdd); in watchdog_dev_register()
1166 ret = watchdog_register_pretimeout(wdd); in watchdog_dev_register()
1168 watchdog_cdev_unregister(wdd); in watchdog_dev_register()
1180 void watchdog_dev_unregister(struct watchdog_device *wdd) in watchdog_dev_unregister() argument
1182 watchdog_unregister_pretimeout(wdd); in watchdog_dev_unregister()
1183 watchdog_cdev_unregister(wdd); in watchdog_dev_unregister()
1199 int watchdog_set_last_hw_keepalive(struct watchdog_device *wdd, in watchdog_set_last_hw_keepalive() argument
1205 if (!wdd) in watchdog_set_last_hw_keepalive()
1208 wd_data = wdd->wd_data; in watchdog_set_last_hw_keepalive()
1214 if (watchdog_hw_running(wdd) && handle_boot_enabled) in watchdog_set_last_hw_keepalive()
1215 return __watchdog_ping(wdd); in watchdog_set_last_hw_keepalive()
1272 int watchdog_dev_suspend(struct watchdog_device *wdd) in watchdog_dev_suspend() argument
1274 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_dev_suspend()
1277 if (!wdd->wd_data) in watchdog_dev_suspend()
1283 ret = __watchdog_ping(wd_data->wdd); in watchdog_dev_suspend()
1299 int watchdog_dev_resume(struct watchdog_device *wdd) in watchdog_dev_resume() argument
1301 struct watchdog_core_data *wd_data = wdd->wd_data; in watchdog_dev_resume()
1304 if (!wdd->wd_data) in watchdog_dev_resume()
1313 ret = __watchdog_ping(wd_data->wdd); in watchdog_dev_resume()