Skip to content

Commit 4229d50

Browse files
wojtas-marcindavem330
authored andcommitted
net: mvpp2: fix buffers' DMA handling on RX path
Each allocated buffer, whose pointer is put into BM pool is DMA-mapped. Hence it should be properly unmapped after usage or when removing buffers from pool. This commit fixes DMA handling on RX path by adding dma_unmap_single() in mvpp2_rx() and in mvpp2_bufs_free(). The latter function's argument number had to be increased for this purpose. 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 e864b4c commit 4229d50

File tree

1 file changed

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

1 file changed

+16
-5
lines changed

drivers/net/ethernet/marvell/mvpp2.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3413,16 +3413,23 @@ static void mvpp2_bm_pool_bufsize_set(struct mvpp2 *priv,
34133413
}
34143414

34153415
/* Free all buffers from the pool */
3416-
static void mvpp2_bm_bufs_free(struct mvpp2 *priv, struct mvpp2_bm_pool *bm_pool)
3416+
static void mvpp2_bm_bufs_free(struct device *dev, struct mvpp2 *priv,
3417+
struct mvpp2_bm_pool *bm_pool)
34173418
{
34183419
int i;
34193420

34203421
for (i = 0; i < bm_pool->buf_num; i++) {
3422+
dma_addr_t buf_phys_addr;
34213423
u32 vaddr;
34223424

34233425
/* Get buffer virtual address (indirect access) */
3424-
mvpp2_read(priv, MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
3426+
buf_phys_addr = mvpp2_read(priv,
3427+
MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
34253428
vaddr = mvpp2_read(priv, MVPP2_BM_VIRT_ALLOC_REG);
3429+
3430+
dma_unmap_single(dev, buf_phys_addr,
3431+
bm_pool->buf_size, DMA_FROM_DEVICE);
3432+
34263433
if (!vaddr)
34273434
break;
34283435
dev_kfree_skb_any((struct sk_buff *)vaddr);
@@ -3439,7 +3446,7 @@ static int mvpp2_bm_pool_destroy(struct platform_device *pdev,
34393446
{
34403447
u32 val;
34413448

3442-
mvpp2_bm_bufs_free(priv, bm_pool);
3449+
mvpp2_bm_bufs_free(&pdev->dev, priv, bm_pool);
34433450
if (bm_pool->buf_num) {
34443451
WARN(1, "cannot free all buffers in pool %d\n", bm_pool->id);
34453452
return 0;
@@ -3692,7 +3699,8 @@ mvpp2_bm_pool_use(struct mvpp2_port *port, int pool, enum mvpp2_bm_type type,
36923699
MVPP2_BM_LONG_BUF_NUM :
36933700
MVPP2_BM_SHORT_BUF_NUM;
36943701
else
3695-
mvpp2_bm_bufs_free(port->priv, new_pool);
3702+
mvpp2_bm_bufs_free(port->dev->dev.parent,
3703+
port->priv, new_pool);
36963704

36973705
new_pool->pkt_size = pkt_size;
36983706

@@ -3756,7 +3764,7 @@ static int mvpp2_bm_update_mtu(struct net_device *dev, int mtu)
37563764
int pkt_size = MVPP2_RX_PKT_SIZE(mtu);
37573765

37583766
/* Update BM pool with new buffer size */
3759-
mvpp2_bm_bufs_free(port->priv, port_pool);
3767+
mvpp2_bm_bufs_free(dev->dev.parent, port->priv, port_pool);
37603768
if (port_pool->buf_num) {
37613769
WARN(1, "cannot free all buffers in pool %d\n", port_pool->id);
37623770
return -EIO;
@@ -5136,6 +5144,9 @@ static int mvpp2_rx(struct mvpp2_port *port, int rx_todo,
51365144

51375145
skb = (struct sk_buff *)rx_desc->buf_cookie;
51385146

5147+
dma_unmap_single(dev->dev.parent, rx_desc->buf_phys_addr,
5148+
bm_pool->buf_size, DMA_FROM_DEVICE);
5149+
51395150
rcvd_pkts++;
51405151
rcvd_bytes += rx_bytes;
51415152
atomic_inc(&bm_pool->in_use);

0 commit comments

Comments
 (0)