From nobody@FreeBSD.org  Sun Mar 25 02:28:05 2012
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 8E4FD106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Mar 2012 02:28:05 +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 78B9C8FC1E
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Mar 2012 02:28:05 +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 q2P2S5Ig023300
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Mar 2012 02:28:05 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q2P2S5Jp023299;
	Sun, 25 Mar 2012 02:28:05 GMT
	(envelope-from nobody)
Message-Id: <201203250228.q2P2S5Jp023299@red.freebsd.org>
Date: Sun, 25 Mar 2012 02:28:05 GMT
From: Brandon Gooch <jamesbrandongooch@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] snd_hda(4) is in a bad state after suspend/resume cycle
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         166382
>Category:       kern
>Synopsis:       [snd_hda] [patch] snd_hda(4) is in a bad state after suspend/resume cycle
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    mav
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Mar 25 02:30:10 UTC 2012
>Closed-Date:    Wed Apr 04 17:29:08 UTC 2012
>Last-Modified:  Wed Apr  4 17:30:08 UTC 2012
>Originator:     Brandon Gooch
>Release:        10.0-CURRENT
>Organization:
>Environment:
FreeBSD m6500.local 10.0-CURRENT FreeBSD 10.0-CURRENT #0 r233252: Tue Mar 20 19:36:33 CDT 2012     root@m6500.local:/usr/obj/usr/src/sys/DELL_M6500  amd64
>Description:
After an ACPI suspend/resume cycle, the snd_hda(4) driver may or may not play back sound. Adding a callout_stop(9) and callout_drain(9) for the poll callback in the suspend path allows the driver to reinit properly on resume.

Also, the (headphone) jack polling callback doesn't fire. The patch unconditionally calls callout_reset(9) for the jack poll callback, forcing the driver to reinit properly.

I'll bet that mav@ will have a few thoughts about this "patch"...
>How-To-Repeat:
Load snd_hda(4), or compile support for the device into the kernel. ACPI suspend, then resume the system. The driver will be in a bad state (fixable by reboot or kldunload/kldload-ing the kernel module).
>Fix:
Index: hdac.c
===================================================================
--- hdac.c	(revision 233252)
+++ hdac.c	(working copy)
@@ -1558,9 +1558,11 @@
 	HDA_BOOTHVERBOSE(
 		device_printf(dev, "Reset controller...\n");
 	);
+	callout_stop(&sc->poll_callout);
 	hdac_reset(sc, 0);
 	hdac_unlock(sc);
 	taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
+	callout_drain(&sc->poll_callout);
 	HDA_BOOTHVERBOSE(
 		device_printf(dev, "Suspend done\n");
 	);
Index: hdaa.c
===================================================================
--- hdaa.c	(revision 233252)
+++ hdaa.c	(working copy)
@@ -646,10 +646,8 @@
 			continue;
 		hdaa_eld_handler(w);
 	}
-	if (poll) {
-		callout_reset(&devinfo->poll_jack, 1,
-		    hdaa_jack_poll_callback, devinfo);
-	}
+	callout_reset(&devinfo->poll_jack, 1,
+	    hdaa_jack_poll_callback, devinfo);
 }
 
 static void


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mav 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Sun Mar 25 04:22:54 UTC 2012 
Responsible-Changed-Why:  
over to maintainer 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/166382: commit references a PR
Date: Wed, 28 Mar 2012 13:28:19 +0000 (UTC)

 Author: mav
 Date: Wed Mar 28 13:28:09 2012
 New Revision: 233606
 URL: http://svn.freebsd.org/changeset/base/233606
 
 Log:
   Stop HDA controller polling callout on suspend and reset it on resume.
   
   PR:		kern/166382
   MFC after:	1 week
 
 Modified:
   head/sys/dev/sound/pci/hda/hdac.c
 
 Modified: head/sys/dev/sound/pci/hda/hdac.c
 ==============================================================================
 --- head/sys/dev/sound/pci/hda/hdac.c	Wed Mar 28 12:46:12 2012	(r233605)
 +++ head/sys/dev/sound/pci/hda/hdac.c	Wed Mar 28 13:28:09 2012	(r233606)
 @@ -1558,8 +1558,10 @@ hdac_suspend(device_t dev)
  	HDA_BOOTHVERBOSE(
  		device_printf(dev, "Reset controller...\n");
  	);
 +	callout_stop(&sc->poll_callout);
  	hdac_reset(sc, 0);
  	hdac_unlock(sc);
 +	callout_drain(&sc->poll_callout);
  	taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
  	HDA_BOOTHVERBOSE(
  		device_printf(dev, "Suspend done\n");
 @@ -1608,6 +1610,7 @@ hdac_resume(device_t dev)
  	    HDAC_GCTL_UNSOL);
  	HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
  	DELAY(1000);
 +	hdac_poll_reinit(sc);
  	hdac_unlock(sc);
  
  	error = bus_generic_resume(dev);
 _______________________________________________
 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->patched 
