Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1569209pxb; Mon, 22 Feb 2021 05:36:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzDtgiu+abnVbyv6bsa7DI0GkJd0xVDw5Bip97TXCL5j7dKeffV5BAH4ZGXumNmz9d4HSob X-Received: by 2002:a17:906:3105:: with SMTP id 5mr21161922ejx.168.1614001000834; Mon, 22 Feb 2021 05:36:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614001000; cv=none; d=google.com; s=arc-20160816; b=UTc0MGaOWFZRGBlIIBOiq0eqMg05pF9sOuTR5NbY1MIfP1oQ57GovSb84Tjnzlvf3/ Yf2QAHef6xqI9HO3a0eFaco5tc1BtEjupFhfEY0/hNpnxh1v6lIsFfHgNCXtfi+ztV95 ri6eVuldvIByuU8+FKm1iEJaWdNXiWum/cMww/ivKG8MknLKQM6TcsA/LBUgl2M3dok4 U7oVr3E4xTWALLYk+64sXXZs7mnRFqs1n1iMfEnmtRqX25vZzPsyksFcyJmHnfgLltLk 0iOT3FtmNVWpRMar4nowpWoyrG6gk3FoEB8mVCHKcPEHC9KwVOswd1BASaCLoviO6xEm uJZA== 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=g2j6LDc+Dl2USOndpjVNehBDMuxW2dRldRE1OjExiVc=; b=nBvtkWGapUbA5fizSU9sKLHKE/fnx4sdsbrg6pkLHN9+WHhmPgYgoepZvKxVoeJ5yR IlDEAGNyVzNof+DPoRmImEGRw9gtk9FFJILRXP4hFaaiP5GiIJ7VAGPqaMMiXUoGQFnU L5Ka+A5KPiMMGvcbeq3mSTxmV6oYtmKMozgUx2eVaWvoFKC7PibeRX9SzXSHhKDHzuGQ 719zZ22o/ytw9xNV967YQmURwoT7MPegAwtVju47yk/++zeJGRWAXVApU2bpeq7IuOoa 1mEBUbQhLQI7HgYPtdFVODWoCgm4pL1cSuZRJvylmLfnvESXqs4yt1BHOwHd+anAgX2p 1uIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=J87e1y7b; 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 kl24si12172995ejc.100.2021.02.22.05.36.18; Mon, 22 Feb 2021 05:36:40 -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=J87e1y7b; 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 S232125AbhBVNdu (ORCPT + 99 others); Mon, 22 Feb 2021 08:33:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:53774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231443AbhBVMmu (ORCPT ); Mon, 22 Feb 2021 07:42:50 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9C1D864F33; Mon, 22 Feb 2021 12:39:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613997600; bh=nFLcdRYG5BoNf50u87HcTK1GEttFGjZ73CL2dGIcOm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J87e1y7b1w/OzGO8CRXOU454TOjBOdqrtYdNqk50qT52uwRJDs+GqtNY6scSmRIaT M25ZVhMabRs85iZmF+ctWwXGt8lAKAY+pfDeyDqi1D/WmaOjZd/P97tWvFLqPynt8o J0G7WPhbDYtKsnMDj53ZesEAHBt0DWrsnJqvcES8= 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 4.4 18/35] usb: dwc3: ulpi: Replace CPU-based busyloop with Protocol-based one Date: Mon, 22 Feb 2021 13:36:14 +0100 Message-Id: <20210222121020.129125658@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210222121013.581198717@linuxfoundation.org> References: <20210222121013.581198717@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 [sudip: adjust context] 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 @@ -10,6 +10,8 @@ * published by the Free Software Foundation. */ +#include +#include #include #include "core.h" @@ -20,12 +22,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_BUSY)) return 0; @@ -44,7 +56,7 @@ static int dwc3_ulpi_read(struct ulpi_op 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; @@ -62,7 +74,7 @@ static int dwc3_ulpi_write(struct ulpi_o 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 struct ulpi_ops dwc3_ulpi_ops = {