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