1 /* $NetBSD: am79900.c,v 1.17 2005/12/24 20:27:29 perry Exp $ */ 2 3 /*- 4 * Copyright (c) 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 /*- 40 * Copyright (c) 1992, 1993 41 * The Regents of the University of California. All rights reserved. 42 * 43 * This code is derived from software contributed to Berkeley by 44 * Ralph Campbell and Rick Macklem. 45 * 46 * Redistribution and use in source and binary forms, with or without 47 * modification, are permitted provided that the following conditions 48 * are met: 49 * 1. Redistributions of source code must retain the above copyright 50 * notice, this list of conditions and the following disclaimer. 51 * 2. Redistributions in binary form must reproduce the above copyright 52 * notice, this list of conditions and the following disclaimer in the 53 * documentation and/or other materials provided with the distribution. 54 * 3. Neither the name of the University nor the names of its contributors 55 * may be used to endorse or promote products derived from this software 56 * without specific prior written permission. 57 * 58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 68 * SUCH DAMAGE. 69 * 70 * @(#)if_le.c 8.2 (Berkeley) 11/16/93 71 */ 72 73 /*- 74 * Copyright (c) 1998 75 * Matthias Drochner. All rights reserved. 76 * Copyright (c) 1995 Charles M. Hannum. All rights reserved. 77 * 78 * This code is derived from software contributed to Berkeley by 79 * Ralph Campbell and Rick Macklem. 80 * 81 * Redistribution and use in source and binary forms, with or without 82 * modification, are permitted provided that the following conditions 83 * are met: 84 * 1. Redistributions of source code must retain the above copyright 85 * notice, this list of conditions and the following disclaimer. 86 * 2. Redistributions in binary form must reproduce the above copyright 87 * notice, this list of conditions and the following disclaimer in the 88 * documentation and/or other materials provided with the distribution. 89 * 3. All advertising materials mentioning features or use of this software 90 * must display the following acknowledgement: 91 * This product includes software developed by the University of 92 * California, Berkeley and its contributors. 93 * 4. Neither the name of the University nor the names of its contributors 94 * may be used to endorse or promote products derived from this software 95 * without specific prior written permission. 96 * 97 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 98 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 99 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 100 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 101 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 102 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 103 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 104 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 105 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 106 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 107 * SUCH DAMAGE. 108 * 109 * @(#)if_le.c 8.2 (Berkeley) 11/16/93 110 */ 111 112 #include <sys/cdefs.h> 113 __FBSDID("$FreeBSD$"); 114 115 #include <sys/param.h> 116 #include <sys/bus.h> 117 #include <sys/endian.h> 118 #include <sys/lock.h> 119 #include <sys/mbuf.h> 120 #include <sys/mutex.h> 121 #include <sys/socket.h> 122 123 #include <net/bpf.h> 124 #include <net/ethernet.h> 125 #include <net/if.h> 126 #include <net/if_arp.h> 127 #include <net/if_dl.h> 128 #include <net/if_media.h> 129 #include <net/if_var.h> 130 131 #include <machine/bus.h> 132 133 #include <dev/le/lancereg.h> 134 #include <dev/le/lancevar.h> 135 #include <dev/le/am79900reg.h> 136 #include <dev/le/am79900var.h> 137 138 static void am79900_meminit(struct lance_softc *); 139 static void am79900_rint(struct lance_softc *); 140 static void am79900_tint(struct lance_softc *); 141 static void am79900_start_locked(struct lance_softc *sc); 142 143 #ifdef LEDEBUG 144 static void am79900_recv_print(struct lance_softc *, int); 145 static void am79900_xmit_print(struct lance_softc *, int); 146 #endif 147 148 int 149 am79900_config(struct am79900_softc *sc, const char* name, int unit) 150 { 151 int error, mem; 152 153 sc->lsc.sc_meminit = am79900_meminit; 154 sc->lsc.sc_start_locked = am79900_start_locked; 155 156 error = lance_config(&sc->lsc, name, unit); 157 if (error != 0) 158 return (error); 159 160 mem = 0; 161 sc->lsc.sc_initaddr = mem; 162 mem += sizeof(struct leinit); 163 sc->lsc.sc_rmdaddr = mem; 164 mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf; 165 sc->lsc.sc_tmdaddr = mem; 166 mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf; 167 sc->lsc.sc_rbufaddr = mem; 168 mem += LEBLEN * sc->lsc.sc_nrbuf; 169 sc->lsc.sc_tbufaddr = mem; 170 mem += LEBLEN * sc->lsc.sc_ntbuf; 171 172 if (mem > sc->lsc.sc_memsize) 173 panic("%s: memsize", __func__); 174 175 lance_attach(&sc->lsc); 176 177 return (0); 178 } 179 180 void 181 am79900_detach(struct am79900_softc *sc) 182 { 183 184 lance_detach(&sc->lsc); 185 } 186 187 /* 188 * Set up the initialization block and the descriptor rings. 189 */ 190 static void 191 am79900_meminit(struct lance_softc *sc) 192 { 193 struct ifnet *ifp = sc->sc_ifp; 194 struct leinit init; 195 struct lermd rmd; 196 struct letmd tmd; 197 u_long a; 198 int bix; 199 200 LE_LOCK_ASSERT(sc, MA_OWNED); 201 202 if (ifp->if_flags & IFF_PROMISC) 203 init.init_mode = LE_HTOLE32(LE_MODE_NORMAL | LE_MODE_PROM); 204 else 205 init.init_mode = LE_HTOLE32(LE_MODE_NORMAL); 206 207 init.init_mode |= LE_HTOLE32(((ffs(sc->sc_ntbuf) - 1) << 28) | 208 ((ffs(sc->sc_nrbuf) - 1) << 20)); 209 210 init.init_padr[0] = LE_HTOLE32(sc->sc_enaddr[0] | 211 (sc->sc_enaddr[1] << 8) | (sc->sc_enaddr[2] << 16) | 212 (sc->sc_enaddr[3] << 24)); 213 init.init_padr[1] = LE_HTOLE32(sc->sc_enaddr[4] | 214 (sc->sc_enaddr[5] << 8)); 215 lance_setladrf(sc, init.init_ladrf); 216 217 sc->sc_last_rd = 0; 218 sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0; 219 220 a = sc->sc_addr + LE_RMDADDR(sc, 0); 221 init.init_rdra = LE_HTOLE32(a); 222 223 a = sc->sc_addr + LE_TMDADDR(sc, 0); 224 init.init_tdra = LE_HTOLE32(a); 225 226 (*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init)); 227 228 /* 229 * Set up receive ring descriptors. 230 */ 231 for (bix = 0; bix < sc->sc_nrbuf; bix++) { 232 a = sc->sc_addr + LE_RBUFADDR(sc, bix); 233 rmd.rmd0 = LE_HTOLE32(a); 234 rmd.rmd1 = LE_HTOLE32(LE_R1_OWN | LE_R1_ONES | 235 (-LEBLEN & 0xfff)); 236 rmd.rmd2 = 0; 237 rmd.rmd3 = 0; 238 (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix), 239 sizeof(rmd)); 240 } 241 242 /* 243 * Set up transmit ring descriptors. 244 */ 245 for (bix = 0; bix < sc->sc_ntbuf; bix++) { 246 a = sc->sc_addr + LE_TBUFADDR(sc, bix); 247 tmd.tmd0 = LE_HTOLE32(a); 248 tmd.tmd1 = LE_HTOLE32(LE_T1_ONES); 249 tmd.tmd2 = 0; 250 tmd.tmd3 = 0; 251 (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix), 252 sizeof(tmd)); 253 } 254 } 255 256 static inline void 257 am79900_rint(struct lance_softc *sc) 258 { 259 struct ifnet *ifp = sc->sc_ifp; 260 struct mbuf *m; 261 struct lermd rmd; 262 uint32_t rmd1; 263 int bix, rp; 264 #if defined(__i386__) && !defined(PC98) 265 struct ether_header *eh; 266 #endif 267 268 bix = sc->sc_last_rd; 269 270 /* Process all buffers with valid data. */ 271 for (;;) { 272 rp = LE_RMDADDR(sc, bix); 273 (*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd)); 274 275 rmd1 = LE_LE32TOH(rmd.rmd1); 276 if (rmd1 & LE_R1_OWN) 277 break; 278 279 m = NULL; 280 if ((rmd1 & (LE_R1_ERR | LE_R1_STP | LE_R1_ENP)) != 281 (LE_R1_STP | LE_R1_ENP)){ 282 if (rmd1 & LE_R1_ERR) { 283 #ifdef LEDEBUG 284 if (rmd1 & LE_R1_ENP) { 285 if ((rmd1 & LE_R1_OFLO) == 0) { 286 if (rmd1 & LE_R1_FRAM) 287 if_printf(ifp, 288 "framing error\n"); 289 if (rmd1 & LE_R1_CRC) 290 if_printf(ifp, 291 "crc mismatch\n"); 292 } 293 } else 294 if (rmd1 & LE_R1_OFLO) 295 if_printf(ifp, "overflow\n"); 296 #endif 297 if (rmd1 & LE_R1_BUFF) 298 if_printf(ifp, 299 "receive buffer error\n"); 300 } else if ((rmd1 & (LE_R1_STP | LE_R1_ENP)) != 301 (LE_R1_STP | LE_R1_ENP)) 302 if_printf(ifp, "dropping chained buffer\n"); 303 } else { 304 #ifdef LEDEBUG 305 if (sc->sc_flags & LE_DEBUG) 306 am79900_recv_print(sc, bix); 307 #endif 308 /* Pull the packet off the interface. */ 309 m = lance_get(sc, LE_RBUFADDR(sc, bix), 310 (LE_LE32TOH(rmd.rmd2) & 0xfff) - ETHER_CRC_LEN); 311 } 312 313 rmd.rmd1 = LE_HTOLE32(LE_R1_OWN | LE_R1_ONES | 314 (-LEBLEN & 0xfff)); 315 rmd.rmd2 = 0; 316 rmd.rmd3 = 0; 317 (*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd)); 318 319 if (++bix == sc->sc_nrbuf) 320 bix = 0; 321 322 if (m != NULL) { 323 ifp->if_ipackets++; 324 325 #if defined(__i386__) && !defined(PC98) 326 /* 327 * The VMware LANCE does not present IFF_SIMPLEX 328 * behavior on multicast packets. Thus drop the 329 * packet if it is from ourselves. 330 */ 331 eh = mtod(m, struct ether_header *); 332 if (!ether_cmp(eh->ether_shost, sc->sc_enaddr)) { 333 m_freem(m); 334 continue; 335 } 336 #endif 337 338 /* Pass the packet up. */ 339 LE_UNLOCK(sc); 340 (*ifp->if_input)(ifp, m); 341 LE_LOCK(sc); 342 } else 343 ifp->if_ierrors++; 344 } 345 346 sc->sc_last_rd = bix; 347 } 348 349 static inline void 350 am79900_tint(struct lance_softc *sc) 351 { 352 struct ifnet *ifp = sc->sc_ifp; 353 struct letmd tmd; 354 uint32_t tmd1, tmd2; 355 int bix; 356 357 bix = sc->sc_first_td; 358 359 for (;;) { 360 if (sc->sc_no_td <= 0) 361 break; 362 363 (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix), 364 sizeof(tmd)); 365 366 tmd1 = LE_LE32TOH(tmd.tmd1); 367 368 #ifdef LEDEBUG 369 if (sc->sc_flags & LE_DEBUG) 370 if_printf(ifp, "trans tmd: " 371 "adr %08x, flags/blen %08x\n", 372 LE_LE32TOH(tmd.tmd0), tmd1); 373 #endif 374 375 if (tmd1 & LE_T1_OWN) 376 break; 377 378 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 379 380 if (tmd1 & LE_T1_ERR) { 381 tmd2 = LE_LE32TOH(tmd.tmd2); 382 if (tmd2 & LE_T2_BUFF) 383 if_printf(ifp, "transmit buffer error\n"); 384 else if (tmd2 & LE_T2_UFLO) 385 if_printf(ifp, "underflow\n"); 386 if (tmd2 & (LE_T2_BUFF | LE_T2_UFLO)) { 387 lance_init_locked(sc); 388 return; 389 } 390 if (tmd2 & LE_T2_LCAR) { 391 if (sc->sc_flags & LE_CARRIER) 392 if_link_state_change(ifp, 393 LINK_STATE_DOWN); 394 sc->sc_flags &= ~LE_CARRIER; 395 if (sc->sc_nocarrier) 396 (*sc->sc_nocarrier)(sc); 397 else 398 if_printf(ifp, "lost carrier\n"); 399 } 400 if (tmd2 & LE_T2_LCOL) 401 ifp->if_collisions++; 402 if (tmd2 & LE_T2_RTRY) { 403 #ifdef LEDEBUG 404 if_printf(ifp, "excessive collisions\n"); 405 #endif 406 ifp->if_collisions += 16; 407 } 408 ifp->if_oerrors++; 409 } else { 410 if (tmd1 & LE_T1_ONE) 411 ifp->if_collisions++; 412 else if (tmd1 & LE_T1_MORE) 413 /* Real number is unknown. */ 414 ifp->if_collisions += 2; 415 ifp->if_opackets++; 416 } 417 418 if (++bix == sc->sc_ntbuf) 419 bix = 0; 420 421 --sc->sc_no_td; 422 } 423 424 sc->sc_first_td = bix; 425 426 sc->sc_wdog_timer = sc->sc_no_td > 0 ? 5 : 0; 427 } 428 429 /* 430 * Controller interrupt 431 */ 432 void 433 am79900_intr(void *arg) 434 { 435 struct lance_softc *sc = arg; 436 struct ifnet *ifp = sc->sc_ifp; 437 uint16_t isr; 438 439 LE_LOCK(sc); 440 441 if (sc->sc_hwintr && (*sc->sc_hwintr)(sc) == -1) { 442 ifp->if_ierrors++; 443 lance_init_locked(sc); 444 LE_UNLOCK(sc); 445 return; 446 } 447 448 isr = (*sc->sc_rdcsr)(sc, LE_CSR0); 449 #if defined(LEDEBUG) && LEDEBUG > 1 450 if (sc->sc_flags & LE_DEBUG) 451 if_printf(ifp, "%s: entering with isr=%04x\n", __func__, isr); 452 #endif 453 if ((isr & LE_C0_INTR) == 0) { 454 LE_UNLOCK(sc); 455 return; 456 } 457 458 /* 459 * Clear interrupt source flags and turn off interrupts. If we 460 * don't clear these flags before processing their sources we 461 * could completely miss some interrupt events as the NIC can 462 * change these flags while we're in this handler. We turn off 463 * interrupts so we don't get another RX interrupt while still 464 * processing the previous one in ifp->if_input() with the 465 * driver lock dropped. 466 */ 467 (*sc->sc_wrcsr)(sc, LE_CSR0, isr & ~(LE_C0_INEA | LE_C0_TDMD | 468 LE_C0_STOP | LE_C0_STRT | LE_C0_INIT)); 469 470 if (isr & LE_C0_ERR) { 471 if (isr & LE_C0_BABL) { 472 #ifdef LEDEBUG 473 if_printf(ifp, "babble\n"); 474 #endif 475 ifp->if_oerrors++; 476 } 477 #if 0 478 if (isr & LE_C0_CERR) { 479 if_printf(ifp, "collision error\n"); 480 ifp->if_collisions++; 481 } 482 #endif 483 if (isr & LE_C0_MISS) { 484 #ifdef LEDEBUG 485 if_printf(ifp, "missed packet\n"); 486 #endif 487 ifp->if_ierrors++; 488 } 489 if (isr & LE_C0_MERR) { 490 if_printf(ifp, "memory error\n"); 491 lance_init_locked(sc); 492 LE_UNLOCK(sc); 493 return; 494 } 495 } 496 497 if ((isr & LE_C0_RXON) == 0) { 498 if_printf(ifp, "receiver disabled\n"); 499 ifp->if_ierrors++; 500 lance_init_locked(sc); 501 LE_UNLOCK(sc); 502 return; 503 } 504 if ((isr & LE_C0_TXON) == 0) { 505 if_printf(ifp, "transmitter disabled\n"); 506 ifp->if_oerrors++; 507 lance_init_locked(sc); 508 LE_UNLOCK(sc); 509 return; 510 } 511 512 /* 513 * Pretend we have carrier; if we don't this will be cleared shortly. 514 */ 515 if (!(sc->sc_flags & LE_CARRIER)) 516 if_link_state_change(ifp, LINK_STATE_UP); 517 sc->sc_flags |= LE_CARRIER; 518 519 if (isr & LE_C0_RINT) 520 am79900_rint(sc); 521 if (isr & LE_C0_TINT) 522 am79900_tint(sc); 523 524 /* Enable interrupts again. */ 525 (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA); 526 527 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) 528 am79900_start_locked(sc); 529 530 LE_UNLOCK(sc); 531 } 532 533 /* 534 * Set up output on interface. 535 * Get another datagram to send off of the interface queue, and map it to the 536 * interface before starting the output. 537 */ 538 static void 539 am79900_start_locked(struct lance_softc *sc) 540 { 541 struct ifnet *ifp = sc->sc_ifp; 542 struct letmd tmd; 543 struct mbuf *m; 544 int bix, enq, len, rp; 545 546 LE_LOCK_ASSERT(sc, MA_OWNED); 547 548 if ((ifp->if_drv_flags & (IFF_DRV_RUNNING | IFF_DRV_OACTIVE)) != 549 IFF_DRV_RUNNING) 550 return; 551 552 bix = sc->sc_last_td; 553 enq = 0; 554 555 for (; sc->sc_no_td < sc->sc_ntbuf && 556 !IFQ_DRV_IS_EMPTY(&ifp->if_snd);) { 557 rp = LE_TMDADDR(sc, bix); 558 (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd)); 559 560 if (LE_LE32TOH(tmd.tmd1) & LE_T1_OWN) { 561 ifp->if_drv_flags |= IFF_DRV_OACTIVE; 562 if_printf(ifp, 563 "missing buffer, no_td = %d, last_td = %d\n", 564 sc->sc_no_td, sc->sc_last_td); 565 } 566 567 IFQ_DRV_DEQUEUE(&ifp->if_snd, m); 568 if (m == 0) 569 break; 570 571 /* 572 * If BPF is listening on this interface, let it see the packet 573 * before we commit it to the wire. 574 */ 575 BPF_MTAP(ifp, m); 576 577 /* 578 * Copy the mbuf chain into the transmit buffer. 579 */ 580 len = lance_put(sc, LE_TBUFADDR(sc, bix), m); 581 582 #ifdef LEDEBUG 583 if (len > ETHERMTU + ETHER_HDR_LEN) 584 if_printf(ifp, "packet length %d\n", len); 585 #endif 586 587 /* 588 * Init transmit registers, and set transmit start flag. 589 */ 590 tmd.tmd1 = LE_HTOLE32(LE_T1_OWN | LE_T1_STP | LE_T1_ENP | 591 LE_T1_ONES | (-len & 0xfff)); 592 tmd.tmd2 = 0; 593 tmd.tmd3 = 0; 594 595 (*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd)); 596 597 #ifdef LEDEBUG 598 if (sc->sc_flags & LE_DEBUG) 599 am79900_xmit_print(sc, bix); 600 #endif 601 602 (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD); 603 enq++; 604 605 if (++bix == sc->sc_ntbuf) 606 bix = 0; 607 608 if (++sc->sc_no_td == sc->sc_ntbuf) { 609 ifp->if_drv_flags |= IFF_DRV_OACTIVE; 610 break; 611 } 612 } 613 614 sc->sc_last_td = bix; 615 616 if (enq > 0) 617 sc->sc_wdog_timer = 5; 618 } 619 620 #ifdef LEDEBUG 621 static void 622 am79900_recv_print(struct lance_softc *sc, int no) 623 { 624 struct ifnet *ifp = sc->sc_ifp; 625 struct ether_header eh; 626 struct lermd rmd; 627 uint16_t len; 628 629 (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd)); 630 len = LE_LE32TOH(rmd.rmd2) & 0xfff; 631 if_printf(ifp, "receive buffer %d, len = %d\n", no, len); 632 if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); 633 if_printf(ifp, "adr %08x, flags/blen %08x\n", LE_LE32TOH(rmd.rmd0), 634 LE_LE32TOH(rmd.rmd1)); 635 if (len - ETHER_CRC_LEN >= sizeof(eh)) { 636 (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh)); 637 if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); 638 printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), 639 ntohs(eh.ether_type)); 640 } 641 } 642 643 static void 644 am79900_xmit_print(struct lance_softc *sc, int no) 645 { 646 struct ifnet *ifp = sc->sc_ifp; 647 struct ether_header eh; 648 struct letmd tmd; 649 uint16_t len; 650 651 (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd)); 652 len = -(LE_LE32TOH(tmd.tmd1) & 0xfff); 653 if_printf(ifp, "transmit buffer %d, len = %d\n", no, len); 654 if_printf(ifp, "status %04x\n", (*sc->sc_rdcsr)(sc, LE_CSR0)); 655 if_printf(ifp, "adr %08x, flags/blen %08x\n", LE_LE32TOH(tmd.tmd0), 656 LE_LE32TOH(tmd.tmd1)); 657 if (len >= sizeof(eh)) { 658 (*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh)); 659 if_printf(ifp, "dst %s", ether_sprintf(eh.ether_dhost)); 660 printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost), 661 ntohs(eh.ether_type)); 662 } 663 } 664 #endif /* LEDEBUG */ 665