Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp329917ybi; Fri, 7 Jun 2019 08:44:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqySO45B5l1AY3cqYA/0YIuPjUB6ykOqaXKI812VonzlcmpfS5NJbp+BLAuZKKKv5FIZmyu3 X-Received: by 2002:a17:90a:338e:: with SMTP id n14mr6012214pjb.35.1559922251599; Fri, 07 Jun 2019 08:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559922251; cv=none; d=google.com; s=arc-20160816; b=xWW9I3+UPlePch1UQZTyNaoSan6gV3aP5/NqxE4Xho+JMKaNCiTU/uq6NmRnAigPvp MNd07U7Y65F2x/PYkU3J7UwmwZu6bunABpjD/pun7n1dj+bJm1oEzkougbUxi0nKkjG7 cpKL6MFEUn3JcWW825Zq0y8FBIC/rLIEIaEuvkZ2hmDRVcrGWNU8AY0gdBbxcFpNZXhS l91bA0YYLekTgvFUVfZOC+HEg+moCHwO7hMp2NHYk2kYOQ5Wi+MCzilUk499VuUSkcnh iAzcW9+kIDIL/k2pI3/PtJXBnNl6o8TTL/pXCPKikq5n9ugQpa6peLGx+de2xBEqgEF+ 2ZAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gWkZoPLvmHlunmouiNn9X1/MLiYgbKrbOtW79k69mow=; b=pdDd81yYlXWfiyTZpqpnj12+9L1nUm/eWxwHbTdlUkXlDqNfYo6unFCNlULPOXafBJ k2SCXZL46WGKkgiNs3Z/Oem09xDkN7P8d73W6dxAStHN81tvWHcF1YssZF6oAkjJq3Zo UN/XmrNSKh97GW859N7c5u4agYrkTYWvnLXNHE/KGCMy3+yMS53yeY1fKVB8/Mtg+hzG dKs562lHasEj532Ath8L+6PGz/0aJraSf/3MZbCMGtDQk/pEh7Su7gFb5EzDrH38Nund A+E4NdNRe6sjAmcxuI1TfYVdaR89RX26c0DHZd/QKE8aEX6TBTR09fH6ahRv2KiQY8lR dptQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Yx0Dhlz7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si2105580plr.138.2019.06.07.08.43.55; Fri, 07 Jun 2019 08:44:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Yx0Dhlz7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730240AbfFGPlK (ORCPT + 99 others); Fri, 7 Jun 2019 11:41:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:50800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730198AbfFGPlJ (ORCPT ); Fri, 7 Jun 2019 11:41:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 A3F8721473; Fri, 7 Jun 2019 15:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559922069; bh=bdchFBGelyjrQhZP75ch+5StzXsh7Me+0soDNYTxoSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Yx0Dhlz7c7W4F6tWOS0rG1PLaMyopBSDLZQPnovUXq0df91fW7Va4YSj4vR9rPezE QVBycLype1WLGPrA4jlOrtfU4ey0/echY/k/UehuhJfB5caoDxUSuIpVOKgXQN3jji UvUOLRKVk3guJ36kVr42yYpZepeuDQf+gIDLTniM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Smirnov , Raul E Rangel , Mathias Nyman Subject: [PATCH 4.14 25/69] xhci: Convert xhci_handshake() to use readl_poll_timeout_atomic() Date: Fri, 7 Jun 2019 17:39:06 +0200 Message-Id: <20190607153851.495996005@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190607153848.271562617@linuxfoundation.org> References: <20190607153848.271562617@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrey Smirnov commit f7fac17ca925faa03fc5eb854c081a24075f8bad upstream. Xhci_handshake() implements the algorithm already captured by readl_poll_timeout_atomic(). Convert the former to use the latter to avoid repetition. Turned out this patch also fixes a bug on the AMD Stoneyridge platform where usleep(1) sometimes takes over 10ms. This means a 5 second timeout can easily take over 15 seconds which will trigger the watchdog and reboot the system. [Add info about patch fixing a bug to commit message -Mathias] Signed-off-by: Andrey Smirnov Tested-by: Raul E Rangel Reviewed-by: Raul E Rangel Cc: Signed-off-by: Mathias Nyman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/host/xhci.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -21,6 +21,7 @@ */ #include +#include #include #include #include @@ -62,7 +63,6 @@ static bool td_on_ring(struct xhci_td *t return false; } -/* TODO: copied from ehci-hcd.c - can this be refactored? */ /* * xhci_handshake - spin reading hc until handshake completes or fails * @ptr: address of hc register to be read @@ -79,18 +79,16 @@ static bool td_on_ring(struct xhci_td *t int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec) { u32 result; + int ret; - do { - result = readl(ptr); - if (result == ~(u32)0) /* card removed */ - return -ENODEV; - result &= mask; - if (result == done) - return 0; - udelay(1); - usec--; - } while (usec > 0); - return -ETIMEDOUT; + ret = readl_poll_timeout_atomic(ptr, result, + (result & mask) == done || + result == U32_MAX, + 1, usec); + if (result == U32_MAX) /* card removed */ + return -ENODEV; + + return ret; } /*