diff options
author | Jason Wright <jason@cvs.openbsd.org> | 1998-11-11 19:34:52 +0000 |
---|---|---|
committer | Jason Wright <jason@cvs.openbsd.org> | 1998-11-11 19:34:52 +0000 |
commit | b67320a002793e8f496722a85d888421724eb4dc (patch) | |
tree | 4c109936ccfb901a84c59a7f464a83c8a9a31a41 /sys/dev/mii/inphy.c | |
parent | b4d28fc47cc2f346e2f660be351cb60a89bd26ee (diff) |
Merge with NetBSD:
o additional phy drivers (seeq, ics, level1)
o "unknown phy" driver for unsupported phys
o collected common code into mii_physubr
o exphy isn't the only phy that doesn't have valid id registers
Diffstat (limited to 'sys/dev/mii/inphy.c')
-rw-r--r-- | sys/dev/mii/inphy.c | 189 |
1 files changed, 61 insertions, 128 deletions
diff --git a/sys/dev/mii/inphy.c b/sys/dev/mii/inphy.c index 70cedb54345..6f43b03fb1a 100644 --- a/sys/dev/mii/inphy.c +++ b/sys/dev/mii/inphy.c @@ -1,5 +1,5 @@ -/* $OpenBSD: inphy.c,v 1.1 1998/09/10 17:17:33 jason Exp $ */ -/* $NetBSD: inphy.c,v 1.3 1998/08/12 20:56:35 thorpej Exp $ */ +/* $OpenBSD: inphy.c,v 1.2 1998/11/11 19:34:46 jason Exp $ */ +/* $NetBSD: inphy.c,v 1.10 1998/11/05 04:08:02 thorpej Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -88,13 +88,6 @@ #include <dev/mii/inphyreg.h> -struct inphy_softc { - struct mii_softc sc_mii; /* generic PHY */ - int sc_capabilities; - int sc_ticks; - int sc_active; -}; - #ifdef __NetBSD__ int inphymatch __P((struct device *, struct cfdata *, void *)); #else @@ -103,7 +96,7 @@ int inphymatch __P((struct device *, void *, void *)); void inphyattach __P((struct device *, struct device *, void *)); struct cfattach inphy_ca = { - sizeof(struct inphy_softc), inphymatch, inphyattach + sizeof(struct mii_softc), inphymatch, inphyattach }; #ifdef __OpenBSD__ @@ -112,18 +105,8 @@ struct cfdriver inphy_cd = { }; #endif -#define INPHY_READ(sc, reg) \ - (*(sc)->sc_mii.mii_pdata->mii_readreg)((sc)->sc_mii.mii_dev.dv_parent, \ - (sc)->sc_mii.mii_phy, (reg)) - -#define INPHY_WRITE(sc, reg, val) \ - (*(sc)->sc_mii.mii_pdata->mii_writereg)((sc)->sc_mii.mii_dev.dv_parent, \ - (sc)->sc_mii.mii_phy, (reg), (val)) - int inphy_service __P((struct mii_softc *, struct mii_data *, int)); -void inphy_reset __P((struct inphy_softc *)); -void inphy_auto __P((struct inphy_softc *)); -void inphy_status __P((struct inphy_softc *)); +void inphy_status __P((struct mii_softc *)); int inphymatch(parent, match, aux) @@ -139,7 +122,7 @@ inphymatch(parent, match, aux) if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_INTEL && MII_MODEL(ma->mii_id2) == MII_MODEL_INTEL_I82555) - return (1); + return (10); return (0); } @@ -149,47 +132,55 @@ inphyattach(parent, self, aux) struct device *parent, *self; void *aux; { - struct inphy_softc *sc = (struct inphy_softc *)self; + struct mii_softc *sc = (struct mii_softc *)self; struct mii_attach_args *ma = aux; struct mii_data *mii = ma->mii_data; printf(": %s, rev. %d\n", MII_STR_INTEL_I82555, MII_REV(ma->mii_id2)); - sc->sc_mii.mii_inst = mii->mii_instance; - sc->sc_mii.mii_phy = ma->mii_phyno; - sc->sc_mii.mii_service = inphy_service; - sc->sc_mii.mii_pdata = mii; + sc->mii_inst = mii->mii_instance; + sc->mii_phy = ma->mii_phyno; + sc->mii_service = inphy_service; + sc->mii_pdata = mii; + + /* + * i82557 wedges if all of its PHYs are isolated! + */ + if (strcmp(parent->dv_cfdata->cf_driver->cd_name, "fxp") == 0 && + mii->mii_instance == 0) + sc->mii_flags |= MIIF_NOISOLATE; #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) -#if 0 - /* Can't do this on the i82557! */ - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->sc_mii.mii_inst), - BMCR_ISO); -#endif - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->sc_mii.mii_inst), + if ((sc->mii_flags & MIIF_NOISOLATE) == 0) + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst), + BMCR_ISO); + + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst), BMCR_LOOP|BMCR_S100); - inphy_reset(sc); + mii_phy_reset(sc); - sc->sc_capabilities = INPHY_READ(sc, MII_BMSR) & ma->mii_capmask; - printf("%s: ", sc->sc_mii.mii_dev.dv_xname); - if ((sc->sc_capabilities & BMSR_MEDIAMASK) == 0) + sc->mii_capabilities = + PHY_READ(sc, MII_BMSR) & ma->mii_capmask; + printf("%s: ", sc->mii_dev.dv_xname); + if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0) printf("no media present"); else - mii_add_media(mii, sc->sc_capabilities, sc->sc_mii.mii_inst); + mii_add_media(mii, sc->mii_capabilities, + sc->mii_inst); printf("\n"); #undef ADD } int -inphy_service(self, mii, cmd) - struct mii_softc *self; +inphy_service(sc, mii, cmd) + struct mii_softc *sc; struct mii_data *mii; int cmd; { - struct inphy_softc *sc = (struct inphy_softc *)self; + struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int reg; switch (cmd) { @@ -197,8 +188,7 @@ inphy_service(self, mii, cmd) /* * If we're not polling our PHY instance, just return. */ - if (IFM_INST(mii->mii_media.ifm_media) != - sc->sc_mii.mii_inst) + if (IFM_INST(ife->ifm_media) != sc->mii_inst) return (0); break; @@ -207,10 +197,9 @@ inphy_service(self, mii, cmd) * If the media indicates a different PHY instance, * isolate ourselves. */ - if (IFM_INST(mii->mii_media.ifm_media) != - sc->sc_mii.mii_inst) { - reg = INPHY_READ(sc, MII_BMCR); - INPHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO); + if (IFM_INST(ife->ifm_media) != sc->mii_inst) { + reg = PHY_READ(sc, MII_BMCR); + PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO); return (0); } @@ -220,14 +209,14 @@ inphy_service(self, mii, cmd) if ((mii->mii_ifp->if_flags & IFF_UP) == 0) break; - switch (IFM_SUBTYPE(mii->mii_media.ifm_media)) { + switch (IFM_SUBTYPE(ife->ifm_media)) { case IFM_AUTO: /* * If we're already in auto mode, just return. */ - if (INPHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) + if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) return (0); - inphy_auto(sc); + (void) mii_phy_auto(sc); break; case IFM_100_T4: /* @@ -238,10 +227,9 @@ inphy_service(self, mii, cmd) /* * BMCR data is stored in the ifmedia entry. */ - INPHY_WRITE(sc, MII_ANAR, - mii_anar(mii->mii_media.ifm_media)); - INPHY_WRITE(sc, MII_BMCR, - mii->mii_media.ifm_cur->ifm_data); + PHY_WRITE(sc, MII_ANAR, + mii_anar(ife->ifm_media)); + PHY_WRITE(sc, MII_BMCR, ife->ifm_data); } break; @@ -249,14 +237,13 @@ inphy_service(self, mii, cmd) /* * If we're not currently selected, just return. */ - if (IFM_INST(mii->mii_media.ifm_media) != - sc->sc_mii.mii_inst) + if (IFM_INST(ife->ifm_media) != sc->mii_inst) return (0); /* * Only used for autonegotiation. */ - if (IFM_SUBTYPE(mii->mii_media.ifm_media) != IFM_AUTO) + if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) return (0); /* @@ -270,19 +257,20 @@ inphy_service(self, mii, cmd) * need to restart the autonegotiation process. Read * the BMSR twice in case it's latched. */ - reg = INPHY_READ(sc, MII_BMSR) | INPHY_READ(sc, MII_BMSR); + reg = PHY_READ(sc, MII_BMSR) | + PHY_READ(sc, MII_BMSR); if (reg & BMSR_LINK) return (0); /* * Only retry autonegotiation every 5 seconds. */ - if (++sc->sc_ticks != 5) + if (++sc->mii_ticks != 5) return (0); - sc->sc_ticks = 0; - inphy_reset(sc); - inphy_auto(sc); + sc->mii_ticks = 0; + mii_phy_reset(sc); + (void) mii_phy_auto(sc); break; } @@ -290,28 +278,29 @@ inphy_service(self, mii, cmd) inphy_status(sc); /* Callback if something changed. */ - if (sc->sc_active != mii->mii_media_active || cmd == MII_MEDIACHG) { - (*mii->mii_statchg)(sc->sc_mii.mii_dev.dv_parent); - sc->sc_active = mii->mii_media_active; + if (sc->mii_active != mii->mii_media_active || cmd == MII_MEDIACHG) { + (*mii->mii_statchg)(sc->mii_dev.dv_parent); + sc->mii_active = mii->mii_media_active; } return (0); } void inphy_status(sc) - struct inphy_softc *sc; + struct mii_softc *sc; { - struct mii_data *mii = sc->sc_mii.mii_pdata; + struct mii_data *mii = sc->mii_pdata; int bmsr, bmcr, scr; mii->mii_media_status = IFM_AVALID; mii->mii_media_active = IFM_ETHER; - bmsr = INPHY_READ(sc, MII_BMSR) | INPHY_READ(sc, MII_BMSR); + bmsr = PHY_READ(sc, MII_BMSR) | + PHY_READ(sc, MII_BMSR); if (bmsr & BMSR_LINK) mii->mii_media_status |= IFM_ACTIVE; - bmcr = INPHY_READ(sc, MII_BMCR); + bmcr = PHY_READ(sc, MII_BMCR); if (bmcr & BMCR_ISO) { mii->mii_media_active |= IFM_NONE; mii->mii_media_status = 0; @@ -327,7 +316,7 @@ inphy_status(sc) mii->mii_media_active |= IFM_NONE; return; } - scr = INPHY_READ(sc, MII_INPHY_SCR); + scr = PHY_READ(sc, MII_INPHY_SCR); if (scr & SCR_T4) mii->mii_media_active |= IFM_100_T4; else if (scr & SCR_S100) @@ -336,62 +325,6 @@ inphy_status(sc) mii->mii_media_active |= IFM_10_T; if (scr & SCR_FDX) mii->mii_media_active |= IFM_FDX; - } else { - if (bmcr & BMCR_S100) - mii->mii_media_active |= IFM_100_TX; - else - mii->mii_media_active |= IFM_10_T; - if (bmcr & BMCR_FDX) - mii->mii_media_active |= IFM_FDX; - } -} - -void -inphy_auto(sc) - struct inphy_softc *sc; -{ - int bmsr, i; - - INPHY_WRITE(sc, MII_ANAR, - BMSR_MEDIA_TO_ANAR(sc->sc_capabilities) | ANAR_CSMA); - INPHY_WRITE(sc, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG); - - /* Wait 500ms for it to complete. */ - for (i = 0; i < 500; i++) { - if ((bmsr = INPHY_READ(sc, MII_BMSR)) & BMSR_ACOMP) - return; - delay(1000); - } -#if 0 - if ((bmsr & BMSR_ACOMP) == 0) - printf("%s: autonegotiation failed to complete\n", - sc->sc_mii.mii_dev.dv_xname); -#endif -} - -void -inphy_reset(sc) - struct inphy_softc *sc; -{ - int reg, i; - - /* - * The i82557 wedges if we isolate all of its PHYs! - */ - if (sc->sc_mii.mii_inst == 0) - INPHY_WRITE(sc, MII_BMCR, BMCR_RESET); - else - INPHY_WRITE(sc, MII_BMCR, BMCR_RESET|BMCR_ISO); - - /* Wait 100ms for it to complete. */ - for (i = 0; i < 100; i++) { - reg = INPHY_READ(sc, MII_BMCR); - if ((reg & BMCR_RESET) == 0) - break; - delay(1000); - } - - /* Make sure the PHY is isolated. */ - if (sc->sc_mii.mii_inst != 0) - INPHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO); + } else + mii->mii_media_active = mii_media_from_bmcr(bmcr); } |