2022-07-15 13:30:53

by Krishna Kurapati

[permalink] [raw]
Subject: [PATCH v2] usb: dwc3: qcom: Defer dwc3-qcom probe if dwc3 isn't probed properly

On SC7180 devices, it is observed that dwc3 probing is deferred
because device_links_check_suppliers() finds that '88e3000.phy'
isn't ready yet.

As a part of its probe call, dwc3-qcom driver checks if dwc3 core
is wakeup capable or not. If the dwc3 core is wakeup capable, driver
configures dwc-qcom's power domain to be always ON. Also it configures
dp/dm interrupts accordingly to support wakeup from system suspend.

More info regarding the same can be found at:
commit d9be8d5c5b03 ("usb: dwc3: qcom: Keep power domain on to retain controller status")
commit 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")

In the event, dwc3 probe gets deferred and is processed after dwc3-qcom
probe, driver ends up reading the wakeup capability of dwc3 core as false
leading to instability in suspend/resume path.

To avoid this scenario, ensure dwc3_probe is successful by checking
if appropriate driver is assigned to it or not after the of_platform_populate
call. If it isn't then defer dwc3-qcom probe as well.

Fixes: 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
Signed-off-by: Krishna Kurapati <[email protected]>
---
v2: Set return value to EPROBE_DEFER to drop reference to dwc3 node

drivers/usb/dwc3/dwc3-qcom.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
index 7703655..6676b39 100644
--- a/drivers/usb/dwc3/dwc3-qcom.c
+++ b/drivers/usb/dwc3/dwc3-qcom.c
@@ -722,6 +722,9 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
dev_err(dev, "failed to get dwc3 platform device\n");
}

+ if (!qcom->dwc3->dev.driver)
+ ret = -EPROBE_DEFER;
+
node_put:
of_node_put(dwc3_np);

--
2.7.4


2022-07-15 21:18:45

by Matthias Kaehlcke

[permalink] [raw]
Subject: Re: [PATCH v2] usb: dwc3: qcom: Defer dwc3-qcom probe if dwc3 isn't probed properly

On Fri, Jul 15, 2022 at 06:51:52PM +0530, Krishna Kurapati wrote:

> Subject: usb: dwc3: qcom: Defer dwc3-qcom probe if dwc3 isn't probed properly

nit: "isn't probed properly" sounds like a bug or HW issue. In case
you re-spin maybe change it to "hasn't probed yet" or similar.

> On SC7180 devices, it is observed that dwc3 probing is deferred
> because device_links_check_suppliers() finds that '88e3000.phy'
> isn't ready yet.
>
> As a part of its probe call, dwc3-qcom driver checks if dwc3 core
> is wakeup capable or not. If the dwc3 core is wakeup capable, driver
> configures dwc-qcom's power domain to be always ON. Also it configures
> dp/dm interrupts accordingly to support wakeup from system suspend.
>
> More info regarding the same can be found at:
> commit d9be8d5c5b03 ("usb: dwc3: qcom: Keep power domain on to retain controller status")
> commit 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")
>
> In the event, dwc3 probe gets deferred and is processed after dwc3-qcom
> probe, driver ends up reading the wakeup capability of dwc3 core as false
> leading to instability in suspend/resume path.
>
> To avoid this scenario, ensure dwc3_probe is successful by checking
> if appropriate driver is assigned to it or not after the of_platform_populate
> call. If it isn't then defer dwc3-qcom probe as well.
>
> Fixes: 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
> Signed-off-by: Krishna Kurapati <[email protected]>

Reported-by: Matthias Kaehlcke <[email protected]>
Tested-by: Matthias Kaehlcke <[email protected]>
Reviewed-by: Matthias Kaehlcke <[email protected]>

Please make sure to add reviewers of previous versions or other folks you
would like to review your patches in cc. I found v2 accidentally while
looking for something else.

2022-07-16 05:06:59

by Krishna Kurapati

[permalink] [raw]
Subject: Re: [PATCH v2] usb: dwc3: qcom: Defer dwc3-qcom probe if dwc3 isn't probed properly


