Skip to content

Commit 9ad372f

Browse files
joabreudavem330
authored andcommitted
net: stmmac: Prepare to convert to phylink
In preparation for the convertion, split the adjust_link function into mac_config and add the mac_link_up and mac_link_down functions. Signed-off-by: Jose Abreu <joabreu@synopsys.com> Cc: Joao Pinto <jpinto@synopsys.com> Cc: David S. Miller <davem@davemloft.net> Cc: Giuseppe Cavallaro <peppe.cavallaro@st.com> Cc: Alexandre Torgue <alexandre.torgue@st.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Andrew Lunn <andrew@lunn.ch> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5948d11 commit 9ad372f

File tree

1 file changed

+72
-41
lines changed

1 file changed

+72
-41
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 72 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,72 @@ static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex)
848848
priv->pause, tx_cnt);
849849
}
850850

851+
static void stmmac_mac_config(struct net_device *dev)
852+
{
853+
struct stmmac_priv *priv = netdev_priv(dev);
854+
struct phy_device *phydev = dev->phydev;
855+
u32 ctrl;
856+
857+
ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
858+
859+
if (phydev->speed != priv->speed) {
860+
ctrl &= ~priv->hw->link.speed_mask;
861+
862+
switch (phydev->speed) {
863+
case SPEED_1000:
864+
ctrl |= priv->hw->link.speed1000;
865+
break;
866+
case SPEED_100:
867+
ctrl |= priv->hw->link.speed100;
868+
break;
869+
case SPEED_10:
870+
ctrl |= priv->hw->link.speed10;
871+
break;
872+
default:
873+
netif_warn(priv, link, priv->dev,
874+
"broken speed: %d\n", phydev->speed);
875+
phydev->speed = SPEED_UNKNOWN;
876+
break;
877+
}
878+
879+
if (phydev->speed != SPEED_UNKNOWN)
880+
stmmac_hw_fix_mac_speed(priv);
881+
882+
priv->speed = phydev->speed;
883+
}
884+
885+
/* Now we make sure that we can be in full duplex mode.
886+
* If not, we operate in half-duplex mode. */
887+
if (phydev->duplex != priv->oldduplex) {
888+
if (!phydev->duplex)
889+
ctrl &= ~priv->hw->link.duplex;
890+
else
891+
ctrl |= priv->hw->link.duplex;
892+
893+
priv->oldduplex = phydev->duplex;
894+
}
895+
896+
/* Flow Control operation */
897+
if (phydev->pause)
898+
stmmac_mac_flow_ctrl(priv, phydev->duplex);
899+
900+
writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
901+
}
902+
903+
static void stmmac_mac_link_down(struct net_device *dev, bool autoneg)
904+
{
905+
struct stmmac_priv *priv = netdev_priv(dev);
906+
907+
stmmac_mac_set(priv, priv->ioaddr, false);
908+
}
909+
910+
static void stmmac_mac_link_up(struct net_device *dev, bool autoneg)
911+
{
912+
struct stmmac_priv *priv = netdev_priv(dev);
913+
914+
stmmac_mac_set(priv, priv->ioaddr, true);
915+
}
916+
851917
/**
852918
* stmmac_adjust_link - adjusts the link parameters
853919
* @dev: net device structure
@@ -869,47 +935,7 @@ static void stmmac_adjust_link(struct net_device *dev)
869935
mutex_lock(&priv->lock);
870936

871937
if (phydev->link) {
872-
u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
873-
874-
/* Now we make sure that we can be in full duplex mode.
875-
* If not, we operate in half-duplex mode. */
876-
if (phydev->duplex != priv->oldduplex) {
877-
new_state = true;
878-
if (!phydev->duplex)
879-
ctrl &= ~priv->hw->link.duplex;
880-
else
881-
ctrl |= priv->hw->link.duplex;
882-
priv->oldduplex = phydev->duplex;
883-
}
884-
/* Flow Control operation */
885-
if (phydev->pause)
886-
stmmac_mac_flow_ctrl(priv, phydev->duplex);
887-
888-
if (phydev->speed != priv->speed) {
889-
new_state = true;
890-
ctrl &= ~priv->hw->link.speed_mask;
891-
switch (phydev->speed) {
892-
case SPEED_1000:
893-
ctrl |= priv->hw->link.speed1000;
894-
break;
895-
case SPEED_100:
896-
ctrl |= priv->hw->link.speed100;
897-
break;
898-
case SPEED_10:
899-
ctrl |= priv->hw->link.speed10;
900-
break;
901-
default:
902-
netif_warn(priv, link, priv->dev,
903-
"broken speed: %d\n", phydev->speed);
904-
phydev->speed = SPEED_UNKNOWN;
905-
break;
906-
}
907-
if (phydev->speed != SPEED_UNKNOWN)
908-
stmmac_hw_fix_mac_speed(priv);
909-
priv->speed = phydev->speed;
910-
}
911-
912-
writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
938+
stmmac_mac_config(dev);
913939

914940
if (!priv->oldlink) {
915941
new_state = true;
@@ -922,6 +948,11 @@ static void stmmac_adjust_link(struct net_device *dev)
922948
priv->oldduplex = DUPLEX_UNKNOWN;
923949
}
924950

951+
if (phydev->link)
952+
stmmac_mac_link_up(dev, false);
953+
else
954+
stmmac_mac_link_down(dev, false);
955+
925956
if (new_state && netif_msg_link(priv))
926957
phy_print_status(phydev);
927958

0 commit comments

Comments
 (0)