From patchwork Sat Jul 28 01:52:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 10547853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 57730112B for ; Sat, 28 Jul 2018 01:52:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C2E420415 for ; Sat, 28 Jul 2018 01:52:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C5992C570; Sat, 28 Jul 2018 01:52:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D29820415 for ; Sat, 28 Jul 2018 01:52:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389091AbeG1DRP (ORCPT ); Fri, 27 Jul 2018 23:17:15 -0400 Received: from us01smtprelay-2.synopsys.com ([198.182.47.9]:39700 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388894AbeG1DRP (ORCPT ); Fri, 27 Jul 2018 23:17:15 -0400 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id 03DF224E101F; Fri, 27 Jul 2018 18:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1532742763; bh=MqstAurPgtv0TCye88GUXbkeseGE2xOzeOd6bYfOj3c=; h=Date:From:Subject:To:CC:From; b=EWGNGAGwn8piC7mB7kdSO8c/75QdRoRLlyCdqSXs0+7DVJwOeAHvvFafmUDOdDFdI DNQK3T0GXY6h+RFl+3J7XQBZNNiv9kpezjvIL0Y00paqIOhbZ+E4+GAf7nTIVFHqLw unuBqFxi3jyU+2cJuSPha4A0zUiBExAm+RbbMSM8qpk4pHXVMviwApQyTzdeHcWwH1 ooVDadqMh9FZQRezzvtkXc52iSYNIcEpn5UO147aWfzI97GdlpK1imAjT758HmTjys hfPzaSjo94DaA9fw71Ixqpyokgx9WHiCik3Mst5cM7vkP/hlqA/j0NxLP4AdwR/Gf4 NkMPzITuH0Qqg== Received: from us01wehtc1.internal.synopsys.com (us01wehtc1-vip.internal.synopsys.com [10.12.239.236]) by mailhost.synopsys.com (Postfix) with ESMTP id E48AB3F55; Fri, 27 Jul 2018 18:52:42 -0700 (PDT) Received: from US01WEHTC3.internal.synopsys.com (10.15.84.232) by us01wehtc1.internal.synopsys.com (10.12.239.235) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 27 Jul 2018 18:52:42 -0700 Received: from te-lab16 (10.13.184.20) by US01WEHTC3.internal.synopsys.com (10.15.84.231) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 27 Jul 2018 18:52:41 -0700 Received: by te-lab16 (sSMTP sendmail emulation); Fri, 27 Jul 2018 18:52:41 -0700 Date: Fri, 27 Jul 2018 18:52:41 -0700 Message-ID: <437a32ebba5bedbae4f6be1a43c1174f4e596f76.1532742607.git.thinhn@synopsys.com> From: Thinh Nguyen Subject: [PATCH 1/3] usb: dwc3: gadget: Check MaxPacketSize from descriptor To: Felipe Balbi , CC: John Youn MIME-Version: 1.0 X-Originating-IP: [10.13.184.20] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP endpoint->maxpacket is not updated after setting the usb_set_maxpacket_limit() on endpoint enable. The MaxPacketSize can be different than the endpoint->maxpacket_limit. DWC3 has been consistently using MaxPacketSize from the endpoint's descriptor, so let's keep it consistent and use the MaxPacketSize from the endpoint's descriptor instead. Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 69bf137aab37..032ea7d709ba 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1121,7 +1121,7 @@ static void dwc3_prepare_one_trb_linear(struct dwc3_ep *dep, req->request.short_not_ok, req->request.no_interrupt); } else if (req->request.zero && req->request.length && - (IS_ALIGNED(req->request.length,dep->endpoint.maxpacket))) { + (IS_ALIGNED(req->request.length, maxp))) { struct dwc3 *dwc = dep->dwc; struct dwc3_trb *trb; From patchwork Sat Jul 28 01:52:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 10547855 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4577112B for ; Sat, 28 Jul 2018 01:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C43EC20415 for ; Sat, 28 Jul 2018 01:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8A452C56F; Sat, 28 Jul 2018 01:52:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 660D72C574 for ; Sat, 28 Jul 2018 01:52:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389109AbeG1DRW (ORCPT ); Fri, 27 Jul 2018 23:17:22 -0400 Received: from smtprelay.synopsys.com ([198.182.60.111]:36393 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388894AbeG1DRW (ORCPT ); Fri, 27 Jul 2018 23:17:22 -0400 Received: from mailhost.synopsys.com (mailhost1.synopsys.com [10.12.238.239]) by smtprelay.synopsys.com (Postfix) with ESMTP id 864DE10C0D61; Fri, 27 Jul 2018 18:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1532742769; bh=HKyv/k5nVd2r4p5lEUtoxk8IHF76NIujA1qRBfr5m0g=; h=Date:In-Reply-To:References:From:Subject:To:CC:From; b=Z7Ge1I9VYmEm42+8Mr0u9+1LFu0kUg27I8kKiRLUQg4sE52X/qN7VILDn14Hvdip7 bG+oovhJawxbVSj1FMAoukmkG/afPb7jwsLHNJJhmkxrNLzJR3kIDFDoctkz1VHO3o qWojEQIgrfrTdFm7m7jE/038M5uQVIkDeAsaHNCfPosKQUU3rjEiMb8PliQANiTEnn v8kJaA2ScrhABNXdDiO/rwrhI87rdjpw3ALV70xDPrH7vk1tfqZNSma1XmdcjQu2p1 rIpTb0B1Th47uUpuyLmAF6JmmfcVOFL/Mb3cybqzucuUFIFGkLKfYupo9n7PsrTBgg Iy8bQlPb6nSWA== Received: from us01wehtc1.internal.synopsys.com (us01wehtc1-vip.internal.synopsys.com [10.12.239.236]) by mailhost.synopsys.com (Postfix) with ESMTP id 76619581F; Fri, 27 Jul 2018 18:52:49 -0700 (PDT) Received: from US01WEHTC3.internal.synopsys.com (10.15.84.232) by us01wehtc1.internal.synopsys.com (10.12.239.235) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 27 Jul 2018 18:52:49 -0700 Received: from te-lab16 (10.13.184.20) by US01WEHTC3.internal.synopsys.com (10.15.84.231) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 27 Jul 2018 18:52:48 -0700 Received: by te-lab16 (sSMTP sendmail emulation); Fri, 27 Jul 2018 18:52:47 -0700 Date: Fri, 27 Jul 2018 18:52:47 -0700 Message-ID: <19a1dd73d68507543e955f508fe47eb7ffef9e73.1532742607.git.thinhn@synopsys.com> In-Reply-To: <437a32ebba5bedbae4f6be1a43c1174f4e596f76.1532742607.git.thinhn@synopsys.com> References: <437a32ebba5bedbae4f6be1a43c1174f4e596f76.1532742607.git.thinhn@synopsys.com> From: Thinh Nguyen Subject: [PATCH 2/3] usb: dwc3: gadget: Don't skip updating remaining data To: Felipe Balbi , CC: John Youn MIME-Version: 1.0 X-Originating-IP: [10.13.184.20] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP DWC3 must check for the BUFSIZ and update the req->remaining regardless of transfer alignment. Returning early from transfer OUT unalignment will skip updating the req->remaining. Fixes: c6267a51639b ("usb: dwc3: gadget: align transfers to wMaxPacketSize") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 032ea7d709ba..a5b8387a37ba 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2246,6 +2246,9 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, if (chain && (trb->ctrl & DWC3_TRB_CTRL_HWO)) trb->ctrl &= ~DWC3_TRB_CTRL_HWO; + count = trb->size & DWC3_TRB_SIZE_MASK; + req->remaining += count; + /* * If we're dealing with unaligned size OUT transfer, we will be left * with one TRB pending in the ring. We need to manually clear HWO bit @@ -2256,9 +2259,6 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep, return 1; } - count = trb->size & DWC3_TRB_SIZE_MASK; - req->remaining += count; - if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN) return 1; From patchwork Sat Jul 28 01:52:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thinh Nguyen X-Patchwork-Id: 10547857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 813A91822 for ; Sat, 28 Jul 2018 01:52:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68BB62C56F for ; Sat, 28 Jul 2018 01:52:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D46D2C574; Sat, 28 Jul 2018 01:52:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 066222C56F for ; Sat, 28 Jul 2018 01:52:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389202AbeG1DR2 (ORCPT ); Fri, 27 Jul 2018 23:17:28 -0400 Received: from smtprelay.synopsys.com ([198.182.60.111]:36394 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388894AbeG1DR2 (ORCPT ); Fri, 27 Jul 2018 23:17:28 -0400 Received: from mailhost.synopsys.com (mailhost2.synopsys.com [10.13.184.66]) by smtprelay.synopsys.com (Postfix) with ESMTP id 2170410C0C35; Fri, 27 Jul 2018 18:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1532742776; bh=PsUsUtCAERHDxil2WYKNaM1xTlru+FILUaFUe3N/NJQ=; h=Date:In-Reply-To:References:From:Subject:To:CC:From; b=Z15M0a+8zt7CoELrvCQqjbL9q34oU3ldMcVBXyJMlMwXtwcZ8dLX4FWYxrabZwXGp OzTPqHPcIkKsa+tyPnpyzvzgoLz3Rw7b2a5VBWQpUQ5aOviIA3DSWRRWQZynK+EX6w gw6cmtqYGN8mg41XHZUyzhV3IdstaBaZdvyKqOWmmyLRxM4WJ5gKso/TK8k/EbQtQI CzP3Za+9V9QpfFfia3uQeJ32G9vX7R8nJyJFZ/PvzM343AlmrPtO+OmMTn/W9WXYT3 /z/2A0JUSFuNdwzfGLuodwIe+rbtAV7CPA8t9njPhDxLZR8h+q4U7K7cFPKGZtAXi2 RYI18BOhCcEWg== Received: from us01wehtc1.internal.synopsys.com (us01wehtc1-vip.internal.synopsys.com [10.12.239.236]) by mailhost.synopsys.com (Postfix) with ESMTP id 153663D36; Fri, 27 Jul 2018 18:52:56 -0700 (PDT) Received: from US01WEHTC3.internal.synopsys.com (10.15.84.232) by us01wehtc1.internal.synopsys.com (10.12.239.235) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 27 Jul 2018 18:52:56 -0700 Received: from te-lab16 (10.13.184.20) by US01WEHTC3.internal.synopsys.com (10.15.84.231) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 27 Jul 2018 18:52:54 -0700 Received: by te-lab16 (sSMTP sendmail emulation); Fri, 27 Jul 2018 18:52:54 -0700 Date: Fri, 27 Jul 2018 18:52:54 -0700 Message-ID: <2152d10ed4bbe7390f4d0361d24994f382aad6bf.1532742607.git.thinhn@synopsys.com> In-Reply-To: <437a32ebba5bedbae4f6be1a43c1174f4e596f76.1532742607.git.thinhn@synopsys.com> References: <437a32ebba5bedbae4f6be1a43c1174f4e596f76.1532742607.git.thinhn@synopsys.com> From: Thinh Nguyen Subject: [PATCH 3/3] usb: dwc3: gadget: Return correct actual bytes written To: Felipe Balbi , CC: John Youn MIME-Version: 1.0 X-Originating-IP: [10.13.184.20] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For OUT transfers, the total size (total TRB buffer allocation) must be a multiple of MaxPacketSize even if software is expecting a fixed non-multiple of MaxPacketSize transfer from the host. (DWC_usb31 programming guide section 4.2.5) So, to calculate the actual bytes written (OUT transfer), do: actual = round_up(expected_length, MaxPacketSize) - remaining_length Fixes: e62c5bc57367 ("usb: dwc3: gadget: tracking per-TRB remaining bytes") Signed-off-by: Thinh Nguyen --- drivers/usb/dwc3/gadget.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index a5b8387a37ba..9859ca9dff9a 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2319,6 +2319,8 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, const struct dwc3_event_depevt *event, struct dwc3_request *req, int status) { + unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc); + unsigned int length = req->request.length; int ret; if (req->num_pending_sgs) @@ -2335,7 +2337,10 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep, req->zero = false; } - req->request.actual = req->request.length - req->remaining; + if (usb_endpoint_dir_out(dep->endpoint.desc)) + req->request.actual = round_up(length, maxp) - req->remaining; + else + req->request.actual = length - req->remaining; if (!dwc3_gadget_ep_request_completed(req) && req->num_pending_sgs) {