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) {