From patchwork Mon Dec 16 18:28:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leigh Brown X-Patchwork-Id: 3356191 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 858C79F386 for ; Mon, 16 Dec 2013 18:21:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 654EE2020E for ; Mon, 16 Dec 2013 18:21:52 +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 2DAF120148 for ; Mon, 16 Dec 2013 18:21:51 +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 1VscnQ-00054K-7Q; Mon, 16 Dec 2013 18:21:36 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VscnN-0002Sd-Q3; Mon, 16 Dec 2013 18:21:33 +0000 Received: from doppler.thel33t.co.uk ([193.110.88.198]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VscnJ-0002Qv-V6 for linux-arm-kernel@lists.infradead.org; Mon, 16 Dec 2013 18:21:31 +0000 Received: from doppler.thel33t.co.uk (localhost [127.0.0.1]) by doppler.thel33t.co.uk (Postfix) with ESMTP id 63294840B4; Mon, 16 Dec 2013 18:28:03 +0000 (GMT) MIME-Version: 1.0 Date: Mon, 16 Dec 2013 18:28:03 +0000 From: Leigh Brown To: Nicolas Schichan Subject: Re: Spurious timeouts in mvmdio In-Reply-To: <52AF4160.9080703@freebox.fr> 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> <20131203234209.GW16735@n2100.arm.linux.org.uk> <52AF4160.9080703@freebox.fr> Message-ID: X-Sender: leigh@solinno.co.uk User-Agent: Roundcube Webmail/0.6 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131216_132130_204153_699D1164 X-CRM114-Status: GOOD ( 22.33 ) X-Spam-Score: -1.9 (-) Cc: Russell King - ARM Linux , Jason Cooper , netdev@vger.kernel.org, LKML , Florian Fainelli , "David S. Miller" , 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.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 2013-12-16 18:07, Nicolas Schichan wrote: > On 12/04/2013 12:42 AM, Russell King - ARM Linux wrote: >> Alternatively, code it like this instead. >> >> drivers/net/ethernet/marvell/mvmdio.c | 32 >> +++++++++++++++----------------- >> 1 files changed, 15 insertions(+), 17 deletions(-) >> >> 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; >> } > > Hi Russell, > > I did not find any commit for this in 3.13-rc4. > > Would you prefer I submit my attempt at refactoring the > orion_mdio_wait_ready() code ? I prefer this patch (which I think you originally proposed) because it is just as correct and the code size is a bit smaller in arm mode, and the same size in thumb mode (on my compiler gcc 4.7.2, at least). I coded the loop in that way to make it small. I don't mind submitting it to David as I made the mistake in the first place. Regards, Leigh. Tested-by: Nicolas Schichan diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c index 7354960..a42a750 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -92,6 +92,12 @@ static int orion_mdio_wait_ready(struct mii_bus *bus) if (time_is_before_jiffies(end)) ++timedout; } else { + /* wait_event_timeout does not guarantee a delay of at + * least one whole jiffie, so timeout must be no less + * than two. + */ + if (timeout < 2) + timeout = 2; wait_event_timeout(dev->smi_busy_wait, orion_mdio_smi_is_done(dev), timeout);