From nobody@FreeBSD.org  Sat Jul 21 23:48:45 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id B31EB106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 21 Jul 2012 23:48:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 9383C8FC14
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 21 Jul 2012 23:48:45 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q6LNmjmi084193
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 21 Jul 2012 23:48:45 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q6LNmjO9084188;
	Sat, 21 Jul 2012 23:48:45 GMT
	(envelope-from nobody)
Message-Id: <201207212348.q6LNmjO9084188@red.freebsd.org>
Date: Sat, 21 Jul 2012 23:48:45 GMT
From: Adrian Chadd <adrian@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [cbb] cardbus slot is not functioning correctly after a resume
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         170058
>Category:       kern
>Synopsis:       [cbb] [patch] cardbus slot is not functioning correctly after a resume
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 21 23:50:02 UTC 2012
>Closed-Date:    Tue Apr 22 05:29:34 UTC 2014
>Last-Modified:  Tue Apr 22 05:29:34 UTC 2014
>Originator:     Adrian Chadd
>Release:        9-STABLE
>Organization:
>Environment:
>Description:
There's a problem with the cbb device where it isn't correctly functioning after a suspend/resume cycle.

The main registers that are different are 0x18, 0x19, 0x1a - which are PCIR_PRIBUS_2, PCIR_SECBUS_2, PCIR_SUBBUS_2.

This is the register contents after a card is inserted and attached:


4c 10 56 ac 07 00 10 02  00 00 07 06 00 20 02 00 
00 00 30 e4 a0 00 00 22  15 16 17 20 00 00 31 e4 
00 f0 31 e4 00 f0 ff ff  00 00 00 00 fc ff ff ff 
00 00 00 00 fc ff ff ff  00 00 00 00 ff 01 00 04 
aa 17 12 20 01 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
70 d0 44 08 00 00 00 00  00 00 00 00 02 10 d0 01 
c0 03 64 40 00 00 00 00  00 00 00 00 00 00 00 00 
01 00 12 fe 00 80 c0 00  13 08 00 00 0f 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 

. and here it is after a suspend/resume:

4c 10 56 ac 07 00 10 02  00 00 07 06 00 20 02 00 
00 00 30 e4 a0 00 00 22  00 00 00 20 00 f0 ff ff 
00 00 00 00 00 f0 ff ff  00 00 00 00 fc ff ff ff 
00 00 00 00 fc ff ff ff  00 00 00 00 ff 01 00 07 
aa 17 12 20 01 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
70 f0 44 08 00 00 00 00  00 00 00 00 02 10 d0 01 
c0 03 64 40 00 00 00 00  00 00 00 00 00 00 00 00 
01 00 12 fe 00 80 c0 00  03 08 00 00 0f 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00 

>How-To-Repeat:

>Fix:
I've added something to the cbb code to work around this.

However, I wonder if the pci bridge code is the culprit. Ie, is pcib_cfg_restore() being called (via pcib_resume()) and writing garbage into the registers? I'm not sure.

It warrants further investigation!

