Commit b1f6696d authored by John Efstathiades's avatar John Efstathiades Committed by David S. Miller

lan78xx: Fix exception on link speed change

An exception is sometimes seen when the link speed is changed
from auto-negotiation to a fixed speed, or vice versa. The
exception occurs when the MAC is reset (due to the link speed
change) at the same time as the PHY state machine is accessing
a PHY register. The following changes fix this problem.

Rework the MAC reset to ensure there is no outstanding MDIO
register transaction before the reset and then wait until the
reset is complete before allowing any further MAC register access.
Signed-off-by: default avatarJohn Efstathiades <john.efstathiades@pebblebay.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3415f6ba
......@@ -1163,6 +1163,52 @@ static int lan78xx_update_flowcontrol(struct lan78xx_net *dev, u8 duplex,
return 0;
}
static int lan78xx_mac_reset(struct lan78xx_net *dev)
{
unsigned long start_time = jiffies;
u32 val;
int ret;
mutex_lock(&dev->phy_mutex);
/* Resetting the device while there is activity on the MDIO
* bus can result in the MAC interface locking up and not
* completing register access transactions.
*/
ret = lan78xx_phy_wait_not_busy(dev);
if (ret < 0)
goto done;
ret = lan78xx_read_reg(dev, MAC_CR, &val);
if (ret < 0)
goto done;
val |= MAC_CR_RST_;
ret = lan78xx_write_reg(dev, MAC_CR, val);
if (ret < 0)
goto done;
/* Wait for the reset to complete before allowing any further
* MAC register accesses otherwise the MAC may lock up.
*/
do {
ret = lan78xx_read_reg(dev, MAC_CR, &val);
if (ret < 0)
goto done;
if (!(val & MAC_CR_RST_)) {
ret = 0;
goto done;
}
} while (!time_after(jiffies, start_time + HZ));
ret = -ETIMEDOUT;
done:
mutex_unlock(&dev->phy_mutex);
return ret;
}
static int lan78xx_link_reset(struct lan78xx_net *dev)
{
struct phy_device *phydev = dev->net->phydev;
......@@ -1184,12 +1230,8 @@ static int lan78xx_link_reset(struct lan78xx_net *dev)
dev->link_on = false;
/* reset MAC */
ret = lan78xx_read_reg(dev, MAC_CR, &buf);
if (unlikely(ret < 0))
return ret;
buf |= MAC_CR_RST_;
ret = lan78xx_write_reg(dev, MAC_CR, buf);
if (unlikely(ret < 0))
ret = lan78xx_mac_reset(dev);
if (ret < 0)
return ret;
del_timer(&dev->stat_monitor);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment