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