From patchwork Mon Feb 16 20:32:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dileep Katta X-Patchwork-Id: 44737 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f199.google.com (mail-we0-f199.google.com [74.125.82.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DBD442154B for ; Mon, 16 Feb 2015 20:33:03 +0000 (UTC) Received: by mail-we0-f199.google.com with SMTP id q59sf20871873wes.2 for ; Mon, 16 Feb 2015 12:33:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list; bh=Unnl5zaJ4/YeKgeTPHIkDTZpFO74cgWzVHTXDNU6PwE=; b=KzbQJZPgjOEiUDXnQTZn5PIneLFTrFUHPtvpN6FVkJBrSAf99M0jejihJUCV395+EG FIjaY0CrXfcjn5KydRSS8tPRc8G/6mpAukRwV+GoM/BaN+THH/mQPirGpPLW5gFtN6IL 6Hpnr+G7cj6fQh83t2+lWF0tj1mx7DXm9ypGIpMuWCW9fpoZpn+YJsAGpf8gAR9uMhE+ 9fSnVUdvEf4yT5yStPEOjqDVSglRBPCNQOdZhETRoPvim7UKeO1CrblFuoItanobG8r9 5omXul9GAAYXfVV5+HU3KlghZ52RO5kEukYEl78mVeJk2eomL/JV2zhsQ6uTY7ToN1Bj cu3Q== X-Gm-Message-State: ALoCoQkF/m2gI1E5qNHe9QMUNqWar+Q78NjMCGrNASOGs512BGAYiBYM1/hjtU2QokFbxHdsffbF X-Received: by 10.180.80.7 with SMTP id n7mr3079721wix.0.1424118783161; Mon, 16 Feb 2015 12:33:03 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.38 with SMTP id p6ls657958lap.49.gmail; Mon, 16 Feb 2015 12:33:03 -0800 (PST) X-Received: by 10.152.43.101 with SMTP id v5mr25244748lal.83.1424118782996; Mon, 16 Feb 2015 12:33:02 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id ao10si10886204lac.42.2015.02.16.12.33.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Feb 2015 12:33:02 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by labgq15 with SMTP id gq15so32131177lab.3 for ; Mon, 16 Feb 2015 12:33:02 -0800 (PST) X-Received: by 10.112.114.230 with SMTP id jj6mr25034248lbb.112.1424118782803; Mon, 16 Feb 2015 12:33:02 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp1804025lbj; Mon, 16 Feb 2015 12:33:02 -0800 (PST) X-Received: by 10.194.108.9 with SMTP id hg9mr55274668wjb.68.1424118781663; Mon, 16 Feb 2015 12:33:01 -0800 (PST) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id ls6si13277904wic.107.2015.02.16.12.33.00; Mon, 16 Feb 2015 12:33:01 -0800 (PST) Received-SPF: none (google.com: u-boot-bounces@lists.denx.de does not designate permitted sender hosts) client-ip=85.214.87.163; Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E64C44B7ED; Mon, 16 Feb 2015 21:32:59 +0100 (CET) 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 UxEID6UqYeYi; Mon, 16 Feb 2015 21:32:59 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 543584B7BD; Mon, 16 Feb 2015 21:32:59 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DDA2D4B7BD for ; Mon, 16 Feb 2015 21:32:55 +0100 (CET) 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 K2ckEAY5j69V for ; Mon, 16 Feb 2015 21:32:55 +0100 (CET) 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-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by theia.denx.de (Postfix) with ESMTPS id 61D8B4B78B for ; Mon, 16 Feb 2015 21:32:53 +0100 (CET) Received: by paceu11 with SMTP id eu11so817644pac.10 for ; Mon, 16 Feb 2015 12:32:51 -0800 (PST) X-Received: by 10.68.200.36 with SMTP id jp4mr42642696pbc.153.1424118771828; Mon, 16 Feb 2015 12:32:51 -0800 (PST) Received: from localhost.localdomain ([106.51.139.45]) by mx.google.com with ESMTPSA id gk1sm15487956pbb.61.2015.02.16.12.32.48 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Feb 2015 12:32:51 -0800 (PST) From: Dileep Katta To: u-boot@lists.denx.de, robherring2@gmail.com, trini@ti.com, rob.herring@linaro.org, srae@broadcom.com, l.majewski@samsung.com, angelabaker@ti.com Date: Tue, 17 Feb 2015 02:02:36 +0530 Message-Id: <1424118756-30619-1-git-send-email-dileep.katta@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <9FBC647E244F23439E86EA1DE6E2EC3BC902F2@DFLE11.ent.ti.com> References: <9FBC647E244F23439E86EA1DE6E2EC3BC902F2@DFLE11.ent.ti.com> Cc: Dileep Katta Subject: [U-Boot] [PATCH v3 1/3] fastboot: OUT transaction length must be aligned to wMaxPacketSize X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: dileep.katta@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 OUT transactions must be aligned to wMaxPacketSize for each transfer, or else transfer will not complete successfully. This patch modifies rx_bytes_expected to return a transfer length that is aligned to wMaxPacketSize. Note that the value of wMaxPacketSize and ep->maxpacket may not be the same value, and it is the value of wMaxPacketSize that should be used for alignment. wMaxPacketSize is passed depending on the speed of connection. Signed-off-by: Dileep Katta --- Changes in v2: - Corrected source of wMaxPacketSize Changes in v3: - Corrected the logic to accomodate both HS and FS speeds drivers/usb/gadget/f_fastboot.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index a8d8205..2793590 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -55,6 +55,7 @@ static inline struct f_fastboot *func_to_fastboot(struct usb_function *f) static struct f_fastboot *fastboot_func; static unsigned int download_size; static unsigned int download_bytes; +static bool is_high_speed; static struct usb_endpoint_descriptor fs_ep_in = { .bLength = USB_DT_ENDPOINT_SIZE, @@ -219,10 +220,13 @@ static int fastboot_set_alt(struct usb_function *f, __func__, f->name, interface, alt); /* make sure we don't enable the ep twice */ - if (gadget->speed == USB_SPEED_HIGH) + if (gadget->speed == USB_SPEED_HIGH) { ret = usb_ep_enable(f_fb->out_ep, &hs_ep_out); - else + is_high_speed = true; + } else { ret = usb_ep_enable(f_fb->out_ep, &fs_ep_out); + is_high_speed = false; + } if (ret) { puts("failed to enable out ep\n"); return ret; @@ -370,13 +374,20 @@ static void cb_getvar(struct usb_ep *ep, struct usb_request *req) fastboot_tx_write_str(response); } -static unsigned int rx_bytes_expected(void) +static unsigned int rx_bytes_expected(unsigned int maxpacket) { int rx_remain = download_size - download_bytes; + int rem = 0; if (rx_remain < 0) return 0; if (rx_remain > EP_BUFFER_SIZE) return EP_BUFFER_SIZE; + if (rx_remain < maxpacket) { + rx_remain = maxpacket; + } else if (rx_remain % maxpacket != 0) { + rem = rx_remain % maxpacket; + rx_remain = rx_remain + (maxpacket - rem); + } return rx_remain; } @@ -388,6 +399,7 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req) const unsigned char *buffer = req->buf; unsigned int buffer_size = req->actual; unsigned int pre_dot_num, now_dot_num; + unsigned int max; if (req->status != 0) { printf("Bad status: %d\n", req->status); @@ -425,7 +437,9 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req) printf("\ndownloading of %d bytes finished\n", download_bytes); } else { - req->length = rx_bytes_expected(); + max = is_high_speed ? hs_ep_out.wMaxPacketSize : + fs_ep_out.wMaxPacketSize; + req->length = rx_bytes_expected(max); if (req->length < ep->maxpacket) req->length = ep->maxpacket; } @@ -438,6 +452,7 @@ static void cb_download(struct usb_ep *ep, struct usb_request *req) { char *cmd = req->buf; char response[RESPONSE_LEN]; + unsigned int max; strsep(&cmd, ":"); download_size = simple_strtoul(cmd, NULL, 16); @@ -453,7 +468,9 @@ static void cb_download(struct usb_ep *ep, struct usb_request *req) } else { sprintf(response, "DATA%08x", download_size); req->complete = rx_handler_dl_image; - req->length = rx_bytes_expected(); + max = is_high_speed ? hs_ep_out.wMaxPacketSize : + fs_ep_out.wMaxPacketSize; + req->length = rx_bytes_expected(max); if (req->length < ep->maxpacket) req->length = ep->maxpacket; }