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