ethernet: stmicro: stmmac: add missing of_node_put after calling of_parse_phandle
[cascardo/linux.git] / drivers / net / ethernet / stmicro / stmmac / stmmac_main.c
index e407126..4c8c60a 100644 (file)
@@ -285,8 +285,9 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
        /* Using PCS we cannot dial with the phy registers at this stage
         * so we do not support extra feature like EEE.
         */
-       if ((priv->pcs == STMMAC_PCS_RGMII) || (priv->pcs == STMMAC_PCS_TBI) ||
-           (priv->pcs == STMMAC_PCS_RTBI))
+       if ((priv->hw->pcs == STMMAC_PCS_RGMII) ||
+           (priv->hw->pcs == STMMAC_PCS_TBI) ||
+           (priv->hw->pcs == STMMAC_PCS_RTBI))
                goto out;
 
        /* MAC core supports the EEE feature. */
@@ -799,10 +800,10 @@ static void stmmac_check_pcs_mode(struct stmmac_priv *priv)
                    (interface == PHY_INTERFACE_MODE_RGMII_RXID) ||
                    (interface == PHY_INTERFACE_MODE_RGMII_TXID)) {
                        pr_debug("STMMAC: PCS RGMII support enable\n");
-                       priv->pcs = STMMAC_PCS_RGMII;
+                       priv->hw->pcs = STMMAC_PCS_RGMII;
                } else if (interface == PHY_INTERFACE_MODE_SGMII) {
                        pr_debug("STMMAC: PCS SGMII support enable\n");
-                       priv->pcs = STMMAC_PCS_SGMII;
+                       priv->hw->pcs = STMMAC_PCS_SGMII;
                }
        }
 }
@@ -1665,6 +1666,19 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
        if (priv->plat->bus_setup)
                priv->plat->bus_setup(priv->ioaddr);
 
+       /* PS and related bits will be programmed according to the speed */
+       if (priv->hw->pcs) {
+               int speed = priv->plat->mac_port_sel_speed;
+
+               if ((speed == SPEED_10) || (speed == SPEED_100) ||
+                   (speed == SPEED_1000)) {
+                       priv->hw->ps = speed;
+               } else {
+                       dev_warn(priv->device, "invalid port speed\n");
+                       priv->hw->ps = 0;
+               }
+       }
+
        /* Initialize the MAC Core */
        priv->hw->mac->core_init(priv->hw, dev->mtu);
 
@@ -1714,8 +1728,8 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp)
                priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT);
        }
 
-       if (priv->pcs && priv->hw->mac->ctrl_ane)
-               priv->hw->mac->ctrl_ane(priv->hw, 0);
+       if (priv->hw->pcs && priv->hw->mac->pcs_ctrl_ane)
+               priv->hw->mac->pcs_ctrl_ane(priv->hw, 1, priv->hw->ps, 0);
 
        /*  set TX ring length */
        if (priv->hw->dma->set_tx_ring_len)
@@ -1748,8 +1762,9 @@ static int stmmac_open(struct net_device *dev)
 
        stmmac_check_ether_addr(priv);
 
-       if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI &&
-           priv->pcs != STMMAC_PCS_RTBI) {
+       if (priv->hw->pcs != STMMAC_PCS_RGMII &&
+           priv->hw->pcs != STMMAC_PCS_TBI &&
+           priv->hw->pcs != STMMAC_PCS_RTBI) {
                ret = stmmac_init_phy(dev);
                if (ret) {
                        pr_err("%s: Cannot attach to PHY (error: %d)\n",
@@ -2809,6 +2824,14 @@ static irqreturn_t stmmac_interrupt(int irq, void *dev_id)
                                                        priv->rx_tail_addr,
                                                        STMMAC_CHAN0);
                }
+
+               /* PCS link status */
+               if (priv->hw->pcs) {
+                       if (priv->xstats.pcs_link)
+                               netif_carrier_on(dev);
+                       else
+                               netif_carrier_off(dev);
+               }
        }
 
        /* To handle DMA interrupts */
@@ -3130,6 +3153,7 @@ static int stmmac_hw_init(struct stmmac_priv *priv)
                 */
                priv->plat->enh_desc = priv->dma_cap.enh_desc;
                priv->plat->pmt = priv->dma_cap.pmt_remote_wake_up;
+               priv->hw->pmt = priv->plat->pmt;
 
                /* TXCOE doesn't work in thresh DMA mode */
                if (priv->plat->force_thresh_dma_mode)
@@ -3325,8 +3349,9 @@ int stmmac_dvr_probe(struct device *device,
 
        stmmac_check_pcs_mode(priv);
 
-       if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI &&
-           priv->pcs != STMMAC_PCS_RTBI) {
+       if (priv->hw->pcs != STMMAC_PCS_RGMII  &&
+           priv->hw->pcs != STMMAC_PCS_TBI &&
+           priv->hw->pcs != STMMAC_PCS_RTBI) {
                /* MDIO bus Registration */
                ret = stmmac_mdio_register(ndev);
                if (ret < 0) {
@@ -3372,12 +3397,14 @@ int stmmac_dvr_remove(struct device *dev)
        stmmac_set_mac(priv->ioaddr, false);
        netif_carrier_off(ndev);
        unregister_netdev(ndev);
+       of_node_put(priv->plat->phy_node);
        if (priv->stmmac_rst)
                reset_control_assert(priv->stmmac_rst);
        clk_disable_unprepare(priv->pclk);
        clk_disable_unprepare(priv->stmmac_clk);
-       if (priv->pcs != STMMAC_PCS_RGMII && priv->pcs != STMMAC_PCS_TBI &&
-           priv->pcs != STMMAC_PCS_RTBI)
+       if (priv->hw->pcs != STMMAC_PCS_RGMII &&
+           priv->hw->pcs != STMMAC_PCS_TBI &&
+           priv->hw->pcs != STMMAC_PCS_RTBI)
                stmmac_mdio_unregister(ndev);
        free_netdev(ndev);