Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9ad372fc authored by Jose Abreu's avatar Jose Abreu Committed by David S. Miller
Browse files

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: default avatarJose 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: default avatarDavid S. Miller <davem@davemloft.net>
parent 5948d117
Loading
Loading
Loading
Loading
+72 −41
Original line number Diff line number Diff line
@@ -848,46 +848,17 @@ static void stmmac_mac_flow_ctrl(struct stmmac_priv *priv, u32 duplex)
			priv->pause, tx_cnt);
}

/**
 * stmmac_adjust_link - adjusts the link parameters
 * @dev: net device structure
 * Description: this is the helper called by the physical abstraction layer
 * drivers to communicate the phy link status. According the speed and duplex
 * this driver can invoke registered glue-logic as well.
 * It also invoke the eee initialization because it could happen when switch
 * on different networks (that are eee capable).
 */
static void stmmac_adjust_link(struct net_device *dev)
static void stmmac_mac_config(struct net_device *dev)
{
	struct stmmac_priv *priv = netdev_priv(dev);
	struct phy_device *phydev = dev->phydev;
	bool new_state = false;
	u32 ctrl;

	if (!phydev)
		return;

	mutex_lock(&priv->lock);

	if (phydev->link) {
		u32 ctrl = readl(priv->ioaddr + MAC_CTRL_REG);

		/* Now we make sure that we can be in full duplex mode.
		 * If not, we operate in half-duplex mode. */
		if (phydev->duplex != priv->oldduplex) {
			new_state = true;
			if (!phydev->duplex)
				ctrl &= ~priv->hw->link.duplex;
			else
				ctrl |= priv->hw->link.duplex;
			priv->oldduplex = phydev->duplex;
		}
		/* Flow Control operation */
		if (phydev->pause)
			stmmac_mac_flow_ctrl(priv, phydev->duplex);
	ctrl = readl(priv->ioaddr + MAC_CTRL_REG);

	if (phydev->speed != priv->speed) {
			new_state = true;
		ctrl &= ~priv->hw->link.speed_mask;

		switch (phydev->speed) {
		case SPEED_1000:
			ctrl |= priv->hw->link.speed1000;
@@ -904,12 +875,67 @@ static void stmmac_adjust_link(struct net_device *dev)
			phydev->speed = SPEED_UNKNOWN;
			break;
		}

		if (phydev->speed != SPEED_UNKNOWN)
			stmmac_hw_fix_mac_speed(priv);

		priv->speed = phydev->speed;
	}

	/* Now we make sure that we can be in full duplex mode.
	 * If not, we operate in half-duplex mode. */
	if (phydev->duplex != priv->oldduplex) {
		if (!phydev->duplex)
			ctrl &= ~priv->hw->link.duplex;
		else
			ctrl |= priv->hw->link.duplex;

		priv->oldduplex = phydev->duplex;
	}

	/* Flow Control operation */
	if (phydev->pause)
		stmmac_mac_flow_ctrl(priv, phydev->duplex);

	writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
}

static void stmmac_mac_link_down(struct net_device *dev, bool autoneg)
{
	struct stmmac_priv *priv = netdev_priv(dev);

	stmmac_mac_set(priv, priv->ioaddr, false);
}

static void stmmac_mac_link_up(struct net_device *dev, bool autoneg)
{
	struct stmmac_priv *priv = netdev_priv(dev);

	stmmac_mac_set(priv, priv->ioaddr, true);
}

/**
 * stmmac_adjust_link - adjusts the link parameters
 * @dev: net device structure
 * Description: this is the helper called by the physical abstraction layer
 * drivers to communicate the phy link status. According the speed and duplex
 * this driver can invoke registered glue-logic as well.
 * It also invoke the eee initialization because it could happen when switch
 * on different networks (that are eee capable).
 */
static void stmmac_adjust_link(struct net_device *dev)
{
	struct stmmac_priv *priv = netdev_priv(dev);
	struct phy_device *phydev = dev->phydev;
	bool new_state = false;

	if (!phydev)
		return;

	mutex_lock(&priv->lock);

	if (phydev->link) {
		stmmac_mac_config(dev);

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

	if (phydev->link)
		stmmac_mac_link_up(dev, false);
	else
		stmmac_mac_link_down(dev, false);

	if (new_state && netif_msg_link(priv))
		phy_print_status(phydev);