linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wesley Cheng <wcheng@codeaurora.org>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Wesley Cheng <quic_wcheng@quicinc.com>,
	Jung Daehwan <dh10.jung@samsung.com>
Cc: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>,
	"quic_jackp@quicinc.com" <quic_jackp@quicinc.com>
Subject: Re: [PATCH v2 1/2] usb: dwc3: Not set DWC3_EP_END_TRANSFER_PENDING in ep cmd fails
Date: Mon, 7 Mar 2022 14:57:50 -0800	[thread overview]
Message-ID: <1238af3f-3110-a1f2-808c-3c07282b4f14@codeaurora.org> (raw)
In-Reply-To: <594fbaf7-d9f0-a3a0-e660-880e12418282@synopsys.com>

Hi Thinh,

On 3/4/2022 4:53 PM, Thinh Nguyen wrote:
> Wesley Cheng wrote:
>> Hi Thinh,
>>
>> On 2/28/2022 7:02 PM, Thinh Nguyen wrote:
>>> Wesley Cheng wrote:
>>>> Hi Thinh,
>>>>
>>>> On 2/28/2022 5:09 PM, Thinh Nguyen wrote:
>>>>> Hi Wesley,
>>>>>
>>>
>>> <snip>
>>>
>>>>>
>>>>> [ 2181.481956865       0x9dc63f265]   dbg_complete: ep6in: trb ffffffc01e7f52a0 (E43:D43) buf 00000000ebaf0000 size 1x 0 ctrl 00000810 (hlcs:sC:normal)
>>>>> [ 2181.482044730       0x9dc63f8fc]   dbg_gadget_giveback: ep6in: req ffffff8860657500 length 8/8 zsI ==> 0
>>>>> [ 2181.482222490       0x9dc640651]   event (0000c040): ep0out: Transfer Complete (sIL) [Setup Phase]
>>>>> [ 2181.482273271       0x9dc640a20]   dbg_trace_log_ctrl: Get Interface Status(Intf = 4, Length = 20)
>>>>> [ 2181.482334782       0x9dc640ebc]   dbg_ep_queue: ep6in: req ffffff8860657500 length 0/8 zsI ==> -115
>>>>> [ 2181.482357386       0x9dc64106e]   dbg_prepare: ep6in: trb ffffffc01e7f52b0 (E44:D43) buf 00000000ea578000 size 1x 8 ctrl 00000811 (Hlcs:sC:normal)
>>>>> [ 2181.482391865       0x9dc641304]   dbg_send_ep_cmd: ep6in: cmd 'Update Transfer' [d0007] params 00000000 00000000 00000000 --> status: Successful
>>>>> [ 2181.482485615       0x9dc641a0d]   dbg_send_ep_cmd: ep0out: cmd 'Start Transfer' [406] params 00000000 efffa000 00000000 --> status: Successful
>>>>> [ 2181.482565303       0x9dc642006]   event (000010c0): ep0out: Transfer Not Ready [0] (Not Active) [Data Phase]
>>>>> [ 2181.482719417       0x9dc642b96]   event (00002040): ep0out: Transfer Complete (Sil) [Data Phase]
>>>>> [ 2181.482814938       0x9dc6432c0]   dbg_gadget_giveback: ep0out: req ffffff87df84d900 length 20/20 zsI ==> 0
>>>>> [ 2181.482926084       0x9dc643b16]   event (000020c2): ep0in: Transfer Not Ready [0] (Not Active) [Status Phase]
>>>>> [ 2181.483024261       0x9dc644272]   dbg_send_ep_cmd: ep0in: cmd 'Start Transfer' [406] params 00000000 efffa000 00000000 --> status: Successful
>>>>>
>>>>> The control status isn't completed here.
>>>>>
>>>>> [ 2181.483069521       0x9dc6445d7]   dbg_ep_dequeue: ep2in: req ffffff879f5a8b00 length 0/63680 zsI ==> -115
>>>>> [ 2181.496068792       0x9dc6814c9]   dbg_send_ep_cmd: ep2in: cmd 'End Transfer' [50d08] params 00000000 00000000 00000000 --> status: Timed Out
>>>>>
>>>>> But the dequeue may come when host already sent a new Setup packet.
>>>>> The ep0out hasn't started yet at the point.
>>>>>
>>>>> Due to various system latency, I can see that this can happen when
>>>>> the dwc3 driver hasn't received the interrupt notified the status stage
>>>>> event yet.
>>>>>
>>>>> If that's the case, the host may have already sent the Setup packet
>>>>> at this point. So the End Transfer may get stuck if the Setup packet
>>>>> isn't DMA out yet.
>>>>>
>>>>> Can you try the change below to see if it resolves the issue?
>>>> Thanks, Thinh.  Sure I'll give it a try with this change.  This is very
>>>> similar to the change proposed here as well:
>>>>
>>>> https://urldefense.com/v3/__https://lore.kernel.org/linux-usb/20220216000835.25400-3-quic_wcheng@quicinc.com/__;!!A4F2R9G_pg!KlgSpNELOXQydIQuarA3A4NJXIcvHslXqzOdBwYqUIR97Mqdp8zdyezhOC9EJ6UqxLxM$ 
>>>>
>>>
>>> Not sure if this completely resolves the issue here. The change seems to
>>> issue the End Transfer command before Start Transfer for the next Setup
>>> stage completes. Also it's missing some checks for async calls to the
>>> endpoint that's pending dequeue. Also, we may not need to wait for End
>>> Transfer command to time out if we know the condition to avoid.
>>>
>>>> One thing to mention is that, I'm not sure how dependable checking soley
>>>> the ep0state would be.  I've seen some scenarios where we'd run into the
>>>> end transfer timeout during the time between inspecting the SETUP packet
>>>> (dwc3_ep0_inspect_setup()) and when the data phase is queued.  The
>>>> timing of the data phase can potentially differ if it is a vendor
>>>> specific control request.
>>>
>>> This timeout should only apply to Setup packet and Setup stage. Even if
>>> it's vendor specific control request, it should be fine. Host should not
>>> issue a Setup packet until it receives a status stage (unless there's a
>>> disconnect in the middle of a control transfer, but that's a different
>>> issue).
>>>
>>> If you do see a problem. We can take a look further.
>>>
>> So far so good w/ the testing.  Had to make a small change in your patch
>> to fix a typo:
>>                 if (!(dwc3_ep->flags & DWC3_EP_DELAY_STOP))
>>                         continue;
>>
>>                 dwc3_ep->flags &= ~DWC3_EP_DELAY_STOP;
>>                 ret = dwc3_stop_active_transfer(dwc3_ep, true, true);
>>
>> Was using dep instead of dwc3_ep.  Will let this run over the weekend
>> and get back to you.
>>
> 
> Ok. This seems to confirm my suspicion. Can you update the patch with
> the following adjustment:
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 3e75eaa13abc..c3f7529f64fc 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2309,6 +2309,10 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
>                 if (r == req) {
>                         struct dwc3_request *t;
> 
> +                       if (dwc->ep0state != EP0_SETUP_PHASE &&
> +                           !dwc->delayed_status)
> +                               dep->flags |= DWC3_EP_DELAY_STOP;
> +
>                         /* wait until it is processed */
>                         dwc3_stop_active_transfer(dep, true, true);
> 
> This is to avoid a case if the function driver has some dependency for
> requests to return before sending the control status using delayed
> status, which can cause a hang.
> 
> We only need to make sure not to issue End Transfer after the status
> transfer started and before its completion interrupt, which may prevent
> the driver from starting the Setup stage.
> 

Added the above change, and tested it over the weekend and it was
working well for me.  However, I wasn't able to really test the
delayed_status flag too much, since we don't have a function driver that
utilizes the USB_GADGET_DELAYED_STATUS too much. (we only have a FFS
interface, which will do it during enum, which is part of the test case
I ran)

Would it also make sense to check for the dwc->setup_packet_pending flag
as well in the same IF condition?  That would mean that there was a
SETUP packet cached in the controller, which would need to be handled.
I heard from our CC w/ Synopsys that we need to ensure any pending SETUP
packets stored in internal memory needed to be cleared as well before
issuing the endxfer.

This sounds similar to your statement previously about if the SETUP
packet wasn't DMA'ed out yet.

Thanks
Wesley Cheng

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

  reply	other threads:[~2022-03-07 22:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20220214111148epcas2p3fac143c7870c53ecadfb6b093fcf626b@epcas2p3.samsung.com>
2022-02-14 11:08 ` [PATCH v2 0/2] Fix ep command fail issue in dequeue Daehwan Jung
     [not found]   ` <CGME20220214111149epcas2p1a1faeda037991885fd6f2f026fa44ec5@epcas2p1.samsung.com>
2022-02-14 11:08     ` [PATCH v2 1/2] usb: dwc3: Not set DWC3_EP_END_TRANSFER_PENDING in ep cmd fails Daehwan Jung
2022-02-14 11:29       ` Greg Kroah-Hartman
2022-02-15  6:58         ` Jung Daehwan
2022-02-15  7:37           ` Greg Kroah-Hartman
2022-02-15  8:20             ` Jung Daehwan
2022-02-14 18:44       ` Thinh Nguyen
2022-02-15  6:39         ` Jung Daehwan
2022-02-15 17:14           ` Thinh Nguyen
2022-02-17 20:05             ` Wesley Cheng
2022-02-17 23:43               ` Thinh Nguyen
2022-02-22 18:08                 ` Wesley Cheng
2022-02-23  2:59                   ` Thinh Nguyen
2022-02-24 21:45                     ` Wesley Cheng
2022-02-25  1:26                       ` Thinh Nguyen
2022-02-25  1:31                         ` Wesley Cheng
2022-02-25  1:44                           ` Thinh Nguyen
2022-02-28 22:53                             ` Wesley Cheng
2022-03-01  1:09                               ` Thinh Nguyen
2022-03-01  2:09                                 ` Wesley Cheng
2022-03-01  3:02                                   ` Thinh Nguyen
2022-03-04 21:58                                     ` Wesley Cheng
2022-03-05  0:53                                       ` Thinh Nguyen
2022-03-07 22:57                                         ` Wesley Cheng [this message]
2022-03-07 23:51                                           ` Thinh Nguyen
2022-03-08 19:20                                             ` Wesley Cheng
2022-02-18  4:44             ` Jung Daehwan
2022-02-23  2:11               ` Thinh Nguyen
     [not found]   ` <CGME20220214111149epcas2p29b9e39b84d7203572422531beb3c39ed@epcas2p2.samsung.com>
2022-02-14 11:08     ` [PATCH v2 2/2] usb: dwc3: Prevent cleanup cancelled requests at the same time Daehwan Jung
2022-02-14 11:30       ` Greg Kroah-Hartman

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=1238af3f-3110-a1f2-808c-3c07282b4f14@codeaurora.org \
    --to=wcheng@codeaurora.org \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=dh10.jung@samsung.com \
    --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 \
    /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;
as well as URLs for NNTP newsgroup(s).