2015-04-12 22:10:40 +00:00
|
|
|
From: Felix Fietkau <nbd@openwrt.org>
|
|
|
|
Date: Sun, 12 Apr 2015 22:23:07 +0200
|
|
|
|
Subject: [PATCH] bgmac: simplify rx DMA error handling
|
|
|
|
|
2015-04-13 17:32:33 +00:00
|
|
|
Unmap the DMA buffer before checking it. If an error occurs, free the
|
|
|
|
buffer and allocate a new one. If allocation or mapping fails, retry as
|
|
|
|
long as there is NAPI poll budget left (count every attempt instead of
|
|
|
|
every frame).
|
2015-04-12 22:10:40 +00:00
|
|
|
|
|
|
|
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
|
|
|
|
---
|
|
|
|
|
|
|
|
--- a/drivers/net/ethernet/broadcom/bgmac.c
|
|
|
|
+++ b/drivers/net/ethernet/broadcom/bgmac.c
|
2015-04-13 17:32:33 +00:00
|
|
|
@@ -404,51 +404,33 @@ static int bgmac_dma_rx_read(struct bgma
|
|
|
|
void *buf = slot->buf;
|
2015-04-12 22:10:40 +00:00
|
|
|
u16 len, flags;
|
|
|
|
|
2015-04-13 17:32:33 +00:00
|
|
|
- /* Unmap buffer to make it accessible to the CPU */
|
2015-04-12 22:10:40 +00:00
|
|
|
- dma_sync_single_for_cpu(dma_dev, slot->dma_addr,
|
|
|
|
- BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
|
2015-04-13 17:32:33 +00:00
|
|
|
-
|
|
|
|
- /* Get info from the header */
|
|
|
|
- len = le16_to_cpu(rx->len);
|
|
|
|
- flags = le16_to_cpu(rx->flags);
|
|
|
|
+ if (++handled >= weight - 1) /* Should never be greater */
|
|
|
|
+ break;
|
2015-04-12 22:10:40 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
- dma_addr_t old_dma_addr = slot->dma_addr;
|
2015-04-13 17:32:33 +00:00
|
|
|
- int err;
|
|
|
|
+ if (!slot->dma_addr)
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ /* Unmap buffer to make it accessible to the CPU */
|
|
|
|
+ dma_unmap_single(dma_dev, slot->dma_addr,
|
|
|
|
+ BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
|
|
|
|
+ slot->dma_addr = 0;
|
|
|
|
+
|
|
|
|
+ /* Get info from the header */
|
|
|
|
+ len = le16_to_cpu(rx->len);
|
|
|
|
+ flags = le16_to_cpu(rx->flags);
|
2015-04-12 22:10:40 +00:00
|
|
|
|
|
|
|
/* Check for poison and drop or pass the packet */
|
|
|
|
if (len == 0xdead && flags == 0xbeef) {
|
|
|
|
bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n",
|
|
|
|
ring->start);
|
|
|
|
- dma_sync_single_for_device(dma_dev,
|
|
|
|
- slot->dma_addr,
|
|
|
|
- BGMAC_RX_BUF_SIZE,
|
|
|
|
- DMA_FROM_DEVICE);
|
2015-04-13 17:32:33 +00:00
|
|
|
+ kfree(buf);
|
2015-04-12 22:10:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-13 17:32:33 +00:00
|
|
|
/* Omit CRC. */
|
|
|
|
len -= ETH_FCS_LEN;
|
|
|
|
|
|
|
|
- /* Prepare new skb as replacement */
|
|
|
|
- err = bgmac_dma_rx_skb_for_slot(bgmac, slot);
|
|
|
|
- if (err) {
|
|
|
|
- /* Poison the old skb */
|
|
|
|
- rx->len = cpu_to_le16(0xdead);
|
|
|
|
- rx->flags = cpu_to_le16(0xbeef);
|
2015-04-12 22:10:40 +00:00
|
|
|
-
|
|
|
|
- dma_sync_single_for_device(dma_dev,
|
|
|
|
- slot->dma_addr,
|
|
|
|
- BGMAC_RX_BUF_SIZE,
|
|
|
|
- DMA_FROM_DEVICE);
|
2015-04-13 17:32:33 +00:00
|
|
|
- break;
|
|
|
|
- }
|
2015-04-12 22:10:40 +00:00
|
|
|
- bgmac_dma_rx_setup_desc(bgmac, ring, ring->start);
|
|
|
|
-
|
|
|
|
- /* Unmap old skb, we'll pass it to the netfif */
|
|
|
|
- dma_unmap_single(dma_dev, old_dma_addr,
|
|
|
|
- BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
|
2015-04-13 17:32:33 +00:00
|
|
|
-
|
2015-04-12 22:10:40 +00:00
|
|
|
skb = build_skb(buf, BGMAC_RX_ALLOC_SIZE);
|
|
|
|
skb_put(skb, BGMAC_RX_FRAME_OFFSET +
|
2015-04-13 17:32:33 +00:00
|
|
|
BGMAC_RX_BUF_OFFSET + len);
|
|
|
|
@@ -458,14 +440,16 @@ static int bgmac_dma_rx_read(struct bgma
|
|
|
|
skb_checksum_none_assert(skb);
|
|
|
|
skb->protocol = eth_type_trans(skb, bgmac->net_dev);
|
|
|
|
napi_gro_receive(&bgmac->napi, skb);
|
|
|
|
- handled++;
|
2015-04-12 22:10:40 +00:00
|
|
|
} while (0);
|
|
|
|
|
2015-04-13 17:32:33 +00:00
|
|
|
+ /* Prepare new skb as replacement */
|
|
|
|
+ if (bgmac_dma_rx_skb_for_slot(bgmac, slot))
|
|
|
|
+ continue;
|
|
|
|
+
|
2015-04-12 22:10:40 +00:00
|
|
|
+ bgmac_dma_rx_setup_desc(bgmac, ring, ring->start);
|
|
|
|
+
|
|
|
|
if (++ring->start >= BGMAC_RX_RING_SLOTS)
|
|
|
|
ring->start = 0;
|
2015-04-13 17:32:33 +00:00
|
|
|
-
|
|
|
|
- if (handled >= weight) /* Should never be greater */
|
|
|
|
- break;
|
|
|
|
}
|
2015-04-12 22:10:40 +00:00
|
|
|
|
2015-04-13 17:32:33 +00:00
|
|
|
return handled;
|