linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hci_usb: implement suspend/resume
@ 2006-01-17 23:21 Johannes Berg
  2006-01-18 13:13 ` Marcel Holtmann
  2006-01-18 13:25 ` Oliver Neukum
  0 siblings, 2 replies; 10+ messages in thread
From: Johannes Berg @ 2006-01-17 23:21 UTC (permalink / raw)
  To: marcel, maxk; +Cc: linux-kernel, bluez-devel

The attached patch implements suspend/resume for the hci_usb bluetooth
driver by simply killing all outstanding urbs on suspend, and re-issuing
them on resume.

This allows me to actually use the internal bluetooth "dongle" in my
powerbook after suspend-to-ram without taking down all userland programs
(sdpd, ...) and the hci device and reloading the module.

Signed-Off-By: Johannes Berg <johannes@sipsolutions.net>

--- linux-2.6.15.1.orig/drivers/bluetooth/hci_usb.c	2006-01-18 00:08:54.840000000 +0100
+++ linux-2.6.15.1/drivers/bluetooth/hci_usb.c	2006-01-18 00:06:35.080000000 +0100
@@ -1043,11 +1043,55 @@
 	hci_free_dev(hdev);
 }
 
+static int hci_usb_suspend(struct usb_interface *intf, pm_message_t message)
+{
+	struct hci_usb *husb = usb_get_intfdata(intf);
+	int i;
+	unsigned long flags;
+	if (!husb || intf == husb->isoc_iface)
+		return 0;
+	
+	for (i = 0; i < 4; i++) {
+		struct _urb_queue *q = &husb->pending_q[i];
+		struct _urb *_urb;
+		spin_lock_irqsave(&q->lock, flags);
+		list_for_each_entry(_urb, &q->head, list)
+			usb_kill_urb(&_urb->urb);
+		spin_unlock_irqrestore(&q->lock, flags);
+	}
+	return 0;
+}
+
+static int hci_usb_resume(struct usb_interface *intf)
+{
+	struct hci_usb *husb = usb_get_intfdata(intf);
+	int i, err;
+	unsigned long flags;
+	if (!husb || intf == husb->isoc_iface)
+		return 0;
+	
+	for (i = 0; i < 4; i++) {
+		struct _urb_queue *q = &husb->pending_q[i];
+		struct _urb *_urb;
+		spin_lock_irqsave(&q->lock, flags);
+		list_for_each_entry(_urb, &q->head, list) {
+			err = usb_submit_urb(&_urb->urb, GFP_ATOMIC);
+			if (err) break;
+		}
+		spin_unlock_irqrestore(&q->lock, flags);
+		if (err)
+			return -EIO;
+	}
+	return 0;
+}
+
 static struct usb_driver hci_usb_driver = {
 	.owner		= THIS_MODULE,
 	.name		= "hci_usb",
 	.probe		= hci_usb_probe,
 	.disconnect	= hci_usb_disconnect,
+	.suspend	= hci_usb_suspend,
+	.resume		= hci_usb_resume,
 	.id_table	= bluetooth_ids,
 };
 



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] hci_usb: implement suspend/resume
  2006-01-17 23:21 [PATCH] hci_usb: implement suspend/resume Johannes Berg
