Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4480097ivc; Tue, 3 Nov 2020 13:08:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5SQeZ5gCvIVwd/+Osox5omiqkQpYIIemsEG7bkmia64nakuUh1jaaW+nw81vwbJUGEiMx X-Received: by 2002:a17:906:370e:: with SMTP id d14mr23020632ejc.259.1604437680451; Tue, 03 Nov 2020 13:08:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437680; cv=none; d=google.com; s=arc-20160816; b=qDrcty34pEvSLV/JHP0gkEZJeKFZRZG/9h9zb7xYSHJwAHTDnr4yhe4m4+aGu+6+d9 dnNiCtfBQZ0hbrP6uljPrDgAecS2GHl6Z8hlInlZwZtG7vc90/KiW1/RQuxAqIDvr9Wf Sgx0yFPo6TtOkRPCiFse6TdkFMRElo6Ujqc8PJEAYGSXj/m8bAxMMRR0HRZKPFCKtguP 6kmDnz1abvgUr6TgcF9P3hjNvd2YJtyJIlLNr6U8+auwA92kACa95AoDG/IvgPBqq/WZ JUrj9fUqtvyOSmDkpgHrBBBZ+Fu9L+05hpMVN4y1A1gnM3gFpqves/jwMJLqJ8hqDKfM +a9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FfOlJn+Tgybjxt/Bsc2QO8f0tPCTUc8gVjs8VPWNIlg=; b=OhIzOHy7GlasAuCt1SFKtEf66ZSLUheLinjwOr7KKsK7RcpXbvhuezdlbl8O+hl3Zt YQZoDxehArqOXKvtrcG86VrKkGCDAjrkCVwfsrM/JsT8x6mu/+yZZtf0LJpa3O9Hc/9H u+9mrAbnZE7o1nVSPBX0rFpPohMaUPHgFIwak6gxlQG2zft0crN+gLAR6GvOgB83Lo8T JHzcOPXvCSBErs8qpZg76EhE+huy2q0FgL8k2KAFmZCfPCT96Qyy2QA9oJtb32yL7oL6 VCcvM0rVJEYr0uTQrh1a13mUYCKpgnYyHvSiLJoEWyq+0g4NAL2QuvV/s7YYqUBXUJQZ RzjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tPoTE0A2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p10si14528ejy.70.2020.11.03.13.07.37; Tue, 03 Nov 2020 13:08:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tPoTE0A2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733296AbgKCVGT (ORCPT + 99 others); Tue, 3 Nov 2020 16:06:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:45150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388128AbgKCVGQ (ORCPT ); Tue, 3 Nov 2020 16:06:16 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0EEE320757; Tue, 3 Nov 2020 21:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437575; bh=ieJvW+4XTpyCOCM7BV3uYu4rSlt3h7eVheyoBNL9qwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tPoTE0A2aihcvzg90ibeQ0EE4ihXiFddNTRpKArLuetL4F/8kSa10Feav86dg0Oji 8pk9K4eObe8sM1W/jx76JW7uBtrKI7x+icRdZnO903uRowEnIjO0TDZsAgvyJ0uP+i FyVieZBg0e5p5lfD13i79A33Di9ID9aELyGS3se4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen , Felipe Balbi Subject: [PATCH 4.19 136/191] usb: dwc3: ep0: Fix ZLP for OUT ep0 requests Date: Tue, 3 Nov 2020 21:37:08 +0100 Message-Id: <20201103203245.711037341@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thinh Nguyen commit 66706077dc89c66a4777a4c6298273816afb848c upstream. The current ZLP handling for ep0 requests is only for control IN requests. For OUT direction, DWC3 needs to check and setup for MPS alignment. Usually, control OUT requests can indicate its transfer size via the wLength field of the control message. So usb_request->zero is usually not needed for OUT direction. To handle ZLP OUT for control endpoint, make sure the TRB is MPS size. Cc: stable@vger.kernel.org Fixes: c7fcdeb2627c ("usb: dwc3: ep0: simplify EP0 state machine") Fixes: d6e5a549cc4d ("usb: dwc3: simplify ZLP handling") Signed-off-by: Thinh Nguyen Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/ep0.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/drivers/usb/dwc3/ep0.c +++ b/drivers/usb/dwc3/ep0.c @@ -935,12 +935,16 @@ static void dwc3_ep0_xfer_complete(struc static void __dwc3_ep0_do_control_data(struct dwc3 *dwc, struct dwc3_ep *dep, struct dwc3_request *req) { + unsigned int trb_length = 0; int ret; req->direction = !!dep->number; if (req->request.length == 0) { - dwc3_ep0_prepare_one_trb(dep, dwc->ep0_trb_addr, 0, + if (!req->direction) + trb_length = dep->endpoint.maxpacket; + + dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, trb_length, DWC3_TRBCTL_CONTROL_DATA, false); ret = dwc3_ep0_start_trans(dep); } else if (!IS_ALIGNED(req->request.length, dep->endpoint.maxpacket) @@ -987,9 +991,12 @@ static void __dwc3_ep0_do_control_data(s req->trb = &dwc->ep0_trb[dep->trb_enqueue - 1]; + if (!req->direction) + trb_length = dep->endpoint.maxpacket; + /* Now prepare one extra TRB to align transfer size */ dwc3_ep0_prepare_one_trb(dep, dwc->bounce_addr, - 0, DWC3_TRBCTL_CONTROL_DATA, + trb_length, DWC3_TRBCTL_CONTROL_DATA, false); ret = dwc3_ep0_start_trans(dep); } else {