Commit 3d0b7265 authored by Sieng Piaw Liew's avatar Sieng Piaw Liew Committed by Jakub Kicinski

bcm63xx_enet: consolidate rx SKB ring cleanup code

The rx SKB ring use the same code for cleanup at various points.
Combine them into a function to reduce lines of code.
Signed-off-by: default avatarSieng Piaw Liew <liew.s.piaw@gmail.com>
Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c4a20786
...@@ -860,6 +860,24 @@ static void bcm_enet_adjust_link(struct net_device *dev) ...@@ -860,6 +860,24 @@ static void bcm_enet_adjust_link(struct net_device *dev)
priv->pause_tx ? "tx" : "off"); priv->pause_tx ? "tx" : "off");
} }
static void bcm_enet_free_rx_skb_ring(struct device *kdev, struct bcm_enet_priv *priv)
{
int i;
for (i = 0; i < priv->rx_ring_size; i++) {
struct bcm_enet_desc *desc;
if (!priv->rx_skb[i])
continue;
desc = &priv->rx_desc_cpu[i];
dma_unmap_single(kdev, desc->address, priv->rx_skb_size,
DMA_FROM_DEVICE);
kfree_skb(priv->rx_skb[i]);
}
kfree(priv->rx_skb);
}
/* /*
* open callback, allocate dma rings & buffers and start rx operation * open callback, allocate dma rings & buffers and start rx operation
*/ */
...@@ -1084,18 +1102,7 @@ static int bcm_enet_open(struct net_device *dev) ...@@ -1084,18 +1102,7 @@ static int bcm_enet_open(struct net_device *dev)
return 0; return 0;
out: out:
for (i = 0; i < priv->rx_ring_size; i++) { bcm_enet_free_rx_skb_ring(kdev, priv);
struct bcm_enet_desc *desc;
if (!priv->rx_skb[i])
continue;
desc = &priv->rx_desc_cpu[i];
dma_unmap_single(kdev, desc->address, priv->rx_skb_size,
DMA_FROM_DEVICE);
kfree_skb(priv->rx_skb[i]);
}
kfree(priv->rx_skb);
out_free_tx_skb: out_free_tx_skb:
kfree(priv->tx_skb); kfree(priv->tx_skb);
...@@ -1174,7 +1181,6 @@ static int bcm_enet_stop(struct net_device *dev) ...@@ -1174,7 +1181,6 @@ static int bcm_enet_stop(struct net_device *dev)
{ {
struct bcm_enet_priv *priv; struct bcm_enet_priv *priv;
struct device *kdev; struct device *kdev;
int i;
priv = netdev_priv(dev); priv = netdev_priv(dev);
kdev = &priv->pdev->dev; kdev = &priv->pdev->dev;
...@@ -1203,20 +1209,9 @@ static int bcm_enet_stop(struct net_device *dev) ...@@ -1203,20 +1209,9 @@ static int bcm_enet_stop(struct net_device *dev)
bcm_enet_tx_reclaim(dev, 1); bcm_enet_tx_reclaim(dev, 1);
/* free the rx skb ring */ /* free the rx skb ring */
for (i = 0; i < priv->rx_ring_size; i++) { bcm_enet_free_rx_skb_ring(kdev, priv);
struct bcm_enet_desc *desc;
if (!priv->rx_skb[i])
continue;
desc = &priv->rx_desc_cpu[i];
dma_unmap_single(kdev, desc->address, priv->rx_skb_size,
DMA_FROM_DEVICE);
kfree_skb(priv->rx_skb[i]);
}
/* free remaining allocated memory */ /* free remaining allocated memory */
kfree(priv->rx_skb);
kfree(priv->tx_skb); kfree(priv->tx_skb);
dma_free_coherent(kdev, priv->rx_desc_alloc_size, dma_free_coherent(kdev, priv->rx_desc_alloc_size,
priv->rx_desc_cpu, priv->rx_desc_dma); priv->rx_desc_cpu, priv->rx_desc_dma);
...@@ -2303,18 +2298,7 @@ static int bcm_enetsw_open(struct net_device *dev) ...@@ -2303,18 +2298,7 @@ static int bcm_enetsw_open(struct net_device *dev)
return 0; return 0;
out: out:
for (i = 0; i < priv->rx_ring_size; i++) { bcm_enet_free_rx_skb_ring(kdev, priv);
struct bcm_enet_desc *desc;
if (!priv->rx_skb[i])
continue;
desc = &priv->rx_desc_cpu[i];
dma_unmap_single(kdev, desc->address, priv->rx_skb_size,
DMA_FROM_DEVICE);
kfree_skb(priv->rx_skb[i]);
}
kfree(priv->rx_skb);
out_free_tx_skb: out_free_tx_skb:
kfree(priv->tx_skb); kfree(priv->tx_skb);
...@@ -2343,7 +2327,6 @@ static int bcm_enetsw_stop(struct net_device *dev) ...@@ -2343,7 +2327,6 @@ static int bcm_enetsw_stop(struct net_device *dev)
{ {
struct bcm_enet_priv *priv; struct bcm_enet_priv *priv;
struct device *kdev; struct device *kdev;
int i;
priv = netdev_priv(dev); priv = netdev_priv(dev);
kdev = &priv->pdev->dev; kdev = &priv->pdev->dev;
...@@ -2366,20 +2349,9 @@ static int bcm_enetsw_stop(struct net_device *dev) ...@@ -2366,20 +2349,9 @@ static int bcm_enetsw_stop(struct net_device *dev)
bcm_enet_tx_reclaim(dev, 1); bcm_enet_tx_reclaim(dev, 1);
/* free the rx skb ring */ /* free the rx skb ring */
for (i = 0; i < priv->rx_ring_size; i++) { bcm_enet_free_rx_skb_ring(kdev, priv);
struct bcm_enet_desc *desc;
if (!priv->rx_skb[i])
continue;
desc = &priv->rx_desc_cpu[i];
dma_unmap_single(kdev, desc->address, priv->rx_skb_size,
DMA_FROM_DEVICE);
kfree_skb(priv->rx_skb[i]);
}
/* free remaining allocated memory */ /* free remaining allocated memory */
kfree(priv->rx_skb);
kfree(priv->tx_skb); kfree(priv->tx_skb);
dma_free_coherent(kdev, priv->rx_desc_alloc_size, dma_free_coherent(kdev, priv->rx_desc_alloc_size,
priv->rx_desc_cpu, priv->rx_desc_dma); priv->rx_desc_cpu, priv->rx_desc_dma);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment