diff options
author | Nathan Binkert <nate@cvs.openbsd.org> | 2000-08-26 20:04:19 +0000 |
---|---|---|
committer | Nathan Binkert <nate@cvs.openbsd.org> | 2000-08-26 20:04:19 +0000 |
commit | 841e005741a8dcb32a106f13731c7dd1e832d2b7 (patch) | |
tree | 61d0acb17595089ed91f7518d6314428615d1b9e /sys/dev/mii/iophy.c | |
parent | bd43edc61a95550b14f127a9a6b2902a6208f11b (diff) |
sync mii code with netbsd
adds detach functionality for phys
some code cleanup
Nobody really had time to test all of this out, but theo said commit anyway
Diffstat (limited to 'sys/dev/mii/iophy.c')
-rw-r--r-- | sys/dev/mii/iophy.c | 81 |
1 files changed, 18 insertions, 63 deletions
diff --git a/sys/dev/mii/iophy.c b/sys/dev/mii/iophy.c index fe5247da650..da3ef62bd53 100644 --- a/sys/dev/mii/iophy.c +++ b/sys/dev/mii/iophy.c @@ -1,8 +1,8 @@ -/* $OpenBSD: iophy.c,v 1.5 1999/12/07 22:01:30 jason Exp $ */ -/* $NetBSD: iophy.c,v 1.1 1999/09/05 00:40:27 soren Exp $ */ +/* $OpenBSD: iophy.c,v 1.6 2000/08/26 20:04:17 nate Exp $ */ +/* $NetBSD: iophy.c,v 1.8 2000/02/02 23:34:56 thorpej Exp $ */ /* - * Copyright (c) 1998 The NetBSD Foundation, Inc. + * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -90,12 +90,13 @@ int iophymatch __P((struct device *, void *, void *)); void iophyattach __P((struct device *, struct device *, void *)); -struct cfdriver iophy_cd = { - NULL, "iophy", DV_DULL +struct cfattach iophy_ca = { + sizeof(struct mii_softc), iophymatch, iophyattach, mii_phy_detach, + mii_phy_activate }; -struct cfattach iophy_ca = { - sizeof(struct mii_softc), iophymatch, iophyattach +struct cfdriver iophy_cd = { + NULL, "iophy", DV_DULL }; int iophy_service __P((struct mii_softc *, struct mii_data *, int)); @@ -135,21 +136,16 @@ iophyattach(parent, self, aux) sc->mii_inst = mii->mii_instance; sc->mii_phy = ma->mii_phyno; sc->mii_service = iophy_service; + sc->mii_status = iophy_status; 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; + sc->mii_flags = mii->mii_flags; mii_phy_reset(sc); sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask; if (sc->mii_capabilities & BMSR_MEDIAMASK) - mii_add_media(sc); + mii_phy_add_media(sc); } int @@ -161,6 +157,9 @@ iophy_service(sc, mii, cmd) struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int reg; + if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0) + return (ENXIO); + switch (cmd) { case MII_POLLSTAT: /* @@ -187,18 +186,7 @@ iophy_service(sc, mii, cmd) if ((mii->mii_ifp->if_flags & IFF_UP) == 0) break; - switch (IFM_SUBTYPE(ife->ifm_media)) { - case IFM_AUTO: - /* - * If we're already in auto mode, just return. - */ - if (PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) - return (0); - (void) mii_phy_auto(sc, 1); - break; - default: - mii_phy_setmedia(sc); - } + mii_phy_setmedia(sc); break; case MII_TICK: @@ -208,37 +196,7 @@ iophy_service(sc, mii, cmd) if (IFM_INST(ife->ifm_media) != sc->mii_inst) return (0); - /* - * Only used for autonegotiation. - */ - if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) - return (0); - - /* - * Is the interface even up? - */ - if ((mii->mii_ifp->if_flags & IFF_UP) == 0) - return (0); - - /* - * Check to see if we have link. If we do, we don't - * need to restart the autonegotiation process. Read - * the BMSR twice in case it's latched. - */ - 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->mii_ticks != 5) - return (0); - - sc->mii_ticks = 0; - mii_phy_reset(sc); - if (mii_phy_auto(sc, 0) == EJUSTRETURN) + if (mii_phy_tick(sc) == EJUSTRETURN) return (0); break; @@ -248,13 +206,10 @@ iophy_service(sc, mii, cmd) } /* Update the media status. */ - iophy_status(sc); + mii_phy_status(sc); /* Callback if something changed. */ - 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; - } + mii_phy_update(sc, cmd); return (0); } |