Bluetooth: btusb: Avoid unnecessary reset upon system resume
Subsystems (2)
Hi Abhishek,
Quoted 77 lines · Abhishek Pandit-Subedi
+ Alex Lu (who contributed the original change)
Hi Kai-Heng,
Quoted 6 lines · Kai-Heng Feng
[+Cc linux-usb]
Hi Abhishek,
Quoted 1 line
On Sep 24, 2020, at 04:41, Abhishek Pandit-Subedi
Quoted 8 lines · <[email protected]> wrote:
Quoted 4 lines
Hi Kai-Heng,
Which Realtek controller is this on?'
The issue happens on 8821CE.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Specifically for RTL8822CE, we tested without
reset_resumebeing set and that was causing the controller being reset without bluez ever learning about it (resulting in devices being unusable without toggling the BT power).The reset is done by the kernel, so how does that affect bluez?
From what you described, it sounds more like runtime resume since bluez
is already running.
Quoted 1 line
If we need reset resume for runtime resume, maybe it's another bug
which needs to be addressed?
From
btusb.c:
https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-
next.git/tree/drivers/bluetooth/btusb.c#n4189
/* Realtek devices lose their updated firmware over global
* suspend that means host doesn't sendSET_FEATURE
* (DEVICE_REMOTE_WAKEUP)
*/Runtime suspend always requires remote wakeup to be set and reset resume isn't used there.
During system suspend, when remote wakeup is not set, RTL8822CE loses the FW loaded by the driver and any state currently in the controller. This causes the kernel and the controller state to go out of sync. One of the issues we observed on the Realtek controller without the reset resume quirk was that paired or connected devices would just stop working after resume.
Quoted 5 lines
Quoted 3 lines
If the firmware doesn't cut off power during suspend, maybe you shouldn't set the
BTUSB_WAKEUP_DISABLEflag for that controller.We don't know beforehand if the platform firmware (BIOS for my case) will
cut power off or not.
Quoted 3 lines
In general, laptops will cut off the USB power during S3. When AC is plugged, some laptops cuts USB power off and some don't. This
also applies to many desktops. Not to mention there can be BIOS options to control USB power under S3/S4/S5...
Quoted 3 lines
So we don't know beforehand.
I think the confusion here stems from what is actually being turned off between our two boards and what we're referring to as firmware :)
In your case, the Realtek controller retains firmware unless the platform cuts of power to USB (which it does during S3). In my case, the Realtek controller loses firmware when Remote Wakeup isn't set, even if the platform doesn't cut power to USB.
Quoted 9 lines
In your case, since you don't need to enforce the 'Remote Wakeup' bit, if you unset the
BTUSB_WAKEUP_DISABLEfor that VID:PID, you should get the desirable behavior (which is actually the default behavior; remote wake will always be asserted instead of only during Runtime Suspend).@Alex -- What is the common behavior for Realtek controllers? Should we set
BTUSB_WAKEUP_DISABLEonly on RTL8822CE or should we unset it only on RTL8821CE?
According to the feedback from our firmware engineers, all Realtek controllers should have the same behavior on suspend and resume. @ Kai-Heng, " Bluetooth: hci0: command 0x1001 tx timeout " is irrelevant to firmware loss or not. The rom code in controller supports this command.
Quoted 68 lines
Quoted 5 lines
Quoted 2 lines
I would prefer this doesn't get accepted in its current state.
Of course.
I think we need to find the root cause for your case before applying thisone.
Quoted 12 lines
Kai-Heng
Quoted 9 lines
Abhishek
Quoted 4 lines · Kai-Heng Feng
Realtek bluetooth controller may fail to work after system sleep:
[ 1272.707670] Bluetooth: hci0: command 0x1001 tx timeout [ 1280.835712] Bluetooth: hci0: RTL: HCI_OP_READ_LOCAL_VERSIONfailed (-110)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
If platform firmware doesn't cut power off during suspend, the
firmware
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
is considered retained in controller but the driver is still asking USB core to perform a reset-resume. This can make bluetooth controller unusable.
So avoid unnecessary reset to resolve the issue.
For devices that really lose power during suspend, USB core will detect and handle reset-resume correctly.
Signed-off-by Kai-Heng Feng <[email protected]>---
drivers/bluetooth/btusb.c| 8 +++-----1 file changed, 3 insertions(+), 5 deletions(-)Quoted 5 lines
Quoted 5 lines
drivers/bluetooth/btusb.c static int btusb_suspend(struct
Quoted 5 lines
drivers/bluetooth/btusb.c +0
-0@@ -4255,17 +4255,15 @@ static int btusb_suspend(struct
usb_interface*intf,pm_message_tmessage)Quoted 9 lines
Quoted 9 lines
drivers/bluetooth/btusb.c static int btusb_suspend(struct · line 4260
Quoted 9 lines
drivers/bluetooth/btusb.c +3
-3enable_irq (data->oob_wake_irq); } -/* For global suspend, Realtek devices lose the loaded fw -* in them. But for autosuspend, firmware should remain. -* Actually, it depends on whether the usb host sends +/* For global suspend, Realtek devices lose the loaded fw in them if +* platform firmware cut power off. But for autosuspend, firmware +* should remain. Actually, it depends on whether the usb host sends
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
drivers/bluetooth/btusb.c +0
-3* set feature (enable wakeup) or not. */ if (test_bit (BTUSB_WAKEUP_DISABLE , &data->flags)) {if (PMSG_IS_AUTO (message) &&device_can_wakeup (&data->udev->dev)) data->udev->do_remote_wakeup =1 ; -else if (!PMSG_IS_AUTO (message)) - data->udev->reset_resume =1 ; }return 0 ; --2.17.1
Quoted 88 lines · 陆朱伟
Hi Abhishek,
Quoted 82 lines · Abhishek Pandit-Subedi
+ Alex Lu (who contributed the original change)
Hi Kai-Heng,
Quoted 6 lines · Kai-Heng Feng
[+Cc linux-usb]
Hi Abhishek,
Quoted 1 line
On Sep 24, 2020, at 04:41, Abhishek Pandit-Subedi
Quoted 8 lines · <[email protected]> wrote:
Quoted 4 lines
Hi Kai-Heng,
Which Realtek controller is this on?'
The issue happens on 8821CE.
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Specifically for RTL8822CE, we tested without
reset_resumebeing set and that was causing the controller being reset without bluez ever learning about it (resulting in devices being unusable without toggling the BT power).The reset is done by the kernel, so how does that affect bluez?
From what you described, it sounds more like runtime resume since bluez
is already running.
Quoted 1 line
If we need reset resume for runtime resume, maybe it's another bug
which needs to be addressed?
From
btusb.c:
https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-
next.git/tree/drivers/bluetooth/btusb.c#n4189
/* Realtek devices lose their updated firmware over global
* suspend that means host doesn't sendSET_FEATURE
* (DEVICE_REMOTE_WAKEUP)
*/Runtime suspend always requires remote wakeup to be set and reset resume isn't used there.
During system suspend, when remote wakeup is not set, RTL8822CE loses the FW loaded by the driver and any state currently in the controller. This causes the kernel and the controller state to go out of sync. One of the issues we observed on the Realtek controller without the reset resume quirk was that paired or connected devices would just stop working after resume.
Quoted 5 lines
Quoted 3 lines
If the firmware doesn't cut off power during suspend, maybe you shouldn't set the
BTUSB_WAKEUP_DISABLEflag for that controller.We don't know beforehand if the platform firmware (BIOS for my case) will
cut power off or not.
Quoted 3 lines
In general, laptops will cut off the USB power during S3. When AC is plugged, some laptops cuts USB power off and some don't. This
also applies to many desktops. Not to mention there can be BIOS options to control USB power under S3/S4/S5...
Quoted 3 lines
So we don't know beforehand.
I think the confusion here stems from what is actually being turned off between our two boards and what we're referring to as firmware :)
In your case, the Realtek controller retains firmware unless the platform cuts of power to USB (which it does during S3). In my case, the Realtek controller loses firmware when Remote Wakeup isn't set, even if the platform doesn't cut power to USB.
In your case, since you don't need to enforce the 'Remote Wakeup' bit, if you unset the
BTUSB_WAKEUP_DISABLEfor that VID:PID, you should get the desirable behavior (which is actually the default behavior; remote wake will always be asserted instead of only during Runtime Suspend).
Quoted 7 lines
Quoted 4 lines
@Alex -- What is the common behavior for Realtek controllers? Should we set
BTUSB_WAKEUP_DISABLEonly on RTL8822CE or should we unset it only on RTL8821CE?According to the feedback from our firmware engineers, all Realtek controllers should have the same behavior on suspend and resume. @ Kai-Heng, " Bluetooth: hci0: command
0x1001tx timeout " is irrelevant to firmware loss or not. The rom code in controller supports this command.
Does USB warm-reset affect the Bluetooth controller?
Kai-Heng
Quoted 66 lines
Quoted 66 lines
Quoted 6 lines
Quoted 3 lines
I would prefer this doesn't get accepted in its current state.
Of course.
I think we need to find the root cause for your case before applying thisone.
Quoted 12 lines
Kai-Heng
Quoted 9 lines
Abhishek
Quoted 4 lines · Kai-Heng Feng
Realtek bluetooth controller may fail to work after system sleep:
[ 1272.707670] Bluetooth: hci0: command 0x1001 tx timeout [ 1280.835712] Bluetooth: hci0: RTL: HCI_OP_READ_LOCAL_VERSIONfailed (-110)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
If platform firmware doesn't cut power off during suspend, the
firmware
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
is considered retained in controller but the driver is still asking USB core to perform a reset-resume. This can make bluetooth controller unusable.
So avoid unnecessary reset to resolve the issue.
For devices that really lose power during suspend, USB core will detect and handle reset-resume correctly.
Signed-off-by Kai-Heng Feng <[email protected]>---
drivers/bluetooth/btusb.c| 8 +++-----1 file changed, 3 insertions(+), 5 deletions(-)Quoted 5 lines
Quoted 5 lines
drivers/bluetooth/btusb.c static int btusb_suspend(struct
Quoted 5 lines
drivers/bluetooth/btusb.c +0
-0@@ -4255,17 +4255,15 @@ static int btusb_suspend(struct
usb_interface*intf,pm_message_tmessage)Quoted 9 lines
Quoted 9 lines
drivers/bluetooth/btusb.c static int btusb_suspend(struct · line 4260
Quoted 9 lines
drivers/bluetooth/btusb.c +3
-3enable_irq (data->oob_wake_irq); } -/* For global suspend, Realtek devices lose the loaded fw -* in them. But for autosuspend, firmware should remain. -* Actually, it depends on whether the usb host sends +/* For global suspend, Realtek devices lose the loaded fw in them if +* platform firmware cut power off. But for autosuspend, firmware +* should remain. Actually, it depends on whether the usb host sends
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
drivers/bluetooth/btusb.c +0
-3* set feature (enable wakeup) or not. */ if (test_bit (BTUSB_WAKEUP_DISABLE , &data->flags)) {if (PMSG_IS_AUTO (message) &&device_can_wakeup (&data->udev->dev)) data->udev->do_remote_wakeup =1 ; -else if (!PMSG_IS_AUTO (message)) - data->udev->reset_resume =1 ; }return 0 ; --2.17.1