On Fri, Aug 09, 2024, André Draszik wrote: > Hi, > > I am trying to get DWC3 runtime suspend working on Google Tensor gs101 > (which is an Exynos derivative) when configured in DRD / peripheral mode > and the USB cable is being unplugged. > > For me runtime suspend currently doesn't happen if a gadget mode had been > configured, e.g. via f_fs, for example via ADBd or if CDC_ECM are active. > What I observe is that when a gadget is configured, various EPs / TRBs are > being configured / queued. These are active and therefore prevent runtime PM > from kicking in. > > Please correct me if I'm wrong, but I believe that during cable disconnect > they should all be dequeued / cancelled. This doesn't happen for me unless That's right. > the UDC device is explicitly (manually) deconfigured, therefore preventing > runtime PM from working. I don't think that manually deconfiguring the UDC > should be a requirement? > > Which part of the stack should be responsible / the entry point for triggering > the dequeuing? When there's a disconnect, the UDC driver will notify the gadget driver via the gadget driver's disconnect() callback. The gadget driver is supposed to do the teardown and cleanup. This includes disabling active endpoints. If the gadget driver disables the endpoint, then all the active requests will be returned properly. Check documentation on usb_ep_disable() for more info. > > I've attached a trace, but if possible I would appreciate confirmation please > as to whether my understanding of what should happen is correct (TRBs should > be dequeued automatically, allowing device to enter idle/suspend state), and > if yes maybe some pointers please as to what to check and why the dequeuing > might not be happening. In the attached trace I've used Android's ADBd, but > I observe same behaviour with CDC_ECM. > > The trace contains two scenarios: > > 1) plug USB cable @ 518.618211 > unplug USB cable @ 679.552884 > -> DWC goes into runtime suspend @ 687.792253 > > 2) configure gadget (start ADBd) @ 690.741254 > plug USB cable @ 721.062462 > unplug USB cable @ 747.502087 > -> no runtime suspend happens, due to TRBs remaining queued > > Is my understanding correct? Any pointers would be greatly appreciated. > (Unfortunately, I have no comparable platform at hand to be able to compare > traces). > Please capture tracepoint events rather than function trace. You can check here for how to do so: https://www.kernel.org/doc/html/latest/driver-api/usb/dwc3.html#required-information > > Thanks, > Andre' > > interesting time stamps: > 503.142696 | 6) | /* ADADAD auto runtime pm */ > 518.618211 | 6) | /* ADADAD plug cable */ > 679.552884 | 6) | /* ADADAD unplug cable */ > 690.741254 | 6) | /* ADADAD start ADBd */ > 721.062462 | 0) | /* ADADAD plug cable */ > 747.502087 | 0) | /* ADADAD unplug cable */ > Check your gadget driver if the gadget_driver->disconnect() callback is handled properly. BR, Thinh