Skip to content

Commit 714239a

Browse files
claudiu-mdavem330
authored andcommitted
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: Claudiu Manoil <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a784c92 commit 714239a

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

drivers/net/ethernet/freescale/enetc/enetc.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
451451

452452
i = rx_ring->next_to_use;
453453
rx_swbd = &rx_ring->rx_swbd[i];
454-
rxbd = ENETC_RXBD(*rx_ring, i);
454+
rxbd = enetc_rxbd(rx_ring, i);
455455

456456
for (j = 0; j < buff_cnt; j++) {
457457
/* try reuse page */
@@ -468,13 +468,12 @@ static int enetc_refill_rx_ring(struct enetc_bdr *rx_ring, const int buff_cnt)
468468
/* clear 'R" as well */
469469
rxbd->r.lstatus = 0;
470470

471+
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
471472
rx_swbd++;
472-
rxbd++;
473473
i++;
474474
if (unlikely(i == rx_ring->bd_count)) {
475475
i = 0;
476476
rx_swbd = rx_ring->rx_swbd;
477-
rxbd = ENETC_RXBD(*rx_ring, 0);
478477
}
479478
}
480479

@@ -655,7 +654,7 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
655654
cleaned_cnt -= count;
656655
}
657656

658-
rxbd = ENETC_RXBD(*rx_ring, i);
657+
rxbd = enetc_rxbd(rx_ring, i);
659658
bd_status = le32_to_cpu(rxbd->r.lstatus);
660659
if (!bd_status)
661660
break;
@@ -670,25 +669,21 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
670669
enetc_get_offloads(rx_ring, rxbd, skb);
671670

672671
cleaned_cnt++;
673-
rxbd++;
674-
i++;
675-
if (unlikely(i == rx_ring->bd_count)) {
672+
673+
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
674+
if (unlikely(++i == rx_ring->bd_count))
676675
i = 0;
677-
rxbd = ENETC_RXBD(*rx_ring, 0);
678-
}
679676

680677
if (unlikely(bd_status &
681678
ENETC_RXBD_LSTATUS(ENETC_RXBD_ERR_MASK))) {
682679
dev_kfree_skb(skb);
683680
while (!(bd_status & ENETC_RXBD_LSTATUS_F)) {
684681
dma_rmb();
685682
bd_status = le32_to_cpu(rxbd->r.lstatus);
686-
rxbd++;
687-
i++;
688-
if (unlikely(i == rx_ring->bd_count)) {
683+
684+
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
685+
if (unlikely(++i == rx_ring->bd_count))
689686
i = 0;
690-
rxbd = ENETC_RXBD(*rx_ring, 0);
691-
}
692687
}
693688

694689
rx_ring->ndev->stats.rx_dropped++;
@@ -710,12 +705,10 @@ static int enetc_clean_rx_ring(struct enetc_bdr *rx_ring,
710705
enetc_add_rx_buff_to_skb(rx_ring, i, size, skb);
711706

712707
cleaned_cnt++;
713-
rxbd++;
714-
i++;
715-
if (unlikely(i == rx_ring->bd_count)) {
708+
709+
rxbd = enetc_rxbd_next(rx_ring, rxbd, i);
710+
if (unlikely(++i == rx_ring->bd_count))
716711
i = 0;
717-
rxbd = ENETC_RXBD(*rx_ring, 0);
718-
}
719712
}
720713

721714
rx_byte_cnt += skb->len;

drivers/net/ethernet/freescale/enetc/enetc.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,22 @@ struct enetc_cbdr {
104104
};
105105

106106
#define ENETC_TXBD(BDR, i) (&(((union enetc_tx_bd *)((BDR).bd_base))[i]))
107-
#define ENETC_RXBD(BDR, i) (&(((union enetc_rx_bd *)((BDR).bd_base))[i]))
107+
108+
static inline union enetc_rx_bd *enetc_rxbd(struct enetc_bdr *rx_ring, int i)
109+
{
110+
return &(((union enetc_rx_bd *)rx_ring->bd_base)[i]);
111+
}
112+
113+
static inline union enetc_rx_bd *enetc_rxbd_next(struct enetc_bdr *rx_ring,
114+
union enetc_rx_bd *rxbd,
115+
int i)
116+
{
117+
rxbd++;
118+
if (unlikely(++i == rx_ring->bd_count))
119+
rxbd = rx_ring->bd_base;
120+
121+
return rxbd;
122+
}
108123

109124
struct enetc_msg_swbd {
110125
void *vaddr;

0 commit comments

Comments
 (0)