From patchwork Tue Dec 3 23:42:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King - ARM Linux X-Patchwork-Id: 3279631 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 522EAC0D4A for ; Tue, 3 Dec 2013 23:43:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 77EBC20483 for ; Tue, 3 Dec 2013 23:43:48 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 961232046F for ; Tue, 3 Dec 2013 23:43:47 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vnzcp-0003gH-L0; Tue, 03 Dec 2013 23:43:31 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vnzce-0005LL-1m; Tue, 03 Dec 2013 23:43:20 +0000 Received: from [2002:4e20:1eda::1] (helo=caramon.arm.linux.org.uk) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Vnzca-0005HF-1c for linux-arm-kernel@lists.infradead.org; Tue, 03 Dec 2013 23:43:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=caramon; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=7rgCoHC2X3g810u0gXhslj/bWrTGXm7qPFak6dksEU8=; b=e3QORbh7oQtk6vqcxnGA+DGs0+RIEQtKKgu0+aU8Yq9ukGOE3EqsdKr5NwT44GsQxs97tDnEheQhIEUb40L9PDxDCyj9g+UZoBUa9w3M9rP4rUNrLm6qnz+T7i+Dalzi9knSfe71z+0J9Lll0W7o475mNF1dxeWks6FgWAfW7N4=; Received: from n2100.arm.linux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]:42164) by caramon.arm.linux.org.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1Vnzbb-00045u-1j; Tue, 03 Dec 2013 23:42:15 +0000 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.76) (envelope-from ) id 1VnzbW-00008B-Kz; Tue, 03 Dec 2013 23:42:10 +0000 Date: Tue, 3 Dec 2013 23:42:09 +0000 From: Russell King - ARM Linux To: Leigh Brown Subject: Re: Spurious timeouts in mvmdio Message-ID: <20131203234209.GW16735@n2100.arm.linux.org.uk> References: <529CA42A.3040504@freebox.fr> <20131203122346.GD29282@titan.lakedaemon.net> <20131203124033.GT16735@n2100.arm.linux.org.uk> <529E5F03.8040607@gmail.com> <8d65780eb7bfe49bb0734a09f05f70a6@doppler.thel33t.co.uk> <529E66A4.4050000@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131203_184316_677904_41CB9D7F X-CRM114-Status: GOOD ( 18.98 ) X-Spam-Score: -1.0 (-) Cc: Jason Cooper , Nicolas Schichan , netdev@vger.kernel.org, LKML , "David S. Miller" , Florian Fainelli , linux-arm-kernel@lists.infradead.org, Sebastian Hesselbarth X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Dec 03, 2013 at 11:38:23PM +0000, Leigh Brown wrote: > On 2013-12-03 23:17, Sebastian Hesselbarth wrote: >> If you want to ensure timeout > 2, why not then just use: >> >> - unsigned long timeout = usecs_to_jiffies(MVMDIO_SMI_TIMEOUT); >> + unsigned long timeout = 1 + usecs_to_jiffies(MVMDIO_SMI_TIMEOUT); > > This will make it correct when using interrupts but it will make the > loop wait one jiffie longer than it should when polling. Alternatively, code it like this instead. drivers/net/ethernet/marvell/mvmdio.c | 32 +++++++++++++++----------------- 1 files changed, 15 insertions(+), 17 deletions(-) Tested-by: Nicolas Schichan diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 7354960b583b..a6f59831fc5b 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -76,31 +76,29 @@ static int orion_mdio_wait_ready(struct mii_bus *bus) { struct orion_mdio_dev *dev = bus->priv; unsigned long timeout = usecs_to_jiffies(MVMDIO_SMI_TIMEOUT); - unsigned long end = jiffies + timeout; - int timedout = 0; - while (1) { - if (orion_mdio_smi_is_done(dev)) + if (dev->err_interrupt > 0) { + if (wait_event_timeout(dev->smi_busy_wait, + orion_mdio_smi_is_done(dev), + 1 + timeout)) return 0; - else if (timedout) - break; + } else { + unsigned long end = jiffies + timeout; - if (dev->err_interrupt <= 0) { - usleep_range(MVMDIO_SMI_POLL_INTERVAL_MIN, - MVMDIO_SMI_POLL_INTERVAL_MAX); + while (1) { + if (orion_mdio_smi_is_done(dev)) + return 0; if (time_is_before_jiffies(end)) - ++timedout; - } else { - wait_event_timeout(dev->smi_busy_wait, - orion_mdio_smi_is_done(dev), - timeout); - - ++timedout; - } + break; + + usleep_range(MVMDIO_SMI_POLL_INTERVAL_MIN, + MVMDIO_SMI_POLL_INTERVAL_MAX); + } } dev_err(bus->parent, "Timeout: SMI busy for too long\n"); + return -ETIMEDOUT; }