Commit 6b655529 authored by Andy Fleming's avatar Andy Fleming Committed by Jeff Garzik

[PATCH] Fixed a number of bugs in the PHY Layer

* genphy_update_link is now exported
* Added a fix from ncase@xes-inc.com which changes forcing so it
  only updates the link.  Otherwise, it never tries the lower
  values, since it is always overwriting the speed/duplex values
  with the current ones, rather than the intended ones.
* Fixed a bug where bringing up a PHY with no link caused it to
  timeout, and enter forcing mode.  Once in forcing mode,
  plugging in the link didn't autonegotiate.  Now the AN state
  detects the lack of link, and enters the NO_LINK state.  AN
  only times out if the link is up and AN fails
* Cleaned up the PHY_AN case, reducing one level of indentation
  for the timeout code.
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent 2109f89f
...@@ -713,61 +713,58 @@ static void phy_timer(unsigned long data) ...@@ -713,61 +713,58 @@ static void phy_timer(unsigned long data)
break; break;
case PHY_AN: case PHY_AN:
err = phy_read_status(phydev);
if (err < 0)
break;
/* If the link is down, give up on
* negotiation for now */
if (!phydev->link) {
phydev->state = PHY_NOLINK;
netif_carrier_off(phydev->attached_dev);
phydev->adjust_link(phydev->attached_dev);
break;
}
/* Check if negotiation is done. Break /* Check if negotiation is done. Break
* if there's an error */ * if there's an error */
err = phy_aneg_done(phydev); err = phy_aneg_done(phydev);
if (err < 0) if (err < 0)
break; break;
/* If auto-negotiation is done, we change to /* If AN is done, we're running */
* either RUNNING, or NOLINK */
if (err > 0) { if (err > 0) {
err = phy_read_status(phydev);
if (err)
break;
if (phydev->link) {
phydev->state = PHY_RUNNING; phydev->state = PHY_RUNNING;
netif_carrier_on(phydev->attached_dev); netif_carrier_on(phydev->attached_dev);
} else {
phydev->state = PHY_NOLINK;
netif_carrier_off(phydev->attached_dev);
}
phydev->adjust_link(phydev->attached_dev); phydev->adjust_link(phydev->attached_dev);
} else if (0 == phydev->link_timeout--) { } else if (0 == phydev->link_timeout--) {
/* The counter expired, so either we
* switch to forced mode, or the
* magic_aneg bit exists, and we try aneg
* again */
if (!(phydev->drv->flags & PHY_HAS_MAGICANEG)) {
int idx; int idx;
/* We'll start from the needs_aneg = 1;
* fastest speed, and work /* If we have the magic_aneg bit,
* our way down */ * we try again */
idx = phy_find_valid(0, if (phydev->drv->flags & PHY_HAS_MAGICANEG)
phydev->supported); break;
/* The timer expired, and we still
* don't have a setting, so we try
* forcing it until we find one that
* works, starting from the fastest speed,
* and working our way down */
idx = phy_find_valid(0, phydev->supported);
phydev->speed = settings[idx].speed; phydev->speed = settings[idx].speed;
phydev->duplex = settings[idx].duplex; phydev->duplex = settings[idx].duplex;
phydev->autoneg = AUTONEG_DISABLE; phydev->autoneg = AUTONEG_DISABLE;
phydev->state = PHY_FORCING;
phydev->link_timeout =
PHY_FORCE_TIMEOUT;
pr_info("Trying %d/%s\n", pr_info("Trying %d/%s\n", phydev->speed,
phydev->speed,
DUPLEX_FULL == DUPLEX_FULL ==
phydev->duplex ? phydev->duplex ?
"FULL" : "HALF"); "FULL" : "HALF");
} }
needs_aneg = 1;
}
break; break;
case PHY_NOLINK: case PHY_NOLINK:
err = phy_read_status(phydev); err = phy_read_status(phydev);
...@@ -782,7 +779,7 @@ static void phy_timer(unsigned long data) ...@@ -782,7 +779,7 @@ static void phy_timer(unsigned long data)
} }
break; break;
case PHY_FORCING: case PHY_FORCING:
err = phy_read_status(phydev); err = genphy_update_link(phydev);
if (err) if (err)
break; break;
......
...@@ -427,6 +427,7 @@ int genphy_update_link(struct phy_device *phydev) ...@@ -427,6 +427,7 @@ int genphy_update_link(struct phy_device *phydev)
return 0; return 0;
} }
EXPORT_SYMBOL(genphy_update_link);
/* genphy_read_status /* genphy_read_status
* *
......
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