On 7/16/2022 2:11 AM, Matthias Kaehlcke wrote:
> On Fri, Jul 15, 2022 at 06:51:52PM +0530, Krishna Kurapati wrote:
>
>> Subject: usb: dwc3: qcom: Defer dwc3-qcom probe if dwc3 isn't probed properly
> nit: "isn't probed properly" sounds like a bug or HW issue. In case
> you re-spin maybe change it to "hasn't probed yet" or similar.
>
>> On SC7180 devices, it is observed that dwc3 probing is deferred
>> because device_links_check_suppliers() finds that '88e3000.phy'
>> isn't ready yet.
>>
>> As a part of its probe call, dwc3-qcom driver checks if dwc3 core
>> is wakeup capable or not. If the dwc3 core is wakeup capable, driver
>> configures dwc-qcom's power domain to be always ON. Also it configures
>> dp/dm interrupts accordingly to support wakeup from system suspend.
>>
>> More info regarding the same can be found at:
>> commit d9be8d5c5b03 ("usb: dwc3: qcom: Keep power domain on to retain controller status")
>> commit 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")
>>
>> In the event, dwc3 probe gets deferred and is processed after dwc3-qcom
>> probe, driver ends up reading the wakeup capability of dwc3 core as false
>> leading to instability in suspend/resume path.
>>
>> To avoid this scenario, ensure dwc3_probe is successful by checking
>> if appropriate driver is assigned to it or not after the of_platform_populate
>> call. If it isn't then defer dwc3-qcom probe as well.
>>
>> Fixes: 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
>> Signed-off-by: Krishna Kurapati <[email protected]>
> Reported-by: Matthias Kaehlcke <[email protected]>
> Tested-by: Matthias Kaehlcke <[email protected]>
> Reviewed-by: Matthias Kaehlcke <[email protected]>
>
> Please make sure to add reviewers of previous versions or other folks you
> would like to review your patches in cc. I found v2 accidentally while
> looking for something else.
Hi Mathias,
    Sure, Thanks for the review.

2022-07-27 18:36:20

by Matthias Kaehlcke

[permalink] [raw]
Subject: Re: [PATCH v2] usb: dwc3: qcom: Defer dwc3-qcom probe if dwc3 isn't probed properly

On Fri, Jul 15, 2022 at 01:41:57PM -0700, Matthias Kaehlcke wrote:
> On Fri, Jul 15, 2022 at 06:51:52PM +0530, Krishna Kurapati wrote:
>
> > Subject: usb: dwc3: qcom: Defer dwc3-qcom probe if dwc3 isn't probed properly
>
> nit: "isn't probed properly" sounds like a bug or HW issue. In case
> you re-spin maybe change it to "hasn't probed yet" or similar.
>
> > On SC7180 devices, it is observed that dwc3 probing is deferred
> > because device_links_check_suppliers() finds that '88e3000.phy'
> > isn't ready yet.
> >
> > As a part of its probe call, dwc3-qcom driver checks if dwc3 core
> > is wakeup capable or not. If the dwc3 core is wakeup capable, driver
> > configures dwc-qcom's power domain to be always ON. Also it configures
> > dp/dm interrupts accordingly to support wakeup from system suspend.
> >
> > More info regarding the same can be found at:
> > commit d9be8d5c5b03 ("usb: dwc3: qcom: Keep power domain on to retain controller status")
> > commit 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")
> >
> > In the event, dwc3 probe gets deferred and is processed after dwc3-qcom
> > probe, driver ends up reading the wakeup capability of dwc3 core as false
> > leading to instability in suspend/resume path.
> >
> > To avoid this scenario, ensure dwc3_probe is successful by checking
> > if appropriate driver is assigned to it or not after the of_platform_populate
> > call. If it isn't then defer dwc3-qcom probe as well.
> >
> > Fixes: 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
> > Signed-off-by: Krishna Kurapati <[email protected]>
>
> Reported-by: Matthias Kaehlcke <[email protected]>
> Tested-by: Matthias Kaehlcke <[email protected]>
> Reviewed-by: Matthias Kaehlcke <[email protected]>

(attempt to 'summarize' and move the discussion from v1 [1] to here)

gregkh> Why not limit this check to a device type like your changelog mentions?

mka> It is not an sc7180 specific issue. It can occur on any platform where the
mka> dwc3 core has supplies that aren't ready when the dwc3-qcom driver probes.
mka>
mka> It won't blow up right away since it requires 'wakeup-source' to be set for
mka> the dwc3 core, which currently is only the case for 'usb@a600000' of the
mka> sc7280 AFAIK (I set it for sc7180 in my tree for testing, which is when I
mka> found the issue this patch intends to address).

krishna> As Mathias pointed out, no issue was seen so far on present QC targets
krishna> as wakeup-source property was added recently and only for SC7180 and
krishna> SC7280. We ran into some issues like wakeup from system suspend in
krishna> host mode wasn't happening although we enabled wakeup-source in SC7180
krishna> that eventually led us to this bug. But, we tried to add debug prints
krishna> to follow the code flow and see that the issue is present on SM8350
krishna> as well : "supplier 88e9000.phy-wrapper not ready" and deferring dwc3
krishna> probe. This doesn't seem to be specific to SC7180.
krishna>
krishna> Since this is seen on multiple platforms, can we go ahead without
krishna> having any platforms specific checks in the code as in V2 version ?

[1] https://lore.kernel.org/all/[email protected]/t/#m6714bf1f2309cfe8be92e6c270ef2a99a9b09ac6

2022-08-02 16:37:02

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH v2] usb: dwc3: qcom: Defer dwc3-qcom probe if dwc3 isn't probed properly

