brgphy.c (95722) | brgphy.c (96026) |
---|---|
1/* 2 * Copyright (c) 2000 3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 * | 1/* 2 * Copyright (c) 2000 3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 * |
32 * $FreeBSD: head/sys/dev/mii/brgphy.c 95722 2002-04-29 13:07:38Z phk $ | 32 * $FreeBSD: head/sys/dev/mii/brgphy.c 96026 2002-05-04 11:00:30Z phk $ |
33 */ 34 35/* 36 * Driver for the Broadcom BCR5400 1000baseTX PHY. Speed is always 37 * 1000mbps; all we need to negotiate here is full or half duplex. 38 */ 39 40#include <sys/param.h> --- 13 unchanged lines hidden (view full) --- 54#include <dev/mii/miidevs.h> 55 56#include <dev/mii/brgphyreg.h> 57 58#include "miibus_if.h" 59 60#if !defined(lint) 61static const char rcsid[] = | 33 */ 34 35/* 36 * Driver for the Broadcom BCR5400 1000baseTX PHY. Speed is always 37 * 1000mbps; all we need to negotiate here is full or half duplex. 38 */ 39 40#include <sys/param.h> --- 13 unchanged lines hidden (view full) --- 54#include <dev/mii/miidevs.h> 55 56#include <dev/mii/brgphyreg.h> 57 58#include "miibus_if.h" 59 60#if !defined(lint) 61static const char rcsid[] = |
62 "$FreeBSD: head/sys/dev/mii/brgphy.c 95722 2002-04-29 13:07:38Z phk $"; | 62 "$FreeBSD: head/sys/dev/mii/brgphy.c 96026 2002-05-04 11:00:30Z phk $"; |
63#endif 64 65static int brgphy_probe (device_t); 66static int brgphy_attach (device_t); 67 68static device_method_t brgphy_methods[] = { 69 /* device interface */ 70 DEVMETHOD(device_probe, brgphy_probe), --- 10 unchanged lines hidden (view full) --- 81 brgphy_methods, 82 sizeof(struct mii_softc) 83}; 84 85DRIVER_MODULE(brgphy, miibus, brgphy_driver, brgphy_devclass, 0, 0); 86 87static int brgphy_service(struct mii_softc *, struct mii_data *, int); 88static void brgphy_status(struct mii_softc *); | 63#endif 64 65static int brgphy_probe (device_t); 66static int brgphy_attach (device_t); 67 68static device_method_t brgphy_methods[] = { 69 /* device interface */ 70 DEVMETHOD(device_probe, brgphy_probe), --- 10 unchanged lines hidden (view full) --- 81 brgphy_methods, 82 sizeof(struct mii_softc) 83}; 84 85DRIVER_MODULE(brgphy, miibus, brgphy_driver, brgphy_devclass, 0, 0); 86 87static int brgphy_service(struct mii_softc *, struct mii_data *, int); 88static void brgphy_status(struct mii_softc *); |
89static int brgphy_mii_phy_auto(struct mii_softc *, int); 90extern void mii_phy_auto_timeout(void *); | 89static int brgphy_mii_phy_auto(struct mii_softc *); |
91 92static int brgphy_probe(dev) 93 device_t dev; 94{ 95 struct mii_attach_args *ma; 96 97 ma = device_get_ivars(dev); 98 --- 124 unchanged lines hidden (view full) --- 223 case IFM_AUTO: 224#ifdef foo 225 /* 226 * If we're already in auto mode, just return. 227 */ 228 if (PHY_READ(sc, BRGPHY_MII_BMCR) & BRGPHY_BMCR_AUTOEN) 229 return (0); 230#endif | 90 91static int brgphy_probe(dev) 92 device_t dev; 93{ 94 struct mii_attach_args *ma; 95 96 ma = device_get_ivars(dev); 97 --- 124 unchanged lines hidden (view full) --- 222 case IFM_AUTO: 223#ifdef foo 224 /* 225 * If we're already in auto mode, just return. 226 */ 227 if (PHY_READ(sc, BRGPHY_MII_BMCR) & BRGPHY_BMCR_AUTOEN) 228 return (0); 229#endif |
231 (void) brgphy_mii_phy_auto(sc, 1); | 230 (void) brgphy_mii_phy_auto(sc); |
232 break; 233 case IFM_1000_T: 234 speed = BRGPHY_S1000; 235 goto setit; 236 case IFM_100_TX: 237 speed = BRGPHY_S100; 238 goto setit; 239 case IFM_10_T: --- 68 unchanged lines hidden (view full) --- 308 /* 309 * Only retry autonegotiation every 5 seconds. 310 */ 311 if (++sc->mii_ticks != 5) 312 return (0); 313 314 sc->mii_ticks = 0; 315 mii_phy_reset(sc); | 231 break; 232 case IFM_1000_T: 233 speed = BRGPHY_S1000; 234 goto setit; 235 case IFM_100_TX: 236 speed = BRGPHY_S100; 237 goto setit; 238 case IFM_10_T: --- 68 unchanged lines hidden (view full) --- 307 /* 308 * Only retry autonegotiation every 5 seconds. 309 */ 310 if (++sc->mii_ticks != 5) 311 return (0); 312 313 sc->mii_ticks = 0; 314 mii_phy_reset(sc); |
316 if (brgphy_mii_phy_auto(sc, 0) == EJUSTRETURN) 317 return (0); 318 break; | 315 brgphy_mii_phy_auto(sc); 316 return (0); |
319 } 320 321 /* Update the media status. */ 322 brgphy_status(sc); 323 324 /* Callback if something changed. */ 325 mii_phy_update(sc, cmd); 326 return (0); --- 58 unchanged lines hidden (view full) --- 385 386 mii->mii_media_active = ife->ifm_media; 387 388 return; 389} 390 391 392static int | 317 } 318 319 /* Update the media status. */ 320 brgphy_status(sc); 321 322 /* Callback if something changed. */ 323 mii_phy_update(sc, cmd); 324 return (0); --- 58 unchanged lines hidden (view full) --- 383 384 mii->mii_media_active = ife->ifm_media; 385 386 return; 387} 388 389 390static int |
393brgphy_mii_phy_auto(mii, waitfor) | 391brgphy_mii_phy_auto(mii) |
394 struct mii_softc *mii; | 392 struct mii_softc *mii; |
395 int waitfor; | |
396{ | 393{ |
397 int bmsr, ktcr = 0, i; | 394 int ktcr = 0; |
398 | 395 |
399 if ((mii->mii_flags & MIIF_DOINGAUTO) == 0) { 400 mii_phy_reset(mii); 401 PHY_WRITE(mii, BRGPHY_MII_BMCR, 0); 402 DELAY(1000); 403 ktcr = PHY_READ(mii, BRGPHY_MII_1000CTL); 404 PHY_WRITE(mii, BRGPHY_MII_1000CTL, ktcr | 405 BRGPHY_1000CTL_AFD|BRGPHY_1000CTL_AHD); 406 ktcr = PHY_READ(mii, BRGPHY_MII_1000CTL); 407 DELAY(1000); 408 PHY_WRITE(mii, BRGPHY_MII_ANAR, 409 BMSR_MEDIA_TO_ANAR(mii->mii_capabilities) | ANAR_CSMA); 410 DELAY(1000); 411 PHY_WRITE(mii, BRGPHY_MII_BMCR, 412 BRGPHY_BMCR_AUTOEN | BRGPHY_BMCR_STARTNEG); 413 PHY_WRITE(mii, BRGPHY_MII_IMR, 0xFF00); 414 } 415 416 if (waitfor) { 417 /* Wait 500ms for it to complete. */ 418 for (i = 0; i < 500; i++) { 419 if ((bmsr = PHY_READ(mii, BRGPHY_MII_BMSR)) & 420 BRGPHY_BMSR_ACOMP) 421 return (0); 422 DELAY(1000); 423#if 0 424 if ((bmsr & BMSR_ACOMP) == 0) 425 printf("%s: autonegotiation failed to complete\n", 426 mii->mii_dev.dv_xname); 427#endif 428 } 429 430 /* 431 * Don't need to worry about clearing MIIF_DOINGAUTO. 432 * If that's set, a timeout is pending, and it will 433 * clear the flag. 434 */ 435 return (EIO); 436 } 437 438 /* 439 * Just let it finish asynchronously. This is for the benefit of 440 * the tick handler driving autonegotiation. Don't want 500ms 441 * delays all the time while the system is running! 442 */ 443 if ((mii->mii_flags & MIIF_DOINGAUTO) == 0) { 444 mii->mii_flags |= MIIF_DOINGAUTO; 445 mii->mii_auto_ch = timeout(mii_phy_auto_timeout, mii, hz >> 1); 446 } | 396 mii_phy_reset(mii); 397 PHY_WRITE(mii, BRGPHY_MII_BMCR, 0); 398 DELAY(1000); 399 ktcr = PHY_READ(mii, BRGPHY_MII_1000CTL); 400 PHY_WRITE(mii, BRGPHY_MII_1000CTL, ktcr | 401 BRGPHY_1000CTL_AFD|BRGPHY_1000CTL_AHD); 402 ktcr = PHY_READ(mii, BRGPHY_MII_1000CTL); 403 DELAY(1000); 404 PHY_WRITE(mii, BRGPHY_MII_ANAR, 405 BMSR_MEDIA_TO_ANAR(mii->mii_capabilities) | ANAR_CSMA); 406 DELAY(1000); 407 PHY_WRITE(mii, BRGPHY_MII_BMCR, 408 BRGPHY_BMCR_AUTOEN | BRGPHY_BMCR_STARTNEG); 409 PHY_WRITE(mii, BRGPHY_MII_IMR, 0xFF00); |
447 return (EJUSTRETURN); 448} | 410 return (EJUSTRETURN); 411} |