nuport-mac: disable MAC RX and TX during interface close
[openwrt/staging/lynxis.git] / target / linux / mcs814x / files-3.3 / drivers / net / ethernet / mcs8140 / nuport_mac.c
index 38dbe1ee7d06b7ffd9ed8f4f62a5739f2c6fd92c..4a4208604618fd71d409997f80f8d538189aac03 100644 (file)
@@ -256,7 +256,7 @@ static int nuport_mac_start_tx_dma(struct nuport_mac_priv *priv,
 
        priv->tx_addr = dma_map_single(&priv->pdev->dev, skb->data,
                        skb->len, DMA_TO_DEVICE);
-       if (!priv->tx_addr)
+       if (dma_mapping_error(&priv->pdev->dev, priv->tx_addr))
                return -ENOMEM;
 
        /* enable enhanced mode */
@@ -299,7 +299,7 @@ static int nuport_mac_start_rx_dma(struct nuport_mac_priv *priv,
 
        priv->rx_addr = dma_map_single(&priv->pdev->dev, skb->data,
                                RX_ALLOC_SIZE, DMA_FROM_DEVICE);
-       if (!priv->rx_addr)
+       if (dma_mapping_error(&priv->pdev->dev, priv->rx_addr))
                return -ENOMEM;
 
        nuport_mac_writel(priv->rx_addr, RX_BUFFER_ADDR);
@@ -688,6 +688,10 @@ static void nuport_mac_free_rx_ring(struct nuport_mac_priv *priv)
                dev_kfree_skb(priv->rx_skb[i]);
                priv->rx_skb[i] = NULL;
        }
+
+       if (priv->rx_addr)
+               dma_unmap_single(&priv->pdev->dev, priv->rx_addr, RX_ALLOC_SIZE,
+                               DMA_TO_DEVICE);
 }
 
 static void nuport_mac_read_mac_address(struct net_device *dev)
@@ -761,7 +765,12 @@ static int nuport_mac_open(struct net_device *dev)
                goto out_emac_clk;
        }
 
-       phy_start(priv->phydev);
+       ret = request_irq(priv->tx_irq, &nuport_mac_tx_interrupt,
+                               0, dev->name, dev);
+       if (ret) {
+               netdev_err(dev, "unable to request rx interrupt\n");
+               goto out_link_irq;
+       }
 
        /* Enable link interrupt monitoring for our PHY address */
        reg = LINK_INT_EN | (priv->phydev->addr << LINK_PHY_ADDR_SHIFT);
@@ -775,14 +784,7 @@ static int nuport_mac_open(struct net_device *dev)
        nuport_mac_writel(LINK_POLL_MASK, LINK_INT_POLL_TIME);
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       ret = request_irq(priv->tx_irq, &nuport_mac_tx_interrupt,
-                               0, dev->name, dev);
-       if (ret) {
-               netdev_err(dev, "unable to request rx interrupt\n");
-               goto out_link_irq;
-       }
-
-       napi_enable(&priv->napi);
+       phy_start(priv->phydev);
 
        ret = request_irq(priv->rx_irq, &nuport_mac_rx_interrupt,
                                0, dev->name, dev);
@@ -805,7 +807,13 @@ static int nuport_mac_open(struct net_device *dev)
        nuport_mac_reset_rx_dma(priv);
 
        /* Start RX DMA */
-       return nuport_mac_start_rx_dma(priv, priv->rx_skb[0]);
+       spin_lock_irqsave(&priv->lock, flags);
+       ret = nuport_mac_start_rx_dma(priv, priv->rx_skb[0]);
+       spin_unlock_irqrestore(&priv->lock, flags);
+
+       napi_enable(&priv->napi);
+
+       return ret;
 
 out_rx_skb:
        nuport_mac_free_rx_ring(priv);
@@ -821,9 +829,14 @@ out_emac_clk:
 
 static int nuport_mac_close(struct net_device *dev)
 {
+       u32 reg;
        struct nuport_mac_priv *priv = netdev_priv(dev);
 
        spin_lock_irq(&priv->lock);
+       reg = nuport_mac_readl(CTRL_REG);
+       reg &= ~(RX_ENABLE | TX_ENABLE);
+       nuport_mac_writel(reg, CTRL_REG);
+
        napi_disable(&priv->napi);
        netif_stop_queue(dev);