summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2010-10-15 14:52:11 +0000
committermarius <marius@FreeBSD.org>2010-10-15 14:52:11 +0000
commit385153aa98ec9bc0cd0bde471d7b89b6f7304427 (patch)
tree6dd0ca5b178547c1f20c8ce1f607ac42d4afe2ae /sys/dev
parent27659e5aa689e80a32d089f84ed2637bb3ce140d (diff)
downloadFreeBSD-src-385153aa98ec9bc0cd0bde471d7b89b6f7304427.zip
FreeBSD-src-385153aa98ec9bc0cd0bde471d7b89b6f7304427.tar.gz
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 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
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ae/if_ae.c16
-rw-r--r--sys/dev/ae/if_aevar.h1
-rw-r--r--sys/dev/age/if_age.c12
-rw-r--r--sys/dev/alc/if_alc.c14
-rw-r--r--sys/dev/ale/if_ale.c14
-rw-r--r--sys/dev/bfe/if_bfe.c13
-rw-r--r--sys/dev/bge/if_bge.c18
-rw-r--r--sys/dev/bge/if_bgereg.h1
-rw-r--r--sys/dev/bm/if_bm.c18
-rw-r--r--sys/dev/cas/if_cas.c37
-rw-r--r--sys/dev/cas/if_casvar.h2
-rw-r--r--sys/dev/dc/if_dc.c64
-rw-r--r--sys/dev/dc/pnphy.c3
-rw-r--r--sys/dev/fxp/if_fxp.c12
-rw-r--r--sys/dev/gem/if_gem.c39
-rw-r--r--sys/dev/gem/if_gemvar.h2
-rw-r--r--sys/dev/hme/if_hme.c25
-rw-r--r--sys/dev/jme/if_jme.c26
-rw-r--r--sys/dev/mge/if_mge.c17
-rw-r--r--sys/dev/mge/if_mgevar.h2
-rw-r--r--sys/dev/mii/acphy.c1
-rw-r--r--sys/dev/mii/amphy.c1
-rw-r--r--sys/dev/mii/atphy.c1
-rw-r--r--sys/dev/mii/axphy.c1
-rw-r--r--sys/dev/mii/bmtphy.c1
-rw-r--r--sys/dev/mii/brgphy.c1
-rw-r--r--sys/dev/mii/ciphy.c5
-rw-r--r--sys/dev/mii/e1000phy.c18
-rw-r--r--sys/dev/mii/exphy.c1
-rw-r--r--sys/dev/mii/gentbi.c1
-rw-r--r--sys/dev/mii/icsphy.c1
-rw-r--r--sys/dev/mii/inphy.c1
-rw-r--r--sys/dev/mii/ip1000phy.c22
-rw-r--r--sys/dev/mii/jmphy.c1
-rw-r--r--sys/dev/mii/lxtphy.c11
-rw-r--r--sys/dev/mii/mlphy.c1
-rw-r--r--sys/dev/mii/nsgphy.c1
-rw-r--r--sys/dev/mii/nsphy.c27
-rw-r--r--sys/dev/mii/nsphyter.c19
-rw-r--r--sys/dev/mii/pnaphy.c1
-rw-r--r--sys/dev/mii/qsphy.c1
-rw-r--r--sys/dev/mii/rgephy.c1
-rw-r--r--sys/dev/mii/rlphy.c1
-rw-r--r--sys/dev/mii/rlswitch.c1
-rw-r--r--sys/dev/mii/ruephy.c1
-rw-r--r--sys/dev/mii/smcphy.c1
-rw-r--r--sys/dev/mii/tdkphy.c1
-rw-r--r--sys/dev/mii/tlphy.c5
-rw-r--r--sys/dev/mii/truephy.c1
-rw-r--r--sys/dev/mii/ukphy.c1
-rw-r--r--sys/dev/mii/xmphy.c1
-rw-r--r--sys/dev/msk/if_msk.c21
-rw-r--r--sys/dev/pcn/if_pcn.c13
-rw-r--r--sys/dev/re/if_re.c28
-rw-r--r--sys/dev/sk/if_sk.c22
-rw-r--r--sys/dev/ste/if_ste.c17
-rw-r--r--sys/dev/stge/if_stge.c13
-rw-r--r--sys/dev/tsec/if_tsec.c19
-rw-r--r--sys/dev/vge/if_vge.c15
-rw-r--r--sys/dev/vr/if_vr.c22
-rw-r--r--sys/dev/vr/if_vrreg.h1
-rw-r--r--sys/dev/xl/if_xl.c32
62 files changed, 285 insertions, 385 deletions
diff --git a/sys/dev/ae/if_ae.c b/sys/dev/ae/if_ae.c
index c47a03e..1a82516 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 eaef62e..8623401 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 cd593ff..c9ea4cd 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 1550571..5f0f7ec 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 eea2175..2122d75 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 00a2e97..f384f6d 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 5381e3b..662713f 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 19c455c..60a39f8 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 c2a4358..ded2b42 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 c3de512..e454fa1 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 e800f4e..fa2e6af 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 19bf069..8569081 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 570ee5f..15704b2 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 6904d9a..2a221eb 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 8be68ab..5c5750e 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 ab5b2f6..59cb582 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 08cef66..09e94e7 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 12cc06b..89c908f 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 c710521..824f8a2 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 e21b590..5f96fa7 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 661bc91..7013dbf 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 a67c66c..010fe90 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 fd531ad..41cd72c 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 cdfa387..3349d3f 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 af1fe11..63d1df1 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 b995110..cf88d20 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 31913ba..cb94f85 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 8df7859..e763c21 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 02ed6442..a5b03dc 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 49cfc67..ee08efe 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 cac9af5..849a14b 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 f6418f7..6830b5a 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 232e280..b60fab6 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 ae066c5..0b04d80 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 fc12ee6..44b40ff 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 5a2e42d..04e4b80 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 6cfb40f..b3df8a2 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 21681f2..af805ca 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 6317a52..5489504 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 46e2eae..69c41d6 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 f6cdd45..19fc77d 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 c1d6703..d1e0e51 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 368b6ca..eeaaaab 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 1fda268..0c1b62f 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 f793c61..fc2a6b94 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 d893c31..f356fdb 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 dc0feca..df08c5e 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 b425c76..e618611 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 c833983..bb99df2 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 75d6132..05b1b45 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 582f864..745c7b3 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 37ee752..4c144fd 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 6295a46..d7314a9 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 ef68f14..8fd20b6 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 c8cd956..5a8c959 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 e3297e6..f616e50 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 aa99dc9..9e85771 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 7ba7dc6..c924419 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 127a123..20a0df4 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 e9359aa..4955575 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 9c85962..d686bdd 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 3f0e1d7..0d77e12 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;
OpenPOWER on IntegriCloud