]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: dwc3: core: Stop processing of pending events if controller is halted
authorSelvarasu Ganesan <selvarasu.g@samsung.com>
Mon, 16 Sep 2024 23:18:09 +0000 (04:48 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 13:08:37 +0000 (15:08 +0200)
commit 0d410e8913f5cffebcca79ffdd596009d4a13a28 upstream.

This commit addresses an issue where events were being processed when
the controller was in a halted state. To fix this issue by stop
processing the events as the event count was considered stale or
invalid when the controller was halted.

Fixes: fc8bb91bc83e ("usb: dwc3: implement runtime PM")
Cc: stable@kernel.org
Signed-off-by: Selvarasu Ganesan <selvarasu.g@samsung.com>
Suggested-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/20240916231813.206-1-selvarasu.g@samsung.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/core.c
drivers/usb/dwc3/core.h
drivers/usb/dwc3/gadget.c

index b0ce9c1ed4501a93dad3f1eeb02f2271976d1726..1264683d45f20bfe32c36db980d167b4773a79de 100644 (file)
@@ -457,6 +457,7 @@ static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
 int dwc3_event_buffers_setup(struct dwc3 *dwc)
 {
        struct dwc3_event_buffer        *evt;
+       u32                             reg;
 
        if (!dwc->ev_buf)
                return 0;
@@ -469,8 +470,10 @@ int dwc3_event_buffers_setup(struct dwc3 *dwc)
                        upper_32_bits(evt->dma));
        dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
                        DWC3_GEVNTSIZ_SIZE(evt->length));
-       dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
 
+       /* Clear any stale event */
+       reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0));
+       dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg);
        return 0;
 }
 
@@ -497,7 +500,10 @@ void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
        dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0);
        dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK
                        | DWC3_GEVNTSIZ_SIZE(0));
-       dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
+
+       /* Clear any stale event */
+       reg = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0));
+       dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), reg);
 }
 
 static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
@@ -1899,7 +1905,11 @@ static int dwc3_runtime_resume(struct device *dev)
 
        switch (dwc->current_dr_role) {
        case DWC3_GCTL_PRTCAP_DEVICE:
-               dwc3_gadget_process_pending_events(dwc);
+               if (dwc->pending_events) {
+                       pm_runtime_put(dwc->dev);
+                       dwc->pending_events = false;
+                       enable_irq(dwc->irq_gadget);
+               }
                break;
        case DWC3_GCTL_PRTCAP_HOST:
        default:
@@ -1986,6 +1996,12 @@ static void dwc3_complete(struct device *dev)
 static const struct dev_pm_ops dwc3_dev_pm_ops = {
        SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
        .complete = dwc3_complete,
+
+       /*
+        * Runtime suspend halts the controller on disconnection. It relies on
+        * platforms with custom connection notification to start the controller
+        * again.
+        */
        SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume,
                        dwc3_runtime_idle)
 };
index ebe086feb3bb5553860ced71e1a896ba8c6f50ae..3649400f04a762fdf7ad0a910644c4608d330cdc 100644 (file)
@@ -1532,7 +1532,6 @@ static inline void dwc3_otg_host_init(struct dwc3 *dwc)
 #if !IS_ENABLED(CONFIG_USB_DWC3_HOST)
 int dwc3_gadget_suspend(struct dwc3 *dwc);
 int dwc3_gadget_resume(struct dwc3 *dwc);
-void dwc3_gadget_process_pending_events(struct dwc3 *dwc);
 #else
 static inline int dwc3_gadget_suspend(struct dwc3 *dwc)
 {
@@ -1544,9 +1543,6 @@ static inline int dwc3_gadget_resume(struct dwc3 *dwc)
        return 0;
 }
 
-static inline void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
-{
-}
 #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
 
 #if IS_ENABLED(CONFIG_USB_DWC3_ULPI)
index 550eae39a63d3914dd96b877e9c9cbf1ed2f0e16..da9599d819291e706febd06f96469161335212b3 100644 (file)
@@ -4093,14 +4093,3 @@ err1:
 err0:
        return ret;
 }
-
-void dwc3_gadget_process_pending_events(struct dwc3 *dwc)
-{
-       if (dwc->pending_events) {
-               dwc3_interrupt(dwc->irq_gadget, dwc->ev_buf);
-               dwc3_thread_interrupt(dwc->irq_gadget, dwc->ev_buf);
-               pm_runtime_put(dwc->dev);
-               dwc->pending_events = false;
-               enable_irq(dwc->irq_gadget);
-       }
-}