Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp883182pxb; Tue, 3 Nov 2020 15:27:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzre0AyLQOgj751BHg7wb8InWCikGLXadlRSlemLOoHAmwNOpq5/EQzPqL34Sgu2IOWEXTo X-Received: by 2002:a50:cd09:: with SMTP id z9mr20590420edi.152.1604446078540; Tue, 03 Nov 2020 15:27:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604446078; cv=none; d=google.com; s=arc-20160816; b=Klz1yy9pCpsB4QeYbLPT6zO2LWDI8THcYsS+alvtdffD5N33DAIkabfHARixjVF4I1 f1dn3LwOpfSSAPsnsaJ29SD4uMrTZFSuvbISvQkY0QV5UFO9ArG49XKLv+7o1bOvWhne cyE6dS9BPmKwGeSOZc5FUsKvJp06uAqdF6dYBCgRnvBTRFNyKJ1uc+S9jNYtg+y4f6iB EUUnUGbm7HOpMEgXXhgjtmhbFbDkdTP9eIyUp9ar/S4MxLTgOxHdTYx3vy5+gOLrAeWy eE6kCrnLc5md7y38KRMFsqsFAaXqds+Ui0N/locHXE0i13Rsgu322VV6SNwbaqh+6cPw g1kg== 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=7b7aCue6ZEwgCTWZQnBuJBTGOc7ywEdPSLtzQ5GjwPM=; b=b8bccTfl9ydg96ge56sepo9SIS3Eu/xv3zjGAFf3y7hgjpqBz7LJ6SahlZJQ6y5XUX j7fBeTEs66krTV2l9qYuszqo7U9JjrqqcunTOitvM31KsVShvvzsmbPRuMF7hjgEEQt/ 4ZNwlsMNvZJzfxLXErQ02UkoseWVkFtbrl7XbfCVLzG3OVygQPwPzCgf3mm26X2lIRQx h8ny0Jpd92azdiKX4urAgsiuDXGDuVWN9aCzu2S/IuY48fp1cV4UsVS3aX8RLc2wocal wW/GvYuj1PvOnRWpzoLMg/LXb9NEZwiXtbcktnWTzNvqRQ7P9/HBXLcbXgVBbls1DpGb aVGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i9IBXbR4; 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 cd26si229633ejb.746.2020.11.03.15.27.35; Tue, 03 Nov 2020 15:27:58 -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=i9IBXbR4; 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 S1732792AbgKCVbM (ORCPT + 99 others); Tue, 3 Nov 2020 16:31:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:60436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731434AbgKCU5y (ORCPT ); Tue, 3 Nov 2020 15:57:54 -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 EA4F92053B; Tue, 3 Nov 2020 20:57:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437074; bh=ETAY37V9+jSoGTqnl9UcgPunUWhPQ0cJvaAKy8DAllg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i9IBXbR4YrtDUnmyzvs9o2jGOranCJZsErk9Dhdueo6EiyGDPtGCLGRSfX5Y2myEv ikpHc58U6cohlfTXbitgAmeSXPufYbHLCSCQKUmHWyM7wik9zrQR4nprI5Op7Pe475 fwtWH4M6bcThU35mEquhEh3ZL51K1SJY5g3eZbNc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen , Felipe Balbi Subject: [PATCH 5.4 135/214] usb: dwc3: ep0: Fix ZLP for OUT ep0 requests Date: Tue, 3 Nov 2020 21:36:23 +0100 Message-Id: <20201103203303.499665032@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@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 @@ -942,12 +942,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) @@ -994,9 +998,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 {