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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by Bill Paul. 16 * 4. Neither the name of the author nor the names of any co-contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD 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 33 #include <sys/cdefs.h> 34 __FBSDID("$FreeBSD$"); 35 36 /* 37 * Driver for the Broadcom BCM54xx/57xx 1000baseTX PHY. 38 */ 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/kernel.h> 43 #include <sys/module.h> 44 #include <sys/socket.h> 45 #include <sys/bus.h> 46 47 #include <net/if.h> 48 #include <net/ethernet.h> 49 #include <net/if_media.h> 50 51 #include <dev/mii/mii.h> 52 #include <dev/mii/miivar.h> 53 #include "miidevs.h" 54 55 #include <dev/mii/brgphyreg.h> 56 #include <net/if_arp.h> 57 #include <machine/bus.h> 58 #include <dev/bge/if_bgereg.h> 59 #include <dev/bce/if_bcereg.h> 60 61 #include <dev/pci/pcireg.h> 62 #include <dev/pci/pcivar.h> 63 64 #include "miibus_if.h" 65 66 static int brgphy_probe(device_t); 67 static int brgphy_attach(device_t); 68 69 struct brgphy_softc { 70 struct mii_softc mii_sc; 71 int mii_model; 72 int mii_rev; 73 }; 74 75 static device_method_t brgphy_methods[] = { 76 /* device interface */ 77 DEVMETHOD(device_probe, brgphy_probe), 78 DEVMETHOD(device_attach, brgphy_attach), 79 DEVMETHOD(device_detach, mii_phy_detach), 80 DEVMETHOD(device_shutdown, bus_generic_shutdown), 81 { 0, 0 } 82 }; 83 84 static devclass_t brgphy_devclass; 85 86 static driver_t brgphy_driver = { 87 "brgphy", 88 brgphy_methods, 89 sizeof(struct brgphy_softc) 90 }; 91 92 DRIVER_MODULE(brgphy, miibus, brgphy_driver, brgphy_devclass, 0, 0); 93 94 static int brgphy_service(struct mii_softc *, struct mii_data *, int); 95 static void brgphy_setmedia(struct mii_softc *, int, int); 96 static void brgphy_status(struct mii_softc *); 97 static int brgphy_mii_phy_auto(struct mii_softc *); 98 static void brgphy_reset(struct mii_softc *); 99 static void brgphy_loop(struct mii_softc *); 100 static int bcm5706_is_tbi(device_t); 101 static void bcm5401_load_dspcode(struct mii_softc *); 102 static void bcm5411_load_dspcode(struct mii_softc *); 103 static void brgphy_fixup_5704_a0_bug(struct mii_softc *); 104 static void brgphy_fixup_adc_bug(struct mii_softc *); 105 static void brgphy_fixup_adjust_trim(struct mii_softc *); 106 static void brgphy_fixup_ber_bug(struct mii_softc *); 107 static void brgphy_fixup_crc_bug(struct mii_softc *); 108 static void brgphy_fixup_jitter_bug(struct mii_softc *); 109 static void brgphy_ethernet_wirespeed(struct mii_softc *); 110 static void brgphy_jumbo_settings(struct mii_softc *, u_long); 111 112 static const struct mii_phydesc brgphys[] = { 113 MII_PHY_DESC(xxBROADCOM, BCM5400), 114 MII_PHY_DESC(xxBROADCOM, BCM5401), 115 MII_PHY_DESC(xxBROADCOM, BCM5411), 116 MII_PHY_DESC(xxBROADCOM, BCM5701), 117 MII_PHY_DESC(xxBROADCOM, BCM5703), 118 MII_PHY_DESC(xxBROADCOM, BCM5704), 119 MII_PHY_DESC(xxBROADCOM, BCM5705), 120 MII_PHY_DESC(xxBROADCOM, BCM5706C), 121 MII_PHY_DESC(xxBROADCOM, BCM5714), 122 MII_PHY_DESC(xxBROADCOM, BCM5750), 123 MII_PHY_DESC(xxBROADCOM, BCM5752), 124 MII_PHY_DESC(xxBROADCOM, BCM5754), 125 MII_PHY_DESC(xxBROADCOM, BCM5780), 126 MII_PHY_DESC(xxBROADCOM, BCM5708C), 127 MII_PHY_DESC(xxBROADCOM_ALT1, BCM5787), 128 MII_PHY_END 129 }; 130 131 static int 132 brgphy_probe(device_t dev) 133 { 134 struct mii_attach_args *ma; 135 int error; 136 137 error = mii_phy_dev_probe(dev, brgphys, BUS_PROBE_DEFAULT); 138 if (error != BUS_PROBE_DEFAULT) 139 return (error); 140 141 ma = device_get_ivars(dev); 142 if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_xxBROADCOM && 143 MII_MODEL(ma->mii_id2) == MII_MODEL_xxBROADCOM_BCM5706C) { 144 /* 145 * Broadcom uses the same MII model ID on two 146 * different types of phys. The first is found on the 147 * BCM 5706 and is supported by this driver. The 148 * other is found on the BCM 5706S and 5708S and is 149 * supported by the gentbi(4) driver, so we check to 150 * see if this phy is supported by gentbi(4) and fail 151 * the probe if so. 152 */ 153 if (bcm5706_is_tbi(dev)) 154 return (ENXIO); 155 } 156 return (error); 157 } 158 159 static int 160 brgphy_attach(device_t dev) 161 { 162 struct brgphy_softc *bsc; 163 struct mii_softc *sc; 164 struct mii_attach_args *ma; 165 struct mii_data *mii; 166 const char *sep = ""; 167 struct bge_softc *bge_sc = NULL; 168 struct bce_softc *bce_sc = NULL; 169 int fast_ether_only = FALSE; 170 171 bsc = device_get_softc(dev); 172 sc = &bsc->mii_sc; 173 ma = device_get_ivars(dev); 174 sc->mii_dev = device_get_parent(dev); 175 mii = device_get_softc(sc->mii_dev); 176 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); 177 178 sc->mii_inst = mii->mii_instance; 179 sc->mii_phy = ma->mii_phyno; 180 sc->mii_service = brgphy_service; 181 sc->mii_pdata = mii; 182 183 sc->mii_flags |= MIIF_NOISOLATE; 184 mii->mii_instance++; 185 186 #define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL) 187 #define PRINT(s) printf("%s%s", sep, s); sep = ", " 188 189 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_NONE, 0, sc->mii_inst), 190 BMCR_ISO); 191 #if 0 192 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_LOOP, sc->mii_inst), 193 BMCR_LOOP | BMCR_S100); 194 #endif 195 196 bsc->mii_model = MII_MODEL(ma->mii_id2); 197 bsc->mii_rev = MII_REV(ma->mii_id2); 198 brgphy_reset(sc); 199 200 sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask; 201 sc->mii_capabilities &= ~BMSR_ANEG; 202 device_printf(dev, " "); 203 mii_add_media(sc); 204 205 /* Find the driver associated with this PHY. */ 206 if (strcmp(mii->mii_ifp->if_dname, "bge") == 0) { 207 bge_sc = mii->mii_ifp->if_softc; 208 } else if (strcmp(mii->mii_ifp->if_dname, "bce") == 0) { 209 bce_sc = mii->mii_ifp->if_softc; 210 } 211 212 /* The 590x chips are 10/100 only. */ 213 if (strcmp(mii->mii_ifp->if_dname, "bge") == 0 && 214 pci_get_vendor(bge_sc->bge_dev) == BCOM_VENDORID && 215 (pci_get_device(bge_sc->bge_dev) == BCOM_DEVICEID_BCM5901 || 216 pci_get_device(bge_sc->bge_dev) == BCOM_DEVICEID_BCM5901A2)) 217 fast_ether_only = TRUE; 218 219 if (fast_ether_only == FALSE) { 220 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_T, 0, 221 sc->mii_inst), BRGPHY_BMCR_FDX); 222 PRINT(", 1000baseTX"); 223 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_1000_T, 224 IFM_FDX, sc->mii_inst), 0); 225 PRINT("1000baseTX-FDX"); 226 sc->mii_anegticks = MII_ANEGTICKS_GIGE; 227 } else 228 sc->mii_anegticks = MII_ANEGTICKS; 229 230 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, sc->mii_inst), 0); 231 PRINT("auto"); 232 233 printf("\n"); 234 #undef ADD 235 #undef PRINT 236 237 MIIBUS_MEDIAINIT(sc->mii_dev); 238 return (0); 239 } 240 241 static int 242 brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) 243 { 244 struct brgphy_softc *bsc = (struct brgphy_softc *)sc; 245 struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 246 247 switch (cmd) { 248 case MII_POLLSTAT: 249 /* If we're not polling our PHY instance, just return. */ 250 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 251 return (0); 252 break; 253 case MII_MEDIACHG: 254 /* 255 * If the media indicates a different PHY instance, 256 * isolate ourselves. 257 */ 258 if (IFM_INST(ife->ifm_media) != sc->mii_inst) { 259 PHY_WRITE(sc, MII_BMCR, 260 PHY_READ(sc, MII_BMCR) | BMCR_ISO); 261 return (0); 262 } 263 264 /* If the interface is not up, don't do anything. */ 265 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 266 break; 267 268 brgphy_reset(sc); /* XXX hardware bug work-around */ 269 270 switch (IFM_SUBTYPE(ife->ifm_media)) { 271 case IFM_AUTO: 272 #ifdef foo 273 /* If we're already in auto mode, just return. */ 274 if (PHY_READ(sc, BRGPHY_MII_BMCR) & BRGPHY_BMCR_AUTOEN) 275 return (0); 276 #endif 277 (void)brgphy_mii_phy_auto(sc); 278 break; 279 case IFM_1000_T: 280 case IFM_100_TX: 281 case IFM_10_T: 282 brgphy_setmedia(sc, ife->ifm_media, 283 mii->mii_ifp->if_flags & IFF_LINK0); 284 break; 285 #ifdef foo 286 case IFM_NONE: 287 PHY_WRITE(sc, MII_BMCR, BMCR_ISO | BMCR_PDOWN); 288 break; 289 #endif 290 case IFM_100_T4: 291 default: 292 return (EINVAL); 293 } 294 break; 295 case MII_TICK: 296 /* If we're not currently selected, just return. */ 297 if (IFM_INST(ife->ifm_media) != sc->mii_inst) 298 return (0); 299 300 /* Is the interface even up? */ 301 if ((mii->mii_ifp->if_flags & IFF_UP) == 0) 302 return (0); 303 304 /* Only used for autonegotiation. */ 305 if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) { 306 sc->mii_ticks = 0; /* Reset autoneg timer. */ 307 break; 308 } 309 310 /* 311 * Check to see if we have link. If we do, we don't 312 * need to restart the autonegotiation process. 313 */ 314 if (PHY_READ(sc, BRGPHY_MII_BMSR) & BRGPHY_BMSR_LINK) { 315 sc->mii_ticks = 0; /* Reset autoneg timer. */ 316 break; 317 } 318 319 /* Announce link loss right after it happens. */ 320 if (sc->mii_ticks++ == 0) 321 break; 322 323 /* Only retry autonegotiation every mii_anegticks seconds. */ 324 if (sc->mii_ticks <= sc->mii_anegticks) 325 return (0); 326 327 sc->mii_ticks = 0; 328 (void)brgphy_mii_phy_auto(sc); 329 break; 330 } 331 332 /* Update the media status. */ 333 brgphy_status(sc); 334 335 /* 336 * Callback if something changed. Note that we need to poke 337 * the DSP on the Broadcom PHYs if the media changes. 338 */ 339 if (sc->mii_media_active != mii->mii_media_active || 340 sc->mii_media_status != mii->mii_media_status || 341 cmd == MII_MEDIACHG) { 342 switch (bsc->mii_model) { 343 case MII_MODEL_xxBROADCOM_BCM5400: 344 bcm5401_load_dspcode(sc); 345 break; 346 case MII_MODEL_xxBROADCOM_BCM5401: 347 if (bsc->mii_rev == 1 || bsc->mii_rev == 3) 348 bcm5401_load_dspcode(sc); 349 break; 350 case MII_MODEL_xxBROADCOM_BCM5411: 351 bcm5411_load_dspcode(sc); 352 break; 353 } 354 } 355 mii_phy_update(sc, cmd); 356 return (0); 357 } 358 359 static void 360 brgphy_setmedia(struct mii_softc *sc, int media, int master) 361 { 362 struct brgphy_softc *bsc = (struct brgphy_softc *)sc; 363 int bmcr, gig; 364 365 switch (IFM_SUBTYPE(media)) { 366 case IFM_1000_T: 367 bmcr = BRGPHY_S1000; 368 break; 369 case IFM_100_TX: 370 bmcr = BRGPHY_S100; 371 break; 372 case IFM_10_T: 373 default: 374 bmcr = BRGPHY_S10; 375 break; 376 } 377 if ((media & IFM_GMASK) == IFM_FDX) { 378 bmcr |= BRGPHY_BMCR_FDX; 379 gig = BRGPHY_1000CTL_AFD; 380 } else { 381 gig = BRGPHY_1000CTL_AHD; 382 } 383 384 brgphy_loop(sc); 385 PHY_WRITE(sc, BRGPHY_MII_1000CTL, 0); 386 PHY_WRITE(sc, BRGPHY_MII_BMCR, bmcr); 387 PHY_WRITE(sc, BRGPHY_MII_ANAR, BRGPHY_SEL_TYPE); 388 389 if (IFM_SUBTYPE(media) != IFM_1000_T) 390 return; 391 392 PHY_WRITE(sc, BRGPHY_MII_1000CTL, gig); 393 PHY_WRITE(sc, BRGPHY_MII_BMCR, 394 bmcr | BRGPHY_BMCR_AUTOEN | BRGPHY_BMCR_STARTNEG); 395 396 if (bsc->mii_model != MII_MODEL_xxBROADCOM_BCM5701) 397 return; 398 399 /* 400 * When setting the link manually, one side must be the master and 401 * the other the slave. However ifmedia doesn't give us a good way 402 * to specify this, so we fake it by using one of the LINK flags. 403 * If LINK0 is set, we program the PHY to be a master, otherwise 404 * it's a slave. 405 */ 406 if (master) { 407 PHY_WRITE(sc, BRGPHY_MII_1000CTL, 408 gig | BRGPHY_1000CTL_MSE | BRGPHY_1000CTL_MSC); 409 } else { 410 PHY_WRITE(sc, BRGPHY_MII_1000CTL, 411 gig | BRGPHY_1000CTL_MSE); 412 } 413 } 414 415 static void 416 brgphy_status(struct mii_softc *sc) 417 { 418 struct mii_data *mii = sc->mii_pdata; 419 struct ifmedia_entry *ife = mii->mii_media.ifm_cur; 420 int bmcr, bmsr; 421 422 mii->mii_media_status = IFM_AVALID; 423 mii->mii_media_active = IFM_ETHER; 424 425 bmcr = PHY_READ(sc, BRGPHY_MII_BMCR); 426 bmsr = PHY_READ(sc, BRGPHY_MII_BMSR); 427 428 if (bmsr & BRGPHY_BMSR_LINK) 429 mii->mii_media_status |= IFM_ACTIVE; 430 431 if (bmcr & BRGPHY_BMCR_LOOP) 432 mii->mii_media_active |= IFM_LOOP; 433 434 if (bmcr & BRGPHY_BMCR_AUTOEN) { 435 if ((bmsr & BRGPHY_BMSR_ACOMP) == 0) { 436 /* Erg, still trying, I guess... */ 437 mii->mii_media_active |= IFM_NONE; 438 return; 439 } 440 } 441 442 if (bmsr & BRGPHY_BMSR_LINK) { 443 switch (PHY_READ(sc, BRGPHY_MII_AUXSTS) & 444 BRGPHY_AUXSTS_AN_RES) { 445 case BRGPHY_RES_1000FD: 446 mii->mii_media_active |= IFM_1000_T | IFM_FDX; 447 break; 448 case BRGPHY_RES_1000HD: 449 mii->mii_media_active |= IFM_1000_T | IFM_HDX; 450 break; 451 case BRGPHY_RES_100FD: 452 mii->mii_media_active |= IFM_100_TX | IFM_FDX; 453 break; 454 case BRGPHY_RES_100T4: 455 mii->mii_media_active |= IFM_100_T4; 456 break; 457 case BRGPHY_RES_100HD: 458 mii->mii_media_active |= IFM_100_TX | IFM_HDX; 459 break; 460 case BRGPHY_RES_10FD: 461 mii->mii_media_active |= IFM_10_T | IFM_FDX; 462 break; 463 case BRGPHY_RES_10HD: 464 mii->mii_media_active |= IFM_10_T | IFM_HDX; 465 break; 466 default: 467 mii->mii_media_active |= IFM_NONE; 468 break; 469 } 470 } else 471 mii->mii_media_active = ife->ifm_media; 472 } 473 474 static int 475 brgphy_mii_phy_auto(struct mii_softc *sc) 476 { 477 struct brgphy_softc *bsc = (struct brgphy_softc *)sc; 478 int ktcr = 0; 479 480 brgphy_loop(sc); 481 brgphy_reset(sc); 482 ktcr = BRGPHY_1000CTL_AFD | BRGPHY_1000CTL_AHD; 483 if (bsc->mii_model == MII_MODEL_xxBROADCOM_BCM5701) 484 ktcr |= BRGPHY_1000CTL_MSE | BRGPHY_1000CTL_MSC; 485 PHY_WRITE(sc, BRGPHY_MII_1000CTL, ktcr); 486 ktcr = PHY_READ(sc, BRGPHY_MII_1000CTL); 487 DELAY(1000); 488 PHY_WRITE(sc, BRGPHY_MII_ANAR, 489 BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA); 490 DELAY(1000); 491 PHY_WRITE(sc, BRGPHY_MII_BMCR, 492 BRGPHY_BMCR_AUTOEN | BRGPHY_BMCR_STARTNEG); 493 PHY_WRITE(sc, BRGPHY_MII_IMR, 0xFF00); 494 return (EJUSTRETURN); 495 } 496 497 static void 498 brgphy_loop(struct mii_softc *sc) 499 { 500 int i; 501 502 PHY_WRITE(sc, BRGPHY_MII_BMCR, BRGPHY_BMCR_LOOP); 503 for (i = 0; i < 15000; i++) { 504 if (!(PHY_READ(sc, BRGPHY_MII_BMSR) & BRGPHY_BMSR_LINK)) { 505 #if 0 506 device_printf(sc->mii_dev, "looped %d\n", i); 507 #endif 508 break; 509 } 510 DELAY(10); 511 } 512 } 513 514 /* 515 * Check to see if a 5706 phy is really a SerDes phy. Copied from 516 * gentbi_probe(). 517 */ 518 static int 519 bcm5706_is_tbi(device_t dev) 520 { 521 device_t parent; 522 struct mii_attach_args *ma; 523 int bmsr, extsr; 524 525 parent = device_get_parent(dev); 526 ma = device_get_ivars(dev); 527 528 bmsr = MIIBUS_READREG(parent, ma->mii_phyno, MII_BMSR); 529 if ((bmsr & BMSR_EXTSTAT) == 0 || (bmsr & BMSR_MEDIAMASK) != 0) 530 return (0); 531 532 extsr = MIIBUS_READREG(parent, ma->mii_phyno, MII_EXTSR); 533 if (extsr & (EXTSR_1000TFDX|EXTSR_1000THDX)) 534 return (0); 535 536 if (extsr & (EXTSR_1000XFDX|EXTSR_1000XHDX)) 537 return (1); 538 539 return (0); 540 } 541 542 /* Turn off tap power management on 5401. */ 543 static void 544 bcm5401_load_dspcode(struct mii_softc *sc) 545 { 546 static const struct { 547 int reg; 548 uint16_t val; 549 } dspcode[] = { 550 { BRGPHY_MII_AUXCTL, 0x0c20 }, 551 { BRGPHY_MII_DSP_ADDR_REG, 0x0012 }, 552 { BRGPHY_MII_DSP_RW_PORT, 0x1804 }, 553 { BRGPHY_MII_DSP_ADDR_REG, 0x0013 }, 554 { BRGPHY_MII_DSP_RW_PORT, 0x1204 }, 555 { BRGPHY_MII_DSP_ADDR_REG, 0x8006 }, 556 { BRGPHY_MII_DSP_RW_PORT, 0x0132 }, 557 { BRGPHY_MII_DSP_ADDR_REG, 0x8006 }, 558 { BRGPHY_MII_DSP_RW_PORT, 0x0232 }, 559 { BRGPHY_MII_DSP_ADDR_REG, 0x201f }, 560 { BRGPHY_MII_DSP_RW_PORT, 0x0a20 }, 561 { 0, 0 }, 562 }; 563 int i; 564 565 for (i = 0; dspcode[i].reg != 0; i++) 566 PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); 567 DELAY(40); 568 } 569 570 static void 571 bcm5411_load_dspcode(struct mii_softc *sc) 572 { 573 static const struct { 574 int reg; 575 uint16_t val; 576 } dspcode[] = { 577 { 0x1c, 0x8c23 }, 578 { 0x1c, 0x8ca3 }, 579 { 0x1c, 0x8c23 }, 580 { 0, 0 }, 581 }; 582 int i; 583 584 for (i = 0; dspcode[i].reg != 0; i++) 585 PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); 586 } 587 588 static void 589 brgphy_fixup_5704_a0_bug(struct mii_softc *sc) 590 { 591 static const struct { 592 int reg; 593 uint16_t val; 594 } dspcode[] = { 595 { 0x1c, 0x8d68 }, 596 { 0x1c, 0x8d68 }, 597 { 0, 0 }, 598 }; 599 int i; 600 601 for (i = 0; dspcode[i].reg != 0; i++) 602 PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); 603 } 604 605 static void 606 brgphy_fixup_adc_bug(struct mii_softc *sc) 607 { 608 static const struct { 609 int reg; 610 uint16_t val; 611 } dspcode[] = { 612 { BRGPHY_MII_AUXCTL, 0x0c00 }, 613 { BRGPHY_MII_DSP_ADDR_REG, 0x201f }, 614 { BRGPHY_MII_DSP_RW_PORT, 0x2aaa }, 615 { 0, 0 }, 616 }; 617 int i; 618 619 for (i = 0; dspcode[i].reg != 0; i++) 620 PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); 621 } 622 623 static void 624 brgphy_fixup_adjust_trim(struct mii_softc *sc) 625 { 626 static const struct { 627 int reg; 628 uint16_t val; 629 } dspcode[] = { 630 { BRGPHY_MII_AUXCTL, 0x0c00 }, 631 { BRGPHY_MII_DSP_ADDR_REG, 0x000a }, 632 { BRGPHY_MII_DSP_RW_PORT, 0x110b }, 633 { BRGPHY_MII_TEST1, 0x0014 }, 634 { BRGPHY_MII_AUXCTL, 0x0400 }, 635 { 0, 0 }, 636 }; 637 int i; 638 639 for (i = 0; dspcode[i].reg != 0; i++) 640 PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); 641 } 642 643 static void 644 brgphy_fixup_ber_bug(struct mii_softc *sc) 645 { 646 static const struct { 647 int reg; 648 uint16_t val; 649 } dspcode[] = { 650 { BRGPHY_MII_AUXCTL, 0x0c00 }, 651 { BRGPHY_MII_DSP_ADDR_REG, 0x000a }, 652 { BRGPHY_MII_DSP_RW_PORT, 0x310b }, 653 { BRGPHY_MII_DSP_ADDR_REG, 0x201f }, 654 { BRGPHY_MII_DSP_RW_PORT, 0x9506 }, 655 { BRGPHY_MII_DSP_ADDR_REG, 0x401f }, 656 { BRGPHY_MII_DSP_RW_PORT, 0x14e2 }, 657 { BRGPHY_MII_AUXCTL, 0x0400 }, 658 { 0, 0 }, 659 }; 660 int i; 661 662 for (i = 0; dspcode[i].reg != 0; i++) 663 PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); 664 } 665 666 static void 667 brgphy_fixup_crc_bug(struct mii_softc *sc) 668 { 669 static const struct { 670 int reg; 671 uint16_t val; 672 } dspcode[] = { 673 { BRGPHY_MII_DSP_RW_PORT, 0x0a75 }, 674 { 0x1c, 0x8c68 }, 675 { 0x1c, 0x8d68 }, 676 { 0x1c, 0x8c68 }, 677 { 0, 0 }, 678 }; 679 int i; 680 681 for (i = 0; dspcode[i].reg != 0; i++) 682 PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); 683 } 684 685 static void 686 brgphy_fixup_jitter_bug(struct mii_softc *sc) 687 { 688 static const struct { 689 int reg; 690 uint16_t val; 691 } dspcode[] = { 692 { BRGPHY_MII_AUXCTL, 0x0c00 }, 693 { BRGPHY_MII_DSP_ADDR_REG, 0x000a }, 694 { BRGPHY_MII_DSP_RW_PORT, 0x010b }, 695 { BRGPHY_MII_AUXCTL, 0x0400 }, 696 { 0, 0 }, 697 }; 698 int i; 699 700 for (i = 0; dspcode[i].reg != 0; i++) 701 PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val); 702 } 703 704 static void 705 brgphy_ethernet_wirespeed(struct mii_softc *sc) 706 { 707 uint32_t val; 708 709 /* Enable Ethernet@WireSpeed. */ 710 PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x7007); 711 val = PHY_READ(sc, BRGPHY_MII_AUXCTL); 712 PHY_WRITE(sc, BRGPHY_MII_AUXCTL, val | (1 << 15) | (1 << 4)); 713 } 714 715 static void 716 brgphy_jumbo_settings(struct mii_softc *sc, u_long mtu) 717 { 718 struct brgphy_softc *bsc = (struct brgphy_softc *)sc; 719 uint32_t val; 720 721 /* Set or clear jumbo frame settings in the PHY. */ 722 if (mtu > ETHER_MAX_LEN) { 723 if (bsc->mii_model == MII_MODEL_xxBROADCOM_BCM5401) { 724 /* BCM5401 PHY cannot read-modify-write. */ 725 PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x4c20); 726 } else { 727 PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x7); 728 val = PHY_READ(sc, BRGPHY_MII_AUXCTL); 729 PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 730 val | BRGPHY_AUXCTL_LONG_PKT); 731 } 732 733 val = PHY_READ(sc, BRGPHY_MII_PHY_EXTCTL); 734 PHY_WRITE(sc, BRGPHY_MII_PHY_EXTCTL, 735 val | BRGPHY_PHY_EXTCTL_HIGH_LA); 736 } else { 737 PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x7); 738 val = PHY_READ(sc, BRGPHY_MII_AUXCTL); 739 PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 740 val & ~(BRGPHY_AUXCTL_LONG_PKT | 0x7)); 741 742 val = PHY_READ(sc, BRGPHY_MII_PHY_EXTCTL); 743 PHY_WRITE(sc, BRGPHY_MII_PHY_EXTCTL, 744 val & ~BRGPHY_PHY_EXTCTL_HIGH_LA); 745 } 746 } 747 748 static void 749 brgphy_reset(struct mii_softc *sc) 750 { 751 struct brgphy_softc *bsc = (struct brgphy_softc *)sc; 752 struct bge_softc *bge_sc = NULL; 753 struct bce_softc *bce_sc = NULL; 754 struct ifnet *ifp; 755 756 mii_phy_reset(sc); 757 758 switch (bsc->mii_model) { 759 case MII_MODEL_xxBROADCOM_BCM5400: 760 bcm5401_load_dspcode(sc); 761 break; 762 case MII_MODEL_xxBROADCOM_BCM5401: 763 if (bsc->mii_rev == 1 || bsc->mii_rev == 3) 764 bcm5401_load_dspcode(sc); 765 break; 766 case MII_MODEL_xxBROADCOM_BCM5411: 767 bcm5411_load_dspcode(sc); 768 break; 769 } 770 771 ifp = sc->mii_pdata->mii_ifp; 772 773 /* Find the driver associated with this PHY. */ 774 if (strcmp(ifp->if_dname, "bge") == 0) { 775 bge_sc = ifp->if_softc; 776 } else if (strcmp(ifp->if_dname, "bce") == 0) { 777 bce_sc = ifp->if_softc; 778 } 779 780 /* Handle any NetXtreme/bge workarounds. */ 781 if (bge_sc) { 782 /* Fix up various bugs */ 783 if (bge_sc->bge_flags & BGE_FLAG_5704_A0_BUG) 784 brgphy_fixup_5704_a0_bug(sc); 785 if (bge_sc->bge_flags & BGE_FLAG_ADC_BUG) 786 brgphy_fixup_adc_bug(sc); 787 if (bge_sc->bge_flags & BGE_FLAG_ADJUST_TRIM) 788 brgphy_fixup_adjust_trim(sc); 789 if (bge_sc->bge_flags & BGE_FLAG_BER_BUG) 790 brgphy_fixup_ber_bug(sc); 791 if (bge_sc->bge_flags & BGE_FLAG_CRC_BUG) 792 brgphy_fixup_crc_bug(sc); 793 if (bge_sc->bge_flags & BGE_FLAG_JITTER_BUG) 794 brgphy_fixup_jitter_bug(sc); 795 796 brgphy_jumbo_settings(sc, ifp->if_mtu); 797 798 /* 799 * Don't enable Ethernet@WireSpeed for the 5700 or the 800 * 5705 A1 and A2 chips. 801 */ 802 if (bge_sc->bge_asicrev != BGE_ASICREV_BCM5700 && 803 bge_sc->bge_chipid != BGE_CHIPID_BCM5705_A1 && 804 bge_sc->bge_chipid != BGE_CHIPID_BCM5705_A2) 805 brgphy_ethernet_wirespeed(sc); 806 807 /* Enable Link LED on Dell boxes */ 808 if (bge_sc->bge_flags & BGE_FLAG_NO_3LED) { 809 PHY_WRITE(sc, BRGPHY_MII_PHY_EXTCTL, 810 PHY_READ(sc, BRGPHY_MII_PHY_EXTCTL) & 811 ~BRGPHY_PHY_EXTCTL_3_LED); 812 } 813 } else if (bce_sc) { 814 brgphy_fixup_ber_bug(sc); 815 brgphy_jumbo_settings(sc, ifp->if_mtu); 816 brgphy_ethernet_wirespeed(sc); 817 } 818 } 819