usb: dwc3: gadget: Avoid runtime resume if disabling pullup
Subsystems (2)
PATCH 1/1 usb: dwc3: gadget: Avoid runtime resume if disabling pullup
If the device is already in the runtime suspended state, any call to the pullup routine will issue a runtime resume on the DWC3 core device. If the USB gadget is disabling the pullup, then avoid having to issue a runtime resume, as DWC3 gadget has already been halted/stopped.
This fixes an issue where the following condition occurs:
usb_gadget_remove_driver()
-->usb_gadget_disconnect()
-->dwc3_gadget_pullup(0)
-->pm_runtime_get_sync() -> ret = 0
-->pm_runtime_put() [async]
-->usb_gadget_udc_stop()
-->dwc3_gadget_stop()
-->dwc->gadget_driver = NULL
...
dwc3_suspend_common()
-->dwc3_gadget_suspend()
-->DWC3 halt/stop routine skipped, driver_data == NULL
This leads to a situation where the DWC3 gadget is not properly stopped, as the runtime resume would have re-enabled EP0 and event interrupts, and since we avoided the DWC3 gadget suspend, these resources were never disabled.
--- drivers/usb/dwc3/gadget.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/usb/dwc3/gadget.c +11 -0
@@ -2435,6 +2435,17 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) }/* +* Avoid issuing a runtime resume if the device is already in the +* suspended state during gadget disconnect. DWC3 gadget was already +* halted/stopped during runtime suspend. +*/ +if (!is_on) { +pm_runtime_barrier (dwc->dev); +if (pm_runtime_suspended (dwc->dev)) +return 0 ; + } + +/* * Check the return value for successful resume, or error. For a * successful resume, the DWC3 runtime PM resume routine will handle * the run stop sequence, so avoid duplicate operations here.
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Hi Wesley,
Quoted 44 lines · Wesley Cheng
If the device is already in the runtime suspended state, any call to the pullup routine will issue a runtime resume on the DWC3 core device. If the USB gadget is disabling the pullup, then avoid having to issue a runtime resume, as DWC3 gadget has already been halted/stopped.
This fixes an issue where the following condition occurs:
usb_gadget_remove_driver()
-->usb_gadget_disconnect()
-->dwc3_gadget_pullup(0)
-->pm_runtime_get_sync() -> ret = 0
-->pm_runtime_put() [async]
-->usb_gadget_udc_stop()
-->dwc3_gadget_stop()
-->dwc->gadget_driver = NULL
...
dwc3_suspend_common()
-->dwc3_gadget_suspend()
-->DWC3 halt/stop routine skipped,driver_data== NULLThis leads to a situation where the DWC3 gadget is not properly stopped, as the runtime resume would have re-enabled EP0 and event interrupts, and since we avoided the DWC3 gadget suspend, these resources were never disabled.
Signed-off-by Wesley Cheng <[email protected]>--- drivers/usb/dwc3/gadget.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/usb/dwc3/gadget.c +4
-0@@ -2435,6 +2435,17 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) }/* +* Avoid issuing a runtime resume if the device is already in the +* suspended state during gadget disconnect. DWC3 gadget was already +* halted/stopped during runtime suspend. +*/
drivers/usb/dwc3/gadget.c static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) · line 2451
Quoted 10 lines
drivers/usb/dwc3/gadget.c +7
-0+if (!is_on) { +pm_runtime_barrier (dwc->dev); +if (pm_runtime_suspended (dwc->dev)) +return 0 ; + } + +/* * Check the return value for successful resume, or error. For a * successful resume, the DWC3 runtime PM resume routine will handle * the run stop sequence, so avoid duplicate operations here.
Should this also go to stable with Fixes: 77adb8bdf422 ("usb: dwc3:
gadget: Allow runtime suspend if UDC unbinded") ?
Jack
Quoted 52 lines · Jack Pham
Hi Wesley,
Quoted 49 lines · Wesley Cheng
If the device is already in the runtime suspended state, any call to the pullup routine will issue a runtime resume on the DWC3 core device. If the USB gadget is disabling the pullup, then avoid having to issue a runtime resume, as DWC3 gadget has already been halted/stopped.
This fixes an issue where the following condition occurs:
usb_gadget_remove_driver()
-->usb_gadget_disconnect()
-->dwc3_gadget_pullup(0)
-->pm_runtime_get_sync() -> ret = 0
-->pm_runtime_put() [async]
-->usb_gadget_udc_stop()
-->dwc3_gadget_stop()
-->dwc->gadget_driver = NULL
...
dwc3_suspend_common()
-->dwc3_gadget_suspend()
-->DWC3 halt/stop routine skipped,driver_data== NULLThis leads to a situation where the DWC3 gadget is not properly stopped, as the runtime resume would have re-enabled EP0 and event interrupts, and since we avoided the DWC3 gadget suspend, these resources were never disabled.
Signed-off-by Wesley Cheng <[email protected]>--- drivers/usb/dwc3/gadget.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/usb/dwc3/gadget.c +9
-0@@ -2435,6 +2435,17 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) }/* +* Avoid issuing a runtime resume if the device is already in the +* suspended state during gadget disconnect. DWC3 gadget was already +* halted/stopped during runtime suspend. +*/ +if (!is_on) { +pm_runtime_barrier (dwc->dev); +if (pm_runtime_suspended (dwc->dev)) +return 0 ; + }
Quoted 8 lines
drivers/usb/dwc3/gadget.c static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) · line 2451
Quoted 5 lines
drivers/usb/dwc3/gadget.c +2
-0+ +/* * Check the return value for successful resume, or error. For a * successful resume, the DWC3 runtime PM resume routine will handle * the run stop sequence, so avoid duplicate operations here. Should this also go to stable with Fixes:
77adb8bdf422("usb: dwc3:
gadget: Allow runtime suspend if UDC unbinded") ?
sounds like a good idea.
Signature · 1 line
balbi
Quoted 45 lines · Felipe Balbi
Quoted 42 lines · Jack Pham
Hi Wesley,
Quoted 39 lines · Wesley Cheng
If the device is already in the runtime suspended state, any call to the pullup routine will issue a runtime resume on the DWC3 core device. If the USB gadget is disabling the pullup, then avoid having to issue a runtime resume, as DWC3 gadget has already been halted/stopped.
This fixes an issue where the following condition occurs:
usb_gadget_remove_driver()
-->usb_gadget_disconnect()
-->dwc3_gadget_pullup(0)
-->pm_runtime_get_sync() -> ret = 0
-->pm_runtime_put() [async]
-->usb_gadget_udc_stop()
-->dwc3_gadget_stop()
-->dwc->gadget_driver = NULL
...
dwc3_suspend_common()
-->dwc3_gadget_suspend()
-->DWC3 halt/stop routine skipped,driver_data== NULLThis leads to a situation where the DWC3 gadget is not properly stopped, as the runtime resume would have re-enabled EP0 and event interrupts, and since we avoided the DWC3 gadget suspend, these resources were never disabled.
Signed-off-by Wesley Cheng <[email protected]>--- drivers/usb/dwc3/gadget.c | 11 +++++++++++ 1 file changed, 11 insertions(+)drivers/usb/dwc3/gadget.c +0
-0@@ -2435,6 +2435,17 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) }
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
drivers/usb/dwc3/gadget.c +6
-0/* +* Avoid issuing a runtime resume if the device is already in the +* suspended state during gadget disconnect. DWC3 gadget was already +* halted/stopped during runtime suspend. +*/ +if (!is_on) { +pm_runtime_barrier (dwc->dev);Quoted 8 lines
drivers/usb/dwc3/gadget.c static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) · line 2451
Quoted 8 lines
drivers/usb/dwc3/gadget.c +5
-0+if (pm_runtime_suspended (dwc->dev)) +return 0 ; + } + +/* * Check the return value for successful resume, or error. For a * successful resume, the DWC3 runtime PM resume routine will handle * the run stop sequence, so avoid duplicate operations here.
Hi Jack/Felipe,
Quoted 6 lines
Quoted 3 lines
Should this also go to stable with Fixes:
77adb8bdf422("usb: dwc3:
gadget: Allow runtime suspend if UDC unbinded") ?sounds like a good idea.
Sure, will update the commit text with the fixes tag. Thanks!
Regards,
Wesley Cheng
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project