1 /* $NetBSD: mb86960.c,v 1.68 2007/10/19 11:59:56 ad Exp $ */ 2 3 /* 4 * All Rights Reserved, Copyright (C) Fujitsu Limited 1995 5 * 6 * This software may be used, modified, copied, distributed, and sold, in 7 * both source and binary form provided that the above copyright, these 8 * terms and the following disclaimer are retained. The name of the author 9 * and/or the contributor may not be used to endorse or promote products 10 * derived from this software without specific prior written permission. 11 * 12 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND THE CONTRIBUTOR ``AS IS'' AND 13 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR THE CONTRIBUTOR BE LIABLE 16 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 17 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 18 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION. 19 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 20 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 21 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 22 * SUCH DAMAGE. 23 */ 24 25 /* 26 * Portions copyright (C) 1993, David Greenman. This software may be used, 27 * modified, copied, distributed, and sold, in both source and binary form 28 * provided that the above copyright and these terms are retained. Under no 29 * circumstances is the author responsible for the proper functioning of this 30 * software, nor does the author assume any responsibility for damages 31 * incurred with its use. 32 */ 33 34 #include <sys/cdefs.h> 35 __KERNEL_RCSID(0, "$NetBSD: mb86960.c,v 1.68 2007/10/19 11:59:56 ad Exp $"); 36 37 /* 38 * Device driver for Fujitsu MB86960A/MB86965A based Ethernet cards. 39 * Contributed by M.S. <seki@sysrap.cs.fujitsu.co.jp> 40 * 41 * This version is intended to be a generic template for various 42 * MB86960A/MB86965A based Ethernet cards. It currently supports 43 * Fujitsu FMV-180 series (i.e., FMV-181 and FMV-182) and Allied- 44 * Telesis AT1700 series and RE2000 series. There are some 45 * unnecessary hooks embedded, which are primarily intended to support 46 * other types of Ethernet cards, but the author is not sure whether 47 * they are useful. 48 */ 49 50 #include "opt_inet.h" 51 #include "bpfilter.h" 52 #include "rnd.h" 53 54 #include <sys/param.h> 55 #include <sys/systm.h> 56 #include <sys/errno.h> 57 #include <sys/ioctl.h> 58 #include <sys/mbuf.h> 59 #include <sys/socket.h> 60 #include <sys/syslog.h> 61 #include <sys/device.h> 62 #if NRND > 0 63 #include <sys/rnd.h> 64 #endif 65 66 #include <net/if.h> 67 #include <net/if_dl.h> 68 #include <net/if_types.h> 69 #include <net/if_media.h> 70 #include <net/if_ether.h> 71 72 #ifdef INET 73 #include <netinet/in.h> 74 #include <netinet/in_systm.h> 75 #include <netinet/in_var.h> 76 #include <netinet/ip.h> 77 #include <netinet/if_inarp.h> 78 #endif 79 80 81 #if NBPFILTER > 0 82 #include <net/bpf.h> 83 #include <net/bpfdesc.h> 84 #endif 85 86 #include <sys/bus.h> 87 88 #include <dev/ic/mb86960reg.h> 89 #include <dev/ic/mb86960var.h> 90 91 #ifndef __BUS_SPACE_HAS_STREAM_METHODS 92 #define bus_space_write_stream_2 bus_space_write_2 93 #define bus_space_write_multi_stream_2 bus_space_write_multi_2 94 #define bus_space_read_multi_stream_2 bus_space_read_multi_2 95 #endif /* __BUS_SPACE_HAS_STREAM_METHODS */ 96 97 /* Standard driver entry points. These can be static. */ 98 void mb86960_init(struct mb86960_softc *); 99 int mb86960_ioctl(struct ifnet *, u_long, void *); 100 void mb86960_start(struct ifnet *); 101 void mb86960_reset(struct mb86960_softc *); 102 void mb86960_watchdog(struct ifnet *); 103 104 /* Local functions. Order of declaration is confused. FIXME. */ 105 int mb86960_get_packet(struct mb86960_softc *, u_int); 106 void mb86960_stop(struct mb86960_softc *); 107 void mb86960_tint(struct mb86960_softc *, uint8_t); 108 void mb86960_rint(struct mb86960_softc *, uint8_t); 109 static inline 110 void mb86960_xmit(struct mb86960_softc *); 111 void mb86960_write_mbufs(struct mb86960_softc *, struct mbuf *); 112 static inline 113 void mb86960_droppacket(struct mb86960_softc *); 114 void mb86960_getmcaf(struct ethercom *, uint8_t *); 115 void mb86960_setmode(struct mb86960_softc *); 116 void mb86960_loadmar(struct mb86960_softc *); 117 118 int mb86960_mediachange(struct ifnet *); 119 void mb86960_mediastatus(struct ifnet *, struct ifmediareq *); 120 121 #if FE_DEBUG >= 1 122 void mb86960_dump(int, struct mb86960_softc *); 123 #endif 124 125 void 126 mb86960_attach(struct mb86960_softc *sc, uint8_t *myea) 127 { 128 bus_space_tag_t bst = sc->sc_bst; 129 bus_space_handle_t bsh = sc->sc_bsh; 130 131 /* Register values which depend on board design. */ 132 sc->proto_dlcr4 = FE_D4_LBC_DISABLE | FE_D4_CNTRL; 133 sc->proto_dlcr5 = 0; 134 sc->proto_dlcr7 = FE_D7_BYTSWP_LH; 135 if ((sc->sc_flags & FE_FLAGS_MB86960) != 0) 136 sc->proto_dlcr7 |= FE_D7_ED_TEST; /* XXX */ 137 sc->proto_bmpr13 = FE_B13_TPTYPE_UTP | FE_B13_PORT_AUTO; 138 139 /* 140 * Program the 86960 as following defaults: 141 * SRAM: 32KB, 100ns, byte-wide access. 142 * Transmission buffer: 4KB x 2. 143 * System bus interface: 16 bits. 144 * These values except TXBSIZE should be modified as per 145 * sc_flags which is set in MD attachments, because they 146 * are hard-wired on the board. Modifying TXBSIZE will affect 147 * the driver performance. 148 */ 149 sc->proto_dlcr6 = FE_D6_BUFSIZ_32KB | FE_D6_TXBSIZ_2x4KB | 150 FE_D6_BBW_BYTE | FE_D6_SRAM_100ns; 151 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) 152 sc->proto_dlcr6 |= FE_D6_SBW_BYTE; 153 if (sc->sc_flags & FE_FLAGS_SRAM_150ns) 154 sc->proto_dlcr6 &= ~FE_D6_SRAM_100ns; 155 156 /* 157 * Minimum initialization of the hardware. 158 * We write into registers; hope I/O ports have no 159 * overlap with other boards. 160 */ 161 162 /* Initialize 86960. */ 163 bus_space_write_1(bst, bsh, FE_DLCR6, 164 sc->proto_dlcr6 | FE_D6_DLC_DISABLE); 165 delay(200); 166 167 #ifdef DIAGNOSTIC 168 if (myea == NULL) { 169 printf("%s: ethernet address shouldn't be NULL\n", 170 sc->sc_dev.dv_xname); 171 panic("NULL ethernet address"); 172 } 173 #endif 174 memcpy(sc->sc_enaddr, myea, sizeof(sc->sc_enaddr)); 175 176 /* Disable all interrupts. */ 177 bus_space_write_1(bst, bsh, FE_DLCR2, 0); 178 bus_space_write_1(bst, bsh, FE_DLCR3, 0); 179 } 180 181 /* 182 * Install interface into kernel networking data structures 183 */ 184 void 185 mb86960_config(struct mb86960_softc *sc, int *media, int nmedia, int defmedia) 186 { 187 struct cfdata *cf = device_cfdata(&sc->sc_dev); 188 struct ifnet *ifp = &sc->sc_ec.ec_if; 189 int i; 190 191 /* Stop the 86960. */ 192 mb86960_stop(sc); 193 194 /* Initialize ifnet structure. */ 195 strcpy(ifp->if_xname, sc->sc_dev.dv_xname); 196 ifp->if_softc = sc; 197 ifp->if_start = mb86960_start; 198 ifp->if_ioctl = mb86960_ioctl; 199 ifp->if_watchdog = mb86960_watchdog; 200 ifp->if_flags = 201 IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST; 202 IFQ_SET_READY(&ifp->if_snd); 203 204 #if FE_DEBUG >= 3 205 log(LOG_INFO, "%s: mb86960_config()\n", sc->sc_dev.dv_xname); 206 mb86960_dump(LOG_INFO, sc); 207 #endif 208 209 #if FE_SINGLE_TRANSMISSION 210 /* Override txb config to allocate minimum. */ 211 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ; 212 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB; 213 #endif 214 215 /* Modify hardware config if it is requested. */ 216 if ((cf->cf_flags & FE_FLAGS_OVERRIDE_DLCR6) != 0) 217 sc->proto_dlcr6 = cf->cf_flags & FE_FLAGS_DLCR6_VALUE; 218 219 /* Find TX buffer size, based on the hardware dependent proto. */ 220 switch (sc->proto_dlcr6 & FE_D6_TXBSIZ) { 221 case FE_D6_TXBSIZ_2x2KB: 222 sc->txb_size = 2048; 223 break; 224 case FE_D6_TXBSIZ_2x4KB: 225 sc->txb_size = 4096; 226 break; 227 case FE_D6_TXBSIZ_2x8KB: 228 sc->txb_size = 8192; 229 break; 230 default: 231 /* Oops, we can't work with single buffer configuration. */ 232 #if FE_DEBUG >= 2 233 log(LOG_WARNING, "%s: strange TXBSIZ config; fixing\n", 234 sc->sc_dev.dv_xname); 235 #endif 236 sc->proto_dlcr6 &= ~FE_D6_TXBSIZ; 237 sc->proto_dlcr6 |= FE_D6_TXBSIZ_2x2KB; 238 sc->txb_size = 2048; 239 break; 240 } 241 242 /* Initialize media goo. */ 243 ifmedia_init(&sc->sc_media, 0, mb86960_mediachange, 244 mb86960_mediastatus); 245 if (media != NULL) { 246 for (i = 0; i < nmedia; i++) 247 ifmedia_add(&sc->sc_media, media[i], 0, NULL); 248 ifmedia_set(&sc->sc_media, defmedia); 249 } else { 250 ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL); 251 ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL); 252 } 253 254 /* Attach the interface. */ 255 if_attach(ifp); 256 ether_ifattach(ifp, sc->sc_enaddr); 257 258 #if NRND > 0 259 rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname, 260 RND_TYPE_NET, 0); 261 #endif 262 /* Print additional info when attached. */ 263 printf("%s: Ethernet address %s\n", sc->sc_dev.dv_xname, 264 ether_sprintf(sc->sc_enaddr)); 265 266 #if FE_DEBUG >= 3 267 { 268 int buf, txb, bbw, sbw, ram; 269 270 buf = txb = bbw = sbw = ram = -1; 271 switch (sc->proto_dlcr6 & FE_D6_BUFSIZ) { 272 case FE_D6_BUFSIZ_8KB: 273 buf = 8; 274 break; 275 case FE_D6_BUFSIZ_16KB: 276 buf = 16; 277 break; 278 case FE_D6_BUFSIZ_32KB: 279 buf = 32; 280 break; 281 case FE_D6_BUFSIZ_64KB: 282 buf = 64; 283 break; 284 } 285 switch (sc->proto_dlcr6 & FE_D6_TXBSIZ) { 286 case FE_D6_TXBSIZ_2x2KB: 287 txb = 2; 288 break; 289 case FE_D6_TXBSIZ_2x4KB: 290 txb = 4; 291 break; 292 case FE_D6_TXBSIZ_2x8KB: 293 txb = 8; 294 break; 295 } 296 switch (sc->proto_dlcr6 & FE_D6_BBW) { 297 case FE_D6_BBW_BYTE: 298 bbw = 8; 299 break; 300 case FE_D6_BBW_WORD: 301 bbw = 16; 302 break; 303 } 304 switch (sc->proto_dlcr6 & FE_D6_SBW) { 305 case FE_D6_SBW_BYTE: 306 sbw = 8; 307 break; 308 case FE_D6_SBW_WORD: 309 sbw = 16; 310 break; 311 } 312 switch (sc->proto_dlcr6 & FE_D6_SRAM) { 313 case FE_D6_SRAM_100ns: 314 ram = 100; 315 break; 316 case FE_D6_SRAM_150ns: 317 ram = 150; 318 break; 319 } 320 printf("%s: SRAM %dKB %dbit %dns, TXB %dKBx2, %dbit I/O\n", 321 sc->sc_dev.dv_xname, buf, bbw, ram, txb, sbw); 322 } 323 #endif 324 325 /* The attach is successful. */ 326 sc->sc_stat |= FE_STAT_ATTACHED; 327 } 328 329 /* 330 * Media change callback. 331 */ 332 int 333 mb86960_mediachange(struct ifnet *ifp) 334 { 335 struct mb86960_softc *sc = ifp->if_softc; 336 337 if (sc->sc_mediachange) 338 return ((*sc->sc_mediachange)(sc)); 339 return (0); 340 } 341 342 /* 343 * Media status callback. 344 */ 345 void 346 mb86960_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr) 347 { 348 struct mb86960_softc *sc = ifp->if_softc; 349 350 if ((sc->sc_stat & FE_STAT_ENABLED) == 0) { 351 ifmr->ifm_active = IFM_ETHER | IFM_NONE; 352 ifmr->ifm_status = 0; 353 return; 354 } 355 356 if (sc->sc_mediastatus) 357 (*sc->sc_mediastatus)(sc, ifmr); 358 } 359 360 /* 361 * Reset interface. 362 */ 363 void 364 mb86960_reset(struct mb86960_softc *sc) 365 { 366 int s; 367 368 s = splnet(); 369 mb86960_stop(sc); 370 mb86960_init(sc); 371 splx(s); 372 } 373 374 /* 375 * Stop everything on the interface. 376 * 377 * All buffered packets, both transmitting and receiving, 378 * if any, will be lost by stopping the interface. 379 */ 380 void 381 mb86960_stop(struct mb86960_softc *sc) 382 { 383 bus_space_tag_t bst = sc->sc_bst; 384 bus_space_handle_t bsh = sc->sc_bsh; 385 386 #if FE_DEBUG >= 3 387 log(LOG_INFO, "%s: top of mb86960_stop()\n", sc->sc_dev.dv_xname); 388 mb86960_dump(LOG_INFO, sc); 389 #endif 390 391 /* Disable interrupts. */ 392 bus_space_write_1(bst, bsh, FE_DLCR2, 0x00); 393 bus_space_write_1(bst, bsh, FE_DLCR3, 0x00); 394 395 /* Stop interface hardware. */ 396 delay(200); 397 bus_space_write_1(bst, bsh, FE_DLCR6, 398 sc->proto_dlcr6 | FE_D6_DLC_DISABLE); 399 delay(200); 400 401 /* Clear all interrupt status. */ 402 bus_space_write_1(bst, bsh, FE_DLCR0, 0xFF); 403 bus_space_write_1(bst, bsh, FE_DLCR1, 0xFF); 404 405 /* Put the chip in stand-by mode. */ 406 delay(200); 407 bus_space_write_1(bst, bsh, FE_DLCR7, 408 sc->proto_dlcr7 | FE_D7_POWER_DOWN); 409 delay(200); 410 411 /* MAR loading can be delayed. */ 412 sc->filter_change = 0; 413 414 /* Call a hook. */ 415 if (sc->stop_card) 416 (*sc->stop_card)(sc); 417 418 #if FE_DEBUG >= 3 419 log(LOG_INFO, "%s: end of mb86960_stop()\n", sc->sc_dev.dv_xname); 420 mb86960_dump(LOG_INFO, sc); 421 #endif 422 } 423 424 /* 425 * Device timeout/watchdog routine. Entered if the device neglects to 426 * generate an interrupt after a transmit has been started on it. 427 */ 428 void 429 mb86960_watchdog(struct ifnet *ifp) 430 { 431 struct mb86960_softc *sc = ifp->if_softc; 432 433 log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname); 434 #if FE_DEBUG >= 3 435 mb86960_dump(LOG_INFO, sc); 436 #endif 437 438 /* Record how many packets are lost by this accident. */ 439 sc->sc_ec.ec_if.if_oerrors += sc->txb_sched + sc->txb_count; 440 441 mb86960_reset(sc); 442 } 443 444 /* 445 * Drop (skip) a packet from receive buffer in 86960 memory. 446 */ 447 static inline void 448 mb86960_droppacket(struct mb86960_softc *sc) 449 { 450 bus_space_tag_t bst = sc->sc_bst; 451 bus_space_handle_t bsh = sc->sc_bsh; 452 453 bus_space_write_1(bst, bsh, FE_BMPR14, FE_B14_FILTER | FE_B14_SKIP); 454 } 455 456 /* 457 * Initialize device. 458 */ 459 void 460 mb86960_init(struct mb86960_softc *sc) 461 { 462 bus_space_tag_t bst = sc->sc_bst; 463 bus_space_handle_t bsh = sc->sc_bsh; 464 struct ifnet *ifp = &sc->sc_ec.ec_if; 465 int i; 466 467 #if FE_DEBUG >= 3 468 log(LOG_INFO, "%s: top of mb86960_init()\n", sc->sc_dev.dv_xname); 469 mb86960_dump(LOG_INFO, sc); 470 #endif 471 472 /* Reset transmitter flags. */ 473 ifp->if_flags &= ~IFF_OACTIVE; 474 ifp->if_timer = 0; 475 476 sc->txb_free = sc->txb_size; 477 sc->txb_count = 0; 478 sc->txb_sched = 0; 479 480 /* Do any card-specific initialization, if applicable. */ 481 if (sc->init_card) 482 (*sc->init_card)(sc); 483 484 #if FE_DEBUG >= 3 485 log(LOG_INFO, "%s: after init hook\n", sc->sc_dev.dv_xname); 486 mb86960_dump(LOG_INFO, sc); 487 #endif 488 489 /* 490 * Make sure to disable the chip, also. 491 * This may also help re-programming the chip after 492 * hot insertion of PCMCIAs. 493 */ 494 bus_space_write_1(bst, bsh, FE_DLCR6, 495 sc->proto_dlcr6 | FE_D6_DLC_DISABLE); 496 delay(200); 497 498 /* Power up the chip and select register bank for DLCRs. */ 499 bus_space_write_1(bst, bsh, FE_DLCR7, 500 sc->proto_dlcr7 | FE_D7_RBS_DLCR | FE_D7_POWER_UP); 501 delay(200); 502 503 /* Feed the station address. */ 504 bus_space_write_region_1(bst, bsh, FE_DLCR8, 505 sc->sc_enaddr, ETHER_ADDR_LEN); 506 507 /* Select the BMPR bank for runtime register access. */ 508 bus_space_write_1(bst, bsh, FE_DLCR7, 509 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP); 510 511 /* Initialize registers. */ 512 bus_space_write_1(bst, bsh, FE_DLCR0, 0xFF); /* Clear all bits. */ 513 bus_space_write_1(bst, bsh, FE_DLCR1, 0xFF); /* ditto. */ 514 bus_space_write_1(bst, bsh, FE_DLCR2, 0x00); 515 bus_space_write_1(bst, bsh, FE_DLCR3, 0x00); 516 bus_space_write_1(bst, bsh, FE_DLCR4, sc->proto_dlcr4); 517 bus_space_write_1(bst, bsh, FE_DLCR5, sc->proto_dlcr5); 518 bus_space_write_1(bst, bsh, FE_BMPR10, 0x00); 519 bus_space_write_1(bst, bsh, FE_BMPR11, FE_B11_CTRL_SKIP); 520 bus_space_write_1(bst, bsh, FE_BMPR12, 0x00); 521 bus_space_write_1(bst, bsh, FE_BMPR13, sc->proto_bmpr13); 522 bus_space_write_1(bst, bsh, FE_BMPR14, FE_B14_FILTER); 523 bus_space_write_1(bst, bsh, FE_BMPR15, 0x00); 524 525 #if FE_DEBUG >= 3 526 log(LOG_INFO, "%s: just before enabling DLC\n", sc->sc_dev.dv_xname); 527 mb86960_dump(LOG_INFO, sc); 528 #endif 529 530 /* Enable interrupts. */ 531 bus_space_write_1(bst, bsh, FE_DLCR2, FE_TMASK); 532 bus_space_write_1(bst, bsh, FE_DLCR3, FE_RMASK); 533 534 /* Enable transmitter and receiver. */ 535 delay(200); 536 bus_space_write_1(bst, bsh, FE_DLCR6, 537 sc->proto_dlcr6 | FE_D6_DLC_ENABLE); 538 delay(200); 539 540 #if FE_DEBUG >= 3 541 log(LOG_INFO, "%s: just after enabling DLC\n", sc->sc_dev.dv_xname); 542 mb86960_dump(LOG_INFO, sc); 543 #endif 544 545 /* 546 * Make sure to empty the receive buffer. 547 * 548 * This may be redundant, but *if* the receive buffer were full 549 * at this point, the driver would hang. I have experienced 550 * some strange hangups just after UP. I hope the following 551 * code solve the problem. 552 * 553 * I have changed the order of hardware initialization. 554 * I think the receive buffer cannot have any packets at this 555 * point in this version. The following code *must* be 556 * redundant now. FIXME. 557 */ 558 for (i = 0; i < FE_MAX_RECV_COUNT; i++) { 559 if (bus_space_read_1(bst, bsh, FE_DLCR5) & FE_D5_BUFEMP) 560 break; 561 mb86960_droppacket(sc); 562 } 563 #if FE_DEBUG >= 1 564 if (i >= FE_MAX_RECV_COUNT) 565 log(LOG_ERR, "%s: cannot empty receive buffer\n", 566 sc->sc_dev.dv_xname); 567 #endif 568 #if FE_DEBUG >= 3 569 if (i < FE_MAX_RECV_COUNT) 570 log(LOG_INFO, "%s: receive buffer emptied (%d)\n", 571 sc->sc_dev.dv_xname, i); 572 #endif 573 574 #if FE_DEBUG >= 3 575 log(LOG_INFO, "%s: after ERB loop\n", sc->sc_dev.dv_xname); 576 mb86960_dump(LOG_INFO, sc); 577 #endif 578 579 /* Do we need this here? */ 580 bus_space_write_1(bst, bsh, FE_DLCR0, 0xFF); /* Clear all bits. */ 581 bus_space_write_1(bst, bsh, FE_DLCR1, 0xFF); /* ditto. */ 582 583 #if FE_DEBUG >= 3 584 log(LOG_INFO, "%s: after FIXME\n", sc->sc_dev.dv_xname); 585 mb86960_dump(LOG_INFO, sc); 586 #endif 587 588 /* Set 'running' flag. */ 589 ifp->if_flags |= IFF_RUNNING; 590 591 /* 592 * At this point, the interface is runnung properly, 593 * except that it receives *no* packets. we then call 594 * mb86960_setmode() to tell the chip what packets to be 595 * received, based on the if_flags and multicast group 596 * list. It completes the initialization process. 597 */ 598 mb86960_setmode(sc); 599 600 #if FE_DEBUG >= 3 601 log(LOG_INFO, "%s: after setmode\n", sc->sc_dev.dv_xname); 602 mb86960_dump(LOG_INFO, sc); 603 #endif 604 605 /* ...and attempt to start output. */ 606 mb86960_start(ifp); 607 608 #if FE_DEBUG >= 3 609 log(LOG_INFO, "%s: end of mb86960_init()\n", sc->sc_dev.dv_xname); 610 mb86960_dump(LOG_INFO, sc); 611 #endif 612 } 613 614 /* 615 * This routine actually starts the transmission on the interface 616 */ 617 static inline void 618 mb86960_xmit(struct mb86960_softc *sc) 619 { 620 bus_space_tag_t bst = sc->sc_bst; 621 bus_space_handle_t bsh = sc->sc_bsh; 622 623 /* 624 * Set a timer just in case we never hear from the board again. 625 * We use longer timeout for multiple packet transmission. 626 * I'm not sure this timer value is appropriate. FIXME. 627 */ 628 sc->sc_ec.ec_if.if_timer = 1 + sc->txb_count; 629 630 /* Update txb variables. */ 631 sc->txb_sched = sc->txb_count; 632 sc->txb_count = 0; 633 sc->txb_free = sc->txb_size; 634 635 #if FE_DELAYED_PADDING 636 /* Omit the postponed padding process. */ 637 sc->txb_padding = 0; 638 #endif 639 640 /* Start transmitter, passing packets in TX buffer. */ 641 bus_space_write_1(bst, bsh, FE_BMPR10, sc->txb_sched | FE_B10_START); 642 } 643 644 /* 645 * Start output on interface. 646 * We make two assumptions here: 647 * 1) that the current priority is set to splnet _before_ this code 648 * is called *and* is returned to the appropriate priority after 649 * return 650 * 2) that the IFF_OACTIVE flag is checked before this code is called 651 * (i.e. that the output part of the interface is idle) 652 */ 653 void 654 mb86960_start(struct ifnet *ifp) 655 { 656 struct mb86960_softc *sc = ifp->if_softc; 657 struct mbuf *m; 658 659 #if FE_DEBUG >= 1 660 /* Just a sanity check. */ 661 if ((sc->txb_count == 0) != (sc->txb_free == sc->txb_size)) { 662 /* 663 * Txb_count and txb_free co-works to manage the 664 * transmission buffer. Txb_count keeps track of the 665 * used potion of the buffer, while txb_free does unused 666 * potion. So, as long as the driver runs properly, 667 * txb_count is zero if and only if txb_free is same 668 * as txb_size (which represents whole buffer.) 669 */ 670 log(LOG_ERR, "%s: inconsistent txb variables (%d, %d)\n", 671 sc->sc_dev.dv_xname, sc->txb_count, sc->txb_free); 672 /* 673 * So, what should I do, then? 674 * 675 * We now know txb_count and txb_free contradicts. We 676 * cannot, however, tell which is wrong. More 677 * over, we cannot peek 86960 transmission buffer or 678 * reset the transmission buffer. (In fact, we can 679 * reset the entire interface. I don't want to do it.) 680 * 681 * If txb_count is incorrect, leaving it as is will cause 682 * sending of gabages after next interrupt. We have to 683 * avoid it. Hence, we reset the txb_count here. If 684 * txb_free was incorrect, resetting txb_count just loose 685 * some packets. We can live with it. 686 */ 687 sc->txb_count = 0; 688 } 689 #endif 690 691 #if FE_DEBUG >= 1 692 /* 693 * First, see if there are buffered packets and an idle 694 * transmitter - should never happen at this point. 695 */ 696 if ((sc->txb_count > 0) && (sc->txb_sched == 0)) { 697 log(LOG_ERR, "%s: transmitter idle with %d buffered packets\n", 698 sc->sc_dev.dv_xname, sc->txb_count); 699 mb86960_xmit(sc); 700 } 701 #endif 702 703 /* 704 * Stop accepting more transmission packets temporarily, when 705 * a filter change request is delayed. Updating the MARs on 706 * 86960 flushes the transmisstion buffer, so it is delayed 707 * until all buffered transmission packets have been sent 708 * out. 709 */ 710 if (sc->filter_change) { 711 /* 712 * Filter change request is delayed only when the DLC is 713 * working. DLC soon raise an interrupt after finishing 714 * the work. 715 */ 716 goto indicate_active; 717 } 718 719 for (;;) { 720 /* 721 * See if there is room to put another packet in the buffer. 722 * We *could* do better job by peeking the send queue to 723 * know the length of the next packet. Current version just 724 * tests against the worst case (i.e., longest packet). FIXME. 725 * 726 * When adding the packet-peek feature, don't forget adding a 727 * test on txb_count against QUEUEING_MAX. 728 * There is a little chance the packet count exceeds 729 * the limit. Assume transmission buffer is 8KB (2x8KB 730 * configuration) and an application sends a bunch of small 731 * (i.e., minimum packet sized) packets rapidly. An 8KB 732 * buffer can hold 130 blocks of 62 bytes long... 733 */ 734 if (sc->txb_free < 735 (ETHER_MAX_LEN - ETHER_CRC_LEN) + FE_TXLEN_SIZE) { 736 /* No room. */ 737 goto indicate_active; 738 } 739 740 #if FE_SINGLE_TRANSMISSION 741 if (sc->txb_count > 0) { 742 /* Just one packet per a transmission buffer. */ 743 goto indicate_active; 744 } 745 #endif 746 747 /* 748 * Get the next mbuf chain for a packet to send. 749 */ 750 IFQ_DEQUEUE(&ifp->if_snd, m); 751 if (m == 0) { 752 /* No more packets to send. */ 753 goto indicate_inactive; 754 } 755 756 #if NBPFILTER > 0 757 /* Tap off here if there is a BPF listener. */ 758 if (ifp->if_bpf) 759 bpf_mtap(ifp->if_bpf, m); 760 #endif 761 762 /* 763 * Copy the mbuf chain into the transmission buffer. 764 * txb_* variables are updated as necessary. 765 */ 766 mb86960_write_mbufs(sc, m); 767 768 m_freem(m); 769 770 /* Start transmitter if it's idle. */ 771 if (sc->txb_sched == 0) 772 mb86960_xmit(sc); 773 } 774 775 indicate_inactive: 776 /* 777 * We are using the !OACTIVE flag to indicate to 778 * the outside world that we can accept an 779 * additional packet rather than that the 780 * transmitter is _actually_ active. Indeed, the 781 * transmitter may be active, but if we haven't 782 * filled all the buffers with data then we still 783 * want to accept more. 784 */ 785 ifp->if_flags &= ~IFF_OACTIVE; 786 return; 787 788 indicate_active: 789 /* 790 * The transmitter is active, and there are no room for 791 * more outgoing packets in the transmission buffer. 792 */ 793 ifp->if_flags |= IFF_OACTIVE; 794 return; 795 } 796 797 /* 798 * Transmission interrupt handler 799 * The control flow of this function looks silly. FIXME. 800 */ 801 void 802 mb86960_tint(struct mb86960_softc *sc, uint8_t tstat) 803 { 804 bus_space_tag_t bst = sc->sc_bst; 805 bus_space_handle_t bsh = sc->sc_bsh; 806 struct ifnet *ifp = &sc->sc_ec.ec_if; 807 int left; 808 int col; 809 810 /* 811 * Handle "excessive collision" interrupt. 812 */ 813 if (tstat & FE_D0_COLL16) { 814 /* 815 * Find how many packets (including this collided one) 816 * are left unsent in transmission buffer. 817 */ 818 left = bus_space_read_1(bst, bsh, FE_BMPR10); 819 820 #if FE_DEBUG >= 2 821 log(LOG_WARNING, "%s: excessive collision (%d/%d)\n", 822 sc->sc_dev.dv_xname, left, sc->txb_sched); 823 #endif 824 #if FE_DEBUG >= 3 825 mb86960_dump(LOG_INFO, sc); 826 #endif 827 828 /* 829 * Update statistics. 830 */ 831 ifp->if_collisions += 16; 832 ifp->if_oerrors++; 833 ifp->if_opackets += sc->txb_sched - left; 834 835 /* 836 * Collision statistics has been updated. 837 * Clear the collision flag on 86960 now to avoid confusion. 838 */ 839 bus_space_write_1(bst, bsh, FE_DLCR0, FE_D0_COLLID); 840 841 /* 842 * Restart transmitter, skipping the 843 * collided packet. 844 * 845 * We *must* skip the packet to keep network running 846 * properly. Excessive collision error is an 847 * indication of the network overload. If we 848 * tried sending the same packet after excessive 849 * collision, the network would be filled with 850 * out-of-time packets. Packets belonging 851 * to reliable transport (such as TCP) are resent 852 * by some upper layer. 853 */ 854 bus_space_write_1(bst, bsh, FE_BMPR11, 855 FE_B11_CTRL_SKIP | FE_B11_MODE1); 856 sc->txb_sched = left - 1; 857 } 858 859 /* 860 * Handle "transmission complete" interrupt. 861 */ 862 if (tstat & FE_D0_TXDONE) { 863 /* 864 * Add in total number of collisions on last 865 * transmission. We also clear "collision occurred" flag 866 * here. 867 * 868 * 86960 has a design flow on collision count on multiple 869 * packet transmission. When we send two or more packets 870 * with one start command (that's what we do when the 871 * transmission queue is clauded), 86960 informs us number 872 * of collisions occurred on the last packet on the 873 * transmission only. Number of collisions on previous 874 * packets are lost. I have told that the fact is clearly 875 * stated in the Fujitsu document. 876 * 877 * I considered not to mind it seriously. Collision 878 * count is not so important, anyway. Any comments? FIXME. 879 */ 880 881 if (bus_space_read_1(bst, bsh, FE_DLCR0) & FE_D0_COLLID) { 882 /* Clear collision flag. */ 883 bus_space_write_1(bst, bsh, FE_DLCR0, FE_D0_COLLID); 884 885 /* Extract collision count from 86960. */ 886 col = bus_space_read_1(bst, bsh, FE_DLCR4) & FE_D4_COL; 887 if (col == 0) { 888 /* 889 * Status register indicates collisions, 890 * while the collision count is zero. 891 * This can happen after multiple packet 892 * transmission, indicating that one or more 893 * previous packet(s) had been collided. 894 * 895 * Since the accurate number of collisions 896 * has been lost, we just guess it as 1; 897 * Am I too optimistic? FIXME. 898 */ 899 col = 1; 900 } else 901 col >>= FE_D4_COL_SHIFT; 902 ifp->if_collisions += col; 903 #if FE_DEBUG >= 4 904 log(LOG_WARNING, "%s: %d collision%s (%d)\n", 905 sc->sc_dev.dv_xname, col, col == 1 ? "" : "s", 906 sc->txb_sched); 907 #endif 908 } 909 910 /* 911 * Update total number of successfully 912 * transmitted packets. 913 */ 914 ifp->if_opackets += sc->txb_sched; 915 sc->txb_sched = 0; 916 } 917 918 if (sc->txb_sched == 0) { 919 /* 920 * The transmitter is no more active. 921 * Reset output active flag and watchdog timer. 922 */ 923 ifp->if_flags &= ~IFF_OACTIVE; 924 ifp->if_timer = 0; 925 926 /* 927 * If more data is ready to transmit in the buffer, start 928 * transmitting them. Otherwise keep transmitter idle, 929 * even if more data is queued. This gives receive 930 * process a slight priority. 931 */ 932 if (sc->txb_count > 0) 933 mb86960_xmit(sc); 934 } 935 } 936 937 /* 938 * Ethernet interface receiver interrupt. 939 */ 940 void 941 mb86960_rint(struct mb86960_softc *sc, uint8_t rstat) 942 { 943 bus_space_tag_t bst = sc->sc_bst; 944 bus_space_handle_t bsh = sc->sc_bsh; 945 struct ifnet *ifp = &sc->sc_ec.ec_if; 946 u_int status, len; 947 int i; 948 949 /* 950 * Update statistics if this interrupt is caused by an error. 951 */ 952 if (rstat & (FE_D1_OVRFLO | FE_D1_CRCERR | FE_D1_ALGERR | 953 FE_D1_SRTPKT)) { 954 #if FE_DEBUG >= 3 955 char sbuf[sizeof(FE_D1_ERRBITS) + 64]; 956 957 bitmask_snprintf(rstat, FE_D1_ERRBITS, sbuf, sizeof(sbuf)); 958 log(LOG_WARNING, "%s: receive error: %s\n", 959 sc->sc_dev.dv_xname, sbuf); 960 #endif 961 ifp->if_ierrors++; 962 } 963 964 /* 965 * MB86960 has a flag indicating "receive queue empty." 966 * We just loop checking the flag to pull out all received 967 * packets. 968 * 969 * We limit the number of iterrations to avoid infinite loop. 970 * It can be caused by a very slow CPU (some broken 971 * peripheral may insert incredible number of wait cycles) 972 * or, worse, by a broken MB86960 chip. 973 */ 974 for (i = 0; i < FE_MAX_RECV_COUNT; i++) { 975 /* Stop the iterration if 86960 indicates no packets. */ 976 if (bus_space_read_1(bst, bsh, FE_DLCR5) & FE_D5_BUFEMP) 977 break; 978 979 /* 980 * Extract receive packet status from the receive 981 * packet header. 982 */ 983 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) { 984 status = bus_space_read_1(bst, bsh, FE_BMPR8); 985 (void)bus_space_read_1(bst, bsh, FE_BMPR8); 986 } else 987 status = bus_space_read_2(bst, bsh, FE_BMPR8); 988 989 #if FE_DEBUG >= 4 990 log(LOG_INFO, "%s: receive status = %02x\n", 991 sc->sc_dev.dv_xname, status); 992 #endif 993 994 /* 995 * If there was an error, update statistics and drop 996 * the packet, unless the interface is in promiscuous 997 * mode. 998 */ 999 if ((status & FE_RXSTAT_GOODPKT) == 0) { 1000 if ((ifp->if_flags & IFF_PROMISC) == 0) { 1001 ifp->if_ierrors++; 1002 mb86960_droppacket(sc); 1003 continue; 1004 } 1005 } 1006 1007 /* 1008 * Extract the packet length from the receive packet header. 1009 * It is a sum of a header (14 bytes) and a payload. 1010 * CRC has been stripped off by the 86960. 1011 */ 1012 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) { 1013 len = bus_space_read_1(bst, bsh, FE_BMPR8); 1014 len |= bus_space_read_1(bst, bsh, FE_BMPR8) << 8; 1015 } else 1016 len = bus_space_read_2(bst, bsh, FE_BMPR8); 1017 1018 /* 1019 * MB86965 checks the packet length and drop big packet 1020 * before passing it to us. There are no chance we can 1021 * get [crufty] packets. Hence, if the length exceeds 1022 * the specified limit, it means some serious failure, 1023 * such as out-of-sync on receive buffer management. 1024 * 1025 * Is this statement true? FIXME. 1026 */ 1027 if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN) || 1028 len < ETHER_HDR_LEN) { 1029 #if FE_DEBUG >= 2 1030 log(LOG_WARNING, 1031 "%s: received a %s packet? (%u bytes)\n", 1032 sc->sc_dev.dv_xname, 1033 len < ETHER_HDR_LEN ? "partial" : "big", len); 1034 #endif 1035 ifp->if_ierrors++; 1036 mb86960_droppacket(sc); 1037 continue; 1038 } 1039 1040 /* 1041 * Check for a short (RUNT) packet. We *do* check 1042 * but do nothing other than print a message. 1043 * Short packets are illegal, but does nothing bad 1044 * if it carries data for upper layer. 1045 */ 1046 #if FE_DEBUG >= 2 1047 if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN)) { 1048 log(LOG_WARNING, 1049 "%s: received a short packet? (%u bytes)\n", 1050 sc->sc_dev.dv_xname, len); 1051 } 1052 #endif 1053 1054 /* 1055 * Go get a packet. 1056 */ 1057 if (mb86960_get_packet(sc, len) == 0) { 1058 /* Skip a packet, updating statistics. */ 1059 #if FE_DEBUG >= 2 1060 log(LOG_WARNING, 1061 "%s: out of mbufs; dropping packet (%u bytes)\n", 1062 sc->sc_dev.dv_xname, len); 1063 #endif 1064 ifp->if_ierrors++; 1065 mb86960_droppacket(sc); 1066 1067 /* 1068 * We stop receiving packets, even if there are 1069 * more in the buffer. We hope we can get more 1070 * mbufs next time. 1071 */ 1072 return; 1073 } 1074 1075 /* Successfully received a packet. Update stat. */ 1076 ifp->if_ipackets++; 1077 } 1078 } 1079 1080 /* 1081 * Ethernet interface interrupt processor 1082 */ 1083 int 1084 mb86960_intr(void *arg) 1085 { 1086 struct mb86960_softc *sc = arg; 1087 bus_space_tag_t bst = sc->sc_bst; 1088 bus_space_handle_t bsh = sc->sc_bsh; 1089 struct ifnet *ifp = &sc->sc_ec.ec_if; 1090 uint8_t tstat, rstat; 1091 1092 if ((sc->sc_stat & FE_STAT_ENABLED) == 0 || 1093 !device_is_active(&sc->sc_dev)) 1094 return (0); 1095 1096 #if FE_DEBUG >= 4 1097 log(LOG_INFO, "%s: mb86960_intr()\n", sc->sc_dev.dv_xname); 1098 mb86960_dump(LOG_INFO, sc); 1099 #endif 1100 1101 /* 1102 * Get interrupt conditions, masking unneeded flags. 1103 */ 1104 tstat = bus_space_read_1(bst, bsh, FE_DLCR0) & FE_TMASK; 1105 rstat = bus_space_read_1(bst, bsh, FE_DLCR1) & FE_RMASK; 1106 if (tstat == 0 && rstat == 0) 1107 return (0); 1108 1109 /* 1110 * Loop until there are no more new interrupt conditions. 1111 */ 1112 for (;;) { 1113 /* 1114 * Reset the conditions we are acknowledging. 1115 */ 1116 bus_space_write_1(bst, bsh, FE_DLCR0, tstat); 1117 bus_space_write_1(bst, bsh, FE_DLCR1, rstat); 1118 1119 /* 1120 * Handle transmitter interrupts. Handle these first because 1121 * the receiver will reset the board under some conditions. 1122 */ 1123 if (tstat != 0) 1124 mb86960_tint(sc, tstat); 1125 1126 /* 1127 * Handle receiver interrupts. 1128 */ 1129 if (rstat != 0) 1130 mb86960_rint(sc, rstat); 1131 1132 /* 1133 * Update the multicast address filter if it is 1134 * needed and possible. We do it now, because 1135 * we can make sure the transmission buffer is empty, 1136 * and there is a good chance that the receive queue 1137 * is empty. It will minimize the possibility of 1138 * packet lossage. 1139 */ 1140 if (sc->filter_change && 1141 sc->txb_count == 0 && sc->txb_sched == 0) { 1142 mb86960_loadmar(sc); 1143 ifp->if_flags &= ~IFF_OACTIVE; 1144 } 1145 1146 /* 1147 * If it looks like the transmitter can take more data, 1148 * attempt to start output on the interface. This is done 1149 * after handling the receiver interrupt to give the 1150 * receive operation priority. 1151 */ 1152 if ((ifp->if_flags & IFF_OACTIVE) == 0) 1153 mb86960_start(ifp); 1154 1155 #if NRND > 0 1156 if (rstat != 0 || tstat != 0) 1157 rnd_add_uint32(&sc->rnd_source, rstat + tstat); 1158 #endif 1159 1160 /* 1161 * Get interrupt conditions, masking unneeded flags. 1162 */ 1163 tstat = bus_space_read_1(bst, bsh, FE_DLCR0) & FE_TMASK; 1164 rstat = bus_space_read_1(bst, bsh, FE_DLCR1) & FE_RMASK; 1165 if (tstat == 0 && rstat == 0) 1166 return (1); 1167 } 1168 } 1169 1170 /* 1171 * Process an ioctl request. This code needs some work - it looks pretty ugly. 1172 */ 1173 int 1174 mb86960_ioctl(struct ifnet *ifp, u_long cmd, void *data) 1175 { 1176 struct mb86960_softc *sc = ifp->if_softc; 1177 struct ifaddr *ifa = (struct ifaddr *)data; 1178 struct ifreq *ifr = (struct ifreq *)data; 1179 int s, error = 0; 1180 1181 #if FE_DEBUG >= 3 1182 log(LOG_INFO, "%s: ioctl(%lx)\n", sc->sc_dev.dv_xname, cmd); 1183 #endif 1184 1185 s = splnet(); 1186 1187 switch (cmd) { 1188 case SIOCSIFADDR: 1189 if ((error = mb86960_enable(sc)) != 0) 1190 break; 1191 ifp->if_flags |= IFF_UP; 1192 1193 switch (ifa->ifa_addr->sa_family) { 1194 #ifdef INET 1195 case AF_INET: 1196 mb86960_init(sc); 1197 arp_ifinit(ifp, ifa); 1198 break; 1199 #endif 1200 default: 1201 mb86960_init(sc); 1202 break; 1203 } 1204 break; 1205 1206 case SIOCSIFFLAGS: 1207 if ((ifp->if_flags & IFF_UP) == 0 && 1208 (ifp->if_flags & IFF_RUNNING) != 0) { 1209 /* 1210 * If interface is marked down and it is running, then 1211 * stop it. 1212 */ 1213 mb86960_stop(sc); 1214 ifp->if_flags &= ~IFF_RUNNING; 1215 mb86960_disable(sc); 1216 } else if ((ifp->if_flags & IFF_UP) != 0 && 1217 (ifp->if_flags & IFF_RUNNING) == 0) { 1218 /* 1219 * If interface is marked up and it is stopped, then 1220 * start it. 1221 */ 1222 if ((error = mb86960_enable(sc)) != 0) 1223 break; 1224 mb86960_init(sc); 1225 } else if ((ifp->if_flags & IFF_UP) != 0) { 1226 /* 1227 * Reset the interface to pick up changes in any other 1228 * flags that affect hardware registers. 1229 */ 1230 mb86960_setmode(sc); 1231 } 1232 #if FE_DEBUG >= 1 1233 /* "ifconfig fe0 debug" to print register dump. */ 1234 if (ifp->if_flags & IFF_DEBUG) { 1235 log(LOG_INFO, "%s: SIOCSIFFLAGS(DEBUG)\n", 1236 sc->sc_dev.dv_xname); 1237 mb86960_dump(LOG_DEBUG, sc); 1238 } 1239 #endif 1240 break; 1241 1242 case SIOCADDMULTI: 1243 case SIOCDELMULTI: 1244 if ((sc->sc_stat & FE_STAT_ENABLED) == 0) { 1245 error = EIO; 1246 break; 1247 } 1248 1249 /* Update our multicast list. */ 1250 if ((error = ether_ioctl(ifp, cmd, data)) == ENETRESET) { 1251 /* 1252 * Multicast list has changed; set the hardware filter 1253 * accordingly. 1254 */ 1255 if (ifp->if_flags & IFF_RUNNING) 1256 mb86960_setmode(sc); 1257 error = 0; 1258 } 1259 break; 1260 1261 case SIOCGIFMEDIA: 1262 case SIOCSIFMEDIA: 1263 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd); 1264 break; 1265 1266 default: 1267 error = EINVAL; 1268 break; 1269 } 1270 1271 splx(s); 1272 return (error); 1273 } 1274 1275 /* 1276 * Retrieve packet from receive buffer and send to the next level up via 1277 * ether_input(). If there is a BPF listener, give a copy to BPF, too. 1278 * Returns 0 if success, -1 if error (i.e., mbuf allocation failure). 1279 */ 1280 int 1281 mb86960_get_packet(struct mb86960_softc *sc, u_int len) 1282 { 1283 bus_space_tag_t bst = sc->sc_bst; 1284 bus_space_handle_t bsh = sc->sc_bsh; 1285 struct ifnet *ifp = &sc->sc_ec.ec_if; 1286 struct mbuf *m; 1287 1288 /* Allocate a header mbuf. */ 1289 MGETHDR(m, M_DONTWAIT, MT_DATA); 1290 if (m == 0) 1291 return (0); 1292 m->m_pkthdr.rcvif = ifp; 1293 m->m_pkthdr.len = len; 1294 1295 /* The following silliness is to make NFS happy. */ 1296 #define EROUND ((sizeof(struct ether_header) + 3) & ~3) 1297 #define EOFF (EROUND - sizeof(struct ether_header)) 1298 1299 /* 1300 * Our strategy has one more problem. There is a policy on 1301 * mbuf cluster allocation. It says that we must have at 1302 * least MINCLSIZE (208 bytes) to allocate a cluster. For a 1303 * packet of a size between (MHLEN - 2) to (MINCLSIZE - 2), 1304 * our code violates the rule... 1305 * On the other hand, the current code is short, simple, 1306 * and fast, however. It does no harmful thing, just waists 1307 * some memory. Any comments? FIXME. 1308 */ 1309 1310 /* Attach a cluster if this packet doesn't fit in a normal mbuf. */ 1311 if (len > MHLEN - EOFF) { 1312 MCLGET(m, M_DONTWAIT); 1313 if ((m->m_flags & M_EXT) == 0) { 1314 m_freem(m); 1315 return (0); 1316 } 1317 } 1318 1319 /* 1320 * The following assumes there is room for the ether header in the 1321 * header mbuf. 1322 */ 1323 m->m_data += EOFF; 1324 1325 /* Set the length of this packet. */ 1326 m->m_len = len; 1327 1328 /* Get a packet. */ 1329 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) 1330 bus_space_read_multi_1(bst, bsh, FE_BMPR8, 1331 mtod(m, uint8_t *), len); 1332 else 1333 bus_space_read_multi_stream_2(bst, bsh, FE_BMPR8, 1334 mtod(m, uint16_t *), (len + 1) >> 1); 1335 1336 #if NBPFILTER > 0 1337 /* 1338 * Check if there's a BPF listener on this interface. If so, hand off 1339 * the raw packet to bpf. 1340 */ 1341 if (ifp->if_bpf) 1342 bpf_mtap(ifp->if_bpf, m); 1343 #endif 1344 1345 (*ifp->if_input)(ifp, m); 1346 return (1); 1347 } 1348 1349 /* 1350 * Write an mbuf chain to the transmission buffer memory using 16 bit PIO. 1351 * Returns number of bytes actually written, including length word. 1352 * 1353 * If an mbuf chain is too long for an Ethernet frame, it is not sent. 1354 * Packets shorter than Ethernet minimum are legal, and we pad them 1355 * before sending out. An exception is "partial" packets which are 1356 * shorter than mandatory Ethernet header. 1357 * 1358 * I wrote a code for an experimental "delayed padding" technique. 1359 * When employed, it postpones the padding process for short packets. 1360 * If xmit() occurred at the moment, the padding process is omitted, and 1361 * garbages are sent as pad data. If next packet is stored in the 1362 * transmission buffer before xmit(), write_mbuf() pads the previous 1363 * packet before transmitting new packet. This *may* gain the 1364 * system performance (slightly). 1365 */ 1366 void 1367 mb86960_write_mbufs(struct mb86960_softc *sc, struct mbuf *m) 1368 { 1369 bus_space_tag_t bst = sc->sc_bst; 1370 bus_space_handle_t bsh = sc->sc_bsh; 1371 int totlen, len; 1372 #if FE_DEBUG >= 2 1373 struct mbuf *mp; 1374 #endif 1375 1376 #if FE_DELAYED_PADDING 1377 /* Do the "delayed padding." */ 1378 if (sc->txb_padding > 0) { 1379 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) { 1380 for (len = sc->txb_padding; len > 0; len--) 1381 bus_space_write_1(bst, bsh, FE_BMPR8, 0); 1382 } else { 1383 for (len = sc->txb_padding >> 1; len > 0; len--) 1384 bus_space_write_2(bst, bsh, FE_BMPR8, 0); 1385 } 1386 sc->txb_padding = 0; 1387 } 1388 #endif 1389 1390 /* We need to use m->m_pkthdr.len, so require the header */ 1391 if ((m->m_flags & M_PKTHDR) == 0) 1392 panic("mb86960_write_mbufs: no header mbuf"); 1393 1394 #if FE_DEBUG >= 2 1395 /* First, count up the total number of bytes to copy. */ 1396 for (totlen = 0, mp = m; mp != 0; mp = mp->m_next) 1397 totlen += mp->m_len; 1398 /* Check if this matches the one in the packet header. */ 1399 if (totlen != m->m_pkthdr.len) 1400 log(LOG_WARNING, "%s: packet length mismatch? (%d/%d)\n", 1401 sc->sc_dev.dv_xname, totlen, m->m_pkthdr.len); 1402 #else 1403 /* Just use the length value in the packet header. */ 1404 totlen = m->m_pkthdr.len; 1405 #endif 1406 1407 #if FE_DEBUG >= 1 1408 /* 1409 * Should never send big packets. If such a packet is passed, 1410 * it should be a bug of upper layer. We just ignore it. 1411 * ... Partial (too short) packets, neither. 1412 */ 1413 if (totlen > (ETHER_MAX_LEN - ETHER_CRC_LEN) || 1414 totlen < ETHER_HDR_LEN) { 1415 log(LOG_ERR, "%s: got a %s packet (%u bytes) to send\n", 1416 sc->sc_dev.dv_xname, 1417 totlen < ETHER_HDR_LEN ? "partial" : "big", totlen); 1418 sc->sc_ec.ec_if.if_oerrors++; 1419 return; 1420 } 1421 #endif 1422 1423 /* 1424 * Put the length word for this frame. 1425 * Does 86960 accept odd length? -- Yes. 1426 * Do we need to pad the length to minimum size by ourselves? 1427 * -- Generally yes. But for (or will be) the last 1428 * packet in the transmission buffer, we can skip the 1429 * padding process. It may gain performance slightly. FIXME. 1430 */ 1431 len = max(totlen, (ETHER_MIN_LEN - ETHER_CRC_LEN)); 1432 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) { 1433 bus_space_write_1(bst, bsh, FE_BMPR8, len); 1434 bus_space_write_1(bst, bsh, FE_BMPR8, len >> 8); 1435 } else { 1436 bus_space_write_2(bst, bsh, FE_BMPR8, len); 1437 /* roundup packet length since we will use word access */ 1438 totlen = (totlen + 1) & ~1; 1439 } 1440 1441 /* 1442 * Update buffer status now. 1443 * Truncate the length up to an even number 1444 * if the chip is set in SBW_WORD mode. 1445 */ 1446 sc->txb_free -= FE_TXLEN_SIZE + 1447 max(totlen, (ETHER_MIN_LEN - ETHER_CRC_LEN)); 1448 sc->txb_count++; 1449 1450 #if FE_DELAYED_PADDING 1451 /* Postpone the packet padding if necessary. */ 1452 if (totlen < (ETHER_MIN_LEN - ETHER_CRC_LEN)) 1453 sc->txb_padding = (ETHER_MIN_LEN - ETHER_CRC_LEN) - totlen; 1454 #endif 1455 1456 /* 1457 * Transfer the data from mbuf chain to the transmission buffer. 1458 * If the MB86960 is configured in word mode, data needs to be 1459 * transferred as words, and only words. 1460 * So that we require some extra code to patch over odd-length 1461 * or unaligned mbufs. 1462 */ 1463 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) { 1464 /* It's simple in byte mode. */ 1465 for (; m != NULL; m = m->m_next) { 1466 if (m->m_len) { 1467 bus_space_write_multi_1(bst, bsh, FE_BMPR8, 1468 mtod(m, uint8_t *), m->m_len); 1469 } 1470 } 1471 } else { 1472 /* a bit trickier in word mode. */ 1473 uint8_t *data, savebyte[2]; 1474 int leftover; 1475 1476 leftover = 0; 1477 savebyte[0] = savebyte[1] = 0; 1478 1479 for (; m != NULL; m = m->m_next) { 1480 len = m->m_len; 1481 if (len == 0) 1482 continue; 1483 data = mtod(m, uint8_t *); 1484 while (len > 0) { 1485 if (leftover) { 1486 /* 1487 * Data left over (from mbuf or 1488 * realignment). Buffer the next 1489 * byte, and write it and the 1490 * leftover data out. 1491 */ 1492 savebyte[1] = *data++; 1493 len--; 1494 bus_space_write_stream_2(bst, bsh, 1495 FE_BMPR8, *(uint16_t *)savebyte); 1496 leftover = 0; 1497 } else if (BUS_SPACE_ALIGNED_POINTER(data, 1498 uint16_t) == 0) { 1499 /* 1500 * Unaligned data; buffer the next byte. 1501 */ 1502 savebyte[0] = *data++; 1503 len--; 1504 leftover = 1; 1505 } else { 1506 /* 1507 * Aligned data; output contiguous 1508 * words as much as we can, then 1509 * buffer the remaining byte, if any. 1510 */ 1511 leftover = len & 1; 1512 len &= ~1; 1513 bus_space_write_multi_stream_2(bst, bsh, 1514 FE_BMPR8, (uint16_t *)data, 1515 len >> 1); 1516 data += len; 1517 if (leftover) 1518 savebyte[0] = *data++; 1519 len = 0; 1520 } 1521 } 1522 if (len < 0) 1523 panic("mb86960_write_mbufs: negative len"); 1524 } 1525 if (leftover) { 1526 savebyte[1] = 0; 1527 bus_space_write_stream_2(bst, bsh, FE_BMPR8, 1528 *(uint16_t *)savebyte); 1529 } 1530 } 1531 #if FE_DELAYED_PADDING == 0 1532 /* 1533 * Pad the packet to the minimum length if necessary. 1534 */ 1535 len = (ETHER_MIN_LEN - ETHER_CRC_LEN) - totlen; 1536 if (len > 0) { 1537 if (sc->sc_flags & FE_FLAGS_SBW_BYTE) { 1538 while (len-- > 0) 1539 bus_space_write_1(bst, bsh, FE_BMPR8, 0); 1540 } else { 1541 len >>= 1; 1542 while (len-- > 0) 1543 bus_space_write_2(bst, bsh, FE_BMPR8, 0); 1544 } 1545 } 1546 #endif 1547 } 1548 1549 /* 1550 * Compute the multicast address filter from the 1551 * list of multicast addresses we need to listen to. 1552 */ 1553 void 1554 mb86960_getmcaf(struct ethercom *ec, uint8_t *af) 1555 { 1556 struct ifnet *ifp = &ec->ec_if; 1557 struct ether_multi *enm; 1558 uint32_t crc; 1559 struct ether_multistep step; 1560 1561 /* 1562 * Set up multicast address filter by passing all multicast addresses 1563 * through a crc generator, and then using the high order 6 bits as an 1564 * index into the 64 bit logical address filter. The high order bit 1565 * selects the word, while the rest of the bits select the bit within 1566 * the word. 1567 */ 1568 1569 if ((ifp->if_flags & IFF_PROMISC) != 0) 1570 goto allmulti; 1571 1572 memset(af, 0, FE_FILTER_LEN); 1573 ETHER_FIRST_MULTI(step, ec, enm); 1574 while (enm != NULL) { 1575 if (memcmp(enm->enm_addrlo, enm->enm_addrhi, 1576 sizeof(enm->enm_addrlo)) != 0) { 1577 /* 1578 * We must listen to a range of multicast addresses. 1579 * For now, just accept all multicasts, rather than 1580 * trying to set only those filter bits needed to match 1581 * the range. (At this time, the only use of address 1582 * ranges is for IP multicast routing, for which the 1583 * range is big enough to require all bits set.) 1584 */ 1585 goto allmulti; 1586 } 1587 1588 crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN); 1589 1590 /* Just want the 6 most significant bits. */ 1591 crc >>= 26; 1592 1593 /* Turn on the corresponding bit in the filter. */ 1594 af[crc >> 3] |= 1 << (crc & 7); 1595 1596 ETHER_NEXT_MULTI(step, enm); 1597 } 1598 ifp->if_flags &= ~IFF_ALLMULTI; 1599 return; 1600 1601 allmulti: 1602 ifp->if_flags |= IFF_ALLMULTI; 1603 memset(af, 0xff, FE_FILTER_LEN); 1604 } 1605 1606 /* 1607 * Calculate a new "multicast packet filter" and put the 86960 1608 * receiver in appropriate mode. 1609 */ 1610 void 1611 mb86960_setmode(struct mb86960_softc *sc) 1612 { 1613 bus_space_tag_t bst = sc->sc_bst; 1614 bus_space_handle_t bsh = sc->sc_bsh; 1615 int flags = sc->sc_ec.ec_if.if_flags; 1616 1617 /* 1618 * If the interface is not running, we postpone the update 1619 * process for receive modes and multicast address filter 1620 * until the interface is restarted. It reduces some 1621 * complicated job on maintaining chip states. (Earlier versions 1622 * of this driver had a bug on that point...) 1623 * 1624 * To complete the trick, mb86960_init() calls mb86960_setmode() after 1625 * restarting the interface. 1626 */ 1627 if ((flags & IFF_RUNNING) == 0) 1628 return; 1629 1630 /* 1631 * Promiscuous mode is handled separately. 1632 */ 1633 if ((flags & IFF_PROMISC) != 0) { 1634 /* 1635 * Program 86960 to receive all packets on the segment 1636 * including those directed to other stations. 1637 * Multicast filter stored in MARs are ignored 1638 * under this setting, so we don't need to update it. 1639 * 1640 * Promiscuous mode is used solely by BPF, and BPF only 1641 * listens to valid (no error) packets. So, we ignore 1642 * errornous ones even in this mode. 1643 */ 1644 bus_space_write_1(bst, bsh, FE_DLCR5, 1645 sc->proto_dlcr5 | FE_D5_AFM0 | FE_D5_AFM1); 1646 sc->filter_change = 0; 1647 1648 #if FE_DEBUG >= 3 1649 log(LOG_INFO, "%s: promiscuous mode\n", sc->sc_dev.dv_xname); 1650 #endif 1651 return; 1652 } 1653 1654 /* 1655 * Turn the chip to the normal (non-promiscuous) mode. 1656 */ 1657 bus_space_write_1(bst, bsh, FE_DLCR5, sc->proto_dlcr5 | FE_D5_AFM1); 1658 1659 /* 1660 * Find the new multicast filter value. 1661 */ 1662 mb86960_getmcaf(&sc->sc_ec, sc->filter); 1663 sc->filter_change = 1; 1664 1665 #if FE_DEBUG >= 3 1666 log(LOG_INFO, 1667 "%s: address filter: [%02x %02x %02x %02x %02x %02x %02x %02x]\n", 1668 sc->sc_dev.dv_xname, 1669 sc->filter[0], sc->filter[1], sc->filter[2], sc->filter[3], 1670 sc->filter[4], sc->filter[5], sc->filter[6], sc->filter[7]); 1671 #endif 1672 1673 /* 1674 * We have to update the multicast filter in the 86960, A.S.A.P. 1675 * 1676 * Note that the DLC (Data Linc Control unit, i.e. transmitter 1677 * and receiver) must be stopped when feeding the filter, and 1678 * DLC trashes all packets in both transmission and receive 1679 * buffers when stopped. 1680 * 1681 * ... Are the above sentenses correct? I have to check the 1682 * manual of the MB86960A. FIXME. 1683 * 1684 * To reduce the packet lossage, we delay the filter update 1685 * process until buffers are empty. 1686 */ 1687 if (sc->txb_sched == 0 && sc->txb_count == 0 && 1688 (bus_space_read_1(bst, bsh, FE_DLCR1) & FE_D1_PKTRDY) == 0) { 1689 /* 1690 * Buffers are (apparently) empty. Load 1691 * the new filter value into MARs now. 1692 */ 1693 mb86960_loadmar(sc); 1694 } else { 1695 /* 1696 * Buffers are not empty. Mark that we have to update 1697 * the MARs. The new filter will be loaded by mb86960_intr() 1698 * later. 1699 */ 1700 #if FE_DEBUG >= 4 1701 log(LOG_INFO, "%s: filter change delayed\n", 1702 sc->sc_dev.dv_xname); 1703 #endif 1704 } 1705 } 1706 1707 /* 1708 * Load a new multicast address filter into MARs. 1709 * 1710 * The caller must have splnet'ed befor mb86960_loadmar. 1711 * This function starts the DLC upon return. So it can be called only 1712 * when the chip is working, i.e., from the driver's point of view, when 1713 * a device is RUNNING. (I mistook the point in previous versions.) 1714 */ 1715 void 1716 mb86960_loadmar(struct mb86960_softc *sc) 1717 { 1718 bus_space_tag_t bst = sc->sc_bst; 1719 bus_space_handle_t bsh = sc->sc_bsh; 1720 1721 /* Stop the DLC (transmitter and receiver). */ 1722 bus_space_write_1(bst, bsh, FE_DLCR6, 1723 sc->proto_dlcr6 | FE_D6_DLC_DISABLE); 1724 1725 /* Select register bank 1 for MARs. */ 1726 bus_space_write_1(bst, bsh, FE_DLCR7, 1727 sc->proto_dlcr7 | FE_D7_RBS_MAR | FE_D7_POWER_UP); 1728 1729 /* Copy filter value into the registers. */ 1730 bus_space_write_region_1(bst, bsh, FE_MAR8, sc->filter, FE_FILTER_LEN); 1731 1732 /* Restore the bank selection for BMPRs (i.e., runtime registers). */ 1733 bus_space_write_1(bst, bsh, FE_DLCR7, 1734 sc->proto_dlcr7 | FE_D7_RBS_BMPR | FE_D7_POWER_UP); 1735 1736 /* Restart the DLC. */ 1737 bus_space_write_1(bst, bsh, FE_DLCR6, 1738 sc->proto_dlcr6 | FE_D6_DLC_ENABLE); 1739 1740 /* We have just updated the filter. */ 1741 sc->filter_change = 0; 1742 1743 #if FE_DEBUG >= 3 1744 log(LOG_INFO, "%s: address filter changed\n", sc->sc_dev.dv_xname); 1745 #endif 1746 } 1747 1748 /* 1749 * Enable power on the interface. 1750 */ 1751 int 1752 mb86960_enable(struct mb86960_softc *sc) 1753 { 1754 1755 #if FE_DEBUG >= 3 1756 log(LOG_INFO, "%s: mb86960_enable()\n", sc->sc_dev.dv_xname); 1757 #endif 1758 1759 if ((sc->sc_stat & FE_STAT_ENABLED) == 0 && sc->sc_enable != NULL) { 1760 if ((*sc->sc_enable)(sc) != 0) { 1761 printf("%s: device enable failed\n", 1762 sc->sc_dev.dv_xname); 1763 return (EIO); 1764 } 1765 } 1766 1767 sc->sc_stat |= FE_STAT_ENABLED; 1768 return (0); 1769 } 1770 1771 /* 1772 * Disable power on the interface. 1773 */ 1774 void 1775 mb86960_disable(struct mb86960_softc *sc) 1776 { 1777 1778 #if FE_DEBUG >= 3 1779 log(LOG_INFO, "%s: mb86960_disable()\n", sc->sc_dev.dv_xname); 1780 #endif 1781 1782 if ((sc->sc_stat & FE_STAT_ENABLED) != 0 && sc->sc_disable != NULL) { 1783 (*sc->sc_disable)(sc); 1784 sc->sc_stat &= ~FE_STAT_ENABLED; 1785 } 1786 } 1787 1788 /* 1789 * mbe_activate: 1790 * 1791 * Handle device activation/deactivation requests. 1792 */ 1793 int 1794 mb86960_activate(struct device *self, enum devact act) 1795 { 1796 struct mb86960_softc *sc = (struct mb86960_softc *)self; 1797 int rv, s; 1798 1799 rv = 0; 1800 s = splnet(); 1801 switch (act) { 1802 case DVACT_ACTIVATE: 1803 rv = EOPNOTSUPP; 1804 break; 1805 1806 case DVACT_DEACTIVATE: 1807 if_deactivate(&sc->sc_ec.ec_if); 1808 break; 1809 } 1810 splx(s); 1811 return (rv); 1812 } 1813 1814 /* 1815 * mb86960_detach: 1816 * 1817 * Detach a MB86960 interface. 1818 */ 1819 int 1820 mb86960_detach(struct mb86960_softc *sc) 1821 { 1822 struct ifnet *ifp = &sc->sc_ec.ec_if; 1823 1824 /* Succeed now if there's no work to do. */ 1825 if ((sc->sc_stat & FE_STAT_ATTACHED) == 0) 1826 return (0); 1827 1828 /* Delete all media. */ 1829 ifmedia_delete_instance(&sc->sc_media, IFM_INST_ANY); 1830 1831 #if NRND > 0 1832 /* Unhook the entropy source. */ 1833 rnd_detach_source(&sc->rnd_source); 1834 #endif 1835 ether_ifdetach(ifp); 1836 if_detach(ifp); 1837 1838 mb86960_disable(sc); 1839 return (0); 1840 } 1841 1842 /* 1843 * Routines to read all bytes from the config EEPROM (93C06) through MB86965A. 1844 */ 1845 void 1846 mb86965_read_eeprom(bus_space_tag_t iot, bus_space_handle_t ioh, uint8_t *data) 1847 { 1848 int addr, op, bit; 1849 uint16_t val; 1850 1851 /* Read bytes from EEPROM; two bytes per an iteration. */ 1852 for (addr = 0; addr < FE_EEPROM_SIZE / 2; addr++) { 1853 /* Reset the EEPROM interface. */ 1854 bus_space_write_1(iot, ioh, FE_BMPR16, 0x00); 1855 bus_space_write_1(iot, ioh, FE_BMPR17, 0x00); 1856 bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT); 1857 1858 /* Send start bit. */ 1859 bus_space_write_1(iot, ioh, FE_BMPR17, FE_B17_DATA); 1860 FE_EEPROM_DELAY(); 1861 bus_space_write_1(iot, ioh, 1862 FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK); 1863 FE_EEPROM_DELAY(); 1864 bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT); 1865 1866 /* Send read command and read address. */ 1867 op = 0x80 | addr; /* READ instruction */ 1868 for (bit = 8; bit > 0; bit--) { 1869 bus_space_write_1(iot, ioh, FE_BMPR17, 1870 (op & (1 << (bit - 1))) ? FE_B17_DATA : 0); 1871 FE_EEPROM_DELAY(); 1872 bus_space_write_1(iot, ioh, 1873 FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK); 1874 FE_EEPROM_DELAY(); 1875 bus_space_write_1(iot, ioh, FE_BMPR16, FE_B16_SELECT); 1876 } 1877 bus_space_write_1(iot, ioh, FE_BMPR17, 0x00); 1878 1879 /* Read two bytes in each address */ 1880 val = 0; 1881 for (bit = 16; bit > 0; bit--) { 1882 FE_EEPROM_DELAY(); 1883 bus_space_write_1(iot, ioh, 1884 FE_BMPR16, FE_B16_SELECT | FE_B16_CLOCK); 1885 FE_EEPROM_DELAY(); 1886 if (bus_space_read_1(iot, ioh, FE_BMPR17) & 1887 FE_B17_DATA) 1888 val |= 1 << (bit - 1); 1889 bus_space_write_1(iot, ioh, 1890 FE_BMPR16, FE_B16_SELECT); 1891 } 1892 data[addr * 2] = val >> 8; 1893 data[addr * 2 + 1] = val & 0xff; 1894 } 1895 1896 /* Make sure the EEPROM is turned off. */ 1897 bus_space_write_1(iot, ioh, FE_BMPR16, 0); 1898 bus_space_write_1(iot, ioh, FE_BMPR17, 0); 1899 1900 #if FE_DEBUG >= 3 1901 /* Report what we got. */ 1902 log(LOG_INFO, "mb86965_read_eeprom: " 1903 " %02x%02x%02x%02x %02x%02x%02x%02x -" 1904 " %02x%02x%02x%02x %02x%02x%02x%02x -" 1905 " %02x%02x%02x%02x %02x%02x%02x%02x -" 1906 " %02x%02x%02x%02x %02x%02x%02x%02x\n", 1907 data[ 0], data[ 1], data[ 2], data[ 3], 1908 data[ 4], data[ 5], data[ 6], data[ 7], 1909 data[ 8], data[ 9], data[10], data[11], 1910 data[12], data[13], data[14], data[15], 1911 data[16], data[17], data[18], data[19], 1912 data[20], data[21], data[22], data[23], 1913 data[24], data[25], data[26], data[27], 1914 data[28], data[29], data[30], data[31]); 1915 #endif 1916 } 1917 1918 #if FE_DEBUG >= 1 1919 void 1920 mb86960_dump(int level, struct mb86960_softc *sc) 1921 { 1922 bus_space_tag_t bst = sc->sc_bst; 1923 bus_space_handle_t bsh = sc->sc_bsh; 1924 uint8_t save_dlcr7; 1925 1926 save_dlcr7 = bus_space_read_1(bst, bsh, FE_DLCR7); 1927 1928 log(level, "\tDLCR = %02x %02x %02x %02x %02x %02x %02x %02x\n", 1929 bus_space_read_1(bst, bsh, FE_DLCR0), 1930 bus_space_read_1(bst, bsh, FE_DLCR1), 1931 bus_space_read_1(bst, bsh, FE_DLCR2), 1932 bus_space_read_1(bst, bsh, FE_DLCR3), 1933 bus_space_read_1(bst, bsh, FE_DLCR4), 1934 bus_space_read_1(bst, bsh, FE_DLCR5), 1935 bus_space_read_1(bst, bsh, FE_DLCR6), 1936 bus_space_read_1(bst, bsh, FE_DLCR7)); 1937 1938 bus_space_write_1(bst, bsh, FE_DLCR7, 1939 (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_DLCR); 1940 log(level, "\t %02x %02x %02x %02x %02x %02x %02x %02x\n", 1941 bus_space_read_1(bst, bsh, FE_DLCR8), 1942 bus_space_read_1(bst, bsh, FE_DLCR9), 1943 bus_space_read_1(bst, bsh, FE_DLCR10), 1944 bus_space_read_1(bst, bsh, FE_DLCR11), 1945 bus_space_read_1(bst, bsh, FE_DLCR12), 1946 bus_space_read_1(bst, bsh, FE_DLCR13), 1947 bus_space_read_1(bst, bsh, FE_DLCR14), 1948 bus_space_read_1(bst, bsh, FE_DLCR15)); 1949 1950 bus_space_write_1(bst, bsh, FE_DLCR7, 1951 (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_MAR); 1952 log(level, "\tMAR = %02x %02x %02x %02x %02x %02x %02x %02x\n", 1953 bus_space_read_1(bst, bsh, FE_MAR8), 1954 bus_space_read_1(bst, bsh, FE_MAR9), 1955 bus_space_read_1(bst, bsh, FE_MAR10), 1956 bus_space_read_1(bst, bsh, FE_MAR11), 1957 bus_space_read_1(bst, bsh, FE_MAR12), 1958 bus_space_read_1(bst, bsh, FE_MAR13), 1959 bus_space_read_1(bst, bsh, FE_MAR14), 1960 bus_space_read_1(bst, bsh, FE_MAR15)); 1961 1962 bus_space_write_1(bst, bsh, FE_DLCR7, 1963 (save_dlcr7 & ~FE_D7_RBS) | FE_D7_RBS_BMPR); 1964 log(level, 1965 "\tBMPR = xx xx %02x %02x %02x %02x %02x %02x %02x %02x xx %02x\n", 1966 bus_space_read_1(bst, bsh, FE_BMPR10), 1967 bus_space_read_1(bst, bsh, FE_BMPR11), 1968 bus_space_read_1(bst, bsh, FE_BMPR12), 1969 bus_space_read_1(bst, bsh, FE_BMPR13), 1970 bus_space_read_1(bst, bsh, FE_BMPR14), 1971 bus_space_read_1(bst, bsh, FE_BMPR15), 1972 bus_space_read_1(bst, bsh, FE_BMPR16), 1973 bus_space_read_1(bst, bsh, FE_BMPR17), 1974 bus_space_read_1(bst, bsh, FE_BMPR19)); 1975 1976 bus_space_write_1(bst, bsh, FE_DLCR7, save_dlcr7); 1977 } 1978 #endif 1979 1980