From nobody@FreeBSD.org  Sat Oct 11 11:39:06 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 70FA51065692
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 11 Oct 2008 11:39:06 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 613358FC23
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 11 Oct 2008 11:39:06 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id m9BBd55i085301
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 11 Oct 2008 11:39:05 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id m9BBd5Sc085300;
	Sat, 11 Oct 2008 11:39:05 GMT
	(envelope-from nobody)
Message-Id: <200810111139.m9BBd5Sc085300@www.freebsd.org>
Date: Sat, 11 Oct 2008 11:39:05 GMT
From: Patrick Lamaiziere <patpr@davenulle.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: AMD Geode CS5536 watchdog(9) not disabled
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         128014
>Category:       i386
>Synopsis:       [geode] [patch] AMD Geode CS5536 watchdog(9) not disabled
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    phk
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Oct 11 11:40:00 UTC 2008
>Closed-Date:    Sat Sep 24 17:54:22 UTC 2011
>Last-Modified:  Sat Sep 24 17:54:22 UTC 2011
>Originator:     Patrick Lamaiziere
>Release:        8.0-CURRENT/i386
>Organization:
>Environment:
FreeBSD malpractice.lamaiziere.net 8.0-CURRENT FreeBSD 8.0-CURRENT #2: Fri Oct 10 11:19:40 CEST 2008     patrick@malpractice.lamaiziere.net:/usr/obj/usr/src/sys/NET5501  i386
>Description:
On the AMD Geode companion chipset CS5536 (by instance on a Soekris
Net5501), the hardware watchdog is implemented by a MFGPT timer. When
the timer has elapsed, the chipset does a hardware reset.

When the watchdog is disabled, the actual code (sys/i386/i386/geode.c)
does not stop the timer, only the the hardware reset is disabled. So if
the watchdog is enabled again after the timer has been elapsed, the
chipset does a reset and the box reboots immediatly.


>How-To-Repeat:
watchdog -t 16; watchdog -t 0
(wait a bit)
watchdog -t 16 => hardware reset


>Fix:
The attached patch stops and resets the timer when the watchdog is disabled and never disables the hardware reset - if the timer has elapsed it's too late - 

Patch attached with submission follows:

--- geode.c	2008-10-09 20:52:47.000000000 +0200
+++ /usr/src/sys/i386/i386/geode.c	2008-10-10 10:25:47.000000000 +0200
@@ -208,14 +208,11 @@
 static void
 cs5536_watchdog(void *foo __unused, u_int cmd, int *error)
 {
-	u_int u, p;
+	u_int u, p, s;
 	uint16_t a;
 	uint32_t m;
 
 	a = rdmsr(0x5140000d);
-	m = rdmsr(0x51400029);
-	m &= ~(1 << 24);
-	wrmsr(0x51400029, m);
 
 	u = cmd & WD_INTERVAL;
 	if (u >= 30 && u <= 44) {
@@ -228,12 +225,24 @@
 		/* reset counter */
 		outw(a + 4, 0);
 		/* Arm reset mechanism */
+		m = rdmsr(0x51400029);
 		m |= (1 << 24);
 		wrmsr(0x51400029, m);
 		/* Start counter */
 		outw(a + 6, 0x8000);
 
 		*error = 0;
+	} else {
+		/* 
+		 * MFGPT_SETUP is write-once
+		 * Check if the counter has been setup
+		 */
+		s = inw(a + 6);
+		if (s & (1 << 12)) {
+			/* Stop and reset counter */
+			outw(a + 6, 0);
+			outw(a + 4, 0);
+		}
 	}
 }
 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-i386 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Oct 12 22:30:57 UTC 2008 
Responsible-Changed-Why:  
This is i386-specific.  Also label it as having a patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=128014 

From: Patrick Lamaiziere <patfbsd@davenulle.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: i386/128014: [geode] [patch] AMD Geode CS5536 watchdog(9) not
 disabled
Date: Sun, 16 May 2010 20:08:05 +0200

 Hello,
 
 This issue has been patched on HEAD (thanks!):
 SVN rev 208111 on 2010-05-15 10:31:11Z by phk
 
 So, I think we can close this PR.
 Regards.
Responsible-Changed-From-To: freebsd-i386->phk 
Responsible-Changed-By: remko 
Responsible-Changed-When: Wed Jul 14 09:43:43 UTC 2010 
Responsible-Changed-Why:  
reassign to Poul-Henning as an MFC reminder. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=128014 
State-Changed-From-To: open->patched 
State-Changed-By: remko 
State-Changed-When: Wed Jul 14 09:44:05 UTC 2010 
State-Changed-Why:  
Set state to patched 

http://www.freebsd.org/cgi/query-pr.cgi?pr=128014 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Sat Sep 24 17:54:21 UTC 2011 
State-Changed-Why:  
This appears to be committed / MFCed already 

http://www.freebsd.org/cgi/query-pr.cgi?pr=128014 
>Unformatted:
