Re: [PATCH net-next] net: ethernet: mediatek: use phydev from struct net_device

2016-09-22 Thread David Miller
From: 
Date: Thu, 22 Sep 2016 16:33:35 +0800

> From: Sean Wang 
> 
> reuse phydev already in struct net_device instead of creating
> another new one in private structure.
> 
> Signed-off-by: Sean Wang 

Applied.


[PATCH net-next] net: ethernet: mediatek: use phydev from struct net_device

2016-09-22 Thread sean.wang
From: Sean Wang 

reuse phydev already in struct net_device instead of creating
another new one in private structure.

Signed-off-by: Sean Wang 
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 73 ++---
 drivers/net/ethernet/mediatek/mtk_eth_soc.h |  2 -
 2 files changed, 36 insertions(+), 39 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c 
b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index ec60794..6b7acf4 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -175,7 +175,7 @@ static void mtk_phy_link_adjust(struct net_device *dev)
if (unlikely(test_bit(MTK_RESETTING, >hw->state)))
return;
 
-   switch (mac->phy_dev->speed) {
+   switch (dev->phydev->speed) {
case SPEED_1000:
mcr |= MAC_MCR_SPEED_1000;
break;
@@ -185,22 +185,22 @@ static void mtk_phy_link_adjust(struct net_device *dev)
};
 
if (mac->id == 0 && !mac->trgmii)
-   mtk_gmac0_rgmii_adjust(mac->hw, mac->phy_dev->speed);
+   mtk_gmac0_rgmii_adjust(mac->hw, dev->phydev->speed);
 
-   if (mac->phy_dev->link)
+   if (dev->phydev->link)
mcr |= MAC_MCR_FORCE_LINK;
 
-   if (mac->phy_dev->duplex) {
+   if (dev->phydev->duplex) {
mcr |= MAC_MCR_FORCE_DPX;
 
-   if (mac->phy_dev->pause)
+   if (dev->phydev->pause)
rmt_adv = LPA_PAUSE_CAP;
-   if (mac->phy_dev->asym_pause)
+   if (dev->phydev->asym_pause)
rmt_adv |= LPA_PAUSE_ASYM;
 
-   if (mac->phy_dev->advertising & ADVERTISED_Pause)
+   if (dev->phydev->advertising & ADVERTISED_Pause)
lcl_adv |= ADVERTISE_PAUSE_CAP;
-   if (mac->phy_dev->advertising & ADVERTISED_Asym_Pause)
+   if (dev->phydev->advertising & ADVERTISED_Asym_Pause)
lcl_adv |= ADVERTISE_PAUSE_ASYM;
 
flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
@@ -217,7 +217,7 @@ static void mtk_phy_link_adjust(struct net_device *dev)
 
mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
 
-   if (mac->phy_dev->link)
+   if (dev->phydev->link)
netif_carrier_on(dev);
else
netif_carrier_off(dev);
@@ -255,17 +255,17 @@ static int mtk_phy_connect_node(struct mtk_eth *eth, 
struct mtk_mac *mac,
 mac->id, phydev_name(phydev), phydev->phy_id,
 phydev->drv->name);
 
-   mac->phy_dev = phydev;
-
return 0;
 }
 
-static int mtk_phy_connect(struct mtk_mac *mac)
+static int mtk_phy_connect(struct net_device *dev)
 {
-   struct mtk_eth *eth = mac->hw;
+   struct mtk_mac *mac = netdev_priv(dev);
+   struct mtk_eth *eth;
struct device_node *np;
u32 val;
 
+   eth = mac->hw;
np = of_parse_phandle(mac->of_node, "phy-handle", 0);
if (!np && of_phy_is_fixed_link(mac->of_node))
if (!of_phy_register_fixed_link(mac->of_node))
@@ -303,20 +303,21 @@ static int mtk_phy_connect(struct mtk_mac *mac)
val |= SYSCFG0_GE_MODE(mac->ge_mode, mac->id);
regmap_write(eth->ethsys, ETHSYS_SYSCFG0, val);
 
+   /* couple phydev to net_device */
mtk_phy_connect_node(eth, mac, np);
-   mac->phy_dev->autoneg = AUTONEG_ENABLE;
-   mac->phy_dev->speed = 0;
-   mac->phy_dev->duplex = 0;
+   dev->phydev->autoneg = AUTONEG_ENABLE;
+   dev->phydev->speed = 0;
+   dev->phydev->duplex = 0;
 
if (of_phy_is_fixed_link(mac->of_node))
-   mac->phy_dev->supported |=
+   dev->phydev->supported |=
SUPPORTED_Pause | SUPPORTED_Asym_Pause;
 
-   mac->phy_dev->supported &= PHY_GBIT_FEATURES | SUPPORTED_Pause |
+   dev->phydev->supported &= PHY_GBIT_FEATURES | SUPPORTED_Pause |
   SUPPORTED_Asym_Pause;
-   mac->phy_dev->advertising = mac->phy_dev->supported |
+   dev->phydev->advertising = dev->phydev->supported |
ADVERTISED_Autoneg;
-   phy_start_aneg(mac->phy_dev);
+   phy_start_aneg(dev->phydev);
 
of_node_put(np);
 
@@ -1742,7 +1743,7 @@ static int mtk_open(struct net_device *dev)
}
atomic_inc(>dma_refcnt);
 
-   phy_start(mac->phy_dev);
+   phy_start(dev->phydev);
netif_start_queue(dev);
 
return 0;
@@ -1777,7 +1778,7 @@ static int mtk_stop(struct net_device *dev)
struct mtk_eth *eth = mac->hw;
 
netif_tx_disable(dev);
-   phy_stop(mac->phy_dev);
+   phy_stop(dev->phydev);
 
/* only shutdown DMA if this is the last user */
if (!atomic_dec_and_test(>dma_refcnt))
@@ -1917,7 +1918,7 @@ static int __init mtk_init(struct net_device *dev)