xref: /openbmc/linux/drivers/watchdog/watchdog_hrtimer_pretimeout.c (revision 762f99f4f3cb41a775b5157dd761217beba65873)
1*7b7d2fdcSCurtis Klein // SPDX-License-Identifier: GPL-2.0
2*7b7d2fdcSCurtis Klein /*
3*7b7d2fdcSCurtis Klein  * (c) Copyright 2021 Hewlett Packard Enterprise Development LP.
4*7b7d2fdcSCurtis Klein  */
5*7b7d2fdcSCurtis Klein 
6*7b7d2fdcSCurtis Klein #include <linux/hrtimer.h>
7*7b7d2fdcSCurtis Klein #include <linux/watchdog.h>
8*7b7d2fdcSCurtis Klein 
9*7b7d2fdcSCurtis Klein #include "watchdog_core.h"
10*7b7d2fdcSCurtis Klein #include "watchdog_pretimeout.h"
11*7b7d2fdcSCurtis Klein 
watchdog_hrtimer_pretimeout(struct hrtimer * timer)12*7b7d2fdcSCurtis Klein static enum hrtimer_restart watchdog_hrtimer_pretimeout(struct hrtimer *timer)
13*7b7d2fdcSCurtis Klein {
14*7b7d2fdcSCurtis Klein 	struct watchdog_core_data *wd_data;
15*7b7d2fdcSCurtis Klein 
16*7b7d2fdcSCurtis Klein 	wd_data = container_of(timer, struct watchdog_core_data, pretimeout_timer);
17*7b7d2fdcSCurtis Klein 
18*7b7d2fdcSCurtis Klein 	watchdog_notify_pretimeout(wd_data->wdd);
19*7b7d2fdcSCurtis Klein 	return HRTIMER_NORESTART;
20*7b7d2fdcSCurtis Klein }
21*7b7d2fdcSCurtis Klein 
watchdog_hrtimer_pretimeout_init(struct watchdog_device * wdd)22*7b7d2fdcSCurtis Klein void watchdog_hrtimer_pretimeout_init(struct watchdog_device *wdd)
23*7b7d2fdcSCurtis Klein {
24*7b7d2fdcSCurtis Klein 	struct watchdog_core_data *wd_data = wdd->wd_data;
25*7b7d2fdcSCurtis Klein 
26*7b7d2fdcSCurtis Klein 	hrtimer_init(&wd_data->pretimeout_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
27*7b7d2fdcSCurtis Klein 	wd_data->pretimeout_timer.function = watchdog_hrtimer_pretimeout;
28*7b7d2fdcSCurtis Klein }
29*7b7d2fdcSCurtis Klein 
watchdog_hrtimer_pretimeout_start(struct watchdog_device * wdd)30*7b7d2fdcSCurtis Klein void watchdog_hrtimer_pretimeout_start(struct watchdog_device *wdd)
31*7b7d2fdcSCurtis Klein {
32*7b7d2fdcSCurtis Klein 	if (!(wdd->info->options & WDIOF_PRETIMEOUT) &&
33*7b7d2fdcSCurtis Klein 	    !watchdog_pretimeout_invalid(wdd, wdd->pretimeout))
34*7b7d2fdcSCurtis Klein 		hrtimer_start(&wdd->wd_data->pretimeout_timer,
35*7b7d2fdcSCurtis Klein 			      ktime_set(wdd->timeout - wdd->pretimeout, 0),
36*7b7d2fdcSCurtis Klein 			      HRTIMER_MODE_REL);
37*7b7d2fdcSCurtis Klein 	else
38*7b7d2fdcSCurtis Klein 		hrtimer_cancel(&wdd->wd_data->pretimeout_timer);
39*7b7d2fdcSCurtis Klein }
40*7b7d2fdcSCurtis Klein 
watchdog_hrtimer_pretimeout_stop(struct watchdog_device * wdd)41*7b7d2fdcSCurtis Klein void watchdog_hrtimer_pretimeout_stop(struct watchdog_device *wdd)
42*7b7d2fdcSCurtis Klein {
43*7b7d2fdcSCurtis Klein 	hrtimer_cancel(&wdd->wd_data->pretimeout_timer);
44*7b7d2fdcSCurtis Klein }
45