From 4aec3028843cf6e3074fa61de9a91bd59471724a Mon Sep 17 00:00:00 2001 From: Marius Strobl Date: Sun, 7 Nov 2010 11:12:30 +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 r214685) 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/arm/xscale/ixp425/if_npe.c | 14 ++++----- sys/dev/ae/if_ae.c | 16 +++-------- sys/dev/ae/if_aevar.h | 1 - sys/dev/age/if_age.c | 12 ++++---- sys/dev/alc/if_alc.c | 14 ++++----- sys/dev/ale/if_ale.c | 14 ++++----- sys/dev/bfe/if_bfe.c | 13 ++++----- sys/dev/bge/if_bge.c | 18 +++++------- sys/dev/bge/if_bgereg.h | 1 - sys/dev/bm/if_bm.c | 18 ++++++++---- sys/dev/cas/if_cas.c | 37 ++++++++---------------- sys/dev/cas/if_casvar.h | 2 -- sys/dev/dc/if_dc.c | 64 +++++++++++++++++++----------------------- sys/dev/dc/pnphy.c | 3 +- sys/dev/fxp/if_fxp.c | 12 +++++--- sys/dev/gem/if_gem.c | 39 +++++++++++-------------- sys/dev/gem/if_gemvar.h | 2 -- sys/dev/hme/if_hme.c | 25 +++++++++-------- sys/dev/jme/if_jme.c | 26 ++++++----------- sys/dev/mii/acphy.c | 1 + sys/dev/mii/amphy.c | 1 + sys/dev/mii/atphy.c | 1 + sys/dev/mii/bmtphy.c | 1 + sys/dev/mii/brgphy.c | 1 + sys/dev/mii/ciphy.c | 5 ++-- sys/dev/mii/e1000phy.c | 18 ++++-------- sys/dev/mii/exphy.c | 1 + sys/dev/mii/gentbi.c | 1 + sys/dev/mii/icsphy.c | 1 + sys/dev/mii/inphy.c | 1 + sys/dev/mii/ip1000phy.c | 22 +++++---------- sys/dev/mii/jmphy.c | 1 + sys/dev/mii/lxtphy.c | 11 +------- sys/dev/mii/mlphy.c | 1 + sys/dev/mii/nsgphy.c | 1 + sys/dev/mii/nsphy.c | 27 ++++++------------ sys/dev/mii/nsphyter.c | 19 +++++-------- sys/dev/mii/pnaphy.c | 1 + sys/dev/mii/qsphy.c | 1 + sys/dev/mii/rgephy.c | 1 + sys/dev/mii/rlphy.c | 1 + sys/dev/mii/rlswitch.c | 1 + sys/dev/mii/ruephy.c | 1 + sys/dev/mii/tdkphy.c | 1 + sys/dev/mii/tlphy.c | 5 ++-- sys/dev/mii/truephy.c | 1 + sys/dev/mii/ukphy.c | 1 + sys/dev/mii/xmphy.c | 1 + sys/dev/msk/if_msk.c | 21 +++++++------- sys/dev/pcn/if_pcn.c | 13 +++++---- sys/dev/re/if_re.c | 28 ++++++++---------- sys/dev/sk/if_sk.c | 22 +++++++-------- sys/dev/ste/if_ste.c | 17 ++++++----- sys/dev/stge/if_stge.c | 13 ++++++--- sys/dev/vge/if_vge.c | 15 ++++------ sys/dev/vr/if_vr.c | 22 ++++++--------- sys/dev/vr/if_vrreg.h | 1 - sys/pci/if_rl.c | 23 +++++++-------- sys/pci/if_xl.c | 32 +++++++++------------ 59 files changed, 288 insertions(+), 379 deletions(-) diff --git a/sys/arm/xscale/ixp425/if_npe.c b/sys/arm/xscale/ixp425/if_npe.c index 44954f9cea44..f59cf59f6230 100644 --- a/sys/arm/xscale/ixp425/if_npe.c +++ b/sys/arm/xscale/ixp425/if_npe.c @@ -318,11 +318,13 @@ npe_attach(device_t dev) npe_getmac(sc, eaddr); - /* NB: must be setup prior to invoking mii code */ sc->sc_ifp = ifp = if_alloc(IFT_ETHER); - if (mii_phy_probe(dev, &sc->sc_mii, npe_ifmedia_update, npe_ifmedia_status)) { - device_printf(dev, "Cannot find my PHY.\n"); - error = ENXIO; + error = mii_attach(dev, &sc->sc_mii, ifp, npe_ifmedia_update, + npe_ifmedia_status, BMSR_DEFCAPMASK, sc->sc_phy, MII_OFFSET_ANY, + 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); + return error; goto out; } @@ -1596,8 +1598,6 @@ npe_miibus_readreg(device_t dev, int phy, int reg) struct npe_softc *sc = device_get_softc(dev); uint32_t v; - if (phy != sc->sc_phy) /* XXX no auto-detect */ - return 0xffff; v = (phy << NPE_MII_ADDR_SHL) | (reg << NPE_MII_REG_SHL) | NPE_MII_GO; npe_mii_mdio_write(sc, NPE_MAC_MDIO_CMD, v); @@ -1615,8 +1615,6 @@ npe_miibus_writereg(device_t dev, int phy, int reg, int data) struct npe_softc *sc = device_get_softc(dev); uint32_t v; - if (phy != sc->sc_phy) /* XXX */ - return; v = (phy << NPE_MII_ADDR_SHL) | (reg << NPE_MII_REG_SHL) | data | NPE_MII_WRITE | NPE_MII_GO; diff --git a/sys/dev/ae/if_ae.c b/sys/dev/ae/if_ae.c index 0c58277eef68..a26e08e973ca 100644 --- a/sys/dev/ae/if_ae.c +++ b/sys/dev/ae/if_ae.c @@ -360,9 +360,6 @@ ae_attach(device_t dev) if (error != 0) goto fail; - /* Set default PHY address. */ - sc->phyaddr = AE_PHYADDR_DEFAULT; - ifp = sc->ifp = if_alloc(IFT_ETHER); if (ifp == NULL) { device_printf(dev, "could not allocate ifnet structure.\n"); @@ -390,10 +387,11 @@ ae_attach(device_t dev) /* * Configure and attach MII bus. */ - error = mii_phy_probe(dev, &sc->miibus, ae_mediachange, - ae_mediastatus); + error = mii_attach(dev, &sc->miibus, ifp, ae_mediachange, + ae_mediastatus, BMSR_DEFCAPMASK, AE_PHYADDR_DEFAULT, + MII_OFFSET_ANY, 0); if (error != 0) { - device_printf(dev, "no PHY found.\n"); + device_printf(dev, "attaching PHYs failed\n"); goto fail; } @@ -813,9 +811,6 @@ ae_miibus_readreg(device_t dev, int phy, int reg) * Locking is done in upper layers. */ - if (phy != sc->phyaddr) - return (0); - val = ((reg << AE_MDIO_REGADDR_SHIFT) & AE_MDIO_REGADDR_MASK) | AE_MDIO_START | AE_MDIO_READ | AE_MDIO_SUP_PREAMBLE | ((AE_MDIO_CLK_25_4 << AE_MDIO_CLK_SHIFT) & AE_MDIO_CLK_MASK); @@ -851,9 +846,6 @@ ae_miibus_writereg(device_t dev, int phy, int reg, int val) * Locking is done in upper layers. */ - if (phy != sc->phyaddr) - return (0); - aereg = ((reg << AE_MDIO_REGADDR_SHIFT) & AE_MDIO_REGADDR_MASK) | AE_MDIO_START | AE_MDIO_SUP_PREAMBLE | ((AE_MDIO_CLK_25_4 << AE_MDIO_CLK_SHIFT) & AE_MDIO_CLK_MASK) | diff --git a/sys/dev/ae/if_aevar.h b/sys/dev/ae/if_aevar.h index eaef62e1f799..862340144d7f 100644 --- a/sys/dev/ae/if_aevar.h +++ b/sys/dev/ae/if_aevar.h @@ -111,7 +111,6 @@ typedef struct ae_softc { struct mtx mtx; - int phyaddr; uint8_t eaddr[ETHER_ADDR_LEN]; uint8_t flags; int if_flags; diff --git a/sys/dev/age/if_age.c b/sys/dev/age/if_age.c index 80430e5a8297..a7449052d40a 100644 --- a/sys/dev/age/if_age.c +++ b/sys/dev/age/if_age.c @@ -210,8 +210,6 @@ age_miibus_readreg(device_t dev, int phy, int reg) int i; sc = device_get_softc(dev); - if (phy != sc->age_phyaddr) - return (0); CSR_WRITE_4(sc, AGE_MDIO, MDIO_OP_EXECUTE | MDIO_OP_READ | MDIO_SUP_PREAMBLE | MDIO_CLK_25_4 | MDIO_REG_ADDR(reg)); @@ -241,8 +239,6 @@ age_miibus_writereg(device_t dev, int phy, int reg, int val) int i; sc = device_get_softc(dev); - if (phy != sc->age_phyaddr) - return (0); CSR_WRITE_4(sc, AGE_MDIO, MDIO_OP_EXECUTE | MDIO_OP_WRITE | (val & MDIO_DATA_MASK) << MDIO_DATA_SHIFT | @@ -621,9 +617,11 @@ age_attach(device_t dev) ifp->if_capenable = ifp->if_capabilities; /* Set up MII bus. */ - if ((error = mii_phy_probe(dev, &sc->age_miibus, age_mediachange, - age_mediastatus)) != 0) { - device_printf(dev, "no PHY found!\n"); + error = mii_attach(dev, &sc->age_miibus, ifp, age_mediachange, + age_mediastatus, BMSR_DEFCAPMASK, sc->age_phyaddr, MII_OFFSET_ANY, + 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/alc/if_alc.c b/sys/dev/alc/if_alc.c index 4d96aab19d41..17a5a69e9af5 100644 --- a/sys/dev/alc/if_alc.c +++ b/sys/dev/alc/if_alc.c @@ -235,9 +235,6 @@ alc_miibus_readreg(device_t dev, int phy, int reg) sc = device_get_softc(dev); - if (phy != sc->alc_phyaddr) - return (0); - /* * For AR8132 fast ethernet controller, do not report 1000baseT * capability to mii(4). Even though AR8132 uses the same @@ -274,9 +271,6 @@ alc_miibus_writereg(device_t dev, int phy, int reg, int val) sc = device_get_softc(dev); - if (phy != sc->alc_phyaddr) - return (0); - CSR_WRITE_4(sc, ALC_MDIO, MDIO_OP_EXECUTE | MDIO_OP_WRITE | (val & MDIO_DATA_MASK) << MDIO_DATA_SHIFT | MDIO_SUP_PREAMBLE | MDIO_CLK_25_4 | MDIO_REG_ADDR(reg)); @@ -978,9 +972,11 @@ alc_attach(device_t dev) ifp->if_capenable = ifp->if_capabilities; /* Set up MII bus. */ - if ((error = mii_phy_probe(dev, &sc->alc_miibus, alc_mediachange, - alc_mediastatus)) != 0) { - device_printf(dev, "no PHY found!\n"); + error = mii_attach(dev, &sc->alc_miibus, ifp, alc_mediachange, + alc_mediastatus, BMSR_DEFCAPMASK, sc->alc_phyaddr, MII_OFFSET_ANY, + 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/ale/if_ale.c b/sys/dev/ale/if_ale.c index 0a22ca1d8577..1282f5192054 100644 --- a/sys/dev/ale/if_ale.c +++ b/sys/dev/ale/if_ale.c @@ -208,9 +208,6 @@ ale_miibus_readreg(device_t dev, int phy, int reg) sc = device_get_softc(dev); - if (phy != sc->ale_phyaddr) - return (0); - CSR_WRITE_4(sc, ALE_MDIO, MDIO_OP_EXECUTE | MDIO_OP_READ | MDIO_SUP_PREAMBLE | MDIO_CLK_25_4 | MDIO_REG_ADDR(reg)); for (i = ALE_PHY_TIMEOUT; i > 0; i--) { @@ -237,9 +234,6 @@ ale_miibus_writereg(device_t dev, int phy, int reg, int val) sc = device_get_softc(dev); - if (phy != sc->ale_phyaddr) - return (0); - CSR_WRITE_4(sc, ALE_MDIO, MDIO_OP_EXECUTE | MDIO_OP_WRITE | (val & MDIO_DATA_MASK) << MDIO_DATA_SHIFT | MDIO_SUP_PREAMBLE | MDIO_CLK_25_4 | MDIO_REG_ADDR(reg)); @@ -605,9 +599,11 @@ ale_attach(device_t dev) ifp->if_capenable = ifp->if_capabilities; /* Set up MII bus. */ - if ((error = mii_phy_probe(dev, &sc->ale_miibus, ale_mediachange, - ale_mediastatus)) != 0) { - device_printf(dev, "no PHY found!\n"); + error = mii_attach(dev, &sc->ale_miibus, ifp, ale_mediachange, + ale_mediastatus, BMSR_DEFCAPMASK, sc->ale_phyaddr, MII_OFFSET_ANY, + 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/bfe/if_bfe.c b/sys/dev/bfe/if_bfe.c index 26d92bc346ea..83ec739d2445 100644 --- a/sys/dev/bfe/if_bfe.c +++ b/sys/dev/bfe/if_bfe.c @@ -498,10 +498,11 @@ bfe_attach(device_t dev) bfe_chip_reset(sc); BFE_UNLOCK(sc); - if (mii_phy_probe(dev, &sc->bfe_miibus, - bfe_ifmedia_upd, bfe_ifmedia_sts)) { - device_printf(dev, "MII without any PHY!\n"); - error = ENXIO; + error = mii_attach(dev, &sc->bfe_miibus, ifp, bfe_ifmedia_upd, + bfe_ifmedia_sts, BMSR_DEFCAPMASK, sc->bfe_phyaddr, MII_OFFSET_ANY, + 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } @@ -624,8 +625,6 @@ bfe_miibus_readreg(device_t dev, int phy, int reg) u_int32_t ret; sc = device_get_softc(dev); - if (phy != sc->bfe_phyaddr) - return (0); bfe_readphy(sc, reg, &ret); return (ret); @@ -637,8 +636,6 @@ bfe_miibus_writereg(device_t dev, int phy, int reg, int val) struct bfe_softc *sc; sc = device_get_softc(dev); - if (phy != sc->bfe_phyaddr) - return (0); bfe_writephy(sc, reg, val); return (0); diff --git a/sys/dev/bge/if_bge.c b/sys/dev/bge/if_bge.c index 5857d22e6acb..df6820cdf43f 100644 --- a/sys/dev/bge/if_bge.c +++ b/sys/dev/bge/if_bge.c @@ -782,10 +782,6 @@ bge_miibus_readreg(device_t dev, int phy, int reg) sc = device_get_softc(dev); - /* Prevent the probe from finding incorrect devices. */ - if (phy != sc->bge_phy_addr) - return (0); - /* Clear the autopoll bit if set, otherwise may trigger PCI errors. */ if ((sc->bge_mi_mode & BGE_MIMODE_AUTOPOLL) != 0) { CSR_WRITE_4(sc, BGE_MI_MODE, @@ -2572,7 +2568,7 @@ bge_attach(device_t dev) struct bge_softc *sc; uint32_t hwcfg = 0, misccfg; u_char eaddr[ETHER_ADDR_LEN]; - int error, msicount, reg, rid, trys; + int error, msicount, phy_addr, reg, rid, trys; sc = device_get_softc(dev); sc->bge_dev = dev; @@ -2605,7 +2601,7 @@ bge_attach(device_t dev) sc->bge_chiprev = BGE_CHIPREV(sc->bge_chipid); /* Set default PHY address. */ - sc->bge_phy_addr = 1; + phy_addr = 1; /* * Don't enable Ethernet@WireSpeed for the 5700, 5906, or the @@ -2972,17 +2968,17 @@ bge_attach(device_t dev) again: bge_asf_driver_up(sc); - if (mii_phy_probe(dev, &sc->bge_miibus, - bge_ifmedia_upd, bge_ifmedia_sts)) { + error = (mii_attach(dev, &sc->bge_miibus, ifp, + bge_ifmedia_upd, bge_ifmedia_sts, BMSR_DEFCAPMASK, + phy_addr, MII_OFFSET_ANY, 0)); + if (error != 0) { if (trys++ < 4) { device_printf(sc->bge_dev, "Try again\n"); bge_miibus_writereg(sc->bge_dev, 1, MII_BMCR, BMCR_RESET); goto again; } - - device_printf(sc->bge_dev, "MII without any PHY!\n"); - error = ENXIO; + device_printf(sc->bge_dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/bge/if_bgereg.h b/sys/dev/bge/if_bgereg.h index fc183157a50a..8a7f0784b68c 100644 --- a/sys/dev/bge/if_bgereg.h +++ b/sys/dev/bge/if_bgereg.h @@ -2762,7 +2762,6 @@ struct bge_softc { uint32_t bge_tx_buf_ratio; uint32_t bge_mi_mode; int bge_if_flags; - int bge_phy_addr; int bge_txcnt; int bge_link; /* link state */ int bge_link_evt; /* pending link event */ diff --git a/sys/dev/bm/if_bm.c b/sys/dev/bm/if_bm.c index b9bddb52a213..d406f68eb490 100644 --- a/sys/dev/bm/if_bm.c +++ b/sys/dev/bm/if_bm.c @@ -594,11 +594,19 @@ bm_attach(device_t dev) /* reset the adapter */ bm_chip_setup(sc); - /* setup MII */ - error = mii_phy_probe(dev, &sc->sc_miibus, bm_ifmedia_upd, - bm_ifmedia_sts); - if (error != 0) - device_printf(dev,"PHY probe failed: %d\n", error); + /* + * Setup MII + * On Apple BMAC controllers, we end up in a weird state of + * partially-completed autonegotiation on boot. So we force + * autonegotation to try again. + */ + error = mii_attach(dev, &sc->sc_miibus, ifp, bm_ifmedia_upd, + bm_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, + MIIF_FORCEANEG); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); + return (error); + } sc->sc_mii = device_get_softc(sc->sc_miibus); diff --git a/sys/dev/cas/if_cas.c b/sys/dev/cas/if_cas.c index c546aeaf021b..6774b5f44541 100644 --- a/sys/dev/cas/if_cas.c +++ b/sys/dev/cas/if_cas.c @@ -344,13 +344,9 @@ cas_attach(struct cas_softc *sc) BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); } - switch (sc->sc_variant) { - default: - sc->sc_phyad = -1; - break; - } - error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, - cas_mediachange, cas_mediastatus); + error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, + cas_mediachange, cas_mediastatus, BMSR_DEFCAPMASK, + MII_PHY_ANY, MII_OFFSET_ANY, 0); } /* * Fall back on an internal PHY if no external PHY was found. @@ -368,13 +364,9 @@ cas_attach(struct cas_softc *sc) BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); } - switch (sc->sc_variant) { - default: - sc->sc_phyad = -1; - break; - } - error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, - cas_mediachange, cas_mediastatus); + error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, + cas_mediachange, cas_mediastatus, BMSR_DEFCAPMASK, + MII_PHY_ANY, MII_OFFSET_ANY, 0); } } else { /* @@ -394,12 +386,12 @@ cas_attach(struct cas_softc *sc) CAS_WRITE_4(sc, CAS_PCS_CONF, CAS_PCS_CONF_EN); CAS_BARRIER(sc, CAS_PCS_CONF, 4, BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); - sc->sc_phyad = CAS_PHYAD_EXTERNAL; - error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, - cas_mediachange, cas_mediastatus); + error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, + cas_mediachange, cas_mediastatus, BMSR_DEFCAPMASK, + CAS_PHYAD_EXTERNAL, MII_OFFSET_ANY, 0); } if (error != 0) { - device_printf(sc->sc_dev, "PHY probe failed: %d\n", error); + device_printf(sc->sc_dev, "attaching PHYs failed\n"); goto fail_rxmap; } sc->sc_mii = device_get_softc(sc->sc_miibus); @@ -2172,9 +2164,6 @@ cas_mii_readreg(device_t dev, int phy, int reg) #endif sc = device_get_softc(dev); - if (sc->sc_phyad != -1 && phy != sc->sc_phyad) - return (0); - if ((sc->sc_flags & CAS_SERDES) != 0) { switch (reg) { case MII_BMCR: @@ -2233,9 +2222,6 @@ cas_mii_writereg(device_t dev, int phy, int reg, int val) #endif sc = device_get_softc(dev); - if (sc->sc_phyad != -1 && phy != sc->sc_phyad) - return (0); - if ((sc->sc_flags & CAS_SERDES) != 0) { switch (reg) { case MII_BMSR: @@ -2318,8 +2304,7 @@ cas_mii_statchg(device_t dev) #ifdef CAS_DEBUG if ((ifp->if_flags & IFF_DEBUG) != 0) - device_printf(sc->sc_dev, "%s: status change: PHY = %d\n", - __func__, sc->sc_phyad); + device_printf(sc->sc_dev, "%s: status changen", __func__); #endif if ((sc->sc_mii->mii_media_status & IFM_ACTIVE) != 0 && diff --git a/sys/dev/cas/if_casvar.h b/sys/dev/cas/if_casvar.h index e800f4e9f7b3..fa2e6af9fdef 100644 --- a/sys/dev/cas/if_casvar.h +++ b/sys/dev/cas/if_casvar.h @@ -154,8 +154,6 @@ struct cas_softc { bus_dma_tag_t sc_cdmatag; /* control data bus DMA tag */ bus_dmamap_t sc_dmamap; /* bus DMA handle */ - u_int sc_phyad; /* PHY to use or -1 for any */ - u_int sc_variant; #define CAS_UNKNOWN 0 /* don't know */ #define CAS_CAS 1 /* Sun Cassini */ diff --git a/sys/dev/dc/if_dc.c b/sys/dev/dc/if_dc.c index df28f4242b29..88fa13d49b08 100644 --- a/sys/dev/dc/if_dc.c +++ b/sys/dev/dc/if_dc.c @@ -779,26 +779,6 @@ dc_miibus_readreg(device_t dev, int phy, int reg) sc = device_get_softc(dev); bzero(&frame, sizeof(frame)); - /* - * Note: both the AL981 and AN983 have internal PHYs, - * however the AL981 provides direct access to the PHY - * registers while the AN983 uses a serial MII interface. - * The AN983's MII interface is also buggy in that you - * can read from any MII address (0 to 31), but only address 1 - * behaves normally. To deal with both cases, we pretend - * that the PHY is at MII address 1. - */ - if (DC_IS_ADMTEK(sc) && phy != DC_ADMTEK_PHYADDR) - return (0); - - /* - * Note: the ukphy probes of the RS7112 report a PHY at - * MII address 0 (possibly HomePNA?) and 1 (ethernet) - * so we only respond to correct one. - */ - if (DC_IS_CONEXANT(sc) && phy != DC_CONEXANT_PHYADDR) - return (0); - if (sc->dc_pmode != DC_PMODE_MII) { if (phy == (MII_NPHY - 1)) { switch (reg) { @@ -901,12 +881,6 @@ dc_miibus_writereg(device_t dev, int phy, int reg, int data) sc = device_get_softc(dev); bzero(&frame, sizeof(frame)); - if (DC_IS_ADMTEK(sc) && phy != DC_ADMTEK_PHYADDR) - return (0); - - if (DC_IS_CONEXANT(sc) && phy != DC_CONEXANT_PHYADDR) - return (0); - if (DC_IS_PNIC(sc)) { CSR_WRITE_4(sc, DC_PN_MII, DC_PN_MIIOPCODE_WRITE | (phy << 23) | (reg << 10) | data); @@ -1815,14 +1789,12 @@ dc_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error) static int dc_attach(device_t dev) { - int tmp = 0; uint32_t eaddr[(ETHER_ADDR_LEN+3)/4]; u_int32_t command; struct dc_softc *sc; struct ifnet *ifp; u_int32_t reg, revision; - int error = 0, rid, mac_offset; - int i; + int error, i, mac_offset, phy, rid, tmp; u_int8_t *mac; sc = device_get_softc(dev); @@ -2203,6 +2175,7 @@ dc_attach(device_t dev) * old selection (SIA only or SIA/SYM) and attach the dcphy * driver instead. */ + tmp = 0; if (DC_IS_INTEL(sc)) { dc_apply_fixup(sc, IFM_AUTO); tmp = sc->dc_pmode; @@ -2211,7 +2184,7 @@ dc_attach(device_t dev) /* * Setup General Purpose port mode and data so the tulip can talk - * to the MII. This needs to be done before mii_phy_probe so that + * to the MII. This needs to be done before mii_attach so that * we can actually see them. */ if (DC_IS_XIRCOM(sc)) { @@ -2223,16 +2196,37 @@ dc_attach(device_t dev) DELAY(10); } - error = mii_phy_probe(dev, &sc->dc_miibus, - dc_ifmedia_upd, dc_ifmedia_sts); + phy = MII_PHY_ANY; + /* + * Note: both the AL981 and AN983 have internal PHYs, however the + * AL981 provides direct access to the PHY registers while the AN983 + * uses a serial MII interface. The AN983's MII interface is also + * buggy in that you can read from any MII address (0 to 31), but + * only address 1 behaves normally. To deal with both cases, we + * pretend that the PHY is at MII address 1. + */ + if (DC_IS_ADMTEK(sc)) + phy = DC_ADMTEK_PHYADDR; + + /* + * Note: the ukphy probes of the RS7112 report a PHY at MII address + * 0 (possibly HomePNA?) and 1 (ethernet) so we only respond to the + * correct one. + */ + if (DC_IS_CONEXANT(sc)) + phy = DC_CONEXANT_PHYADDR; + + error = mii_attach(dev, &sc->dc_miibus, ifp, dc_ifmedia_upd, + dc_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); if (error && DC_IS_INTEL(sc)) { sc->dc_pmode = tmp; if (sc->dc_pmode != DC_PMODE_SIA) sc->dc_pmode = DC_PMODE_SYM; sc->dc_flags |= DC_21143_NWAY; - mii_phy_probe(dev, &sc->dc_miibus, - dc_ifmedia_upd, dc_ifmedia_sts); + mii_attach(dev, &sc->dc_miibus, ifp, dc_ifmedia_upd, + dc_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, + MII_OFFSET_ANY, 0); /* * For non-MII cards, we need to have the 21143 * drive the LEDs. Except there are some systems @@ -2247,7 +2241,7 @@ dc_attach(device_t dev) } if (error) { - device_printf(dev, "MII without any PHY!\n"); + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/dc/pnphy.c b/sys/dev/dc/pnphy.c index 570ee5fa0c64..15704b2aebb5 100644 --- a/sys/dev/dc/pnphy.c +++ b/sys/dev/dc/pnphy.c @@ -132,6 +132,7 @@ pnphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = pnphy_service; @@ -169,8 +170,6 @@ pnphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) if ((mii->mii_ifp->if_flags & IFF_UP) == 0) break; - sc->mii_flags = 0; - switch (IFM_SUBTYPE(ife->ifm_media)) { case IFM_AUTO: /* NWAY is busted on this chip */ diff --git a/sys/dev/fxp/if_fxp.c b/sys/dev/fxp/if_fxp.c index 6493395dbeb9..234d384e6fe4 100644 --- a/sys/dev/fxp/if_fxp.c +++ b/sys/dev/fxp/if_fxp.c @@ -805,10 +805,14 @@ fxp_attach(device_t dev) ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL); ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL); } else { - if (mii_phy_probe(dev, &sc->miibus, fxp_ifmedia_upd, - fxp_ifmedia_sts)) { - device_printf(dev, "MII without any PHY!\n"); - error = ENXIO; + /* + * i82557 wedge when isolating all of their PHYs. + */ + error = mii_attach(dev, &sc->miibus, ifp, fxp_ifmedia_upd, + fxp_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, + MII_OFFSET_ANY, MIIF_NOISOLATE); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } } diff --git a/sys/dev/gem/if_gem.c b/sys/dev/gem/if_gem.c index f8097fdfc9c0..0a397f56820a 100644 --- a/sys/dev/gem/if_gem.c +++ b/sys/dev/gem/if_gem.c @@ -149,7 +149,7 @@ gem_attach(struct gem_softc *sc) { struct gem_txsoft *txs; struct ifnet *ifp; - int error, i; + int error, i, phy; uint32_t v; if (bootverbose) @@ -294,14 +294,15 @@ gem_attach(struct gem_softc *sc) BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE); switch (sc->sc_variant) { case GEM_SUN_ERI: - sc->sc_phyad = GEM_PHYAD_EXTERNAL; + phy = GEM_PHYAD_EXTERNAL; break; default: - sc->sc_phyad = -1; + phy = MII_PHY_ANY; break; } - error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, - gem_mediachange, gem_mediastatus); + error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, + gem_mediachange, gem_mediastatus, BMSR_DEFCAPMASK, phy, + MII_OFFSET_ANY, 0); } /* @@ -318,17 +319,18 @@ gem_attach(struct gem_softc *sc) switch (sc->sc_variant) { case GEM_SUN_ERI: case GEM_APPLE_K2_GMAC: - sc->sc_phyad = GEM_PHYAD_INTERNAL; + phy = GEM_PHYAD_INTERNAL; break; case GEM_APPLE_GMAC: - sc->sc_phyad = GEM_PHYAD_EXTERNAL; + phy = GEM_PHYAD_EXTERNAL; break; default: - sc->sc_phyad = -1; + phy = MII_PHY_ANY; break; } - error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, - gem_mediachange, gem_mediastatus); + error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, + gem_mediachange, gem_mediastatus, BMSR_DEFCAPMASK, phy, + MII_OFFSET_ANY, 0); } /* @@ -348,12 +350,12 @@ gem_attach(struct gem_softc *sc) GEM_BANK1_BARRIER(sc, GEM_MII_CONFIG, 4, BUS_SPACE_BARRIER_WRITE); sc->sc_flags |= GEM_SERDES; - sc->sc_phyad = GEM_PHYAD_EXTERNAL; - error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, - gem_mediachange, gem_mediastatus); + error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, + gem_mediachange, gem_mediastatus, BMSR_DEFCAPMASK, + GEM_PHYAD_EXTERNAL, MII_OFFSET_ANY, 0); } if (error != 0) { - device_printf(sc->sc_dev, "PHY probe failed: %d\n", error); + device_printf(sc->sc_dev, "attaching PHYs failed\n"); goto fail_rxd; } sc->sc_mii = device_get_softc(sc->sc_miibus); @@ -1848,9 +1850,6 @@ gem_mii_readreg(device_t dev, int phy, int reg) #endif sc = device_get_softc(dev); - if (sc->sc_phyad != -1 && phy != sc->sc_phyad) - return (0); - if ((sc->sc_flags & GEM_SERDES) != 0) { switch (reg) { case MII_BMCR: @@ -1909,9 +1908,6 @@ gem_mii_writereg(device_t dev, int phy, int reg, int val) #endif sc = device_get_softc(dev); - if (sc->sc_phyad != -1 && phy != sc->sc_phyad) - return (0); - if ((sc->sc_flags & GEM_SERDES) != 0) { switch (reg) { case MII_BMSR: @@ -1992,8 +1988,7 @@ gem_mii_statchg(device_t dev) #ifdef GEM_DEBUG if ((sc->sc_ifp->if_flags & IFF_DEBUG) != 0) - device_printf(sc->sc_dev, "%s: status change: PHY = %d\n", - __func__, sc->sc_phyad); + device_printf(sc->sc_dev, "%s: status change\n", __func__); #endif if ((sc->sc_mii->mii_media_status & IFM_ACTIVE) != 0 && diff --git a/sys/dev/gem/if_gemvar.h b/sys/dev/gem/if_gemvar.h index ab5b2f6ea7f7..59cb58231023 100644 --- a/sys/dev/gem/if_gemvar.h +++ b/sys/dev/gem/if_gemvar.h @@ -126,8 +126,6 @@ struct gem_softc { bus_dma_tag_t sc_cdmatag; /* control data bus DMA tag */ bus_dmamap_t sc_dmamap; /* bus DMA handle */ - int sc_phyad; /* PHY to use or -1 for any */ - u_int sc_variant; #define GEM_UNKNOWN 0 /* don't know */ #define GEM_SUN_GEM 1 /* Sun GEM */ diff --git a/sys/dev/hme/if_hme.c b/sys/dev/hme/if_hme.c index 393bf2f6a7b5..abd441bdcb6e 100644 --- a/sys/dev/hme/if_hme.c +++ b/sys/dev/hme/if_hme.c @@ -315,9 +315,20 @@ hme_config(struct hme_softc *sc) hme_mifinit(sc); - if ((error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, hme_mediachange, - hme_mediastatus)) != 0) { - device_printf(sc->sc_dev, "phy probe failed: %d\n", error); + /* + * DP83840A used with HME chips don't advertise their media + * capabilities themselves properly so force writing the ANAR + * according to the BMSR in mii_phy_setmedia(). + */ + error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, hme_mediachange, + hme_mediastatus, BMSR_DEFCAPMASK, HME_PHYAD_EXTERNAL, + MII_OFFSET_ANY, MIIF_FORCEANEG); + i = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, hme_mediachange, + hme_mediastatus, BMSR_DEFCAPMASK, HME_PHYAD_INTERNAL, + MII_OFFSET_ANY, MIIF_FORCEANEG); + if (error != 0 && i != 0) { + error = ENXIO; + device_printf(sc->sc_dev, "attaching PHYs failed\n"); goto fail_rxdesc; } sc->sc_mii = device_get_softc(sc->sc_miibus); @@ -1404,10 +1415,6 @@ hme_mii_readreg(device_t dev, int phy, int reg) int n; u_int32_t v; - /* We can at most have two PHYs. */ - if (phy != HME_PHYAD_EXTERNAL && phy != HME_PHYAD_INTERNAL) - return (0); - sc = device_get_softc(dev); /* Select the desired PHY in the MIF configuration register */ v = HME_MIF_READ_4(sc, HME_MIFI_CFG); @@ -1445,10 +1452,6 @@ hme_mii_writereg(device_t dev, int phy, int reg, int val) int n; u_int32_t v; - /* We can at most have two PHYs. */ - if (phy != HME_PHYAD_EXTERNAL && phy != HME_PHYAD_INTERNAL) - return (0); - sc = device_get_softc(dev); /* Select the desired PHY in the MIF configuration register */ v = HME_MIF_READ_4(sc, HME_MIFI_CFG); diff --git a/sys/dev/jme/if_jme.c b/sys/dev/jme/if_jme.c index 6b257eec48d2..3cf8876ec500 100644 --- a/sys/dev/jme/if_jme.c +++ b/sys/dev/jme/if_jme.c @@ -224,13 +224,8 @@ jme_miibus_readreg(device_t dev, int phy, int reg) sc = device_get_softc(dev); /* For FPGA version, PHY address 0 should be ignored. */ - if ((sc->jme_flags & JME_FLAG_FPGA) != 0) { - if (phy == 0) - return (0); - } else { - if (sc->jme_phyaddr != phy) - return (0); - } + if ((sc->jme_flags & JME_FLAG_FPGA) != 0 && phy == 0) + return (0); CSR_WRITE_4(sc, JME_SMI, SMI_OP_READ | SMI_OP_EXECUTE | SMI_PHY_ADDR(phy) | SMI_REG_ADDR(reg)); @@ -260,13 +255,8 @@ jme_miibus_writereg(device_t dev, int phy, int reg, int val) sc = device_get_softc(dev); /* For FPGA version, PHY address 0 should be ignored. */ - if ((sc->jme_flags & JME_FLAG_FPGA) != 0) { - if (phy == 0) - return (0); - } else { - if (sc->jme_phyaddr != phy) - return (0); - } + if ((sc->jme_flags & JME_FLAG_FPGA) != 0 && phy == 0) + return (0); CSR_WRITE_4(sc, JME_SMI, SMI_OP_WRITE | SMI_OP_EXECUTE | ((val << SMI_DATA_SHIFT) & SMI_DATA_MASK) | @@ -751,9 +741,11 @@ jme_attach(device_t dev) ifp->if_capenable = ifp->if_capabilities; /* Set up MII bus. */ - if ((error = mii_phy_probe(dev, &sc->jme_miibus, jme_mediachange, - jme_mediastatus)) != 0) { - device_printf(dev, "no PHY found!\n"); + error = mii_attach(dev, &sc->jme_miibus, ifp, jme_mediachange, + jme_mediastatus, BMSR_DEFCAPMASK, sc->jme_phyaddr, MII_OFFSET_ANY, + 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/mii/acphy.c b/sys/dev/mii/acphy.c index 661bc9175885..7013dbfaa6e8 100644 --- a/sys/dev/mii/acphy.c +++ b/sys/dev/mii/acphy.c @@ -132,6 +132,7 @@ acphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = acphy_service; diff --git a/sys/dev/mii/amphy.c b/sys/dev/mii/amphy.c index a67c66c9cd98..010fe9066a80 100644 --- a/sys/dev/mii/amphy.c +++ b/sys/dev/mii/amphy.c @@ -109,6 +109,7 @@ amphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = amphy_service; diff --git a/sys/dev/mii/atphy.c b/sys/dev/mii/atphy.c index fd531adf2c10..41cd72cc4afe 100644 --- a/sys/dev/mii/atphy.c +++ b/sys/dev/mii/atphy.c @@ -113,6 +113,7 @@ atphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = atphy_service; diff --git a/sys/dev/mii/bmtphy.c b/sys/dev/mii/bmtphy.c index af1fe116aea5..63d1df1fb263 100644 --- a/sys/dev/mii/bmtphy.c +++ b/sys/dev/mii/bmtphy.c @@ -147,6 +147,7 @@ bmtphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = bmtphy_service; diff --git a/sys/dev/mii/brgphy.c b/sys/dev/mii/brgphy.c index 3ad512f3f2a4..826a3a07f4bc 100644 --- a/sys/dev/mii/brgphy.c +++ b/sys/dev/mii/brgphy.c @@ -191,6 +191,7 @@ brgphy_attach(device_t dev) LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); /* Initialize mii_softc structure */ + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = brgphy_service; diff --git a/sys/dev/mii/ciphy.c b/sys/dev/mii/ciphy.c index d665de6cc787..97f3cf9b28ea 100644 --- a/sys/dev/mii/ciphy.c +++ b/sys/dev/mii/ciphy.c @@ -57,9 +57,7 @@ __FBSDID("$FreeBSD$"); #include "miibus_if.h" #include -/* -#include -*/ + static int ciphy_probe(device_t); static int ciphy_attach(device_t); @@ -118,6 +116,7 @@ ciphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = ciphy_service; diff --git a/sys/dev/mii/e1000phy.c b/sys/dev/mii/e1000phy.c index 8df7859f869b..e763c21c4726 100644 --- a/sys/dev/mii/e1000phy.c +++ b/sys/dev/mii/e1000phy.c @@ -59,9 +59,6 @@ __FBSDID("$FreeBSD$"); #include "miidevs.h" #include -/* XXX */ -#include -#include #include "miibus_if.h" @@ -71,7 +68,6 @@ static int e1000phy_attach(device_t); struct e1000phy_softc { struct mii_softc mii_sc; int mii_model; - struct msk_mii_data *mmd; }; static device_method_t e1000phy_methods[] = { @@ -144,6 +140,7 @@ e1000phy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = e1000phy_service; @@ -151,14 +148,9 @@ e1000phy_attach(device_t dev) esc->mii_model = MII_MODEL(ma->mii_id2); ifp = sc->mii_pdata->mii_ifp; - if (strcmp(ifp->if_dname, "msk") == 0) { - /* XXX */ - esc->mmd = device_get_ivars( - device_get_parent(device_get_parent(dev))); - if (esc->mmd != NULL && - (esc->mmd->mii_flags & MIIF_HAVEFIBER) != 0) - sc->mii_flags |= MIIF_HAVEFIBER; - } + if (strcmp(ifp->if_dname, "msk") == 0 && + (sc->mii_flags & MIIF_MACPRIV0) != 0) + sc->mii_flags |= MIIF_PHYPRIV0; switch (esc->mii_model) { case MII_MODEL_MARVELL_E1011: @@ -214,7 +206,7 @@ e1000phy_reset(struct mii_softc *sc) reg &= ~E1000_SCR_MODE_MASK; reg |= E1000_SCR_MODE_1000BX; PHY_WRITE(sc, E1000_SCR, reg); - if (esc->mmd != NULL && esc->mmd->pmd == 'P') { + if ((sc->mii_flags & MIIF_MACPRIV0) != 0) { /* Set SIGDET polarity low for SFP module. */ PHY_WRITE(sc, E1000_EADR, 1); reg = PHY_READ(sc, E1000_SCR); diff --git a/sys/dev/mii/exphy.c b/sys/dev/mii/exphy.c index 02ed6442e918..a5b03dcd271e 100644 --- a/sys/dev/mii/exphy.c +++ b/sys/dev/mii/exphy.c @@ -138,6 +138,7 @@ exphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = exphy_service; diff --git a/sys/dev/mii/gentbi.c b/sys/dev/mii/gentbi.c index 49cfc676e921..ee08efed758f 100644 --- a/sys/dev/mii/gentbi.c +++ b/sys/dev/mii/gentbi.c @@ -166,6 +166,7 @@ gentbi_attach(device_t dev) MII_OUI(ma->mii_id1, ma->mii_id2), MII_MODEL(ma->mii_id2), MII_REV(ma->mii_id2)); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = gentbi_service; diff --git a/sys/dev/mii/icsphy.c b/sys/dev/mii/icsphy.c index cac9af52aacf..849a14b3c5de 100644 --- a/sys/dev/mii/icsphy.c +++ b/sys/dev/mii/icsphy.c @@ -141,6 +141,7 @@ icsphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = icsphy_service; diff --git a/sys/dev/mii/inphy.c b/sys/dev/mii/inphy.c index f6418f7d2094..6830b5adacb5 100644 --- a/sys/dev/mii/inphy.c +++ b/sys/dev/mii/inphy.c @@ -107,6 +107,7 @@ inphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = inphy_service; diff --git a/sys/dev/mii/ip1000phy.c b/sys/dev/mii/ip1000phy.c index 232e2805826b..b60fab6fc783 100644 --- a/sys/dev/mii/ip1000phy.c +++ b/sys/dev/mii/ip1000phy.c @@ -114,6 +114,7 @@ ip1000phy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = ip1000phy_service; @@ -123,6 +124,10 @@ ip1000phy_attach(device_t dev) isc->model = MII_MODEL(ma->mii_id2); isc->revision = MII_REV(ma->mii_id2); + if (isc->model == MII_MODEL_ICPLUS_IP1000A && + strcmp(mii->mii_ifp->if_dname, "stge") == 0 && + (sc->mii_flags & MIIF_MACPRIV0) != 0) + sc->mii_flags |= MIIF_PHYPRIV0; sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask; if (sc->mii_capabilities & BMSR_EXTSTAT) @@ -412,12 +417,8 @@ ip1000phy_load_dspcode(struct mii_softc *sc) static void ip1000phy_reset(struct mii_softc *sc) { - struct ip1000phy_softc *isc; - struct stge_softc *stge_sc; - struct mii_data *mii; uint32_t reg; - isc = (struct ip1000phy_softc *)sc; mii_phy_reset(sc); /* clear autoneg/full-duplex as we don't want it after reset */ @@ -425,15 +426,6 @@ ip1000phy_reset(struct mii_softc *sc) reg &= ~(IP1000PHY_BMCR_AUTOEN | IP1000PHY_BMCR_FDX); PHY_WRITE(sc, MII_BMCR, reg); - mii = sc->mii_pdata; - /* - * XXX There should be more general way to pass PHY specific - * data via mii interface. - */ - if (isc->model == MII_MODEL_ICPLUS_IP1000A && - strcmp(mii->mii_ifp->if_dname, "stge") == 0) { - stge_sc = mii->mii_ifp->if_softc; - if (stge_sc->sc_rev >= 0x40 && stge_sc->sc_rev <= 0x4e) - ip1000phy_load_dspcode(sc); - } + if ((sc->mii_flags & MIIF_PHYPRIV0) != 0) + ip1000phy_load_dspcode(sc); } diff --git a/sys/dev/mii/jmphy.c b/sys/dev/mii/jmphy.c index ae066c5fa06f..0b04d80dd068 100644 --- a/sys/dev/mii/jmphy.c +++ b/sys/dev/mii/jmphy.c @@ -112,6 +112,7 @@ jmphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = jmphy_service; diff --git a/sys/dev/mii/lxtphy.c b/sys/dev/mii/lxtphy.c index fc12ee6d5a89..44b40ff9cc46 100644 --- a/sys/dev/mii/lxtphy.c +++ b/sys/dev/mii/lxtphy.c @@ -127,7 +127,6 @@ lxtphy_attach(device_t dev) struct mii_softc *sc; struct mii_attach_args *ma; struct mii_data *mii; - const char *nic; sc = device_get_softc(dev); ma = device_get_ivars(dev); @@ -135,6 +134,7 @@ lxtphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = lxtphy_service; @@ -145,15 +145,6 @@ lxtphy_attach(device_t dev) sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask; device_printf(dev, " "); - /* - * On Apple BMAC controllers, we end up in a weird state - * of partially-completed autonegotiation on boot. So - * force autonegotation to try again. - */ - nic = device_get_name(device_get_parent(sc->mii_dev)); - if (strcmp(nic, "bm") == 0) - sc->mii_flags |= MIIF_FORCEANEG | MIIF_NOISOLATE; - #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst), MII_MEDIA_100_TX); diff --git a/sys/dev/mii/mlphy.c b/sys/dev/mii/mlphy.c index 5a2e42d97162..04e4b80f7129 100644 --- a/sys/dev/mii/mlphy.c +++ b/sys/dev/mii/mlphy.c @@ -146,6 +146,7 @@ mlphy_attach(dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = mlphy_service; diff --git a/sys/dev/mii/nsgphy.c b/sys/dev/mii/nsgphy.c index 6cfb40ffd03e..b3df8a205f81 100644 --- a/sys/dev/mii/nsgphy.c +++ b/sys/dev/mii/nsgphy.c @@ -129,6 +129,7 @@ nsgphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = nsgphy_service; diff --git a/sys/dev/mii/nsphy.c b/sys/dev/mii/nsphy.c index 21681f270eb8..af805cac2d31 100644 --- a/sys/dev/mii/nsphy.c +++ b/sys/dev/mii/nsphy.c @@ -133,6 +133,7 @@ nsphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = nsphy_service; @@ -140,34 +141,23 @@ nsphy_attach(device_t dev) nic = device_get_name(device_get_parent(sc->mii_dev)); /* - * Am79C971 and i82557 wedge when isolating all of their - * (external) PHYs. + * Am79C971 wedge when isolating all of their external PHYs. */ - if (strcmp(nic, "fxp") == 0 || strcmp(nic, "pcn") == 0) + if (strcmp(nic, "pcn") == 0) sc->mii_flags |= MIIF_NOISOLATE; - /* - * DP83840A used with HME chips don't advertise their media - * capabilities themselves properly so force writing the ANAR - * according to the BMSR in mii_phy_setmedia(). - */ - if (strcmp(nic, "hme") == 0) - sc->mii_flags |= MIIF_FORCEANEG; +#if 1 #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) /* - * In order for MII loopback to work Am79C971 and greater PCnet - * chips additionally need to be placed into external loopback - * mode which pcn(4) doesn't do so far. + * XXX IFM_LOOP should be handled by mii_phy_add_media() based + * on MIIF_NOLOOP. */ - if (strcmp(nic, "pcn") != 0) -#if 1 + if ((sc->mii_flags & MIIF_NOLOOP) == 0) ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst), MII_MEDIA_100_TX); -#else - if (strcmp(nic, "pcn") == 0) - sc->mii_flags |= MIIF_NOLOOP; + #endif nsphy_reset(sc); @@ -176,7 +166,6 @@ nsphy_attach(device_t dev) device_printf(dev, " "); mii_phy_add_media(sc); printf("\n"); -#undef ADD MIIBUS_MEDIAINIT(sc->mii_dev); return (0); diff --git a/sys/dev/mii/nsphyter.c b/sys/dev/mii/nsphyter.c index 6317a52ffb38..5489504d4d62 100644 --- a/sys/dev/mii/nsphyter.c +++ b/sys/dev/mii/nsphyter.c @@ -130,7 +130,6 @@ nsphyter_attach(device_t dev) struct mii_softc *sc; struct mii_attach_args *ma; struct mii_data *mii; - const char *nic; sc = device_get_softc(dev); ma = device_get_ivars(dev); @@ -138,26 +137,24 @@ nsphyter_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = nsphyter_service; sc->mii_pdata = mii; +#if 1 + #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) - nic = device_get_name(device_get_parent(sc->mii_dev)); /* - * In order for MII loopback to work Am79C971 and greater PCnet - * chips additionally need to be placed into external loopback - * mode which pcn(4) doesn't do so far. + * XXX IFM_LOOP should be handled by mii_phy_add_media() based + * on MIIF_NOLOOP. */ - if (strcmp(nic, "pcn") != 0) -#if 1 + if ((sc->mii_flags & MIIF_NOLOOP) == 0) ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst), MII_MEDIA_100_TX); -#else - if (strcmp(nic, "pcn") == 0) - sc->mii_flags |= MIIF_NOLOOP; + #endif nsphyter_reset(sc); @@ -167,8 +164,6 @@ nsphyter_attach(device_t dev) mii_phy_add_media(sc); printf("\n"); -#undef ADD - MIIBUS_MEDIAINIT(sc->mii_dev); return (0); } diff --git a/sys/dev/mii/pnaphy.c b/sys/dev/mii/pnaphy.c index 46e2eae6ffe3..69c41d66ee45 100644 --- a/sys/dev/mii/pnaphy.c +++ b/sys/dev/mii/pnaphy.c @@ -110,6 +110,7 @@ pnaphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = pnaphy_service; diff --git a/sys/dev/mii/qsphy.c b/sys/dev/mii/qsphy.c index f6cdd451a611..19fc77d5cd35 100644 --- a/sys/dev/mii/qsphy.c +++ b/sys/dev/mii/qsphy.c @@ -133,6 +133,7 @@ qsphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = qsphy_service; diff --git a/sys/dev/mii/rgephy.c b/sys/dev/mii/rgephy.c index c1d67038e82b..d1e0e51954e2 100644 --- a/sys/dev/mii/rgephy.c +++ b/sys/dev/mii/rgephy.c @@ -122,6 +122,7 @@ rgephy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = rgephy_service; diff --git a/sys/dev/mii/rlphy.c b/sys/dev/mii/rlphy.c index 368b6ca3cfea..eeaaaab6145e 100644 --- a/sys/dev/mii/rlphy.c +++ b/sys/dev/mii/rlphy.c @@ -141,6 +141,7 @@ rlphy_attach(device_t dev) LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = rlphy_service; diff --git a/sys/dev/mii/rlswitch.c b/sys/dev/mii/rlswitch.c index 1fda268f62ae..0c1b62f7458c 100644 --- a/sys/dev/mii/rlswitch.c +++ b/sys/dev/mii/rlswitch.c @@ -120,6 +120,7 @@ rlswitch_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = rlswitch_service; diff --git a/sys/dev/mii/ruephy.c b/sys/dev/mii/ruephy.c index f793c611bc3e..fc2a6b942f1f 100644 --- a/sys/dev/mii/ruephy.c +++ b/sys/dev/mii/ruephy.c @@ -111,6 +111,7 @@ ruephy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = ruephy_service; diff --git a/sys/dev/mii/tdkphy.c b/sys/dev/mii/tdkphy.c index 661c6d96dedb..9b285f75cae2 100644 --- a/sys/dev/mii/tdkphy.c +++ b/sys/dev/mii/tdkphy.c @@ -116,6 +116,7 @@ tdkphy_attach(device_t dev) MII_OUI(ma->mii_id1, ma->mii_id2), MII_MODEL(ma->mii_id2), MII_REV(ma->mii_id2)); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = tdkphy_service; diff --git a/sys/dev/mii/tlphy.c b/sys/dev/mii/tlphy.c index b425c764384f..e618611d8b03 100644 --- a/sys/dev/mii/tlphy.c +++ b/sys/dev/mii/tlphy.c @@ -144,12 +144,13 @@ tlphy_attach(device_t dev) mii = device_get_softc(sc->sc_mii.mii_dev); LIST_INSERT_HEAD(&mii->mii_phys, &sc->sc_mii, mii_list); + sc->sc_mii.mii_flags = miibus_get_flags(dev); sc->sc_mii.mii_inst = mii->mii_instance; sc->sc_mii.mii_phy = ma->mii_phyno; sc->sc_mii.mii_service = tlphy_service; sc->sc_mii.mii_pdata = mii; - capmask = 0xFFFFFFFF; + capmask = BMSR_DEFCAPMASK; if (mii->mii_instance && device_get_children(sc->sc_mii.mii_dev, &devlist, &devs) == 0) { for (i = 0; i < devs; i++) { @@ -174,7 +175,7 @@ tlphy_attach(device_t dev) * the TLPHY_MEDIA_NO_10_T bit. */ sc->sc_mii.mii_capabilities = - PHY_READ(&sc->sc_mii, MII_BMSR) & capmask /*ma->mii_capmask*/; + PHY_READ(&sc->sc_mii, MII_BMSR) & capmask; #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) diff --git a/sys/dev/mii/truephy.c b/sys/dev/mii/truephy.c index c83398383dd6..bb99df283f4b 100644 --- a/sys/dev/mii/truephy.c +++ b/sys/dev/mii/truephy.c @@ -151,6 +151,7 @@ truephy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = truephy_service; diff --git a/sys/dev/mii/ukphy.c b/sys/dev/mii/ukphy.c index 75d613263076..05b1b45b05ab 100644 --- a/sys/dev/mii/ukphy.c +++ b/sys/dev/mii/ukphy.c @@ -130,6 +130,7 @@ ukphy_attach(device_t dev) MII_OUI(ma->mii_id1, ma->mii_id2), MII_MODEL(ma->mii_id2), MII_REV(ma->mii_id2)); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = ukphy_service; diff --git a/sys/dev/mii/xmphy.c b/sys/dev/mii/xmphy.c index 582f8645d013..745c7b33718f 100644 --- a/sys/dev/mii/xmphy.c +++ b/sys/dev/mii/xmphy.c @@ -110,6 +110,7 @@ xmphy_attach(device_t dev) mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); + sc->mii_flags = miibus_get_flags(dev); sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_service = xmphy_service; diff --git a/sys/dev/msk/if_msk.c b/sys/dev/msk/if_msk.c index 4cf7ebb52dc7..c50c35d42b97 100644 --- a/sys/dev/msk/if_msk.c +++ b/sys/dev/msk/if_msk.c @@ -399,9 +399,6 @@ msk_miibus_readreg(device_t dev, int phy, int reg) { struct msk_if_softc *sc_if; - if (phy != PHY_ADDR_MARV) - return (0); - sc_if = device_get_softc(dev); return (msk_phy_readreg(sc_if, phy, reg)); @@ -440,9 +437,6 @@ msk_miibus_writereg(device_t dev, int phy, int reg, int val) { struct msk_if_softc *sc_if; - if (phy != PHY_ADDR_MARV) - return (0); - sc_if = device_get_softc(dev); return (msk_phy_writereg(sc_if, phy, reg, val)); @@ -1571,10 +1565,11 @@ msk_attach(device_t dev) * Do miibus setup. */ MSK_IF_UNLOCK(sc_if); - error = mii_phy_probe(dev, &sc_if->msk_miibus, msk_mediachange, - msk_mediastatus); + error = mii_attach(dev, &sc_if->msk_miibus, ifp, msk_mediachange, + msk_mediastatus, BMSR_DEFCAPMASK, PHY_ADDR_MARV, MII_OFFSET_ANY, + mmd->mii_flags); if (error != 0) { - device_printf(sc_if->msk_if_dev, "no PHY found!\n"); + device_printf(sc_if->msk_if_dev, "attaching PHYs failed\n"); ether_ifdetach(ifp); error = ENXIO; goto fail; @@ -1815,8 +1810,10 @@ mskc_attach(device_t dev) } mmd->port = MSK_PORT_A; mmd->pmd = sc->msk_pmd; - if (sc->msk_pmd == 'L' || sc->msk_pmd == 'S' || sc->msk_pmd == 'P') + if (sc->msk_pmd == 'L' || sc->msk_pmd == 'S') mmd->mii_flags |= MIIF_HAVEFIBER; + if (sc->msk_pmd == 'P') + mmd->mii_flags |= MIIF_HAVEFIBER | MIIF_MACPRIV0; device_set_ivars(sc->msk_devs[MSK_PORT_A], mmd); if (sc->msk_num_port > 1) { @@ -1835,8 +1832,10 @@ mskc_attach(device_t dev) } mmd->port = MSK_PORT_B; mmd->pmd = sc->msk_pmd; - if (sc->msk_pmd == 'L' || sc->msk_pmd == 'S' || sc->msk_pmd == 'P') + if (sc->msk_pmd == 'L' || sc->msk_pmd == 'S') mmd->mii_flags |= MIIF_HAVEFIBER; + if (sc->msk_pmd == 'P') + mmd->mii_flags |= MIIF_HAVEFIBER | MIIF_MACPRIV0; device_set_ivars(sc->msk_devs[MSK_PORT_B], mmd); } diff --git a/sys/dev/pcn/if_pcn.c b/sys/dev/pcn/if_pcn.c index 97d2a4957a19..45bfc9b774e3 100644 --- a/sys/dev/pcn/if_pcn.c +++ b/sys/dev/pcn/if_pcn.c @@ -635,13 +635,16 @@ pcn_attach(dev) ifp->if_snd.ifq_maxlen = PCN_TX_LIST_CNT - 1; /* - * Do MII setup. + * Do MII setup. Note that loopback support isn't implemented. + * See the comment in pcn_miibus_readreg() for why we can't + * universally pass MIIF_NOISOLATE here. */ sc->pcn_extphyaddr = -1; - if (mii_phy_probe(dev, &sc->pcn_miibus, - pcn_ifmedia_upd, pcn_ifmedia_sts)) { - device_printf(dev, "MII without any PHY!\n"); - error = ENXIO; + error = mii_attach(dev, &sc->pcn_miibus, ifp, pcn_ifmedia_upd, + pcn_ifmedia_sts, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, + MIIF_NOLOOP); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } /* diff --git a/sys/dev/re/if_re.c b/sys/dev/re/if_re.c index 453bdc80a9ca..45af419ffb64 100644 --- a/sys/dev/re/if_re.c +++ b/sys/dev/re/if_re.c @@ -410,9 +410,6 @@ re_gmii_readreg(device_t dev, int phy, int reg) u_int32_t rval; int i; - if (phy != 1) - return (0); - sc = device_get_softc(dev); /* Let the rgephy driver read the GMEDIASTAT register */ @@ -482,10 +479,6 @@ re_miibus_readreg(device_t dev, int phy, int reg) return (rval); } - /* Pretend the internal PHY is only at address 0 */ - if (phy) { - return (0); - } switch (reg) { case MII_BMCR: re8139_reg = RL_BMCR; @@ -540,10 +533,6 @@ re_miibus_writereg(device_t dev, int phy, int reg, int data) return (rval); } - /* Pretend the internal PHY is only at address 0 */ - if (phy) - return (0); - switch (reg) { case MII_BMCR: re8139_reg = RL_BMCR; @@ -1109,7 +1098,7 @@ re_attach(device_t dev) struct rl_hwrev *hw_rev; int hwrev; u_int16_t devid, re_did = 0; - int error = 0, rid, i; + int error = 0, i, phy, rid; int msic, reg; uint8_t cfg; @@ -1408,11 +1397,16 @@ re_attach(device_t dev) re_gmii_writereg(dev, 1, 0x0e, 0); } - /* Do MII setup */ - if (mii_phy_probe(dev, &sc->rl_miibus, - re_ifmedia_upd, re_ifmedia_sts)) { - device_printf(dev, "MII without any phy!\n"); - error = ENXIO; +#define RE_PHYAD_INTERNAL 0 + + /* Do MII setup. */ + phy = RE_PHYAD_INTERNAL; + if (sc->rl_type == RL_8169) + phy = 1; + error = mii_attach(dev, &sc->rl_miibus, ifp, re_ifmedia_upd, + re_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/sk/if_sk.c b/sys/dev/sk/if_sk.c index d861b57143b9..b5d770ab6e97 100644 --- a/sys/dev/sk/if_sk.c +++ b/sys/dev/sk/if_sk.c @@ -545,9 +545,6 @@ sk_xmac_miibus_readreg(sc_if, phy, reg) { int i; - if (sc_if->sk_phytype == SK_PHYTYPE_XMAC && phy != 0) - return(0); - SK_XM_WRITE_2(sc_if, XM_PHY_ADDR, reg|(phy << 8)); SK_XM_READ_2(sc_if, XM_PHY_DATA); if (sc_if->sk_phytype != SK_PHYTYPE_XMAC) { @@ -628,9 +625,8 @@ sk_marv_miibus_readreg(sc_if, phy, reg) u_int16_t val; int i; - if (phy != 0 || - (sc_if->sk_phytype != SK_PHYTYPE_MARV_COPPER && - sc_if->sk_phytype != SK_PHYTYPE_MARV_FIBER)) { + if (sc_if->sk_phytype != SK_PHYTYPE_MARV_COPPER && + sc_if->sk_phytype != SK_PHYTYPE_MARV_FIBER) { return(0); } @@ -1323,7 +1319,7 @@ sk_attach(dev) struct sk_softc *sc; struct sk_if_softc *sc_if; struct ifnet *ifp; - int i, port, error; + int error, i, phy, port; u_char eaddr[6]; if (dev == NULL) @@ -1498,23 +1494,27 @@ sk_attach(dev) /* * Do miibus setup. */ + phy = MII_PHY_ANY; switch (sc->sk_type) { case SK_GENESIS: sk_init_xmac(sc_if); + if (sc_if->sk_phytype == SK_PHYTYPE_XMAC) + phy = 0; break; case SK_YUKON: case SK_YUKON_LITE: case SK_YUKON_LP: sk_init_yukon(sc_if); + phy = 0; break; } SK_IF_UNLOCK(sc_if); - if (mii_phy_probe(dev, &sc_if->sk_miibus, - sk_ifmedia_upd, sk_ifmedia_sts)) { - device_printf(sc_if->sk_if_dev, "no PHY found!\n"); + error = mii_attach(dev, &sc_if->sk_miibus, ifp, sk_ifmedia_upd, + sk_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); + if (error != 0) { + device_printf(sc_if->sk_if_dev, "attaching PHYs failed\n"); ether_ifdetach(ifp); - error = ENXIO; goto fail; } diff --git a/sys/dev/ste/if_ste.c b/sys/dev/ste/if_ste.c index 0ddf18d3fe29..c241a1a84a21 100644 --- a/sys/dev/ste/if_ste.c +++ b/sys/dev/ste/if_ste.c @@ -369,10 +369,6 @@ ste_miibus_readreg(device_t dev, int phy, int reg) struct ste_mii_frame frame; sc = device_get_softc(dev); - - if ((sc->ste_flags & STE_FLAG_ONE_PHY) != 0 && phy != 0) - return (0); - bzero((char *)&frame, sizeof(frame)); frame.mii_phyaddr = phy; @@ -1053,7 +1049,7 @@ ste_attach(device_t dev) struct ste_softc *sc; struct ifnet *ifp; uint16_t eaddr[ETHER_ADDR_LEN / 2]; - int error = 0, pmc, prefer_iomap, rid; + int error = 0, phy, pmc, prefer_iomap, rid; sc = device_get_softc(dev); sc->ste_dev = dev; @@ -1142,10 +1138,13 @@ ste_attach(device_t dev) } /* Do MII setup. */ - if (mii_phy_probe(dev, &sc->ste_miibus, - ste_ifmedia_upd, ste_ifmedia_sts)) { - device_printf(dev, "MII without any phy!\n"); - error = ENXIO; + phy = MII_PHY_ANY; + if ((sc->ste_flags & STE_FLAG_ONE_PHY) != 0) + phy = 0; + error = mii_attach(dev, &sc->ste_miibus, ifp, ste_ifmedia_upd, + ste_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/stge/if_stge.c b/sys/dev/stge/if_stge.c index de23b878a11b..4583be1893a1 100644 --- a/sys/dev/stge/if_stge.c +++ b/sys/dev/stge/if_stge.c @@ -583,7 +583,7 @@ stge_attach(device_t dev) struct stge_softc *sc; struct ifnet *ifp; uint8_t enaddr[ETHER_ADDR_LEN]; - int error, i; + int error, flags, i; uint16_t cmd; uint32_t val; @@ -747,9 +747,14 @@ stge_attach(device_t dev) (PC_PhyDuplexPolarity | PC_PhyLnkPolarity); /* Set up MII bus. */ - if ((error = mii_phy_probe(sc->sc_dev, &sc->sc_miibus, stge_mediachange, - stge_mediastatus)) != 0) { - device_printf(sc->sc_dev, "no PHY found!\n"); + flags = 0; + if (sc->sc_rev >= 0x40 && sc->sc_rev <= 0x4e) + flags |= MIIF_MACPRIV0; + error = mii_attach(sc->sc_dev, &sc->sc_miibus, ifp, stge_mediachange, + stge_mediastatus, BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, + flags); + if (error != 0) { + device_printf(sc->sc_dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/vge/if_vge.c b/sys/dev/vge/if_vge.c index d3238078ff03..d244b39ad2ac 100644 --- a/sys/dev/vge/if_vge.c +++ b/sys/dev/vge/if_vge.c @@ -369,9 +369,6 @@ vge_miibus_readreg(device_t dev, int phy, int reg) sc = device_get_softc(dev); - if (phy != sc->vge_phyaddr) - return (0); - vge_miipoll_stop(sc); /* Specify the register we want to read. */ @@ -405,9 +402,6 @@ vge_miibus_writereg(device_t dev, int phy, int reg, int data) sc = device_get_softc(dev); - if (phy != sc->vge_phyaddr) - return (0); - vge_miipoll_stop(sc); /* Specify the register we want to write. */ @@ -1094,10 +1088,11 @@ vge_attach(device_t dev) } /* Do MII setup */ - if (mii_phy_probe(dev, &sc->vge_miibus, - vge_ifmedia_upd, vge_ifmedia_sts)) { - device_printf(dev, "MII without any phy!\n"); - error = ENXIO; + error = mii_attach(dev, &sc->vge_miibus, ifp, vge_ifmedia_upd, + vge_ifmedia_sts, BMSR_DEFCAPMASK, sc->vge_phyaddr, MII_OFFSET_ANY, + 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/vr/if_vr.c b/sys/dev/vr/if_vr.c index 2b975fa5024a..38aa555e2ccd 100644 --- a/sys/dev/vr/if_vr.c +++ b/sys/dev/vr/if_vr.c @@ -249,8 +249,6 @@ vr_miibus_readreg(device_t dev, int phy, int reg) int i; sc = device_get_softc(dev); - if (sc->vr_phyaddr != phy) - return (0); /* Set the register address. */ CSR_WRITE_1(sc, VR_MIIADDR, reg); @@ -274,8 +272,6 @@ vr_miibus_writereg(device_t dev, int phy, int reg, int data) int i; sc = device_get_softc(dev); - if (sc->vr_phyaddr != phy) - return (0); /* Set the register address and data to write. */ CSR_WRITE_1(sc, VR_MIIADDR, reg); @@ -613,7 +609,7 @@ vr_attach(device_t dev) struct vr_type *t; uint8_t eaddr[ETHER_ADDR_LEN]; int error, rid; - int i, pmc; + int i, phy, pmc; sc = device_get_softc(dev); sc->vr_dev = dev; @@ -780,17 +776,15 @@ vr_attach(device_t dev) goto fail; } - /* Save PHY address. */ + /* Do MII setup. */ if (sc->vr_revid >= REV_ID_VT6105_A0) - sc->vr_phyaddr = 1; + phy = 1; else - sc->vr_phyaddr = CSR_READ_1(sc, VR_PHYADDR) & VR_PHYADDR_MASK; - - /* Do MII setup. */ - if (mii_phy_probe(dev, &sc->vr_miibus, - vr_ifmedia_upd, vr_ifmedia_sts)) { - device_printf(dev, "MII without any phy!\n"); - error = ENXIO; + phy = CSR_READ_1(sc, VR_PHYADDR) & VR_PHYADDR_MASK; + error = mii_attach(dev, &sc->vr_miibus, ifp, vr_ifmedia_upd, + vr_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/dev/vr/if_vrreg.h b/sys/dev/vr/if_vrreg.h index 9c85962916c2..d686bddb240c 100644 --- a/sys/dev/vr/if_vrreg.h +++ b/sys/dev/vr/if_vrreg.h @@ -722,7 +722,6 @@ struct vr_softc { uint8_t vr_revid; /* Rhine chip revision */ uint8_t vr_flags; /* See VR_F_* below */ #define VR_F_RESTART 0x01 /* Restart unit on next tick */ - int vr_phyaddr; int vr_if_flags; struct task vr_link_task; struct vr_chain_data vr_cdata; diff --git a/sys/pci/if_rl.c b/sys/pci/if_rl.c index 20e9c86c45ec..d6defa8c3c20 100644 --- a/sys/pci/if_rl.c +++ b/sys/pci/if_rl.c @@ -519,10 +519,6 @@ rl_miibus_readreg(device_t dev, int phy, int reg) sc = device_get_softc(dev); if (sc->rl_type == RL_8139) { - /* Pretend the internal PHY is only at address 0 */ - if (phy) { - return (0); - } switch (reg) { case MII_BMCR: rl8139_reg = RL_BMCR; @@ -577,10 +573,6 @@ rl_miibus_writereg(device_t dev, int phy, int reg, int data) sc = device_get_softc(dev); if (sc->rl_type == RL_8139) { - /* Pretend the internal PHY is only at address 0 */ - if (phy) { - return (0); - } switch (reg) { case MII_BMCR: rl8139_reg = RL_BMCR; @@ -784,7 +776,7 @@ rl_attach(device_t dev) struct rl_type *t; struct sysctl_ctx_list *ctx; struct sysctl_oid_list *children; - int error = 0, hwrev, i, pmc, rid; + int error = 0, hwrev, i, phy, pmc, rid; int prefer_iomap, unit; uint16_t rl_did = 0; char tn[32]; @@ -924,11 +916,16 @@ rl_attach(device_t dev) goto fail; } +#define RL_PHYAD_INTERNAL 0 + /* Do MII setup */ - if (mii_phy_probe(dev, &sc->rl_miibus, - rl_ifmedia_upd, rl_ifmedia_sts)) { - device_printf(dev, "MII without any phy!\n"); - error = ENXIO; + phy = MII_PHY_ANY; + if (sc->rl_type == RL_8139) + phy = RL_PHYAD_INTERNAL; + error = mii_attach(dev, &sc->rl_miibus, ifp, rl_ifmedia_upd, + rl_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } diff --git a/sys/pci/if_xl.c b/sys/pci/if_xl.c index 65143744f962..7d0520d9de84 100644 --- a/sys/pci/if_xl.c +++ b/sys/pci/if_xl.c @@ -527,16 +527,6 @@ xl_miibus_readreg(device_t dev, int phy, int reg) sc = device_get_softc(dev); - /* - * Pretend that PHYs are only available at MII address 24. - * This is to guard against problems with certain 3Com ASIC - * revisions that incorrectly map the internal transceiver - * control registers at all MII addresses. This can cause - * the miibus code to attach the same PHY several times over. - */ - if ((sc->xl_flags & XL_FLAG_PHYOK) == 0 && phy != 24) - return (0); - bzero((char *)&frame, sizeof(frame)); frame.mii_phyaddr = phy; frame.mii_regaddr = reg; @@ -554,9 +544,6 @@ xl_miibus_writereg(device_t dev, int phy, int reg, int data) sc = device_get_softc(dev); - if ((sc->xl_flags & XL_FLAG_PHYOK) == 0 && phy != 24) - return (0); - bzero((char *)&frame, sizeof(frame)); frame.mii_phyaddr = phy; frame.mii_regaddr = reg; @@ -1154,7 +1141,7 @@ xl_attach(device_t dev) struct xl_softc *sc; struct ifnet *ifp; int media, pmcap; - int unit, error = 0, rid, res; + int error = 0, phy, rid, res, unit; uint16_t did; sc = device_get_softc(dev); @@ -1472,10 +1459,19 @@ xl_attach(device_t dev) if (bootverbose) device_printf(dev, "found MII/AUTO\n"); xl_setcfg(sc); - if (mii_phy_probe(dev, &sc->xl_miibus, - xl_ifmedia_upd, xl_ifmedia_sts)) { - device_printf(dev, "no PHY found!\n"); - error = ENXIO; + /* + * Attach PHYs only at MII address 24 if !XL_FLAG_PHYOK. + * This is to guard against problems with certain 3Com ASIC + * revisions that incorrectly map the internal transceiver + * control registers at all MII addresses. + */ + phy = MII_PHY_ANY; + if ((sc->xl_flags & XL_FLAG_PHYOK) == 0) + phy = 24; + error = mii_attach(dev, &sc->xl_miibus, ifp, xl_ifmedia_upd, + xl_ifmedia_sts, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto fail; } goto done; -- cgit v1.3