[v2,1/2] usb: ulpi: defer ulpi_register on ulpi_read_id timeout

Message ID 20221110211132.297512-2-ftoth@exalondelft.nl
State New
Headers
Series usb: dwc3: core: defer probe on ulpi_read_id timeout |

Commit Message

Ferry Toth Nov. 10, 2022, 9:11 p.m. UTC
  Since commit 0f010171
Dual Role support on Intel Merrifield platform broke due to rearranging
the call to dwc3_get_extcon().

It appears to be caused by ulpi_read_id() on the first test write failing
with -ETIMEDOUT. Currently ulpi_read_id() expects to discover the phy via
DT when the test write fails and returns 0 in that case even if DT does not
provide the phy. As a result usb probe completes without phy.

Signed-off-by: Ferry Toth <ftoth@exalondelft.nl>
---
 drivers/usb/common/ulpi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Greg KH Nov. 11, 2022, 6:08 a.m. UTC | #1
On Thu, Nov 10, 2022 at 10:11:31PM +0100, Ferry Toth wrote:
> Since commit 0f010171
> Dual Role support on Intel Merrifield platform broke due to rearranging
> the call to dwc3_get_extcon().

Please see the kernel documentation for how to refer to commits.  This
should be written as:

	Since commit 0f0101719138 ("usb: dwc3: Don't switch OTG -> peripheral if
	extcon is present"), Dual role....

> It appears to be caused by ulpi_read_id() on the first test write failing
> with -ETIMEDOUT. Currently ulpi_read_id() expects to discover the phy via
> DT when the test write fails and returns 0 in that case even if DT does not
> provide the phy. As a result usb probe completes without phy.
> 
> Signed-off-by: Ferry Toth <ftoth@exalondelft.nl>

What commit does this fix?

Should this also get a cc: stable?

thanks,

greg k-h
  
Ferry Toth Nov. 11, 2022, 2:04 p.m. UTC | #2
+ Stephen Boyd

On 10-11-2022 22:11, Ferry Toth wrote:
> Since commit 0f010171
> Dual Role support on Intel Merrifield platform broke due to rearranging
> the call to dwc3_get_extcon().
> 
> It appears to be caused by ulpi_read_id() on the first test write failing
> with -ETIMEDOUT. Currently ulpi_read_id() expects to discover the phy via
> DT when the test write fails and returns 0 in that case even if DT does not
> provide the phy. As a result usb probe completes without phy.
> 
> Signed-off-by: Ferry Toth <ftoth@exalondelft.nl>
> ---
>   drivers/usb/common/ulpi.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
> index d7c8461976ce..60e8174686a1 100644
> --- a/drivers/usb/common/ulpi.c
> +++ b/drivers/usb/common/ulpi.c
> @@ -207,7 +207,7 @@ static int ulpi_read_id(struct ulpi *ulpi)
>   	/* Test the interface */
>   	ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa);
>   	if (ret < 0)
> -		goto err;
> +		return ret;
>   
>   	ret = ulpi_read(ulpi, ULPI_SCRATCH);
>   	if (ret < 0)

Would this affect others phys (like qcom HSIC)? I'm not sure if failing 
the test write is a normal behavior.
  
Ferry Toth Nov. 14, 2022, 9:55 p.m. UTC | #3
Op 11-11-2022 om 07:08 schreef Greg Kroah-Hartman:
> On Thu, Nov 10, 2022 at 10:11:31PM +0100, Ferry Toth wrote:
>> Since commit 0f010171
>> Dual Role support on Intel Merrifield platform broke due to rearranging
>> the call to dwc3_get_extcon().
> 
> Please see the kernel documentation for how to refer to commits.  This
> should be written as:
> 
> 	Since commit 0f0101719138 ("usb: dwc3: Don't switch OTG -> peripheral if
> 	extcon is present"), Dual role....

Thanks I'll fix that in v3.

>> It appears to be caused by ulpi_read_id() on the first test write failing
>> with -ETIMEDOUT. Currently ulpi_read_id() expects to discover the phy via
>> DT when the test write fails and returns 0 in that case even if DT does not
>> provide the phy. As a result usb probe completes without phy.
>>
>> Signed-off-by: Ferry Toth <ftoth@exalondelft.nl>
> 
> What commit does this fix?

It's complicated, not sure how to explain this clearly:
ef6a7bcfb01c ("usb: ulpi: Support device discovery via DT") started to 
hide -ETIMEDOUT by returning 0. That problem was hidden due to another
problem causing dwc3 to be deferred. But not properly, causing an 
infinite probe loop. This was fixed for quite some time by an out of 
tree patch. Now 0f0101719138 ("usb: dwc3: Don't switch OTG -> peripheral 
if extcon is present") accidentally fixes the probe loop, makes the out 
tree patch obsolete, but exposes the initial problem.

In short this patch fixes ef6a7bcfb01c ("usb: ulpi: Support device 
discovery via DT") by returning -ETIMEDOUT to its user, who should 
handle it appropriately. In case of dwc3 probe it sets -EPROBE_DEFER and 
bails out.

I'll add the short fixes: in v3.

> Should this also get a cc: stable?

I will add.

> thanks,
> 
> greg k-h
  
Stephen Boyd Dec. 12, 2022, 9:51 p.m. UTC | #4
Quoting Ferry Toth (2022-11-11 06:04:16)
> + Stephen Boyd
> 
> On 10-11-2022 22:11, Ferry Toth wrote:
> > Since commit 0f010171
> > Dual Role support on Intel Merrifield platform broke due to rearranging
> > the call to dwc3_get_extcon().
> > 
> > It appears to be caused by ulpi_read_id() on the first test write failing
> > with -ETIMEDOUT. Currently ulpi_read_id() expects to discover the phy via
> > DT when the test write fails and returns 0 in that case even if DT does not
> > provide the phy. As a result usb probe completes without phy.
> > 
> > Signed-off-by: Ferry Toth <ftoth@exalondelft.nl>
> > ---
> >   drivers/usb/common/ulpi.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
> > index d7c8461976ce..60e8174686a1 100644
> > --- a/drivers/usb/common/ulpi.c
> > +++ b/drivers/usb/common/ulpi.c
> > @@ -207,7 +207,7 @@ static int ulpi_read_id(struct ulpi *ulpi)
> >       /* Test the interface */
> >       ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa);
> >       if (ret < 0)
> > -             goto err;
> > +             return ret;
> >   
> >       ret = ulpi_read(ulpi, ULPI_SCRATCH);
> >       if (ret < 0)
> 
> Would this affect others phys (like qcom HSIC)? I'm not sure if failing 
> the test write is a normal behavior.

I don't think failing a test write is normal behavior. I don't have this
hardware on hand anymore though, so I can't help test it. Looks OK to me
though:

Reviewed-by: Stephen Boyd <sboyd@kernel.org>
  

Patch

diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
index d7c8461976ce..60e8174686a1 100644
--- a/drivers/usb/common/ulpi.c
+++ b/drivers/usb/common/ulpi.c
@@ -207,7 +207,7 @@  static int ulpi_read_id(struct ulpi *ulpi)
 	/* Test the interface */
 	ret = ulpi_write(ulpi, ULPI_SCRATCH, 0xaa);
 	if (ret < 0)
-		goto err;
+		return ret;
 
 	ret = ulpi_read(ulpi, ULPI_SCRATCH);
 	if (ret < 0)