From: Felipe Balbi <balbi@kernel.org>
To: Baolin Wang <baolin.wang@linaro.org>, gregkh@linuxfoundation.org
Cc: broonie@kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, baolin.wang@linaro.org
Subject: Re: [PATCH v2 2/2] usb: dwc3: Wait for control tranfer completed when stopping gadget
Date: Fri, 09 Sep 2016 14:03:31 +0300 [thread overview]
Message-ID: <871t0tgwsc.fsf@linux.intel.com> (raw)
In-Reply-To: <3a4c91231787d31e82874161aa2ef9351f1c4b73.1473405255.git.baolin.wang@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 3006 bytes --]
Hi,
Baolin Wang <baolin.wang@linaro.org> writes:
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 057739d..22787b6 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -999,6 +999,7 @@ static int dwc3_probe(struct platform_device *pdev)
> goto err0;
>
> spin_lock_init(&dwc->lock);
> + init_completion(&dwc->ep0_completed);
this should be done only when gadget is required; meaning that this
should be moved to dwc3_gadget_init()
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index b2317e7..858e661 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
[...]
> @@ -843,6 +844,7 @@ struct dwc3 {
> dma_addr_t ep0_bounce_addr;
> dma_addr_t scratch_addr;
> struct dwc3_request ep0_usb_req;
> + struct completion ep0_completed;
when you call this "ep0_completed" it seems like you're defining a flag,
but you're not :) How about "ep0_in_setup" instead? That conveys the
idea that we're waiting for ep0 to reach setup phase.
> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
> index 632e5a4..baf932d 100644
> --- a/drivers/usb/dwc3/ep0.c
> +++ b/drivers/usb/dwc3/ep0.c
> @@ -286,6 +286,7 @@ static void dwc3_ep0_stall_and_restart(struct dwc3 *dwc)
>
> dwc->ep0state = EP0_SETUP_PHASE;
> dwc3_ep0_out_start(dwc);
> + complete(&dwc->ep0_completed);
no, this is wrong. I see what you're trying to do here, but we don't
want to duplicate this call to complete() right? One thing we can
realize is that *always* after STATUS phase or after a STALL, we will go
through dwc3_ep0_out_start(), this mean we can call complete() before
starting the following SETUP phase.
Single place to call complete() ;-)
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 1a33308..c9026ce 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1441,6 +1441,15 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
> if (pm_runtime_suspended(dwc->dev))
> return 0;
>
> + /*
> + * Per databook, when we want to stop the gadget, if a control transfer
> + * is still in process, complete it and get the core into setup phase.
> + */
> + if (!is_on && dwc->ep0state != EP0_SETUP_PHASE) {
> + reinit_completion(&dwc->ep0_completed);
this seems unnecessary to me. Also, why return here so the caller has to
wait? You could just have called wait_for_completion() here straight
away:
if (!is_on && dwc->ep0state != EP0_SETUP_PHASE) {
/* should this be interruptible? */
ret = wait_for_completion_timeout(&dwc->ep0_in_setup,
msecs_to_jiffies(500));
if (ret == 0) {
dwc3_trace(trace_dwc3_gadget, "RUN/STOP timeout");
return -ETIMEDOUT;
}
}
There's also no need for that "try_again" trickery. We either can halt
the controller within 500ms or we cannot.
--
balbi
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]
next prev parent reply other threads:[~2016-09-09 11:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-09 7:16 [PATCH v2 1/2] usb: dwc3: gadget: Add disconnect checking when changing function dynamically Baolin Wang
2016-09-09 7:16 ` [PATCH v2 2/2] usb: dwc3: Wait for control tranfer completed when stopping gadget Baolin Wang
2016-09-09 11:03 ` Felipe Balbi [this message]
2016-09-18 4:58 ` Baolin Wang
2016-09-19 9:58 ` Felipe Balbi
2016-09-19 10:42 ` Baolin Wang
2016-09-09 10:47 ` [PATCH v2 1/2] usb: dwc3: gadget: Add disconnect checking when changing function dynamically Felipe Balbi
2016-09-18 4:48 ` Baolin Wang
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=871t0tgwsc.fsf@linux.intel.com \
--to=balbi@kernel.org \
--cc=baolin.wang@linaro.org \
--cc=broonie@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).