On Fri, Jul 15, 2022 at 06:51:52PM +0530, Krishna Kurapati wrote:
> On SC7180 devices, it is observed that dwc3 probing is deferred
> because device_links_check_suppliers() finds that '88e3000.phy'
> isn't ready yet.
>
> As a part of its probe call, dwc3-qcom driver checks if dwc3 core
> is wakeup capable or not. If the dwc3 core is wakeup capable, driver
> configures dwc-qcom's power domain to be always ON. Also it configures
> dp/dm interrupts accordingly to support wakeup from system suspend.
>
> More info regarding the same can be found at:
> commit d9be8d5c5b03 ("usb: dwc3: qcom: Keep power domain on to retain controller status")
> commit 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")
>
> In the event, dwc3 probe gets deferred and is processed after dwc3-qcom
> probe, driver ends up reading the wakeup capability of dwc3 core as false
> leading to instability in suspend/resume path.
>
> To avoid this scenario, ensure dwc3_probe is successful by checking
> if appropriate driver is assigned to it or not after the of_platform_populate
> call. If it isn't then defer dwc3-qcom probe as well.
>
> Fixes: 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
> Signed-off-by: Krishna Kurapati <[email protected]>
> ---
> v2: Set return value to EPROBE_DEFER to drop reference to dwc3 node
>
> drivers/usb/dwc3/dwc3-qcom.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> index 7703655..6676b39 100644
> --- a/drivers/usb/dwc3/dwc3-qcom.c
> +++ b/drivers/usb/dwc3/dwc3-qcom.c
> @@ -722,6 +722,9 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
> dev_err(dev, "failed to get dwc3 platform device\n");
> }
>
> + if (!qcom->dwc3->dev.driver)
> + ret = -EPROBE_DEFER;
> +
> node_put:
> of_node_put(dwc3_np);

NAK.

We should not be adding hacks like this to the driver.

There are other ways to avoid this, but please take a look at the
following series which makes the problem identified by this patch go
away first:

https://lore.kernel.org/all/[email protected]

Johan

2022-08-04 04:52:38

by Krishna Kurapati

[permalink] [raw]
Subject: Re: [PATCH v2] usb: dwc3: qcom: Defer dwc3-qcom probe if dwc3 isn't probed properly


On 8/2/2022 9:40 PM, Johan Hovold wrote:
> On Fri, Jul 15, 2022 at 06:51:52PM +0530, Krishna Kurapati wrote:
>> On SC7180 devices, it is observed that dwc3 probing is deferred
>> because device_links_check_suppliers() finds that '88e3000.phy'
>> isn't ready yet.
>>
>> As a part of its probe call, dwc3-qcom driver checks if dwc3 core
>> is wakeup capable or not. If the dwc3 core is wakeup capable, driver
>> configures dwc-qcom's power domain to be always ON. Also it configures
>> dp/dm interrupts accordingly to support wakeup from system suspend.
>>
>> More info regarding the same can be found at:
>> commit d9be8d5c5b03 ("usb: dwc3: qcom: Keep power domain on to retain controller status")
>> commit 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")
>>
>> In the event, dwc3 probe gets deferred and is processed after dwc3-qcom
>> probe, driver ends up reading the wakeup capability of dwc3 core as false
>> leading to instability in suspend/resume path.
>>
>> To avoid this scenario, ensure dwc3_probe is successful by checking
>> if appropriate driver is assigned to it or not after the of_platform_populate
>> call. If it isn't then defer dwc3-qcom probe as well.
>>
>> Fixes: 649f5c842ba3 ("usb: dwc3: core: Host wake up support from system suspend")
>> Signed-off-by: Krishna Kurapati <[email protected]>
>> ---
>> v2: Set return value to EPROBE_DEFER to drop reference to dwc3 node
>>
>> drivers/usb/dwc3/dwc3-qcom.c | 3 +++
>> 1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
>> index 7703655..6676b39 100644
>> --- a/drivers/usb/dwc3/dwc3-qcom.c
>> +++ b/drivers/usb/dwc3/dwc3-qcom.c
>> @@ -722,6 +722,9 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
>> dev_err(dev, "failed to get dwc3 platform device\n");
>> }
>>
>> + if (!qcom->dwc3->dev.driver)
>> + ret = -EPROBE_DEFER;
>> +
>> node_put:
>> of_node_put(dwc3_np);
> NAK.
>
> We should not be adding hacks like this to the driver.
>
> There are other ways to avoid this, but please take a look at the
> following series which makes the problem identified by this patch go
> away first:
>
> https://lore.kernel.org/all/[email protected]
>
> Johan
Hi Johan,

 Thanks for the review and patches. Agreed that if we are moving
wakeup-source to glue driver, dwc3 probe getting deferred won't be an issue.

Regards,
Krishna,