From: "Carlo Caione" <ccaione@baylibre.com>
To: "Marek Vasut" <marek.vasut@mailbox.org>,
"Carlo Caione" <ccaione@baylibre.com>,
"GSS_MTK_Uboot_upstream" <GSS_MTK_Uboot_upstream@mediatek.com>,
"Bin Meng" <bmeng.cn@gmail.com>,
"Chunfeng Yun" <chunfeng.yun@mediatek.com>,
<u-boot@lists.denx.de>
Cc: "Ryder Lee" <ryder.lee@mediatek.com>,
"Weijie Gao" <weijie.gao@mediatek.com>,
"Igor Belwon" <igor.belwon@mentallysanemainliners.org>,
"David Lechner" <dlechner@baylibre.com>,
"Julien Stephan" <jstephan@baylibre.com>,
"Marek Vasut" <marex@denx.de>, "Tom Rini" <trini@konsulko.com>,
"Lukasz Majewski" <lukma@denx.de>,
"Mattijs Korpershoek" <mkorpershoek@kernel.org>,
"Vitor Sato Eschholz" <vsatoes@baylibre.com>
Subject: Re: [PATCH v2] usb: mtu3: wait for TX FIFO to drain before disconnect
Date: Mon, 20 Jul 2026 09:32:54 +0200 [thread overview]
Message-ID: <DK382N861VQO.19D7SQAQ19GEW@baylibre.com> (raw)
In-Reply-To: <6f37728a-901b-4f39-9923-3852cbe95061@mailbox.org>
On Sat Jul 18, 2026 at 10:17 PM CEST, Marek Vasut wrote:
> On 7/18/26 12:37 PM, Carlo Caione wrote:
>
> [...]
>
>> +static int mtu3_wait_for_tx_fifo_empty(struct mtu3 *mtu)
>> +{
>> + struct mtu3_ep *mep;
>> + u32 value;
>> + int ret = 0;
>> + int i;
>> +
>> + for (i = 1; i < mtu->num_eps; i++) {
>> + mep = mtu->in_eps + i;
>> + if (!(mep->flags & MTU3_EP_ENABLED) ||
>> + !list_empty(&mep->req_list))
>> + continue;
>> +
>> + if (readl_poll_timeout(mtu->mac_base + MU3D_EP_TXCR0(i),
>> + value, value & TX_FIFOEMPTY,
>> + MTU3_TX_FIFO_DRAIN_TIMEOUT_US)) {
>> + dev_warn(mtu->dev, "%s TX FIFO did not drain\n",
>> + mep->name);
>> + mtu3_ep_reset(mep);
>> + ret = -ETIMEDOUT;
>
> You could get the ETIMEDOUT return value from readl_poll_timeout().
fair enough.
>> + }
>> + }
>> +
>> + return ret;
>> +}
>> +
>> /* set/clear the stall and toggle bits for non-ep0 */
>> void mtu3_ep_stall_set(struct mtu3_ep *mep, bool set)
>> {
>> @@ -261,8 +290,14 @@ void mtu3_ep_stall_set(struct mtu3_ep *mep, bool set)
>> set ? "SEND STALL" : "CLEAR STALL, with EP RESET");
>> }
>>
>> -void mtu3_dev_on_off(struct mtu3 *mtu, int is_on)
>> +int mtu3_dev_on_off(struct mtu3 *mtu, int is_on)
>> {
>> + int ret = 0;
>> +
>> + /* QMU completion may precede transmission from the TX FIFO. */
>> + if (!is_on)
>> + ret = mtu3_wait_for_tx_fifo_empty(mtu);
>
> Shouldn't this bail early on ret != 0 ?
No, disconnect must still be forced after resetting a timed-out endpoint
(we still want to disconnect it, even forcefully)
cheers,
--
Carlo Caione
next prev parent reply other threads:[~2026-07-20 7:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 10:37 [PATCH v2] usb: mtu3: wait for TX FIFO to drain before disconnect Carlo Caione
2026-07-18 20:17 ` Marek Vasut
2026-07-20 7:32 ` Carlo Caione [this message]
[not found] ` <3acd7279-8baa-47b5-b384-425bde8a9d1f@mailbox.org>
2026-07-21 5:54 ` Carlo Caione via U-Boot
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=DK382N861VQO.19D7SQAQ19GEW@baylibre.com \
--to=ccaione@baylibre.com \
--cc=GSS_MTK_Uboot_upstream@mediatek.com \
--cc=bmeng.cn@gmail.com \
--cc=chunfeng.yun@mediatek.com \
--cc=dlechner@baylibre.com \
--cc=igor.belwon@mentallysanemainliners.org \
--cc=jstephan@baylibre.com \
--cc=lukma@denx.de \
--cc=marek.vasut@mailbox.org \
--cc=marex@denx.de \
--cc=mkorpershoek@kernel.org \
--cc=ryder.lee@mediatek.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=vsatoes@baylibre.com \
--cc=weijie.gao@mediatek.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.