Commit 714239ac authored by Claudiu Manoil's avatar Claudiu Manoil Committed by David S. Miller

enetc: Clean up Rx BD iteration

Improve maintainability of the code iterating the Rx buffer
descriptors to prepare it to support iterating extended Rx BD
descriptors as well.
Don't increment by one the h/w descriptor pointers explicitly,
provide an iterator that takes care of the h/w details.
Signed-off-by: default avatarClaudiu Manoil <claudiu.manoil@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a784c92e
......@@ -451,7 +451,7 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
i = rx_ring->next_to_use;
rx_swbd = &rx_ring->rx_swbd[i];
rxbd = ENETC_RXBD(*rx_ring, i);
rxbd = enetc_rxbd(rx_ring, i);
for (j = 0; j < buff_cnt; j++) {
/* try reuse page */
......@@ -468,13 +468,12 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
/* clear 'R" as well */
rxbd->r.lstatus = 0;
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
rx_swbd++;
rxbd++;
i++;
if (unlikely(i == rx_ring->bd_count)) {
i = 0;
rx_swbd = rx_ring->rx_swbd;
rxbd = ENETC_RXBD(*rx_ring, 0);
}
}
......@@ -655,7 +654,7 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
cleaned_cnt -= count;
}
rxbd = ENETC_RXBD(*rx_ring, i);
rxbd = enetc_rxbd(rx_ring, i);
bd_status = le32_to_cpu(rxbd->r.lstatus);
if (!bd_status)
break;
......@@ -670,12 +669,10 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
enetc_get_offloads(rx_ring, rxbd, skb);
cleaned_cnt++;
rxbd++;
i++;
if (unlikely(i == rx_ring->bd_count)) {
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
if (unlikely(++i == rx_ring->bd_count))
i = 0;
rxbd = ENETC_RXBD(*rx_ring, 0);
}
if (unlikely(bd_status &
ENETC_RXBD_LSTATUS(ENETC_RXBD_ERR_MASK))) {
......@@ -683,12 +680,10 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
while (!(bd_status & ENETC_RXBD_LSTATUS_F)) {
dma_rmb();
bd_status = le32_to_cpu(rxbd->r.lstatus);
rxbd++;
i++;
if (unlikely(i == rx_ring->bd_count)) {
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
if (unlikely(++i == rx_ring->bd_count))
i = 0;
rxbd = ENETC_RXBD(*rx_ring, 0);
}
}
rx_ring->ndev->stats.rx_dropped++;
......@@ -710,12 +705,10 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
enetc_add_rx_buff_to_skb(rx_ring, i, size, skb);
cleaned_cnt++;
rxbd++;
i++;
if (unlikely(i == rx_ring->bd_count)) {
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
if (unlikely(++i == rx_ring->bd_count))
i = 0;
rxbd = ENETC_RXBD(*rx_ring, 0);
}
}
rx_byte_cnt += skb->len;
......
......@@ -104,7 +104,22 @@ struct enetc_cbdr {
};
#define ENETC_TXBD(BDR, i) (&(((union enetc_tx_bd *)((BDR).bd_base))[i]))
#define ENETC_RXBD(BDR, i) (&(((union enetc_rx_bd *)((BDR).bd_base))[i]))
static inline union enetc_rx_bd *enetc_rxbd(struct enetc_bdr *rx_ring, int i)
{
return &(((union enetc_rx_bd *)rx_ring->bd_base)[i]);
}
static inline union enetc_rx_bd *enetc_rxbd_next(struct enetc_bdr *rx_ring,
union enetc_rx_bd *rxbd,
int i)
{
rxbd++;
if (unlikely(++i == rx_ring->bd_count))
rxbd = rx_ring->bd_base;
return rxbd;
}
struct enetc_msg_swbd {
void *vaddr;
......
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