]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/net/stmmac/stmmac_main.c
stmmac: add init/exit callback in plat_stmmacenet_data struct
[net-next-2.6.git] / drivers / net / stmmac / stmmac_main.c
index 823b9e6431d5f29a3b23a45be8bdbda962a61565..b806cd3515b43f36c7cfd84bef45926bb32b6e40 100644 (file)
@@ -186,6 +186,18 @@ static inline u32 stmmac_tx_avail(struct stmmac_priv *priv)
        return priv->dirty_tx + priv->dma_tx_size - priv->cur_tx - 1;
 }
 
+/* On some ST platforms, some HW system configuraton registers have to be
+ * set according to the link speed negotiated.
+ */
+static inline void stmmac_hw_fix_mac_speed(struct stmmac_priv *priv)
+{
+       struct phy_device *phydev = priv->phydev;
+
+       if (likely(priv->plat->fix_mac_speed))
+               priv->plat->fix_mac_speed(priv->plat->bsp_priv,
+                                         phydev->speed);
+}
+
 /**
  * stmmac_adjust_link
  * @dev: net device structure
@@ -228,15 +240,13 @@ static void stmmac_adjust_link(struct net_device *dev)
                        new_state = 1;
                        switch (phydev->speed) {
                        case 1000:
-                               if (likely(priv->is_gmac))
+                               if (likely(priv->plat->has_gmac))
                                        ctrl &= ~priv->hw->link.port;
-                               if (likely(priv->fix_mac_speed))
-                                       priv->fix_mac_speed(priv->bsp_priv,
-                                                           phydev->speed);
+                               stmmac_hw_fix_mac_speed(priv);
                                break;
                        case 100:
                        case 10:
-                               if (priv->is_gmac) {
+                               if (priv->plat->has_gmac) {
                                        ctrl |= priv->hw->link.port;
                                        if (phydev->speed == SPEED_100) {
                                                ctrl |= priv->hw->link.speed;
@@ -246,9 +256,7 @@ static void stmmac_adjust_link(struct net_device *dev)
                                } else {
                                        ctrl &= ~priv->hw->link.port;
                                }
-                               if (likely(priv->fix_mac_speed))
-                                       priv->fix_mac_speed(priv->bsp_priv,
-                                                           phydev->speed);
+                               stmmac_hw_fix_mac_speed(priv);
                                break;
                        default:
                                if (netif_msg_link(priv))
@@ -305,7 +313,7 @@ static int stmmac_init_phy(struct net_device *dev)
                return 0;
        }
 
-       snprintf(bus_id, MII_BUS_ID_SIZE, "%x", priv->bus_id);
+       snprintf(bus_id, MII_BUS_ID_SIZE, "%x", priv->plat->bus_id);
        snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
                 priv->phy_addr);
        pr_debug("stmmac_init_phy:  trying to attach to %s\n", phy_id);
@@ -337,33 +345,19 @@ static int stmmac_init_phy(struct net_device *dev)
        return 0;
 }
 
-static inline void stmmac_mac_enable_rx(void __iomem *ioaddr)
+static inline void stmmac_enable_mac(void __iomem *ioaddr)
 {
        u32 value = readl(ioaddr + MAC_CTRL_REG);
-       value |= MAC_RNABLE_RX;
-       /* Set the RE (receive enable bit into the MAC CTRL register).  */
-       writel(value, ioaddr + MAC_CTRL_REG);
-}
 
-static inline void stmmac_mac_enable_tx(void __iomem *ioaddr)
-{
-       u32 value = readl(ioaddr + MAC_CTRL_REG);
-       value |= MAC_ENABLE_TX;
-       /* Set the TE (transmit enable bit into the MAC CTRL register).  */
+       value |= MAC_RNABLE_RX | MAC_ENABLE_TX;
        writel(value, ioaddr + MAC_CTRL_REG);
 }
 
