From patchwork Tue Oct 7 07:44:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Manoil X-Patchwork-Id: 397143 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 DCD2214008C for ; Tue, 7 Oct 2014 18:47:35 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753244AbaJGHrc (ORCPT ); Tue, 7 Oct 2014 03:47:32 -0400 Received: from [157.56.111.134] ([157.56.111.134]:48770 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753275AbaJGHrQ (ORCPT ); Tue, 7 Oct 2014 03:47:16 -0400 Received: from DM2PR03CA0036.namprd03.prod.outlook.com (10.141.96.35) by BL2PR03MB354.namprd03.prod.outlook.com (10.141.89.22) with Microsoft SMTP Server (TLS) id 15.0.1044.10; Tue, 7 Oct 2014 07:44:54 +0000 Received: from BY2FFO11FD044.protection.gbl (2a01:111:f400:7c0c::146) by DM2PR03CA0036.outlook.office365.com (2a01:111:e400:2428::35) with Microsoft SMTP Server (TLS) id 15.0.1044.10 via Frontend Transport; Tue, 7 Oct 2014 07:44:53 +0000 Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD044.mail.protection.outlook.com (10.1.14.229) with Microsoft SMTP Server (TLS) id 15.0.1039.16 via Frontend Transport; Tue, 7 Oct 2014 07:44:53 +0000 Received: from fsr-fed1764-016.ea.freescale.net (fsr-fed1764-016.ea.freescale.net [10.171.81.161]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id s977ie0T003260; Tue, 7 Oct 2014 00:44:52 -0700 From: Claudiu Manoil To: CC: "David S. Miller" , Xiubo Li , Shruti Kanetkar , "Kim Phillips" Subject: [net v2 7/8] gianfar: Replace spin_event_timeout() with arch independent Date: Tue, 7 Oct 2014 10:44:34 +0300 Message-ID: <1412667875-18225-8-git-send-email-claudiu.manoil@freescale.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1412667875-18225-1-git-send-email-claudiu.manoil@freescale.com> References: <1412667875-18225-1-git-send-email-claudiu.manoil@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(189002)(199003)(62966002)(50466002)(120916001)(89996001)(104166001)(76482002)(44976005)(50986999)(76176999)(6806004)(19580405001)(36756003)(77156001)(88136002)(102836001)(105606002)(19580395003)(99396003)(31966008)(104016003)(69596002)(33646002)(106466001)(81156004)(48376002)(84676001)(87936001)(92566001)(85852003)(68736004)(95666004)(87286001)(97736003)(4396001)(86362001)(93916002)(85306004)(50226001)(110136001)(2351001)(46102003)(80022003)(26826002)(64706001)(229853001)(92726001)(20776003)(21056001)(47776003)(107046002); DIR:OUT; SFP:1102; SCL:1; SRVR:BL2PR03MB354; H:az84smr01.freescale.net; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB354; X-Exchange-Antispam-Report-Test: UriScan:; X-Forefront-PRVS: 035748864E Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=claudiu.manoil@freescale.com; X-OriginatorOrg: freescale.com Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use arch independent code to replace the powerpc dependent spin_event_timeout() from gfar_halt_nodisable(). Added GRS/GTS read accessors to clean-up the implementation of gfar_halt_nodisable(). Signed-off-by: Claudiu Manoil --- v2 - none drivers/net/ethernet/freescale/gianfar.c | 32 +++++++++++++++++++------------- drivers/net/ethernet/freescale/gianfar.h | 15 +++++++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/freescale/gianfar.c b/drivers/net/ethernet/freescale/gianfar.c index 961198a..356a998 100644 --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -1762,26 +1762,32 @@ static void gfar_halt_nodisable(struct gfar_private *priv) { struct gfar __iomem *regs = priv->gfargrp[0].regs; u32 tempval; + unsigned int timeout; + int stopped; gfar_ints_disable(priv); + if (gfar_is_dma_stopped(priv)) + return; + /* Stop the DMA, and wait for it to stop */ tempval = gfar_read(®s->dmactrl); - if ((tempval & (DMACTRL_GRS | DMACTRL_GTS)) != - (DMACTRL_GRS | DMACTRL_GTS)) { - int ret; - - tempval |= (DMACTRL_GRS | DMACTRL_GTS); - gfar_write(®s->dmactrl, tempval); + tempval |= (DMACTRL_GRS | DMACTRL_GTS); + gfar_write(®s->dmactrl, tempval); - do { - ret = spin_event_timeout(((gfar_read(®s->ievent) & - (IEVENT_GRSC | IEVENT_GTSC)) == - (IEVENT_GRSC | IEVENT_GTSC)), 1000000, 0); - if (!ret && !(gfar_read(®s->ievent) & IEVENT_GRSC)) - ret = __gfar_is_rx_idle(priv); - } while (!ret); +retry: + timeout = 1000; + while (!(stopped = gfar_is_dma_stopped(priv)) && timeout) { + cpu_relax(); + timeout--; } + + if (!timeout) + stopped = gfar_is_dma_stopped(priv); + + if (!stopped && !gfar_is_rx_dma_stopped(priv) && + !__gfar_is_rx_idle(priv)) + goto retry; } /* Halt the receive and transmit queues */ diff --git a/drivers/net/ethernet/freescale/gianfar.h b/drivers/net/ethernet/freescale/gianfar.h index 84632c5..0b37722 100644 --- a/drivers/net/ethernet/freescale/gianfar.h +++ b/drivers/net/ethernet/freescale/gianfar.h @@ -1226,6 +1226,21 @@ static inline void gfar_write_isrg(struct gfar_private *priv) } } +static inline int gfar_is_dma_stopped(struct gfar_private *priv) +{ + struct gfar __iomem *regs = priv->gfargrp[0].regs; + + return ((gfar_read(®s->ievent) & (IEVENT_GRSC | IEVENT_GTSC)) == + (IEVENT_GRSC | IEVENT_GTSC)); +} + +static inline int gfar_is_rx_dma_stopped(struct gfar_private *priv) +{ + struct gfar __iomem *regs = priv->gfargrp[0].regs; + + return gfar_read(®s->ievent) & IEVENT_GRSC; +} + irqreturn_t gfar_receive(int irq, void *dev_id); int startup_gfar(struct net_device *dev); void stop_gfar(struct net_device *dev);