diff options
author | Marius Strobl <marius@FreeBSD.org> | 2010-10-15 14:52:11 +0000 |
---|---|---|
committer | Marius Strobl <marius@FreeBSD.org> | 2010-10-15 14:52:11 +0000 |
commit | 8e5d93dbb40452863b266a378868255bf986af67 (patch) | |
tree | 6dd0ca5b178547c1f20c8ce1f607ac42d4afe2ae | |
parent | d1457e3703928a249a45a6dd996918bc7eb6ba20 (diff) | |
download | src-8e5d93dbb40452863b266a378868255bf986af67.tar.gz src-8e5d93dbb40452863b266a378868255bf986af67.zip |
Notes
67 files changed, 321 insertions, 427 deletions
diff --git a/sys/arm/econa/if_ece.c b/sys/arm/econa/if_ece.c index 136860c4aa09..a7433f24215c 100644 --- a/sys/arm/econa/if_ece.c +++ b/sys/arm/econa/if_ece.c @@ -353,10 +353,11 @@ ece_attach(device_t dev) } ece_set_mac(sc, eaddr); sc->ifp = ifp = if_alloc(IFT_ETHER); - if (mii_phy_probe(dev, &sc->miibus, ece_ifmedia_upd, - ece_ifmedia_sts)) { - device_printf(dev, "Cannot find my PHY.\n"); - err = ENXIO; + /* Only one PHY at address 0 in this device. */ + err = mii_attach(dev, &sc->miibus, ifp, ece_ifmedia_upd, + ece_ifmedia_sts, BMSR_DEFCAPMASK, 0, MII_OFFSET_ANY, 0); + if (err != 0) { + device_printf(dev, "attaching PHYs failed\n"); goto out; } ifp->if_softc = sc; @@ -1904,9 +1905,6 @@ static int ece_miibus_readreg(device_t dev, int phy, int reg) { struct ece_softc *sc; - /* Only one phy in this device. */ - if (phy>0) - return (0); sc = device_get_softc(dev); return (phy_read(sc, phy, reg)); } diff --git a/sys/arm/xscale/ixp425/if_npe.c b/sys/arm/xscale/ixp425/if_npe.c index 3d8d670eec94..d4a1f10268e0 100644 --- a/sys/arm/xscale/ixp425/if_npe.c +++ b/sys/arm/xscale/ixp425/if_npe.c @@ -137,7 +137,6 @@ struct npe_softc { int rx_freeqid; /* rx free buffers qid */ int tx_qid; /* tx qid */ int tx_doneqid; /* tx completed qid */ - int sc_phy; /* PHY id */ struct ifmib_iso_8802_3 mibdata; bus_dma_tag_t sc_stats_tag; /* bus dma tag for stats block */ struct npestats *sc_stats; @@ -668,7 +667,7 @@ static int npe_activate(device_t dev) { struct npe_softc *sc = device_get_softc(dev); - int error, i, macbase, miibase; + int error, i, macbase, miibase, phy; /* * Setup NEP ID, MAC, and MII bindings. We allow override @@ -693,8 +692,8 @@ npe_activate(device_t dev) } /* PHY */ - if (!override_unit(dev, "phy", &sc->sc_phy, 0, MII_NPHY-1)) - sc->sc_phy = npeconfig[sc->sc_npeid].phy; + if (!override_unit(dev, "phy", &phy, 0, MII_NPHY - 1)) + phy = npeconfig[sc->sc_npeid].phy; if (!override_addr(dev, "mii", &miibase)) miibase = npeconfig[sc->sc_npeid].miibase; device_printf(sc->sc_dev, "MII at 0x%x\n", miibase); @@ -721,10 +720,12 @@ npe_activate(device_t dev) return error; } - /* probe for PHY */ - if (mii_phy_probe(dev, &sc->sc_mii, npe_ifmedia_update, npe_ifmedia_status)) { - device_printf(dev, "cannot find PHY %d.\n", sc->sc_phy); - return ENXIO; + /* attach PHY */ + error = mii_attach(dev, &sc->sc_mii, sc->sc_ifp, npe_ifmedia_update, + npe_ifmedia_status, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0); + if (error != 0) { + device_printf(dev, "attaching PHYs failed\n"); + return error; } error = npe_dma_setup(sc, &sc->txdma, "tx", npe_txbuf, NPE_MAXSEG); @@ -1700,8 +1701,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); if (npe_mii_mdio_wait(sc)) @@ -1717,8 +1716,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 (0); 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 c47a03eb4d0a..1a8251623e9d 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 cd593ffa6295..c9ea4cdac88f 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 15505714fa0d..5f0f7eccfd85 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 eea21755250e..2122d75b7ae6 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 00a2e97e5be3..f384f6de9ee8 100644 --- a/sys/dev/bfe/if_bfe.c +++ b/sys/dev/bfe/if_bfe.c @@ -505,10 +505,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; } @@ -631,8 +632,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); @@ -644,8 +643,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 5381e3b543ba..662713fe5b24 100644 --- a/sys/dev/bge/if_bge.c +++ b/sys/dev/bge/if_bge.c @@ -781,10 +781,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, @@ -2563,7 +2559,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; @@ -2596,7 +2592,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 @@ -2961,17 +2957,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 19c455c17ff3..60a39f88fad3 100644 --- a/sys/dev/bge/if_bgereg.h +++ b/sys/dev/bge/if_bgereg.h @@ -2757,7 +2757,6 @@ struct bge_softc { uint32_t bge_tx_max_coal_bds; 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 c2a43589baf0..ded2b42f6f3f 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 c3de5122c407..e454fa1592d5 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 19bf069e9215..856908129bc4 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); @@ -2217,6 +2189,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; @@ -2225,7 +2198,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)) { @@ -2237,16 +2210,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 @@ -2261,7 +2255,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 6904d9ae9df2..2a221ebcbe69 100644 --- a/sys/dev/fxp/if_fxp.c +++ b/sys/dev/fxp/if_fxp.c @@ -804,10 +804,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 8be68abaf78b..5c5750e3eabe 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 08cef669343d..09e94e749604 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 12cc06bbda5e..89c908fca48a 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) | @@ -743,9 +733,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/mge/if_mge.c b/sys/dev/mge/if_mge.c index c710521c6ba9..824f8a21a615 100644 --- a/sys/dev/mge/if_mge.c +++ b/sys/dev/mge/if_mge.c @@ -629,7 +629,7 @@ mge_attach(device_t dev) struct mii_softc *miisc; struct ifnet *ifp; uint8_t hwaddr[ETHER_ADDR_LEN]; - int i, error ; + int i, error, phy; sc = device_get_softc(dev); sc->dev = dev; @@ -642,7 +642,7 @@ mge_attach(device_t dev) mge_ver_params(sc); /* Get phy address from fdt */ - if (fdt_get_phyaddr(sc->node, &sc->phyaddr) != 0) + if (fdt_get_phyaddr(sc->node, &phy) != 0) return (ENXIO); /* Initialize mutexes */ @@ -706,10 +706,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"); mge_detach(dev); return (error); } @@ -1293,9 +1294,6 @@ mge_miibus_readreg(device_t dev, int phy, int reg) sc = device_get_softc(dev); - if (sc->phyaddr != phy) - return (0); - MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff & (MGE_SMI_READ | (reg << 21) | (phy << 16))); @@ -1317,9 +1315,6 @@ mge_miibus_writereg(device_t dev, int phy, int reg, int value) sc = device_get_softc(dev); - if (sc->phyaddr != phy) - return (0); - MGE_WRITE(sc_mge0, MGE_REG_SMI, 0x1fffffff & (MGE_SMI_WRITE | (reg << 21) | (phy << 16) | (value & 0xffff))); diff --git a/sys/dev/mge/if_mgevar.h b/sys/dev/mge/if_mgevar.h index e21b590f43ec..5f96fa760904 100644 --- a/sys/dev/mge/if_mgevar.h +++ b/sys/dev/mge/if_mgevar.h @@ -103,8 +103,6 @@ struct mge_softc { uint32_t mge_tx_tok_cnt; uint16_t mge_mtu; int mge_ver; - - int phyaddr; }; 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/axphy.c b/sys/dev/mii/axphy.c index cdfa387d1b58..3349d3f5f0df 100644 --- a/sys/dev/mii/axphy.c +++ b/sys/dev/mii/axphy.c @@ -97,6 +97,7 @@ axphy_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 = axphy_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 b99511038c6e..cf88d200f5ff 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 31913baa5b9a..cb94f85acc80 100644 --- a/sys/dev/mii/ciphy.c +++ b/sys/dev/mii/ciphy.c @@ -57,9 +57,7 @@ __FBSDID("$FreeBSD$"); #include "miibus_if.h" #include <machine/bus.h> -/* -#include <dev/vge/if_vgereg.h> -*/ + 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 <dev/mii/e1000phyreg.h> -/* XXX */ -#include <machine/bus.h> -#include <dev/msk/if_mskreg.h> #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/smcphy.c b/sys/dev/mii/smcphy.c index d893c317c492..f356fdb7e94b 100644 --- a/sys/dev/mii/smcphy.c +++ b/sys/dev/mii/smcphy.c @@ -105,6 +105,7 @@ smcphy_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 = smcphy_service; diff --git a/sys/dev/mii/tdkphy.c b/sys/dev/mii/tdkphy.c index dc0feca608d3..df08c5efe9fa 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 37ee752971c3..4c144fdf1271 100644 --- a/sys/dev/msk/if_msk.c +++ b/sys/dev/msk/if_msk.c @@ -401,9 +401,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)); @@ -442,9 +439,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)); @@ -1647,10 +1641,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; @@ -1891,8 +1886,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) { @@ -1911,8 +1908,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 6295a46b5bd5..d7314a9c6bb1 100644 --- a/sys/dev/pcn/if_pcn.c +++ b/sys/dev/pcn/if_pcn.c @@ -634,13 +634,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 ef68f145af04..8fd20b6a8327 100644 --- a/sys/dev/re/if_re.c +++ b/sys/dev/re/if_re.c @@ -409,9 +409,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 */ @@ -481,10 +478,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; @@ -539,10 +532,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; @@ -1108,7 +1097,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; @@ -1407,11 +1396,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 c8cd9564dc5c..5a8c959e3bda 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) @@ -1496,23 +1492,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 e3297e6d5735..f616e50b8541 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; @@ -1059,7 +1055,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; @@ -1148,10 +1144,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 aa99dc920cbe..9e8577194027 100644 --- a/sys/dev/stge/if_stge.c +++ b/sys/dev/stge/if_stge.c @@ -576,7 +576,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; @@ -738,9 +738,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/tsec/if_tsec.c b/sys/dev/tsec/if_tsec.c index 7ba7dc68528b..c924419675ab 100644 --- a/sys/dev/tsec/if_tsec.c +++ b/sys/dev/tsec/if_tsec.c @@ -268,11 +268,12 @@ tsec_attach(struct tsec_softc *sc) ifp->if_capabilities |= IFCAP_POLLING; #endif - /* Probe PHY(s) */ - error = mii_phy_probe(sc->dev, &sc->tsec_miibus, tsec_ifmedia_upd, - tsec_ifmedia_sts); + /* Attach PHY(s) */ + error = mii_attach(sc->dev, &sc->tsec_miibus, ifp, tsec_ifmedia_upd, + tsec_ifmedia_sts, BMSR_DEFCAPMASK, sc->phyaddr, MII_OFFSET_ANY, + 0); if (error) { - device_printf(sc->dev, "MII failed to find PHY!\n"); + device_printf(sc->dev, "attaching PHYs failed\n"); if_free(ifp); sc->tsec_ifp = NULL; tsec_detach(sc); @@ -1561,11 +1562,6 @@ tsec_miibus_readreg(device_t dev, int phy, int reg) struct tsec_softc *sc; uint32_t timeout; - sc = device_get_softc(dev); - - if (sc->phyaddr != phy) - return (0); - sc = tsec0_sc; TSEC_WRITE(sc, TSEC_REG_MIIMADD, (phy << 8) | reg); @@ -1589,11 +1585,6 @@ tsec_miibus_writereg(device_t dev, int phy, int reg, int value) struct tsec_softc *sc; uint32_t timeout; - sc = device_get_softc(dev); - - if (sc->phyaddr != phy) - return (0); - sc = tsec0_sc; TSEC_WRITE(sc, TSEC_REG_MIIMADD, (phy << 8) | reg); diff --git a/sys/dev/vge/if_vge.c b/sys/dev/vge/if_vge.c index 127a123cc63d..20a0df4b242a 100644 --- a/sys/dev/vge/if_vge.c +++ b/sys/dev/vge/if_vge.c @@ -368,9 +368,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. */ @@ -404,9 +401,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. */ @@ -1091,10 +1085,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 e9359aa0964c..49555757b77a 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/dev/xl/if_xl.c b/sys/dev/xl/if_xl.c index 3f0e1d751ec2..0d77e12947e4 100644 --- a/sys/dev/xl/if_xl.c +++ b/sys/dev/xl/if_xl.c @@ -523,16 +523,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; @@ -550,9 +540,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; @@ -1150,7 +1137,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); @@ -1467,10 +1454,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; diff --git a/sys/mips/cavium/octe/octe.c b/sys/mips/cavium/octe/octe.c index 2e0573459dbc..daccb369eeb2 100644 --- a/sys/mips/cavium/octe/octe.c +++ b/sys/mips/cavium/octe/octe.c @@ -157,10 +157,11 @@ octe_attach(device_t dev) if (priv->phy_id != -1) { if (priv->phy_device == NULL) { - error = mii_phy_probe(dev, &priv->miibus, octe_mii_medchange, - octe_mii_medstat); + error = mii_attach(dev, &priv->miibus, ifp, + octe_mii_medchange, octe_mii_medstat, + BMSR_DEFCAPMASK, priv->phy_id, MII_OFFSET_ANY, 0); if (error != 0) - device_printf(dev, "missing phy %u\n", priv->phy_id); + device_printf(dev, "attaching PHYs failed\n"); } else { child = device_add_child(dev, priv->phy_device, -1); if (child == NULL) @@ -239,9 +240,8 @@ octe_miibus_readreg(device_t dev, int phy, int reg) /* * Try generic MII routine. */ - if (phy != priv->phy_id) - return (0); - + KASSERT(phy == priv->phy_id, + ("read from phy %u but our phy is %u", phy, priv->phy_id)); return (cvm_oct_mdio_read(priv->ifp, phy, reg)); } diff --git a/sys/mips/rmi/dev/nlge/if_nlge.c b/sys/mips/rmi/dev/nlge/if_nlge.c index 6688422396ff..6495e4bf1f68 100644 --- a/sys/mips/rmi/dev/nlge/if_nlge.c +++ b/sys/mips/rmi/dev/nlge/if_nlge.c @@ -848,7 +848,7 @@ nlge_mii_write(struct device *dev, int phyaddr, int regidx, int regval) struct nlge_softc *sc; sc = device_get_softc(dev); - if (sc->phy_addr == phyaddr && sc->port_type != XLR_XGMII) + if (sc->port_type != XLR_XGMII) nlge_mii_write_internal(sc->mii_base, phyaddr, regidx, regval); return (0); @@ -861,7 +861,7 @@ nlge_mii_read(struct device *dev, int phyaddr, int regidx) int val; sc = device_get_softc(dev); - val = (sc->phy_addr != phyaddr && sc->port_type != XLR_XGMII) ? (0xffff) : + val = (sc->port_type != XLR_XGMII) ? (0xffff) : nlge_mii_read_internal(sc->mii_base, phyaddr, regidx); return (val); @@ -1907,9 +1907,11 @@ nlge_mii_init(device_t dev, struct nlge_softc *sc) if (sc->port_type != XLR_XAUI && sc->port_type != XLR_XGMII) { NLGE_WRITE(sc->mii_base, R_MII_MGMT_CONFIG, 0x07); } - error = mii_phy_probe(dev, &sc->mii_bus, nlge_mediachange, nlge_mediastatus); + error = mii_attach(dev, &sc->mii_bus, sc->nlge_if, nlge_mediachange, + nlge_mediastatus, BMSR_DEFCAPMASK, sc->phy_addr, MII_OFFSET_ANY, + 0); if (error) { - device_printf(dev, "no PHY device found\n"); + device_printf(dev, "attaching PHYs failed\n"); sc->mii_bus = NULL; } if (sc->mii_bus != NULL) { diff --git a/sys/pci/if_rl.c b/sys/pci/if_rl.c index 05eeffb778d0..f2170099cbc9 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; } |