diff options
author | Anton Vorontsov <avorontsov@ru.mvista.com> | 2009-10-12 02:00:30 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2009-10-13 02:54:02 -0400 |
commit | e69edd21819823bbad06d1d02f9fa21713fad173 (patch) | |
tree | 28069eedd9e8c972282b10de844f7a14737ad288 /drivers/net/gianfar.c | |
parent | ccc05c6e1e4fb672c93c98d92079c89a976e80ba (diff) |
gianfar: Simplify skb resources freeing code
Remove dma_free_coherent() from stop_gfar() and gfar_start() calls,
place it into free_skb_resources(). That makes SKB resources management
more understandable, plus free_skb_resources() will be used as a cleanup
routine for gfar_alloc_skb_resources() that will be implemented soon.
Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/gianfar.c')
-rw-r--r-- | drivers/net/gianfar.c | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c index 5d6480c7cc95..a8b50c9b2d94 100644 --- a/drivers/net/gianfar.c +++ b/drivers/net/gianfar.c | |||
@@ -806,7 +806,6 @@ void gfar_halt(struct net_device *dev) | |||
806 | void stop_gfar(struct net_device *dev) | 806 | void stop_gfar(struct net_device *dev) |
807 | { | 807 | { |
808 | struct gfar_private *priv = netdev_priv(dev); | 808 | struct gfar_private *priv = netdev_priv(dev); |
809 | struct gfar __iomem *regs = priv->regs; | ||
810 | unsigned long flags; | 809 | unsigned long flags; |
811 | 810 | ||
812 | phy_stop(priv->phydev); | 811 | phy_stop(priv->phydev); |
@@ -830,18 +829,13 @@ void stop_gfar(struct net_device *dev) | |||
830 | } | 829 | } |
831 | 830 | ||
832 | free_skb_resources(priv); | 831 | free_skb_resources(priv); |
833 | |||
834 | dma_free_coherent(&priv->ofdev->dev, | ||
835 | sizeof(struct txbd8)*priv->tx_ring_size | ||
836 | + sizeof(struct rxbd8)*priv->rx_ring_size, | ||
837 | priv->tx_bd_base, | ||
838 | gfar_read(®s->tbase0)); | ||
839 | } | 832 | } |
840 | 833 | ||
841 | /* If there are any tx skbs or rx skbs still around, free them. | 834 | /* If there are any tx skbs or rx skbs still around, free them. |
842 | * Then free tx_skbuff and rx_skbuff */ | 835 | * Then free tx_skbuff and rx_skbuff */ |
843 | static void free_skb_resources(struct gfar_private *priv) | 836 | static void free_skb_resources(struct gfar_private *priv) |
844 | { | 837 | { |
838 | struct device *dev = &priv->ofdev->dev; | ||
845 | struct rxbd8 *rxbdp; | 839 | struct rxbd8 *rxbdp; |
846 | struct txbd8 *txbdp; | 840 | struct txbd8 *txbdp; |
847 | int i, j; | 841 | int i, j; |
@@ -849,6 +843,9 @@ static void free_skb_resources(struct gfar_private *priv) | |||
849 | /* Go through all the buffer descriptors and free their data buffers */ | 843 | /* Go through all the buffer descriptors and free their data buffers */ |
850 | txbdp = priv->tx_bd_base; | 844 | txbdp = priv->tx_bd_base; |
851 | 845 | ||
846 | if (!priv->tx_skbuff) | ||
847 | goto skip_tx_skbuff; | ||
848 | |||
852 | for (i = 0; i < priv->tx_ring_size; i++) { | 849 | for (i = 0; i < priv->tx_ring_size; i++) { |
853 | if (!priv->tx_skbuff[i]) | 850 | if (!priv->tx_skbuff[i]) |
854 | continue; | 851 | continue; |
@@ -867,30 +864,33 @@ static void free_skb_resources(struct gfar_private *priv) | |||
867 | } | 864 | } |
868 | 865 | ||
869 | kfree(priv->tx_skbuff); | 866 | kfree(priv->tx_skbuff); |
867 | skip_tx_skbuff: | ||
870 | 868 | ||
871 | rxbdp = priv->rx_bd_base; | 869 | rxbdp = priv->rx_bd_base; |
872 | 870 | ||
873 | /* rx_skbuff is not guaranteed to be allocated, so only | 871 | if (!priv->rx_skbuff) |
874 | * free it and its contents if it is allocated */ | 872 | goto skip_rx_skbuff; |
875 | if(priv->rx_skbuff != NULL) { | ||
876 | for (i = 0; i < priv->rx_ring_size; i++) { | ||
877 | if (priv->rx_skbuff[i]) { | ||
878 | dma_unmap_single(&priv->ofdev->dev, rxbdp->bufPtr, | ||
879 | priv->rx_buffer_size, | ||
880 | DMA_FROM_DEVICE); | ||
881 | |||
882 | dev_kfree_skb_any(priv->rx_skbuff[i]); | ||
883 | priv->rx_skbuff[i] = NULL; | ||
884 | } | ||
885 | |||
886 | rxbdp->lstatus = 0; | ||
887 | rxbdp->bufPtr = 0; | ||
888 | 873 | ||
889 | rxbdp++; | 874 | for (i = 0; i < priv->rx_ring_size; i++) { |
875 | if (priv->rx_skbuff[i]) { | ||
876 | dma_unmap_single(&priv->ofdev->dev, rxbdp->bufPtr, | ||
877 | priv->rx_buffer_size, | ||
878 | DMA_FROM_DEVICE); | ||
879 | dev_kfree_skb_any(priv->rx_skbuff[i]); | ||
880 | priv->rx_skbuff[i] = NULL; | ||
890 | } | 881 | } |
891 | 882 | ||
892 | kfree(priv->rx_skbuff); | 883 | rxbdp->lstatus = 0; |
884 | rxbdp->bufPtr = 0; | ||
885 | rxbdp++; | ||
893 | } | 886 | } |
887 | |||
888 | kfree(priv->rx_skbuff); | ||
889 | skip_rx_skbuff: | ||
890 | |||
891 | dma_free_coherent(dev, sizeof(*txbdp) * priv->tx_ring_size + | ||
892 | sizeof(*rxbdp) * priv->rx_ring_size, | ||
893 | priv->tx_bd_base, gfar_read(&priv->regs->tbase0)); | ||
894 | } | 894 | } |
895 | 895 | ||
896 | void gfar_start(struct net_device *dev) | 896 | void gfar_start(struct net_device *dev) |
@@ -1148,11 +1148,8 @@ tx_irq_fail: | |||
1148 | err_irq_fail: | 1148 | err_irq_fail: |
1149 | err_rxalloc_fail: | 1149 | err_rxalloc_fail: |
1150 | rx_skb_fail: | 1150 | rx_skb_fail: |
1151 | free_skb_resources(priv); | ||
1152 | tx_skb_fail: | 1151 | tx_skb_fail: |
1153 | dma_free_coherent(dev, sizeof(*txbdp) * priv->tx_ring_size + | 1152 | free_skb_resources(priv); |
1154 | sizeof(*rxbdp) * priv->rx_ring_size, | ||
1155 | priv->tx_bd_base, gfar_read(®s->tbase0)); | ||
1156 | return err; | 1153 | return err; |
1157 | } | 1154 | } |
1158 | 1155 | ||