Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5036325pxb; Mon, 15 Feb 2021 07:56:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJx1hTC0EdDdnbr/69rIJc4mq++F4yXZ9mhQZo5GgkIhn3ZS2S2XqJ0x5tpULGSZzbmh/fHR X-Received: by 2002:a17:906:dff1:: with SMTP id lc17mr15844518ejc.198.1613404591126; Mon, 15 Feb 2021 07:56:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613404591; cv=none; d=google.com; s=arc-20160816; b=izE9q46PAbrVneAtvqmwsi6EvYEx0QTA1HpgfIzX0G5YkbCE52z0NmYL3ATMb3LxFh Hj0cX/3Tyl1jhxpqdiwMk/5i5Gzc7Rmsa7U7IxdrUJaGNBSX5pi42sQBtcBK1WrE6Wcd plIteV/6262eXiNbVQJrfiswBvnC12xvOcdvw2TPC4L4IdfjZRR6hfJeBftzO3ZZSj0p 0ZvNTfTayxrgzvhxj52tQUwvvbg1pfvCJQgLwn+eUvUWpJuEmeJnOcjCCiCE1x+0FzR3 O9GP8MzFG9Jeq+hhztZTwjocD2WDcBWrmdqS+HJqOodsY60lC7OIo4BZF7C6XqXiu3/m uTyQ== 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=oYs477wvv80n6LTMBBCcsPAqe3Pw9qS79CX7lh664bo=; b=D/aRY7XeE3t51/YgzzDghN02svQ7vvlfU75w4tlPm+1d9Ox059zqs3JzW0xJVSqwbi Y/cVFerDx/D5CnTbbT2KgKH0QHsoleFQyQgxIGciqtpS14qlgkKCPudamOpCfMPsyNEH gjqVrNq1bBw79aBKTDCbblWfqp5TQQ1jhg6CbDrzofegf17y5D+5dYOes3hqZtXnLlV7 QYCYVWfoEQ978r4j7p1bQz6qVRESdicEpZf1tLR2v8IuUXAWCO+Ud2MigU9sm5i5xhwX DJdOtjF+heU8YLhpWEuZ349U6nLz+PHUbtH0H0V6DUbUqqEdu6TbRsRAPSS3jqqlU62n Jkew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=abE8o4px; 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 j9si7768105ejc.261.2021.02.15.07.56.08; Mon, 15 Feb 2021 07:56:31 -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=@linuxfoundation.org header.s=korg header.b=abE8o4px; 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 S232361AbhBOPxb (ORCPT + 99 others); Mon, 15 Feb 2021 10:53:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:45568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231218AbhBOPcd (ORCPT ); Mon, 15 Feb 2021 10:32:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6AED564EAC; Mon, 15 Feb 2021 15:29:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613402999; bh=bXu+3Njr8/+tN4f/IALTL9GxBcfMQjO99UoiG7nOQy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=abE8o4px3MCA60wUP+T+VKGlnmmuSftlC5Jz15jsfv++ART7Bs/7/xXLxltP6wYSE 8SSZVoOo8fM5tg+1uAFKUcZZsLDg+GyQr52KfSYFXnSn5dyGz543s3vzp9t+WFrDPe XGvZXUVtNsEVUHVxyabHeRmnJlGcN/xuhvgeLWjI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heikki Krogerus , Serge Semin , Sudip Mukherjee Subject: [PATCH 5.4 48/60] usb: dwc3: ulpi: Replace CPU-based busyloop with Protocol-based one Date: Mon, 15 Feb 2021 16:27:36 +0100 Message-Id: <20210215152716.913993294@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@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: Serge Semin commit fca3f138105727c3a22edda32d02f91ce1bf11c9 upstream Originally the procedure of the ULPI transaction finish detection has been developed as a simple busy-loop with just decrementing counter and no delays. It's wrong since on different systems the loop will take a different time to complete. So if the system bus and CPU are fast enough to overtake the ULPI bus and the companion PHY reaction, then we'll get to take a false timeout error. Fix this by converting the busy-loop procedure to take the standard bus speed, address value and the registers access mode into account for the busy-loop delay calculation. Here is the way the fix works. It's known that the ULPI bus is clocked with 60MHz signal. In accordance with [1] the ULPI bus protocol is created so to spend 5 and 6 clock periods for immediate register write and read operations respectively, and 6 and 7 clock periods - for the extended register writes and reads. Based on that we can easily pre-calculate the time which will be needed for the controller to perform a requested IO operation. Note we'll still preserve the attempts counter in case if the DWC USB3 controller has got some internals delays. [1] UTMI+ Low Pin Interface (ULPI) Specification, Revision 1.1, October 20, 2004, pp. 30 - 36. Fixes: 88bc9d194ff6 ("usb: dwc3: add ULPI interface support") Acked-by: Heikki Krogerus Signed-off-by: Serge Semin Link: https://lore.kernel.org/r/20201210085008.13264-3-Sergey.Semin@baikalelectronics.ru Cc: stable Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/ulpi.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) --- a/drivers/usb/dwc3/ulpi.c +++ b/drivers/usb/dwc3/ulpi.c @@ -7,6 +7,8 @@ * Author: Heikki Krogerus */ +#include +#include #include #include "core.h" @@ -17,12 +19,22 @@ DWC3_GUSB2PHYACC_ADDR(ULPI_ACCESS_EXTENDED) | \ DWC3_GUSB2PHYACC_EXTEND_ADDR(a) : DWC3_GUSB2PHYACC_ADDR(a)) -static int dwc3_ulpi_busyloop(struct dwc3 *dwc) +#define DWC3_ULPI_BASE_DELAY DIV_ROUND_UP(NSEC_PER_SEC, 60000000L) + +static int dwc3_ulpi_busyloop(struct dwc3 *dwc, u8 addr, bool read) { + unsigned long ns = 5L * DWC3_ULPI_BASE_DELAY; unsigned int count = 1000; u32 reg; + if (addr >= ULPI_EXT_VENDOR_SPECIFIC) + ns += DWC3_ULPI_BASE_DELAY; + + if (read) + ns += DWC3_ULPI_BASE_DELAY; + while (count--) { + ndelay(ns); reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYACC(0)); if (reg & DWC3_GUSB2PHYACC_DONE) return 0; @@ -47,7 +59,7 @@ static int dwc3_ulpi_read(struct device reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr); dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg); - ret = dwc3_ulpi_busyloop(dwc); + ret = dwc3_ulpi_busyloop(dwc, addr, true); if (ret) return ret; @@ -71,7 +83,7 @@ static int dwc3_ulpi_write(struct device reg |= DWC3_GUSB2PHYACC_WRITE | val; dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg); - return dwc3_ulpi_busyloop(dwc); + return dwc3_ulpi_busyloop(dwc, addr, false); } static const struct ulpi_ops dwc3_ulpi_ops = {