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