Home | History | Annotate | Line # | Download | only in ic
am7990.c revision 1.70
      1 /*	$NetBSD: am7990.c,v 1.70 2008/04/04 12:25:07 tsutsui 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  * 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 #include <sys/cdefs.h>
     75 __KERNEL_RCSID(0, "$NetBSD: am7990.c,v 1.70 2008/04/04 12:25:07 tsutsui Exp $");
     76 
     77 #include "bpfilter.h"
     78 #include "rnd.h"
     79 
     80 #include <sys/param.h>
     81 #include <sys/systm.h>
     82 #include <sys/mbuf.h>
     83 #include <sys/syslog.h>
     84 #include <sys/socket.h>
     85 #include <sys/device.h>
     86 #include <sys/malloc.h>
     87 #include <sys/ioctl.h>
     88 #include <sys/errno.h>
     89 #if NRND > 0
     90 #include <sys/rnd.h>
     91 #endif
     92 
     93 #include <net/if.h>
     94 #include <net/if_dl.h>
     95 #include <net/if_ether.h>
     96 #include <net/if_media.h>
     97 
     98 #if NBPFILTER > 0
     99 #include <net/bpf.h>
    100 #include <net/bpfdesc.h>
    101 #endif
    102 
    103 #include <dev/ic/lancereg.h>
    104 #include <dev/ic/lancevar.h>
    105 #include <dev/ic/am7990reg.h>
    106 #include <dev/ic/am7990var.h>
    107 
    108 static void	am7990_meminit(struct lance_softc *);
    109 static void	am7990_start(struct ifnet *);
    110 
    111 #if defined(_KERNEL_OPT)
    112 #include "opt_ddb.h"
    113 #endif
    114 
    115 #ifdef LEDEBUG
    116 static void	am7990_recv_print(struct lance_softc *, int);
    117 static void	am7990_xmit_print(struct lance_softc *, int);
    118 #endif
    119 
    120 #define	ifp	(&sc->sc_ethercom.ec_if)
    121 
    122 void
    123 am7990_config(struct am7990_softc *sc)
    124 {
    125 	int mem, i;
    126 
    127 	sc->lsc.sc_meminit = am7990_meminit;
    128 	sc->lsc.sc_start = am7990_start;
    129 
    130 	lance_config(&sc->lsc);
    131 
    132 	mem = 0;
    133 	sc->lsc.sc_initaddr = mem;
    134 	mem += sizeof(struct leinit);
    135 	sc->lsc.sc_rmdaddr = mem;
    136 	mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf;
    137 	sc->lsc.sc_tmdaddr = mem;
    138 	mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf;
    139 	for (i = 0; i < sc->lsc.sc_nrbuf; i++, mem += LEBLEN)
    140 		sc->lsc.sc_rbufaddr[i] = mem;
    141 	for (i = 0; i < sc->lsc.sc_ntbuf; i++, mem += LEBLEN)
    142 		sc->lsc.sc_tbufaddr[i] = mem;
    143 #ifdef notyet
    144 	if (mem > ...)
    145 		panic(...);
    146 #endif
    147 }
    148 
    149 /*
    150  * Set up the initialization block and the descriptor rings.
    151  */
    152 static void
    153 am7990_meminit(struct lance_softc *sc)
    154 {
    155 	u_long a;
    156 	int bix;
    157 	struct leinit init;
    158 	struct lermd rmd;
    159 	struct letmd tmd;
    160 	uint8_t *myaddr;
    161 
    162 #if NBPFILTER > 0
    163 	if (ifp->if_flags & IFF_PROMISC)
    164 		init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM;
    165 	else
    166 #endif
    167 		init.init_mode = LE_MODE_NORMAL;
    168 	if (sc->sc_initmodemedia == 1)
    169 		init.init_mode |= LE_MODE_PSEL0;
    170 
    171 	/*
    172 	 * Update our private copy of the Ethernet address.
    173 	 * We NEED the copy so we can ensure its alignment!
    174 	 */
    175 	memcpy(sc->sc_enaddr, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
    176 	myaddr = sc->sc_enaddr;
    177 
    178 	init.init_padr[0] = (myaddr[1] << 8) | myaddr[0];
    179 	init.init_padr[1] = (myaddr[3] << 8) | myaddr[2];
    180 	init.init_padr[2] = (myaddr[5] << 8) | myaddr[4];
    181 	lance_setladrf(&sc->sc_ethercom, init.init_ladrf);
    182 
    183 	sc->sc_last_rd = 0;
    184 	sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0;
    185 
    186 	a = sc->sc_addr + LE_RMDADDR(sc, 0);
    187 	init.init_rdra = a;
    188 	init.init_rlen = (a >> 16) | ((ffs(sc->sc_nrbuf) - 1) << 13);
    189 
    190 	a = sc->sc_addr + LE_TMDADDR(sc, 0);
    191 	init.init_tdra = a;
    192 	init.init_tlen = (a >> 16) | ((ffs(sc->sc_ntbuf) - 1) << 13);
    193 
    194 	(*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init));
    195 
    196 	/*
    197 	 * Set up receive ring descriptors.
    198 	 */
    199 	for (bix = 0; bix < sc->sc_nrbuf; bix++) {
    200 		a = sc->sc_addr + LE_RBUFADDR(sc, bix);
    201 		rmd.rmd0 = a;
    202 		rmd.rmd1_hadr = a >> 16;
    203 		rmd.rmd1_bits = LE_R1_OWN;
    204 		rmd.rmd2 = -LEBLEN | LE_XMD2_ONES;
    205 		rmd.rmd3 = 0;
    206 		(*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix),
    207 		    sizeof(rmd));
    208 	}
    209 
    210 	/*
    211 	 * Set up transmit ring descriptors.
    212 	 */
    213 	for (bix = 0; bix < sc->sc_ntbuf; bix++) {
    214 		a = sc->sc_addr + LE_TBUFADDR(sc, bix);
    215 		tmd.tmd0 = a;
    216 		tmd.tmd1_hadr = a >> 16;
    217 		tmd.tmd1_bits = 0;
    218 		tmd.tmd2 = 0 | LE_XMD2_ONES;
    219 		tmd.tmd3 = 0;
    220 		(*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix),
    221 		    sizeof(tmd));
    222 	}
    223 }
    224 
    225 static void
    226 am7990_rint(struct lance_softc *sc)
    227 {
    228 	int bix;
    229 	int rp;
    230 	struct lermd rmd;
    231 
    232 	bix = sc->sc_last_rd;
    233 
    234 	/* Process all buffers with valid data. */
    235 	for (;;) {
    236 		rp = LE_RMDADDR(sc, bix);
    237 		(*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd));
    238 
    239 		if (rmd.rmd1_bits & LE_R1_OWN)
    240 			break;
    241 
    242 		if (rmd.rmd1_bits & LE_R1_ERR) {
    243 			if (rmd.rmd1_bits & LE_R1_ENP) {
    244 #ifdef LEDEBUG
    245 				if ((rmd.rmd1_bits & LE_R1_OFLO) == 0) {
    246 					if (rmd.rmd1_bits & LE_R1_FRAM)
    247 						printf("%s: framing error\n",
    248 						    device_xname(sc->sc_dev));
    249 					if (rmd.rmd1_bits & LE_R1_CRC)
    250 						printf("%s: crc mismatch\n",
    251 						    device_xname(sc->sc_dev));
    252 				}
    253 #endif
    254 			} else {
    255 				if (rmd.rmd1_bits & LE_R1_OFLO)
    256 					printf("%s: overflow\n",
    257 					    device_xname(sc->sc_dev));
    258 			}
    259 			if (rmd.rmd1_bits & LE_R1_BUFF)
    260 				printf("%s: receive buffer error\n",
    261 				    device_xname(sc->sc_dev));
    262 			ifp->if_ierrors++;
    263 		} else if ((rmd.rmd1_bits & (LE_R1_STP | LE_R1_ENP)) !=
    264 		    (LE_R1_STP | LE_R1_ENP)) {
    265 			printf("%s: dropping chained buffer\n",
    266 			    device_xname(sc->sc_dev));
    267 			ifp->if_ierrors++;
    268 		} else {
    269 #ifdef LEDEBUG
    270 			if (sc->sc_debug > 1)
    271 				am7990_recv_print(sc, sc->sc_last_rd);
    272 #endif
    273 			lance_read(sc, LE_RBUFADDR(sc, bix),
    274 				   (int)rmd.rmd3 - 4);
    275 		}
    276 
    277 		rmd.rmd1_bits = LE_R1_OWN;
    278 		rmd.rmd2 = -LEBLEN | LE_XMD2_ONES;
    279 		rmd.rmd3 = 0;
    280 		(*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd));
    281 
    282 #ifdef LEDEBUG
    283 		if (sc->sc_debug)
    284 			printf("sc->sc_last_rd = %x, rmd: "
    285 			       "ladr %04x, hadr %02x, flags %02x, "
    286 			       "bcnt %04x, mcnt %04x\n",
    287 				sc->sc_last_rd,
    288 				rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits,
    289 				rmd.rmd2, rmd.rmd3);
    290 #endif
    291 
    292 		if (++bix == sc->sc_nrbuf)
    293 			bix = 0;
    294 	}
    295 
    296 	sc->sc_last_rd = bix;
    297 }
    298 
    299 static void
    300 am7990_tint(struct lance_softc *sc)
    301 {
    302 	int bix;
    303 	struct letmd tmd;
    304 
    305 	bix = sc->sc_first_td;
    306 
    307 	for (;;) {
    308 		if (sc->sc_no_td <= 0)
    309 			break;
    310 
    311 		(*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix),
    312 		    sizeof(tmd));
    313 
    314 #ifdef LEDEBUG
    315 		if (sc->sc_debug)
    316 			printf("trans tmd: "
    317 			    "ladr %04x, hadr %02x, flags %02x, "
    318 			    "bcnt %04x, mcnt %04x\n",
    319 			    tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits,
    320 			    tmd.tmd2, tmd.tmd3);
    321 #endif
    322 
    323 		if (tmd.tmd1_bits & LE_T1_OWN)
    324 			break;
    325 
    326 		ifp->if_flags &= ~IFF_OACTIVE;
    327 
    328 		if (tmd.tmd1_bits & LE_T1_ERR) {
    329 			if (tmd.tmd3 & LE_T3_BUFF)
    330 				printf("%s: transmit buffer error\n",
    331 				    device_xname(sc->sc_dev));
    332 			else if (tmd.tmd3 & LE_T3_UFLO)
    333 				printf("%s: underflow\n",
    334 				    device_xname(sc->sc_dev));
    335 			if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) {
    336 				lance_reset(sc);
    337 				return;
    338 			}
    339 			if (tmd.tmd3 & LE_T3_LCAR) {
    340 				sc->sc_havecarrier = 0;
    341 				if (sc->sc_nocarrier)
    342 					(*sc->sc_nocarrier)(sc);
    343 				else
    344 					printf("%s: lost carrier\n",
    345 					    device_xname(sc->sc_dev));
    346 			}
    347 			if (tmd.tmd3 & LE_T3_LCOL)
    348 				ifp->if_collisions++;
    349 			if (tmd.tmd3 & LE_T3_RTRY) {
    350 #ifdef LEDEBUG
    351 				printf("%s: excessive collisions, tdr %d\n",
    352 				    device_xname(sc->sc_dev),
    353 				    tmd.tmd3 & LE_T3_TDR_MASK);
    354 #endif
    355 				ifp->if_collisions += 16;
    356 			}
    357 			ifp->if_oerrors++;
    358 		} else {
    359 			if (tmd.tmd1_bits & LE_T1_ONE)
    360 				ifp->if_collisions++;
    361 			else if (tmd.tmd1_bits & LE_T1_MORE)
    362 				/* Real number is unknown. */
    363 				ifp->if_collisions += 2;
    364 			ifp->if_opackets++;
    365 		}
    366 
    367 		if (++bix == sc->sc_ntbuf)
    368 			bix = 0;
    369 
    370 		--sc->sc_no_td;
    371 	}
    372 
    373 	sc->sc_first_td = bix;
    374 
    375 	am7990_start(ifp);
    376 
    377 	if (sc->sc_no_td == 0)
    378 		ifp->if_timer = 0;
    379 }
    380 
    381 /*
    382  * Controller interrupt.
    383  */
    384 int
    385 am7990_intr(void *arg)
    386 {
    387 	struct lance_softc *sc = arg;
    388 	uint16_t isr;
    389 
    390 	isr = (*sc->sc_rdcsr)(sc, LE_CSR0) | sc->sc_saved_csr0;
    391 	sc->sc_saved_csr0 = 0;
    392 #if defined(LEDEBUG) && LEDEBUG > 1
    393 	if (sc->sc_debug)
    394 		printf("%s: am7990_intr entering with isr=%04x\n",
    395 		    device_xname(sc->sc_dev), isr);
    396 #endif
    397 	if ((isr & LE_C0_INTR) == 0)
    398 		return (0);
    399 
    400 #ifdef __vax__
    401 	/*
    402 	 * DEC needs this write order to the registers, don't know
    403 	 * the results on other arch's.  Ragge 991029
    404 	 */
    405 	isr &= ~LE_C0_INEA;
    406 	(*sc->sc_wrcsr)(sc, LE_CSR0, isr);
    407 	(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA);
    408 #else
    409 	(*sc->sc_wrcsr)(sc, LE_CSR0,
    410 	    isr & (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR |
    411 		   LE_C0_RINT | LE_C0_TINT | LE_C0_IDON));
    412 #endif
    413 	if (isr & LE_C0_ERR) {
    414 		if (isr & LE_C0_BABL) {
    415 #ifdef LEDEBUG
    416 			printf("%s: babble\n", device_xname(sc->sc_dev));
    417 #endif
    418 			ifp->if_oerrors++;
    419 		}
    420 #if 0
    421 		if (isr & LE_C0_CERR) {
    422 			printf("%s: collision error\n",
    423 			    device_xname(sc->sc_dev));
    424 			ifp->if_collisions++;
    425 		}
    426 #endif
    427 		if (isr & LE_C0_MISS) {
    428 #ifdef LEDEBUG
    429 			printf("%s: missed packet\n", device_xname(sc->sc_dev));
    430 #endif
    431 			ifp->if_ierrors++;
    432 		}
    433 		if (isr & LE_C0_MERR) {
    434 			printf("%s: memory error\n", device_xname(sc->sc_dev));
    435 			lance_reset(sc);
    436 			return (1);
    437 		}
    438 	}
    439 
    440 	if ((isr & LE_C0_RXON) == 0) {
    441 		printf("%s: receiver disabled\n", device_xname(sc->sc_dev));
    442 		ifp->if_ierrors++;
    443 		lance_reset(sc);
    444 		return (1);
    445 	}
    446 	if ((isr & LE_C0_TXON) == 0) {
    447 		printf("%s: transmitter disabled\n", device_xname(sc->sc_dev));
    448 		ifp->if_oerrors++;
    449 		lance_reset(sc);
    450 		return (1);
    451 	}
    452 
    453 	/*
    454 	 * Pretend we have carrier; if we don't this will be cleared
    455 	 * shortly.
    456 	 */
    457 	sc->sc_havecarrier = 1;
    458 
    459 	if (isr & LE_C0_RINT)
    460 		am7990_rint(sc);
    461 	if (isr & LE_C0_TINT)
    462 		am7990_tint(sc);
    463 
    464 #if NRND > 0
    465 	rnd_add_uint32(&sc->rnd_source, isr);
    466 #endif
    467 
    468 	return (1);
    469 }
    470 
    471 #undef ifp
    472 
    473 /*
    474  * Setup output on interface.
    475  * Get another datagram to send off of the interface queue, and map it to the
    476  * interface before starting the output.
    477  * Called only at splnet or interrupt level.
    478  */
    479 static void
    480 am7990_start(struct ifnet *ifp)
    481 {
    482 	struct lance_softc *sc = ifp->if_softc;
    483 	int bix;
    484 	struct mbuf *m;
    485 	struct letmd tmd;
    486 	int rp;
    487 	int len;
    488 
    489 	if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
    490 		return;
    491 
    492 	bix = sc->sc_last_td;
    493 
    494 	for (;;) {
    495 		rp = LE_TMDADDR(sc, bix);
    496 		(*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd));
    497 
    498 		if (tmd.tmd1_bits & LE_T1_OWN) {
    499 			ifp->if_flags |= IFF_OACTIVE;
    500 			printf("missing buffer, no_td = %d, last_td = %d\n",
    501 			    sc->sc_no_td, sc->sc_last_td);
    502 		}
    503 
    504 		IFQ_DEQUEUE(&ifp->if_snd, m);
    505 		if (m == 0)
    506 			break;
    507 
    508 #if NBPFILTER > 0
    509 		/*
    510 		 * If BPF is listening on this interface, let it see the packet
    511 		 * before we commit it to the wire.
    512 		 */
    513 		if (ifp->if_bpf)
    514 			bpf_mtap(ifp->if_bpf, m);
    515 #endif
    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_bits = LE_T1_OWN | LE_T1_STP | LE_T1_ENP;
    533 		tmd.tmd2 = -len | LE_XMD2_ONES;
    534 		tmd.tmd3 = 0;
    535 
    536 		(*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd));
    537 
    538 #ifdef LEDEBUG
    539 		if (sc->sc_debug > 1)
    540 			am7990_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 am7990_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.rmd3;
    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: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",
    573 	    device_xname(sc->sc_dev),
    574 	    rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3);
    575 	if (len >= sizeof(eh)) {
    576 		(*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh));
    577 		printf("%s: dst %s", device_xname(sc->sc_dev),
    578 			ether_sprintf(eh.ether_dhost));
    579 		printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
    580 			ntohs(eh.ether_type));
    581 	}
    582 }
    583 
    584 static void
    585 am7990_xmit_print(struct lance_softc *sc, int no)
    586 {
    587 	struct letmd tmd;
    588 	uint16_t len;
    589 	struct ether_header eh;
    590 
    591 	(*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd));
    592 	len = -tmd.tmd2;
    593 	printf("%s: transmit buffer %d, len = %d\n",
    594 	    device_xname(sc->sc_dev), no, len);
    595 	printf("%s: status %04x\n", device_xname(sc->sc_dev),
    596 	    (*sc->sc_rdcsr)(sc, LE_CSR0));
    597 	printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",
    598 	    device_xname(sc->sc_dev),
    599 	    tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, tmd.tmd2, tmd.tmd3);
    600 	if (len >= sizeof(eh)) {
    601 		(*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh));
    602 		printf("%s: dst %s", device_xname(sc->sc_dev),
    603 			ether_sprintf(eh.ether_dhost));
    604 		printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
    605 		    ntohs(eh.ether_type));
    606 	}
    607 }
    608 #endif /* LEDEBUG */
    609