1 /* SPDX-License-Identifier: GPL-2.0+ */
5 * (c) Copyright 2008-2011 Alan Cox <alan@lxorguk.ukuu.org.uk>,
8 * (c) Copyright 2008-2011 Wim Van Sebroeck <wim@iguana.be>.
10 * (c) Copyright 2021 Hewlett Packard Enterprise Development LP.
12 * This source code is part of the generic code that can be used
13 * by all the watchdog timer drivers.
15 * Based on source code of the following authors:
16 * Matt Domsch <Matt_Domsch@dell.com>,
17 * Rob Radez <rob@osinvestor.com>,
18 * Rusty Lynch <rusty@linux.co.intel.com>
19 * Satyam Sharma <satyam@infradead.org>
20 * Randy Dunlap <randy.dunlap@oracle.com>
22 * Neither Alan Cox, CymruNet Ltd., Wim Van Sebroeck nor Iguana vzw.
23 * admit liability nor provide warranty for any of this software.
24 * This material is provided "AS-IS" and at no charge.
27 #include <linux/hrtimer.h>
28 #include <linux/kthread.h>
30 #define MAX_DOGS 32 /* Maximum number of watchdog devices */
33 * struct watchdog_core_data - watchdog core internal data
34 * @dev: The watchdog's internal device
35 * @cdev: The watchdog's Character device.
36 * @wdd: Pointer to watchdog device.
37 * @lock: Lock for watchdog core.
38 * @status: Watchdog core internal status bits.
40 struct watchdog_core_data
{
43 struct watchdog_device
*wdd
;
45 ktime_t last_keepalive
;
46 ktime_t last_hw_keepalive
;
47 ktime_t open_deadline
;
49 struct kthread_work work
;
50 #if IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT)
51 struct hrtimer pretimeout_timer
;
53 unsigned long status
; /* Internal status bits */
54 #define _WDOG_DEV_OPEN 0 /* Opened ? */
55 #define _WDOG_ALLOW_RELEASE 1 /* Did we receive the magic char ? */
56 #define _WDOG_KEEPALIVE 2 /* Did we receive a keepalive ? */
60 * Functions/procedures to be called by the core
62 extern int watchdog_dev_register(struct watchdog_device
*);
63 extern void watchdog_dev_unregister(struct watchdog_device
*);
64 extern int __init
watchdog_dev_init(void);
65 extern void __exit
watchdog_dev_exit(void);
67 static inline bool watchdog_have_pretimeout(struct watchdog_device
*wdd
)
69 return wdd
->info
->options
& WDIOF_PRETIMEOUT
||
70 IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT
);
73 #if IS_ENABLED(CONFIG_WATCHDOG_HRTIMER_PRETIMEOUT)
74 void watchdog_hrtimer_pretimeout_init(struct watchdog_device
*wdd
);
75 void watchdog_hrtimer_pretimeout_start(struct watchdog_device
*wdd
);
76 void watchdog_hrtimer_pretimeout_stop(struct watchdog_device
*wdd
);
78 static inline void watchdog_hrtimer_pretimeout_init(struct watchdog_device
*wdd
) {}
79 static inline void watchdog_hrtimer_pretimeout_start(struct watchdog_device
*wdd
) {}
80 static inline void watchdog_hrtimer_pretimeout_stop(struct watchdog_device
*wdd
) {}