@ 2006-01-18 13:13 ` Marcel Holtmann
  2006-01-18 16:38   ` Johannes Berg
  2006-01-18 13:25 ` Oliver Neukum
  1 sibling, 1 reply; 10+ messages in thread
From: Marcel Holtmann @ 2006-01-18 13:13 UTC (permalink / raw)
  To: Johannes Berg; +Cc: maxk, linux-kernel, bluez-devel

Hi Johannes,

> The attached patch implements suspend/resume for the hci_usb bluetooth
> driver by simply killing all outstanding urbs on suspend, and re-issuing
> them on resume.
> 
> This allows me to actually use the internal bluetooth "dongle" in my
> powerbook after suspend-to-ram without taking down all userland programs
> (sdpd, ...) and the hci device and reloading the module.

thanks for the patch. Due to the removed owner field it won't apply
cleanly to 2.6.16-rc1, but I can fix this easily by myself.

> +static int hci_usb_resume(struct usb_interface *intf)
> +{
> +	struct hci_usb *husb = usb_get_intfdata(intf);
> +	int i, err;
> +	unsigned long flags;
> +	if (!husb || intf == husb->isoc_iface)
> +		return 0;
> +	
> +	for (i = 0; i < 4; i++) {
> +		struct _urb_queue *q = &husb->pending_q[i];
> +		struct _urb *_urb;
> +		spin_lock_irqsave(&q->lock, flags);
> +		list_for_each_entry(_urb, &q->head, list) {
> +			err = usb_submit_urb(&_urb->urb, GFP_ATOMIC);
> +			if (err) break;
> +		}
> +		spin_unlock_irqrestore(&q->lock, flags);
> +		if (err)
> +			return -EIO;
> +	}
> +	return 0;
> +}

What happens if hci_usb_resume() really returns -EIO? Do we have to kill
the URBs again or does the USB subsystems disconnect the device in this
case?

Regards

Marcel



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] hci_usb: implement suspend/resume
  2006-01-17 23:21 [PATCH] hci_usb: implement suspend/resume Johannes Berg
  2006-01-18 13:13 ` Marcel Holtmann
@ 2006-01-18 13:25 ` Oliver Neukum
  2006-01-18 14:13   ` Johannes Berg
  1 sibling, 1 reply; 10+ messages in thread
From: Oliver Neukum @ 2006-01-18 13:25 UTC (permalink / raw)
  To: Johannes Berg, linux-usb-devel; +Cc: marcel, maxk, linux-kernel, bluez-devel

Am Mittwoch, 18. Januar 2006 00:21 schrieb Johannes Berg:
> The attached patch implements suspend/resume for the hci_usb bluetooth
> driver by simply killing all outstanding urbs on suspend, and re-issuing
> them on resume.
> 
> This allows me to actually use the internal bluetooth "dongle" in my
> powerbook after suspend-to-ram without taking down all userland programs
> (sdpd, ...) and the hci device and reloading the module.
> 
> Signed-Off-By: Johannes Berg <johannes@sipsolutions.net>
> 
> --- linux-2.6.15.1.orig/drivers/bluetooth/hci_usb.c	2006-01-18 00:08:54.840000000 +0100
> +++ linux-2.6.15.1/drivers/bluetooth/hci_usb.c	2006-01-18 00:06:35.080000000 +0100
> @@ -1043,11 +1043,55 @@
>  	hci_free_dev(hdev);
>  }
>  
> +static int hci_usb_suspend(struct usb_interface *intf, pm_message_t message)
> +{
> +	struct hci_usb *husb = usb_get_intfdata(intf);
> +	int i;
> +	unsigned long flags;
> +	if (!husb || intf == husb->isoc_iface)
> +		return 0;
> +	
> +	for (i = 0; i < 4; i++) {
> +		struct _urb_queue *q = &husb->pending_q[i];
> +		struct _urb *_urb;
> +		spin_lock_irqsave(&q->lock, flags);
> +		list_for_each_entry(_urb, &q->head, list)
> +			usb_kill_urb(&_urb->urb);
> +		spin_unlock_irqrestore(&q->lock, flags);
> +	}
> +	return 0;

This patch is wrong. usb_kill_urb() will sleep. You must not use it under
a spinlock.

	Regards
		Oliver

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] hci_usb: implement suspend/resume
  2006-01-18 13:25 ` Oliver Neukum
@ 2006-01-18 14:13   ` Johannes Berg
  2006-01-18 15:34     ` Oliver Neukum
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2006-01-18 14:13 UTC (permalink / raw)
  To: Oliver Neukum; +Cc: linux-usb-devel, marcel, maxk, linux-kernel, bluez-devel

[-- Attachment #1: Type: text/plain, Size: 443 bytes --]

On Wed, 2006-01-18 at 14:25 +0100, Oliver Neukum wrote:

> This patch is wrong. usb_kill_urb() will sleep. You must not use it under
> a spinlock.

Whoops. Good catch. I'll have to analyse the logic with the lists being
used here (and probably add a temporary list). Will try to get a new
patch until tomorrow.

[side note: how about adding might_sleep() to usb_kill_urb? Then I'd at
least have noticed this right away]

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] hci_usb: implement suspend/resume
  2006-01-18 14:13   ` Johannes Berg
