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