In upcomming changes for adding vlan support struct net_device will not be available in all cases, therefore use struct device instead. Signed-off-by: Michael Dege --- drivers/net/ethernet/renesas/rswitch_main.c | 56 +++++++++++++++-------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/drivers/net/ethernet/renesas/rswitch_main.c b/drivers/net/ethernet/renesas/rswitch_main.c index 9b739594cc02..74d441ae1976 100644 --- a/drivers/net/ethernet/renesas/rswitch_main.c +++ b/drivers/net/ethernet/renesas/rswitch_main.c @@ -304,26 +304,30 @@ static int rswitch_gwca_queue_alloc_rx_buf(struct rswitch_gwca_queue *gq, return -ENOMEM; } -static void rswitch_gwca_queue_free(struct net_device *ndev, +static void rswitch_gwca_queue_free(struct device *dev, struct rswitch_gwca_queue *gq) { unsigned int i; if (!gq->dir_tx) { - dma_free_coherent(ndev->dev.parent, - sizeof(struct rswitch_ext_ts_desc) * - (gq->ring_size + 1), gq->rx_ring, gq->ring_dma); - gq->rx_ring = NULL; - + if (gq->rx_ring) { + dma_free_coherent(dev, + sizeof(struct rswitch_ext_ts_desc) * + (gq->ring_size + 1), gq->rx_ring, gq->ring_dma); + gq->rx_ring = NULL; + } for (i = 0; i < gq->ring_size; i++) - skb_free_frag(gq->rx_bufs[i]); + if (gq->rx_bufs[i]) + skb_free_frag(gq->rx_bufs[i]); kfree(gq->rx_bufs); gq->rx_bufs = NULL; } else { - dma_free_coherent(ndev->dev.parent, - sizeof(struct rswitch_ext_desc) * - (gq->ring_size + 1), gq->tx_ring, gq->ring_dma); - gq->tx_ring = NULL; + if (gq->tx_ring) { + dma_free_coherent(dev, + sizeof(struct rswitch_ext_desc) * + (gq->ring_size + 1), gq->tx_ring, gq->ring_dma); + gq->tx_ring = NULL; + } kfree(gq->skbs); gq->skbs = NULL; kfree(gq->unmap_addrs); @@ -359,7 +363,7 @@ static int rswitch_gwca_queue_alloc(struct net_device *ndev, if (rswitch_gwca_queue_alloc_rx_buf(gq, 0, gq->ring_size) < 0) goto out; - gq->rx_ring = dma_alloc_coherent(ndev->dev.parent, + gq->rx_ring = dma_alloc_coherent(&priv->pdev->dev, sizeof(struct rswitch_ext_ts_desc) * (gq->ring_size + 1), &gq->ring_dma, GFP_KERNEL); } else { @@ -369,7 +373,7 @@ static int rswitch_gwca_queue_alloc(struct net_device *ndev, gq->unmap_addrs = kzalloc_objs(*gq->unmap_addrs, gq->ring_size); if (!gq->unmap_addrs) goto out; - gq->tx_ring = dma_alloc_coherent(ndev->dev.parent, + gq->tx_ring = dma_alloc_coherent(&priv->pdev->dev, sizeof(struct rswitch_ext_desc) * (gq->ring_size + 1), &gq->ring_dma, GFP_KERNEL); } @@ -387,7 +391,7 @@ static int rswitch_gwca_queue_alloc(struct net_device *ndev, return 0; out: - rswitch_gwca_queue_free(ndev, gq); + rswitch_gwca_queue_free(&priv->pdev->dev, gq); return -ENOMEM; } @@ -469,12 +473,11 @@ static void rswitch_gwca_ts_queue_fill(struct rswitch_private *priv, } } -static int rswitch_gwca_queue_ext_ts_fill(struct net_device *ndev, +static int rswitch_gwca_queue_ext_ts_fill(struct device *dev, struct rswitch_gwca_queue *gq, unsigned int start_index, unsigned int num) { - struct rswitch_device *rdev = netdev_priv(ndev); struct rswitch_ext_ts_desc *desc; unsigned int i, index; dma_addr_t dma_addr; @@ -483,18 +486,17 @@ static int rswitch_gwca_queue_ext_ts_fill(struct net_device *ndev, index = (i + start_index) % gq->ring_size; desc = &gq->rx_ring[index]; if (!gq->dir_tx) { - dma_addr = dma_map_single(ndev->dev.parent, + dma_addr = dma_map_single(dev, gq->rx_bufs[index] + RSWITCH_HEADROOM, RSWITCH_MAP_BUF_SIZE, DMA_FROM_DEVICE); - if (dma_mapping_error(ndev->dev.parent, dma_addr)) + if (dma_mapping_error(dev, dma_addr)) goto err; desc->desc.info_ds = cpu_to_le16(RSWITCH_DESC_BUF_SIZE); rswitch_desc_set_dptr(&desc->desc, dma_addr); dma_wmb(); desc->desc.die_dt = DT_FEMPTY | DIE; - desc->info1 = cpu_to_le64(INFO1_SPN(rdev->etha->index)); } else { desc->desc.die_dt = DT_EEMPTY | DIE; } @@ -507,8 +509,10 @@ static int rswitch_gwca_queue_ext_ts_fill(struct net_device *ndev, for (; i-- > 0; ) { index = (i + start_index) % gq->ring_size; desc = &gq->rx_ring[index]; + desc->desc.die_dt = 0x00; + dma_wmb(); dma_addr = rswitch_desc_get_dptr(&desc->desc); - dma_unmap_single(ndev->dev.parent, dma_addr, + dma_unmap_single(dev, dma_addr, RSWITCH_MAP_BUF_SIZE, DMA_FROM_DEVICE); } } @@ -516,7 +520,7 @@ static int rswitch_gwca_queue_ext_ts_fill(struct net_device *ndev, return -ENOMEM; } -static int rswitch_gwca_queue_ext_ts_format(struct net_device *ndev, +static int rswitch_gwca_queue_ext_ts_format(struct device *dev, struct rswitch_private *priv, struct rswitch_gwca_queue *gq) { @@ -526,7 +530,7 @@ static int rswitch_gwca_queue_ext_ts_format(struct net_device *ndev, int err; memset(gq->rx_ring, 0, ring_size); - err = rswitch_gwca_queue_ext_ts_fill(ndev, gq, 0, gq->ring_size); + err = rswitch_gwca_queue_ext_ts_fill(dev, gq, 0, gq->ring_size); if (err < 0) return err; @@ -638,7 +642,7 @@ static void rswitch_txdmac_free(struct net_device *ndev) { struct rswitch_device *rdev = netdev_priv(ndev); - rswitch_gwca_queue_free(ndev, rdev->tx_queue); + rswitch_gwca_queue_free(ndev->dev.parent, rdev->tx_queue); rswitch_gwca_put(rdev->priv, rdev->tx_queue); } @@ -672,7 +676,7 @@ static void rswitch_rxdmac_free(struct net_device *ndev) { struct rswitch_device *rdev = netdev_priv(ndev); - rswitch_gwca_queue_free(ndev, rdev->rx_queue); + rswitch_gwca_queue_free(ndev->dev.parent, rdev->rx_queue); rswitch_gwca_put(rdev->priv, rdev->rx_queue); } @@ -681,7 +685,7 @@ static int rswitch_rxdmac_init(struct rswitch_private *priv, unsigned int index) struct rswitch_device *rdev = priv->rdev[index]; struct net_device *ndev = rdev->ndev; - return rswitch_gwca_queue_ext_ts_format(ndev, priv, rdev->rx_queue); + return rswitch_gwca_queue_ext_ts_format(ndev->dev.parent, priv, rdev->rx_queue); } static int rswitch_gwca_hw_init(struct rswitch_private *priv) @@ -872,7 +876,7 @@ static bool rswitch_rx(struct net_device *ndev, int *quota) ret = rswitch_gwca_queue_alloc_rx_buf(gq, gq->dirty, num); if (ret < 0) goto err; - ret = rswitch_gwca_queue_ext_ts_fill(ndev, gq, gq->dirty, num); + ret = rswitch_gwca_queue_ext_ts_fill(ndev->dev.parent, gq, gq->dirty, num); if (ret < 0) goto err; gq->dirty = rswitch_next_queue_index(gq, false, num); -- 2.43.0