From 605d4f8b84e727c542eec73fceec034384cb7d5e Mon Sep 17 00:00:00 2001 From: Marius Strobl Date: Sun, 7 Nov 2010 11:12:29 +0000 Subject: MFC: r213893, r213908, r214566, r214605, r214846 Convert the PHY drivers to honor the mii_flags passed down and convert the NIC drivers as well as the PHY drivers to take advantage of the mii_attach() introduced in r213878 (MFC'ed to stable/8 in r214684) to get rid of certain hacks. For the most part these were: - Artificially limiting miibus_{read,write}reg methods to certain PHY addresses; we now let mii_attach() only probe the PHY at the desired address(es) instead. - PHY drivers setting MIIF_* flags based on the NIC driver they hang off from, partly even based on grabbing and using the softc of the parent; we now pass these flags down from the NIC to the PHY drivers via mii_attach(). This got us rid of all such hacks except those of brgphy() in combination with bce(4) and bge(4), which is way beyond what can be expressed with simple flags. While at it, I took the opportunity to change the NIC drivers to pass up the error returned by mii_attach() (previously by mii_phy_probe()) and unify the error message used in this case where and as appropriate as mii_attach() actually can fail for a number of reasons, not just because of no PHY(s) being present at the expected address(es). Reviewed by: jhb, yongari --- sys/dev/mge/if_mge.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'sys/dev/mge') diff --git a/sys/dev/mge/if_mge.c b/sys/dev/mge/if_mge.c index d36ce099ae6a..1b119b9e91a3 100644 --- a/sys/dev/mge/if_mge.c +++ b/sys/dev/mge/if_mge.c @@ -608,7 +608,7 @@ mge_attach(device_t dev) struct mge_softc *sc; struct ifnet *ifp; uint8_t hwaddr[ETHER_ADDR_LEN]; - int i, error ; + int i, error, phy; sc = device_get_softc(dev); sc->dev = dev; @@ -619,6 +619,13 @@ mge_attach(device_t dev) /* Set chip version-dependent parameters */ mge_ver_params(sc); + /* + * We assume static PHY address <=> device unit mapping: + * PHY Address = MII_ADDR_BASE + devce unit. + * This is true for most Marvell boards. + */ + phy = MII_ADDR_BASE + device_get_unit(dev); + /* Initialize mutexes */ mtx_init(&sc->transmit_lock, device_get_nameunit(dev), "mge TX lock", MTX_DEF); mtx_init(&sc->receive_lock, device_get_nameunit(dev), "mge RX lock", MTX_DEF); @@ -680,10 +687,11 @@ mge_attach(device_t dev) ether_ifattach(ifp, hwaddr); callout_init(&sc->wd_callout, 0); - /* Probe PHY(s) */ - error = mii_phy_probe(dev, &sc->miibus, mge_ifmedia_upd, mge_ifmedia_sts); + /* Attach PHY(s) */ + error = mii_attach(dev, &sc->miibus, ifp, mge_ifmedia_upd, + mge_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); if (error) { - device_printf(dev, "MII failed to find PHY\n"); + device_printf(dev, "attaching PHYs failed\n"); if_free(ifp); sc->ifp = NULL; mge_detach(dev); @@ -1259,19 +1267,6 @@ mge_miibus_readreg(device_t dev, int phy, int reg) { uint32_t retries; - /* - * We assume static PHY address <=> device unit mapping: - * PHY Address = MII_ADDR_BASE + devce unit. - * This is true for most Marvell boards. - * - * Code below grants proper PHY detection on each device - * unit. - */ - - - if ((MII_ADDR_BASE + device_get_unit(dev)) != phy) - return (0); - MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff & (MGE_SMI_READ | (reg << 21) | (phy << 16))); @@ -1290,9 +1285,6 @@ mge_miibus_writereg(device_t dev, int phy, int reg, int value) { uint32_t retries; - if ((MII_ADDR_BASE + device_get_unit(dev)) != phy) - return (0); - MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff & (MGE_SMI_WRITE | (reg << 21) | (phy << 16) | (value & 0xffff))); -- cgit v1.3