Index: pccbb_pci.c
===================================================================
--- pccbb_pci.c	(revision 238210)
+++ pccbb_pci.c	(working copy)
@@ -457,6 +457,11 @@
 {
 	uint32_t mux, sysctrl, reg;
 
+	/*
+	 * Wake it up out of sleep
+	 */
+	cbb_powerstate_d0(sc->dev);
+
 	/* Set CardBus latency timer */
 	if (pci_read_config(sc->dev, PCIR_SECLAT_1, 1) < 0x20)
 		pci_write_config(sc->dev, PCIR_SECLAT_1, 0x20, 1);
@@ -465,6 +470,11 @@
 	if (pci_read_config(sc->dev, PCIR_LATTIMER, 1) < 0x20)
 		pci_write_config(sc->dev, PCIR_LATTIMER, 0x20, 1);
 
+	/* Restore bus configuration */
+	pci_write_config(sc->dev, PCIR_PRIBUS_2, sc->pribus, 1);
+	pci_write_config(sc->dev, PCIR_SECBUS_2, sc->secbus, 1);
+	pci_write_config(sc->dev, PCIR_SUBBUS_2, sc->subbus, 1);
+
 	/* Enable memory access */
 	PCI_MASK_CONFIG(sc->dev, PCIR_COMMAND,
 	    | PCIM_CMD_MEMEN



>Release-Note:
>Audit-Trail:

From: Mark Linimon <linimon@lonesome.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/170058: [cbb] cardbus slot is not functioning correctly
 after a resume
Date: Mon, 23 Jul 2012 05:14:13 -0500

 ----- Forwarded message from Warner Losh <imp@bsdimp.com> -----
 
 Date: Sat, 21 Jul 2012 23:41:35 -0600
 From: Warner Losh <imp@bsdimp.com>
 To: Adrian Chadd <adrian@FreeBSD.org>
 Cc: hackers@freebsd.org
 Subject: Re: kern/170058: [cbb] cardbus slot is not functioning correctly
 	after a resume
 
 On Jul 21, 2012, at 5:50 PM, Adrian Chadd wrote:
 
 > Hi all,
 > 
 > I found this in stable/9. I think it's also a problem in -HEAD.
 > 
 > Would someone with PCI bus clue take a look ?
 
 I'll be happy to look at it...  just as soon as I get a laptop that suspends/resumes with a cardbus slot to test it though...  I have  a couple that might work, but most of them don't suspend/resume right :(
 
 Warner
 _______________________________________________
 freebsd-hackers@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
 To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
 
 
 ----- End forwarded message -----

From: John Baldwin <jhb@freebsd.org>
To: bug-followup@freebsd.org,
 adrian@freebsd.org
Cc:  
Subject: Re: kern/170058: [cbb] [patch] cardbus slot is not functioning correctly after a resume
Date: Tue, 31 Jul 2012 10:56:49 -0400

 Your patch is probably close to correct.  You should not need the d0 bit for 
 the cbb device itself (the PCI bus should do that), but the PCI bus driver 
 only saves config register information for type 0 devices.  The PCI-PCI bridge 
 driver restores its config registers on its own, and cbb should do the same.
 
 -- 
 John Baldwin

From: Adrian Chadd <adrian@freebsd.org>
To: John Baldwin <jhb@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: kern/170058: [cbb] [patch] cardbus slot is not functioning
 correctly after a resume
Date: Tue, 31 Jul 2012 11:39:56 -0700

 On 31 July 2012 07:56, John Baldwin <jhb@freebsd.org> wrote:
 > Your patch is probably close to correct.  You should not need the d0 bit for
 > the cbb device itself (the PCI bus should do that), but the PCI bus driver
 > only saves config register information for type 0 devices.  The PCI-PCI bridge
 > driver restores its config registers on its own, and cbb should do the same.
 
 Ok, I'll commit this for -HEAD and MFC it to -9.
 
 Thanks,
 
 
 
 Adrian

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/170058: commit references a PR
Date: Tue, 31 Jul 2012 18:47:32 +0000 (UTC)

 Author: adrian
 Date: Tue Jul 31 18:47:17 2012
 New Revision: 238954
 URL: http://svn.freebsd.org/changeset/base/238954
 
 Log:
   Restore the PCI bridge configuration upon resume.
   
   This allows my TI1510 cardbus/PCI bridge to work after a suspend/resume,
   without having to unload/reload the cbb driver.
   
   I've also tested this on stable/9.  I'll MFC it shortly.
   
   PR:		kern/170058
   Reviewed by:	jhb
   MFC after:	1 day
 
 Modified:
   head/sys/dev/pccbb/pccbb_pci.c
 
 Modified: head/sys/dev/pccbb/pccbb_pci.c
 ==============================================================================
 --- head/sys/dev/pccbb/pccbb_pci.c	Tue Jul 31 18:44:10 2012	(r238953)
 +++ head/sys/dev/pccbb/pccbb_pci.c	Tue Jul 31 18:47:17 2012	(r238954)
 @@ -465,6 +465,11 @@ cbb_chipinit(struct cbb_softc *sc)
  	if (pci_read_config(sc->dev, PCIR_LATTIMER, 1) < 0x20)
  		pci_write_config(sc->dev, PCIR_LATTIMER, 0x20, 1);
  
 +	/* Restore bus configuration */
 +	pci_write_config(sc->dev, PCIR_PRIBUS_2, sc->pribus, 1);
 +	pci_write_config(sc->dev, PCIR_SECBUS_2, sc->secbus, 1);
 +	pci_write_config(sc->dev, PCIR_SUBBUS_2, sc->subbus, 1);
 +
  	/* Enable memory access */
  	PCI_MASK_CONFIG(sc->dev, PCIR_COMMAND,
  	    | PCIM_CMD_MEMEN
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/170058: commit references a PR
Date: Sun,  9 Sep 2012 20:13:33 +0000 (UTC)

 Author: adrian
 Date: Sun Sep  9 20:13:11 2012
 New Revision: 240287
 URL: http://svn.freebsd.org/changeset/base/240287
 
 Log:
   MFC r238954 - Restore the PCI bridge configuration upon resume.
   
   This allows my TI1510 cardbus/PCI bridge to work after a suspend/resume,
   without having to unload/reload the cbb driver.
   
   PR:		kern/170058
 
 Modified:
   stable/9/sys/dev/pccbb/pccbb_pci.c
 Directory Properties:
   stable/9/sys/   (props changed)
   stable/9/sys/dev/   (props changed)
 
 Modified: stable/9/sys/dev/pccbb/pccbb_pci.c
 ==============================================================================
 --- stable/9/sys/dev/pccbb/pccbb_pci.c	Sun Sep  9 20:00:00 2012	(r240286)
 +++ stable/9/sys/dev/pccbb/pccbb_pci.c	Sun Sep  9 20:13:11 2012	(r240287)
 @@ -465,6 +465,11 @@ cbb_chipinit(struct cbb_softc *sc)
  	if (pci_read_config(sc->dev, PCIR_LATTIMER, 1) < 0x20)
  		pci_write_config(sc->dev, PCIR_LATTIMER, 0x20, 1);
  
 +	/* Restore bus configuration */
 +	pci_write_config(sc->dev, PCIR_PRIBUS_2, sc->pribus, 1);
 +	pci_write_config(sc->dev, PCIR_SECBUS_2, sc->secbus, 1);
 +	pci_write_config(sc->dev, PCIR_SUBBUS_2, sc->subbus, 1);
 +
  	/* Enable memory access */
  	PCI_MASK_CONFIG(sc->dev, PCIR_COMMAND,
  	    | PCIM_CMD_MEMEN
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Tue Apr 22 05:29:10 UTC 2014 
State-Changed-Why:  
committed and MFCed in 2012. 

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