Commit 56faacd0 authored by Felix Fietkau's avatar Felix Fietkau Committed by David S. Miller

bgmac: simplify/optimize rx DMA error handling

Allocate a new buffer before processing the completed one. If allocation
fails, reuse the old buffer.
Signed-off-by: default avatarFelix Fietkau <nbd@openwrt.org>
Acked-by: default avatarRafał Miłecki <zajec5@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4b62dce4
...@@ -386,6 +386,19 @@ static void bgmac_dma_rx_setup_desc(struct bgmac *bgmac, ...@@ -386,6 +386,19 @@ static void bgmac_dma_rx_setup_desc(struct bgmac *bgmac,
dma_desc->ctl1 = cpu_to_le32(ctl1); dma_desc->ctl1 = cpu_to_le32(ctl1);
} }
static void bgmac_dma_rx_poison_buf(struct device *dma_dev,
struct bgmac_slot_info *slot)
{
struct bgmac_rx_header *rx = slot->buf + BGMAC_RX_BUF_OFFSET;
dma_sync_single_for_cpu(dma_dev, slot->dma_addr, BGMAC_RX_BUF_SIZE,
DMA_FROM_DEVICE);
rx->len = cpu_to_le16(0xdead);
rx->flags = cpu_to_le16(0xbeef);
dma_sync_single_for_device(dma_dev, slot->dma_addr, BGMAC_RX_BUF_SIZE,
DMA_FROM_DEVICE);
}
static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring, static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
int weight) int weight)
{ {
...@@ -406,53 +419,35 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring, ...@@ -406,53 +419,35 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
struct bgmac_rx_header *rx = slot->buf + BGMAC_RX_BUF_OFFSET; struct bgmac_rx_header *rx = slot->buf + BGMAC_RX_BUF_OFFSET;
struct sk_buff *skb; struct sk_buff *skb;
void *buf = slot->buf; void *buf = slot->buf;
dma_addr_t dma_addr = slot->dma_addr;
u16 len, flags; u16 len, flags;
/* Unmap buffer to make it accessible to the CPU */ do {
dma_sync_single_for_cpu(dma_dev, slot->dma_addr, /* Prepare new skb as replacement */
BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE); if (bgmac_dma_rx_skb_for_slot(bgmac, slot)) {
bgmac_dma_rx_poison_buf(dma_dev, slot);
break;
}
/* Get info from the header */ /* Unmap buffer to make it accessible to the CPU */
len = le16_to_cpu(rx->len); dma_unmap_single(dma_dev, dma_addr,
flags = le16_to_cpu(rx->flags); BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
do { /* Get info from the header */
dma_addr_t old_dma_addr = slot->dma_addr; len = le16_to_cpu(rx->len);
int err; flags = le16_to_cpu(rx->flags);
/* Check for poison and drop or pass the packet */ /* Check for poison and drop or pass the packet */
if (len == 0xdead && flags == 0xbeef) { if (len == 0xdead && flags == 0xbeef) {
bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n", bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n",
ring->start); ring->start);
dma_sync_single_for_device(dma_dev, put_page(virt_to_head_page(buf));
slot->dma_addr,
BGMAC_RX_BUF_SIZE,
DMA_FROM_DEVICE);
break; break;
} }
/* Omit CRC. */ /* Omit CRC. */
len -= ETH_FCS_LEN; 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);
dma_sync_single_for_device(dma_dev,
slot->dma_addr,
BGMAC_RX_BUF_SIZE,
DMA_FROM_DEVICE);
break;
}
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);
skb = build_skb(buf, BGMAC_RX_ALLOC_SIZE); skb = build_skb(buf, BGMAC_RX_ALLOC_SIZE);
skb_put(skb, BGMAC_RX_FRAME_OFFSET + skb_put(skb, BGMAC_RX_FRAME_OFFSET +
BGMAC_RX_BUF_OFFSET + len); BGMAC_RX_BUF_OFFSET + len);
...@@ -465,6 +460,8 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring, ...@@ -465,6 +460,8 @@ static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
handled++; handled++;
} while (0); } while (0);
bgmac_dma_rx_setup_desc(bgmac, ring, ring->start);
if (++ring->start >= BGMAC_RX_RING_SLOTS) if (++ring->start >= BGMAC_RX_RING_SLOTS)
ring->start = 0; ring->start = 0;
...@@ -532,14 +529,14 @@ static void bgmac_dma_rx_ring_free(struct bgmac *bgmac, ...@@ -532,14 +529,14 @@ static void bgmac_dma_rx_ring_free(struct bgmac *bgmac,
for (i = 0; i < ring->num_slots; i++) { for (i = 0; i < ring->num_slots; i++) {
slot = &ring->slots[i]; slot = &ring->slots[i];
if (!slot->buf) if (!slot->dma_addr)
continue; continue;
if (slot->dma_addr) dma_unmap_single(dma_dev, slot->dma_addr,
dma_unmap_single(dma_dev, slot->dma_addr, BGMAC_RX_BUF_SIZE,
BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
DMA_FROM_DEVICE);
put_page(virt_to_head_page(slot->buf)); put_page(virt_to_head_page(slot->buf));
slot->dma_addr = 0;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment