Skip to content

Commit 1a1d74d

Browse files
Jakub Kicinskidavem330
authored andcommitted
nfp: use AND instead of modulo to get ring indexes
We already force ring sizes to be power of 2 so replace modulo operations with AND (size - 1) in index calculations. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b64b7bb commit 1a1d74d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/net/ethernet/netronome/nfp/nfp_net_common.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ static int nfp_net_tx(struct sk_buff *skb, struct net_device *netdev)
778778
if (dma_mapping_error(&nn->pdev->dev, dma_addr))
779779
goto err_free;
780780

781-
wr_idx = tx_ring->wr_p % tx_ring->cnt;
781+
wr_idx = tx_ring->wr_p & (tx_ring->cnt - 1);
782782

783783
/* Stash the soft descriptor of the head then initialize it */
784784
txbuf = &tx_ring->txbufs[wr_idx];
@@ -822,7 +822,7 @@ static int nfp_net_tx(struct sk_buff *skb, struct net_device *netdev)
822822
if (dma_mapping_error(&nn->pdev->dev, dma_addr))
823823
goto err_unmap;
824824

825-
wr_idx = (wr_idx + 1) % tx_ring->cnt;
825+
wr_idx = (wr_idx + 1) & (tx_ring->cnt - 1);
826826
tx_ring->txbufs[wr_idx].skb = skb;
827827
tx_ring->txbufs[wr_idx].dma_addr = dma_addr;
828828
tx_ring->txbufs[wr_idx].fidx = f;
@@ -917,7 +917,7 @@ static void nfp_net_tx_complete(struct nfp_net_tx_ring *tx_ring)
917917
todo = qcp_rd_p + tx_ring->cnt - tx_ring->qcp_rd_p;
918918

919919
while (todo--) {
920-
idx = tx_ring->rd_p % tx_ring->cnt;
920+
idx = tx_ring->rd_p & (tx_ring->cnt - 1);
921921
tx_ring->rd_p++;
922922

923923
skb = tx_ring->txbufs[idx].skb;
@@ -992,7 +992,7 @@ nfp_net_tx_ring_reset(struct nfp_net *nn, struct nfp_net_tx_ring *tx_ring)
992992
int nr_frags, fidx, idx;
993993
struct sk_buff *skb;
994994

995-
idx = tx_ring->rd_p % tx_ring->cnt;
995+
idx = tx_ring->rd_p & (tx_ring->cnt - 1);
996996
skb = tx_ring->txbufs[idx].skb;
997997
nr_frags = skb_shinfo(skb)->nr_frags;
998998
fidx = tx_ring->txbufs[idx].fidx;
@@ -1129,7 +1129,7 @@ static void nfp_net_rx_give_one(struct nfp_net_rx_ring *rx_ring,
11291129
{
11301130
unsigned int wr_idx;
11311131

1132-
wr_idx = rx_ring->wr_p % rx_ring->cnt;
1132+
wr_idx = rx_ring->wr_p & (rx_ring->cnt - 1);
11331133

11341134
/* Stash SKB and DMA address away */
11351135
rx_ring->rxbufs[wr_idx].frag = frag;
@@ -1164,7 +1164,7 @@ static void nfp_net_rx_ring_reset(struct nfp_net_rx_ring *rx_ring)
11641164
unsigned int wr_idx, last_idx;
11651165

11661166
/* Move the empty entry to the end of the list */
1167-
wr_idx = rx_ring->wr_p % rx_ring->cnt;
1167+
wr_idx = rx_ring->wr_p & (rx_ring->cnt - 1);
11681168
last_idx = rx_ring->cnt - 1;
11691169
rx_ring->rxbufs[wr_idx].dma_addr = rx_ring->rxbufs[last_idx].dma_addr;
11701170
rx_ring->rxbufs[wr_idx].frag = rx_ring->rxbufs[last_idx].frag;
@@ -1413,7 +1413,7 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget)
14131413
int idx;
14141414

14151415
while (pkts_polled < budget) {
1416-
idx = rx_ring->rd_p % rx_ring->cnt;
1416+
idx = rx_ring->rd_p & (rx_ring->cnt - 1);
14171417

14181418
rxd = &rx_ring->rxds[idx];
14191419
if (!(rxd->rxd.meta_len_dd & PCIE_DESC_RX_DD))

0 commit comments

Comments
 (0)