/Documentation/watchdog/watchdog-api.txt

https://bitbucket.org/evzijst/gittest · Plain Text · 399 lines · 263 code · 136 blank · 0 comment · 0 complexity · 2401a8c24e14e4f6d79b10afd6e2f559 MD5 · raw file

  1. The Linux Watchdog driver API.
  2. Copyright 2002 Christer Weingel <wingel@nano-system.com>
  3. Some parts of this document are copied verbatim from the sbc60xxwdt
  4. driver which is (c) Copyright 2000 Jakob Oestergaard <jakob@ostenfeld.dk>
  5. This document describes the state of the Linux 2.4.18 kernel.
  6. Introduction:
  7. A Watchdog Timer (WDT) is a hardware circuit that can reset the
  8. computer system in case of a software fault. You probably knew that
  9. already.
  10. Usually a userspace daemon will notify the kernel watchdog driver via the
  11. /dev/watchdog special device file that userspace is still alive, at
  12. regular intervals. When such a notification occurs, the driver will
  13. usually tell the hardware watchdog that everything is in order, and
  14. that the watchdog should wait for yet another little while to reset
  15. the system. If userspace fails (RAM error, kernel bug, whatever), the
  16. notifications cease to occur, and the hardware watchdog will reset the
  17. system (causing a reboot) after the timeout occurs.
  18. The Linux watchdog API is a rather AD hoc construction and different
  19. drivers implement different, and sometimes incompatible, parts of it.
  20. This file is an attempt to document the existing usage and allow
  21. future driver writers to use it as a reference.
  22. The simplest API:
  23. All drivers support the basic mode of operation, where the watchdog
  24. activates as soon as /dev/watchdog is opened and will reboot unless
  25. the watchdog is pinged within a certain time, this time is called the
  26. timeout or margin. The simplest way to ping the watchdog is to write
  27. some data to the device. So a very simple watchdog daemon would look
  28. like this:
  29. int main(int argc, const char *argv[]) {
  30. int fd=open("/dev/watchdog",O_WRONLY);
  31. if (fd==-1) {
  32. perror("watchdog");
  33. exit(1);
  34. }
  35. while(1) {
  36. write(fd, "\0", 1);
  37. sleep(10);
  38. }
  39. }
  40. A more advanced driver could for example check that a HTTP server is
  41. still responding before doing the write call to ping the watchdog.
  42. When the device is closed, the watchdog is disabled. This is not
  43. always such a good idea, since if there is a bug in the watchdog
  44. daemon and it crashes the system will not reboot. Because of this,
  45. some of the drivers support the configuration option "Disable watchdog
  46. shutdown on close", CONFIG_WATCHDOG_NOWAYOUT. If it is set to Y when
  47. compiling the kernel, there is no way of disabling the watchdog once
  48. it has been started. So, if the watchdog dameon crashes, the system
  49. will reboot after the timeout has passed.
  50. Some other drivers will not disable the watchdog, unless a specific
  51. magic character 'V' has been sent /dev/watchdog just before closing
  52. the file. If the userspace daemon closes the file without sending
  53. this special character, the driver will assume that the daemon (and
  54. userspace in general) died, and will stop pinging the watchdog without
  55. disabling it first. This will then cause a reboot.
  56. The ioctl API:
  57. All conforming drivers also support an ioctl API.
  58. Pinging the watchdog using an ioctl:
  59. All drivers that have an ioctl interface support at least one ioctl,
  60. KEEPALIVE. This ioctl does exactly the same thing as a write to the
  61. watchdog device, so the main loop in the above program could be
  62. replaced with:
  63. while (1) {
  64. ioctl(fd, WDIOC_KEEPALIVE, 0);
  65. sleep(10);
  66. }
  67. the argument to the ioctl is ignored.
  68. Setting and getting the timeout:
  69. For some drivers it is possible to modify the watchdog timeout on the
  70. fly with the SETTIMEOUT ioctl, those drivers have the WDIOF_SETTIMEOUT
  71. flag set in their option field. The argument is an integer
  72. representing the timeout in seconds. The driver returns the real
  73. timeout used in the same variable, and this timeout might differ from
  74. the requested one due to limitation of the hardware.
  75. int timeout = 45;
  76. ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
  77. printf("The timeout was set to %d seconds\n", timeout);
  78. This example might actually print "The timeout was set to 60 seconds"
  79. if the device has a granularity of minutes for its timeout.
  80. Starting with the Linux 2.4.18 kernel, it is possible to query the
  81. current timeout using the GETTIMEOUT ioctl.
  82. ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
  83. printf("The timeout was is %d seconds\n", timeout);
  84. Envinronmental monitoring:
  85. All watchdog drivers are required return more information about the system,
  86. some do temperature, fan and power level monitoring, some can tell you
  87. the reason for the last reboot of the system. The GETSUPPORT ioctl is
  88. available to ask what the device can do:
  89. struct watchdog_info ident;
  90. ioctl(fd, WDIOC_GETSUPPORT, &ident);
  91. the fields returned in the ident struct are:
  92. identity a string identifying the watchdog driver
  93. firmware_version the firmware version of the card if available
  94. options a flags describing what the device supports
  95. the options field can have the following bits set, and describes what
  96. kind of information that the GET_STATUS and GET_BOOT_STATUS ioctls can
  97. return. [FIXME -- Is this correct?]
  98. WDIOF_OVERHEAT Reset due to CPU overheat
  99. The machine was last rebooted by the watchdog because the thermal limit was
  100. exceeded
  101. WDIOF_FANFAULT Fan failed
  102. A system fan monitored by the watchdog card has failed
  103. WDIOF_EXTERN1 External relay 1
  104. External monitoring relay/source 1 was triggered. Controllers intended for
  105. real world applications include external monitoring pins that will trigger
  106. a reset.
  107. WDIOF_EXTERN2 External relay 2
  108. External monitoring relay/source 2 was triggered
  109. WDIOF_POWERUNDER Power bad/power fault
  110. The machine is showing an undervoltage status
  111. WDIOF_CARDRESET Card previously reset the CPU
  112. The last reboot was caused by the watchdog card
  113. WDIOF_POWEROVER Power over voltage
  114. The machine is showing an overvoltage status. Note that if one level is
  115. under and one over both bits will be set - this may seem odd but makes
  116. sense.
  117. WDIOF_KEEPALIVEPING Keep alive ping reply
  118. The watchdog saw a keepalive ping since it was last queried.
  119. WDIOF_SETTIMEOUT Can set/get the timeout
  120. For those drivers that return any bits set in the option field, the
  121. GETSTATUS and GETBOOTSTATUS ioctls can be used to ask for the current
  122. status, and the status at the last reboot, respectively.
  123. int flags;
  124. ioctl(fd, WDIOC_GETSTATUS, &flags);
  125. or
  126. ioctl(fd, WDIOC_GETBOOTSTATUS, &flags);
  127. Note that not all devices support these two calls, and some only
  128. support the GETBOOTSTATUS call.
  129. Some drivers can measure the temperature using the GETTEMP ioctl. The
  130. returned value is the temperature in degrees farenheit.
  131. int temperature;
  132. ioctl(fd, WDIOC_GETTEMP, &temperature);
  133. Finally the SETOPTIONS ioctl can be used to control some aspects of
  134. the cards operation; right now the pcwd driver is the only one
  135. supporting thiss ioctl.
  136. int options = 0;
  137. ioctl(fd, WDIOC_SETOPTIONS, options);
  138. The following options are available:
  139. WDIOS_DISABLECARD Turn off the watchdog timer
  140. WDIOS_ENABLECARD Turn on the watchdog timer
  141. WDIOS_TEMPPANIC Kernel panic on temperature trip
  142. [FIXME -- better explanations]
  143. Implementations in the current drivers in the kernel tree:
  144. Here I have tried to summarize what the different drivers support and
  145. where they do strange things compared to the other drivers.
  146. acquirewdt.c -- Acquire Single Board Computer
  147. This driver has a hardcoded timeout of 1 minute
  148. Supports CONFIG_WATCHDOG_NOWAYOUT
  149. GETSUPPORT returns KEEPALIVEPING. GETSTATUS will return 1 if
  150. the device is open, 0 if not. [FIXME -- isn't this rather
  151. silly? To be able to use the ioctl, the device must be open
  152. and so GETSTATUS will always return 1].
  153. advantechwdt.c -- Advantech Single Board Computer
  154. Timeout that defaults to 60 seconds, supports SETTIMEOUT.
  155. Supports CONFIG_WATCHDOG_NOWAYOUT
  156. GETSUPPORT returns WDIOF_KEEPALIVEPING and WDIOF_SETTIMEOUT.
  157. The GETSTATUS call returns if the device is open or not.
  158. [FIXME -- silliness again?]
  159. eurotechwdt.c -- Eurotech CPU-1220/1410
  160. The timeout can be set using the SETTIMEOUT ioctl and defaults
  161. to 60 seconds.
  162. Also has a module parameter "ev", event type which controls
  163. what should happen on a timeout, the string "int" or anything
  164. else that causes a reboot. [FIXME -- better description]
  165. Supports CONFIG_WATCHDOG_NOWAYOUT
  166. GETSUPPORT returns CARDRESET and WDIOF_SETTIMEOUT but
  167. GETSTATUS is not supported and GETBOOTSTATUS just returns 0.
  168. i810-tco.c -- Intel 810 chipset
  169. Also has support for a lot of other i8x0 stuff, but the
  170. watchdog is one of the things.
  171. The timeout is set using the module parameter "i810_margin",
  172. which is in steps of 0.6 seconds where 2<i810_margin<64. The
  173. driver supports the SETTIMEOUT ioctl.
  174. Supports CONFIG_WATCHDOG_NOWAYOUT.
  175. GETSUPPORT returns WDIOF_SETTIMEOUT. The GETSTATUS call
  176. returns some kind of timer value which ist not compatible with
  177. the other drivers. GETBOOT status returns some kind of
  178. hardware specific boot status. [FIXME -- describe this]
  179. ib700wdt.c -- IB700 Single Board Computer
  180. Default timeout of 30 seconds and the timeout is settable
  181. using the SETTIMEOUT ioctl. Note that only a few timeout
  182. values are supported.
  183. Supports CONFIG_WATCHDOG_NOWAYOUT
  184. GETSUPPORT returns WDIOF_KEEPALIVEPING and WDIOF_SETTIMEOUT.
  185. The GETSTATUS call returns if the device is open or not.
  186. [FIXME -- silliness again?]
  187. machzwd.c -- MachZ ZF-Logic
  188. Hardcoded timeout of 10 seconds
  189. Has a module parameter "action" that controls what happens
  190. when the timeout runs out which can be 0 = RESET (default),
  191. 1 = SMI, 2 = NMI, 3 = SCI.
  192. Supports CONFIG_WATCHDOG_NOWAYOUT and the magic character
  193. 'V' close handling.
  194. GETSUPPORT returns WDIOF_KEEPALIVEPING, and the GETSTATUS call
  195. returns if the device is open or not. [FIXME -- silliness
  196. again?]
  197. mixcomwd.c -- MixCom Watchdog
  198. [FIXME -- I'm unable to tell what the timeout is]
  199. Supports CONFIG_WATCHDOG_NOWAYOUT
  200. GETSUPPORT returns WDIOF_KEEPALIVEPING, GETSTATUS returns if
  201. the device is opened or not [FIXME -- I'm not really sure how
  202. this works, there seems to be some magic connected to
  203. CONFIG_WATCHDOG_NOWAYOUT]
  204. pcwd.c -- Berkshire PC Watchdog
  205. Hardcoded timeout of 1.5 seconds
  206. Supports CONFIG_WATCHDOG_NOWAYOUT
  207. GETSUPPORT returns WDIOF_OVERHEAT|WDIOF_CARDRESET and both
  208. GETSTATUS and GETBOOTSTATUS return something useful.
  209. The SETOPTIONS call can be used to enable and disable the card
  210. and to ask the driver to call panic if the system overheats.
  211. sbc60xxwdt.c -- 60xx Single Board Computer
  212. Hardcoded timeout of 10 seconds
  213. Does not support CONFIG_WATCHDOG_NOWAYOUT, but has the magic
  214. character 'V' close handling.
  215. No bits set in GETSUPPORT
  216. scx200.c -- National SCx200 CPUs
  217. Not in the kernel yet.
  218. The timeout is set using a module parameter "margin" which
  219. defaults to 60 seconds. The timeout can also be set using
  220. SETTIMEOUT and read using GETTIMEOUT.
  221. Supports a module parameter "nowayout" that is initialized
  222. with the value of CONFIG_WATCHDOG_NOWAYOUT. Also supports the
  223. magic character 'V' handling.
  224. shwdt.c -- SuperH 3/4 processors
  225. [FIXME -- I'm unable to tell what the timeout is]
  226. Supports CONFIG_WATCHDOG_NOWAYOUT
  227. GETSUPPORT returns WDIOF_KEEPALIVEPING, and the GETSTATUS call
  228. returns if the device is open or not. [FIXME -- silliness
  229. again?]
  230. softdog.c -- Software watchdog
  231. The timeout is set with the module parameter "soft_margin"
  232. which defaults to 60 seconds, the timeout is also settable
  233. using the SETTIMEOUT ioctl.
  234. Supports CONFIG_WATCHDOG_NOWAYOUT
  235. WDIOF_SETTIMEOUT bit set in GETSUPPORT
  236. w83877f_wdt.c -- W83877F Computer
  237. Hardcoded timeout of 30 seconds
  238. Does not support CONFIG_WATCHDOG_NOWAYOUT, but has the magic
  239. character 'V' close handling.
  240. No bits set in GETSUPPORT
  241. w83627hf_wdt.c -- w83627hf watchdog
  242. Timeout that defaults to 60 seconds, supports SETTIMEOUT.
  243. Supports CONFIG_WATCHDOG_NOWAYOUT
  244. GETSUPPORT returns WDIOF_KEEPALIVEPING and WDIOF_SETTIMEOUT.
  245. The GETSTATUS call returns if the device is open or not.
  246. wdt.c -- ICS WDT500/501 ISA and
  247. wdt_pci.c -- ICS WDT500/501 PCI
  248. Default timeout of 60 seconds. The timeout is also settable
  249. using the SETTIMEOUT ioctl.
  250. Supports CONFIG_WATCHDOG_NOWAYOUT
  251. GETSUPPORT returns with bits set depending on the actual
  252. card. The WDT501 supports a lot of external monitoring, the
  253. WDT500 much less.
  254. wdt285.c -- Footbridge watchdog
  255. The timeout is set with the module parameter "soft_margin"
  256. which defaults to 60 seconds. The timeout is also settable
  257. using the SETTIMEOUT ioctl.
  258. Does not support CONFIG_WATCHDOG_NOWAYOUT
  259. WDIOF_SETTIMEOUT bit set in GETSUPPORT
  260. wdt977.c -- Netwinder W83977AF chip
  261. Hardcoded timeout of 3 minutes
  262. Supports CONFIG_WATCHDOG_NOWAYOUT
  263. Does not support any ioctls at all.