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