Blame view

drivers/watchdog/iTCO_vendor_support.c 11 KB
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
1
2
3
  /*
   *	intel TCO vendor specific watchdog driver support
   *
12d60e28b   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
4
   *	(c) Copyright 2006-2009 Wim Van Sebroeck <wim@iguana.be>.
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   *
   *	This program is free software; you can redistribute it and/or
   *	modify it under the terms of the GNU General Public License
   *	as published by the Free Software Foundation; either version
   *	2 of the License, or (at your option) any later version.
   *
   *	Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
   *	provide warranty for any of this software. This material is
   *	provided "AS-IS" and at no charge.
   */
  
  /*
   *	Includes, defines, variables, module parameters, ...
   */
  
  /* Module and version information */
7944d3a5a   Wim Van Sebroeck   [WATCHDOG] more c...
21
  #define DRV_NAME	"iTCO_vendor_support"
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
22
  #define DRV_VERSION	"1.04"
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
23
24
25
26
27
28
29
30
31
32
  #define PFX		DRV_NAME ": "
  
  /* Includes */
  #include <linux/module.h>		/* For module specific items */
  #include <linux/moduleparam.h>		/* For new moduleparam's */
  #include <linux/types.h>		/* For standard types (like size_t) */
  #include <linux/errno.h>		/* For the -ENODEV/... values */
  #include <linux/kernel.h>		/* For printk/panic/... */
  #include <linux/init.h>			/* For __init/__exit/... */
  #include <linux/ioport.h>		/* For io-port access */
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
33
34
35
  #include <linux/io.h>			/* For inb/outb/... */
  
  #include "iTCO_vendor.h"
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
36
37
  
  /* iTCO defines */
0a7e65822   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
38
39
40
  #define	SMI_EN		(acpibase + 0x30) /* SMI Control and Enable Register */
  #define	TCOBASE		(acpibase + 0x60) /* TCO base address */
  #define	TCO1_STS	(TCOBASE + 0x04)  /* TCO1 Status Register */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
41
42
  
  /* List of vendor support modes */
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
43
44
45
46
  /* SuperMicro Pentium 3 Era 370SSE+-OEM1/P3TSSE */
  #define SUPERMICRO_OLD_BOARD	1
  /* SuperMicro Pentium 4 / Xeon 4 / EMT64T Era Systems */
  #define SUPERMICRO_NEW_BOARD	2
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
47
48
  /* Broken BIOS */
  #define BROKEN_BIOS		911
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
49

0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
50
  static int vendorsupport;
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
51
  module_param(vendorsupport, int, 0);
143a2e54b   Wim Van Sebroeck   [WATCHDOG] More c...
52
  MODULE_PARM_DESC(vendorsupport, "iTCO vendor specific support mode, default="
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
53
54
  			"0 (none), 1=SuperMicro Pent3, 2=SuperMicro Pent4+, "
  							"911=Broken SMI BIOS");
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  
  /*
   *	Vendor Specific Support
   */
  
  /*
   *	Vendor Support: 1
   *	Board: Super Micro Computer Inc. 370SSE+-OEM1/P3TSSE
   *	iTCO chipset: ICH2
   *
   *	Code contributed by: R. Seretny <lkpatches@paypc.com>
   *	Documentation obtained by R. Seretny from SuperMicro Technical Support
   *
   *	To enable Watchdog function:
   *	    BIOS setup -> Power -> TCO Logic SMI Enable -> Within5Minutes
   *	    This setting enables SMI to clear the watchdog expired flag.
   *	    If BIOS or CPU fail which may cause SMI hang, then system will
   *	    reboot. When application starts to use watchdog function,
   *	    application has to take over the control from SMI.
   *
   *	    For P3TSSE, J36 jumper needs to be removed to enable the Watchdog
   *	    function.
   *
   *	    Note: The system will reboot when Expire Flag is set TWICE.
   *	    So, if the watchdog timer is 20 seconds, then the maximum hang
   *	    time is about 40 seconds, and the minimum hang time is about
   *	    20.6 seconds.
   */
12d60e28b   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  static void supermicro_old_pre_start(unsigned long acpibase)
  {
  	unsigned long val32;
  
  	/* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
  	val32 = inl(SMI_EN);
  	val32 &= 0xffffdfff;	/* Turn off SMI clearing watchdog */
  	outl(val32, SMI_EN);	/* Needed to activate watchdog */
  }
  
  static void supermicro_old_pre_stop(unsigned long acpibase)
  {
  	unsigned long val32;
  
  	/* Bit 13: TCO_EN -> 1 = Enables the TCO logic to generate SMI# */
  	val32 = inl(SMI_EN);
  	val32 |= 0x00002000;	/* Turn on SMI clearing watchdog */
  	outl(val32, SMI_EN);	/* Needed to deactivate watchdog */
  }
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  /*
   *	Vendor Support: 2
   *	Board: Super Micro Computer Inc. P4SBx, P4DPx
   *	iTCO chipset: ICH4
   *
   *	Code contributed by: R. Seretny <lkpatches@paypc.com>
   *	Documentation obtained by R. Seretny from SuperMicro Technical Support
   *
   *	To enable Watchdog function:
   *	 1. BIOS
   *	  For P4SBx:
   *	  BIOS setup -> Advanced -> Integrated Peripherals -> Watch Dog Feature
   *	  For P4DPx:
   *	  BIOS setup -> Advanced -> I/O Device Configuration -> Watch Dog
   *	 This setting enables or disables Watchdog function. When enabled, the
96de0e252   Jan Engelhardt   Convert files to ...
117
   *	 default watchdog timer is set to be 5 minutes (about 4m35s). It is
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
   *	 enough to load and run the OS. The application (service or driver) has
   *	 to take over the control once OS is running up and before watchdog
   *	 expires.
   *
   *	 2. JUMPER
   *	  For P4SBx: JP39
   *	  For P4DPx: JP37
   *	  This jumper is used for safety.  Closed is enabled. This jumper
   *	  prevents user enables watchdog in BIOS by accident.
   *
   *	 To enable Watch Dog function, both BIOS and JUMPER must be enabled.
   *
   *	The documentation lists motherboards P4SBx and P4DPx series as of
   *	20-March-2002. However, this code works flawlessly with much newer
   *	motherboards, such as my X6DHR-8G2 (SuperServer 6014H-82).
   *
   *	The original iTCO driver as written does not actually reset the
   *	watchdog timer on these machines, as a result they reboot after five
   *	minutes.
   *
   *	NOTE: You may leave the Watchdog function disabled in the SuperMicro
   *	BIOS to avoid a "boot-race"... This driver will enable watchdog
   *	functionality even if it's disabled in the BIOS once the /dev/watchdog
   *	file is opened.
   */
  
  /* I/O Port's */
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
145
146
  #define SM_REGINDEX	0x2e	/* SuperMicro ICH4+ Register Index */
  #define SM_DATAIO	0x2f	/* SuperMicro ICH4+ Register Data I/O */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
147
148
  
  /* Control Register's */
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
149
150
  #define SM_CTLPAGESW	0x07	/* SuperMicro ICH4+ Control Page Switch */
  #define SM_CTLPAGE	0x08	/* SuperMicro ICH4+ Control Page Num */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
151

0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
152
  #define SM_WATCHENABLE	0x30	/* Watchdog enable: Bit 0: 0=off, 1=on */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
153

0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
154
  #define SM_WATCHPAGE	0x87	/* Watchdog unlock control page */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
155

0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
156
  #define SM_ENDWATCH	0xAA	/* Watchdog lock control page */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
157

0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
158
159
  #define SM_COUNTMODE	0xf5	/* Watchdog count mode select */
  				/* (Bit 3: 0 = seconds, 1 = minutes */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
160

0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
161
  #define SM_WATCHTIMER	0xf6	/* 8-bits, Watchdog timer counter (RW) */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
162

0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
163
164
165
  #define SM_RESETCONTROL	0xf7	/* Watchdog reset control */
  				/* Bit 6: timer is reset by kbd interrupt */
  				/* Bit 7: timer is reset by mouse interrupt */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
