|
|
@@ -364,7 +364,11 @@ int phy_device_register(struct phy_device *phydev)
|
|
|
phydev->bus->phy_map[phydev->addr] = phydev;
|
|
|
|
|
|
/* Run all of the fixups for this PHY */
|
|
|
- phy_scan_fixups(phydev);
|
|
|
+ err = phy_init_hw(phydev);
|
|
|
+ if (err) {
|
|
|
+ pr_err("PHY %d failed to initialize\n", phydev->addr);
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
|
|
|
err = device_add(&phydev->dev);
|
|
|
if (err) {
|
|
|
@@ -497,6 +501,47 @@ void phy_disconnect(struct phy_device *phydev)
|
|
|
}
|
|
|
EXPORT_SYMBOL(phy_disconnect);
|
|
|
|
|
|
+/**
|
|
|
+ * phy_poll_reset - Safely wait until a PHY reset has properly completed
|
|
|
+ * @phydev: The PHY device to poll
|
|
|
+ *
|
|
|
+ * Description: According to IEEE 802.3, Section 2, Subsection 22.2.4.1.1, as
|
|
|
+ * published in 2008, a PHY reset may take up to 0.5 seconds. The MII BMCR
|
|
|
+ * register must be polled until the BMCR_RESET bit clears.
|
|
|
+ *
|
|
|
+ * Furthermore, any attempts to write to PHY registers may have no effect
|
|
|
+ * or even generate MDIO bus errors until this is complete.
|
|
|
+ *
|
|
|
+ * Some PHYs (such as the Marvell 88E1111) don't entirely conform to the
|
|
|
+ * standard and do not fully reset after the BMCR_RESET bit is set, and may
|
|
|
+ * even *REQUIRE* a soft-reset to properly restart autonegotiation. In an
|
|
|
+ * effort to support such broken PHYs, this function is separate from the
|
|
|
+ * standard phy_init_hw() which will zero all the other bits in the BMCR
|
|
|
+ * and reapply all driver-specific and board-specific fixups.
|
|
|
+ */
|
|
|
+static int phy_poll_reset(struct phy_device *phydev)
|
|
|
+{
|
|
|
+ /* Poll until the reset bit clears (50ms per retry == 0.6 sec) */
|
|
|
+ unsigned int retries = 12;
|
|
|
+ int ret;
|
|
|
+
|
|
|
+ do {
|
|
|
+ msleep(50);
|
|
|
+ ret = phy_read(phydev, MII_BMCR);
|
|
|
+ if (ret < 0)
|
|
|
+ return ret;
|
|
|
+ } while (ret & BMCR_RESET && --retries);
|
|
|
+ if (ret & BMCR_RESET)
|
|
|
+ return -ETIMEDOUT;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Some chips (smsc911x) may still need up to another 1ms after the
|
|
|
+ * BMCR_RESET bit is cleared before they are usable.
|
|
|
+ */
|
|
|
+ msleep(1);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
int phy_init_hw(struct phy_device *phydev)
|
|
|
{
|
|
|
int ret;
|
|
|
@@ -504,12 +549,21 @@ int phy_init_hw(struct phy_device *phydev)
|
|
|
if (!phydev->drv || !phydev->drv->config_init)
|
|
|
return 0;
|
|
|
|
|
|
+ ret = phy_write(phydev, MII_BMCR, BMCR_RESET);
|
|
|
+ if (ret < 0)
|
|
|
+ return ret;
|
|
|
+
|
|
|
+ ret = phy_poll_reset(phydev);
|
|
|
+ if (ret < 0)
|
|
|
+ return ret;
|
|
|
+
|
|
|
ret = phy_scan_fixups(phydev);
|
|
|
if (ret < 0)
|
|
|
return ret;
|
|
|
|
|
|
return phydev->drv->config_init(phydev);
|
|
|
}
|
|
|
+EXPORT_SYMBOL(phy_init_hw);
|
|
|
|
|
|
/**
|
|
|
* phy_attach_direct - attach a network device to a given PHY device pointer
|
|
|
@@ -839,6 +893,8 @@ int genphy_read_status(struct phy_device *phydev)
|
|
|
if (err)
|
|
|
return err;
|
|
|
|
|
|
+ phydev->lp_advertising = 0;
|
|
|
+
|
|
|
if (AUTONEG_ENABLE == phydev->autoneg) {
|
|
|
if (phydev->supported & (SUPPORTED_1000baseT_Half
|
|
|
| SUPPORTED_1000baseT_Full)) {
|
|
|
@@ -852,6 +908,8 @@ int genphy_read_status(struct phy_device *phydev)
|
|
|
if (adv < 0)
|
|
|
return adv;
|
|
|
|
|
|
+ phydev->lp_advertising =
|
|
|
+ mii_stat1000_to_ethtool_lpa_t(lpagb);
|
|
|
lpagb &= adv << 2;
|
|
|
}
|
|
|
|
|
|
@@ -860,6 +918,8 @@ int genphy_read_status(struct phy_device *phydev)
|
|
|
if (lpa < 0)
|
|
|
return lpa;
|
|
|
|
|
|
+ phydev->lp_advertising |= mii_lpa_to_ethtool_lpa_t(lpa);
|
|
|
+
|
|
|
adv = phy_read(phydev, MII_ADVERTISE);
|
|
|
|
|
|
if (adv < 0)
|