blob: b6b2f90b5d443c85f08c10e7a68de0f1b25942f4 [file] [log] [blame]
Wim Van Sebroecke0333512006-11-12 18:05:09 +01001/*
2 * intel TCO vendor specific watchdog driver support
3 *
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +00004 * (c) Copyright 2006-2009 Wim Van Sebroeck <wim@iguana.be>.
Wim Van Sebroecke0333512006-11-12 18:05:09 +01005 *
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/*
17 * Includes, defines, variables, module parameters, ...
18 */
19
Joe Perches27c766a2012-02-15 15:06:19 -080020#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
Wim Van Sebroecke0333512006-11-12 18:05:09 +010022/* Module and version information */
Wim Van Sebroeck7944d3a2008-08-06 20:19:41 +000023#define DRV_NAME "iTCO_vendor_support"
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +000024#define DRV_VERSION "1.04"
Wim Van Sebroecke0333512006-11-12 18:05:09 +010025
26/* Includes */
27#include <linux/module.h> /* For module specific items */
28#include <linux/moduleparam.h> /* For new moduleparam's */
29#include <linux/types.h> /* For standard types (like size_t) */
30#include <linux/errno.h> /* For the -ENODEV/... values */
31#include <linux/kernel.h> /* For printk/panic/... */
32#include <linux/init.h> /* For __init/__exit/... */
33#include <linux/ioport.h> /* For io-port access */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010034#include <linux/io.h> /* For inb/outb/... */
35
36#include "iTCO_vendor.h"
Wim Van Sebroecke0333512006-11-12 18:05:09 +010037
Wim Van Sebroecke0333512006-11-12 18:05:09 +010038/* List of vendor support modes */
Alan Cox0e6fa3f2008-05-19 14:06:25 +010039/* SuperMicro Pentium 3 Era 370SSE+-OEM1/P3TSSE */
40#define SUPERMICRO_OLD_BOARD 1
41/* SuperMicro Pentium 4 / Xeon 4 / EMT64T Era Systems */
42#define SUPERMICRO_NEW_BOARD 2
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +000043/* Broken BIOS */
44#define BROKEN_BIOS 911
Wim Van Sebroecke0333512006-11-12 18:05:09 +010045
Alan Cox0e6fa3f2008-05-19 14:06:25 +010046static int vendorsupport;
Wim Van Sebroecke0333512006-11-12 18:05:09 +010047module_param(vendorsupport, int, 0);
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +000048MODULE_PARM_DESC(vendorsupport, "iTCO vendor specific support mode, default="
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +000049 "0 (none), 1=SuperMicro Pent3, 2=SuperMicro Pent4+, "
50 "911=Broken SMI BIOS");
Wim Van Sebroecke0333512006-11-12 18:05:09 +010051
52/*
53 * Vendor Specific Support
54 */
55
56/*
57 * Vendor Support: 1
58 * Board: Super Micro Computer Inc. 370SSE+-OEM1/P3TSSE
59 * iTCO chipset: ICH2
60 *
61 * Code contributed by: R. Seretny <lkpatches@paypc.com>
62 * Documentation obtained by R. Seretny from SuperMicro Technical Support
63 *
64 * To enable Watchdog function:
65 * BIOS setup -> Power -> TCO Logic SMI Enable -> Within5Minutes
66 * This setting enables SMI to clear the watchdog expired flag.
67 * If BIOS or CPU fail which may cause SMI hang, then system will
68 * reboot. When application starts to use watchdog function,
69 * application has to take over the control from SMI.
70 *
71 * For P3TSSE, J36 jumper needs to be removed to enable the Watchdog
72 * function.
73 *
74 * Note: The system will reboot when Expire Flag is set TWICE.
75 * So, if the watchdog timer is 20 seconds, then the maximum hang
76 * time is about 40 seconds, and the minimum hang time is about
77 * 20.6 seconds.
78 */
79
Aaron Sierra887c8ec2012-04-20 14:14:11 -050080static void supermicro_old_pre_start(struct resource *smires)
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +000081{
82 unsigned long val32;
83
84 /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
Aaron Sierra887c8ec2012-04-20 14:14:11 -050085 val32 = inl(smires->start);
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +000086 val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
Aaron Sierra887c8ec2012-04-20 14:14:11 -050087 outl(val32, smires->start); /* Needed to activate watchdog */
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +000088}
89
Aaron Sierra887c8ec2012-04-20 14:14:11 -050090static void supermicro_old_pre_stop(struct resource *smires)
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +000091{
92 unsigned long val32;
93
94 /* Bit 13: TCO_EN -> 1 = Enables the TCO logic to generate SMI# */
Aaron Sierra887c8ec2012-04-20 14:14:11 -050095 val32 = inl(smires->start);
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +000096 val32 |= 0x00002000; /* Turn on SMI clearing watchdog */
Aaron Sierra887c8ec2012-04-20 14:14:11 -050097 outl(val32, smires->start); /* Needed to deactivate watchdog */
Wim Van Sebroeck12d60e22009-01-28 20:51:04 +000098}
99
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100100/*
101 * Vendor Support: 2
102 * Board: Super Micro Computer Inc. P4SBx, P4DPx
103 * iTCO chipset: ICH4
104 *
105 * Code contributed by: R. Seretny <lkpatches@paypc.com>
106 * Documentation obtained by R. Seretny from SuperMicro Technical Support
107 *
108 * To enable Watchdog function:
109 * 1. BIOS
110 * For P4SBx:
111 * BIOS setup -> Advanced -> Integrated Peripherals -> Watch Dog Feature
112 * For P4DPx:
113 * BIOS setup -> Advanced -> I/O Device Configuration -> Watch Dog
114 * This setting enables or disables Watchdog function. When enabled, the
Jan Engelhardt96de0e22007-10-19 23:21:04 +0200115 * default watchdog timer is set to be 5 minutes (about 4m35s). It is
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100116 * enough to load and run the OS. The application (service or driver) has
117 * to take over the control once OS is running up and before watchdog
118 * expires.
119 *
120 * 2. JUMPER
121 * For P4SBx: JP39
122 * For P4DPx: JP37
123 * This jumper is used for safety. Closed is enabled. This jumper
124 * prevents user enables watchdog in BIOS by accident.
125 *
126 * To enable Watch Dog function, both BIOS and JUMPER must be enabled.
127 *
128 * The documentation lists motherboards P4SBx and P4DPx series as of
129 * 20-March-2002. However, this code works flawlessly with much newer
130 * motherboards, such as my X6DHR-8G2 (SuperServer 6014H-82).
131 *
132 * The original iTCO driver as written does not actually reset the
133 * watchdog timer on these machines, as a result they reboot after five
134 * minutes.
135 *
136 * NOTE: You may leave the Watchdog function disabled in the SuperMicro
137 * BIOS to avoid a "boot-race"... This driver will enable watchdog
138 * functionality even if it's disabled in the BIOS once the /dev/watchdog
139 * file is opened.
140 */
141
142/* I/O Port's */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100143#define SM_REGINDEX 0x2e /* SuperMicro ICH4+ Register Index */
144#define SM_DATAIO 0x2f /* SuperMicro ICH4+ Register Data I/O */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100145
146/* Control Register's */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100147#define SM_CTLPAGESW 0x07 /* SuperMicro ICH4+ Control Page Switch */
148#define SM_CTLPAGE 0x08 /* SuperMicro ICH4+ Control Page Num */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100149
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100150#define SM_WATCHENABLE 0x30 /* Watchdog enable: Bit 0: 0=off, 1=on */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100151
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100152#define SM_WATCHPAGE 0x87 /* Watchdog unlock control page */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100153
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100154#define SM_ENDWATCH 0xAA /* Watchdog lock control page */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100155
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100156#define SM_COUNTMODE 0xf5 /* Watchdog count mode select */
157 /* (Bit 3: 0 = seconds, 1 = minutes */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100158
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100159#define SM_WATCHTIMER 0xf6 /* 8-bits, Watchdog timer counter (RW) */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100160
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100161#define SM_RESETCONTROL 0xf7 /* Watchdog reset control */
162 /* Bit 6: timer is reset by kbd interrupt */
163 /* Bit 7: timer is reset by mouse interrupt */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100164
165static void supermicro_new_unlock_watchdog(void)
166{
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100167 /* Write 0x87 to port 0x2e twice */
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100168 outb(SM_WATCHPAGE, SM_REGINDEX);
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100169 outb(SM_WATCHPAGE, SM_REGINDEX);
170 /* Switch to watchdog control page */
171 outb(SM_CTLPAGESW, SM_REGINDEX);
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100172 outb(SM_CTLPAGE, SM_DATAIO);
173}
174
175static void supermicro_new_lock_watchdog(void)
176{
177 outb(SM_ENDWATCH, SM_REGINDEX);
178}
179
180static void supermicro_new_pre_start(unsigned int heartbeat)
181{
182 unsigned int val;
183
184 supermicro_new_unlock_watchdog();
185
186 /* Watchdog timer setting needs to be in seconds*/
187 outb(SM_COUNTMODE, SM_REGINDEX);
188 val = inb(SM_DATAIO);
189 val &= 0xF7;
190 outb(val, SM_DATAIO);
191
192 /* Write heartbeat interval to WDOG */
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100193 outb(SM_WATCHTIMER, SM_REGINDEX);
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100194 outb((heartbeat & 255), SM_DATAIO);
195
196 /* Make sure keyboard/mouse interrupts don't interfere */
197 outb(SM_RESETCONTROL, SM_REGINDEX);
198 val = inb(SM_DATAIO);
199 val &= 0x3f;
200 outb(val, SM_DATAIO);
201
202 /* enable watchdog by setting bit 0 of Watchdog Enable to 1 */
203 outb(SM_WATCHENABLE, SM_REGINDEX);
204 val = inb(SM_DATAIO);
205 val |= 0x01;
206 outb(val, SM_DATAIO);
207
208 supermicro_new_lock_watchdog();
209}
210
211static void supermicro_new_pre_stop(void)
212{
213 unsigned int val;
214
215 supermicro_new_unlock_watchdog();
216
217 /* disable watchdog by setting bit 0 of Watchdog Enable to 0 */
218 outb(SM_WATCHENABLE, SM_REGINDEX);
219 val = inb(SM_DATAIO);
220 val &= 0xFE;
221 outb(val, SM_DATAIO);
222
223 supermicro_new_lock_watchdog();
224}
225
226static void supermicro_new_pre_set_heartbeat(unsigned int heartbeat)
227{
228 supermicro_new_unlock_watchdog();
229
230 /* reset watchdog timeout to heartveat value */
231 outb(SM_WATCHTIMER, SM_REGINDEX);
232 outb((heartbeat & 255), SM_DATAIO);
233
234 supermicro_new_lock_watchdog();
235}
236
237/*
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000238 * Vendor Support: 911
239 * Board: Some Intel ICHx based motherboards
240 * iTCO chipset: ICH7+
241 *
242 * Some Intel motherboards have a broken BIOS implementation: i.e.
243 * the SMI handler clear's the TIMEOUT bit in the TC01_STS register
244 * and does not reload the time. Thus the TCO watchdog does not reboot
245 * the system.
246 *
247 * These are the conclusions of Andriy Gapon <avg@icyb.net.ua> after
248 * debugging: the SMI handler is quite simple - it tests value in
249 * TCO1_CNT against 0x800, i.e. checks TCO_TMR_HLT. If the bit is set
250 * the handler goes into an infinite loop, apparently to allow the
251 * second timeout and reboot. Otherwise it simply clears TIMEOUT bit
252 * in TCO1_STS and that's it.
253 * So the logic seems to be reversed, because it is hard to see how
254 * TIMEOUT can get set to 1 and SMI generated when TCO_TMR_HLT is set
255 * (other than a transitional effect).
256 *
257 * The only fix found to get the motherboard(s) to reboot is to put
258 * the glb_smi_en bit to 0. This is a dirty hack that bypasses the
259 * broken code by disabling Global SMI.
260 *
261 * WARNING: globally disabling SMI could possibly lead to dramatic
262 * problems, especially on laptops! I.e. various ACPI things where
263 * SMI is used for communication between OS and firmware.
264 *
265 * Don't use this fix if you don't need to!!!
266 */
267
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500268static void broken_bios_start(struct resource *smires)
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000269{
270 unsigned long val32;
271
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500272 val32 = inl(smires->start);
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000273 /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI#
274 Bit 0: GBL_SMI_EN -> 0 = No SMI# will be generated by ICH. */
275 val32 &= 0xffffdffe;
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500276 outl(val32, smires->start);
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000277}
278
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500279static void broken_bios_stop(struct resource *smires)
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000280{
281 unsigned long val32;
282
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500283 val32 = inl(smires->start);
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000284 /* Bit 13: TCO_EN -> 1 = Enables TCO logic generating an SMI#
285 Bit 0: GBL_SMI_EN -> 1 = Turn global SMI on again. */
286 val32 |= 0x00002001;
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500287 outl(val32, smires->start);
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000288}
289
290/*
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100291 * Generic Support Functions
292 */
293
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500294void iTCO_vendor_pre_start(struct resource *smires,
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100295 unsigned int heartbeat)
296{
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000297 switch (vendorsupport) {
298 case SUPERMICRO_OLD_BOARD:
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500299 supermicro_old_pre_start(smires);
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000300 break;
301 case SUPERMICRO_NEW_BOARD:
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100302 supermicro_new_pre_start(heartbeat);
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000303 break;
304 case BROKEN_BIOS:
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500305 broken_bios_start(smires);
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000306 break;
307 }
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100308}
309EXPORT_SYMBOL(iTCO_vendor_pre_start);
310
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500311void iTCO_vendor_pre_stop(struct resource *smires)
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100312{
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000313 switch (vendorsupport) {
314 case SUPERMICRO_OLD_BOARD:
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500315 supermicro_old_pre_stop(smires);
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000316 break;
317 case SUPERMICRO_NEW_BOARD:
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100318 supermicro_new_pre_stop();
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000319 break;
320 case BROKEN_BIOS:
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500321 broken_bios_stop(smires);
Wim Van Sebroeck55e8dde2009-06-08 17:41:51 +0000322 break;
323 }
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100324}
325EXPORT_SYMBOL(iTCO_vendor_pre_stop);
326
Aaron Sierra887c8ec2012-04-20 14:14:11 -0500327void iTCO_vendor_pre_keepalive(struct resource *smires, unsigned int heartbeat)
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100328{
Pádraig Brady7e6811d2010-04-19 13:38:25 +0100329 if (vendorsupport == SUPERMICRO_NEW_BOARD)
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100330 supermicro_new_pre_set_heartbeat(heartbeat);
331}
332EXPORT_SYMBOL(iTCO_vendor_pre_keepalive);
333
334void iTCO_vendor_pre_set_heartbeat(unsigned int heartbeat)
335{
336 if (vendorsupport == SUPERMICRO_NEW_BOARD)
337 supermicro_new_pre_set_heartbeat(heartbeat);
338}
339EXPORT_SYMBOL(iTCO_vendor_pre_set_heartbeat);
340
341int iTCO_vendor_check_noreboot_on(void)
342{
Alan Cox0e6fa3f2008-05-19 14:06:25 +0100343 switch (vendorsupport) {
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100344 case SUPERMICRO_OLD_BOARD:
345 return 0;
346 default:
347 return 1;
348 }
349}
350EXPORT_SYMBOL(iTCO_vendor_check_noreboot_on);
351
352static int __init iTCO_vendor_init_module(void)
353{
Joe Perches27c766a2012-02-15 15:06:19 -0800354 pr_info("vendor-support=%d\n", vendorsupport);
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100355 return 0;
356}
357
358static void __exit iTCO_vendor_exit_module(void)
359{
Joe Perches27c766a2012-02-15 15:06:19 -0800360 pr_info("Module Unloaded\n");
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100361}
362
363module_init(iTCO_vendor_init_module);
364module_exit(iTCO_vendor_exit_module);
365
Wim Van Sebroeck143a2e52009-03-18 08:35:09 +0000366MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>, "
367 "R. Seretny <lkpatches@paypc.com>");
Wim Van Sebroecke0333512006-11-12 18:05:09 +0100368MODULE_DESCRIPTION("Intel TCO Vendor Specific WatchDog Timer Driver Support");
369MODULE_VERSION(DRV_VERSION);
370MODULE_LICENSE("GPL");
371