@ 2006-01-18 15:34     ` Oliver Neukum
  2006-01-18 20:46       ` [linux-usb-devel] " Greg KH
  0 siblings, 1 reply; 10+ messages in thread
From: Oliver Neukum @ 2006-01-18 15:34 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linux-usb-devel, marcel, maxk, linux-kernel, bluez-devel

Am Mittwoch, 18. Januar 2006 15:13 schrieb Johannes Berg:
> On Wed, 2006-01-18 at 14:25 +0100, Oliver Neukum wrote:
> 
> > This patch is wrong. usb_kill_urb() will sleep. You must not use it under
> > a spinlock.
> 
> Whoops. Good catch. I'll have to analyse the logic with the lists being
> used here (and probably add a temporary list). Will try to get a new
> patch until tomorrow.
> 
> [side note: how about adding might_sleep() to usb_kill_urb? Then I'd at
> least have noticed this right away]

Good idea.

	Regards
		Oliver

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] hci_usb: implement suspend/resume
  2006-01-18 13:13 ` Marcel Holtmann
@ 2006-01-18 16:38   ` Johannes Berg
  2006-03-21  9:42     ` Johannes Berg
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2006-01-18 16:38 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: maxk, linux-kernel, bluez-devel

The attached patch implements suspend/resume for the hci_usb bluetooth
driver by simply killing all outstanding urbs on suspend, and re-issuing
them on resume.

This allows me to actually use the internal bluetooth "dongle" in my
powerbook after suspend-to-ram without taking down all userland programs
(sdpd, ...) and the hci device and reloading the module.

Signed-Off-By: Johannes Berg <johannes@sipsolutions.net>

--- linux-2.6.git.orig/drivers/bluetooth/hci_usb.c
+++ linux-2.6.git/drivers/bluetooth/hci_usb.c
@@ -1043,10 +1043,65 @@
 	hci_free_dev(hdev);
 }
 
+static int hci_usb_suspend(struct usb_interface *intf, pm_message_t message)
+{
+	struct hci_usb *husb = usb_get_intfdata(intf);
+	int i;
+	unsigned long flags;
+	struct list_head killed;
+
+	if (!husb || intf == husb->isoc_iface)
+		return 0;
+
+	INIT_LIST_HEAD(&killed);
+
+	for (i = 0; i < 4; i++) {
+		struct _urb_queue *q = &husb->pending_q[i];
+		struct _urb *_urb, *_tmp;
+		while ((_urb = _urb_dequeue(q))) {
+			/* reset queue since _urb_dequeue sets it to NULL */
+			_urb->queue = q;
+			usb_kill_urb(&_urb->urb);
+			list_add(&_urb->list, &killed);
+		}
+		spin_lock_irqsave(&q->lock, flags);
+		list_for_each_entry_safe(_urb, _tmp, &killed, list) {
+			list_move_tail(&_urb->list, &q->head);
+		}
+		spin_unlock_irqrestore(&q->lock, flags);
+	}
+	return 0;
+}
+
+static int hci_usb_resume(struct usb_interface *intf)
+{
+	struct hci_usb *husb = usb_get_intfdata(intf);
+	int i, err = 0;
+	unsigned long flags;
+	if (!husb || intf == husb->isoc_iface)
+		return 0;
+	
+	for (i = 0; i < 4; i++) {
+		struct _urb_queue *q = &husb->pending_q[i];
+		struct _urb *_urb;
+		spin_lock_irqsave(&q->lock, flags);
+		list_for_each_entry(_urb, &q->head, list) {
+			err = usb_submit_urb(&_urb->urb, GFP_ATOMIC);
+			if (err) break;
+		}
+		spin_unlock_irqrestore(&q->lock, flags);
+		if (err)
+			return -EIO;
+	}
+	return 0;
+}
+
 static struct usb_driver hci_usb_driver = {
 	.name		= "hci_usb",
 	.probe		= hci_usb_probe,
 	.disconnect	= hci_usb_disconnect,
+	.suspend	= hci_usb_suspend,
+	.resume		= hci_usb_resume,
 	.id_table	= bluetooth_ids,
 };
 



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [linux-usb-devel] Re: [PATCH] hci_usb: implement suspend/resume
  2006-01-18 15:34     ` Oliver Neukum
