Commit d7a6c0ce authored by Kai-Heng Feng's avatar Kai-Heng Feng Committed by Greg Kroah-Hartman

USB: Consolidate LPM checks to avoid enabling LPM twice

USB Bluetooth controller QCA ROME (0cf3:e007) sometimes stops working
after S3:
[ 165.110742] Bluetooth: hci0: using NVM file: qca/nvm_usb_00000302.bin
[ 168.432065] Bluetooth: hci0: Failed to send body at 4 of 1953 (-110)

After some experiments, I found that disabling LPM can workaround the
issue.

On some platforms, the USB power is cut during S3, so the driver uses
reset-resume to resume the device. During port resume, LPM gets enabled
twice, by usb_reset_and_verify_device() and usb_port_resume().

Consolidate all checks into new LPM helpers to make sure LPM only gets
enabled once.

Fixes: de68bab4 ("usb: Don't enable USB 2.0 Link PM by default.”)
Signed-off-by: default avatarKai-Heng Feng <kai.heng.feng@canonical.com>
Cc: stable <stable@vger.kernel.org> # after much soaking
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7529b257
...@@ -1901,9 +1901,6 @@ static int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable) ...@@ -1901,9 +1901,6 @@ static int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
struct usb_hcd *hcd = bus_to_hcd(udev->bus); struct usb_hcd *hcd = bus_to_hcd(udev->bus);
int ret = -EPERM; int ret = -EPERM;
if (enable && !udev->usb2_hw_lpm_allowed)
return 0;
if (hcd->driver->set_usb2_hw_lpm) { if (hcd->driver->set_usb2_hw_lpm) {
ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable); ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable);
if (!ret) if (!ret)
...@@ -1915,11 +1912,19 @@ static int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable) ...@@ -1915,11 +1912,19 @@ static int usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
int usb_enable_usb2_hardware_lpm(struct usb_device *udev) int usb_enable_usb2_hardware_lpm(struct usb_device *udev)
{ {
if (!udev->usb2_hw_lpm_capable ||
!udev->usb2_hw_lpm_allowed ||
udev->usb2_hw_lpm_enabled)
return 0;
return usb_set_usb2_hardware_lpm(udev, 1); return usb_set_usb2_hardware_lpm(udev, 1);
} }
int usb_disable_usb2_hardware_lpm(struct usb_device *udev) int usb_disable_usb2_hardware_lpm(struct usb_device *udev)
{ {
if (!udev->usb2_hw_lpm_enabled)
return 0;
return usb_set_usb2_hardware_lpm(udev, 0); return usb_set_usb2_hardware_lpm(udev, 0);
} }
......
...@@ -3251,8 +3251,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) ...@@ -3251,8 +3251,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
} }
/* disable USB2 hardware LPM */ /* disable USB2 hardware LPM */
if (udev->usb2_hw_lpm_enabled == 1) usb_disable_usb2_hardware_lpm(udev);
usb_disable_usb2_hardware_lpm(udev);
if (usb_disable_ltm(udev)) { if (usb_disable_ltm(udev)) {
dev_err(&udev->dev, "Failed to disable LTM before suspend\n"); dev_err(&udev->dev, "Failed to disable LTM before suspend\n");
...@@ -3290,8 +3289,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) ...@@ -3290,8 +3289,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg)
usb_enable_ltm(udev); usb_enable_ltm(udev);
err_ltm: err_ltm:
/* Try to enable USB2 hardware LPM again */ /* Try to enable USB2 hardware LPM again */
if (udev->usb2_hw_lpm_capable == 1) usb_enable_usb2_hardware_lpm(udev);
usb_enable_usb2_hardware_lpm(udev);
if (udev->do_remote_wakeup) if (udev->do_remote_wakeup)
(void) usb_disable_remote_wakeup(udev); (void) usb_disable_remote_wakeup(udev);
...@@ -3574,8 +3572,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg) ...@@ -3574,8 +3572,7 @@ int usb_port_resume(struct usb_device *udev, pm_message_t msg)
hub_port_logical_disconnect(hub, port1); hub_port_logical_disconnect(hub, port1);
} else { } else {
/* Try to enable USB2 hardware LPM */ /* Try to enable USB2 hardware LPM */
if (udev->usb2_hw_lpm_capable == 1) usb_enable_usb2_hardware_lpm(udev);
usb_enable_usb2_hardware_lpm(udev);
/* Try to enable USB3 LTM */ /* Try to enable USB3 LTM */
usb_enable_ltm(udev); usb_enable_ltm(udev);
...@@ -5680,8 +5677,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev) ...@@ -5680,8 +5677,7 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
/* Disable USB2 hardware LPM. /* Disable USB2 hardware LPM.
* It will be re-enabled by the enumeration process. * It will be re-enabled by the enumeration process.
*/ */
if (udev->usb2_hw_lpm_enabled == 1) usb_disable_usb2_hardware_lpm(udev);
usb_disable_usb2_hardware_lpm(udev);
/* Disable LPM while we reset the device and reinstall the alt settings. /* Disable LPM while we reset the device and reinstall the alt settings.
* Device-initiated LPM, and system exit latency settings are cleared * Device-initiated LPM, and system exit latency settings are cleared
......
...@@ -1243,8 +1243,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0) ...@@ -1243,8 +1243,7 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
dev->actconfig->interface[i] = NULL; dev->actconfig->interface[i] = NULL;
} }
if (dev->usb2_hw_lpm_enabled == 1) usb_disable_usb2_hardware_lpm(dev);
usb_disable_usb2_hardware_lpm(dev);
usb_unlocked_disable_lpm(dev); usb_unlocked_disable_lpm(dev);
usb_disable_ltm(dev); usb_disable_ltm(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment