1d0027533SBill Paul /* $NetBSD: nsphy.c,v 1.18 1999/07/14 23:57:36 thorpej Exp $ */ 2d0027533SBill Paul 3d0027533SBill Paul /*- 4d0027533SBill Paul * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 5d0027533SBill Paul * All rights reserved. 6d0027533SBill Paul * 7d0027533SBill Paul * This code is derived from software contributed to The NetBSD Foundation 8d0027533SBill Paul * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9d0027533SBill Paul * NASA Ames Research Center. 10d0027533SBill Paul * 11d0027533SBill Paul * Redistribution and use in source and binary forms, with or without 12d0027533SBill Paul * modification, are permitted provided that the following conditions 13d0027533SBill Paul * are met: 14d0027533SBill Paul * 1. Redistributions of source code must retain the above copyright 15d0027533SBill Paul * notice, this list of conditions and the following disclaimer. 16d0027533SBill Paul * 2. Redistributions in binary form must reproduce the above copyright 17d0027533SBill Paul * notice, this list of conditions and the following disclaimer in the 18d0027533SBill Paul * documentation and/or other materials provided with the distribution. 19d0027533SBill Paul * 3. All advertising materials mentioning features or use of this software 20d0027533SBill Paul * must display the following acknowledgement: 21d0027533SBill Paul * This product includes software developed by the NetBSD 22d0027533SBill Paul * Foundation, Inc. and its contributors. 23d0027533SBill Paul * 4. Neither the name of The NetBSD Foundation nor the names of its 24d0027533SBill Paul * contributors may be used to endorse or promote products derived 25d0027533SBill Paul * from this software without specific prior written permission. 26d0027533SBill Paul * 27d0027533SBill Paul * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28d0027533SBill Paul * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29d0027533SBill Paul * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30d0027533SBill Paul * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31d0027533SBill Paul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32d0027533SBill Paul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33d0027533SBill Paul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34d0027533SBill Paul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35d0027533SBill Paul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36d0027533SBill Paul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37d0027533SBill Paul * POSSIBILITY OF SUCH DAMAGE. 38d0027533SBill Paul */ 39d0027533SBill Paul 40098ca2bdSWarner Losh /*- 41d0027533SBill Paul * Copyright (c) 1997 Manuel Bouyer. All rights reserved. 42d0027533SBill Paul * 43d0027533SBill Paul * Redistribution and use in source and binary forms, with or without 44d0027533SBill Paul * modification, are permitted provided that the following conditions 45d0027533SBill Paul * are met: 46d0027533SBill Paul * 1. Redistributions of source code must retain the above copyright 47d0027533SBill Paul * notice, this list of conditions and the following disclaimer. 48d0027533SBill Paul * 2. Redistributions in binary form must reproduce the above copyright 49d0027533SBill Paul * notice, this list of conditions and the following disclaimer in the 50d0027533SBill Paul * documentation and/or other materials provided with the distribution. 51d0027533SBill Paul * 3. All advertising materials mentioning features or use of this software 52d0027533SBill Paul * must display the following acknowledgement: 53d0027533SBill Paul * This product includes software developed by Manuel Bouyer. 54d0027533SBill Paul * 4. The name of the author may not be used to endorse or promote products 55d0027533SBill Paul * derived from this software without specific prior written permission. 56d0027533SBill Paul * 57d0027533SBill Paul * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 58d0027533SBill Paul * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 59d0027533SBill Paul * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 60d0027533SBill Paul * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 61d0027533SBill Paul * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 62d0027533SBill Paul * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 63d0027533SBill Paul * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 64d0027533SBill Paul * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 65d0027533SBill Paul * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 66d0027533SBill Paul * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 67d0027533SBill Paul */ 68d0027533SBill Paul 6950aa1061SMarius Strobl #include <sys/cdefs.h> 7050aa1061SMarius Strobl __FBSDID("$FreeBSD$"); 7150aa1061SMarius Strobl 72d0027533SBill Paul /* 73d0027533SBill Paul * driver for National Semiconductor's DP83840A ethernet 10/100 PHY 74d0027533SBill Paul * Data Sheet available from www.national.com 75d0027533SBill Paul */ 76d0027533SBill Paul 77d0027533SBill Paul #include <sys/param.h> 78d0027533SBill Paul #include <sys/systm.h> 79d0027533SBill Paul #include <sys/kernel.h> 80d0027533SBill Paul #include <sys/socket.h> 81d0027533SBill Paul #include <sys/errno.h> 82d0027533SBill Paul #include <sys/module.h> 83d0027533SBill Paul #include <sys/bus.h> 84d0027533SBill Paul 85d0027533SBill Paul #include <net/if.h> 86d0027533SBill Paul #include <net/if_media.h> 87d0027533SBill Paul 88d0027533SBill Paul #include <dev/mii/mii.h> 89d0027533SBill Paul #include <dev/mii/miivar.h> 902d3ce713SDavid E. O'Brien #include "miidevs.h" 91d0027533SBill Paul 92d0027533SBill Paul #include <dev/mii/nsphyreg.h> 93d0027533SBill Paul 94d0027533SBill Paul #include "miibus_if.h" 95d0027533SBill Paul 96e51a25f8SAlfred Perlstein static int nsphy_probe(device_t); 97e51a25f8SAlfred Perlstein static int nsphy_attach(device_t); 98d0027533SBill Paul 99d0027533SBill Paul static device_method_t nsphy_methods[] = { 100d0027533SBill Paul /* device interface */ 101d0027533SBill Paul DEVMETHOD(device_probe, nsphy_probe), 102d0027533SBill Paul DEVMETHOD(device_attach, nsphy_attach), 103279fe8d1SPoul-Henning Kamp DEVMETHOD(device_detach, mii_phy_detach), 104d0027533SBill Paul DEVMETHOD(device_shutdown, bus_generic_shutdown), 105d0027533SBill Paul { 0, 0 } 106d0027533SBill Paul }; 107d0027533SBill Paul 108d0027533SBill Paul static devclass_t nsphy_devclass; 109d0027533SBill Paul 110d0027533SBill Paul static driver_t nsphy_driver = { 111d0027533SBill Paul "nsphy", 112d0027533SBill Paul nsphy_methods, 113d0027533SBill Paul sizeof(struct mii_softc) 114d0027533SBill Paul }; 115d0027533SBill Paul 116d0027533SBill Paul DRIVER_MODULE(nsphy, miibus, nsphy_driver, nsphy_devclass, 0, 0); 117d0027533SBill Paul 118e51a25f8SAlfred Perlstein static int nsphy_service(struct mii_softc *, struct mii_data *, int); 119e51a25f8SAlfred Perlstein static void nsphy_status(struct mii_softc *); 120fb58dc87SMarius Strobl static void nsphy_reset(struct mii_softc *); 121d0027533SBill Paul 122a35b9333SMarius Strobl static const struct mii_phydesc nsphys[] = { 123a35b9333SMarius Strobl MII_PHY_DESC(NATSEMI, DP83840), 124a35b9333SMarius Strobl MII_PHY_END 125a35b9333SMarius Strobl }; 126a35b9333SMarius Strobl 1279c1c2e99SAlfred Perlstein static int 1287d830ac9SWarner Losh nsphy_probe(device_t dev) 129d0027533SBill Paul { 130d0027533SBill Paul 131a35b9333SMarius Strobl return (mii_phy_dev_probe(dev, nsphys, BUS_PROBE_DEFAULT)); 132d0027533SBill Paul } 133d0027533SBill Paul 1349c1c2e99SAlfred Perlstein static int 1357d830ac9SWarner Losh nsphy_attach(device_t dev) 136d0027533SBill Paul { 137d0027533SBill Paul struct mii_softc *sc; 138d0027533SBill Paul struct mii_attach_args *ma; 139d0027533SBill Paul struct mii_data *mii; 140fb58dc87SMarius Strobl const char *nic; 141d0027533SBill Paul 142d0027533SBill Paul sc = device_get_softc(dev); 143d0027533SBill Paul ma = device_get_ivars(dev); 144d0027533SBill Paul sc->mii_dev = device_get_parent(dev); 145d0027533SBill Paul mii = device_get_softc(sc->mii_dev); 146d0027533SBill Paul LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); 147d0027533SBill Paul 148d0027533SBill Paul sc->mii_inst = mii->mii_instance; 149d0027533SBill Paul sc->mii_phy = ma->mii_phyno; 150d0027533SBill Paul sc->mii_service = nsphy_service; 151d0027533SBill Paul sc->mii_pdata = mii; 152d0027533SBill Paul 153d0027533SBill Paul mii->mii_instance++; 154d0027533SBill Paul 155fb58dc87SMarius Strobl nic = device_get_name(device_get_parent(sc->mii_dev)); 156fb58dc87SMarius Strobl /* 157fb58dc87SMarius Strobl * Am79C971 and i82557 wedge when isolating all of their 158fb58dc87SMarius Strobl * (external) PHYs. 159fb58dc87SMarius Strobl */ 160fb58dc87SMarius Strobl if (strcmp(nic, "fxp") == 0 || strcmp(nic, "pcn") == 0) 161fb58dc87SMarius Strobl sc->mii_flags |= MIIF_NOISOLATE; 162fb58dc87SMarius Strobl 163fb58dc87SMarius Strobl /* 164fb58dc87SMarius Strobl * DP83840A used with HME chips don't advertise their media 165fb58dc87SMarius Strobl * capabilities themselves properly so force writing the ANAR 166fb58dc87SMarius Strobl * according to the BMSR in mii_phy_setmedia(). 167fb58dc87SMarius Strobl */ 168fb58dc87SMarius Strobl if (strcmp(nic, "hme") == 0) 169fb58dc87SMarius Strobl sc->mii_flags |= MIIF_FORCEANEG; 170fb58dc87SMarius Strobl 171d0027533SBill Paul #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) 172d0027533SBill Paul 173fb58dc87SMarius Strobl /* 174fb58dc87SMarius Strobl * In order for MII loopback to work Am79C971 and greater PCnet 175fb58dc87SMarius Strobl * chips additionally need to be placed into external loopback 176fb58dc87SMarius Strobl * mode which pcn(4) doesn't do so far. 177fb58dc87SMarius Strobl */ 178fb58dc87SMarius Strobl if (strcmp(nic, "pcn") != 0) 179fb58dc87SMarius Strobl #if 1 180fb58dc87SMarius Strobl ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, 1813d7c219dSMarius Strobl sc->mii_inst), MII_MEDIA_100_TX); 182fb58dc87SMarius Strobl #else 183fb58dc87SMarius Strobl if (strcmp(nic, "pcn") == 0) 184fb58dc87SMarius Strobl sc->mii_flags |= MIIF_NOLOOP; 185d0027533SBill Paul #endif 186d0027533SBill Paul 187fb58dc87SMarius Strobl nsphy_reset(sc); 188d0027533SBill Paul 189d0027533SBill Paul sc->mii_capabilities = 190d0027533SBill Paul PHY_READ(sc, MII_BMSR) & ma->mii_capmask; 191d0027533SBill Paul device_printf(dev, " "); 192fb58dc87SMarius Strobl mii_phy_add_media(sc); 193d0027533SBill Paul printf("\n"); 194d0027533SBill Paul #undef ADD 195d0027533SBill Paul 196d0027533SBill Paul MIIBUS_MEDIAINIT(sc->mii_dev); 197d0027533SBill Paul return (0); 198d0027533SBill Paul } 199d0027533SBill Paul 200d9730b8bSJonathan Lemon static int 2017d830ac9SWarner Losh nsphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) 202d0027533SBill Paul { 203d0027533SBill Paul struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 204d0027533SBill Paul int reg; 205d0027533SBill Paul 206d0027533SBill Paul switch (cmd) { 207d0027533SBill Paul case MII_POLLSTAT: 208d0027533SBill Paul /* 209d0027533SBill Paul * If we're not polling our PHY instance, just return. 210d0027533SBill Paul */ 211d0027533SBill Paul if (IFM_INST(ife->ifm_media) != sc->mii_inst) 212d0027533SBill Paul return (0); 213d0027533SBill Paul break; 214d0027533SBill Paul 215d0027533SBill Paul case MII_MEDIACHG: 216d0027533SBill Paul /* 217d0027533SBill Paul * If the media indicates a different PHY instance, 218d0027533SBill Paul * isolate ourselves. 219d0027533SBill Paul */ 220d0027533SBill Paul if (IFM_INST(ife->ifm_media) != sc->mii_inst) { 221d0027533SBill Paul reg = PHY_READ(sc, MII_BMCR); 222d0027533SBill Paul PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO); 223d0027533SBill Paul return (0); 224d0027533SBill Paul } 225d0027533SBill Paul 226d0027533SBill Paul /* 227d0027533SBill Paul * If the interface is not up, don't do anything. 228d0027533SBill Paul */ 229d0027533SBill Paul if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 230d0027533SBill Paul break; 231d0027533SBill Paul 232d0027533SBill Paul reg = PHY_READ(sc, MII_NSPHY_PCR); 233d0027533SBill Paul 234d0027533SBill Paul /* 235d0027533SBill Paul * Set up the PCR to use LED4 to indicate full-duplex 236d0027533SBill Paul * in both 10baseT and 100baseTX modes. 237d0027533SBill Paul */ 238d0027533SBill Paul reg |= PCR_LED4MODE; 239d0027533SBill Paul 240d0027533SBill Paul /* 2415aa54809SMarius Strobl * Make sure Carrier Integrity Monitor function is 242d0027533SBill Paul * disabled (normal for Node operation, but sometimes 243d0027533SBill Paul * it's not set?!) 244d0027533SBill Paul */ 245d0027533SBill Paul reg |= PCR_CIMDIS; 246d0027533SBill Paul 247d0027533SBill Paul /* 248d0027533SBill Paul * Make sure "force link good" is set to normal mode. 249d0027533SBill Paul * It's only intended for debugging. 250d0027533SBill Paul */ 251d0027533SBill Paul reg |= PCR_FLINK100; 252d0027533SBill Paul 253d0027533SBill Paul /* 254d0027533SBill Paul * Mystery bits which are supposedly `reserved', 255d0027533SBill Paul * but we seem to need to set them when the PHY 25632de04d5SJonathan Lemon * is connected to some interfaces: 25732de04d5SJonathan Lemon * 25832de04d5SJonathan Lemon * 0x0400 is needed for fxp 25932de04d5SJonathan Lemon * (Intel EtherExpress Pro 10+/100B, 82557 chip) 26032de04d5SJonathan Lemon * (nsphy with a DP83840 chip) 26132de04d5SJonathan Lemon * 0x0100 may be needed for some other card 262d0027533SBill Paul */ 263d0027533SBill Paul reg |= 0x0100 | 0x0400; 26432de04d5SJonathan Lemon 265fb58dc87SMarius Strobl if (strcmp(mii->mii_ifp->if_dname, "fxp") == 0) 266d0027533SBill Paul PHY_WRITE(sc, MII_NSPHY_PCR, reg); 26732de04d5SJonathan Lemon 268fb58dc87SMarius Strobl mii_phy_setmedia(sc); 269d0027533SBill Paul break; 270d0027533SBill Paul 271d0027533SBill Paul case MII_TICK: 272d0027533SBill Paul /* 273d0027533SBill Paul * If we're not currently selected, just return. 274d0027533SBill Paul */ 275d0027533SBill Paul if (IFM_INST(ife->ifm_media) != sc->mii_inst) 276d0027533SBill Paul return (0); 277d9730b8bSJonathan Lemon if (mii_phy_tick(sc) == EJUSTRETURN) 278d0027533SBill Paul return (0); 279d0027533SBill Paul break; 280d0027533SBill Paul } 281d0027533SBill Paul 282d0027533SBill Paul /* Update the media status. */ 283d0027533SBill Paul nsphy_status(sc); 284d0027533SBill Paul 285d0027533SBill Paul /* Callback if something changed. */ 286d9730b8bSJonathan Lemon mii_phy_update(sc, cmd); 287d0027533SBill Paul return (0); 288d0027533SBill Paul } 289d0027533SBill Paul 290d9730b8bSJonathan Lemon static void 2917d830ac9SWarner Losh nsphy_status(struct mii_softc *sc) 292d0027533SBill Paul { 293d0027533SBill Paul struct mii_data *mii = sc->mii_pdata; 294fb58dc87SMarius Strobl struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 295d0027533SBill Paul int bmsr, bmcr, par, anlpar; 296d0027533SBill Paul 297d0027533SBill Paul mii->mii_media_status = IFM_AVALID; 298d0027533SBill Paul mii->mii_media_active = IFM_ETHER; 299d0027533SBill Paul 300d0027533SBill Paul bmsr = PHY_READ(sc, MII_BMSR) | 301d0027533SBill Paul PHY_READ(sc, MII_BMSR); 302d0027533SBill Paul if (bmsr & BMSR_LINK) 303d0027533SBill Paul mii->mii_media_status |= IFM_ACTIVE; 304d0027533SBill Paul 305d0027533SBill Paul bmcr = PHY_READ(sc, MII_BMCR); 306d0027533SBill Paul if (bmcr & BMCR_ISO) { 307d0027533SBill Paul mii->mii_media_active |= IFM_NONE; 308d0027533SBill Paul mii->mii_media_status = 0; 309d0027533SBill Paul return; 310d0027533SBill Paul } 311d0027533SBill Paul 312d0027533SBill Paul if (bmcr & BMCR_LOOP) 313d0027533SBill Paul mii->mii_media_active |= IFM_LOOP; 314d0027533SBill Paul 315d0027533SBill Paul if (bmcr & BMCR_AUTOEN) { 316d0027533SBill Paul /* 317d0027533SBill Paul * The PAR status bits are only valid of autonegotiation 318d0027533SBill Paul * has completed (or it's disabled). 319d0027533SBill Paul */ 320d0027533SBill Paul if ((bmsr & BMSR_ACOMP) == 0) { 321d0027533SBill Paul /* Erg, still trying, I guess... */ 322d0027533SBill Paul mii->mii_media_active |= IFM_NONE; 323d0027533SBill Paul return; 324d0027533SBill Paul } 325d0027533SBill Paul 326d0027533SBill Paul /* 327d0027533SBill Paul * Argh. The PAR doesn't seem to indicate duplex mode 328d0027533SBill Paul * properly! Determine media based on link partner's 329d0027533SBill Paul * advertised capabilities. 330d0027533SBill Paul */ 331d0027533SBill Paul if (PHY_READ(sc, MII_ANER) & ANER_LPAN) { 332d0027533SBill Paul anlpar = PHY_READ(sc, MII_ANAR) & 333d0027533SBill Paul PHY_READ(sc, MII_ANLPAR); 334d612cc59SPyun YongHyeon if (anlpar & ANLPAR_TX_FD) 335d0027533SBill Paul mii->mii_media_active |= IFM_100_TX|IFM_FDX; 336d612cc59SPyun YongHyeon else if (anlpar & ANLPAR_T4) 337d612cc59SPyun YongHyeon mii->mii_media_active |= IFM_100_T4; 338d0027533SBill Paul else if (anlpar & ANLPAR_TX) 339d0027533SBill Paul mii->mii_media_active |= IFM_100_TX; 340d0027533SBill Paul else if (anlpar & ANLPAR_10_FD) 341d0027533SBill Paul mii->mii_media_active |= IFM_10_T|IFM_FDX; 342d0027533SBill Paul else if (anlpar & ANLPAR_10) 343d0027533SBill Paul mii->mii_media_active |= IFM_10_T; 344d0027533SBill Paul else 345d0027533SBill Paul mii->mii_media_active |= IFM_NONE; 346d0027533SBill Paul return; 347d0027533SBill Paul } 348d0027533SBill Paul 349d0027533SBill Paul /* 350d0027533SBill Paul * Link partner is not capable of autonegotiation. 351d0027533SBill Paul * We will never be in full-duplex mode if this is 352d0027533SBill Paul * the case, so reading the PAR is OK. 353d0027533SBill Paul */ 354d0027533SBill Paul par = PHY_READ(sc, MII_NSPHY_PAR); 355d0027533SBill Paul if (par & PAR_10) 356d0027533SBill Paul mii->mii_media_active |= IFM_10_T; 357d0027533SBill Paul else 358d0027533SBill Paul mii->mii_media_active |= IFM_100_TX; 359d0027533SBill Paul #if 0 360d0027533SBill Paul if (par & PAR_FDX) 361d0027533SBill Paul mii->mii_media_active |= IFM_FDX; 362d0027533SBill Paul #endif 363d0027533SBill Paul } else 364fb58dc87SMarius Strobl mii->mii_media_active = ife->ifm_media; 365fb58dc87SMarius Strobl } 366fb58dc87SMarius Strobl 367fb58dc87SMarius Strobl static void 368fb58dc87SMarius Strobl nsphy_reset(struct mii_softc *sc) 369fb58dc87SMarius Strobl { 370fb58dc87SMarius Strobl struct ifmedia_entry *ife = sc->mii_pdata->mii_media.ifm_cur; 371fb58dc87SMarius Strobl int reg, i; 372fb58dc87SMarius Strobl 373fb58dc87SMarius Strobl if (sc->mii_flags & MIIF_NOISOLATE) 374fb58dc87SMarius Strobl reg = BMCR_RESET; 375fb58dc87SMarius Strobl else 376fb58dc87SMarius Strobl reg = BMCR_RESET | BMCR_ISO; 377fb58dc87SMarius Strobl PHY_WRITE(sc, MII_BMCR, reg); 378fb58dc87SMarius Strobl 379fb58dc87SMarius Strobl /* 380fb58dc87SMarius Strobl * Give it a little time to settle in case we just got power. 381fb58dc87SMarius Strobl * The DP83840A data sheet suggests that a soft reset should not 382fb58dc87SMarius Strobl * happen within 500us of power being applied. Be conservative. 383fb58dc87SMarius Strobl */ 384fb58dc87SMarius Strobl DELAY(1000); 385fb58dc87SMarius Strobl 386fb58dc87SMarius Strobl /* 387fb58dc87SMarius Strobl * Wait another 2s for it to complete. 388fb58dc87SMarius Strobl * This is only a little overkill as under normal circumstances 389fb58dc87SMarius Strobl * the PHY can take up to 1s to complete reset. 390fb58dc87SMarius Strobl * This is also a bit odd because after a reset, the BMCR will 391fb58dc87SMarius Strobl * clear the reset bit and simply reports 0 even though the reset 392fb58dc87SMarius Strobl * is not yet complete. 393fb58dc87SMarius Strobl */ 394fb58dc87SMarius Strobl for (i = 0; i < 1000; i++) { 395fb58dc87SMarius Strobl reg = PHY_READ(sc, MII_BMCR); 396fb58dc87SMarius Strobl if (reg != 0 && (reg & BMCR_RESET) == 0) 397fb58dc87SMarius Strobl break; 398fb58dc87SMarius Strobl DELAY(2000); 399fb58dc87SMarius Strobl } 400fb58dc87SMarius Strobl 401fb58dc87SMarius Strobl if ((sc->mii_flags & MIIF_NOISOLATE) == 0) { 402fb58dc87SMarius Strobl if ((ife == NULL && sc->mii_inst != 0) || 403fb58dc87SMarius Strobl (ife != NULL && IFM_INST(ife->ifm_media) != sc->mii_inst)) 404fb58dc87SMarius Strobl PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO); 405fb58dc87SMarius Strobl } 406d0027533SBill Paul } 407