From: Felipe Balbi <balbi@kernel.org>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org,
Bryan O'Donoghue <pure.logic@nexus-software.ie>
Cc: John Youn <John.Youn@synopsys.com>, stable@vger.kernel.org
Subject: Re: [PATCH] usb: dwc3: gadget: Init only available HW eps
Date: Wed, 06 Jan 2021 09:51:10 +0200 [thread overview]
Message-ID: <87eeiycxld.fsf@kernel.org> (raw)
In-Reply-To: <3080c0452df14d510d24471ce0f9bb7592cdfd4d.1609866964.git.Thinh.Nguyen@synopsys.com>
Hi,
Thinh Nguyen <Thinh.Nguyen@synopsys.com> writes:
> Typically FPGA devices are configured with CoreConsultant parameter
> DWC_USB3x_EN_LOG_PHYS_EP_SUPT=0 to reduce gate count and improve timing.
> This means that the number of INs equals to OUTs endpoints. But
> typically non-FPGA devices enable this CoreConsultant parameter to
> support flexible endpoint mapping and potentially may have unequal
> number of INs to OUTs physical endpoints.
>
> The driver must check how many physical endpoints are available for each
> direction and initialize them properly.
>
> Cc: stable@vger.kernel.org
> Fixes: 47d3946ea220 ("usb: dwc3: refactor gadget endpoint count calculation")
> Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> ---
> drivers/usb/dwc3/core.c | 1 +
> drivers/usb/dwc3/core.h | 2 ++
> drivers/usb/dwc3/gadget.c | 19 ++++++++++++-------
> 3 files changed, 15 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 841daec70b6e..1084aa8623c2 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -529,6 +529,7 @@ static void dwc3_core_num_eps(struct dwc3 *dwc)
> struct dwc3_hwparams *parms = &dwc->hwparams;
>
> dwc->num_eps = DWC3_NUM_EPS(parms);
> + dwc->num_in_eps = DWC3_NUM_IN_EPS(parms);
> }
>
> static void dwc3_cache_hwparams(struct dwc3 *dwc)
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 1b241f937d8f..1295dac019f9 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -990,6 +990,7 @@ struct dwc3_scratchpad_array {
> * @u1sel: parameter from Set SEL request.
> * @u1pel: parameter from Set SEL request.
> * @num_eps: number of endpoints
> + * @num_in_eps: number of IN endpoints
> * @ep0_next_event: hold the next expected event
> * @ep0state: state of endpoint zero
> * @link_state: link state
> @@ -1193,6 +1194,7 @@ struct dwc3 {
> u8 speed;
>
> u8 num_eps;
> + u8 num_in_eps;
>
> struct dwc3_hwparams hwparams;
> struct dentry *root;
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 25f654b79e48..8a38ee10c00b 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2025,7 +2025,7 @@ static void dwc3_stop_active_transfers(struct dwc3 *dwc)
> {
> u32 epnum;
>
> - for (epnum = 2; epnum < dwc->num_eps; epnum++) {
> + for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
> struct dwc3_ep *dep;
>
> dep = dwc->eps[epnum];
> @@ -2628,16 +2628,21 @@ static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum)
> return 0;
> }
>
> -static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total)
> +static int dwc3_gadget_init_endpoints(struct dwc3 *dwc)
> {
> - u8 epnum;
> + u8 i;
> + int ret;
>
> INIT_LIST_HEAD(&dwc->gadget->ep_list);
>
> - for (epnum = 0; epnum < total; epnum++) {
> - int ret;
> + for (i = 0; i < dwc->num_in_eps; i++) {
> + ret = dwc3_gadget_init_endpoint(dwc, i * 2 + 1);
> + if (ret)
> + return ret;
> + }
>
> - ret = dwc3_gadget_init_endpoint(dwc, epnum);
> + for (i = 0; i < dwc->num_eps - dwc->num_in_eps; i++) {
> + ret = dwc3_gadget_init_endpoint(dwc, i * 2);
> if (ret)
> return ret;
> }
> @@ -3863,7 +3868,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
> * sure we're starting from a well known location.
> */
>
> - ret = dwc3_gadget_init_endpoints(dwc, dwc->num_eps);
> + ret = dwc3_gadget_init_endpoints(dwc);
> if (ret)
> goto err4;
heh, looking at original commit, we used to have num_in_eps and
num_out_eps. In fact, this commit will reintroduce another problem that
Bryan tried to solve. num_eps - num_in_eps is not necessarily
num_out_eps.
How have you verified this patch? Did you read Bryan's commit log? This
is likely to reintroduce the problem raised by Bryan.
--
balbi
next prev parent reply other threads:[~2021-01-06 7:52 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-05 17:20 [PATCH] usb: dwc3: gadget: Init only available HW eps Thinh Nguyen
2021-01-06 7:51 ` Felipe Balbi [this message]
2021-01-06 9:29 ` Thinh Nguyen
2021-01-07 9:33 ` Felipe Balbi
2021-01-08 2:32 ` Thinh Nguyen
2021-01-08 3:54 ` Thinh Nguyen
2021-01-08 12:23 ` Felipe Balbi
2021-01-29 0:58 ` Bryan O'Donoghue
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=87eeiycxld.fsf@kernel.org \
--to=balbi@kernel.org \
--cc=John.Youn@synopsys.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=pure.logic@nexus-software.ie \
--cc=stable@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