From patchwork Wed Sep 5 08:19:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Ferre X-Patchwork-Id: 1405991 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 3F075DF264 for ; Wed, 5 Sep 2012 08:23:25 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T9Aq3-0000ng-6p; Wed, 05 Sep 2012 08:19:55 +0000 Received: from eusmtp01.atmel.com ([212.144.249.242]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T9Apw-0000mC-AK for linux-arm-kernel@lists.infradead.org; Wed, 05 Sep 2012 08:19:50 +0000 Received: from HNOCHT02.corp.atmel.com (10.161.30.162) by eusmtp01.atmel.com (10.161.101.30) with Microsoft SMTP Server (TLS) id 14.2.318.1; Wed, 5 Sep 2012 10:21:33 +0200 Received: from tenerife.rfo.atmel.com (10.161.30.18) by HNOCHT02.corp.atmel.com (10.161.30.162) with Microsoft SMTP Server (TLS) id 14.2.318.1; Wed, 5 Sep 2012 10:19:46 +0200 From: Nicolas Ferre To: Subject: [PATCH 04/10] net/macb: Fix a race in macb_start_xmit() Date: Wed, 5 Sep 2012 10:19:11 +0200 Message-ID: <40f02ee50a29aaec6c949432a1bcf09f4b027181.1346775479.git.nicolas.ferre@atmel.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.161.30.18] X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.1 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: patrice.vilchez@atmel.com, nicolas.ferre@atmel.com, linux-kernel@vger.kernel.org, havard@skinnemoen.net, jamie@jamieiles.com, plagnioj@jcrosoft.com, davem@davemloft.net, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Havard Skinnemoen Fix a race in macb_start_xmit() where we unconditionally set the TSTART bit. If an underrun just happened (we do this with interrupts disabled, so it might not have been handled yet), the controller starts transmitting from the first entry in the ring, which is usually wrong. Restart the controller after error handling. Signed-off-by: Havard Skinnemoen [nicolas.ferre@atmel.com: split patch in topics] Signed-off-by: Nicolas Ferre --- drivers/net/ethernet/cadence/macb.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index 2228dfc..f4b8adf 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -390,6 +390,13 @@ static void macb_tx(struct macb *bp) dev_kfree_skb_irq(skb); } + /* + * Someone may have submitted a new frame while this interrupt + * was pending, or we may just have handled an error. + */ + if (head != tail && !(status & MACB_BIT(TGO))) + macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); + bp->tx_tail = tail; if (netif_queue_stopped(bp->dev) && TX_BUFFS_AVAIL(bp) > MACB_TX_WAKEUP_THRESH) @@ -696,7 +703,18 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev) skb_tx_timestamp(skb); - macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); + /* + * Only start the controller if the queue was empty; otherwise + * we may race against the hardware resetting the ring pointer + * due to a transmit error. + * + * If the controller is idle but the queue isn't empty, there + * must be a pending interrupt that will trigger as soon as we + * re-enable interrupts, and the interrupt handler will make + * sure the controler is started. + */ + if (NEXT_TX(bp->tx_tail) == bp->tx_head) + macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TSTART)); if (TX_BUFFS_AVAIL(bp) < 1) netif_stop_queue(dev);