From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Wesley Cheng <quic_wcheng@quicinc.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH v5 3/3] usb: dwc3: gadget: Refactor EP0 forced stall/restart into a separate API
Date: Tue, 18 Apr 2023 01:47:36 +0000 [thread overview]
Message-ID: <20230418014726.5q4lawwyxg7vqifh@synopsys.com> (raw)
In-Reply-To: <20230413195742.11821-4-quic_wcheng@quicinc.com>
On Thu, Apr 13, 2023, Wesley Cheng wrote:
> Several sequences utilize the same routine for forcing the control endpoint
> back into the SETUP phase. This is required, because those operations need
> to ensure that EP0 is back in the default state.
>
> Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
> ---
> drivers/usb/dwc3/gadget.c | 53 ++++++++++++++++-----------------------
> 1 file changed, 21 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 0bb4926933b6..9715de8e99bc 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -139,6 +139,24 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state)
> return -ETIMEDOUT;
> }
>
> +static void dwc3_ep0_reset_state(struct dwc3 *dwc)
> +{
> + unsigned int dir;
> +
> + if (dwc->ep0state != EP0_SETUP_PHASE) {
> + dir = !!dwc->ep0_expect_in;
> + if (dwc->ep0state == EP0_DATA_PHASE)
> + dwc3_ep0_end_control_data(dwc, dwc->eps[dir]);
> + else
> + dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]);
> +
> + dwc->eps[0]->trb_enqueue = 0;
> + dwc->eps[1]->trb_enqueue = 0;
> +
> + dwc3_ep0_stall_and_restart(dwc);
> + }
> +}
> +
> /**
> * dwc3_ep_inc_trb - increment a trb index.
> * @index: Pointer to the TRB index to increment.
> @@ -2563,16 +2581,9 @@ static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc)
> ret = wait_for_completion_timeout(&dwc->ep0_in_setup,
> msecs_to_jiffies(DWC3_PULL_UP_TIMEOUT));
> if (ret == 0) {
> - unsigned int dir;
> -
> dev_warn(dwc->dev, "wait for SETUP phase timed out\n");
> spin_lock_irqsave(&dwc->lock, flags);
> - dir = !!dwc->ep0_expect_in;
> - if (dwc->ep0state == EP0_DATA_PHASE)
> - dwc3_ep0_end_control_data(dwc, dwc->eps[dir]);
> - else
> - dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]);
> - dwc3_ep0_stall_and_restart(dwc);
> + dwc3_ep0_reset_state(dwc);
> spin_unlock_irqrestore(&dwc->lock, flags);
> }
> }
> @@ -3847,16 +3858,7 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc)
> dwc->setup_packet_pending = false;
> usb_gadget_set_state(dwc->gadget, USB_STATE_NOTATTACHED);
>
> - if (dwc->ep0state != EP0_SETUP_PHASE) {
> - unsigned int dir;
> -
> - dir = !!dwc->ep0_expect_in;
> - if (dwc->ep0state == EP0_DATA_PHASE)
> - dwc3_ep0_end_control_data(dwc, dwc->eps[dir]);
> - else
> - dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]);
> - dwc3_ep0_stall_and_restart(dwc);
> - }
> + dwc3_ep0_reset_state(dwc);
> }
>
> static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
> @@ -3910,20 +3912,7 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
> * phase. So ensure that EP0 is in setup phase by issuing a stall
> * and restart if EP0 is not in setup phase.
> */
> - if (dwc->ep0state != EP0_SETUP_PHASE) {
> - unsigned int dir;
> -
> - dir = !!dwc->ep0_expect_in;
> - if (dwc->ep0state == EP0_DATA_PHASE)
> - dwc3_ep0_end_control_data(dwc, dwc->eps[dir]);
> - else
> - dwc3_ep0_end_control_data(dwc, dwc->eps[!dir]);
> -
> - dwc->eps[0]->trb_enqueue = 0;
> - dwc->eps[1]->trb_enqueue = 0;
> -
> - dwc3_ep0_stall_and_restart(dwc);
> - }
> + dwc3_ep0_reset_state(dwc);
>
> /*
> * In the Synopsis DesignWare Cores USB3 Databook Rev. 3.30a
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Thanks,
Thinh
next prev parent reply other threads:[~2023-04-18 2:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-13 19:57 [PATCH v5 0/3] Avoid having pending end transfers on soft disconnect Wesley Cheng
2023-04-13 19:57 ` [PATCH v5 1/3] usb: dwc3: gadget: Stall and restart EP0 if host is unresponsive Wesley Cheng
2023-04-18 1:46 ` Thinh Nguyen
2023-04-13 19:57 ` [PATCH v5 2/3] usb: dwc3: gadget: Execute gadget stop after halting the controller Wesley Cheng
2023-04-13 19:57 ` [PATCH v5 3/3] usb: dwc3: gadget: Refactor EP0 forced stall/restart into a separate API Wesley Cheng
2023-04-18 1:47 ` Thinh Nguyen [this message]
2023-04-20 9:21 ` [PATCH v5 0/3] Avoid having pending end transfers on soft disconnect Greg KH
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=20230418014726.5q4lawwyxg7vqifh@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--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 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.