From patchwork Wed Apr 13 12:01:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 65721 Delivered-To: patch@linaro.org Received: by 10.140.43.199 with SMTP id e65csp9176qga; Wed, 13 Apr 2016 06:08:07 -0700 (PDT) X-Received: by 10.194.78.235 with SMTP id e11mr9460065wjx.54.1460552887860; Wed, 13 Apr 2016 06:08:07 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id g16si39748385wjs.166.2016.04.13.06.08.07; Wed, 13 Apr 2016 06:08:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 835E4A75F6; Wed, 13 Apr 2016 15:08:06 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vbOZZH86JJPE; Wed, 13 Apr 2016 15:08:06 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DA194A7550; Wed, 13 Apr 2016 15:08:05 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 73478A7550 for ; Wed, 13 Apr 2016 15:08:02 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CkuGLBDhVK1J for ; Wed, 13 Apr 2016 15:08:02 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) by theia.denx.de (Postfix) with ESMTPS id 2D3A2A748A for ; Wed, 13 Apr 2016 15:07:58 +0200 (CEST) Received: by mail-lf0-f44.google.com with SMTP id g184so68683514lfb.3 for ; Wed, 13 Apr 2016 06:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rVtcWXywJJQJx9ufMAoG1bfNyXZ2I/EupaWTxcUob14=; b=KqCkZED6QXckWrlTpECyGe4jkqhbXo9HmHaoBbPIWTXlB+LmHDZLLfcsYLZeCDYrnN 9Ql+FxAfvDUJiJiGrps2W2kKbPTdS5+1x3b3LFp1r4KO2tgAGVG7o4RRNvCyPtjp7aPB WdG6vYK1mJLXlUuqi9X9bv9Pjq5riqDyMb2R4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rVtcWXywJJQJx9ufMAoG1bfNyXZ2I/EupaWTxcUob14=; b=Kg0r9Rh+S0GfXX2JF8x4SvnXaD6J6AaDBvFnQoNgD68sDpMuDWbHCEvyYz/vDLcDbf ZMbxHeUblwEwqLUIJmI1IR86qaE3lHnJRKjNQzF3KR544sxbX2GkReFYR2AdabN+rNpr I3jPzh04jh2gPIcqaaW1n1aIm5OfY2oNC/mBPDUYBZvU3nuBtMG9u1GKJpfKzmDliRnt 1fERQUSXZnPQTeRC8+DbkNRbCNjS5mHVvqvACkf1jyeIfXOEH2k1xJKUzGfrH/zw1Iva +9H3xBgRIQVFyMhl+pfnA/53Pi6CLLDrXcFt1PVM2Grcuo7YteTjSx5IUJqyWlUQoPh8 fpCw== X-Gm-Message-State: AOPr4FWor5ue01vuXJ2H/2ztHY/EdW2TJq735Ue8Y88Fnszmzc0SjjBIb5lRliVm9Gd11nHK X-Received: by 10.112.201.105 with SMTP id jz9mr3305338lbc.139.1460548864364; Wed, 13 Apr 2016 05:01:04 -0700 (PDT) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id l5sm6123910lbw.44.2016.04.13.05.01.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Apr 2016 05:01:03 -0700 (PDT) From: Semen Protsenko To: u-boot@lists.denx.de Date: Wed, 13 Apr 2016 15:01:02 +0300 Message-Id: <1460548862-27625-1-git-send-email-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.8.0.rc3 MIME-Version: 1.0 Cc: Marek Vasut , Steve Rae , Praneeth Bajjuri , Tom Rini Subject: [U-Boot] [PATCH] fastboot: Fix OUT transaction length alignment X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Sam Protsenko 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 --- 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; }