@ 2006-01-18 20:46       ` Greg KH
  0 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2006-01-18 20:46 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: Johannes Berg, linux-usb-devel, marcel, maxk, linux-kernel, bluez-devel

On Wed, Jan 18, 2006 at 04:34:08PM +0100, Oliver Neukum wrote:
> Am Mittwoch, 18. Januar 2006 15:13 schrieb Johannes Berg:
> > On Wed, 2006-01-18 at 14:25 +0100, Oliver Neukum wrote:
> > 
> > > This patch is wrong. usb_kill_urb() will sleep. You must not use it under
> > > a spinlock.
> > 
> > Whoops. Good catch. I'll have to analyse the logic with the lists being
> > used here (and probably add a temporary list). Will try to get a new
> > patch until tomorrow.
> > 
> > [side note: how about adding might_sleep() to usb_kill_urb? Then I'd at
> > least have noticed this right away]
> 
> Good idea.

Done.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] hci_usb: implement suspend/resume
  2006-01-18 16:38   ` Johannes Berg
@ 2006-03-21  9:42     ` Johannes Berg
  2006-03-21  9:52       ` Marcel Holtmann
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2006-03-21  9:42 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: maxk, linux-kernel, bluez-devel

[-- Attachment #1: Type: text/plain, Size: 614 bytes --]

On Wed, 2006-01-18 at 19:39 +0100, Johannes Berg wrote:
> The attached patch implements suspend/resume for the hci_usb bluetooth
> driver by simply killing all outstanding urbs on suspend, and re-issuing
> them on resume.
> 
> This allows me to actually use the internal bluetooth "dongle" in my
> powerbook after suspend-to-ram without taking down all userland programs
> (sdpd, ...) and the hci device and reloading the module.

Can someone push this patch for 2.6.17 now that 2.6.16 is out? Or is
there still anything fundamentally wrong with it? I've been waiting for
it forever now ;)

johannes

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 793 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] hci_usb: implement suspend/resume
  2006-03-21  9:42     ` Johannes Berg
@ 2006-03-21  9:52       ` Marcel Holtmann
  2006-04-16 14:42         ` Johannes Berg
  0 siblings, 1 reply; 10+ messages in thread
From: Marcel Holtmann @ 2006-03-21  9:52 UTC (permalink / raw)
  To: Johannes Berg; +Cc: maxk, linux-kernel, bluez-devel

Hi Johannes,

> > The attached patch implements suspend/resume for the hci_usb bluetooth
> > driver by simply killing all outstanding urbs on suspend, and re-issuing
> > them on resume.
> > 
> > This allows me to actually use the internal bluetooth "dongle" in my
> > powerbook after suspend-to-ram without taking down all userland programs
> > (sdpd, ...) and the hci device and reloading the module.
> 
> Can someone push this patch for 2.6.17 now that 2.6.16 is out? Or is
> there still anything fundamentally wrong with it? I've been waiting for
> it forever now ;)

I will push it with some other small changes in the next few days.

Regards

Marcel



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] hci_usb: implement suspend/resume
  2006-03-21  9:52       ` Marcel Holtmann
@ 2006-04-16 14:42         ` Johannes Berg
  0 siblings, 0 replies; 10+ messages in thread
From: Johannes Berg @ 2006-04-16 14:42 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: maxk, linux-kernel, bluez-devel

On Tue, 2006-03-21 at 10:52 +0100, Marcel Holtmann wrote:

> I will push it with some other small changes in the next few days.

I don't see it yet, should I just post it instead?

johannes


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-04-16 14:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-17 23:21 [PATCH] hci_usb: implement suspend/resume Johannes Berg
2006-01-18 13:13 ` Marcel Holtmann
2006-01-18 16:38   ` Johannes Berg
2006-03-21  9:42     ` Johannes Berg
2006-03-21  9:52       ` Marcel Holtmann
2006-04-16 14:42         ` Johannes Berg
2006-01-18 13:25 ` Oliver Neukum
2006-01-18 14:13   ` Johannes Berg
2006-01-18 15:34     ` Oliver Neukum
2006-01-18 20:46       ` [linux-usb-devel] " Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).