State-Changed-By: mav 
State-Changed-When: Wed Mar 28 13:31:38 UTC 2012 
State-Changed-Why:  
Slightly different patch committed to HEAD at r233606. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/166382: commit references a PR
Date: Fri, 30 Mar 2012 08:33:22 +0000 (UTC)

 Author: mav
 Date: Fri Mar 30 08:33:08 2012
 New Revision: 233692
 URL: http://svn.freebsd.org/changeset/base/233692
 
 Log:
   Reenable unsolicited responses on CODEC if hdaa_sense_init() called again.
   This fixes jack connection events handling after suspend/resume.
   
   PR:		kern/166382
   MFC after:	1 week
 
 Modified:
   head/sys/dev/sound/pci/hda/hdaa.c
 
 Modified: head/sys/dev/sound/pci/hda/hdaa.c
 ==============================================================================
 --- head/sys/dev/sound/pci/hda/hdaa.c	Fri Mar 30 05:49:32 2012	(r233691)
 +++ head/sys/dev/sound/pci/hda/hdaa.c	Fri Mar 30 08:33:08 2012	(r233692)
 @@ -612,10 +612,11 @@ hdaa_sense_init(struct hdaa_devinfo *dev
  		if (w == NULL || w->enable == 0 || w->type !=
  		    HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
  			continue;
 -		if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap) &&
 -		    w->unsol < 0) {
 -			w->unsol = HDAC_UNSOL_ALLOC(
 -			    device_get_parent(devinfo->dev), devinfo->dev, w->nid);
 +		if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) {
 +			if (w->unsol < 0)
 +				w->unsol = HDAC_UNSOL_ALLOC(
 +				    device_get_parent(devinfo->dev),
 +				    devinfo->dev, w->nid);
  			hda_command(devinfo->dev,
  			    HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid,
  			    HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE | w->unsol));
 _______________________________________________
 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: Mark Linimon <linimon@lonesome.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/166382: [patch] snd_hda(4) is in a bad state after
 suspend/resume cycle
Date: Mon, 2 Apr 2012 01:27:06 -0500

 ----- Forwarded message from Brandon Gooch <jamesbrandongooch@gmail.com> -----
 
 Date: Wed, 28 Mar 2012 19:26:40 -0500
 From: Brandon Gooch <jamesbrandongooch@gmail.com>
 To: mav@freebsd.org, eadler@freebsd.org
 Cc: freebsd-bugs@freebsd.org
 Subject: Re: kern/166382: [patch] snd_hda(4) is in a bad state after
 	suspend/resume cycle
 
 Hey mav, thanks for taking a look and providing a patch!
 Unfortunately, it doesn't fix the suspend/resume issue  The headphone
 jack sense polling doesn't work after resume unless the callback is
 reinitialized.
 
 Does it hurt to reinit the callback in the case of both polling and
 non-polling configuartions?
 
 -Brandon
 
 ----- End forwarded message -----

From: Mark Linimon <linimon@lonesome.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/166382: [patch] snd_hda(4) is in a bad state after
 suspend/resume cycle
Date: Mon, 2 Apr 2012 01:27:33 -0500

 ----- Forwarded message from Brandon Gooch <jamesbrandongooch@gmail.com> -----
 
 Date: Thu, 29 Mar 2012 15:57:32 -0500
 From: Brandon Gooch <jamesbrandongooch@gmail.com>
 To: Alexander Motin <mav@freebsd.org>
 Cc: freebsd-bugs@freebsd.org, eadler@freebsd.org
 Subject: Re: kern/166382: [patch] snd_hda(4) is in a bad state after
 	suspend/resume cycle
 
 Yes, you're right about polling.  And, yes, this is the correct fix, thank you!
 
 -Brandon
 
 ----- End forwarded message -----
