1 The Linux Watchdog driver API.
3 Copyright 2002 Christer Weingel <wingel@nano-system.com>
5 Some parts of this document are copied verbatim from the sbc60xxwdt
6 driver which is (c) Copyright 2000 Jakob Oestergaard <jakob@ostenfeld.dk>
8 This document describes the state of the Linux 2.4.18 kernel.
12 A Watchdog Timer (WDT) is a hardware circuit that can reset the
13 computer system in case of a software fault. You probably knew that
16 Usually a userspace daemon will notify the kernel watchdog driver via the
17 /dev/watchdog special device file that userspace is still alive, at
18 regular intervals. When such a notification occurs, the driver will
19 usually tell the hardware watchdog that everything is in order, and
20 that the watchdog should wait for yet another little while to reset
21 the system. If userspace fails (RAM error, kernel bug, whatever), the
22 notifications cease to occur, and the hardware watchdog will reset the
23 system (causing a reboot) after the timeout occurs.
25 The Linux watchdog API is a rather AD hoc construction and different
26 drivers implement different, and sometimes incompatible, parts of it.
27 This file is an attempt to document the existing usage and allow
28 future driver writers to use it as a reference.
32 All drivers support the basic mode of operation, where the watchdog
33 activates as soon as /dev/watchdog is opened and will reboot unless
34 the watchdog is pinged within a certain time, this time is called the
35 timeout or margin. The simplest way to ping the watchdog is to write
36 some data to the device. So a very simple watchdog daemon would look
42 int main(int argc, const char *argv[]) {
43 int fd=open("/dev/watchdog",O_WRONLY);
54 A more advanced driver could for example check that a HTTP server is
55 still responding before doing the write call to ping the watchdog.
57 When the device is closed, the watchdog is disabled. This is not
58 always such a good idea, since if there is a bug in the watchdog
59 daemon and it crashes the system will not reboot. Because of this,
60 some of the drivers support the configuration option "Disable watchdog
61 shutdown on close", CONFIG_WATCHDOG_NOWAYOUT. If it is set to Y when
62 compiling the kernel, there is no way of disabling the watchdog once
63 it has been started. So, if the watchdog dameon crashes, the system
64 will reboot after the timeout has passed.
66 Some other drivers will not disable the watchdog, unless a specific
67 magic character 'V' has been sent /dev/watchdog just before closing
68 the file. If the userspace daemon closes the file without sending
69 this special character, the driver will assume that the daemon (and
70 userspace in general) died, and will stop pinging the watchdog without
71 disabling it first. This will then cause a reboot.
75 All conforming drivers also support an ioctl API.
77 Pinging the watchdog using an ioctl:
79 All drivers that have an ioctl interface support at least one ioctl,
80 KEEPALIVE. This ioctl does exactly the same thing as a write to the
81 watchdog device, so the main loop in the above program could be
85 ioctl(fd, WDIOC_KEEPALIVE, 0);
89 the argument to the ioctl is ignored.
91 Setting and getting the timeout:
93 For some drivers it is possible to modify the watchdog timeout on the
94 fly with the SETTIMEOUT ioctl, those drivers have the WDIOF_SETTIMEOUT
95 flag set in their option field. The argument is an integer
96 representing the timeout in seconds. The driver returns the real
97 timeout used in the same variable, and this timeout might differ from
98 the requested one due to limitation of the hardware.
101 ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
102 printf("The timeout was set to %d seconds\n", timeout);
104 This example might actually print "The timeout was set to 60 seconds"
105 if the device has a granularity of minutes for its timeout.
107 Starting with the Linux 2.4.18 kernel, it is possible to query the
108 current timeout using the GETTIMEOUT ioctl.
110 ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
111 printf("The timeout was is %d seconds\n", timeout);
113 Envinronmental monitoring:
115 All watchdog drivers are required return more information about the system,
116 some do temperature, fan and power level monitoring, some can tell you
117 the reason for the last reboot of the system. The GETSUPPORT ioctl is
118 available to ask what the device can do:
120 struct watchdog_info ident;
121 ioctl(fd, WDIOC_GETSUPPORT, &ident);
123 the fields returned in the ident struct are:
125 identity a string identifying the watchdog driver
126 firmware_version the firmware version of the card if available
127 options a flags describing what the device supports
129 the options field can have the following bits set, and describes what
130 kind of information that the GET_STATUS and GET_BOOT_STATUS ioctls can
131 return. [FIXME -- Is this correct?]
133 WDIOF_OVERHEAT Reset due to CPU overheat
135 The machine was last rebooted by the watchdog because the thermal limit was
138 WDIOF_FANFAULT Fan failed
140 A system fan monitored by the watchdog card has failed
142 WDIOF_EXTERN1 External relay 1
144 External monitoring relay/source 1 was triggered. Controllers intended for
145 real world applications include external monitoring pins that will trigger
148 WDIOF_EXTERN2 External relay 2
150 External monitoring relay/source 2 was triggered
152 WDIOF_POWERUNDER Power bad/power fault
154 The machine is showing an undervoltage status
156 WDIOF_CARDRESET Card previously reset the CPU
158 The last reboot was caused by the watchdog card
160 WDIOF_POWEROVER Power over voltage
162 The machine is showing an overvoltage status. Note that if one level is
163 under and one over both bits will be set - this may seem odd but makes
166 WDIOF_KEEPALIVEPING Keep alive ping reply
168 The watchdog saw a keepalive ping since it was last queried.
170 WDIOF_SETTIMEOUT Can set/get the timeout
173 For those drivers that return any bits set in the option field, the
174 GETSTATUS and GETBOOTSTATUS ioctls can be used to ask for the current
175 status, and the status at the last reboot, respectively.
178 ioctl(fd, WDIOC_GETSTATUS, &flags);
182 ioctl(fd, WDIOC_GETBOOTSTATUS, &flags);
184 Note that not all devices support these two calls, and some only
185 support the GETBOOTSTATUS call.
187 Some drivers can measure the temperature using the GETTEMP ioctl. The
188 returned value is the temperature in degrees farenheit.
191 ioctl(fd, WDIOC_GETTEMP, &temperature);
193 Finally the SETOPTIONS ioctl can be used to control some aspects of
194 the cards operation; right now the pcwd driver is the only one
195 supporting thiss ioctl.
198 ioctl(fd, WDIOC_SETOPTIONS, options);
200 The following options are available:
202 WDIOS_DISABLECARD Turn off the watchdog timer
203 WDIOS_ENABLECARD Turn on the watchdog timer
204 WDIOS_TEMPPANIC Kernel panic on temperature trip
206 [FIXME -- better explanations]
208 Implementations in the current drivers in the kernel tree:
210 Here I have tried to summarize what the different drivers support and
211 where they do strange things compared to the other drivers.
213 acquirewdt.c -- Acquire Single Board Computer
215 This driver has a hardcoded timeout of 1 minute
217 Supports CONFIG_WATCHDOG_NOWAYOUT
219 GETSUPPORT returns KEEPALIVEPING. GETSTATUS will return 1 if
220 the device is open, 0 if not. [FIXME -- isn't this rather
221 silly? To be able to use the ioctl, the device must be open
222 and so GETSTATUS will always return 1].
224 advantechwdt.c -- Advantech Single Board Computer
226 Timeout that defaults to 60 seconds, supports SETTIMEOUT.
228 Supports CONFIG_WATCHDOG_NOWAYOUT
230 GETSUPPORT returns WDIOF_KEEPALIVEPING and WDIOF_SETTIMEOUT.
231 The GETSTATUS call returns if the device is open or not.
232 [FIXME -- silliness again?]
234 booke_wdt.c -- PowerPC BookE Watchdog Timer
236 Timeout default varies according to frequency, supports
239 Watchdog can not be turned off, CONFIG_WATCHDOG_NOWAYOUT
242 GETSUPPORT returns the watchdog_info struct, and
243 GETSTATUS returns the supported options. GETBOOTSTATUS
244 returns a 1 if the last reset was caused by the
245 watchdog and a 0 otherwise. This watchdog can not be
246 disabled once it has been started. The wdt_period kernel
247 parameter selects which bit of the time base changing
248 from 0->1 will trigger the watchdog exception. Changing
249 the timeout from the ioctl calls will change the
250 wdt_period as defined above. Finally if you would like to
251 replace the default Watchdog Handler you can implement the
252 WatchdogHandler() function in your own code.
254 eurotechwdt.c -- Eurotech CPU-1220/1410
256 The timeout can be set using the SETTIMEOUT ioctl and defaults
259 Also has a module parameter "ev", event type which controls
260 what should happen on a timeout, the string "int" or anything
261 else that causes a reboot. [FIXME -- better description]
263 Supports CONFIG_WATCHDOG_NOWAYOUT
265 GETSUPPORT returns CARDRESET and WDIOF_SETTIMEOUT but
266 GETSTATUS is not supported and GETBOOTSTATUS just returns 0.
268 i810-tco.c -- Intel 810 chipset
270 Also has support for a lot of other i8x0 stuff, but the
271 watchdog is one of the things.
273 The timeout is set using the module parameter "i810_margin",
274 which is in steps of 0.6 seconds where 2<i810_margin<64. The
275 driver supports the SETTIMEOUT ioctl.
277 Supports CONFIG_WATCHDOG_NOWAYOUT.
279 GETSUPPORT returns WDIOF_SETTIMEOUT. The GETSTATUS call
280 returns some kind of timer value which ist not compatible with
281 the other drivers. GETBOOT status returns some kind of
282 hardware specific boot status. [FIXME -- describe this]
284 ib700wdt.c -- IB700 Single Board Computer
286 Default timeout of 30 seconds and the timeout is settable
287 using the SETTIMEOUT ioctl. Note that only a few timeout
288 values are supported.
290 Supports CONFIG_WATCHDOG_NOWAYOUT
292 GETSUPPORT returns WDIOF_KEEPALIVEPING and WDIOF_SETTIMEOUT.
293 The GETSTATUS call returns if the device is open or not.
294 [FIXME -- silliness again?]
296 machzwd.c -- MachZ ZF-Logic
298 Hardcoded timeout of 10 seconds
300 Has a module parameter "action" that controls what happens
301 when the timeout runs out which can be 0 = RESET (default),
302 1 = SMI, 2 = NMI, 3 = SCI.
304 Supports CONFIG_WATCHDOG_NOWAYOUT and the magic character
307 GETSUPPORT returns WDIOF_KEEPALIVEPING, and the GETSTATUS call
308 returns if the device is open or not. [FIXME -- silliness
311 mixcomwd.c -- MixCom Watchdog
313 [FIXME -- I'm unable to tell what the timeout is]
315 Supports CONFIG_WATCHDOG_NOWAYOUT
317 GETSUPPORT returns WDIOF_KEEPALIVEPING, GETSTATUS returns if
318 the device is opened or not [FIXME -- I'm not really sure how
319 this works, there seems to be some magic connected to
320 CONFIG_WATCHDOG_NOWAYOUT]
322 pcwd.c -- Berkshire PC Watchdog
324 Hardcoded timeout of 1.5 seconds
326 Supports CONFIG_WATCHDOG_NOWAYOUT
328 GETSUPPORT returns WDIOF_OVERHEAT|WDIOF_CARDRESET and both
329 GETSTATUS and GETBOOTSTATUS return something useful.
331 The SETOPTIONS call can be used to enable and disable the card
332 and to ask the driver to call panic if the system overheats.
334 sbc60xxwdt.c -- 60xx Single Board Computer
336 Hardcoded timeout of 10 seconds
338 Does not support CONFIG_WATCHDOG_NOWAYOUT, but has the magic
339 character 'V' close handling.
341 No bits set in GETSUPPORT
343 scx200.c -- National SCx200 CPUs
345 Not in the kernel yet.
347 The timeout is set using a module parameter "margin" which
348 defaults to 60 seconds. The timeout can also be set using
349 SETTIMEOUT and read using GETTIMEOUT.
351 Supports a module parameter "nowayout" that is initialized
352 with the value of CONFIG_WATCHDOG_NOWAYOUT. Also supports the
353 magic character 'V' handling.
355 shwdt.c -- SuperH 3/4 processors
357 [FIXME -- I'm unable to tell what the timeout is]
359 Supports CONFIG_WATCHDOG_NOWAYOUT
361 GETSUPPORT returns WDIOF_KEEPALIVEPING, and the GETSTATUS call
362 returns if the device is open or not. [FIXME -- silliness
365 softdog.c -- Software watchdog
367 The timeout is set with the module parameter "soft_margin"
368 which defaults to 60 seconds, the timeout is also settable
369 using the SETTIMEOUT ioctl.
371 Supports CONFIG_WATCHDOG_NOWAYOUT
373 WDIOF_SETTIMEOUT bit set in GETSUPPORT
375 w83877f_wdt.c -- W83877F Computer
377 Hardcoded timeout of 30 seconds
379 Does not support CONFIG_WATCHDOG_NOWAYOUT, but has the magic
380 character 'V' close handling.
382 No bits set in GETSUPPORT
384 w83627hf_wdt.c -- w83627hf watchdog
386 Timeout that defaults to 60 seconds, supports SETTIMEOUT.
388 Supports CONFIG_WATCHDOG_NOWAYOUT
390 GETSUPPORT returns WDIOF_KEEPALIVEPING and WDIOF_SETTIMEOUT.
391 The GETSTATUS call returns if the device is open or not.
393 wdt.c -- ICS WDT500/501 ISA and
394 wdt_pci.c -- ICS WDT500/501 PCI
396 Default timeout of 60 seconds. The timeout is also settable
397 using the SETTIMEOUT ioctl.
399 Supports CONFIG_WATCHDOG_NOWAYOUT
401 GETSUPPORT returns with bits set depending on the actual
402 card. The WDT501 supports a lot of external monitoring, the
405 wdt285.c -- Footbridge watchdog
407 The timeout is set with the module parameter "soft_margin"
408 which defaults to 60 seconds. The timeout is also settable
409 using the SETTIMEOUT ioctl.
411 Does not support CONFIG_WATCHDOG_NOWAYOUT
413 WDIOF_SETTIMEOUT bit set in GETSUPPORT
415 wdt977.c -- Netwinder W83977AF chip
417 Hardcoded timeout of 3 minutes
419 Supports CONFIG_WATCHDOG_NOWAYOUT
421 Does not support any ioctls at all.