Index: head/sys/dev/mii/acphy.c =================================================================== --- head/sys/dev/mii/acphy.c (revision 281820) +++ head/sys/dev/mii/acphy.c (revision 281821) @@ -1,246 +1,244 @@ /*- * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, * NASA Ames Research Center. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*- * Copyright (c) 1997 Manuel Bouyer. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * Driver for Altima AC101 10/100 PHY */ #include #include #include #include #include #include #include #include #include #include #include #include "miidevs.h" #include #include "miibus_if.h" static int acphy_probe(device_t); static int acphy_attach(device_t); static device_method_t acphy_methods[] = { /* device interface */ DEVMETHOD(device_probe, acphy_probe), DEVMETHOD(device_attach, acphy_attach), DEVMETHOD(device_detach, mii_phy_detach), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD_END }; static devclass_t acphy_devclass; static driver_t acphy_driver = { "acphy", acphy_methods, sizeof(struct mii_softc) }; DRIVER_MODULE(acphy, miibus, acphy_driver, acphy_devclass, 0, 0); static int acphy_service(struct mii_softc *, struct mii_data *, int); static void acphy_reset(struct mii_softc *); static void acphy_status(struct mii_softc *); static const struct mii_phydesc acphys[] = { MII_PHY_DESC(ALTIMA, AC101), MII_PHY_DESC(ALTIMA, AC101L), /* XXX This is reported to work, but it's not from any data sheet. */ MII_PHY_DESC(ALTIMA, ACXXX), MII_PHY_END }; static const struct mii_phy_funcs acphy_funcs = { acphy_service, acphy_status, acphy_reset }; static int acphy_probe(device_t dev) { return (mii_phy_dev_probe(dev, acphys, BUS_PROBE_DEFAULT)); } static int acphy_attach(device_t dev) { struct mii_softc *sc; sc = device_get_softc(dev); mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &acphy_funcs, 0); PHY_RESET(sc); sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask; device_printf(dev, " "); -#define ADD(m, c) ifmedia_add(&sc->mii_pdata->mii_media, (m), (c), NULL) +#define ADD(m) ifmedia_add(&sc->mii_pdata->mii_media, (m), 0, NULL) if ((PHY_READ(sc, MII_ACPHY_MCTL) & AC_MCTL_FX_SEL) != 0) { sc->mii_flags |= MIIF_HAVEFIBER; - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst), - MII_MEDIA_100_TX); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst)); printf("100baseFX, "); - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, IFM_FDX, sc->mii_inst), - MII_MEDIA_100_TX_FDX); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, IFM_FDX, sc->mii_inst)); printf("100baseFX-FDX, "); } #undef ADD mii_phy_add_media(sc); printf("\n"); MIIBUS_MEDIAINIT(sc->mii_dev); return (0); } static int acphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) { int reg; switch (cmd) { case MII_POLLSTAT: break; case MII_MEDIACHG: /* Wake & deisolate up if necessary */ reg = PHY_READ(sc, MII_BMCR); if (reg & (BMCR_ISO | BMCR_PDOWN)) PHY_WRITE(sc, MII_BMCR, reg & ~(BMCR_ISO | BMCR_PDOWN)); mii_phy_setmedia(sc); break; case MII_TICK: /* * This PHY's autonegotiation doesn't need to be kicked. */ break; } /* Update the media status. */ PHY_STATUS(sc); /* Callback if something changed. */ mii_phy_update(sc, cmd); return (0); } static void acphy_status(struct mii_softc *sc) { struct mii_data *mii = sc->mii_pdata; struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int bmsr, bmcr, diag; mii->mii_media_status = IFM_AVALID; mii->mii_media_active = IFM_ETHER; bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR); if (bmsr & BMSR_LINK) mii->mii_media_status |= IFM_ACTIVE; bmcr = PHY_READ(sc, MII_BMCR); if (bmcr & BMCR_ISO) { mii->mii_media_active |= IFM_NONE; mii->mii_media_status = 0; return; } if (bmcr & BMCR_LOOP) mii->mii_media_active |= IFM_LOOP; if (bmcr & BMCR_AUTOEN) { if ((bmsr & BMSR_ACOMP) == 0) { /* Erg, still trying, I guess... */ mii->mii_media_active |= IFM_NONE; return; } diag = PHY_READ(sc, MII_ACPHY_DIAG); if (diag & AC_DIAG_SPEED) mii->mii_media_active |= IFM_100_TX; else mii->mii_media_active |= IFM_10_T; if (diag & AC_DIAG_DUPLEX) mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(sc); else mii->mii_media_active |= IFM_HDX; } else mii->mii_media_active = ife->ifm_media; } static void acphy_reset(struct mii_softc *sc) { mii_phy_reset(sc); PHY_WRITE(sc, MII_ACPHY_INT, 0); } Index: head/sys/dev/mii/lxtphy.c =================================================================== --- head/sys/dev/mii/lxtphy.c (revision 281820) +++ head/sys/dev/mii/lxtphy.c (revision 281821) @@ -1,269 +1,267 @@ /* OpenBSD: lxtphy.c,v 1.5 2000/08/26 20:04:17 nate Exp */ /* NetBSD: lxtphy.c,v 1.19 2000/02/02 23:34:57 thorpej Exp */ /*- * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, * NASA Ames Research Center. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /*- * Copyright (c) 1997 Manuel Bouyer. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * driver for Level One's LXT-970 ethernet 10/100 PHY * datasheet from www.level1.com */ #include #include #include #include #include #include #include #include #include #include #include #include "miidevs.h" #include #include "miibus_if.h" static int lxtphy_probe(device_t); static int lxtphy_attach(device_t); static device_method_t lxtphy_methods[] = { /* device interface */ DEVMETHOD(device_probe, lxtphy_probe), DEVMETHOD(device_attach, lxtphy_attach), DEVMETHOD(device_detach, mii_phy_detach), DEVMETHOD(device_shutdown, bus_generic_shutdown), DEVMETHOD_END }; static devclass_t lxtphy_devclass; static driver_t lxtphy_driver = { "lxtphy", lxtphy_methods, sizeof(struct mii_softc) }; DRIVER_MODULE(lxtphy, miibus, lxtphy_driver, lxtphy_devclass, 0, 0); static int lxtphy_service(struct mii_softc *, struct mii_data *, int); static void lxtphy_status(struct mii_softc *); static void lxtphy_reset(struct mii_softc *); static void lxtphy_set_tp(struct mii_softc *); static void lxtphy_set_fx(struct mii_softc *); static const struct mii_phydesc lxtphys[] = { MII_PHY_DESC(xxLEVEL1, LXT970), MII_PHY_END }; static const struct mii_phy_funcs lxtphy_funcs = { lxtphy_service, lxtphy_status, lxtphy_reset }; static int lxtphy_probe(device_t dev) { return (mii_phy_dev_probe(dev, lxtphys, BUS_PROBE_DEFAULT)); } static int lxtphy_attach(device_t dev) { struct mii_softc *sc; sc = device_get_softc(dev); mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &lxtphy_funcs, 0); PHY_RESET(sc); sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask; device_printf(dev, " "); -#define ADD(m, c) ifmedia_add(&sc->mii_pdata->mii_media, (m), (c), NULL) - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst), - MII_MEDIA_100_TX); +#define ADD(m) ifmedia_add(&sc->mii_pdata->mii_media, (m), 0, NULL) + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, sc->mii_inst)); printf("100baseFX, "); - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, IFM_FDX, sc->mii_inst), - MII_MEDIA_100_TX_FDX); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, IFM_FDX, sc->mii_inst)); printf("100baseFX-FDX, "); #undef ADD mii_phy_add_media(sc); printf("\n"); MIIBUS_MEDIAINIT(sc->mii_dev); return (0); } static int lxtphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) { struct ifmedia_entry *ife = mii->mii_media.ifm_cur; switch (cmd) { case MII_POLLSTAT: break; case MII_MEDIACHG: if (IFM_SUBTYPE(ife->ifm_media) == IFM_100_FX) lxtphy_set_fx(sc); else lxtphy_set_tp(sc); mii_phy_setmedia(sc); break; case MII_TICK: if (mii_phy_tick(sc) == EJUSTRETURN) return (0); break; } /* Update the media status. */ PHY_STATUS(sc); /* Callback if something changed. */ mii_phy_update(sc, cmd); return (0); } static void lxtphy_status(struct mii_softc *sc) { struct mii_data *mii = sc->mii_pdata; struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int bmcr, bmsr, csr; mii->mii_media_status = IFM_AVALID; mii->mii_media_active = IFM_ETHER; /* * Get link status from the CSR; we need to read the CSR * for media type anyhow, and the link status in the CSR * doens't latch, so fewer register reads are required. */ csr = PHY_READ(sc, MII_LXTPHY_CSR); if (csr & CSR_LINK) mii->mii_media_status |= IFM_ACTIVE; bmcr = PHY_READ(sc, MII_BMCR); if (bmcr & BMCR_ISO) { mii->mii_media_active |= IFM_NONE; mii->mii_media_status = 0; return; } if (bmcr & BMCR_LOOP) mii->mii_media_active |= IFM_LOOP; if (bmcr & BMCR_AUTOEN) { bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR); if ((bmsr & BMSR_ACOMP) == 0) { /* Erg, still trying, I guess... */ mii->mii_media_active |= IFM_NONE; return; } if (csr & CSR_SPEED) mii->mii_media_active |= IFM_100_TX; else mii->mii_media_active |= IFM_10_T; if (csr & CSR_DUPLEX) mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(sc); else mii->mii_media_active |= IFM_HDX; } else mii->mii_media_active = ife->ifm_media; } static void lxtphy_reset(struct mii_softc *sc) { mii_phy_reset(sc); PHY_WRITE(sc, MII_LXTPHY_IER, PHY_READ(sc, MII_LXTPHY_IER) & ~IER_INTEN); } static void lxtphy_set_tp(struct mii_softc *sc) { int cfg; cfg = PHY_READ(sc, MII_LXTPHY_CONFIG); cfg &= ~CONFIG_100BASEFX; PHY_WRITE(sc, MII_LXTPHY_CONFIG, cfg); } static void lxtphy_set_fx(struct mii_softc *sc) { int cfg; cfg = PHY_READ(sc, MII_LXTPHY_CONFIG); cfg |= CONFIG_100BASEFX; PHY_WRITE(sc, MII_LXTPHY_CONFIG, cfg); } Index: head/sys/dev/mii/mii_physubr.c =================================================================== --- head/sys/dev/mii/mii_physubr.c (revision 281820) +++ head/sys/dev/mii/mii_physubr.c (revision 281821) @@ -1,608 +1,676 @@ /* $NetBSD: mii_physubr.c,v 1.5 1999/08/03 19:41:49 drochner Exp $ */ /*- * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, * NASA Ames Research Center. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * Subroutines common to all PHYs. */ #include #include #include #include #include #include #include #include #include #include #include #include "miibus_if.h" /* - * Media to register setting conversion table. Order matters. + * + * An array of structures to map MII media types to BMCR/ANAR settings. */ -static const struct mii_media mii_media_table[MII_NMEDIA] = { +enum { + MII_MEDIA_NONE = 0, + MII_MEDIA_10_T, + MII_MEDIA_10_T_FDX, + MII_MEDIA_100_T4, + MII_MEDIA_100_TX, + MII_MEDIA_100_TX_FDX, + MII_MEDIA_1000_X, + MII_MEDIA_1000_X_FDX, + MII_MEDIA_1000_T, + MII_MEDIA_1000_T_FDX, + MII_NMEDIA, +}; + +static const struct mii_media { + u_int mm_bmcr; /* BMCR settings for this media */ + u_int mm_anar; /* ANAR settings for this media */ + u_int mm_gtcr; /* 100base-T2 or 1000base-T CR */ +} mii_media_table[MII_NMEDIA] = { /* None */ { BMCR_ISO, ANAR_CSMA, 0, }, /* 10baseT */ { BMCR_S10, ANAR_CSMA|ANAR_10, 0, }, /* 10baseT-FDX */ { BMCR_S10|BMCR_FDX, ANAR_CSMA|ANAR_10_FD, 0, }, /* 100baseT4 */ { BMCR_S100, ANAR_CSMA|ANAR_T4, 0, }, /* 100baseTX */ { BMCR_S100, ANAR_CSMA|ANAR_TX, 0, }, /* 100baseTX-FDX */ { BMCR_S100|BMCR_FDX, ANAR_CSMA|ANAR_TX_FD, 0, }, /* 1000baseX */ { BMCR_S1000, ANAR_CSMA, 0, }, /* 1000baseX-FDX */ { BMCR_S1000|BMCR_FDX, ANAR_CSMA, 0, }, /* 1000baseT */ { BMCR_S1000, ANAR_CSMA, GTCR_ADV_1000THDX }, /* 1000baseT-FDX */ { BMCR_S1000, ANAR_CSMA, GTCR_ADV_1000TFDX }, }; void mii_phy_setmedia(struct mii_softc *sc) { struct mii_data *mii = sc->mii_pdata; struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int bmcr, anar, gtcr; + int index = -1; - if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO) { + switch (IFM_SUBTYPE(ife->ifm_media)) { + case IFM_AUTO: /* * Force renegotiation if MIIF_DOPAUSE or MIIF_FORCEANEG. * The former is necessary as we might switch from flow- * control advertisement being off to on or vice versa. */ if ((PHY_READ(sc, MII_BMCR) & BMCR_AUTOEN) == 0 || (sc->mii_flags & (MIIF_DOPAUSE | MIIF_FORCEANEG)) != 0) (void)mii_phy_auto(sc); return; - } - /* - * Table index is stored in the media entry. - */ + case IFM_NONE: + index = MII_MEDIA_NONE; + break; - KASSERT(ife->ifm_data >=0 && ife->ifm_data < MII_NMEDIA, - ("invalid ife->ifm_data (0x%x) in mii_phy_setmedia", - ife->ifm_data)); + case IFM_HPNA_1: + index = MII_MEDIA_10_T; + break; - anar = mii_media_table[ife->ifm_data].mm_anar; - bmcr = mii_media_table[ife->ifm_data].mm_bmcr; - gtcr = mii_media_table[ife->ifm_data].mm_gtcr; + case IFM_10_T: + switch (IFM_OPTIONS(ife->ifm_media)) { + case 0: + index = MII_MEDIA_10_T; + break; + case IFM_FDX: + case (IFM_FDX | IFM_FLOW): + index = MII_MEDIA_10_T_FDX; + break; + }; + break; + case IFM_100_TX: + case IFM_100_FX: + switch (IFM_OPTIONS(ife->ifm_media)) { + case 0: + index = MII_MEDIA_100_TX; + break; + case IFM_FDX: + case (IFM_FDX | IFM_FLOW): + index = MII_MEDIA_100_TX_FDX; + break; + } + break; + + case IFM_100_T4: + index = MII_MEDIA_100_T4; + break; + + case IFM_1000_SX: + switch (IFM_OPTIONS(ife->ifm_media)) { + case 0: + index = MII_MEDIA_1000_X; + break; + case IFM_FDX: + case (IFM_FDX | IFM_FLOW): + index = MII_MEDIA_1000_X_FDX; + break; + } + break; + + case IFM_1000_T: + switch (IFM_OPTIONS(ife->ifm_media)) { + case 0: + case IFM_ETH_MASTER: + index = MII_MEDIA_1000_T; + break; + case IFM_FDX: + case (IFM_FDX | IFM_ETH_MASTER): + case (IFM_FDX | IFM_FLOW): + case (IFM_FDX | IFM_FLOW | IFM_ETH_MASTER): + index = MII_MEDIA_1000_T_FDX; + break; + } + break; + } + + KASSERT(index != -1, ("%s: failed to map media word %d", + __func__, ife->ifm_media)); + + anar = mii_media_table[index].mm_anar; + bmcr = mii_media_table[index].mm_bmcr; + gtcr = mii_media_table[index].mm_gtcr; + if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) { gtcr |= GTCR_MAN_MS; if ((ife->ifm_media & IFM_ETH_MASTER) != 0) gtcr |= GTCR_ADV_MS; } if ((ife->ifm_media & IFM_FDX) != 0 && ((ife->ifm_media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0)) { if ((sc->mii_flags & MIIF_IS_1000X) != 0) anar |= ANAR_X_PAUSE_TOWARDS; else { anar |= ANAR_FC; /* XXX Only 1000BASE-T has PAUSE_ASYM? */ if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0 && (sc->mii_extcapabilities & (EXTSR_1000THDX | EXTSR_1000TFDX)) != 0) anar |= ANAR_X_PAUSE_ASYM; } } PHY_WRITE(sc, MII_ANAR, anar); PHY_WRITE(sc, MII_BMCR, bmcr); if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0) PHY_WRITE(sc, MII_100T2CR, gtcr); } int mii_phy_auto(struct mii_softc *sc) { struct ifmedia_entry *ife = sc->mii_pdata->mii_media.ifm_cur; int anar, gtcr; /* * Check for 1000BASE-X. Autonegotiation is a bit * different on such devices. */ if ((sc->mii_flags & MIIF_IS_1000X) != 0) { anar = 0; if ((sc->mii_extcapabilities & EXTSR_1000XFDX) != 0) anar |= ANAR_X_FD; if ((sc->mii_extcapabilities & EXTSR_1000XHDX) != 0) anar |= ANAR_X_HD; if ((ife->ifm_media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0) anar |= ANAR_X_PAUSE_TOWARDS; PHY_WRITE(sc, MII_ANAR, anar); } else { anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA; if ((ife->ifm_media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0) { if ((sc->mii_capabilities & (BMSR_10TFDX | BMSR_100TXFDX)) != 0) anar |= ANAR_FC; /* XXX Only 1000BASE-T has PAUSE_ASYM? */ if (((sc->mii_flags & MIIF_HAVE_GTCR) != 0) && (sc->mii_extcapabilities & (EXTSR_1000THDX | EXTSR_1000TFDX)) != 0) anar |= ANAR_X_PAUSE_ASYM; } PHY_WRITE(sc, MII_ANAR, anar); if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0) { gtcr = 0; if ((sc->mii_extcapabilities & EXTSR_1000TFDX) != 0) gtcr |= GTCR_ADV_1000TFDX; if ((sc->mii_extcapabilities & EXTSR_1000THDX) != 0) gtcr |= GTCR_ADV_1000THDX; PHY_WRITE(sc, MII_100T2CR, gtcr); } } PHY_WRITE(sc, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG); return (EJUSTRETURN); } int mii_phy_tick(struct mii_softc *sc) { struct ifmedia_entry *ife = sc->mii_pdata->mii_media.ifm_cur; int reg; /* * If we're not doing autonegotiation, we don't need to do * any extra work here. However, we need to check the link * status so we can generate an announcement if the status * changes. */ if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) { sc->mii_ticks = 0; /* reset autonegotiation timer. */ return (0); } /* Read the status register twice; BMSR_LINK is latch-low. */ reg = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR); if ((reg & BMSR_LINK) != 0) { sc->mii_ticks = 0; /* reset autonegotiation timer. */ /* See above. */ return (0); } /* Announce link loss right after it happens */ if (sc->mii_ticks++ == 0) return (0); /* XXX: use default value if phy driver did not set mii_anegticks */ if (sc->mii_anegticks == 0) sc->mii_anegticks = MII_ANEGTICKS_GIGE; /* Only retry autonegotiation every mii_anegticks ticks. */ if (sc->mii_ticks <= sc->mii_anegticks) return (EJUSTRETURN); sc->mii_ticks = 0; PHY_RESET(sc); mii_phy_auto(sc); return (0); } void mii_phy_reset(struct mii_softc *sc) { struct ifmedia_entry *ife = sc->mii_pdata->mii_media.ifm_cur; int i, reg; if ((sc->mii_flags & MIIF_NOISOLATE) != 0) reg = BMCR_RESET; else reg = BMCR_RESET | BMCR_ISO; PHY_WRITE(sc, MII_BMCR, reg); /* Wait 100ms for it to complete. */ for (i = 0; i < 100; i++) { reg = PHY_READ(sc, MII_BMCR); if ((reg & BMCR_RESET) == 0) break; DELAY(1000); } /* NB: a PHY may default to being powered down and/or isolated. */ reg &= ~(BMCR_PDOWN | BMCR_ISO); if ((sc->mii_flags & MIIF_NOISOLATE) == 0 && ((ife == NULL && sc->mii_inst != 0) || (ife != NULL && IFM_INST(ife->ifm_media) != sc->mii_inst))) reg |= BMCR_ISO; if (PHY_READ(sc, MII_BMCR) != reg) PHY_WRITE(sc, MII_BMCR, reg); } void mii_phy_update(struct mii_softc *sc, int cmd) { struct mii_data *mii = sc->mii_pdata; if (sc->mii_media_active != mii->mii_media_active || cmd == MII_MEDIACHG) { MIIBUS_STATCHG(sc->mii_dev); sc->mii_media_active = mii->mii_media_active; } if (sc->mii_media_status != mii->mii_media_status) { MIIBUS_LINKCHG(sc->mii_dev); sc->mii_media_status = mii->mii_media_status; } } /* * Initialize generic PHY media based on BMSR, called when a PHY is * attached. We expect to be set up to print a comma-separated list * of media names. Does not print a newline. */ void mii_phy_add_media(struct mii_softc *sc) { struct mii_data *mii = sc->mii_pdata; const char *sep = ""; int fdx = 0; if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0 && (sc->mii_extcapabilities & EXTSR_MEDIAMASK) == 0) { printf("no media present"); return; } /* * Set the autonegotiation timer for 10/100 media. Gigabit media is * handled below. */ sc->mii_anegticks = MII_ANEGTICKS; -#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) +#define ADD(m) ifmedia_add(&mii->mii_media, (m), 0, NULL) #define PRINT(s) printf("%s%s", sep, s); sep = ", " if ((sc->mii_flags & MIIF_NOISOLATE) == 0) { - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst), - MII_MEDIA_NONE); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst)); PRINT("none"); } /* * There are different interpretations for the bits in * HomePNA PHYs. And there is really only one media type * that is supported. */ if ((sc->mii_flags & MIIF_IS_HPNA) != 0) { if ((sc->mii_capabilities & BMSR_10THDX) != 0) { ADD(IFM_MAKEWORD(IFM_ETHER, IFM_HPNA_1, 0, - sc->mii_inst), MII_MEDIA_10_T); + sc->mii_inst)); PRINT("HomePNA1"); } return; } if ((sc->mii_capabilities & BMSR_10THDX) != 0) { - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, sc->mii_inst), - MII_MEDIA_10_T); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, sc->mii_inst)); PRINT("10baseT"); } if ((sc->mii_capabilities & BMSR_10TFDX) != 0) { - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, IFM_FDX, sc->mii_inst), - MII_MEDIA_10_T_FDX); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, IFM_FDX, sc->mii_inst)); PRINT("10baseT-FDX"); if ((sc->mii_flags & MIIF_DOPAUSE) != 0 && (sc->mii_flags & MIIF_NOMANPAUSE) == 0) { ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, - IFM_FDX | IFM_FLOW, sc->mii_inst), - MII_MEDIA_10_T_FDX); + IFM_FDX | IFM_FLOW, sc->mii_inst)); PRINT("10baseT-FDX-flow"); } fdx = 1; } if ((sc->mii_capabilities & BMSR_100TXHDX) != 0) { - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, 0, sc->mii_inst), - MII_MEDIA_100_TX); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, 0, sc->mii_inst)); PRINT("100baseTX"); } if ((sc->mii_capabilities & BMSR_100TXFDX) != 0) { - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_FDX, sc->mii_inst), - MII_MEDIA_100_TX_FDX); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_FDX, sc->mii_inst)); PRINT("100baseTX-FDX"); if ((sc->mii_flags & MIIF_DOPAUSE) != 0 && (sc->mii_flags & MIIF_NOMANPAUSE) == 0) { ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, - IFM_FDX | IFM_FLOW, sc->mii_inst), - MII_MEDIA_100_TX_FDX); + IFM_FDX | IFM_FLOW, sc->mii_inst)); PRINT("100baseTX-FDX-flow"); } fdx = 1; } if ((sc->mii_capabilities & BMSR_100T4) != 0) { - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_T4, 0, sc->mii_inst), - MII_MEDIA_100_T4); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_T4, 0, sc->mii_inst)); PRINT("100baseT4"); } if ((sc->mii_extcapabilities & EXTSR_MEDIAMASK) != 0) { /* * XXX Right now only handle 1000SX and 1000TX. Need * XXX to handle 1000LX and 1000CX somehow. */ if ((sc->mii_extcapabilities & EXTSR_1000XHDX) != 0) { sc->mii_anegticks = MII_ANEGTICKS_GIGE; sc->mii_flags |= MIIF_IS_1000X; ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_SX, 0, - sc->mii_inst), MII_MEDIA_1000_X); + sc->mii_inst)); PRINT("1000baseSX"); } if ((sc->mii_extcapabilities & EXTSR_1000XFDX) != 0) { sc->mii_anegticks = MII_ANEGTICKS_GIGE; sc->mii_flags |= MIIF_IS_1000X; ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_SX, IFM_FDX, - sc->mii_inst), MII_MEDIA_1000_X_FDX); + sc->mii_inst)); PRINT("1000baseSX-FDX"); if ((sc->mii_flags & MIIF_DOPAUSE) != 0 && (sc->mii_flags & MIIF_NOMANPAUSE) == 0) { ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_SX, - IFM_FDX | IFM_FLOW, sc->mii_inst), - MII_MEDIA_1000_X_FDX); + IFM_FDX | IFM_FLOW, sc->mii_inst)); PRINT("1000baseSX-FDX-flow"); } fdx = 1; } /* * 1000baseT media needs to be able to manipulate * master/slave mode. * * All 1000baseT PHYs have a 1000baseT control register. */ if ((sc->mii_extcapabilities & EXTSR_1000THDX) != 0) { sc->mii_anegticks = MII_ANEGTICKS_GIGE; sc->mii_flags |= MIIF_HAVE_GTCR; ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_T, 0, - sc->mii_inst), MII_MEDIA_1000_T); + sc->mii_inst)); PRINT("1000baseT"); ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_T, - IFM_ETH_MASTER, sc->mii_inst), MII_MEDIA_1000_T); + IFM_ETH_MASTER, sc->mii_inst)); PRINT("1000baseT-master"); } if ((sc->mii_extcapabilities & EXTSR_1000TFDX) != 0) { sc->mii_anegticks = MII_ANEGTICKS_GIGE; sc->mii_flags |= MIIF_HAVE_GTCR; ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_T, IFM_FDX, - sc->mii_inst), MII_MEDIA_1000_T_FDX); + sc->mii_inst)); PRINT("1000baseT-FDX"); ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_T, - IFM_FDX | IFM_ETH_MASTER, sc->mii_inst), - MII_MEDIA_1000_T_FDX); + IFM_FDX | IFM_ETH_MASTER, sc->mii_inst)); PRINT("1000baseT-FDX-master"); if ((sc->mii_flags & MIIF_DOPAUSE) != 0 && (sc->mii_flags & MIIF_NOMANPAUSE) == 0) { ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_T, - IFM_FDX | IFM_FLOW, sc->mii_inst), - MII_MEDIA_1000_T_FDX); + IFM_FDX | IFM_FLOW, sc->mii_inst)); PRINT("1000baseT-FDX-flow"); ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_T, IFM_FDX | IFM_FLOW | IFM_ETH_MASTER, - sc->mii_inst), MII_MEDIA_1000_T_FDX); + sc->mii_inst)); PRINT("1000baseT-FDX-flow-master"); } fdx = 1; } } if ((sc->mii_capabilities & BMSR_ANEG) != 0) { /* intentionally invalid index */ - ADD(IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, sc->mii_inst), - MII_NMEDIA); + ADD(IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, sc->mii_inst)); PRINT("auto"); if (fdx != 0 && (sc->mii_flags & MIIF_DOPAUSE) != 0) { ADD(IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, IFM_FLOW, - sc->mii_inst), MII_NMEDIA); + sc->mii_inst)); PRINT("auto-flow"); } } #undef ADD #undef PRINT } int mii_phy_detach(device_t dev) { struct mii_softc *sc; sc = device_get_softc(dev); sc->mii_dev = NULL; LIST_REMOVE(sc, mii_list); return (0); } const struct mii_phydesc * mii_phy_match_gen(const struct mii_attach_args *ma, const struct mii_phydesc *mpd, size_t len) { for (; mpd->mpd_name != NULL; mpd = (const struct mii_phydesc *)((const char *)mpd + len)) { if (MII_OUI(ma->mii_id1, ma->mii_id2) == mpd->mpd_oui && MII_MODEL(ma->mii_id2) == mpd->mpd_model) return (mpd); } return (NULL); } const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma, const struct mii_phydesc *mpd) { return (mii_phy_match_gen(ma, mpd, sizeof(struct mii_phydesc))); } int mii_phy_dev_probe(device_t dev, const struct mii_phydesc *mpd, int mrv) { mpd = mii_phy_match(device_get_ivars(dev), mpd); if (mpd != NULL) { device_set_desc(dev, mpd->mpd_name); return (mrv); } return (ENXIO); } void mii_phy_dev_attach(device_t dev, u_int flags, const struct mii_phy_funcs *mpf, int add_media) { struct mii_softc *sc; struct mii_attach_args *ma; struct mii_data *mii; sc = device_get_softc(dev); ma = device_get_ivars(dev); sc->mii_dev = device_get_parent(dev); mii = ma->mii_data; LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); sc->mii_flags = flags | miibus_get_flags(dev); sc->mii_mpd_oui = MII_OUI(ma->mii_id1, ma->mii_id2); sc->mii_mpd_model = MII_MODEL(ma->mii_id2); sc->mii_mpd_rev = MII_REV(ma->mii_id2); sc->mii_capmask = ma->mii_capmask; sc->mii_inst = mii->mii_instance++; sc->mii_phy = ma->mii_phyno; sc->mii_offset = ma->mii_offset; sc->mii_funcs = mpf; sc->mii_pdata = mii; if (bootverbose) device_printf(dev, "OUI 0x%06x, model 0x%04x, rev. %d\n", sc->mii_mpd_oui, sc->mii_mpd_model, sc->mii_mpd_rev); if (add_media == 0) return; PHY_RESET(sc); sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & sc->mii_capmask; if (sc->mii_capabilities & BMSR_EXTSTAT) sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR); device_printf(dev, " "); mii_phy_add_media(sc); printf("\n"); MIIBUS_MEDIAINIT(sc->mii_dev); } /* * Return the flow control status flag from MII_ANAR & MII_ANLPAR. */ u_int mii_phy_flowstatus(struct mii_softc *sc) { int anar, anlpar; if ((sc->mii_flags & MIIF_DOPAUSE) == 0) return (0); anar = PHY_READ(sc, MII_ANAR); anlpar = PHY_READ(sc, MII_ANLPAR); /* * Check for 1000BASE-X. Autonegotiation is a bit * different on such devices. */ if ((sc->mii_flags & MIIF_IS_1000X) != 0) { anar <<= 3; anlpar <<= 3; } if ((anar & ANAR_PAUSE_SYM) != 0 && (anlpar & ANLPAR_PAUSE_SYM) != 0) return (IFM_FLOW | IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE); if ((anar & ANAR_PAUSE_SYM) == 0) { if ((anar & ANAR_PAUSE_ASYM) != 0 && (anlpar & ANLPAR_PAUSE_TOWARDS) != 0) return (IFM_FLOW | IFM_ETH_TXPAUSE); else return (0); } if ((anar & ANAR_PAUSE_ASYM) == 0) { if ((anlpar & ANLPAR_PAUSE_SYM) != 0) return (IFM_FLOW | IFM_ETH_TXPAUSE | IFM_ETH_RXPAUSE); else return (0); } switch ((anlpar & ANLPAR_PAUSE_TOWARDS)) { case ANLPAR_PAUSE_NONE: return (0); case ANLPAR_PAUSE_ASYM: return (IFM_FLOW | IFM_ETH_RXPAUSE); default: return (IFM_FLOW | IFM_ETH_RXPAUSE | IFM_ETH_TXPAUSE); } /* NOTREACHED */ } Index: head/sys/dev/mii/miivar.h =================================================================== --- head/sys/dev/mii/miivar.h (revision 281820) +++ head/sys/dev/mii/miivar.h (revision 281821) @@ -1,272 +1,251 @@ /* $NetBSD: miivar.h,v 1.8 1999/04/23 04:24:32 thorpej Exp $ */ /*- * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, * NASA Ames Research Center. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _DEV_MII_MIIVAR_H_ #define _DEV_MII_MIIVAR_H_ #include #include /* XXX driver API temporary */ /* * Media Independent Interface data structure defintions */ struct mii_softc; /* * A network interface driver has one of these structures in its softc. * It is the interface from the network interface driver to the MII * layer. */ struct mii_data { struct ifmedia mii_media; /* media information */ if_t mii_ifp; /* pointer back to network interface */ /* * For network interfaces with multiple PHYs, a list of all * PHYs is required so they can all be notified when a media * request is made. */ LIST_HEAD(mii_listhead, mii_softc) mii_phys; u_int mii_instance; /* * PHY driver fills this in with active media status. */ u_int mii_media_status; u_int mii_media_active; }; typedef struct mii_data mii_data_t; /* * Functions provided by the PHY to perform various functions. */ struct mii_phy_funcs { int (*pf_service)(struct mii_softc *, struct mii_data *, int); void (*pf_status)(struct mii_softc *); void (*pf_reset)(struct mii_softc *); }; /* * Requests that can be made to the downcall. */ #define MII_TICK 1 /* once-per-second tick */ #define MII_MEDIACHG 2 /* user changed media; perform the switch */ #define MII_POLLSTAT 3 /* user requested media status; fill it in */ /* * Each PHY driver's softc has one of these as the first member. * XXX This would be better named "phy_softc", but this is the name * XXX BSDI used, and we would like to have the same interface. */ struct mii_softc { device_t mii_dev; /* generic device glue */ LIST_ENTRY(mii_softc) mii_list; /* entry on parent's PHY list */ uint32_t mii_mpd_oui; /* the PHY's OUI (MII_OUI())*/ uint32_t mii_mpd_model; /* the PHY's model (MII_MODEL())*/ uint32_t mii_mpd_rev; /* the PHY's revision (MII_REV())*/ u_int mii_capmask; /* capability mask for BMSR */ u_int mii_phy; /* our MII address */ u_int mii_offset; /* first PHY, second PHY, etc. */ u_int mii_inst; /* instance for ifmedia */ /* Our PHY functions. */ const struct mii_phy_funcs *mii_funcs; struct mii_data *mii_pdata; /* pointer to parent's mii_data */ u_int mii_flags; /* misc. flags; see below */ u_int mii_capabilities; /* capabilities from BMSR */ u_int mii_extcapabilities; /* extended capabilities */ u_int mii_ticks; /* MII_TICK counter */ u_int mii_anegticks; /* ticks before retrying aneg */ u_int mii_media_active; /* last active media */ u_int mii_media_status; /* last active status */ }; typedef struct mii_softc mii_softc_t; /* mii_flags */ #define MIIF_INITDONE 0x00000001 /* has been initialized (mii_data) */ #define MIIF_NOISOLATE 0x00000002 /* do not isolate the PHY */ #if 0 #define MIIF_NOLOOP 0x00000004 /* no loopback capability */ #endif #define MIIF_DOINGAUTO 0x00000008 /* doing autonegotiation (mii_softc) */ #define MIIF_AUTOTSLEEP 0x00000010 /* use tsleep(), not callout() */ #define MIIF_HAVEFIBER 0x00000020 /* from parent: has fiber interface */ #define MIIF_HAVE_GTCR 0x00000040 /* has 100base-T2/1000base-T CR */ #define MIIF_IS_1000X 0x00000080 /* is a 1000BASE-X device */ #define MIIF_DOPAUSE 0x00000100 /* advertise PAUSE capability */ #define MIIF_IS_HPNA 0x00000200 /* is a HomePNA device */ #define MIIF_FORCEANEG 0x00000400 /* force auto-negotiation */ #define MIIF_NOMANPAUSE 0x00100000 /* no manual PAUSE selection */ #define MIIF_FORCEPAUSE 0x00200000 /* force PAUSE advertisement */ #define MIIF_MACPRIV0 0x01000000 /* private to the MAC driver */ #define MIIF_MACPRIV1 0x02000000 /* private to the MAC driver */ #define MIIF_MACPRIV2 0x04000000 /* private to the MAC driver */ #define MIIF_PHYPRIV0 0x10000000 /* private to the PHY driver */ #define MIIF_PHYPRIV1 0x20000000 /* private to the PHY driver */ #define MIIF_PHYPRIV2 0x40000000 /* private to the PHY driver */ /* Default mii_anegticks values */ #define MII_ANEGTICKS 5 #define MII_ANEGTICKS_GIGE 17 #define MIIF_INHERIT_MASK (MIIF_NOISOLATE|MIIF_NOLOOP|MIIF_AUTOTSLEEP) /* * Special `locators' passed to mii_attach(). If one of these is not * an `any' value, we look for *that* PHY and configure it. If both * are not `any', that is an error, and mii_attach() will fail. */ #define MII_OFFSET_ANY -1 #define MII_PHY_ANY -1 /* * Used to attach a PHY to a parent. */ struct mii_attach_args { struct mii_data *mii_data; /* pointer to parent data */ u_int mii_phyno; /* MII address */ u_int mii_offset; /* first PHY, second PHY, etc. */ uint32_t mii_id1; /* PHY ID register 1 */ uint32_t mii_id2; /* PHY ID register 2 */ u_int mii_capmask; /* capability mask for BMSR */ }; typedef struct mii_attach_args mii_attach_args_t; /* * Used to match a PHY. */ struct mii_phydesc { uint32_t mpd_oui; /* the PHY's OUI */ uint32_t mpd_model; /* the PHY's model */ const char *mpd_name; /* the PHY's name */ }; #define MII_PHY_DESC(a, b) { MII_OUI_ ## a, MII_MODEL_ ## a ## _ ## b, \ MII_STR_ ## a ## _ ## b } #define MII_PHY_END { 0, 0, NULL } -/* - * An array of these structures map MII media types to BMCR/ANAR settings. - */ -struct mii_media { - u_int mm_bmcr; /* BMCR settings for this media */ - u_int mm_anar; /* ANAR settings for this media */ - u_int mm_gtcr; /* 100base-T2 or 1000base-T CR */ -}; - -#define MII_MEDIA_NONE 0 -#define MII_MEDIA_10_T 1 -#define MII_MEDIA_10_T_FDX 2 -#define MII_MEDIA_100_T4 3 -#define MII_MEDIA_100_TX 4 -#define MII_MEDIA_100_TX_FDX 5 -#define MII_MEDIA_1000_X 6 -#define MII_MEDIA_1000_X_FDX 7 -#define MII_MEDIA_1000_T 8 -#define MII_MEDIA_1000_T_FDX 9 -#define MII_NMEDIA 10 - #ifdef _KERNEL #define PHY_READ(p, r) \ MIIBUS_READREG((p)->mii_dev, (p)->mii_phy, (r)) #define PHY_WRITE(p, r, v) \ MIIBUS_WRITEREG((p)->mii_dev, (p)->mii_phy, (r), (v)) #define PHY_SERVICE(p, d, o) \ (*(p)->mii_funcs->pf_service)((p), (d), (o)) #define PHY_STATUS(p) \ (*(p)->mii_funcs->pf_status)(p) #define PHY_RESET(p) \ (*(p)->mii_funcs->pf_reset)(p) enum miibus_device_ivars { MIIBUS_IVAR_FLAGS }; /* * Simplified accessors for miibus */ #define MIIBUS_ACCESSOR(var, ivar, type) \ __BUS_ACCESSOR(miibus, var, MIIBUS, ivar, type) MIIBUS_ACCESSOR(flags, FLAGS, u_int) extern devclass_t miibus_devclass; extern driver_t miibus_driver; int mii_attach(device_t, device_t *, if_t, ifm_change_cb_t, ifm_stat_cb_t, int, int, int, int); int mii_mediachg(struct mii_data *); void mii_tick(struct mii_data *); void mii_pollstat(struct mii_data *); void mii_phy_add_media(struct mii_softc *); int mii_phy_auto(struct mii_softc *); int mii_phy_detach(device_t dev); u_int mii_phy_flowstatus(struct mii_softc *); void mii_phy_reset(struct mii_softc *); void mii_phy_setmedia(struct mii_softc *sc); void mii_phy_update(struct mii_softc *, int); int mii_phy_tick(struct mii_softc *); int mii_phy_mac_match(struct mii_softc *, const char *); int mii_dev_mac_match(device_t, const char *); void *mii_phy_mac_softc(struct mii_softc *); void *mii_dev_mac_softc(device_t); const struct mii_phydesc * mii_phy_match(const struct mii_attach_args *ma, const struct mii_phydesc *mpd); const struct mii_phydesc * mii_phy_match_gen(const struct mii_attach_args *ma, const struct mii_phydesc *mpd, size_t endlen); int mii_phy_dev_probe(device_t dev, const struct mii_phydesc *mpd, int mrv); void mii_phy_dev_attach(device_t dev, u_int flags, const struct mii_phy_funcs *mpf, int add_media); void ukphy_status(struct mii_softc *); u_int mii_oui(u_int, u_int); #define MII_OUI(id1, id2) mii_oui(id1, id2) #define MII_MODEL(id2) (((id2) & IDR2_MODEL) >> 4) #define MII_REV(id2) ((id2) & IDR2_REV) #endif /* _KERNEL */ #endif /* _DEV_MII_MIIVAR_H_ */