[PATCH 1/2] usb: dwc2: handle NAK when CHHLTD does not fire

Ahmad Fatoum a.fatoum at pengutronix.de
Mon Apr 20 04:32:25 PDT 2026


Hello,

On 4/20/26 1:20 PM, Sascha Hauer wrote:
> From: Sascha Hauer <sascha at saschahauer.de>
> 
> Some DWC2 configurations do not assert CHHLTD when a NAK is received;
> the hardware keeps the channel active and only sets the NAK bit in HCINT.
> wait_for_chhltd() polls for CHHLTD with a 10ms timeout; when CHHLTD never
> fires the timeout expires and -ETIMEDOUT is returned without inspecting
> HCINT. This causes the caller to treat the NAK as a hard error instead of
> a retryable condition.
> 
> The symptom is that devices which NAK bulk or control transfers during
> initialisation (e.g. some Samsung USB-C flash drives that NAK while their
> firmware starts up) fail immediately rather than being retried via the
> 5-second NAK-retry loop in dwc2_submit_bulk_msg() or the do/while loops
> in dwc2_submit_control_msg().
> 
> Fix by reading HCINT before aborting the channel when the CHHLTD timeout
> fires. If the NAK or FRMOVRUN bit is set, abort the channel, wait for the
> abort to complete, and return -EAGAIN so that the existing retry logic can
> handle the NAK. Log a diagnostic message if the channel abort itself times
> out, which would indicate a real hardware problem.

How does this relate to
https://lore.barebox.org/barebox/20260331034819.227094-1-chalianis1@gmail.com/

Do we need both? Only this one? Is there something over there, which you
would want in your series?

Thanks,
Ahmad

> 
> Co-Authored-By: Claude Sonnet 4.6 <noreply at anthropic.com>
> Signed-off-by: Sascha Hauer <sascha at saschahauer.de>
> ---
>  drivers/usb/dwc2/host.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc2/host.c b/drivers/usb/dwc2/host.c
> index 93994f0be3..ddad51c882 100644
> --- a/drivers/usb/dwc2/host.c
> +++ b/drivers/usb/dwc2/host.c
> @@ -134,9 +134,14 @@ static int wait_for_chhltd(struct dwc2 *dwc2, u8 hc, uint32_t *sub, u8 *tgl)
>  
>  	ret = dwc2_wait_bit_set(dwc2, HCINT(hc), HCINTMSK_CHHLTD, 10000);
>  	if (ret) {
> +		hcint = dwc2_readl(dwc2, HCINT(hc));
>  		hcchar = dwc2_readl(dwc2, HCCHAR(hc));
>  		dwc2_writel(dwc2, hcchar | HCCHAR_CHDIS, HCCHAR(hc));
> -		dwc2_wait_bit_set(dwc2, HCINT(hc), HCINTMSK_CHHLTD, 10000);
> +		if (dwc2_wait_bit_set(dwc2, HCINT(hc), HCINTMSK_CHHLTD, 10000))
> +			dwc2_err(dwc2, "%s: channel abort timed out: HCINT=%08x HCCHAR=%08x\n",
> +				 __func__, hcint, hcchar);
> +		if (hcint & (HCINTMSK_NAK | HCINTMSK_FRMOVRUN))
> +			return -EAGAIN;
>  		return ret;
>  	}
>  
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |




More information about the barebox mailing list