mbox series

[v2,0/9] usb: dwc3: qcom: fix wakeup implementation

Message ID 20220804151001.23612-1-johan+linaro@kernel.org
Headers show
Series usb: dwc3: qcom: fix wakeup implementation | expand

Message

Johan Hovold Aug. 4, 2022, 3:09 p.m. UTC
This series fixes some of the fallout after the recently merged series
that added wakeup support to the Qualcomm dwc3 driver:

	https://lore.kernel.org/all/1655094654-24052-1-git-send-email-quic_kriskura@quicinc.com/

The first patch fixes a long standing PHY power sequencing issue in dwc3
core.

The second patch reverts a power-domain hack that was added by the above
series. There are other ways to implement this which doesn't violate the
genpd interface, and if for some reason those are not sufficient, the
genpd implementation needs to be extended, not hacked around.

The third patch fixes a build breakage caused by the same series. (new
in v2)

The fourth patch fixes another long-standing bug which could lead to a
use-after-free when using runtime PM. (new in v2)

The next patch fixes another issue in the Qualcomm dwc3 implementation
that has been added a while back and which breaks runtime PM.

The sixt patch fixes a NULL-pointer dereference or use-after-free when
suspending controllers in peripheral or OTG mode due to a hack that was
added to suspend path. Unfortunately, it seems the hack needs to stay
for now if we want functioning suspend on some Qualcomm platforms.

The remaining patches moves the wakeup-source property over from the
core node to the glue node in the binding and instead propagates the
wakeup capability to the former during probe.

Note that this incidentally also avoids adding probe-deferral hacks to
the driver as was recently proposed to deal with another problem with
the current implementation:

	https://lore.kernel.org/all/1657891312-21748-1-git-send-email-quic_kriskura@quicinc.com/

With this series I have functioning USB system suspend and wakeup as
well as somewhat functioning runtime PM in host mode on sc8280xp. Note
that the PHYs apparently do not not to be left enabled for wakeup on
this platform.

Some issues remain such as that root-hub connect/disconnect events
cannot selectively be disabled.

And of course, the suspend speed hack needs to be replaced at some
point but that likely requires some more heavy lifting in the dwc3
implementation.

Johan

Changes in v2
 - add review and ack tags
 - fix a gadget-only build breakage (new patch)
 - fix a use-after-free on wakeup from runtime suspend (new patch)
 - disable wakeup completely instead of falling back to the
   "disconnected" host configuration when not acting as host
 - disallow 'wakeup-source' in child node in the binding


Johan Hovold (9):
  usb: dwc3: fix PHY disable sequence
  Revert "usb: dwc3: qcom: Keep power domain on to retain controller
    status"
  usb: dwc3: qcom: fix gadget-only builds
  usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup
  usb: dwc3: qcom: fix runtime PM wakeup
  usb: dwc3: qcom: fix peripheral and OTG suspend
  dt-bindings: usb: qcom,dwc3: add wakeup-source property
  usb: dwc3: qcom: fix wakeup implementation
  usb: dwc3: qcom: clean up suspend callbacks

 .../devicetree/bindings/usb/qcom,dwc3.yaml    |  5 +
 drivers/usb/dwc3/core.c                       | 24 ++---
 drivers/usb/dwc3/dwc3-qcom.c                  | 96 +++++++++++--------
 drivers/usb/dwc3/host.c                       |  1 +
 4 files changed, 76 insertions(+), 50 deletions(-)

Comments

Johan Hovold Aug. 4, 2022, 3:15 p.m. UTC | #1
On Thu, Aug 04, 2022 at 05:09:52PM +0200, Johan Hovold wrote:

> Changes in v2
>  - add review and ack tags
>  - fix a gadget-only build breakage (new patch)
>  - fix a use-after-free on wakeup from runtime suspend (new patch)
>  - disable wakeup completely instead of falling back to the
>    "disconnected" host configuration when not acting as host
>  - disallow 'wakeup-source' in child node in the binding

Forgot to mention that I also dropped the revert of the dt-binding
commit adding 'wakeup-source' to the core node as Rob suggested.

Johan
Randy Dunlap Aug. 4, 2022, 6:18 p.m. UTC | #2
Hi John,

On 8/4/22 08:09, Johan Hovold wrote:
> A recent change added a dependency to the USB host stack and broke
> gadget-only builds of the driver.
> 
> Fixes: 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Johan Hovold <johan+linaro@kernel.org>

LGTM. Thanks.

Reviewed-by: Randy Dunlap <rdunlap@infradead.org>

> ---
> 
> Changes in v2
>  - new patch
> 
>  drivers/usb/dwc3/dwc3-qcom.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index be2e3dd36440..e9364141661b 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -310,8 +310,11 @@ static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom)
>  	 * currently supports only 1 port per controller. So
>  	 * this is sufficient.
>  	 */
> +#ifdef CONFIG_USB
>  	udev = usb_hub_find_child(hcd->self.root_hub, 1);
> -
> +#else
> +	udev = NULL;
> +#endif
>  	if (!udev)
>  		return USB_SPEED_UNKNOWN;
>