Skip to content

Commit b501585

Browse files
wojtas-marcindavem330
authored andcommitted
net: mvpp2: fix refilling BM pools in RX path
In hitherto code in case of RX buffer allocation error during refill, original buffer is pushed to the network stack, but the amount of available buffer pointers in BM pool is decreased. This commit fixes the situation by moving refill call before skb_put(), and returning original buffer pointer to the pool in case of an error. Signed-off-by: Marcin Wojtas <[email protected]> Fixes: 3f51850 ("ethernet: Add new driver for Marvell Armada 375 network unit") Cc: <[email protected]> # v3.18+ Signed-off-by: David S. Miller <[email protected]>
1 parent 4229d50 commit b501585

File tree

1 file changed

+16
-12
lines changed
  • drivers/net/ethernet/marvell

1 file changed

+16
-12
lines changed

drivers/net/ethernet/marvell/mvpp2.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5099,7 +5099,8 @@ static int mvpp2_rx(struct mvpp2_port *port, int rx_todo,
50995099
struct mvpp2_rx_queue *rxq)
51005100
{
51015101
struct net_device *dev = port->dev;
5102-
int rx_received, rx_filled, i;
5102+
int rx_received;
5103+
int rx_done = 0;
51035104
u32 rcvd_pkts = 0;
51045105
u32 rcvd_bytes = 0;
51055106

@@ -5108,17 +5109,18 @@ static int mvpp2_rx(struct mvpp2_port *port, int rx_todo,
51085109
if (rx_todo > rx_received)
51095110
rx_todo = rx_received;
51105111

5111-
rx_filled = 0;
5112-
for (i = 0; i < rx_todo; i++) {
5112+
while (rx_done < rx_todo) {
51135113
struct mvpp2_rx_desc *rx_desc = mvpp2_rxq_next_desc_get(rxq);
51145114
struct mvpp2_bm_pool *bm_pool;
51155115
struct sk_buff *skb;
5116+
dma_addr_t phys_addr;
51165117
u32 bm, rx_status;
51175118
int pool, rx_bytes, err;
51185119

5119-
rx_filled++;
5120+
rx_done++;
51205121
rx_status = rx_desc->status;
51215122
rx_bytes = rx_desc->data_size - MVPP2_MH_SIZE;
5123+
phys_addr = rx_desc->buf_phys_addr;
51225124

51235125
bm = mvpp2_bm_cookie_build(rx_desc);
51245126
pool = mvpp2_bm_cookie_pool_get(bm);
@@ -5135,16 +5137,24 @@ static int mvpp2_rx(struct mvpp2_port *port, int rx_todo,
51355137
* comprised by the RX descriptor.
51365138
*/
51375139
if (rx_status & MVPP2_RXD_ERR_SUMMARY) {
5140+
err_drop_frame:
51385141
dev->stats.rx_errors++;
51395142
mvpp2_rx_error(port, rx_desc);
5143+
/* Return the buffer to the pool */
51405144
mvpp2_pool_refill(port, bm, rx_desc->buf_phys_addr,
51415145
rx_desc->buf_cookie);
51425146
continue;
51435147
}
51445148

51455149
skb = (struct sk_buff *)rx_desc->buf_cookie;
51465150

5147-
dma_unmap_single(dev->dev.parent, rx_desc->buf_phys_addr,
5151+
err = mvpp2_rx_refill(port, bm_pool, bm, 0);
5152+
if (err) {
5153+
netdev_err(port->dev, "failed to refill BM pools\n");
5154+
goto err_drop_frame;
5155+
}
5156+
5157+
dma_unmap_single(dev->dev.parent, phys_addr,
51485158
bm_pool->buf_size, DMA_FROM_DEVICE);
51495159

51505160
rcvd_pkts++;
@@ -5157,12 +5167,6 @@ static int mvpp2_rx(struct mvpp2_port *port, int rx_todo,
51575167
mvpp2_rx_csum(port, rx_status, skb);
51585168

51595169
napi_gro_receive(&port->napi, skb);
5160-
5161-
err = mvpp2_rx_refill(port, bm_pool, bm, 0);
5162-
if (err) {
5163-
netdev_err(port->dev, "failed to refill BM pools\n");
5164-
rx_filled--;
5165-
}
51665170
}
51675171

51685172
if (rcvd_pkts) {
@@ -5176,7 +5180,7 @@ static int mvpp2_rx(struct mvpp2_port *port, int rx_todo,
51765180

51775181
/* Update Rx queue management counters */
51785182
wmb();
5179-
mvpp2_rxq_status_update(port, rxq->id, rx_todo, rx_filled);
5183+
mvpp2_rxq_status_update(port, rxq->id, rx_done, rx_done);
51805184

51815185
return rx_todo;
51825186
}

0 commit comments

Comments
 (0)