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