Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp432568pxj; Thu, 20 May 2021 12:45:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA+EyTjvl3F880DZQcmCYWCAkpeYxX8LW+tZ+kwPIILZ4XgFbXMYHUQLp+/KEn4OQRu5v0 X-Received: by 2002:a05:6402:1158:: with SMTP id g24mr6646298edw.134.1621539927447; Thu, 20 May 2021 12:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621539927; cv=none; d=google.com; s=arc-20160816; b=Iag4Qkzdt/Mb1SjzTok70/J9+tBaCa3hrJoYw/63ccPnkPVxt9MXdQucBioiXAM+RP 4EX8BWTWZo21U5GK/aDi8WouxgA8H1MaeRIqpuQZlC7zCTXAkNoeVlpN60r6HG8quYwL 6PPSePCX9+Z+AUTkC71+XKnMgqDhJhBf7PC38l2TcylrVZYY3UYg1wQJE71HHppuyKuy 6cv40mZA6i4PJmH644MdiTKIyluGeJrgcvET1XU6fFuxvMT0yf+oSXcUyvZdWvtPNBa9 T2QeqbghNTTN8GeSlZxTtq/6+IOjEi19dwPpMvWO5xo3+UuaG4wRAxPwXfnDqmgo1IjD 9q5w== 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=KhPAZj43SKpqaQBdGRbT1XiA6R8tHBq7oqBRr8w+/Tk=; b=e/Ij61HUyS+MYvdpfBSZh47FGykZXT6DBahAIxiqtWU49oPIXG/7lYmqOuKjWp/A59 VqdnUub+wKvD4h6K0mUqQwuqR7ULlDs7ROJOMkFgJd7QzkgQ6K9ZxKzOdZFGoA6DXNV5 vvaB7swr7SYSUrJ7QnEsmdrHkCr9vAANIhI1Sq2lYjBHwQTMBBcCltDNSDrH1Yqul6gq fRCtJVTzYcisBgAy6IyA6UvFAmcHUBHohVHM6plwDQPUTU1P8rl7moiryCLUX6Y+6kcF atZT4ulInuAWBWA+XdkIEiJ/zFm12AVD7wUGKlUmF2iPFzMLIXFEIK1SG1ntn0OEB8L8 zHcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pHrvI207; 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=pass (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 ds10si4124225ejc.559.2021.05.20.12.45.02; Thu, 20 May 2021 12:45:27 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=pHrvI207; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236856AbhETKkT (ORCPT + 99 others); Thu, 20 May 2021 06:40:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:55676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235978AbhETKZj (ORCPT ); Thu, 20 May 2021 06:25:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 82F3661A19; Thu, 20 May 2021 09:49:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504189; bh=svMnD97kcxSsQYIJRs6AoqGB3t7hPcCceON0I3cbFEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pHrvI207OnZCPrDsaj1k/GiwBiF48b/LGOm+Bzp2kyvTlOfHxnpiGWiphpriQ78l/ m0GLM4H4L6wwWwJWoYtsu0bGTzBuaBqsQ1sEo2NMisHU+dRoZ8g+rAdXcO1CHDGRpp wVujw6e5KDwF19Ewbtq06IVZRA4Cf0hirGWw60JE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Felipe Balbi , Thinh Nguyen Subject: [PATCH 4.14 098/323] usb: dwc3: gadget: Fix START_TRANSFER link state check Date: Thu, 20 May 2021 11:19:50 +0200 Message-Id: <20210520092123.463021997@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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 c560e76319a94a3b9285bc426c609903408e4826 upstream. The START_TRANSFER command needs to be executed while in ON/U0 link state (with an exception during register initialization). Don't use dwc->link_state to check this since the driver only tracks the link state when the link state change interrupt is enabled. Check the link state from DSTS register instead. Note that often the host already brings the device out of low power before it sends/requests the next transfer. So, the user won't see any issue when the device starts transfer then. This issue is more noticeable in cases when the device delays starting transfer, which can happen during delayed control status after the host put the device in low power. Fixes: 799e9dc82968 ("usb: dwc3: gadget: conditionally disable Link State change events") Cc: Acked-by: Felipe Balbi Signed-off-by: Thinh Nguyen Link: https://lore.kernel.org/r/bcefaa9ecbc3e1936858c0baa14de6612960e909.1618884221.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -310,13 +310,12 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ } if (DWC3_DEPCMD_CMD(cmd) == DWC3_DEPCMD_STARTTRANSFER) { - int needs_wakeup; + int link_state; - needs_wakeup = (dwc->link_state == DWC3_LINK_STATE_U1 || - dwc->link_state == DWC3_LINK_STATE_U2 || - dwc->link_state == DWC3_LINK_STATE_U3); - - if (unlikely(needs_wakeup)) { + link_state = dwc3_gadget_get_link_state(dwc); + if (link_state == DWC3_LINK_STATE_U1 || + link_state == DWC3_LINK_STATE_U2 || + link_state == DWC3_LINK_STATE_U3) { ret = __dwc3_gadget_wakeup(dwc); dev_WARN_ONCE(dwc->dev, ret, "wakeup failed --> %d\n", ret); @@ -1671,6 +1670,8 @@ static int __dwc3_gadget_wakeup(struct d case DWC3_LINK_STATE_RESET: case DWC3_LINK_STATE_RX_DET: /* in HS, means Early Suspend */ case DWC3_LINK_STATE_U3: /* in HS, means SUSPEND */ + case DWC3_LINK_STATE_U2: /* in HS, means Sleep (L1) */ + case DWC3_LINK_STATE_U1: case DWC3_LINK_STATE_RESUME: break; default: