mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Peter Chen (Qualcomm)" <peter.chen@kernel.org>
To: Mario Behn <mario.behn@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Clark Williams <clrkwllms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH] usb: chipidea: udc: give up when the endpoint halt bit is not taken
Date: Wed, 25 Nov 2026 19:13:37 -0800	[thread overview]
Message-ID: <awej4edcffKnljdt@hu-petche-lv.qualcomm.com> (raw)
In-Reply-To: <20261105205343.982465-1-mario.behn@gmail.com>

On 26-11-05 21:53:42, Mario Behn wrote:
> hw_ep_set_halt() writes the stall bit of an endpoint and loops until it
> reads back. On endpoint 0 the controller clears the stall bit itself when
> a SETUP packet arrives, so when one arrives while the driver stalls the
> endpoint the loop never ends. It runs in the UDC interrupt thread with the
> controller lock held, and the SETUP packet it is waiting out can only be
> consumed by that same thread.
> 
> Seen on a Zynq-7000 (an ADALM-PLUTO class board, PREEMPT_RT) during the
> host RNDIS initialisation: the gadget stalls the GET_ENCAPSULATED_RESPONSE
> poll that has no answer yet, the stall is refused, the interrupt thread
> spins for a minute, RCU stalls and every other USB operation blocks on the
> lock. With a bounded loop the condition shows on 1 to 3 percent of boots
> and is harmless: the pending SETUP packet is handled next and the host
> repeats its poll.
> 
> Retry for about a millisecond, then warn with the endpoint control and
> setup status registers and return -EBUSY. The callers already report a
> failed stall.
> 
> A loop timeout for the same hang was proposed in 2021 (usb: chipidea: add
> loop timeout for hw_ep_set_halt(), Jeaho Hwang) and not applied.
> 
> Signed-off-by: Mario Behn <mario.behn@gmail.com>

Please add Fixes tag and Cc to stable tree.

Peter
> ---
>  drivers/usb/chipidea/udc.c | 22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> index d52f89489893..4f4e6d296de5 100644
> --- a/drivers/usb/chipidea/udc.c
> +++ b/drivers/usb/chipidea/udc.c
> @@ -224,20 +224,28 @@ static int hw_ep_prime(struct ci_hdrc *ci, int num, int dir, int is_ctrl)
>   */
>  static int hw_ep_set_halt(struct ci_hdrc *ci, int num, int dir, int value)
>  {
> +	enum ci_hw_regs reg = OP_ENDPTCTRL + num;
> +	u32 mask_xs = (dir == TX) ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
> +	u32 mask_xr = (dir == TX) ? ENDPTCTRL_TXR : ENDPTCTRL_RXR;
> +	int retries = 1000;
> +
>  	if (value != 0 && value != 1)
>  		return -EINVAL;
>  
>  	do {
> -		enum ci_hw_regs reg = OP_ENDPTCTRL + num;
> -		u32 mask_xs = (dir == TX) ? ENDPTCTRL_TXS : ENDPTCTRL_RXS;
> -		u32 mask_xr = (dir == TX) ? ENDPTCTRL_TXR : ENDPTCTRL_RXR;
> -
>  		/* data toggle - reserved for EP0 but it's in ESS */
>  		hw_write(ci, reg, mask_xs|mask_xr,
>  			  value ? mask_xs : mask_xr);
> -	} while (value != hw_ep_get_halt(ci, num, dir));
> -
> -	return 0;
> +		if (value == hw_ep_get_halt(ci, num, dir))
> +			return 0;
> +		udelay(1);
> +	} while (--retries);
> +
> +	dev_warn_ratelimited(ci->dev,
> +			     "ep%d%s: halt=%d not taken, ENDPTCTRL 0x%08x ENDPTSETUPSTAT 0x%08x\n",
> +			     num, dir == TX ? "in" : "out", value, hw_read(ci, reg, ~0),
> +			     hw_read(ci, OP_ENDPTSETUPSTAT, ~0));
> +	return -EBUSY;
>  }
>  
>  /**
> -- 
> 2.53.0
> 

-- 

Thanks,
Peter Chen

      parent reply	other threads:[~2026-11-26  3:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 20:53 Mario Behn
2026-11-09 20:01 ` sashiko-bot
2026-11-26  3:13 ` Peter Chen (Qualcomm) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awej4edcffKnljdt@hu-petche-lv.qualcomm.com \
    --to=peter.chen@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=clrkwllms@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=linux-usb@vger.kernel.org \
    --cc=mario.behn@gmail.com \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®