-static inline void stmmac_mac_disable_rx(void __iomem *ioaddr)
+static inline void stmmac_disable_mac(void __iomem *ioaddr)
 {
        u32 value = readl(ioaddr + MAC_CTRL_REG);
-       value &= ~MAC_RNABLE_RX;
-       writel(value, ioaddr + MAC_CTRL_REG);
-}
 
-static inline void stmmac_mac_disable_tx(void __iomem *ioaddr)
-{
-       u32 value = readl(ioaddr + MAC_CTRL_REG);
-       value &= ~MAC_ENABLE_TX;
+       value &= ~(MAC_ENABLE_TX | MAC_RNABLE_RX);
        writel(value, ioaddr + MAC_CTRL_REG);
 }
 
@@ -566,7 +560,7 @@ static void free_dma_desc_resources(struct stmmac_priv *priv)
  */
 static void stmmac_dma_operation_mode(struct stmmac_priv *priv)
 {
-       if (likely((priv->tx_coe) && (!priv->no_csum_insertion))) {
+       if (likely((priv->plat->tx_coe) && (!priv->no_csum_insertion))) {
                /* In case of GMAC, SF mode has to be enabled
                 * to perform the TX COE. This depends on:
                 * 1) TX COE if actually supported
@@ -828,7 +822,7 @@ static int stmmac_open(struct net_device *dev)
        init_dma_desc_rings(dev);
 
        /* DMA initialization and SW reset */
-       if (unlikely(priv->hw->dma->init(priv->ioaddr, priv->pbl,
+       if (unlikely(priv->hw->dma->init(priv->ioaddr, priv->plat->pbl,
                                         priv->dma_tx_phy,
                                         priv->dma_rx_phy) < 0)) {
 
@@ -839,15 +833,15 @@ static int stmmac_open(struct net_device *dev)
        /* Copy the MAC addr into the HW  */
        priv->hw->mac->set_umac_addr(priv->ioaddr, dev->dev_addr, 0);
        /* If required, perform hw setup of the bus. */
-       if (priv->bus_setup)
-               priv->bus_setup(priv->ioaddr);
+       if (priv->plat->bus_setup)
+               priv->plat->bus_setup(priv->ioaddr);
        /* Initialize the MAC Core */
        priv->hw->mac->core_init(priv->ioaddr);
 
        priv->rx_coe = priv->hw->mac->rx_coe(priv->ioaddr);
        if (priv->rx_coe)
                pr_info("stmmac: Rx Checksum Offload Engine supported\n");
-       if (priv->tx_coe)
+       if (priv->plat->tx_coe)
                pr_info("\tTX Checksum insertion supported\n");
 
        priv->shutdown = 0;
@@ -857,8 +851,7 @@ static int stmmac_open(struct net_device *dev)
        writel(0xffffffff, priv->ioaddr + MMC_LOW_INTR_MASK);
 
        /* Enable the MAC Rx/Tx */
-       stmmac_mac_enable_rx(priv->ioaddr);
-       stmmac_mac_enable_tx(priv->ioaddr);
+       stmmac_enable_mac(priv->ioaddr);
 
        /* Set the HW DMA mode and the COE */
        stmmac_dma_operation_mode(priv);
@@ -928,9 +921,8 @@ static int stmmac_release(struct net_device *dev)
        /* Release and free the Rx/Tx resources */
        free_dma_desc_resources(priv);
 
-       /* Disable the MAC core */
-       stmmac_mac_disable_tx(priv->ioaddr);
-       stmmac_mac_disable_rx(priv->ioaddr);
+       /* Disable the MAC Rx/Tx */
+       stmmac_disable_mac(priv->ioaddr);
 
        netif_carrier_off(dev);
 
@@ -1058,7 +1050,8 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
                return stmmac_sw_tso(priv, skb);
 
        if (likely((skb->ip_summed == CHECKSUM_PARTIAL))) {
-               if (unlikely((!priv->tx_coe) || (priv->no_csum_insertion)))
+               if (unlikely((!priv->plat->tx_coe) ||
+                            (priv->no_csum_insertion)))
                        skb_checksum_help(skb);
                else
                        csum_insertion = 1;
@@ -1162,7 +1155,7 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv)
                                           DMA_FROM_DEVICE);
 
                        (p + entry)->des2 = priv->rx_skbuff_dma[entry];
-                       if (unlikely(priv->is_gmac)) {
+                       if (unlikely(priv->plat->has_gmac)) {
                                if (bfsize >= BUF_SIZE_8KiB)
                                        (p + entry)->des3 =
                                            (p + entry)->des2 + BUF_SIZE_8KiB;
@@ -1372,7 +1365,7 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
                return -EBUSY;
        }
 
-       if (priv->is_gmac)
+       if (priv->plat->has_gmac)
                max_mtu = JUMBO_LEN;
        else
                max_mtu = ETH_DATA_LEN;
@@ -1386,7 +1379,7 @@ static int stmmac_change_mtu(struct net_device *dev, int new_mtu)
         * needs to have the Tx COE disabled for oversized frames
         * (due to limited buffer sizes). In this case we disable
         * the TX csum insertionin the TDES and not use SF. */
-       if ((priv->bugged_jumbo) && (priv->dev->mtu > ETH_DATA_LEN))
+       if ((priv->plat->bugged_jumbo) && (priv->dev->mtu > ETH_DATA_LEN))
                priv->no_csum_insertion = 1;
        else
                priv->no_csum_insertion = 0;
@@ -1406,7 +1399,7 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
                return IRQ_NONE;
        }
 
-       if (priv->is_gmac)
+       if (priv->plat->has_gmac)
                /* To handle GMAC own interrupts */
                priv->hw->mac->host_irq_status((void __iomem *) dev->base_addr);
 
@@ -1552,7 +1545,7 @@ static int stmmac_mac_device_setup(struct net_device *dev)
 
        struct mac_device_info *device;
 
-       if (priv->is_gmac)
+       if (priv->plat->has_gmac)
                device = dwmac1000_setup(priv->ioaddr);
        else
                device = dwmac100_setup(priv->ioaddr);
@@ -1560,7 +1553,7 @@ static int stmmac_mac_device_setup(struct net_device *dev)
        if (!device)
                return -ENOMEM;
 
-       if (priv->enh_desc) {
+       if (priv->plat->enh_desc) {
                device->desc = &enh_desc_ops;
                pr_info("\tEnhanced descriptor structure\n");
        } else
@@ -1614,7 +1607,7 @@ static int stmmac_associate_phy(struct device *dev, void *data)
                plat_dat->bus_id);
 
        /* Check that this phy is for the MAC being initialised */
-       if (priv->bus_id != plat_dat->bus_id)
+       if (priv->plat->bus_id != plat_dat->bus_id)
                return 0;
 
        /* OK, this PHY is connected to the MAC.
@@ -1650,7 +1643,7 @@ static int stmmac_dvr_probe(struct platform_device *pdev)
        struct resource *res;
        void __iomem *addr = NULL;
        struct net_device *ndev = NULL;
-       struct stmmac_priv *priv;
+       struct stmmac_priv *priv = NULL;
        struct plat_stmmacenet_data *plat_dat;
 
        pr_info("STMMAC driver:\n\tplatform registration... ");
@@ -1699,13 +1692,9 @@ static int stmmac_dvr_probe(struct platform_device *pdev)
        priv->device = &(pdev->dev);
        priv->dev = ndev;
        plat_dat = pdev->dev.platform_data;
-       priv->bus_id = plat_dat->bus_id;
-       priv->pbl = plat_dat->pbl;      /* TLI */
-       priv->mii_clk_csr = plat_dat->clk_csr;
-       priv->tx_coe = plat_dat->tx_coe;
-       priv->bugged_jumbo = plat_dat->bugged_jumbo;
-       priv->is_gmac = plat_dat->has_gmac;     /* GMAC is on board */
-       priv->enh_desc = plat_dat->enh_desc;
+
+       priv->plat = plat_dat;
+
        priv->ioaddr = addr;
 
        /* PMT module is not integrated in all the MAC devices. */
@@ -1719,10 +1708,12 @@ static int stmmac_dvr_probe(struct platform_device *pdev)
        /* Set the I/O base addr */
        ndev->base_addr = (unsigned long)addr;
 
-       /* Verify embedded resource for the platform */
-       ret = stmmac_claim_resource(pdev);
-       if (ret < 0)
-               goto out;
+       /* Custom initialisation */
+       if (priv->plat->init) {
+               ret = priv->plat->init(pdev);
+               if (unlikely(ret))
+                       goto out;
+       }
 
        /* MAC HW revice detection */
        ret = stmmac_mac_device_setup(ndev);
@@ -1743,16 +1734,12 @@ static int stmmac_dvr_probe(struct platform_device *pdev)
                goto out;
        }
 
-       priv->fix_mac_speed = plat_dat->fix_mac_speed;
-       priv->bus_setup = plat_dat->bus_setup;
-       priv->bsp_priv = plat_dat->bsp_priv;
-
        pr_info("\t%s - (dev. name: %s - id: %d, IRQ #%d\n"
               "\tIO base addr: 0x%p)\n", ndev->name, pdev->name,
               pdev->id, ndev->irq, addr);
 
        /* MDIO bus Registration */
-       pr_debug("\tMDIO bus (id: %d)...", priv->bus_id);
+       pr_debug("\tMDIO bus (id: %d)...", priv->plat->bus_id);
        ret = stmmac_mdio_register(ndev);
        if (ret < 0)
                goto out;
@@ -1760,6 +1747,9 @@ static int stmmac_dvr_probe(struct platform_device *pdev)
 
 out:
        if (ret < 0) {
+               if (priv->plat->exit)
+                       priv->plat->exit(pdev);
+
                platform_set_drvdata(pdev, NULL);
                release_mem_region(res->start, resource_size(res));
                if (addr != NULL)
@@ -1787,13 +1777,15 @@ static int stmmac_dvr_remove(struct platform_device *pdev)
        priv->hw->dma->stop_rx(priv->ioaddr);
        priv->hw->dma->stop_tx(priv->ioaddr);
 
-       stmmac_mac_disable_rx(priv->ioaddr);
-       stmmac_mac_disable_tx(priv->ioaddr);
+       stmmac_disable_mac(priv->ioaddr);
 
        netif_carrier_off(ndev);
 
        stmmac_mdio_unregister(ndev);
 
+       if (priv->plat->exit)
+               priv->plat->exit(pdev);
+
        platform_set_drvdata(pdev, NULL);
        unregister_netdev(ndev);
 
@@ -1839,13 +1831,11 @@ static int stmmac_suspend(struct platform_device *pdev, pm_message_t state)
                                             dis_ic);
                priv->hw->desc->init_tx_desc(priv->dma_tx, priv->dma_tx_size);
 
-               stmmac_mac_disable_tx(priv->ioaddr);
-
                /* Enable Power down mode by programming the PMT regs */
                if (device_can_wakeup(priv->device))
                        priv->hw->mac->pmt(priv->ioaddr, priv->wolopts);
                else
-                       stmmac_mac_disable_rx(priv->ioaddr);
+                       stmmac_disable_mac(priv->ioaddr);
        } else {
                priv->shutdown = 1;
                /* Although this can appear slightly redundant it actually
@@ -1886,8 +1876,7 @@ static int stmmac_resume(struct platform_device *pdev)
        netif_device_attach(dev);
 
        /* Enable the MAC and DMA */
-       stmmac_mac_enable_rx(priv->ioaddr);
-       stmmac_mac_enable_tx(priv->ioaddr);
+       stmmac_enable_mac(priv->ioaddr);
        priv->hw->dma->start_tx(priv->ioaddr);
        priv->hw->dma->start_rx(priv->ioaddr);