State-Changed-From-To: patched->closed 
State-Changed-By: mav 
State-Changed-When: Wed Apr 4 17:28:40 UTC 2012 
State-Changed-Why:  
Patches merged to 9-STABLE. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/166382: commit references a PR
Date: Wed,  4 Apr 2012 17:25:18 +0000 (UTC)

 Author: mav
 Date: Wed Apr  4 17:24:53 2012
 New Revision: 233878
 URL: http://svn.freebsd.org/changeset/base/233878
 
 Log:
   MFC r233606:
   Stop HDA controller polling callout on suspend and reset it on resume.
   
   PR:		kern/166382
 
 Modified:
   stable/9/sys/dev/sound/pci/hda/hdac.c
 Directory Properties:
   stable/9/sys/   (props changed)
 
 Modified: stable/9/sys/dev/sound/pci/hda/hdac.c
 ==============================================================================
 --- stable/9/sys/dev/sound/pci/hda/hdac.c	Wed Apr  4 16:15:40 2012	(r233877)
 +++ stable/9/sys/dev/sound/pci/hda/hdac.c	Wed Apr  4 17:24:53 2012	(r233878)
 @@ -1558,8 +1558,10 @@ hdac_suspend(device_t dev)
  	HDA_BOOTHVERBOSE(
  		device_printf(dev, "Reset controller...\n");
  	);
 +	callout_stop(&sc->poll_callout);
  	hdac_reset(sc, 0);
  	hdac_unlock(sc);
 +	callout_drain(&sc->poll_callout);
  	taskqueue_drain(taskqueue_thread, &sc->unsolq_task);
  	HDA_BOOTHVERBOSE(
  		device_printf(dev, "Suspend done\n");
 @@ -1608,6 +1610,7 @@ hdac_resume(device_t dev)
  	    HDAC_GCTL_UNSOL);
  	HDAC_WRITE_4(&sc->mem, HDAC_INTCTL, HDAC_INTCTL_CIE | HDAC_INTCTL_GIE);
  	DELAY(1000);
 +	hdac_poll_reinit(sc);
  	hdac_unlock(sc);
  
  	error = bus_generic_resume(dev);
 _______________________________________________
 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/166382: commit references a PR
Date: Wed,  4 Apr 2012 17:27:21 +0000 (UTC)

 Author: mav
 Date: Wed Apr  4 17:27:13 2012
 New Revision: 233879
 URL: http://svn.freebsd.org/changeset/base/233879
 
 Log:
   MFC r233692:
   Reenable unsolicited responses on CODEC if hdaa_sense_init() called again.
   This fixes jack connection events handling after suspend/resume.
   
   PR:		kern/166382
 
 Modified:
   stable/9/sys/dev/sound/pci/hda/hdaa.c
 Directory Properties:
   stable/9/sys/   (props changed)
 
 Modified: stable/9/sys/dev/sound/pci/hda/hdaa.c
 ==============================================================================
 --- stable/9/sys/dev/sound/pci/hda/hdaa.c	Wed Apr  4 17:24:53 2012	(r233878)
 +++ stable/9/sys/dev/sound/pci/hda/hdaa.c	Wed Apr  4 17:27:13 2012	(r233879)
 @@ -612,10 +612,11 @@ hdaa_sense_init(struct hdaa_devinfo *dev
  		if (w == NULL || w->enable == 0 || w->type !=
  		    HDA_PARAM_AUDIO_WIDGET_CAP_TYPE_PIN_COMPLEX)
  			continue;
 -		if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap) &&
 -		    w->unsol < 0) {
 -			w->unsol = HDAC_UNSOL_ALLOC(
 -			    device_get_parent(devinfo->dev), devinfo->dev, w->nid);
 +		if (HDA_PARAM_AUDIO_WIDGET_CAP_UNSOL_CAP(w->param.widget_cap)) {
 +			if (w->unsol < 0)
 +				w->unsol = HDAC_UNSOL_ALLOC(
 +				    device_get_parent(devinfo->dev),
 +				    devinfo->dev, w->nid);
  			hda_command(devinfo->dev,
  			    HDA_CMD_SET_UNSOLICITED_RESPONSE(0, w->nid,
  			    HDA_CMD_SET_UNSOLICITED_RESPONSE_ENABLE | w->unsol));
 _______________________________________________
 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"
 
>Unformatted:
