xref: /OK3568_Linux_fs/kernel/drivers/watchdog/iTCO_vendor_support.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0+
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *	intel TCO vendor specific watchdog driver support
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *	(c) Copyright 2006-2009 Wim Van Sebroeck <wim@iguana.be>.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  *	Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
8*4882a593Smuzhiyun  *	provide warranty for any of this software. This material is
9*4882a593Smuzhiyun  *	provided "AS-IS" and at no charge.
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /*
13*4882a593Smuzhiyun  *	Includes, defines, variables, module parameters, ...
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /* Module and version information */
19*4882a593Smuzhiyun #define DRV_NAME	"iTCO_vendor_support"
20*4882a593Smuzhiyun #define DRV_VERSION	"1.04"
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /* Includes */
23*4882a593Smuzhiyun #include <linux/module.h>		/* For module specific items */
24*4882a593Smuzhiyun #include <linux/moduleparam.h>		/* For new moduleparam's */
25*4882a593Smuzhiyun #include <linux/types.h>		/* For standard types (like size_t) */
26*4882a593Smuzhiyun #include <linux/errno.h>		/* For the -ENODEV/... values */
27*4882a593Smuzhiyun #include <linux/kernel.h>		/* For printk/panic/... */
28*4882a593Smuzhiyun #include <linux/init.h>			/* For __init/__exit/... */
29*4882a593Smuzhiyun #include <linux/ioport.h>		/* For io-port access */
30*4882a593Smuzhiyun #include <linux/io.h>			/* For inb/outb/... */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #include "iTCO_vendor.h"
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /* List of vendor support modes */
35*4882a593Smuzhiyun /* SuperMicro Pentium 3 Era 370SSE+-OEM1/P3TSSE */
36*4882a593Smuzhiyun #define SUPERMICRO_OLD_BOARD	1
37*4882a593Smuzhiyun /* SuperMicro Pentium 4 / Xeon 4 / EMT64T Era Systems - no longer supported */
38*4882a593Smuzhiyun #define SUPERMICRO_NEW_BOARD	2
39*4882a593Smuzhiyun /* Broken BIOS */
40*4882a593Smuzhiyun #define BROKEN_BIOS		911
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun int iTCO_vendorsupport;
43*4882a593Smuzhiyun EXPORT_SYMBOL(iTCO_vendorsupport);
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun module_param_named(vendorsupport, iTCO_vendorsupport, int, 0);
46*4882a593Smuzhiyun MODULE_PARM_DESC(vendorsupport, "iTCO vendor specific support mode, default="
47*4882a593Smuzhiyun 			"0 (none), 1=SuperMicro Pent3, 911=Broken SMI BIOS");
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /*
50*4882a593Smuzhiyun  *	Vendor Specific Support
51*4882a593Smuzhiyun  */
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /*
54*4882a593Smuzhiyun  *	Vendor Support: 1
55*4882a593Smuzhiyun  *	Board: Super Micro Computer Inc. 370SSE+-OEM1/P3TSSE
56*4882a593Smuzhiyun  *	iTCO chipset: ICH2
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  *	Code contributed by: R. Seretny <lkpatches@paypc.com>
59*4882a593Smuzhiyun  *	Documentation obtained by R. Seretny from SuperMicro Technical Support
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  *	To enable Watchdog function:
62*4882a593Smuzhiyun  *	    BIOS setup -> Power -> TCO Logic SMI Enable -> Within5Minutes
63*4882a593Smuzhiyun  *	    This setting enables SMI to clear the watchdog expired flag.
64*4882a593Smuzhiyun  *	    If BIOS or CPU fail which may cause SMI hang, then system will
65*4882a593Smuzhiyun  *	    reboot. When application starts to use watchdog function,
66*4882a593Smuzhiyun  *	    application has to take over the control from SMI.
67*4882a593Smuzhiyun  *
68*4882a593Smuzhiyun  *	    For P3TSSE, J36 jumper needs to be removed to enable the Watchdog
69*4882a593Smuzhiyun  *	    function.
70*4882a593Smuzhiyun  *
71*4882a593Smuzhiyun  *	    Note: The system will reboot when Expire Flag is set TWICE.
72*4882a593Smuzhiyun  *	    So, if the watchdog timer is 20 seconds, then the maximum hang
73*4882a593Smuzhiyun  *	    time is about 40 seconds, and the minimum hang time is about
74*4882a593Smuzhiyun  *	    20.6 seconds.
75*4882a593Smuzhiyun  */
76*4882a593Smuzhiyun 
supermicro_old_pre_start(struct resource * smires)77*4882a593Smuzhiyun static void supermicro_old_pre_start(struct resource *smires)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun 	unsigned long val32;
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	/* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
82*4882a593Smuzhiyun 	val32 = inl(smires->start);
83*4882a593Smuzhiyun 	val32 &= 0xffffdfff;	/* Turn off SMI clearing watchdog */
84*4882a593Smuzhiyun 	outl(val32, smires->start);	/* Needed to activate watchdog */
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun 
supermicro_old_pre_stop(struct resource * smires)87*4882a593Smuzhiyun static void supermicro_old_pre_stop(struct resource *smires)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun 	unsigned long val32;
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 	/* Bit 13: TCO_EN -> 1 = Enables the TCO logic to generate SMI# */
92*4882a593Smuzhiyun 	val32 = inl(smires->start);
93*4882a593Smuzhiyun 	val32 |= 0x00002000;	/* Turn on SMI clearing watchdog */
94*4882a593Smuzhiyun 	outl(val32, smires->start);	/* Needed to deactivate watchdog */
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun /*
98*4882a593Smuzhiyun  *	Vendor Support: 911
99*4882a593Smuzhiyun  *	Board: Some Intel ICHx based motherboards
100*4882a593Smuzhiyun  *	iTCO chipset: ICH7+
101*4882a593Smuzhiyun  *
102*4882a593Smuzhiyun  *	Some Intel motherboards have a broken BIOS implementation: i.e.
103*4882a593Smuzhiyun  *	the SMI handler clear's the TIMEOUT bit in the TC01_STS register
104*4882a593Smuzhiyun  *	and does not reload the time. Thus the TCO watchdog does not reboot
105*4882a593Smuzhiyun  *	the system.
106*4882a593Smuzhiyun  *
107*4882a593Smuzhiyun  *	These are the conclusions of Andriy Gapon <avg@icyb.net.ua> after
108*4882a593Smuzhiyun  *	debugging: the SMI handler is quite simple - it tests value in
109*4882a593Smuzhiyun  *	TCO1_CNT against 0x800, i.e. checks TCO_TMR_HLT. If the bit is set
110*4882a593Smuzhiyun  *	the handler goes into an infinite loop, apparently to allow the
111*4882a593Smuzhiyun  *	second timeout and reboot. Otherwise it simply clears TIMEOUT bit
112*4882a593Smuzhiyun  *	in TCO1_STS and that's it.
113*4882a593Smuzhiyun  *	So the logic seems to be reversed, because it is hard to see how
114*4882a593Smuzhiyun  *	TIMEOUT can get set to 1 and SMI generated when TCO_TMR_HLT is set
115*4882a593Smuzhiyun  *	(other than a transitional effect).
116*4882a593Smuzhiyun  *
117*4882a593Smuzhiyun  *	The only fix found to get the motherboard(s) to reboot is to put
118*4882a593Smuzhiyun  *	the glb_smi_en bit to 0. This is a dirty hack that bypasses the
119*4882a593Smuzhiyun  *	broken code by disabling Global SMI.
120*4882a593Smuzhiyun  *
121*4882a593Smuzhiyun  *	WARNING: globally disabling SMI could possibly lead to dramatic
122*4882a593Smuzhiyun  *	problems, especially on laptops! I.e. various ACPI things where
123*4882a593Smuzhiyun  *	SMI is used for communication between OS and firmware.
124*4882a593Smuzhiyun  *
125*4882a593Smuzhiyun  *	Don't use this fix if you don't need to!!!
126*4882a593Smuzhiyun  */
127*4882a593Smuzhiyun 
broken_bios_start(struct resource * smires)128*4882a593Smuzhiyun static void broken_bios_start(struct resource *smires)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun 	unsigned long val32;
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	val32 = inl(smires->start);
133*4882a593Smuzhiyun 	/* Bit 13: TCO_EN     -> 0 = Disables TCO logic generating an SMI#
134*4882a593Smuzhiyun 	   Bit  0: GBL_SMI_EN -> 0 = No SMI# will be generated by ICH. */
135*4882a593Smuzhiyun 	val32 &= 0xffffdffe;
136*4882a593Smuzhiyun 	outl(val32, smires->start);
137*4882a593Smuzhiyun }
138*4882a593Smuzhiyun 
broken_bios_stop(struct resource * smires)139*4882a593Smuzhiyun static void broken_bios_stop(struct resource *smires)
140*4882a593Smuzhiyun {
141*4882a593Smuzhiyun 	unsigned long val32;
142*4882a593Smuzhiyun 
143*4882a593Smuzhiyun 	val32 = inl(smires->start);
144*4882a593Smuzhiyun 	/* Bit 13: TCO_EN     -> 1 = Enables TCO logic generating an SMI#
145*4882a593Smuzhiyun 	   Bit  0: GBL_SMI_EN -> 1 = Turn global SMI on again. */
146*4882a593Smuzhiyun 	val32 |= 0x00002001;
147*4882a593Smuzhiyun 	outl(val32, smires->start);
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun /*
151*4882a593Smuzhiyun  *	Generic Support Functions
152*4882a593Smuzhiyun  */
153*4882a593Smuzhiyun 
iTCO_vendor_pre_start(struct resource * smires,unsigned int heartbeat)154*4882a593Smuzhiyun void iTCO_vendor_pre_start(struct resource *smires,
155*4882a593Smuzhiyun 			   unsigned int heartbeat)
156*4882a593Smuzhiyun {
157*4882a593Smuzhiyun 	switch (iTCO_vendorsupport) {
158*4882a593Smuzhiyun 	case SUPERMICRO_OLD_BOARD:
159*4882a593Smuzhiyun 		supermicro_old_pre_start(smires);
160*4882a593Smuzhiyun 		break;
161*4882a593Smuzhiyun 	case BROKEN_BIOS:
162*4882a593Smuzhiyun 		broken_bios_start(smires);
163*4882a593Smuzhiyun 		break;
164*4882a593Smuzhiyun 	}
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun EXPORT_SYMBOL(iTCO_vendor_pre_start);
167*4882a593Smuzhiyun 
iTCO_vendor_pre_stop(struct resource * smires)168*4882a593Smuzhiyun void iTCO_vendor_pre_stop(struct resource *smires)
169*4882a593Smuzhiyun {
170*4882a593Smuzhiyun 	switch (iTCO_vendorsupport) {
171*4882a593Smuzhiyun 	case SUPERMICRO_OLD_BOARD:
172*4882a593Smuzhiyun 		supermicro_old_pre_stop(smires);
173*4882a593Smuzhiyun 		break;
174*4882a593Smuzhiyun 	case BROKEN_BIOS:
175*4882a593Smuzhiyun 		broken_bios_stop(smires);
176*4882a593Smuzhiyun 		break;
177*4882a593Smuzhiyun 	}
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun EXPORT_SYMBOL(iTCO_vendor_pre_stop);
180*4882a593Smuzhiyun 
iTCO_vendor_check_noreboot_on(void)181*4882a593Smuzhiyun int iTCO_vendor_check_noreboot_on(void)
182*4882a593Smuzhiyun {
183*4882a593Smuzhiyun 	switch (iTCO_vendorsupport) {
184*4882a593Smuzhiyun 	case SUPERMICRO_OLD_BOARD:
185*4882a593Smuzhiyun 		return 0;
186*4882a593Smuzhiyun 	default:
187*4882a593Smuzhiyun 		return 1;
188*4882a593Smuzhiyun 	}
189*4882a593Smuzhiyun }
190*4882a593Smuzhiyun EXPORT_SYMBOL(iTCO_vendor_check_noreboot_on);
191*4882a593Smuzhiyun 
iTCO_vendor_init_module(void)192*4882a593Smuzhiyun static int __init iTCO_vendor_init_module(void)
193*4882a593Smuzhiyun {
194*4882a593Smuzhiyun 	if (iTCO_vendorsupport == SUPERMICRO_NEW_BOARD) {
195*4882a593Smuzhiyun 		pr_warn("Option vendorsupport=%d is no longer supported, "
196*4882a593Smuzhiyun 			"please use the w83627hf_wdt driver instead\n",
197*4882a593Smuzhiyun 			SUPERMICRO_NEW_BOARD);
198*4882a593Smuzhiyun 		return -EINVAL;
199*4882a593Smuzhiyun 	}
200*4882a593Smuzhiyun 	pr_info("vendor-support=%d\n", iTCO_vendorsupport);
201*4882a593Smuzhiyun 	return 0;
202*4882a593Smuzhiyun }
203*4882a593Smuzhiyun 
iTCO_vendor_exit_module(void)204*4882a593Smuzhiyun static void __exit iTCO_vendor_exit_module(void)
205*4882a593Smuzhiyun {
206*4882a593Smuzhiyun 	pr_info("Module Unloaded\n");
207*4882a593Smuzhiyun }
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun module_init(iTCO_vendor_init_module);
210*4882a593Smuzhiyun module_exit(iTCO_vendor_exit_module);
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>, "
213*4882a593Smuzhiyun 		"R. Seretny <lkpatches@paypc.com>");
214*4882a593Smuzhiyun MODULE_DESCRIPTION("Intel TCO Vendor Specific WatchDog Timer Driver Support");
215*4882a593Smuzhiyun MODULE_VERSION(DRV_VERSION);
216*4882a593Smuzhiyun MODULE_LICENSE("GPL");
217