[PATCH RFC 05/22] usb: dwc3: apple: Do not use host-vbus-glitches workaround

Sven Peter posted 22 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH RFC 05/22] usb: dwc3: apple: Do not use host-vbus-glitches workaround
Posted by Sven Peter 1 month, 1 week ago
From: Janne Grunau <j@jannau.net>

It results in SErrors during init presumedly because MMIO accesses fail
while certain parts are shutdown.

Signed-off-by: Janne Grunau <j@jannau.net>
Signed-off-by: Sven Peter <sven@kernel.org>
---
 drivers/usb/dwc3/core.c | 1 +
 drivers/usb/dwc3/core.h | 2 ++
 drivers/usb/dwc3/host.c | 5 ++++-
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 26aa507a738f001409a97ef563c6561433a1cac5..8d2dc7fa18114102cc8893c4ca0e745e16f30754 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -2273,6 +2273,7 @@ int dwc3_core_probe(const struct dwc3_probe_data *data)
 
 			dwc->dr_mode = USB_DR_MODE_OTG;
 			dwc->role_switch_reset_quirk = true;
+			dwc->no_early_roothub_poweroff = true;
 		}
 	}
 
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 38f32f2a6193c1b2662ab4f38f4d20cf4b0e198d..3c3a36ec37345b2f9e71444ba3b90b52dbd24443 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1155,6 +1155,7 @@ struct dwc3_scratchpad_array {
  * @susphy_state: state of DWC3_GUSB2PHYCFG_SUSPHY + DWC3_GUSB3PIPECTL_SUSPHY
  *		  before PM suspend.
  * @role_switch_reset_quirk: set to force reinitialization after any role switch
+ * @no_early_roothub_poweroff: set to skip early root hub port power off
  * @imod_interval: set the interrupt moderation interval in 250ns
  *			increments or 0 to disable.
  * @max_cfg_eps: current max number of IN eps used across all USB configs.
@@ -1394,6 +1395,7 @@ struct dwc3 {
 	unsigned		susphy_state:1;
 
 	unsigned		role_switch_reset_quirk:1;
+	unsigned		no_early_roothub_poweroff:1;
 
 	u16			imod_interval;
 
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index f7a71e6f9d80aca632f1f970d900a3de8a76f0a7..f7c3a0fc5fe258705311f89c1ba11ff599c01afe 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -134,8 +134,11 @@ int dwc3_host_init(struct dwc3 *dwc)
 	/*
 	 * Some platforms need to power off all Root hub ports immediately after DWC3 set to host
 	 * mode to avoid VBUS glitch happen when xhci get reset later.
+	 * On Apple platforms we must not touch any MMIO yet because dwc3
+	 * will not work correctly before its PHY has been initialized.
 	 */
-	dwc3_power_off_all_roothub_ports(dwc);
+	if (!dwc->no_early_roothub_poweroff)
+		dwc3_power_off_all_roothub_ports(dwc);
 
 	irq = dwc3_host_get_irq(dwc);
 	if (irq < 0)

-- 
2.34.1
Re: [PATCH RFC 05/22] usb: dwc3: apple: Do not use host-vbus-glitches workaround
Posted by Thinh Nguyen 1 month, 1 week ago
On Thu, Aug 21, 2025, Sven Peter wrote:
> From: Janne Grunau <j@jannau.net>
> 
> It results in SErrors during init presumedly because MMIO accesses fail
> while certain parts are shutdown.
> 
> Signed-off-by: Janne Grunau <j@jannau.net>
> Signed-off-by: Sven Peter <sven@kernel.org>
> ---
>  drivers/usb/dwc3/core.c | 1 +
>  drivers/usb/dwc3/core.h | 2 ++
>  drivers/usb/dwc3/host.c | 5 ++++-
>  3 files changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 26aa507a738f001409a97ef563c6561433a1cac5..8d2dc7fa18114102cc8893c4ca0e745e16f30754 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -2273,6 +2273,7 @@ int dwc3_core_probe(const struct dwc3_probe_data *data)
>  
>  			dwc->dr_mode = USB_DR_MODE_OTG;
>  			dwc->role_switch_reset_quirk = true;
> +			dwc->no_early_roothub_poweroff = true;
>  		}
>  	}
>  
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 38f32f2a6193c1b2662ab4f38f4d20cf4b0e198d..3c3a36ec37345b2f9e71444ba3b90b52dbd24443 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1155,6 +1155,7 @@ struct dwc3_scratchpad_array {
>   * @susphy_state: state of DWC3_GUSB2PHYCFG_SUSPHY + DWC3_GUSB3PIPECTL_SUSPHY
>   *		  before PM suspend.
>   * @role_switch_reset_quirk: set to force reinitialization after any role switch
> + * @no_early_roothub_poweroff: set to skip early root hub port power off
>   * @imod_interval: set the interrupt moderation interval in 250ns
>   *			increments or 0 to disable.
>   * @max_cfg_eps: current max number of IN eps used across all USB configs.
> @@ -1394,6 +1395,7 @@ struct dwc3 {
>  	unsigned		susphy_state:1;
>  
>  	unsigned		role_switch_reset_quirk:1;
> +	unsigned		no_early_roothub_poweroff:1;
>  
>  	u16			imod_interval;
>  
> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
> index f7a71e6f9d80aca632f1f970d900a3de8a76f0a7..f7c3a0fc5fe258705311f89c1ba11ff599c01afe 100644
> --- a/drivers/usb/dwc3/host.c
> +++ b/drivers/usb/dwc3/host.c
> @@ -134,8 +134,11 @@ int dwc3_host_init(struct dwc3 *dwc)
>  	/*
>  	 * Some platforms need to power off all Root hub ports immediately after DWC3 set to host
>  	 * mode to avoid VBUS glitch happen when xhci get reset later.
> +	 * On Apple platforms we must not touch any MMIO yet because dwc3
> +	 * will not work correctly before its PHY has been initialized.

This doesn't make sense, the phy should've been initialized by this
point. We already access MMIO before this. Even your [PATCH RFC 7/22]
attempts to access MMIO before this, yet accessing here causes problem.
Do we know when the phy get initialized then?

BR,
Thinh

>  	 */
> -	dwc3_power_off_all_roothub_ports(dwc);
> +	if (!dwc->no_early_roothub_poweroff)
> +		dwc3_power_off_all_roothub_ports(dwc);
>  
>  	irq = dwc3_host_get_irq(dwc);
>  	if (irq < 0)
> 
> -- 
> 2.34.1
> 
> 
Re: [PATCH RFC 05/22] usb: dwc3: apple: Do not use host-vbus-glitches workaround
Posted by Sven Peter 1 month, 1 week ago
On 22.08.25 00:28, Thinh Nguyen wrote:
> On Thu, Aug 21, 2025, Sven Peter wrote:
>> From: Janne Grunau <j@jannau.net>

[...]

>>   	/*
>>   	 * Some platforms need to power off all Root hub ports immediately after DWC3 set to host
>>   	 * mode to avoid VBUS glitch happen when xhci get reset later.
>> +	 * On Apple platforms we must not touch any MMIO yet because dwc3
>> +	 * will not work correctly before its PHY has been initialized.
> 
> This doesn't make sense, the phy should've been initialized by this
> point. We already access MMIO before this. Even your [PATCH RFC 7/22]
> attempts to access MMIO before this, yet accessing here causes problem.
> Do we know when the phy get initialized then?

You're absolutely right, this doesn't make any sense!

dwc3_power_off_all_roothub_ports uses ioremap which will map the XHCI 
region as Device-nGnRE. That just doesn't work on these machines and 
actually explains the SErrors.
Resources on these machines generally have the IORESOURCE_MEM_NONPOSTED 
flag set (via the nonposted-mmio dt property) and then use ioremap_np to 
map them using Device-nGnRnE.


Best,


Sven
Re: [PATCH RFC 05/22] usb: dwc3: apple: Do not use host-vbus-glitches workaround
Posted by Thinh Nguyen 1 month ago
On Sat, Aug 23, 2025, Sven Peter wrote:
> On 22.08.25 00:28, Thinh Nguyen wrote:
> > On Thu, Aug 21, 2025, Sven Peter wrote:
> > > From: Janne Grunau <j@jannau.net>
> 
> [...]
> 
> > >   	/*
> > >   	 * Some platforms need to power off all Root hub ports immediately after DWC3 set to host
> > >   	 * mode to avoid VBUS glitch happen when xhci get reset later.
> > > +	 * On Apple platforms we must not touch any MMIO yet because dwc3
> > > +	 * will not work correctly before its PHY has been initialized.
> > 
> > This doesn't make sense, the phy should've been initialized by this
> > point. We already access MMIO before this. Even your [PATCH RFC 7/22]
> > attempts to access MMIO before this, yet accessing here causes problem.
> > Do we know when the phy get initialized then?
> 
> You're absolutely right, this doesn't make any sense!
> 
> dwc3_power_off_all_roothub_ports uses ioremap which will map the XHCI region
> as Device-nGnRE. That just doesn't work on these machines and actually
> explains the SErrors.
> Resources on these machines generally have the IORESOURCE_MEM_NONPOSTED flag
> set (via the nonposted-mmio dt property) and then use ioremap_np to map them
> using Device-nGnRnE.
> 

Ok. So the failure does not seem to be because the phy hasn't been
initialized yet, but it's because of io mapping.

Did you try to check against IORESOURCE_MEM_NONPOSTED to use ioremap_np
instead? That keeps the logic consistent between different platforms.

BR,
Thinh