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: 296353 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1D4B22C00A0 for ; Wed, 4 Dec 2013 10:43:14 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756003Ab3LCXml (ORCPT ); Tue, 3 Dec 2013 18:42:41 -0500 Received: from caramon.arm.linux.org.uk ([78.32.30.218]:43926 "EHLO caramon.arm.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753478Ab3LCXmi (ORCPT ); Tue, 3 Dec 2013 18:42:38 -0500 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 Cc: Sebastian Hesselbarth , Nicolas Schichan , Jason Cooper , netdev@vger.kernel.org, LKML , Florian Fainelli , "David S. Miller" , linux-arm-kernel@lists.infradead.org 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) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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; }