Skip to content

Commit 31a6afb

Browse files
Xu Yanggregkh
authored andcommitted
usb: chipidea: udc: disconnect/reconnect from host when do suspend/resume
Shawn and John reported a hang issue during system suspend as below: - USB gadget is enabled as Ethernet - There is data transfer over USB Ethernet (scp a big file between host and device) - Device is going in/out suspend (echo mem > /sys/power/state) The root cause is the USB device controller is suspended but the USB bus is still active which caused the USB host continues to transfer data with device and the device continues to queue USB requests (in this case, a delayed TCP ACK packet trigger the issue) after controller is suspended, however the USB controller clock is already gated off. Then if udc driver access registers after that point, the system will hang. The correct way to avoid such issue is to disconnect device from host when the USB bus is not at suspend state. Then the host will receive disconnect event and stop data transfer in time. To continue make USB gadget device work after system resume, this will reconnect device automatically. To make usb wakeup work if USB bus is already at suspend state, this will keep connection for it only when USB device controller has enabled wakeup capability. Reported-by: Shawn Guo <[email protected]> Reported-by: John Ernberg <[email protected]> Closes: https://lore.kernel.org/linux-usb/aEZxmlHmjeWcXiF3@dragon/ Tested-by: John Ernberg <[email protected]> # iMX8QXP Fixes: 235ffc1 ("usb: chipidea: udc: add suspend/resume support for device controller") Cc: stable <[email protected]> Reviewed-by: Jun Li <[email protected]> Signed-off-by: Xu Yang <[email protected]> Acked-by: Peter Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3b18405 commit 31a6afb

File tree

1 file changed

+7
-0
lines changed
  • drivers/usb/chipidea

1 file changed

+7
-0
lines changed

drivers/usb/chipidea/udc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,6 +2374,10 @@ static void udc_suspend(struct ci_hdrc *ci)
23742374
*/
23752375
if (hw_read(ci, OP_ENDPTLISTADDR, ~0) == 0)
23762376
hw_write(ci, OP_ENDPTLISTADDR, ~0, ~0);
2377+
2378+
if (ci->gadget.connected &&
2379+
(!ci->suspended || !device_may_wakeup(ci->dev)))
2380+
usb_gadget_disconnect(&ci->gadget);
23772381
}
23782382

23792383
static void udc_resume(struct ci_hdrc *ci, bool power_lost)
@@ -2384,6 +2388,9 @@ static void udc_resume(struct ci_hdrc *ci, bool power_lost)
23842388
OTGSC_BSVIS | OTGSC_BSVIE);
23852389
if (ci->vbus_active)
23862390
usb_gadget_vbus_disconnect(&ci->gadget);
2391+
} else if (ci->vbus_active && ci->driver &&
2392+
!ci->gadget.connected) {
2393+
usb_gadget_connect(&ci->gadget);
23872394
}
23882395

23892396
/* Restore value 0 if it was set for power lost check */

0 commit comments

Comments
 (0)