public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] fastboot: Fix OUT transaction length alignment
Date: Wed, 13 Apr 2016 15:32:39 +0300	[thread overview]
Message-ID: <570E3C67.6080200@ti.com> (raw)
In-Reply-To: <1460548862-27625-1-git-send-email-semen.protsenko@linaro.org>

Hi,

On 13/04/16 15:01, Semen Protsenko wrote:
> From: Sam Protsenko <semen.protsenko@linaro.org>
> 
> Some UDC controllers may require buffer size to be aligned to
> wMaxPacketSize. It's indicated by gadget->quirk_ep_out_aligned_size
> field being set to "true" (in UDC driver code). In that case
> rx_bytes_expected must be aligned to wMaxPacket size, otherwise stuck on
> transaction will happen. For example, it's required by DWC3 controller
> data manual:
> 
>     section 8.2.3.3 Buffer Size Rules and Zero-Length Packets:
> 
>     For OUT endpoints, the following rules apply:
>     - The BUFSIZ field must be ? 1 byte.
>     - The total size of a Buffer Descriptor must be a multiple of
>       MaxPacketSize
>     - A received zero-length packet still requires a MaxPacketSize buffer.
>       Therefore, if the expected amount of data to be received is a multiple
>       of MaxPacketSize, software should add MaxPacketSize bytes to the buffer
>       to sink a possible zero-length packet at the end of the transfer.
> 
> But other UDC controllers don't need such alignment, so mentioned field
> is set to "false". If buffer size is aligned to wMaxPacketSize, those
> controllers may stuck on transaction. The example is DWC2.
> 
> This patch checks gadget->quirk_ep_out_aligned_size field and aligns
> rx_bytes_expected to wMaxPacketSize only when it's needed.
> 
> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>
> ---
>  drivers/usb/gadget/f_fastboot.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
> index 2e87fee..54dcce0 100644
> --- a/drivers/usb/gadget/f_fastboot.c
> +++ b/drivers/usb/gadget/f_fastboot.c
> @@ -58,6 +58,7 @@ static unsigned int fastboot_flash_session_id;
>  static unsigned int download_size;
>  static unsigned int download_bytes;
>  static bool is_high_speed;
> +static bool quirk_ep_out_aligned_size;
>  
>  static struct usb_endpoint_descriptor fs_ep_in = {
>  	.bLength            = USB_DT_ENDPOINT_SIZE,
> @@ -240,6 +241,8 @@ static int fastboot_set_alt(struct usb_function *f,
>  	debug("%s: func: %s intf: %d alt: %d\n",
>  	      __func__, f->name, interface, alt);
>  
> +	quirk_ep_out_aligned_size = gadget->quirk_ep_out_aligned_size;
> +
>  	/* make sure we don't enable the ep twice */
>  	if (gadget->speed == USB_SPEED_HIGH) {
>  		ret = usb_ep_enable(f_fb->out_ep, &hs_ep_out);
> @@ -435,12 +438,18 @@ static unsigned int rx_bytes_expected(unsigned int maxpacket)
>  		return 0;
>  	if (rx_remain > EP_BUFFER_SIZE)
>  		return EP_BUFFER_SIZE;
> +
> +	if (!quirk_ep_out_aligned_size)
> +		goto out;
> +
>  	if (rx_remain < maxpacket) {
>  		rx_remain = maxpacket;
>  	} else if (rx_remain % maxpacket != 0) {
>  		rem = rx_remain % maxpacket;
>  		rx_remain = rx_remain + (maxpacket - rem);
>  	}
> +
> +out:
>  	return rx_remain;
>  }
>  
> 

Why do we need a special flag for this driver if other drivers e.g. mass storage
are doing perfectly fine without it?

This patch is just covering up the real problem, by bypassing the faulty code
with a flag.

The buffer size is EP_BUFFER_SIZE and is already aligned to wMaxPacketSize so
the problem shouldn't have happened in the first place. But it is happening
indicating something else is wrong.

Why is the code using wMaxPacketSize for the check. why can't it just use usb_ep->maxpacket?

cheers,
-roger

  parent reply	other threads:[~2016-04-13 12:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-13 12:01 [U-Boot] [PATCH] fastboot: Fix OUT transaction length alignment Semen Protsenko
2016-04-13 12:02 ` Sam Protsenko
2016-04-13 12:26 ` Tom Rini
2016-04-13 12:32 ` Roger Quadros [this message]
2016-04-13 16:56   ` Sam Protsenko
2016-04-14  1:06     ` Steve Rae
2016-04-14 10:18     ` Roger Quadros
2016-04-15 19:44       ` Steve Rae
2016-04-18  7:56         ` Roger Quadros
2016-04-18 11:39           ` Roger Quadros
2016-04-18 13:47             ` Lukasz Majewski
2016-04-18 13:55               ` Roger Quadros
2016-04-18 15:43                 ` Steve Rae
2016-04-19  8:46                   ` Lukasz Majewski

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=570E3C67.6080200@ti.com \
    --to=rogerq@ti.com \
    --cc=u-boot@lists.denx.de \
    /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