power management for btusb
Hi,
this implements very simple power management for btusb. Comments?
Regards
Oliver
---
drivers/bluetooth/btusb.c renamed from drivers/bluetooth/btusb.c.alt2 +80 -16
@@ -228,7 +228,7 @@ static void btusb_intr_complete(struct u } } -static int btusb_submit_intr_urb (struct hci_dev *hdev) +static int btusb_submit_intr_urb (struct hci_dev *hdev,gfp_t gfp) {struct btusb_data *data = hdev->driver_data;struct urb *urb;
@@ -241,13 +241,13 @@ static int btusb_submit_intr_urb(structif (!data->intr_ep)return -ENODEV ; - urb =usb_alloc_urb (0 ,GFP_ATOMIC ); + urb =usb_alloc_urb (0 , gfp);if (!urb)return -ENOMEM ; size =le16_to_cpu (data->intr_ep->wMaxPacketSize); - buf =kmalloc (size,GFP_ATOMIC ); + buf =kmalloc (size, gfp);if (!buf) {usb_free_urb (urb);return -ENOMEM ;
@@ -263,7 +263,7 @@ static int btusb_submit_intr_urb(structusb_anchor_urb (urb, &data->intr_anchor); - err =usb_submit_urb (urb,GFP_ATOMIC ); + err =usb_submit_urb (urb, gfp);if (err <0 ) {BT_ERR ("%s urb %p submission failed (%d)" , hdev->name, urb, -err);
@@ -312,7 +312,7 @@ static void btusb_bulk_complete(struct u } } -static int btusb_submit_bulk_urb (struct hci_dev *hdev) +static int btusb_submit_bulk_urb (struct hci_dev *hdev,gfp_t gfp) {struct btusb_data *data = hdev->driver_data;struct urb *urb;
@@ -325,13 +325,13 @@ static int btusb_submit_bulk_urb(structif (!data->bulk_rx_ep)return -ENODEV ; - urb =usb_alloc_urb (0 ,GFP_ATOMIC ); + urb =usb_alloc_urb (0 , gfp);if (!urb)return -ENOMEM ; size =le16_to_cpu (data->bulk_rx_ep->wMaxPacketSize); - buf =kmalloc (size,GFP_ATOMIC ); + buf =kmalloc (size, gfp);if (!buf) {usb_free_urb (urb);return -ENOMEM ;
@@ -346,7 +346,7 @@ static int btusb_submit_bulk_urb(structusb_anchor_urb (urb, &data->bulk_anchor); - err =usb_submit_urb (urb,GFP_ATOMIC ); + err =usb_submit_urb (urb, gfp);if (err <0 ) {BT_ERR ("%s urb %p submission failed (%d)" , hdev->name, urb, -err);
@@ -509,21 +509,32 @@ static int btusb_open(struct hci_dev *hdBT_DBG ("%s" , hdev->name); + err =usb_autopm_get_interface (data->acl); +if (err <0 ) +return err;if (test_and_set_bit (HCI_RUNNING , &hdev->flags))return 0 ;if (test_and_set_bit (BTUSB_INTR_RUNNING , &data->flags))return 0 ; - err =btusb_submit_intr_urb (hdev); + err =btusb_submit_intr_urb (hdev,GFP_ATOMIC );if (err <0 ) {clear_bit (BTUSB_INTR_RUNNING , &hdev->flags);clear_bit (HCI_RUNNING , &hdev->flags); +usb_autopm_put_interface (data->acl); }return err; } +static void btusb_stop_traffic (struct btusb_data *data) +{ +usb_kill_anchored_urbs (&data->intr_anchor); +usb_kill_anchored_urbs (&data->bulk_anchor); +usb_kill_anchored_urbs (&data->isoc_anchor); +} +static int btusb_close (struct hci_dev *hdev) {struct btusb_data *data = hdev->driver_data;
@@ -536,13 +547,10 @@ static int btusb_close(struct hci_dev *hflush_work (&data->work);clear_bit (BTUSB_ISOC_RUNNING , &data->flags); -usb_kill_anchored_urbs (&data->intr_anchor); -clear_bit (BTUSB_BULK_RUNNING , &data->flags); -usb_kill_anchored_urbs (&data->bulk_anchor); -clear_bit (BTUSB_INTR_RUNNING , &data->flags); -usb_kill_anchored_urbs (&data->intr_anchor); +btusb_stop_traffic (data); +usb_autopm_put_interface (data->acl);return 0 ; }
@@ -677,10 +685,10 @@ static void btusb_notify(struct hci_devif (hdev->conn_hash.acl_num >0 ) {if (!test_and_set_bit (BTUSB_BULK_RUNNING , &data->flags)) { -if (btusb_submit_bulk_urb (hdev) <0 ) +if (btusb_submit_bulk_urb (hdev,GFP_ATOMIC ) <0 )clear_bit (BTUSB_BULK_RUNNING , &data->flags);else -btusb_submit_bulk_urb (hdev); +btusb_submit_bulk_urb (hdev,GFP_ATOMIC ); } }else {clear_bit (BTUSB_BULK_RUNNING , &data->flags);
@@ -944,11 +952,67 @@ static void btusb_disconnect(struct usb_hci_free_dev (hdev); } +static int btusb_suspend (struct usb_interface *intf,pm_message_t message) +{ +struct btusb_data *data =usb_get_intfdata (intf); + +cancel_work_sync (&data->work); +btusb_stop_traffic (data); +usb_kill_anchored_urbs (&data->tx_anchor); +return 0 ; +} + +static int btusb_resume (struct usb_interface *intf) +{ +struct btusb_data *data =usb_get_intfdata (intf); +struct hci_dev *hdev = data->hdev; +int ret; + +if (test_bit (HCI_RUNNING , &hdev->flags)) { + ret =btusb_submit_intr_urb (hdev,GFP_NOIO ); +if (ret <0 ) { +clear_bit (HCI_RUNNING , &hdev->flags); +return ret; + } + } + +if (hdev->conn_hash.acl_num >0 ) { + ret =btusb_submit_bulk_urb (hdev,GFP_NOIO ); +if (ret <0 ) { +clear_bit (BTUSB_BULK_RUNNING , &data->flags); +return ret; + }else { + ret =btusb_submit_bulk_urb (hdev,GFP_NOIO ); +if (ret <0 ) { +clear_bit (BTUSB_BULK_RUNNING , &data->flags); +usb_kill_anchored_urbs (&data->bulk_anchor); +return ret; + } + } + } + +schedule_work (&data->work); +if (!data->isoc) +return 0 ; + +if (test_bit (BTUSB_ISOC_RUNNING , &data->flags)) { + ret =btusb_submit_isoc_urb (hdev); +if (ret <0 ) +clear_bit (BTUSB_ISOC_RUNNING , &data->flags); +else +btusb_submit_isoc_urb (hdev); + } +return 0 ; +} +static struct usb_driver btusb_driver = { .name ="btusb" , .probe = btusb_probe, .disconnect = btusb_disconnect, + .suspend = btusb_suspend, + .resume = btusb_resume, .id_table = btusb_table, + .supports_autosuspend =1 , };static int __init btusb_init (void )
Marcel Holtmann
maintainerHi Oliver,
Quoted 2 lines
this implements very simple power management for btusb. Comments?
looks a little but too much.
What are the semantics for usb_autopm_{get,put}_interface? Can we expect to always get a suspend() and resume() callback?
So in open(), do we have to actually start the interrupt URB or can we just wait for resume() to be happening?
I don't wanna misuse the *_RUNNING bits. They are only there to make sure that we non re-submit the URBs.
Regards
Marcel
Am Mittwoch 20 August 2008 12:18:04 schrieb Marcel Holtmann:
Quoted 6 lines
Hi Oliver,
Quoted 2 lines
this implements very simple power management for btusb. Comments?
looks a little but too much.
How so?
Quoted 2 lines
What are the semantics for usb_autopm_{get,put}_interface? Can we expect to always get a
suspend()andresume()callback?
usb_autopm_get_interface() guarantees that after it returns successsfully the interface (and teh device with it) remains unautosuspended until you call usb_autopm_put_interface. The calls stack with a counter.
You'll get a resume() callback only if the device was actually suspended.
Quoted 2 lines
So in
open(), do we have to actually start the interrupt URB or can we just wait forresume()to be happening?
We have to start the URB.
Quoted 2 lines
I don't wanna misuse the
*_RUNNINGbits. They are only there to make sure that we non re-submit the URBs.
Do you suggest making a copy of these bits at suspend() time?
Regards
Oliver
Marcel Holtmann
maintainerHi Oliver,
Quoted 8 lines
Quoted 2 lines
What are the semantics for usb_autopm_{get,put}_interface? Can we expect to always get a
suspend()andresume()callback?
usb_autopm_get_interface()guarantees that after it returns successsfully the interface (and teh device with it) remains unautosuspended until you callusb_autopm_put_interface. The calls stack with a counter.You'll get a
resume()callback only if the device was actually suspended.
so a device didn't start out suspended? Too bad, otherwise you could cut the logic in the driver a lot.
I tried to run this on my Quad G5, but I never see suspend() or resume() called. Do I have to do something to make autosuspend work?
Regards
Marcel
Am Mittwoch 20 August 2008 14:34:43 schrieb Marcel Holtmann:
Quoted 5 lines
Hi Oliver,
Quoted 3 lines
Quoted 2 lines
What are the semantics for usb_autopm_{get,put}_interface? Can we expect to always get a
suspend()andresume()callback?
Quoted 8 lines
Quoted 5 lines
usb_autopm_get_interface()guarantees that after it returns successsfully the interface (and teh device with it) remains unautosuspended until you callusb_autopm_put_interface. The calls stack with a counter.You'll get a
resume()callback only if the device was actually suspended.so a device didn't start out suspended? Too bad, otherwise you could cut the logic in the driver a lot.
Devices can have multiple interfaces. Therefore this guarantee is impossible.
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?
echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with CONFIG_USB_DEBUG
Regards
Oliver
Marcel Holtmann
maintainerHi Oliver,
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUG
I only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Regards
Marcel
Quoted 2 lines · ext Marcel Holtmann
I only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
CONFIG_USB_SUSPEND
Signature · 1 line
balbi
Am Mittwoch 20 August 2008 15:00:50 schrieb Marcel Holtmann:
Quoted 11 lines
Hi Oliver,
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUGI only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Probably CONFIG_USB_SUSPEND
HTH
Oliver
Marcel Holtmann
maintainerHi Oliver,
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUGI only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Probably
CONFIG_USB_SUSPEND
that one is on of course. Do you think it makes a difference that it is PowerPC system I am testing this with?
Regards
Marcel
Am Mittwoch 20 August 2008 15:05:54 schrieb Marcel Holtmann:
Quoted 9 lines
Hi Oliver,
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUG
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Probably
CONFIG_USB_SUSPENDthat one is on of course. Do you think it makes a difference that it is PowerPC system I am testing this with?
If it does make a difference, that's a bug. Runtime PM should work anyway.
Regards
Oliver
Marcel Holtmann
maintainerHi Oliver,
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUGI only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Probably
CONFIG_USB_SUSPENDthat one is on of course. Do you think it makes a difference that it is PowerPC system I am testing this with?
If it does make a difference, that's a bug. Runtime PM should work anyway.
I really don't see any calls to suspend() and I am missing the power/level option. This is the latest 2.6.27-rc3-git tree from Linus.
Regards
Marcel
Am Mittwoch 20 August 2008 15:13:04 schrieb Marcel Holtmann:
Quoted 14 lines
Hi Oliver,
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUGI only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Probably
CONFIG_USB_SUSPEND
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
that one is on of course. Do you think it makes a difference that it is PowerPC system I am testing this with?
If it does make a difference, that's a bug. Runtime PM should work anyway.
I really don't see any calls to
suspend()and I am missing the power/level option. This is the latest 2.6.27-rc3-git tree from Linus.
Odd. Send /proc/config.gz please.
Regards
Oliver
Marcel Holtmann
maintainerHi Oliver,
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUGI only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Probably
CONFIG_USB_SUSPENDthat one is on of course. Do you think it makes a difference that it is PowerPC system I am testing this with?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
If it does make a difference, that's a bug. Runtime PM should work anyway.
I really don't see any calls to
suspend()and I am missing the power/level option. This is the latest 2.6.27-rc3-git tree from Linus.Odd. Send
/proc/config.gzplease.
there you go. It is a nice Quad G5 machine.
Regards
Marcel
Am Mittwoch 20 August 2008 15:24:42 schrieb Marcel Holtmann:
Quoted 20 lines
Hi Oliver,
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUGQuoted 7 lines
Quoted 4 lines
Quoted 2 lines
I only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Probably
CONFIG_USB_SUSPENDthat one is on of course. Do you think it makes a difference that it is PowerPC system I am testing this with?
If it does make a difference, that's a bug. Runtime PM should work anyway.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I really don't see any calls to
suspend()and I am missing the power/level option. This is the latest 2.6.27-rc3-git tree from Linus.Odd. Send
/proc/config.gzplease.there you go. It is a nice Quad G5 machine.
That should work. Did you perhaps forget to remake your initrd?
Regards
Oliver
Marcel Holtmann
maintainerHi Oliver,
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUGQuoted 7 lines
Quoted 4 lines
Quoted 2 lines
I only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Probably
CONFIG_USB_SUSPENDthat one is on of course. Do you think it makes a difference that it is PowerPC system I am testing this with?
If it does make a difference, that's a bug. Runtime PM should work anyway.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
I really don't see any calls to
suspend()and I am missing the power/level option. This is the latest 2.6.27-rc3-git tree from Linus.Odd. Send
/proc/config.gzplease.there you go. It is a nice Quad G5 machine.
That should work. Did you perhaps forget to remake your initrd?
no initrd on this system.
Regards
Marcel
Am Mittwoch 20 August 2008 15:39:35 schrieb Marcel Holtmann:
Quoted 23 lines
Hi Oliver,
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUGI only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Probably
CONFIG_USB_SUSPENDthat one is on of course. Do you think it makes a difference that it is PowerPC system I am testing this with?
If it does make a difference, that's a bug. Runtime PM should work anyway.
I really don't see any calls to
suspend()and I am missing the power/level option. This is the latest 2.6.27-rc3-git tree from Linus.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Odd. Send
/proc/config.gzplease.there you go. It is a nice Quad G5 machine.
That should work. Did you perhaps forget to remake your initrd?
no initrd on this system.
It should work. Are you perhaps looking at the interface level as opposed to the device level?
Regards
Oliver
Marcel Holtmann
maintainerHi Oliver,
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I tried to run this on my Quad G5, but I never see
suspend()orresume()called. Do I have to do something to make autosuspend work?echo "auto" > $(directry in sysfs for device)/power/level And you'll see power events in syslog only if you compile with
CONFIG_USB_DEBUGI only seem to see power/wakeup entries. I don't have power/level. Am I missing some configuration option?
Probably
CONFIG_USB_SUSPENDQuoted 8 lines
Quoted 5 lines
Quoted 2 lines
that one is on of course. Do you think it makes a difference that it is PowerPC system I am testing this with?
If it does make a difference, that's a bug. Runtime PM should work anyway.
I really don't see any calls to
suspend()and I am missing the power/level option. This is the latest 2.6.27-rc3-git tree from Linus.Odd. Send
/proc/config.gzplease.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
there you go. It is a nice Quad G5 machine.
That should work. Did you perhaps forget to remake your initrd?
no initrd on this system.
It should work. Are you perhaps looking at the interface level as opposed to the device level?
finally I found the device and setting it to auto makes it actually suspend. Why is this not default? The driver has to enable it anyway.
Regards
Marcel
Am Mittwoch 20 August 2008 17:25:14 schrieb Marcel Holtmann:
Hi,
Quoted 2 lines
finally I found the device and setting it to auto makes it actually suspend. Why is this not default? The driver has to enable it anyway.
for too many class drivers some devices survive suspension and others crash. We don't want the lists of such devices in kernel space.
Regards
Oliver
Quoted 2 lines · Marcel Holtmann
finally I found the device and setting it to auto makes it actually suspend. Why is this not default? The driver has to enable it anyway.
If there's no driver then it would take effect right away. This causes problems for devices during startup -- the period of time from device discovery to driver binding is long enough (because there's so much other activity during bootup) that the device can autosuspend before the driver is there to prevent it.
For well-behaved devices this wouldn't matter. But unfortunately there are lots of devices which break when they suspend. That's why level = auto is not the default.
Alan Stern
Marcel Holtmann
maintainerHi Alan,
Quoted 9 lines
Quoted 2 lines
finally I found the device and setting it to auto makes it actually suspend. Why is this not default? The driver has to enable it anyway.
If there's no driver then it would take effect right away. This causes problems for devices during startup -- the period of time from device discovery to driver binding is long enough (because there's so much other activity during bootup) that the device can autosuspend before the driver is there to prevent it.
Quoted 3 lines
For well-behaved devices this wouldn't matter. But unfortunately there are lots of devices which break when they suspend. That's why level = auto is not the default.
is there any way to make it default if we know it works all the time?
Regards
Marcel
Quoted 11 lines · Marcel Holtmann
Hi Alan,
Quoted 9 lines
Quoted 2 lines
finally I found the device and setting it to auto makes it actually suspend. Why is this not default? The driver has to enable it anyway.
If there's no driver then it would take effect right away. This causes problems for devices during startup -- the period of time from device discovery to driver binding is long enough (because there's so much other activity during bootup) that the device can autosuspend before the driver is there to prevent it.
Quoted 5 lines
Quoted 3 lines
For well-behaved devices this wouldn't matter. But unfortunately there are lots of devices which break when they suspend. That's why level = auto is not the default.
is there any way to make it default if we know it works all the time?
No, probably not. But in general we don't know that. And we do know that a fair number of devices really are broken in this way -- lots of printers or scanners have this problem. Too many for us to want to keep a blacklist in the kernel, as Oliver mentioned.
The idea is that some desktop management program, like hal, should be able to recognize which devices can autosuspend safely and then enable them. That way the whole problem is pushed out to userspace. :-)
There is one exception: The kernel enables autosuspend automatically for hubs.
Alan Stern
Am Mittwoch 20 August 2008 17:55:23 schrieb Alan Stern:
Quoted 5 lines · Marcel Holtmann
Quoted 3 lines
is there any way to make it default if we know it works all the time?
Quoted 8 lines
No, probably not. But in general we don't know that. And we do know that a fair number of devices really are broken in this way -- lots of printers or scanners have this problem. Too many for us to want to keep a blacklist in the kernel, as Oliver mentioned.
The idea is that some desktop management program, like hal, should be able to recognize which devices can autosuspend safely and then enable them. That way the whole problem is pushed out to userspace. :-)
You could write a udev rule.
Regards
Oliver