From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Wesley Cheng <wcheng@codeaurora.org>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Wesley Cheng <quic_wcheng@quicinc.com>,
"balbi@kernel.org" <balbi@kernel.org>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"quic_jackp@quicinc.com" <quic_jackp@quicinc.com>
Subject: Re: [RFC PATCH v2 1/3] usb: dwc3: Flush pending SETUP data during stop active xfers
Date: Thu, 24 Mar 2022 00:39:06 +0000 [thread overview]
Message-ID: <e2a15c5e-f437-3dfb-6c49-a97a094eaaae@synopsys.com> (raw)
In-Reply-To: <469213d0-526a-e26e-88c2-b34b2aa8dfe7@codeaurora.org>
Hi Wesley,
Wesley Cheng wrote:
> Hi Thinh,
>
> On 3/22/2022 6:31 PM, Thinh Nguyen wrote:
>> Hi Wesley,
>>
>> Wesley Cheng wrote:
>>> Hi Thinh,
>>>
>>> On 2/15/2022 4:08 PM, Wesley Cheng wrote:
>>>> While running the pullup disable sequence, if there are pending SETUP
>>>> transfers stored in the controller, then the ENDTRANSFER commands on non
>>>> control eps will fail w/ ETIMEDOUT. As a suggestion from SNPS, in order
>>>> to drain potentially cached SETUP packets, SW needs to issue a
>>>> STARTTRANSFER command. After issuing the STARTTRANSFER, and retrying the
>>>> ENDTRANSFER, the command should succeed. Else, if the endpoints are not
>>>> properly stopped, the controller halt sequence will fail as well.
>>>>
>>>> One limitation is that the current logic will drop the SETUP data
>>>> being received (ie dropping the SETUP packet), however, it should be
>>>> acceptable in the pullup disable case, as the device is eventually
>>>> going to disconnect from the host.
>>>>
>>>> Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
>>>> ---
>>> Just wondering if you had any inputs for this particular change? I
>>> think on the dequeue path discussion you had some concerns with parts of
>>> this change? I think the difficult part for the pullup disable path is
>>> that we have this API running w/ interrupts disabled, so the EP0 state
>>> won't be able to advance compared to the dequeue case.
>>
>> This doesn't sound right. The pullup disable (or device initiated
>> disconnect) should wait for the EP0 state to be EP0_SETUP_PHASE before
>> proceeding, which it does.
>>
> That is correct, but even though that check is passed, it doesn't
> prevent the host from sending another SETUP token between the pending
> setup packet check and run/stop clear.
>
That should be fine, because we would have the TRB ready for that SETUP
packet.
>>>
>>> Ideally, if there is a way to ensure that we avoid reading further setup
>>> packets, that would be nice, but from our discussions with Synopsys,
>>> this was not possible. (controller is always armed and ready to ACK
>>> setup tokens)
>>>
>>> I did evaluate keeping IRQs enabled and periodically releasing/attaining
>>> the lock between the stop active xfer calls, but that opened another can
>>> of worms. If you think this is the approach we should take, I can take
>>> a look at this implementation further.
>>>
>>
>> This patch doesn't look right to me. The change I suggested before
>> should address this (I believe Greg already picked it up). What other
>> problem do you see, I'm not clear what's the problem here. One potential
>> problem that I can see is that currently dwc3 driver doesn't wait for
>> active endpoints to complete/end before clearing the run_stop bit on
>> device initiated disconnect, but I'm not sure if that's what you're seeing.
>>
>> Please help clarify further. If there's trace points log, that'd help.
>>
> Main difference between the issue Greg recently pulled in and this one
> is that this is on the pullup disable patch (no dequeue involved). In
> this situation we will also stop active transfers, so that the
> controller can halt properly.
>
> I attached a few files, and will give a summary of them below:
> 1. pullup_disable_timeout.txt - ftrace of an instance of when we see
> several endxfer timeouts. Refer to line#2016.
>
> 2. lecroy+ftrace_snip.png - picture showing a matching bus sniffer log
> and a ftrace collected (difference instance to #1)
>
> #2 will show that we completed a SETUP transfer before entering into
> dwc3_gadget_stop_active_transfers(). In here, we then see DWC ACK
> another SETUP token, which leads to endxfer timeouts on all subsequent
> endpoints.
Thanks for the captures. I think the problem here is because the dwc3
driver disables the control endpoint. It shouldn't do that.
Can you try this:
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index ab725d2262d6..f0b9ea353620 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1010,12 +1010,12 @@ static int __dwc3_gadget_ep_disable(struct
dwc3_ep *dep)
if (dep->flags & DWC3_EP_STALL)
__dwc3_gadget_ep_set_halt(dep, 0, false);
- reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
- reg &= ~DWC3_DALEPENA_EP(dep->number);
- dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
-
- /* Clear out the ep descriptors for non-ep0 */
if (dep->number > 1) {
+ reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
+ reg &= ~DWC3_DALEPENA_EP(dep->number);
+ dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
+
+ /* Clear out the ep descriptors for non-ep0 */
dep->endpoint.comp_desc = NULL;
dep->endpoint.desc = NULL;
}
Thanks,
Thinh
next prev parent reply other threads:[~2022-03-24 0:39 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-16 0:08 [RFC PATCH v2 0/3] Fix enumeration issues during composition switching Wesley Cheng
2022-02-16 0:08 ` [RFC PATCH v2 1/3] usb: dwc3: Flush pending SETUP data during stop active xfers Wesley Cheng
2022-03-22 18:21 ` Wesley Cheng
2022-03-23 1:31 ` Thinh Nguyen
[not found] ` <469213d0-526a-e26e-88c2-b34b2aa8dfe7@codeaurora.org>
2022-03-24 0:39 ` Thinh Nguyen [this message]
2022-03-24 2:19 ` Thinh Nguyen
2022-03-24 18:53 ` Wesley Cheng
2022-03-25 1:51 ` Thinh Nguyen
2022-03-25 18:35 ` Wesley Cheng
2022-04-01 19:31 ` Wesley Cheng
2022-04-04 23:32 ` Thinh Nguyen
2022-02-16 0:08 ` [RFC PATCH v2 2/3] usb: dwc3: gadget: Wait for ep0 xfers to complete during dequeue Wesley Cheng
2022-02-16 0:08 ` [RFC PATCH v2 3/3] usb: dwc3: Issue core soft reset before enabling run/stop Wesley Cheng
2022-02-17 5:52 ` Jung Daehwan
2022-02-17 9:43 ` Jung Daehwan
2022-02-17 19:01 ` Wesley Cheng
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=e2a15c5e-f437-3dfb-6c49-a97a094eaaae@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=quic_jackp@quicinc.com \
--cc=quic_wcheng@quicinc.com \
--cc=wcheng@codeaurora.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