From patchwork Fri Jul 18 09:53:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 371429 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 C110114013B for ; Fri, 18 Jul 2014 19:53:54 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964915AbaGRJxd (ORCPT ); Fri, 18 Jul 2014 05:53:33 -0400 Received: from mail-we0-f172.google.com ([74.125.82.172]:56712 "EHLO mail-we0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933956AbaGRJxb (ORCPT ); Fri, 18 Jul 2014 05:53:31 -0400 Received: by mail-we0-f172.google.com with SMTP id x48so4392866wes.3 for ; Fri, 18 Jul 2014 02:53:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=tQDyXYUwvwkLq/+plwoxTAY2nTZq6vWb0nyAoDqy6Kc=; b=L62/deMUNccyKh18jSlDwYqGwmzd1XRzNGjJd7OyhwUOEA83rc/GMwD2xZW+vzzOYh DPBGRrQDawrRhJUeU011i5D8hq8zRimLTqfbEOrI6ZSRRNrr55D5UF50sFddAFOFxt4u 6QC/u2WZ1tKa6fXpzMgrCoRvajQQ8NQpiljFVlMR3aH903uJ4hhxW0Lc/0dz6zRuLbrc N9B6R+QNNkWxZF3lDiDyoCeP+Px93NepRr0jpljF2wV964V739OUrrVbHp0Mgd4n4xSp ZERlNyBpGpTSpTYSGgc4ZAUShkZG4F8rkyJp0oehnBRyZfgSb+m1N3XQy1XdnOZqT3sv +PWQ== X-Received: by 10.181.11.232 with SMTP id el8mr5997959wid.57.1405677210296; Fri, 18 Jul 2014 02:53:30 -0700 (PDT) Received: from [10.140.1.109] (sop06-1-82-228-251-23.fbx.proxad.net. [82.228.251.23]) by mx.google.com with ESMTPSA id d12sm12972748wjx.0.2014.07.18.02.53.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Jul 2014 02:53:29 -0700 (PDT) Message-ID: <53C8EE99.6070605@gmail.com> Date: Fri, 18 Jul 2014 11:53:29 +0200 From: Neil Armstrong User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Nicolas Ferre , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] net: macb: Handle errors in RX path Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In certain circumstances, the MACB fails to write correct RX ring descriptor, and lead to actually managed by BUG_ON() error cases. Handle these two cases by returning error values, while resetting the RX ring and RX HW path in the poll methos. In the same time, check and handle BNA and OVR into poll method by using the same error management. Signed-off-by: Neil Armstrong --- drivers/net/ethernet/cadence/macb.c | 55 +++++++++++++++++++++++++++++++--- 1 files changed, 50 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c index 20ad483..c94355d 100644 --- a/drivers/net/ethernet/cadence/macb.c +++ b/drivers/net/ethernet/cadence/macb.c @@ -755,6 +755,17 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag, macb_rx_ring_wrap(first_frag), macb_rx_ring_wrap(last_frag), len); + if (!(desc->ctrl & MACB_BIT(RX_EOF))) { + netdev_vdbg(bp->dev, "macb_rx_frame missing EOF\n"); + return -EIO; + } + + desc = macb_rx_desc(bp, first_frag); + if (!(desc->ctrl & MACB_BIT(RX_SOF))) { + netdev_vdbg(bp->dev, "macb_rx_frame missing SOF\n"); + return -EIO; + } + /* * The ethernet header starts NET_IP_ALIGN bytes into the * first buffer. Since the header is 14 bytes, this makes the @@ -789,7 +800,10 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag, unsigned int frag_len = bp->rx_buffer_size; if (offset + frag_len > len) { - BUG_ON(frag != last_frag); + if(frag != last_frag) { + dev_kfree_skb_any(skb); + return -EIO; + } frag_len = len - offset; } skb_copy_to_linear_data_offset(skb, offset, @@ -844,9 +858,13 @@ static int macb_rx(struct macb *bp, int budget) if (ctrl & MACB_BIT(RX_EOF)) { int dropped; - BUG_ON(first_frag == -1); + if (first_frag == -1) + return -EIO; dropped = macb_rx_frame(bp, first_frag, tail); + if (dropped < 0) + return dropped; + first_frag = -1; if (!dropped) { received++; @@ -872,12 +890,22 @@ static int macb_poll(struct napi_struct *napi, int budget) status = macb_readl(bp, RSR); macb_writel(bp, RSR, status); - work_done = 0; + work_done = -EIO; netdev_vdbg(bp->dev, "poll: status = %08lx, budget = %d\n", - (unsigned long)status, budget); + (unsigned long)status, budget); + + if (status & (MACB_BIT(OVR) | MACB_BIT(BNA)) || + !(status & MACB_BIT(REC))) { + netdev_err(bp->dev, "RX error, status = %02lx\n", + (unsigned long)status); + goto rx_out; + } work_done = bp->macbgem_ops.mog_rx(bp, budget); + if (work_done < 0) + goto rx_out; + if (work_done < budget) { napi_complete(napi); @@ -892,7 +920,24 @@ static int macb_poll(struct napi_struct *napi, int budget) } } - /* TODO: Handle errors */ + return work_done; + +rx_out: + /* + * In case of error, disable RX and reset + * the descriptor ring before re-enabling RX. + */ + macb_writel(bp, NCR, macb_readl(bp, NCR) & ~MACB_BIT(RE)); + + bp->macbgem_ops.mog_init_rx_rings(bp); + macb_writel(bp, RBQP, bp->rx_ring_dma); + + /* Re-enable RX and get notified for new packets */ + macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(RE)); + + napi_complete(napi); + + macb_writel(bp, IER, MACB_RX_INT_FLAGS); return work_done; }