166
167
168
  
  static void supermicro_new_unlock_watchdog(void)
  {
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
169
  	/* Write 0x87 to port 0x2e twice */
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
170
  	outb(SM_WATCHPAGE, SM_REGINDEX);
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
171
172
173
  	outb(SM_WATCHPAGE, SM_REGINDEX);
  	/* Switch to watchdog control page */
  	outb(SM_CTLPAGESW, SM_REGINDEX);
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  	outb(SM_CTLPAGE, SM_DATAIO);
  }
  
  static void supermicro_new_lock_watchdog(void)
  {
  	outb(SM_ENDWATCH, SM_REGINDEX);
  }
  
  static void supermicro_new_pre_start(unsigned int heartbeat)
  {
  	unsigned int val;
  
  	supermicro_new_unlock_watchdog();
  
  	/* Watchdog timer setting needs to be in seconds*/
  	outb(SM_COUNTMODE, SM_REGINDEX);
  	val = inb(SM_DATAIO);
  	val &= 0xF7;
  	outb(val, SM_DATAIO);
  
  	/* Write heartbeat interval to WDOG */
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
195
  	outb(SM_WATCHTIMER, SM_REGINDEX);
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
  	outb((heartbeat & 255), SM_DATAIO);
  
  	/* Make sure keyboard/mouse interrupts don't interfere */
  	outb(SM_RESETCONTROL, SM_REGINDEX);
  	val = inb(SM_DATAIO);
  	val &= 0x3f;
  	outb(val, SM_DATAIO);
  
  	/* enable watchdog by setting bit 0 of Watchdog Enable to 1 */
  	outb(SM_WATCHENABLE, SM_REGINDEX);
  	val = inb(SM_DATAIO);
  	val |= 0x01;
  	outb(val, SM_DATAIO);
  
  	supermicro_new_lock_watchdog();
  }
  
  static void supermicro_new_pre_stop(void)
  {
  	unsigned int val;
  
  	supermicro_new_unlock_watchdog();
  
  	/* disable watchdog by setting bit 0 of Watchdog Enable to 0 */
  	outb(SM_WATCHENABLE, SM_REGINDEX);
  	val = inb(SM_DATAIO);
  	val &= 0xFE;
  	outb(val, SM_DATAIO);
  
  	supermicro_new_lock_watchdog();
  }
  
  static void supermicro_new_pre_set_heartbeat(unsigned int heartbeat)
  {
  	supermicro_new_unlock_watchdog();
  
  	/* reset watchdog timeout to heartveat value */
  	outb(SM_WATCHTIMER, SM_REGINDEX);
  	outb((heartbeat & 255), SM_DATAIO);
  
  	supermicro_new_lock_watchdog();
  }
  
  /*
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
   *	Vendor Support: 911
   *	Board: Some Intel ICHx based motherboards
   *	iTCO chipset: ICH7+
   *
   *	Some Intel motherboards have a broken BIOS implementation: i.e.
   *	the SMI handler clear's the TIMEOUT bit in the TC01_STS register
   *	and does not reload the time. Thus the TCO watchdog does not reboot
   *	the system.
   *
   *	These are the conclusions of Andriy Gapon <avg@icyb.net.ua> after
   *	debugging: the SMI handler is quite simple - it tests value in
   *	TCO1_CNT against 0x800, i.e. checks TCO_TMR_HLT. If the bit is set
   *	the handler goes into an infinite loop, apparently to allow the
   *	second timeout and reboot. Otherwise it simply clears TIMEOUT bit
   *	in TCO1_STS and that's it.
   *	So the logic seems to be reversed, because it is hard to see how
   *	TIMEOUT can get set to 1 and SMI generated when TCO_TMR_HLT is set
   *	(other than a transitional effect).
   *
   *	The only fix found to get the motherboard(s) to reboot is to put
   *	the glb_smi_en bit to 0. This is a dirty hack that bypasses the
   *	broken code by disabling Global SMI.
   *
   *	WARNING: globally disabling SMI could possibly lead to dramatic
   *	problems, especially on laptops! I.e. various ACPI things where
   *	SMI is used for communication between OS and firmware.
   *
   *	Don't use this fix if you don't need to!!!
   */
  
  static void broken_bios_start(unsigned long acpibase)
  {
  	unsigned long val32;
  
  	val32 = inl(SMI_EN);
  	/* Bit 13: TCO_EN     -> 0 = Disables TCO logic generating an SMI#
  	   Bit  0: GBL_SMI_EN -> 0 = No SMI# will be generated by ICH. */
  	val32 &= 0xffffdffe;
  	outl(val32, SMI_EN);
  }
  
  static void broken_bios_stop(unsigned long acpibase)
  {
  	unsigned long val32;
  
  	val32 = inl(SMI_EN);
  	/* Bit 13: TCO_EN     -> 1 = Enables TCO logic generating an SMI#
  	   Bit  0: GBL_SMI_EN -> 1 = Turn global SMI on again. */
  	val32 |= 0x00002001;
  	outl(val32, SMI_EN);
  }
  
  /*
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
293
294
295
296
297
298
   *	Generic Support Functions
   */
  
  void iTCO_vendor_pre_start(unsigned long acpibase,
  			   unsigned int heartbeat)
  {
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
299
300
  	switch (vendorsupport) {
  	case SUPERMICRO_OLD_BOARD:
12d60e28b   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
301
  		supermicro_old_pre_start(acpibase);
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
302
303
  		break;
  	case SUPERMICRO_NEW_BOARD:
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
304
  		supermicro_new_pre_start(heartbeat);
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
305
306
307
308
309
  		break;
  	case BROKEN_BIOS:
  		broken_bios_start(acpibase);
  		break;
  	}
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
310
311
312
313
314
  }
  EXPORT_SYMBOL(iTCO_vendor_pre_start);
  
  void iTCO_vendor_pre_stop(unsigned long acpibase)
  {
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
315
316
  	switch (vendorsupport) {
  	case SUPERMICRO_OLD_BOARD:
12d60e28b   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
317
  		supermicro_old_pre_stop(acpibase);
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
318
319
  		break;
  	case SUPERMICRO_NEW_BOARD:
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
320
  		supermicro_new_pre_stop();
55e8ddece   Wim Van Sebroeck   [WATCHDOG] iTCO_w...
321
322
323
324
325
  		break;
  	case BROKEN_BIOS:
  		broken_bios_stop(acpibase);
  		break;
  	}
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
326
327
328
329
330
  }
  EXPORT_SYMBOL(iTCO_vendor_pre_stop);
  
  void iTCO_vendor_pre_keepalive(unsigned long acpibase, unsigned int heartbeat)
  {
7e6811daa   Pádraig Brady   iTCO_wdt: fix TCO...
331
  	if (vendorsupport == SUPERMICRO_NEW_BOARD)
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
332
333
334
335
336
337
338
339
340
341
342
343
344
  		supermicro_new_pre_set_heartbeat(heartbeat);
  }
  EXPORT_SYMBOL(iTCO_vendor_pre_keepalive);
  
  void iTCO_vendor_pre_set_heartbeat(unsigned int heartbeat)
  {
  	if (vendorsupport == SUPERMICRO_NEW_BOARD)
  		supermicro_new_pre_set_heartbeat(heartbeat);
  }
  EXPORT_SYMBOL(iTCO_vendor_pre_set_heartbeat);
  
  int iTCO_vendor_check_noreboot_on(void)
  {
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
345
  	switch (vendorsupport) {
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
346
347
348
349
350
351
352
353
354
355
  	case SUPERMICRO_OLD_BOARD:
  		return 0;
  	default:
  		return 1;
  	}
  }
  EXPORT_SYMBOL(iTCO_vendor_check_noreboot_on);
  
  static int __init iTCO_vendor_init_module(void)
  {
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
356
357
  	printk(KERN_INFO PFX "vendor-support=%d
  ", vendorsupport);
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
358
359
360
361
362
  	return 0;
  }
  
  static void __exit iTCO_vendor_exit_module(void)
  {
0e6fa3fb3   Alan Cox   [WATCHDOG 18/57] ...
363
364
  	printk(KERN_INFO PFX "Module Unloaded
  ");
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
365
366
367
368
  }
  
  module_init(iTCO_vendor_init_module);
  module_exit(iTCO_vendor_exit_module);
143a2e54b   Wim Van Sebroeck   [WATCHDOG] More c...
369
370
  MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>, "
  		"R. Seretny <lkpatches@paypc.com>");
e033351d5   Wim Van Sebroeck   [WATCHDOG] Add iT...
371
372
373
  MODULE_DESCRIPTION("Intel TCO Vendor Specific WatchDog Timer Driver Support");
  MODULE_VERSION(DRV_VERSION);
  MODULE_LICENSE("GPL");