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