Home | History | Annotate | Line # | Download | only in ic
am79900.c revision 1.26.2.1
      1 /*	$NetBSD: am79900.c,v 1.26.2.1 2018/07/26 23:55:29 snj 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.26.2.1 2018/07/26 23:55:29 snj 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/rndsource.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 #include <net/bpf.h>
    124 
    125 #include <dev/ic/lancereg.h>
    126 #include <dev/ic/lancevar.h>
    127 #include <dev/ic/am79900reg.h>
    128 #include <dev/ic/am79900var.h>
    129 
    130 static void	am79900_meminit(struct lance_softc *);
    131 static void	am79900_start(struct ifnet *);
    132 
    133 #if defined(_KERNEL_OPT)
    134 #include "opt_ddb.h"
    135 #endif
    136 
    137 #ifdef LEDEBUG
    138 static void	am79900_recv_print(struct lance_softc *, int);
    139 static void	am79900_xmit_print(struct lance_softc *, int);
    140 #endif
    141 
    142 #define	ifp	(&sc->sc_ethercom.ec_if)
    143 
    144 void
    145 am79900_config(struct am79900_softc *sc)
    146 {
    147 	int mem, i;
    148 
    149 	sc->lsc.sc_meminit = am79900_meminit;
    150 	sc->lsc.sc_start = am79900_start;
    151 
    152 	lance_config(&sc->lsc);
    153 	if_deferred_start_init(&sc->lsc.sc_ethercom.ec_if, NULL);
    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 	for (i = 0; i < sc->lsc.sc_nrbuf; i++, mem += LEBLEN)
    163 		sc->lsc.sc_rbufaddr[i] = mem;
    164 	for (i = 0; i < sc->lsc.sc_ntbuf; i++, mem += LEBLEN)
    165 		sc->lsc.sc_tbufaddr[i] = mem;
    166 
    167 	if (mem > sc->lsc.sc_memsize)
    168 		panic("%s: memsize", device_xname(sc->lsc.sc_dev));
    169 }
    170 
    171 /*
    172  * Set up the initialization block and the descriptor rings.
    173  */
    174 static void
    175 am79900_meminit(struct lance_softc *sc)
    176 {
    177 	u_long a;
    178 	int bix;
    179 	struct leinit init;
    180 	struct lermd rmd;
    181 	struct letmd tmd;
    182 	uint8_t *myaddr;
    183 
    184 	if (ifp->if_flags & IFF_PROMISC)
    185 		init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM;
    186 	else
    187 		init.init_mode = LE_MODE_NORMAL;
    188 	if (sc->sc_initmodemedia == 1)
    189 		init.init_mode |= LE_MODE_PSEL0;
    190 
    191 	init.init_mode |= ((ffs(sc->sc_ntbuf) - 1) << 28)
    192 	  | ((ffs(sc->sc_nrbuf) - 1) << 20);
    193 
    194 	/*
    195 	 * Update our private copy of the Ethernet address.
    196 	 * We NEED the copy so we can ensure its alignment!
    197 	 */
    198 	memcpy(sc->sc_enaddr, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
    199 	myaddr = sc->sc_enaddr;
    200 
    201 	init.init_padr[0] = myaddr[0] | (myaddr[1] << 8)
    202 	  | (myaddr[2] << 16) | (myaddr[3] << 24);
    203 	init.init_padr[1] = myaddr[4] | (myaddr[5] << 8);
    204 	lance_setladrf(&sc->sc_ethercom, init.init_ladrf);
    205 
    206 	sc->sc_last_rd = 0;
    207 	sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0;
    208 
    209 	a = sc->sc_addr + LE_RMDADDR(sc, 0);
    210 	init.init_rdra = a;
    211 
    212 	a = sc->sc_addr + LE_TMDADDR(sc, 0);
    213 	init.init_tdra = a;
    214 
    215 	(*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init));
    216 
    217 	/*
    218 	 * Set up receive ring descriptors.
    219 	 */
    220 	for (bix = 0; bix < sc->sc_nrbuf; bix++) {
    221 		a = sc->sc_addr + LE_RBUFADDR(sc, bix);
    222 		rmd.rmd0 = a;
    223 		rmd.rmd1 = LE_R1_OWN | LE_R1_ONES | (-LEBLEN & 0xfff);
    224 		rmd.rmd2 = 0;
    225 		rmd.rmd3 = 0;
    226 		(*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix),
    227 		    sizeof(rmd));
    228 	}
    229 
    230 	/*
    231 	 * Set up transmit ring descriptors.
    232 	 */
    233 	for (bix = 0; bix < sc->sc_ntbuf; bix++) {
    234 		a = sc->sc_addr + LE_TBUFADDR(sc, bix);
    235 		tmd.tmd0 = a;
    236 		tmd.tmd1 = LE_T1_ONES;
    237 		tmd.tmd2 = 0;
    238 		tmd.tmd3 = 0;
    239 		(*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix),
    240 		    sizeof(tmd));
    241 	}
    242 }
    243 
    244 static inline void
    245 am79900_rint(struct lance_softc *sc)
    246 {
    247 	int bix;
    248 	int rp;
    249 	struct lermd rmd;
    250 
    251 	bix = sc->sc_last_rd;
    252 
    253 	/* Process all buffers with valid data. */
    254 	for (;;) {
    255 		rp = LE_RMDADDR(sc, bix);
    256 		(*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd));
    257 
    258 		if (rmd.rmd1 & LE_R1_OWN)
    259 			break;
    260 
    261 		if (rmd.rmd1 & LE_R1_ERR) {
    262 			if (rmd.rmd1 & LE_R1_ENP) {
    263 #ifdef LEDEBUG
    264 				if ((rmd.rmd1 & LE_R1_OFLO) == 0) {
    265 					if (rmd.rmd1 & LE_R1_FRAM)
    266 						printf("%s: framing error\n",
    267 						    device_xname(sc->sc_dev));
    268 					if (rmd.rmd1 & LE_R1_CRC)
    269 						printf("%s: crc mismatch\n",
    270 						    device_xname(sc->sc_dev));
    271 				}
    272 #endif
    273 			} else {
    274 				if (rmd.rmd1 & LE_R1_OFLO)
    275 					printf("%s: overflow\n",
    276 					    device_xname(sc->sc_dev));
    277 			}
    278 			if (rmd.rmd1 & LE_R1_BUFF)
    279 				printf("%s: receive buffer error\n",
    280 				    device_xname(sc->sc_dev));
    281 			ifp->if_ierrors++;
    282 		} else if ((rmd.rmd1 & (LE_R1_STP | LE_R1_ENP)) !=
    283 		    (LE_R1_STP | LE_R1_ENP)) {
    284 			printf("%s: dropping chained buffer\n",
    285 			    device_xname(sc->sc_dev));
    286 			ifp->if_ierrors++;
    287 		} else {
    288 #ifdef LEDEBUG
    289 			if (sc->sc_debug)
    290 				am79900_recv_print(sc, sc->sc_last_rd);
    291 #endif
    292 			lance_read(sc, LE_RBUFADDR(sc, bix),
    293 				   (rmd.rmd2  & 0xfff) - 4);
    294 		}
    295 
    296 		rmd.rmd1 = LE_R1_OWN | LE_R1_ONES | (-LEBLEN & 0xfff);
    297 		rmd.rmd2 = 0;
    298 		rmd.rmd3 = 0;
    299 		(*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd));
    300 
    301 #ifdef LEDEBUG
    302 		if (sc->sc_debug)
    303 			printf("sc->sc_last_rd = %x, rmd: "
    304 			       "adr %08x, flags/blen %08x\n",
    305 				sc->sc_last_rd,
    306 				rmd.rmd0, rmd.rmd1);
    307 #endif
    308 
    309 		if (++bix == sc->sc_nrbuf)
    310 			bix = 0;
    311 	}
    312 
    313 	sc->sc_last_rd = bix;
    314 }
    315 
    316 static inline void
    317 am79900_tint(struct lance_softc *sc)
    318 {
    319 	int bix;
    320 	struct letmd tmd;
    321 
    322 	bix = sc->sc_first_td;
    323 
    324 	for (;;) {
    325 		if (sc->sc_no_td <= 0)
    326 			break;
    327 
    328 		(*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix),
    329 		    sizeof(tmd));
    330 
    331 #ifdef LEDEBUG
    332 		if (sc->sc_debug)
    333 			printf("trans tmd: "
    334 			    "adr %08x, flags/blen %08x\n",
    335 			    tmd.tmd0, tmd.tmd1);
    336 #endif
    337 
    338 		if (tmd.tmd1 & LE_T1_OWN)
    339 			break;
    340 
    341 		ifp->if_flags &= ~IFF_OACTIVE;
    342 
    343 		if (tmd.tmd1 & LE_T1_ERR) {
    344 			if (tmd.tmd2 & LE_T2_BUFF)
    345 				printf("%s: transmit buffer error\n",
    346 				    device_xname(sc->sc_dev));
    347 			else if (tmd.tmd2 & LE_T2_UFLO)
    348 				printf("%s: underflow\n",
    349 				    device_xname(sc->sc_dev));
    350 			if (tmd.tmd2 & (LE_T2_BUFF | LE_T2_UFLO)) {
    351 				lance_reset(sc);
    352 				return;
    353 			}
    354 			if (tmd.tmd2 & LE_T2_LCAR) {
    355 				sc->sc_havecarrier = 0;
    356 				if (sc->sc_nocarrier)
    357 					(*sc->sc_nocarrier)(sc);
    358 				else
    359 					printf("%s: lost carrier\n",
    360 					    device_xname(sc->sc_dev));
    361 			}
    362 			if (tmd.tmd2 & LE_T2_LCOL)
    363 				ifp->if_collisions++;
    364 			if (tmd.tmd2 & LE_T2_RTRY) {
    365 #ifdef LEDEBUG
    366 				printf("%s: excessive collisions\n",
    367 				    device_xname(sc->sc_dev));
    368 #endif
    369 				ifp->if_collisions += 16;
    370 			}
    371 			ifp->if_oerrors++;
    372 		} else {
    373 			if (tmd.tmd1 & LE_T1_ONE)
    374 				ifp->if_collisions++;
    375 			else if (tmd.tmd1 & LE_T1_MORE)
    376 				/* Real number is unknown. */
    377 				ifp->if_collisions += 2;
    378 			ifp->if_opackets++;
    379 		}
    380 
    381 		if (++bix == sc->sc_ntbuf)
    382 			bix = 0;
    383 
    384 		--sc->sc_no_td;
    385 	}
    386 
    387 	sc->sc_first_td = bix;
    388 
    389 	if_schedule_deferred_start(ifp);
    390 
    391 	if (sc->sc_no_td == 0)
    392 		ifp->if_timer = 0;
    393 }
    394 
    395 /*
    396  * Controller interrupt.
    397  */
    398 int
    399 am79900_intr(void *arg)
    400 {
    401 	struct lance_softc *sc = arg;
    402 	uint16_t isr;
    403 
    404 	isr = (*sc->sc_rdcsr)(sc, LE_CSR0) | sc->sc_saved_csr0;
    405 	sc->sc_saved_csr0 = 0;
    406 #if defined(LEDEBUG) && LEDEBUG > 1
    407 	if (sc->sc_debug)
    408 		printf("%s: am79900_intr entering with isr=%04x\n",
    409 		    device_xname(sc->sc_dev), isr);
    410 #endif
    411 	if ((isr & LE_C0_INTR) == 0)
    412 		return (0);
    413 
    414 	(*sc->sc_wrcsr)(sc, LE_CSR0,
    415 	    isr & (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR |
    416 		   LE_C0_RINT | LE_C0_TINT | LE_C0_IDON));
    417 	if (isr & LE_C0_ERR) {
    418 		if (isr & LE_C0_BABL) {
    419 #ifdef LEDEBUG
    420 			printf("%s: babble\n", device_xname(sc->sc_dev));
    421 #endif
    422 			ifp->if_oerrors++;
    423 		}
    424 #if 0
    425 		if (isr & LE_C0_CERR) {
    426 			printf("%s: collision error\n",
    427 			    device_xname(sc->sc_dev));
    428 			ifp->if_collisions++;
    429 		}
    430 #endif
    431 		if (isr & LE_C0_MISS) {
    432 #ifdef LEDEBUG
    433 			printf("%s: missed packet\n", device_xname(sc->sc_dev));
    434 #endif
    435 			ifp->if_ierrors++;
    436 		}
    437 		if (isr & LE_C0_MERR) {
    438 			printf("%s: memory error\n", device_xname(sc->sc_dev));
    439 			lance_reset(sc);
    440 			return (1);
    441 		}
    442 	}
    443 
    444 	if ((isr & LE_C0_RXON) == 0) {
    445 		printf("%s: receiver disabled\n", device_xname(sc->sc_dev));
    446 		ifp->if_ierrors++;
    447 		lance_reset(sc);
    448 		return (1);
    449 	}
    450 	if ((isr & LE_C0_TXON) == 0) {
    451 		printf("%s: transmitter disabled\n", device_xname(sc->sc_dev));
    452 		ifp->if_oerrors++;
    453 		lance_reset(sc);
    454 		return (1);
    455 	}
    456 
    457 	/*
    458 	 * Pretend we have carrier; if we don't this will be cleared
    459 	 * shortly.
    460 	 */
    461 	sc->sc_havecarrier = 1;
    462 
    463 	if (isr & LE_C0_RINT)
    464 		am79900_rint(sc);
    465 	if (isr & LE_C0_TINT)
    466 		am79900_tint(sc);
    467 
    468 	rnd_add_uint32(&sc->rnd_source, isr);
    469 
    470 	return (1);
    471 }
    472 
    473 #undef	ifp
    474 
    475 /*
    476  * Setup output on interface.
    477  * Get another datagram to send off of the interface queue, and map it to the
    478  * interface before starting the output.
    479  * Called only at splnet or interrupt level.
    480  */
    481 static void
    482 am79900_start(struct ifnet *ifp)
    483 {
    484 	struct lance_softc *sc = ifp->if_softc;
    485 	int bix;
    486 	struct mbuf *m;
    487 	struct letmd tmd;
    488 	int rp;
    489 	int len;
    490 
    491 	if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
    492 		return;
    493 
    494 	bix = sc->sc_last_td;
    495 
    496 	for (;;) {
    497 		rp = LE_TMDADDR(sc, bix);
    498 		(*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd));
    499 
    500 		if (tmd.tmd1 & LE_T1_OWN) {
    501 			ifp->if_flags |= IFF_OACTIVE;
    502 			printf("missing buffer, no_td = %d, last_td = %d\n",
    503 			    sc->sc_no_td, sc->sc_last_td);
    504 		}
    505 
    506 		IFQ_DEQUEUE(&ifp->if_snd, m);
    507 		if (m == 0)
    508 			break;
    509 
    510 		/*
    511 		 * If BPF is listening on this interface, let it see the packet
    512 		 * before we commit it to the wire.
    513 		 */
    514 		bpf_mtap(ifp, m);
    515 
    516 		/*
    517 		 * Copy the mbuf chain into the transmit buffer.
    518 		 */
    519 		len = lance_put(sc, LE_TBUFADDR(sc, bix), m);
    520 
    521 #ifdef LEDEBUG
    522 		if (len > ETHERMTU + sizeof(struct ether_header))
    523 			printf("packet length %d\n", len);
    524 #endif
    525 
    526 		ifp->if_timer = 5;
    527 
    528 		/*
    529 		 * Init transmit registers, and set transmit start flag.
    530 		 */
    531 		tmd.tmd1 = LE_T1_OWN | LE_T1_STP | LE_T1_ENP | LE_T1_ONES | (-len & 0xfff);
    532 		tmd.tmd2 = 0;
    533 		tmd.tmd3 = 0;
    534 
    535 		(*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd));
    536 
    537 #ifdef LEDEBUG
    538 		if (sc->sc_debug)
    539 			am79900_xmit_print(sc, sc->sc_last_td);
    540 #endif
    541 
    542 		(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD);
    543 
    544 		if (++bix == sc->sc_ntbuf)
    545 			bix = 0;
    546 
    547 		if (++sc->sc_no_td == sc->sc_ntbuf) {
    548 			ifp->if_flags |= IFF_OACTIVE;
    549 			break;
    550 		}
    551 
    552 	}
    553 
    554 	sc->sc_last_td = bix;
    555 }
    556 
    557 #ifdef LEDEBUG
    558 static void
    559 am79900_recv_print(struct lance_softc *sc, int no)
    560 {
    561 	struct lermd rmd;
    562 	uint16_t len;
    563 	struct ether_header eh;
    564 
    565 	(*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd));
    566 	len = (rmd.rmd2  & 0xfff) - 4;
    567 	printf("%s: receive buffer %d, len = %d\n",
    568 	    device_xname(sc->sc_dev), no, len);
    569 	printf("%s: status %04x\n", device_xname(sc->sc_dev),
    570 	    (*sc->sc_rdcsr)(sc, LE_CSR0));
    571 	printf("%s: adr %08x, flags/blen %08x\n",
    572 	    device_xname(sc->sc_dev), rmd.rmd0, rmd.rmd1);
    573 	if (len >= sizeof(eh)) {
    574 		(*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh));
    575 		printf("%s: dst %s", device_xname(sc->sc_dev),
    576 			ether_sprintf(eh.ether_dhost));
    577 		printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
    578 			ntohs(eh.ether_type));
    579 	}
    580 }
    581 
    582 static void
    583 am79900_xmit_print(struct lance_softc *sc, int no)
    584 {
    585 	struct letmd tmd;
    586 	uint16_t len;
    587 	struct ether_header eh;
    588 
    589 	(*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd));
    590 	len = -(tmd.tmd1 & 0xfff);
    591 	printf("%s: transmit buffer %d, len = %d\n",
    592 	    device_xname(sc->sc_dev), no, len);
    593 	printf("%s: status %04x\n", device_xname(sc->sc_dev),
    594 	    (*sc->sc_rdcsr)(sc, LE_CSR0));
    595 	printf("%s: adr %08x, flags/blen %08x\n",
    596 	    device_xname(sc->sc_dev), tmd.tmd0, tmd.tmd1);
    597 	if (len >= sizeof(eh)) {
    598 		(*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh));
    599 		printf("%s: dst %s", device_xname(sc->sc_dev),
    600 			ether_sprintf(eh.ether_dhost));
    601 		printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
    602 		    ntohs(eh.ether_type));
    603 	}
    604 }
    605 #endif /* LEDEBUG */
    606