xref: /linux/Documentation/watchdog/watchdog-kernel-api.rst (revision d56b699d76d1b352f7a3d3a0a3e91c79b8612d94)
1cc2a2d19SMauro Carvalho Chehab===============================================
2cc2a2d19SMauro Carvalho ChehabThe Linux WatchDog Timer Driver Core kernel API
3cc2a2d19SMauro Carvalho Chehab===============================================
4cc2a2d19SMauro Carvalho Chehab
5cc2a2d19SMauro Carvalho ChehabLast reviewed: 12-Feb-2013
6cc2a2d19SMauro Carvalho Chehab
7cc2a2d19SMauro Carvalho ChehabWim Van Sebroeck <wim@iguana.be>
8cc2a2d19SMauro Carvalho Chehab
9cc2a2d19SMauro Carvalho ChehabIntroduction
10cc2a2d19SMauro Carvalho Chehab------------
11cc2a2d19SMauro Carvalho ChehabThis document does not describe what a WatchDog Timer (WDT) Driver or Device is.
12cc2a2d19SMauro Carvalho ChehabIt also does not describe the API which can be used by user space to communicate
13cc2a2d19SMauro Carvalho Chehabwith a WatchDog Timer. If you want to know this then please read the following
14cc2a2d19SMauro Carvalho Chehabfile: Documentation/watchdog/watchdog-api.rst .
15cc2a2d19SMauro Carvalho Chehab
16cc2a2d19SMauro Carvalho ChehabSo what does this document describe? It describes the API that can be used by
17cc2a2d19SMauro Carvalho ChehabWatchDog Timer Drivers that want to use the WatchDog Timer Driver Core
18cc2a2d19SMauro Carvalho ChehabFramework. This framework provides all interfacing towards user space so that
19cc2a2d19SMauro Carvalho Chehabthe same code does not have to be reproduced each time. This also means that
20cc2a2d19SMauro Carvalho Chehaba watchdog timer driver then only needs to provide the different routines
21cc2a2d19SMauro Carvalho Chehab(operations) that control the watchdog timer (WDT).
22cc2a2d19SMauro Carvalho Chehab
23cc2a2d19SMauro Carvalho ChehabThe API
24cc2a2d19SMauro Carvalho Chehab-------
25cc2a2d19SMauro Carvalho ChehabEach watchdog timer driver that wants to use the WatchDog Timer Driver Core
26cc2a2d19SMauro Carvalho Chehabmust #include <linux/watchdog.h> (you would have to do this anyway when
27cc2a2d19SMauro Carvalho Chehabwriting a watchdog device driver). This include file contains following
28cc2a2d19SMauro Carvalho Chehabregister/unregister routines::
29cc2a2d19SMauro Carvalho Chehab
30cc2a2d19SMauro Carvalho Chehab	extern int watchdog_register_device(struct watchdog_device *);
31cc2a2d19SMauro Carvalho Chehab	extern void watchdog_unregister_device(struct watchdog_device *);
32cc2a2d19SMauro Carvalho Chehab
33cc2a2d19SMauro Carvalho ChehabThe watchdog_register_device routine registers a watchdog timer device.
34cc2a2d19SMauro Carvalho ChehabThe parameter of this routine is a pointer to a watchdog_device structure.
35cc2a2d19SMauro Carvalho ChehabThis routine returns zero on success and a negative errno code for failure.
36cc2a2d19SMauro Carvalho Chehab
37cc2a2d19SMauro Carvalho ChehabThe watchdog_unregister_device routine deregisters a registered watchdog timer
38cc2a2d19SMauro Carvalho Chehabdevice. The parameter of this routine is the pointer to the registered
39cc2a2d19SMauro Carvalho Chehabwatchdog_device structure.
40cc2a2d19SMauro Carvalho Chehab
41cc2a2d19SMauro Carvalho ChehabThe watchdog subsystem includes an registration deferral mechanism,
42cc2a2d19SMauro Carvalho Chehabwhich allows you to register an watchdog as early as you wish during
43cc2a2d19SMauro Carvalho Chehabthe boot process.
44cc2a2d19SMauro Carvalho Chehab
45cc2a2d19SMauro Carvalho ChehabThe watchdog device structure looks like this::
46cc2a2d19SMauro Carvalho Chehab
47cc2a2d19SMauro Carvalho Chehab  struct watchdog_device {
48cc2a2d19SMauro Carvalho Chehab	int id;
49cc2a2d19SMauro Carvalho Chehab	struct device *parent;
50cc2a2d19SMauro Carvalho Chehab	const struct attribute_group **groups;
51cc2a2d19SMauro Carvalho Chehab	const struct watchdog_info *info;
52cc2a2d19SMauro Carvalho Chehab	const struct watchdog_ops *ops;
53cc2a2d19SMauro Carvalho Chehab	const struct watchdog_governor *gov;
54cc2a2d19SMauro Carvalho Chehab	unsigned int bootstatus;
55cc2a2d19SMauro Carvalho Chehab	unsigned int timeout;
56cc2a2d19SMauro Carvalho Chehab	unsigned int pretimeout;
57cc2a2d19SMauro Carvalho Chehab	unsigned int min_timeout;
58cc2a2d19SMauro Carvalho Chehab	unsigned int max_timeout;
59cc2a2d19SMauro Carvalho Chehab	unsigned int min_hw_heartbeat_ms;
60cc2a2d19SMauro Carvalho Chehab	unsigned int max_hw_heartbeat_ms;
61cc2a2d19SMauro Carvalho Chehab	struct notifier_block reboot_nb;
62cc2a2d19SMauro Carvalho Chehab	struct notifier_block restart_nb;
63cc2a2d19SMauro Carvalho Chehab	void *driver_data;
64cc2a2d19SMauro Carvalho Chehab	struct watchdog_core_data *wd_data;
65cc2a2d19SMauro Carvalho Chehab	unsigned long status;
66cc2a2d19SMauro Carvalho Chehab	struct list_head deferred;
67cc2a2d19SMauro Carvalho Chehab  };
68cc2a2d19SMauro Carvalho Chehab
69cc2a2d19SMauro Carvalho ChehabIt contains following fields:
70cc2a2d19SMauro Carvalho Chehab
71cc2a2d19SMauro Carvalho Chehab* id: set by watchdog_register_device, id 0 is special. It has both a
72cc2a2d19SMauro Carvalho Chehab  /dev/watchdog0 cdev (dynamic major, minor 0) as well as the old
73cc2a2d19SMauro Carvalho Chehab  /dev/watchdog miscdev. The id is set automatically when calling
74cc2a2d19SMauro Carvalho Chehab  watchdog_register_device.
75cc2a2d19SMauro Carvalho Chehab* parent: set this to the parent device (or NULL) before calling
76cc2a2d19SMauro Carvalho Chehab  watchdog_register_device.
77cc2a2d19SMauro Carvalho Chehab* groups: List of sysfs attribute groups to create when creating the watchdog
78cc2a2d19SMauro Carvalho Chehab  device.
79cc2a2d19SMauro Carvalho Chehab* info: a pointer to a watchdog_info structure. This structure gives some
80*d56b699dSBjorn Helgaas  additional information about the watchdog timer itself. (Like its unique name)
81cc2a2d19SMauro Carvalho Chehab* ops: a pointer to the list of watchdog operations that the watchdog supports.
82cc2a2d19SMauro Carvalho Chehab* gov: a pointer to the assigned watchdog device pretimeout governor or NULL.
83cc2a2d19SMauro Carvalho Chehab* timeout: the watchdog timer's timeout value (in seconds).
84cc2a2d19SMauro Carvalho Chehab  This is the time after which the system will reboot if user space does
85cc2a2d19SMauro Carvalho Chehab  not send a heartbeat request if WDOG_ACTIVE is set.
86cc2a2d19SMauro Carvalho Chehab* pretimeout: the watchdog timer's pretimeout value (in seconds).
87cc2a2d19SMauro Carvalho Chehab* min_timeout: the watchdog timer's minimum timeout value (in seconds).
88cc2a2d19SMauro Carvalho Chehab  If set, the minimum configurable value for 'timeout'.
89cc2a2d19SMauro Carvalho Chehab* max_timeout: the watchdog timer's maximum timeout value (in seconds),
90cc2a2d19SMauro Carvalho Chehab  as seen from userspace. If set, the maximum configurable value for
91cc2a2d19SMauro Carvalho Chehab  'timeout'. Not used if max_hw_heartbeat_ms is non-zero.
92cc2a2d19SMauro Carvalho Chehab* min_hw_heartbeat_ms: Hardware limit for minimum time between heartbeats,
93cc2a2d19SMauro Carvalho Chehab  in milli-seconds. This value is normally 0; it should only be provided
94cc2a2d19SMauro Carvalho Chehab  if the hardware can not tolerate lower intervals between heartbeats.
95cc2a2d19SMauro Carvalho Chehab* max_hw_heartbeat_ms: Maximum hardware heartbeat, in milli-seconds.
96cc2a2d19SMauro Carvalho Chehab  If set, the infrastructure will send heartbeats to the watchdog driver
97cc2a2d19SMauro Carvalho Chehab  if 'timeout' is larger than max_hw_heartbeat_ms, unless WDOG_ACTIVE
98cc2a2d19SMauro Carvalho Chehab  is set and userspace failed to send a heartbeat for at least 'timeout'
99cc2a2d19SMauro Carvalho Chehab  seconds. max_hw_heartbeat_ms must be set if a driver does not implement
100cc2a2d19SMauro Carvalho Chehab  the stop function.
101cc2a2d19SMauro Carvalho Chehab* reboot_nb: notifier block that is registered for reboot notifications, for
102cc2a2d19SMauro Carvalho Chehab  internal use only. If the driver calls watchdog_stop_on_reboot, watchdog core
103cc2a2d19SMauro Carvalho Chehab  will stop the watchdog on such notifications.
104cc2a2d19SMauro Carvalho Chehab* restart_nb: notifier block that is registered for machine restart, for
105cc2a2d19SMauro Carvalho Chehab  internal use only. If a watchdog is capable of restarting the machine, it
106cc2a2d19SMauro Carvalho Chehab  should define ops->restart. Priority can be changed through
107cc2a2d19SMauro Carvalho Chehab  watchdog_set_restart_priority.
108cc2a2d19SMauro Carvalho Chehab* bootstatus: status of the device after booting (reported with watchdog
109cc2a2d19SMauro Carvalho Chehab  WDIOF_* status bits).
110cc2a2d19SMauro Carvalho Chehab* driver_data: a pointer to the drivers private data of a watchdog device.
111cc2a2d19SMauro Carvalho Chehab  This data should only be accessed via the watchdog_set_drvdata and
112cc2a2d19SMauro Carvalho Chehab  watchdog_get_drvdata routines.
113cc2a2d19SMauro Carvalho Chehab* wd_data: a pointer to watchdog core internal data.
114cc2a2d19SMauro Carvalho Chehab* status: this field contains a number of status bits that give extra
115cc2a2d19SMauro Carvalho Chehab  information about the status of the device (Like: is the watchdog timer
116cc2a2d19SMauro Carvalho Chehab  running/active, or is the nowayout bit set).
117cc2a2d19SMauro Carvalho Chehab* deferred: entry in wtd_deferred_reg_list which is used to
118cc2a2d19SMauro Carvalho Chehab  register early initialized watchdogs.
119cc2a2d19SMauro Carvalho Chehab
120cc2a2d19SMauro Carvalho ChehabThe list of watchdog operations is defined as::
121cc2a2d19SMauro Carvalho Chehab
122cc2a2d19SMauro Carvalho Chehab  struct watchdog_ops {
123cc2a2d19SMauro Carvalho Chehab	struct module *owner;
124cc2a2d19SMauro Carvalho Chehab	/* mandatory operations */
125cc2a2d19SMauro Carvalho Chehab	int (*start)(struct watchdog_device *);
126cc2a2d19SMauro Carvalho Chehab	/* optional operations */
1274951d27bSBumsik Kim	int (*stop)(struct watchdog_device *);
128cc2a2d19SMauro Carvalho Chehab	int (*ping)(struct watchdog_device *);
129cc2a2d19SMauro Carvalho Chehab	unsigned int (*status)(struct watchdog_device *);
130cc2a2d19SMauro Carvalho Chehab	int (*set_timeout)(struct watchdog_device *, unsigned int);
131cc2a2d19SMauro Carvalho Chehab	int (*set_pretimeout)(struct watchdog_device *, unsigned int);
132cc2a2d19SMauro Carvalho Chehab	unsigned int (*get_timeleft)(struct watchdog_device *);
133cc2a2d19SMauro Carvalho Chehab	int (*restart)(struct watchdog_device *);
134cc2a2d19SMauro Carvalho Chehab	long (*ioctl)(struct watchdog_device *, unsigned int, unsigned long);
135cc2a2d19SMauro Carvalho Chehab  };
136cc2a2d19SMauro Carvalho Chehab
137cc2a2d19SMauro Carvalho ChehabIt is important that you first define the module owner of the watchdog timer
138cc2a2d19SMauro Carvalho Chehabdriver's operations. This module owner will be used to lock the module when
139cc2a2d19SMauro Carvalho Chehabthe watchdog is active. (This to avoid a system crash when you unload the
140cc2a2d19SMauro Carvalho Chehabmodule and /dev/watchdog is still open).
141cc2a2d19SMauro Carvalho Chehab
142cc2a2d19SMauro Carvalho ChehabSome operations are mandatory and some are optional. The mandatory operations
143cc2a2d19SMauro Carvalho Chehabare:
144cc2a2d19SMauro Carvalho Chehab
145cc2a2d19SMauro Carvalho Chehab* start: this is a pointer to the routine that starts the watchdog timer
146cc2a2d19SMauro Carvalho Chehab  device.
147cc2a2d19SMauro Carvalho Chehab  The routine needs a pointer to the watchdog timer device structure as a
148cc2a2d19SMauro Carvalho Chehab  parameter. It returns zero on success or a negative errno code for failure.
149cc2a2d19SMauro Carvalho Chehab
150cc2a2d19SMauro Carvalho ChehabNot all watchdog timer hardware supports the same functionality. That's why
151cc2a2d19SMauro Carvalho Chehaball other routines/operations are optional. They only need to be provided if
152cc2a2d19SMauro Carvalho Chehabthey are supported. These optional routines/operations are:
153cc2a2d19SMauro Carvalho Chehab
154cc2a2d19SMauro Carvalho Chehab* stop: with this routine the watchdog timer device is being stopped.
155cc2a2d19SMauro Carvalho Chehab
156cc2a2d19SMauro Carvalho Chehab  The routine needs a pointer to the watchdog timer device structure as a
157cc2a2d19SMauro Carvalho Chehab  parameter. It returns zero on success or a negative errno code for failure.
158cc2a2d19SMauro Carvalho Chehab  Some watchdog timer hardware can only be started and not be stopped. A
159cc2a2d19SMauro Carvalho Chehab  driver supporting such hardware does not have to implement the stop routine.
160cc2a2d19SMauro Carvalho Chehab
161cc2a2d19SMauro Carvalho Chehab  If a driver has no stop function, the watchdog core will set WDOG_HW_RUNNING
162cc2a2d19SMauro Carvalho Chehab  and start calling the driver's keepalive pings function after the watchdog
163cc2a2d19SMauro Carvalho Chehab  device is closed.
164cc2a2d19SMauro Carvalho Chehab
165cc2a2d19SMauro Carvalho Chehab  If a watchdog driver does not implement the stop function, it must set
166cc2a2d19SMauro Carvalho Chehab  max_hw_heartbeat_ms.
167cc2a2d19SMauro Carvalho Chehab* ping: this is the routine that sends a keepalive ping to the watchdog timer
168cc2a2d19SMauro Carvalho Chehab  hardware.
169cc2a2d19SMauro Carvalho Chehab
170cc2a2d19SMauro Carvalho Chehab  The routine needs a pointer to the watchdog timer device structure as a
171cc2a2d19SMauro Carvalho Chehab  parameter. It returns zero on success or a negative errno code for failure.
172cc2a2d19SMauro Carvalho Chehab
173cc2a2d19SMauro Carvalho Chehab  Most hardware that does not support this as a separate function uses the
174cc2a2d19SMauro Carvalho Chehab  start function to restart the watchdog timer hardware. And that's also what
175cc2a2d19SMauro Carvalho Chehab  the watchdog timer driver core does: to send a keepalive ping to the watchdog
176cc2a2d19SMauro Carvalho Chehab  timer hardware it will either use the ping operation (when available) or the
177cc2a2d19SMauro Carvalho Chehab  start operation (when the ping operation is not available).
178cc2a2d19SMauro Carvalho Chehab
179cc2a2d19SMauro Carvalho Chehab  (Note: the WDIOC_KEEPALIVE ioctl call will only be active when the
180cc2a2d19SMauro Carvalho Chehab  WDIOF_KEEPALIVEPING bit has been set in the option field on the watchdog's
181cc2a2d19SMauro Carvalho Chehab  info structure).
182cc2a2d19SMauro Carvalho Chehab* status: this routine checks the status of the watchdog timer device. The
183cc2a2d19SMauro Carvalho Chehab  status of the device is reported with watchdog WDIOF_* status flags/bits.
184cc2a2d19SMauro Carvalho Chehab
185cc2a2d19SMauro Carvalho Chehab  WDIOF_MAGICCLOSE and WDIOF_KEEPALIVEPING are reported by the watchdog core;
186cc2a2d19SMauro Carvalho Chehab  it is not necessary to report those bits from the driver. Also, if no status
187cc2a2d19SMauro Carvalho Chehab  function is provided by the driver, the watchdog core reports the status bits
188cc2a2d19SMauro Carvalho Chehab  provided in the bootstatus variable of struct watchdog_device.
189cc2a2d19SMauro Carvalho Chehab
190cc2a2d19SMauro Carvalho Chehab* set_timeout: this routine checks and changes the timeout of the watchdog
191cc2a2d19SMauro Carvalho Chehab  timer device. It returns 0 on success, -EINVAL for "parameter out of range"
192cc2a2d19SMauro Carvalho Chehab  and -EIO for "could not write value to the watchdog". On success this
193cc2a2d19SMauro Carvalho Chehab  routine should set the timeout value of the watchdog_device to the
194cc2a2d19SMauro Carvalho Chehab  achieved timeout value (which may be different from the requested one
195cc2a2d19SMauro Carvalho Chehab  because the watchdog does not necessarily have a 1 second resolution).
196cc2a2d19SMauro Carvalho Chehab
197cc2a2d19SMauro Carvalho Chehab  Drivers implementing max_hw_heartbeat_ms set the hardware watchdog heartbeat
198cc2a2d19SMauro Carvalho Chehab  to the minimum of timeout and max_hw_heartbeat_ms. Those drivers set the
199cc2a2d19SMauro Carvalho Chehab  timeout value of the watchdog_device either to the requested timeout value
200cc2a2d19SMauro Carvalho Chehab  (if it is larger than max_hw_heartbeat_ms), or to the achieved timeout value.
201cc2a2d19SMauro Carvalho Chehab  (Note: the WDIOF_SETTIMEOUT needs to be set in the options field of the
202cc2a2d19SMauro Carvalho Chehab  watchdog's info structure).
203cc2a2d19SMauro Carvalho Chehab
204cc2a2d19SMauro Carvalho Chehab  If the watchdog driver does not have to perform any action but setting the
205cc2a2d19SMauro Carvalho Chehab  watchdog_device.timeout, this callback can be omitted.
206cc2a2d19SMauro Carvalho Chehab
207cc2a2d19SMauro Carvalho Chehab  If set_timeout is not provided but, WDIOF_SETTIMEOUT is set, the watchdog
208cc2a2d19SMauro Carvalho Chehab  infrastructure updates the timeout value of the watchdog_device internally
209cc2a2d19SMauro Carvalho Chehab  to the requested value.
210cc2a2d19SMauro Carvalho Chehab
211cc2a2d19SMauro Carvalho Chehab  If the pretimeout feature is used (WDIOF_PRETIMEOUT), then set_timeout must
212cc2a2d19SMauro Carvalho Chehab  also take care of checking if pretimeout is still valid and set up the timer
213cc2a2d19SMauro Carvalho Chehab  accordingly. This can't be done in the core without races, so it is the
214cc2a2d19SMauro Carvalho Chehab  duty of the driver.
215cc2a2d19SMauro Carvalho Chehab* set_pretimeout: this routine checks and changes the pretimeout value of
216cc2a2d19SMauro Carvalho Chehab  the watchdog. It is optional because not all watchdogs support pretimeout
217cc2a2d19SMauro Carvalho Chehab  notification. The timeout value is not an absolute time, but the number of
218cc2a2d19SMauro Carvalho Chehab  seconds before the actual timeout would happen. It returns 0 on success,
219cc2a2d19SMauro Carvalho Chehab  -EINVAL for "parameter out of range" and -EIO for "could not write value to
220cc2a2d19SMauro Carvalho Chehab  the watchdog". A value of 0 disables pretimeout notification.
221cc2a2d19SMauro Carvalho Chehab
222cc2a2d19SMauro Carvalho Chehab  (Note: the WDIOF_PRETIMEOUT needs to be set in the options field of the
223cc2a2d19SMauro Carvalho Chehab  watchdog's info structure).
224cc2a2d19SMauro Carvalho Chehab
225cc2a2d19SMauro Carvalho Chehab  If the watchdog driver does not have to perform any action but setting the
226cc2a2d19SMauro Carvalho Chehab  watchdog_device.pretimeout, this callback can be omitted. That means if
227cc2a2d19SMauro Carvalho Chehab  set_pretimeout is not provided but WDIOF_PRETIMEOUT is set, the watchdog
228cc2a2d19SMauro Carvalho Chehab  infrastructure updates the pretimeout value of the watchdog_device internally
229cc2a2d19SMauro Carvalho Chehab  to the requested value.
230cc2a2d19SMauro Carvalho Chehab
231cc2a2d19SMauro Carvalho Chehab* get_timeleft: this routines returns the time that's left before a reset.
232cc2a2d19SMauro Carvalho Chehab* restart: this routine restarts the machine. It returns 0 on success or a
233cc2a2d19SMauro Carvalho Chehab  negative errno code for failure.
234cc2a2d19SMauro Carvalho Chehab* ioctl: if this routine is present then it will be called first before we do
235cc2a2d19SMauro Carvalho Chehab  our own internal ioctl call handling. This routine should return -ENOIOCTLCMD
236cc2a2d19SMauro Carvalho Chehab  if a command is not supported. The parameters that are passed to the ioctl
237cc2a2d19SMauro Carvalho Chehab  call are: watchdog_device, cmd and arg.
238cc2a2d19SMauro Carvalho Chehab
239cc2a2d19SMauro Carvalho ChehabThe status bits should (preferably) be set with the set_bit and clear_bit alike
240cc2a2d19SMauro Carvalho Chehabbit-operations. The status bits that are defined are:
241cc2a2d19SMauro Carvalho Chehab
242cc2a2d19SMauro Carvalho Chehab* WDOG_ACTIVE: this status bit indicates whether or not a watchdog timer device
243cc2a2d19SMauro Carvalho Chehab  is active or not from user perspective. User space is expected to send
244cc2a2d19SMauro Carvalho Chehab  heartbeat requests to the driver while this flag is set.
245cc2a2d19SMauro Carvalho Chehab* WDOG_NO_WAY_OUT: this bit stores the nowayout setting for the watchdog.
246cc2a2d19SMauro Carvalho Chehab  If this bit is set then the watchdog timer will not be able to stop.
247cc2a2d19SMauro Carvalho Chehab* WDOG_HW_RUNNING: Set by the watchdog driver if the hardware watchdog is
248cc2a2d19SMauro Carvalho Chehab  running. The bit must be set if the watchdog timer hardware can not be
249cc2a2d19SMauro Carvalho Chehab  stopped. The bit may also be set if the watchdog timer is running after
250cc2a2d19SMauro Carvalho Chehab  booting, before the watchdog device is opened. If set, the watchdog
251cc2a2d19SMauro Carvalho Chehab  infrastructure will send keepalives to the watchdog hardware while
252cc2a2d19SMauro Carvalho Chehab  WDOG_ACTIVE is not set.
253cc2a2d19SMauro Carvalho Chehab  Note: when you register the watchdog timer device with this bit set,
254cc2a2d19SMauro Carvalho Chehab  then opening /dev/watchdog will skip the start operation but send a keepalive
255cc2a2d19SMauro Carvalho Chehab  request instead.
256cc2a2d19SMauro Carvalho Chehab
257cc2a2d19SMauro Carvalho Chehab  To set the WDOG_NO_WAY_OUT status bit (before registering your watchdog
258cc2a2d19SMauro Carvalho Chehab  timer device) you can either:
259cc2a2d19SMauro Carvalho Chehab
260cc2a2d19SMauro Carvalho Chehab  * set it statically in your watchdog_device struct with
261cc2a2d19SMauro Carvalho Chehab
262cc2a2d19SMauro Carvalho Chehab	.status = WATCHDOG_NOWAYOUT_INIT_STATUS,
263cc2a2d19SMauro Carvalho Chehab
264cc2a2d19SMauro Carvalho Chehab    (this will set the value the same as CONFIG_WATCHDOG_NOWAYOUT) or
265cc2a2d19SMauro Carvalho Chehab  * use the following helper function::
266cc2a2d19SMauro Carvalho Chehab
267cc2a2d19SMauro Carvalho Chehab	static inline void watchdog_set_nowayout(struct watchdog_device *wdd,
268cc2a2d19SMauro Carvalho Chehab						 int nowayout)
269cc2a2d19SMauro Carvalho Chehab
270cc2a2d19SMauro Carvalho ChehabNote:
271cc2a2d19SMauro Carvalho Chehab   The WatchDog Timer Driver Core supports the magic close feature and
272cc2a2d19SMauro Carvalho Chehab   the nowayout feature. To use the magic close feature you must set the
273cc2a2d19SMauro Carvalho Chehab   WDIOF_MAGICCLOSE bit in the options field of the watchdog's info structure.
274cc2a2d19SMauro Carvalho Chehab
275cc2a2d19SMauro Carvalho ChehabThe nowayout feature will overrule the magic close feature.
276cc2a2d19SMauro Carvalho Chehab
277cc2a2d19SMauro Carvalho ChehabTo get or set driver specific data the following two helper functions should be
278cc2a2d19SMauro Carvalho Chehabused::
279cc2a2d19SMauro Carvalho Chehab
280cc2a2d19SMauro Carvalho Chehab  static inline void watchdog_set_drvdata(struct watchdog_device *wdd,
281cc2a2d19SMauro Carvalho Chehab					  void *data)
282cc2a2d19SMauro Carvalho Chehab  static inline void *watchdog_get_drvdata(struct watchdog_device *wdd)
283cc2a2d19SMauro Carvalho Chehab
284cc2a2d19SMauro Carvalho ChehabThe watchdog_set_drvdata function allows you to add driver specific data. The
285cc2a2d19SMauro Carvalho Chehabarguments of this function are the watchdog device where you want to add the
286cc2a2d19SMauro Carvalho Chehabdriver specific data to and a pointer to the data itself.
287cc2a2d19SMauro Carvalho Chehab
288cc2a2d19SMauro Carvalho ChehabThe watchdog_get_drvdata function allows you to retrieve driver specific data.
289cc2a2d19SMauro Carvalho ChehabThe argument of this function is the watchdog device where you want to retrieve
290cc2a2d19SMauro Carvalho Chehabdata from. The function returns the pointer to the driver specific data.
291cc2a2d19SMauro Carvalho Chehab
292cc2a2d19SMauro Carvalho ChehabTo initialize the timeout field, the following function can be used::
293cc2a2d19SMauro Carvalho Chehab
294cc2a2d19SMauro Carvalho Chehab  extern int watchdog_init_timeout(struct watchdog_device *wdd,
295cc2a2d19SMauro Carvalho Chehab                                   unsigned int timeout_parm,
296cc2a2d19SMauro Carvalho Chehab                                   struct device *dev);
297cc2a2d19SMauro Carvalho Chehab
298cc2a2d19SMauro Carvalho ChehabThe watchdog_init_timeout function allows you to initialize the timeout field
299cc2a2d19SMauro Carvalho Chehabusing the module timeout parameter or by retrieving the timeout-sec property from
300cc2a2d19SMauro Carvalho Chehabthe device tree (if the module timeout parameter is invalid). Best practice is
301cc2a2d19SMauro Carvalho Chehabto set the default timeout value as timeout value in the watchdog_device and
302cc2a2d19SMauro Carvalho Chehabthen use this function to set the user "preferred" timeout value.
303cc2a2d19SMauro Carvalho ChehabThis routine returns zero on success and a negative errno code for failure.
304cc2a2d19SMauro Carvalho Chehab
305cc2a2d19SMauro Carvalho ChehabTo disable the watchdog on reboot, the user must call the following helper::
306cc2a2d19SMauro Carvalho Chehab
307cc2a2d19SMauro Carvalho Chehab  static inline void watchdog_stop_on_reboot(struct watchdog_device *wdd);
308cc2a2d19SMauro Carvalho Chehab
309cc2a2d19SMauro Carvalho ChehabTo disable the watchdog when unregistering the watchdog, the user must call
310cc2a2d19SMauro Carvalho Chehabthe following helper. Note that this will only stop the watchdog if the
311cc2a2d19SMauro Carvalho Chehabnowayout flag is not set.
312cc2a2d19SMauro Carvalho Chehab
313cc2a2d19SMauro Carvalho Chehab::
314cc2a2d19SMauro Carvalho Chehab
315cc2a2d19SMauro Carvalho Chehab  static inline void watchdog_stop_on_unregister(struct watchdog_device *wdd);
316cc2a2d19SMauro Carvalho Chehab
317cc2a2d19SMauro Carvalho ChehabTo change the priority of the restart handler the following helper should be
318cc2a2d19SMauro Carvalho Chehabused::
319cc2a2d19SMauro Carvalho Chehab
320cc2a2d19SMauro Carvalho Chehab  void watchdog_set_restart_priority(struct watchdog_device *wdd, int priority);
321cc2a2d19SMauro Carvalho Chehab
322cc2a2d19SMauro Carvalho ChehabUser should follow the following guidelines for setting the priority:
323cc2a2d19SMauro Carvalho Chehab
324cc2a2d19SMauro Carvalho Chehab* 0: should be called in last resort, has limited restart capabilities
325cc2a2d19SMauro Carvalho Chehab* 128: default restart handler, use if no other handler is expected to be
326cc2a2d19SMauro Carvalho Chehab  available, and/or if restart is sufficient to restart the entire system
327cc2a2d19SMauro Carvalho Chehab* 255: highest priority, will preempt all other restart handlers
328cc2a2d19SMauro Carvalho Chehab
329cc2a2d19SMauro Carvalho ChehabTo raise a pretimeout notification, the following function should be used::
330cc2a2d19SMauro Carvalho Chehab
331cc2a2d19SMauro Carvalho Chehab  void watchdog_notify_pretimeout(struct watchdog_device *wdd)
332cc2a2d19SMauro Carvalho Chehab
333cc2a2d19SMauro Carvalho ChehabThe function can be called in the interrupt context. If watchdog pretimeout
334cc2a2d19SMauro Carvalho Chehabgovernor framework (kbuild CONFIG_WATCHDOG_PRETIMEOUT_GOV symbol) is enabled,
335cc2a2d19SMauro Carvalho Chehaban action is taken by a preconfigured pretimeout governor preassigned to
336cc2a2d19SMauro Carvalho Chehabthe watchdog device. If watchdog pretimeout governor framework is not
337cc2a2d19SMauro Carvalho Chehabenabled, watchdog_notify_pretimeout() prints a notification message to
338cc2a2d19SMauro Carvalho Chehabthe kernel log buffer.
339cef9572eSTero Kristo
340cef9572eSTero KristoTo set the last known HW keepalive time for a watchdog, the following function
341cef9572eSTero Kristoshould be used::
342cef9572eSTero Kristo
343cef9572eSTero Kristo  int watchdog_set_last_hw_keepalive(struct watchdog_device *wdd,
344cef9572eSTero Kristo                                     unsigned int last_ping_ms)
345cef9572eSTero Kristo
346cef9572eSTero KristoThis function must be called immediately after watchdog registration. It
347cef9572eSTero Kristosets the last known hardware heartbeat to have happened last_ping_ms before
348cef9572eSTero Kristocurrent time. Calling this is only needed if the watchdog is already running
349cef9572eSTero Kristowhen probe is called, and the watchdog can only be pinged after the
350cef9572eSTero Kristomin_hw_heartbeat_ms time has passed from the last ping.
351