iTCO_vendor_support.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /*
  2. * intel TCO vendor specific watchdog driver support
  3. *
  4. * (c) Copyright 2006-2009 Wim Van Sebroeck <wim@iguana.be>.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
  12. * provide warranty for any of this software. This material is
  13. * provided "AS-IS" and at no charge.
  14. */
  15. /*
  16. * Includes, defines, variables, module parameters, ...
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. /* Module and version information */
  20. #define DRV_NAME "iTCO_vendor_support"
  21. #define DRV_VERSION "1.04"
  22. /* Includes */
  23. #include <linux/module.h> /* For module specific items */
  24. #include <linux/moduleparam.h> /* For new moduleparam's */
  25. #include <linux/types.h> /* For standard types (like size_t) */
  26. #include <linux/errno.h> /* For the -ENODEV/... values */
  27. #include <linux/kernel.h> /* For printk/panic/... */
  28. #include <linux/init.h> /* For __init/__exit/... */
  29. #include <linux/ioport.h> /* For io-port access */
  30. #include <linux/io.h> /* For inb/outb/... */
  31. #include "iTCO_vendor.h"
  32. /* List of vendor support modes */
  33. /* SuperMicro Pentium 3 Era 370SSE+-OEM1/P3TSSE */
  34. #define SUPERMICRO_OLD_BOARD 1
  35. /* SuperMicro Pentium 4 / Xeon 4 / EMT64T Era Systems */
  36. #define SUPERMICRO_NEW_BOARD 2
  37. /* Broken BIOS */
  38. #define BROKEN_BIOS 911
  39. static int vendorsupport;
  40. module_param(vendorsupport, int, 0);
  41. MODULE_PARM_DESC(vendorsupport, "iTCO vendor specific support mode, default="
  42. "0 (none), 1=SuperMicro Pent3, 2=SuperMicro Pent4+, "
  43. "911=Broken SMI BIOS");
  44. /*
  45. * Vendor Specific Support
  46. */
  47. /*
  48. * Vendor Support: 1
  49. * Board: Super Micro Computer Inc. 370SSE+-OEM1/P3TSSE
  50. * iTCO chipset: ICH2
  51. *
  52. * Code contributed by: R. Seretny <lkpatches@paypc.com>
  53. * Documentation obtained by R. Seretny from SuperMicro Technical Support
  54. *
  55. * To enable Watchdog function:
  56. * BIOS setup -> Power -> TCO Logic SMI Enable -> Within5Minutes
  57. * This setting enables SMI to clear the watchdog expired flag.
  58. * If BIOS or CPU fail which may cause SMI hang, then system will
  59. * reboot. When application starts to use watchdog function,
  60. * application has to take over the control from SMI.
  61. *
  62. * For P3TSSE, J36 jumper needs to be removed to enable the Watchdog
  63. * function.
  64. *
  65. * Note: The system will reboot when Expire Flag is set TWICE.
  66. * So, if the watchdog timer is 20 seconds, then the maximum hang
  67. * time is about 40 seconds, and the minimum hang time is about
  68. * 20.6 seconds.
  69. */
  70. static void supermicro_old_pre_start(struct resource *smires)
  71. {
  72. unsigned long val32;
  73. /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
  74. val32 = inl(smires->start);
  75. val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
  76. outl(val32, smires->start); /* Needed to activate watchdog */
  77. }
  78. static void supermicro_old_pre_stop(struct resource *smires)
  79. {
  80. unsigned long val32;
  81. /* Bit 13: TCO_EN -> 1 = Enables the TCO logic to generate SMI# */
  82. val32 = inl(smires->start);
  83. val32 |= 0x00002000; /* Turn on SMI clearing watchdog */
  84. outl(val32, smires->start); /* Needed to deactivate watchdog */
  85. }
  86. /*
  87. * Vendor Support: 2
  88. * Board: Super Micro Computer Inc. P4SBx, P4DPx
  89. * iTCO chipset: ICH4
  90. *
  91. * Code contributed by: R. Seretny <lkpatches@paypc.com>
  92. * Documentation obtained by R. Seretny from SuperMicro Technical Support
  93. *
  94. * To enable Watchdog function:
  95. * 1. BIOS
  96. * For P4SBx:
  97. * BIOS setup -> Advanced -> Integrated Peripherals -> Watch Dog Feature
  98. * For P4DPx:
  99. * BIOS setup -> Advanced -> I/O Device Configuration -> Watch Dog
  100. * This setting enables or disables Watchdog function. When enabled, the
  101. * default watchdog timer is set to be 5 minutes (about 4m35s). It is
  102. * enough to load and run the OS. The application (service or driver) has
  103. * to take over the control once OS is running up and before watchdog
  104. * expires.
  105. *
  106. * 2. JUMPER
  107. * For P4SBx: JP39
  108. * For P4DPx: JP37
  109. * This jumper is used for safety. Closed is enabled. This jumper
  110. * prevents user enables watchdog in BIOS by accident.
  111. *
  112. * To enable Watch Dog function, both BIOS and JUMPER must be enabled.
  113. *
  114. * The documentation lists motherboards P4SBx and P4DPx series as of
  115. * 20-March-2002. However, this code works flawlessly with much newer
  116. * motherboards, such as my X6DHR-8G2 (SuperServer 6014H-82).
  117. *
  118. * The original iTCO driver as written does not actually reset the
  119. * watchdog timer on these machines, as a result they reboot after five
  120. * minutes.
  121. *
  122. * NOTE: You may leave the Watchdog function disabled in the SuperMicro
  123. * BIOS to avoid a "boot-race"... This driver will enable watchdog
  124. * functionality even if it's disabled in the BIOS once the /dev/watchdog
  125. * file is opened.
  126. */
  127. /* I/O Port's */
  128. #define SM_REGINDEX 0x2e /* SuperMicro ICH4+ Register Index */
  129. #define SM_DATAIO 0x2f /* SuperMicro ICH4+ Register Data I/O */
  130. /* Control Register's */
  131. #define SM_CTLPAGESW 0x07 /* SuperMicro ICH4+ Control Page Switch */
  132. #define SM_CTLPAGE 0x08 /* SuperMicro ICH4+ Control Page Num */
  133. #define SM_WATCHENABLE 0x30 /* Watchdog enable: Bit 0: 0=off, 1=on */
  134. #define SM_WATCHPAGE 0x87 /* Watchdog unlock control page */
  135. #define SM_ENDWATCH 0xAA /* Watchdog lock control page */
  136. #define SM_COUNTMODE 0xf5 /* Watchdog count mode select */
  137. /* (Bit 3: 0 = seconds, 1 = minutes */
  138. #define SM_WATCHTIMER 0xf6 /* 8-bits, Watchdog timer counter (RW) */
  139. #define SM_RESETCONTROL 0xf7 /* Watchdog reset control */
  140. /* Bit 6: timer is reset by kbd interrupt */
  141. /* Bit 7: timer is reset by mouse interrupt */
  142. static void supermicro_new_unlock_watchdog(void)
  143. {
  144. /* Write 0x87 to port 0x2e twice */
  145. outb(SM_WATCHPAGE, SM_REGINDEX);
  146. outb(SM_WATCHPAGE, SM_REGINDEX);
  147. /* Switch to watchdog control page */
  148. outb(SM_CTLPAGESW, SM_REGINDEX);
  149. outb(SM_CTLPAGE, SM_DATAIO);
  150. }
  151. static void supermicro_new_lock_watchdog(void)
  152. {
  153. outb(SM_ENDWATCH, SM_REGINDEX);
  154. }
  155. static void supermicro_new_pre_start(unsigned int heartbeat)
  156. {
  157. unsigned int val;
  158. supermicro_new_unlock_watchdog();
  159. /* Watchdog timer setting needs to be in seconds*/
  160. outb(SM_COUNTMODE, SM_REGINDEX);
  161. val = inb(SM_DATAIO);
  162. val &= 0xF7;
  163. outb(val, SM_DATAIO);
  164. /* Write heartbeat interval to WDOG */
  165. outb(SM_WATCHTIMER, SM_REGINDEX);
  166. outb((heartbeat & 255), SM_DATAIO);
  167. /* Make sure keyboard/mouse interrupts don't interfere */
  168. outb(SM_RESETCONTROL, SM_REGINDEX);
  169. val = inb(SM_DATAIO);
  170. val &= 0x3f;
  171. outb(val, SM_DATAIO);
  172. /* enable watchdog by setting bit 0 of Watchdog Enable to 1 */
  173. outb(SM_WATCHENABLE, SM_REGINDEX);
  174. val = inb(SM_DATAIO);
  175. val |= 0x01;
  176. outb(val, SM_DATAIO);
  177. supermicro_new_lock_watchdog();
  178. }
  179. static void supermicro_new_pre_stop(void)
  180. {
  181. unsigned int val;
  182. supermicro_new_unlock_watchdog();
  183. /* disable watchdog by setting bit 0 of Watchdog Enable to 0 */
  184. outb(SM_WATCHENABLE, SM_REGINDEX);
  185. val = inb(SM_DATAIO);
  186. val &= 0xFE;
  187. outb(val, SM_DATAIO);
  188. supermicro_new_lock_watchdog();
  189. }
  190. static void supermicro_new_pre_set_heartbeat(unsigned int heartbeat)
  191. {
  192. supermicro_new_unlock_watchdog();
  193. /* reset watchdog timeout to heartveat value */
  194. outb(SM_WATCHTIMER, SM_REGINDEX);
  195. outb((heartbeat & 255), SM_DATAIO);
  196. supermicro_new_lock_watchdog();
  197. }
  198. /*
  199. * Vendor Support: 911
  200. * Board: Some Intel ICHx based motherboards
  201. * iTCO chipset: ICH7+
  202. *
  203. * Some Intel motherboards have a broken BIOS implementation: i.e.
  204. * the SMI handler clear's the TIMEOUT bit in the TC01_STS register
  205. * and does not reload the time. Thus the TCO watchdog does not reboot
  206. * the system.
  207. *
  208. * These are the conclusions of Andriy Gapon <avg@icyb.net.ua> after
  209. * debugging: the SMI handler is quite simple - it tests value in
  210. * TCO1_CNT against 0x800, i.e. checks TCO_TMR_HLT. If the bit is set
  211. * the handler goes into an infinite loop, apparently to allow the
  212. * second timeout and reboot. Otherwise it simply clears TIMEOUT bit
  213. * in TCO1_STS and that's it.
  214. * So the logic seems to be reversed, because it is hard to see how
  215. * TIMEOUT can get set to 1 and SMI generated when TCO_TMR_HLT is set
  216. * (other than a transitional effect).
  217. *
  218. * The only fix found to get the motherboard(s) to reboot is to put
  219. * the glb_smi_en bit to 0. This is a dirty hack that bypasses the
  220. * broken code by disabling Global SMI.
  221. *
  222. * WARNING: globally disabling SMI could possibly lead to dramatic
  223. * problems, especially on laptops! I.e. various ACPI things where
  224. * SMI is used for communication between OS and firmware.
  225. *
  226. * Don't use this fix if you don't need to!!!
  227. */
  228. static void broken_bios_start(struct resource *smires)
  229. {
  230. unsigned long val32;
  231. val32 = inl(smires->start);
  232. /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI#
  233. Bit 0: GBL_SMI_EN -> 0 = No SMI# will be generated by ICH. */
  234. val32 &= 0xffffdffe;
  235. outl(val32, smires->start);
  236. }
  237. static void broken_bios_stop(struct resource *smires)
  238. {
  239. unsigned long val32;
  240. val32 = inl(smires->start);
  241. /* Bit 13: TCO_EN -> 1 = Enables TCO logic generating an SMI#
  242. Bit 0: GBL_SMI_EN -> 1 = Turn global SMI on again. */
  243. val32 |= 0x00002001;
  244. outl(val32, smires->start);
  245. }
  246. /*
  247. * Generic Support Functions
  248. */
  249. void iTCO_vendor_pre_start(struct resource *smires,
  250. unsigned int heartbeat)
  251. {
  252. switch (vendorsupport) {
  253. case SUPERMICRO_OLD_BOARD:
  254. supermicro_old_pre_start(smires);
  255. break;
  256. case SUPERMICRO_NEW_BOARD:
  257. supermicro_new_pre_start(heartbeat);
  258. break;
  259. case BROKEN_BIOS:
  260. broken_bios_start(smires);
  261. break;
  262. }
  263. }
  264. EXPORT_SYMBOL(iTCO_vendor_pre_start);
  265. void iTCO_vendor_pre_stop(struct resource *smires)
  266. {
  267. switch (vendorsupport) {
  268. case SUPERMICRO_OLD_BOARD:
  269. supermicro_old_pre_stop(smires);
  270. break;
  271. case SUPERMICRO_NEW_BOARD:
  272. supermicro_new_pre_stop();
  273. break;
  274. case BROKEN_BIOS:
  275. broken_bios_stop(smires);
  276. break;
  277. }
  278. }
  279. EXPORT_SYMBOL(iTCO_vendor_pre_stop);
  280. void iTCO_vendor_pre_keepalive(struct resource *smires, unsigned int heartbeat)
  281. {
  282. if (vendorsupport == SUPERMICRO_NEW_BOARD)
  283. supermicro_new_pre_set_heartbeat(heartbeat);
  284. }
  285. EXPORT_SYMBOL(iTCO_vendor_pre_keepalive);
  286. void iTCO_vendor_pre_set_heartbeat(unsigned int heartbeat)
  287. {
  288. if (vendorsupport == SUPERMICRO_NEW_BOARD)
  289. supermicro_new_pre_set_heartbeat(heartbeat);
  290. }
  291. EXPORT_SYMBOL(iTCO_vendor_pre_set_heartbeat);
  292. int iTCO_vendor_check_noreboot_on(void)
  293. {
  294. switch (vendorsupport) {
  295. case SUPERMICRO_OLD_BOARD:
  296. return 0;
  297. default:
  298. return 1;
  299. }
  300. }
  301. EXPORT_SYMBOL(iTCO_vendor_check_noreboot_on);
  302. static int __init iTCO_vendor_init_module(void)
  303. {
  304. pr_info("vendor-support=%d\n", vendorsupport);
  305. return 0;
  306. }
  307. static void __exit iTCO_vendor_exit_module(void)
  308. {
  309. pr_info("Module Unloaded\n");
  310. }
  311. module_init(iTCO_vendor_init_module);
  312. module_exit(iTCO_vendor_exit_module);
  313. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>, "
  314. "R. Seretny <lkpatches@paypc.com>");
  315. MODULE_DESCRIPTION("Intel TCO Vendor Specific WatchDog Timer Driver Support");
  316. MODULE_VERSION(DRV_VERSION);
  317. MODULE_LICENSE("GPL");