Home | History | Annotate | Line # | Download | only in ic
seeq8005.c revision 1.8.2.3
      1  1.8.2.3  nathanw /* $NetBSD: seeq8005.c,v 1.8.2.3 2001/08/24 00:09:36 nathanw Exp $ */
      2      1.1    bjh21 
      3      1.1    bjh21 /*
      4  1.8.2.3  nathanw  * Copyright (c) 2000, 2001 Ben Harris
      5  1.8.2.1  nathanw  * Copyright (c) 1995-1998 Mark Brinicombe
      6      1.1    bjh21  * All rights reserved.
      7      1.1    bjh21  *
      8      1.1    bjh21  * Redistribution and use in source and binary forms, with or without
      9      1.1    bjh21  * modification, are permitted provided that the following conditions
     10      1.1    bjh21  * are met:
     11      1.1    bjh21  * 1. Redistributions of source code must retain the above copyright
     12      1.1    bjh21  *    notice, this list of conditions and the following disclaimer.
     13      1.1    bjh21  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1    bjh21  *    notice, this list of conditions and the following disclaimer in the
     15      1.1    bjh21  *    documentation and/or other materials provided with the distribution.
     16      1.1    bjh21  * 3. All advertising materials mentioning features or use of this software
     17      1.1    bjh21  *    must display the following acknowledgement:
     18  1.8.2.1  nathanw  *	This product includes software developed by Mark Brinicombe
     19  1.8.2.1  nathanw  *	for the NetBSD Project.
     20      1.1    bjh21  * 4. The name of the company nor the name of the author may be used to
     21      1.1    bjh21  *    endorse or promote products derived from this software without specific
     22      1.1    bjh21  *    prior written permission.
     23      1.1    bjh21  *
     24      1.1    bjh21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     25      1.1    bjh21  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     26      1.1    bjh21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27      1.1    bjh21  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     28      1.1    bjh21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     29      1.1    bjh21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     30      1.1    bjh21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31      1.1    bjh21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32      1.1    bjh21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33      1.1    bjh21  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34      1.1    bjh21  * SUCH DAMAGE.
     35      1.1    bjh21  */
     36      1.1    bjh21 /*
     37      1.2    bjh21  * seeq8005.c - SEEQ 8005 device driver
     38      1.2    bjh21  */
     39      1.2    bjh21 /*
     40  1.8.2.3  nathanw  * This driver currently supports the following chips:
     41      1.2    bjh21  * SEEQ 8005 Advanced Ethernet Data Link Controller
     42  1.8.2.1  nathanw  * SEEQ 80C04 Ethernet Data Link Controller
     43  1.8.2.1  nathanw  * SEEQ 80C04A AutoDUPLEX CMOS Ethernet Data Link Controller
     44  1.8.2.1  nathanw  */
     45  1.8.2.1  nathanw /*
     46  1.8.2.1  nathanw  * More information on the 8004 and 8005 AEDLC controllers can be found in
     47  1.8.2.1  nathanw  * the SEEQ Technology Inc 1992 Data Comm Devices data book.
     48  1.8.2.1  nathanw  *
     49  1.8.2.1  nathanw  * This data book may no longer be available as these are rather old chips
     50  1.8.2.1  nathanw  * (1991 - 1993)
     51      1.2    bjh21  */
     52      1.2    bjh21 /*
     53      1.2    bjh21  * This driver is based on the arm32 ea(4) driver, hence the names of many
     54      1.2    bjh21  * of the functions.
     55      1.1    bjh21  */
     56      1.1    bjh21 /*
     57      1.1    bjh21  * Bugs/possible improvements:
     58      1.1    bjh21  *	- Does not currently support DMA
     59      1.1    bjh21  *	- Does not transmit multiple packets in one go
     60      1.1    bjh21  *	- Does not support 8-bit busses
     61      1.1    bjh21  */
     62      1.1    bjh21 
     63      1.1    bjh21 #include <sys/types.h>
     64      1.1    bjh21 #include <sys/param.h>
     65      1.1    bjh21 
     66  1.8.2.3  nathanw __RCSID("$NetBSD: seeq8005.c,v 1.8.2.3 2001/08/24 00:09:36 nathanw Exp $");
     67      1.1    bjh21 
     68      1.1    bjh21 #include <sys/systm.h>
     69      1.1    bjh21 #include <sys/endian.h>
     70      1.1    bjh21 #include <sys/errno.h>
     71      1.1    bjh21 #include <sys/ioctl.h>
     72      1.1    bjh21 #include <sys/mbuf.h>
     73      1.1    bjh21 #include <sys/socket.h>
     74      1.1    bjh21 #include <sys/syslog.h>
     75      1.1    bjh21 #include <sys/device.h>
     76      1.1    bjh21 
     77      1.1    bjh21 #include <net/if.h>
     78      1.1    bjh21 #include <net/if_dl.h>
     79      1.1    bjh21 #include <net/if_types.h>
     80      1.1    bjh21 #include <net/if_ether.h>
     81  1.8.2.1  nathanw #include <net/if_media.h>
     82      1.1    bjh21 
     83      1.1    bjh21 #include "bpfilter.h"
     84      1.1    bjh21 #if NBPFILTER > 0
     85      1.1    bjh21 #include <net/bpf.h>
     86      1.1    bjh21 #include <net/bpfdesc.h>
     87      1.1    bjh21 #endif
     88      1.1    bjh21 
     89      1.1    bjh21 #include <machine/bus.h>
     90      1.1    bjh21 #include <machine/intr.h>
     91      1.1    bjh21 
     92      1.1    bjh21 #include <dev/ic/seeq8005reg.h>
     93      1.1    bjh21 #include <dev/ic/seeq8005var.h>
     94      1.1    bjh21 
     95  1.8.2.1  nathanw /*#define SEEQ_DEBUG*/
     96      1.1    bjh21 
     97      1.1    bjh21 /* for debugging convenience */
     98  1.8.2.1  nathanw #ifdef SEEQ8005_DEBUG
     99  1.8.2.1  nathanw #define SEEQ_DEBUG_MISC		1
    100  1.8.2.1  nathanw #define SEEQ_DEBUG_TX		2
    101  1.8.2.1  nathanw #define SEEQ_DEBUG_RX		4
    102  1.8.2.1  nathanw #define SEEQ_DEBUG_PKT		8
    103  1.8.2.1  nathanw #define SEEQ_DEBUG_TXINT	16
    104  1.8.2.1  nathanw #define SEEQ_DEBUG_RXINT	32
    105  1.8.2.1  nathanw int seeq8005_debug = 0;
    106  1.8.2.1  nathanw #define DPRINTF(f, x) { if (seeq8005_debug & (f)) printf x; }
    107      1.1    bjh21 #else
    108  1.8.2.1  nathanw #define DPRINTF(f, x)
    109      1.1    bjh21 #endif
    110      1.1    bjh21 
    111  1.8.2.3  nathanw #define	SEEQ_TX_BUFFER_SIZE		0x800		/* (> ETHER_MAX_LEN) */
    112  1.8.2.3  nathanw 
    113  1.8.2.3  nathanw #define SEEQ_READ16(sc, iot, ioh, reg)					\
    114  1.8.2.3  nathanw 	((sc)->sc_flags & SF_8BIT ?					\
    115  1.8.2.3  nathanw 	    (bus_space_read_1((iot), (ioh), (reg)) |			\
    116  1.8.2.3  nathanw 	     (bus_space_read_1((iot), (ioh), (reg) + 1) << 8)) :	\
    117  1.8.2.3  nathanw 	    (bus_space_read_2((iot), (ioh), (reg))))
    118  1.8.2.3  nathanw 
    119  1.8.2.3  nathanw #define SEEQ_WRITE16(sc, iot, ioh, reg, val) do {			\
    120  1.8.2.3  nathanw 	if ((sc)->sc_flags & SF_8BIT) {					\
    121  1.8.2.3  nathanw 		bus_space_write_1((iot), (ioh), (reg), (val) & 0xff);	\
    122  1.8.2.3  nathanw 		bus_space_write_1((iot), (ioh), (reg) + 1, (val) >> 8);	\
    123  1.8.2.3  nathanw 	} else								\
    124  1.8.2.3  nathanw 		bus_space_write_2((iot), (ioh), (reg), (val));		\
    125  1.8.2.3  nathanw } while (/*CONSTCOND*/0)
    126  1.8.2.1  nathanw 
    127      1.1    bjh21 /*
    128      1.1    bjh21  * prototypes
    129      1.1    bjh21  */
    130      1.1    bjh21 
    131      1.5    bjh21 static int ea_init(struct ifnet *);
    132      1.1    bjh21 static int ea_ioctl(struct ifnet *, u_long, caddr_t);
    133      1.1    bjh21 static void ea_start(struct ifnet *);
    134      1.1    bjh21 static void ea_watchdog(struct ifnet *);
    135      1.1    bjh21 static void ea_chipreset(struct seeq8005_softc *);
    136      1.1    bjh21 static void ea_ramtest(struct seeq8005_softc *);
    137      1.1    bjh21 static int ea_stoptx(struct seeq8005_softc *);
    138      1.1    bjh21 static int ea_stoprx(struct seeq8005_softc *);
    139      1.5    bjh21 static void ea_stop(struct ifnet *, int);
    140      1.1    bjh21 static void ea_await_fifo_empty(struct seeq8005_softc *);
    141      1.1    bjh21 static void ea_await_fifo_full(struct seeq8005_softc *);
    142  1.8.2.1  nathanw static void ea_writebuf(struct seeq8005_softc *, u_char *, int, size_t);
    143  1.8.2.1  nathanw static void ea_readbuf(struct seeq8005_softc *, u_char *, int, size_t);
    144      1.3    bjh21 static void ea_select_buffer(struct seeq8005_softc *, int);
    145      1.5    bjh21 static void ea_set_address(struct seeq8005_softc *, int, const u_int8_t *);
    146  1.8.2.1  nathanw static void ea_read(struct seeq8005_softc *, int, int);
    147  1.8.2.1  nathanw static struct mbuf *ea_get(struct seeq8005_softc *, int, int, struct ifnet *);
    148  1.8.2.1  nathanw static void ea_txint(struct seeq8005_softc *);
    149  1.8.2.1  nathanw static void ea_rxint(struct seeq8005_softc *);
    150      1.1    bjh21 static void eatxpacket(struct seeq8005_softc *);
    151  1.8.2.1  nathanw static int ea_writembuf(struct seeq8005_softc *, struct mbuf *, int);
    152      1.5    bjh21 static void ea_mc_reset(struct seeq8005_softc *);
    153  1.8.2.1  nathanw static void ea_mc_reset_8004(struct seeq8005_softc *);
    154  1.8.2.1  nathanw static void ea_mc_reset_8005(struct seeq8005_softc *);
    155  1.8.2.1  nathanw static int ea_mediachange(struct ifnet *);
    156  1.8.2.1  nathanw static void ea_mediastatus(struct ifnet *, struct ifmediareq *);
    157      1.1    bjh21 
    158      1.1    bjh21 
    159      1.1    bjh21 /*
    160      1.1    bjh21  * Attach chip.
    161      1.1    bjh21  */
    162      1.1    bjh21 
    163      1.1    bjh21 void
    164  1.8.2.1  nathanw seeq8005_attach(struct seeq8005_softc *sc, const u_int8_t *myaddr, int *media,
    165  1.8.2.1  nathanw     int nmedia, int defmedia)
    166      1.1    bjh21 {
    167      1.1    bjh21 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    168  1.8.2.3  nathanw 	bus_space_tag_t iot = sc->sc_iot;
    169  1.8.2.3  nathanw 	bus_space_handle_t ioh = sc->sc_ioh;
    170      1.2    bjh21 	u_int id;
    171      1.2    bjh21 
    172  1.8.2.1  nathanw 	KASSERT(myaddr != NULL);
    173      1.2    bjh21 	printf(" address %s", ether_sprintf(myaddr));
    174      1.2    bjh21 
    175      1.3    bjh21 	/* Stop the board. */
    176      1.3    bjh21 
    177      1.3    bjh21 	ea_chipreset(sc);
    178      1.3    bjh21 
    179  1.8.2.3  nathanw 	/* Work out data bus width. */
    180  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_RX_PTR, 0x1234);
    181  1.8.2.3  nathanw 	if (SEEQ_READ16(sc, iot, ioh, SEEQ_RX_PTR) != 0x1234) {
    182  1.8.2.3  nathanw 		/* Try 8-bit mode */
    183  1.8.2.3  nathanw 		sc->sc_flags |= SF_8BIT;
    184  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_RX_PTR, 0x1234);
    185  1.8.2.3  nathanw 		if (SEEQ_READ16(sc, iot, ioh, SEEQ_RX_PTR) != 0x1234) {
    186  1.8.2.3  nathanw 			printf("\n%s: Cannot determine data bus width\n",
    187  1.8.2.3  nathanw 			    sc->sc_dev.dv_xname);
    188  1.8.2.3  nathanw 			return;
    189  1.8.2.3  nathanw 		}
    190  1.8.2.3  nathanw 	}
    191  1.8.2.3  nathanw 
    192  1.8.2.3  nathanw 	printf(", %d-bit", sc->sc_flags & SF_8BIT ? 8 : 16);
    193  1.8.2.3  nathanw 
    194      1.2    bjh21 	/* Get the product ID */
    195      1.1    bjh21 
    196  1.8.2.1  nathanw 	ea_select_buffer(sc, SEEQ_BUFCODE_PRODUCTID);
    197  1.8.2.3  nathanw 	id = SEEQ_READ16(sc, sc->sc_iot, sc->sc_ioh, SEEQ_BUFWIN);
    198      1.2    bjh21 
    199  1.8.2.1  nathanw 	switch (id & SEEQ_PRODUCTID_MASK) {
    200  1.8.2.1  nathanw 	case SEEQ_PRODUCTID_8004:
    201  1.8.2.1  nathanw 		sc->sc_variant = SEEQ_8004;
    202  1.8.2.1  nathanw 		switch (id & SEEQ_PRODUCTID_REV_MASK) {
    203  1.8.2.1  nathanw 		case SEEQ_PRODUCTID_REV_80C04:
    204  1.8.2.1  nathanw 			printf(", SEEQ 80C04\n");
    205  1.8.2.1  nathanw 			break;
    206  1.8.2.1  nathanw 		case SEEQ_PRODUCTID_REV_80C04A:
    207  1.8.2.1  nathanw 			printf(", SEEQ 80C04A\n");
    208  1.8.2.1  nathanw 			break;
    209  1.8.2.1  nathanw 		default:
    210  1.8.2.1  nathanw 			/* Unknown SEEQ 8004 variants */
    211  1.8.2.1  nathanw 			printf(", SEEQ 8004 rev %x\n",
    212  1.8.2.1  nathanw 			    id & SEEQ_PRODUCTID_REV_MASK);
    213  1.8.2.1  nathanw 			break;
    214  1.8.2.1  nathanw 		}
    215  1.8.2.1  nathanw 		break;
    216  1.8.2.1  nathanw 	default:	/* XXX */
    217  1.8.2.1  nathanw 		sc->sc_variant = SEEQ_8005;
    218  1.8.2.1  nathanw 		printf(", SEEQ 8005\n");
    219  1.8.2.1  nathanw 		break;
    220  1.8.2.1  nathanw 	}
    221  1.8.2.1  nathanw 
    222  1.8.2.1  nathanw 	/* Both the 8004 and 8005 are designed for 64K Buffer memory */
    223  1.8.2.1  nathanw 	sc->sc_buffersize = SEEQ_MAX_BUFFER_SIZE;
    224  1.8.2.1  nathanw 
    225  1.8.2.1  nathanw 	/*
    226  1.8.2.1  nathanw 	 * Set up tx and rx buffers.
    227  1.8.2.1  nathanw 	 *
    228  1.8.2.1  nathanw 	 * We use approximately a quarter of the packet memory for TX
    229  1.8.2.1  nathanw 	 * buffers and the rest for RX buffers
    230  1.8.2.1  nathanw 	 */
    231  1.8.2.1  nathanw 	/* sc->sc_tx_bufs = sc->sc_buffersize / SEEQ_TX_BUFFER_SIZE / 4; */
    232  1.8.2.1  nathanw 	sc->sc_tx_bufs = 1;
    233  1.8.2.1  nathanw 	sc->sc_tx_bufsize = sc->sc_tx_bufs * SEEQ_TX_BUFFER_SIZE;
    234  1.8.2.1  nathanw 	sc->sc_rx_bufsize = sc->sc_buffersize - sc->sc_tx_bufsize;
    235  1.8.2.1  nathanw 	sc->sc_enabled = 0;
    236  1.8.2.1  nathanw 
    237  1.8.2.1  nathanw 	/* Test the RAM */
    238  1.8.2.1  nathanw 	ea_ramtest(sc);
    239  1.8.2.1  nathanw 
    240  1.8.2.1  nathanw 	printf("%s: %dKB packet memory, txbuf=%dKB (%d buffers), rxbuf=%dKB",
    241  1.8.2.1  nathanw 	    sc->sc_dev.dv_xname, sc->sc_buffersize >> 10,
    242  1.8.2.1  nathanw 	    sc->sc_tx_bufsize >> 10, sc->sc_tx_bufs, sc->sc_rx_bufsize >> 10);
    243      1.1    bjh21 
    244      1.1    bjh21 	/* Initialise ifnet structure. */
    245      1.1    bjh21 
    246  1.8.2.3  nathanw 	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
    247      1.1    bjh21 	ifp->if_softc = sc;
    248      1.1    bjh21 	ifp->if_start = ea_start;
    249      1.1    bjh21 	ifp->if_ioctl = ea_ioctl;
    250      1.5    bjh21 	ifp->if_init = ea_init;
    251      1.5    bjh21 	ifp->if_stop = ea_stop;
    252      1.1    bjh21 	ifp->if_watchdog = ea_watchdog;
    253      1.5    bjh21 	ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_NOTRAILERS;
    254  1.8.2.1  nathanw 	if (sc->sc_variant == SEEQ_8004)
    255  1.8.2.1  nathanw 		ifp->if_flags |= IFF_SIMPLEX;
    256      1.7  thorpej 	IFQ_SET_READY(&ifp->if_snd);
    257      1.1    bjh21 
    258  1.8.2.1  nathanw 	/* Initialize media goo. */
    259  1.8.2.1  nathanw 	ifmedia_init(&sc->sc_media, 0, ea_mediachange, ea_mediastatus);
    260  1.8.2.1  nathanw 	if (media != NULL) {
    261  1.8.2.1  nathanw 		int i;
    262  1.8.2.1  nathanw 
    263  1.8.2.1  nathanw 		for (i = 0; i < nmedia; i++)
    264  1.8.2.1  nathanw 			ifmedia_add(&sc->sc_media, media[i], 0, NULL);
    265  1.8.2.1  nathanw 		ifmedia_set(&sc->sc_media, defmedia);
    266  1.8.2.1  nathanw 	} else {
    267  1.8.2.1  nathanw 		ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
    268  1.8.2.1  nathanw 		ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
    269  1.8.2.1  nathanw 	}
    270  1.8.2.1  nathanw 
    271  1.8.2.3  nathanw 	/* We can support 802.1Q VLAN-sized frames. */
    272  1.8.2.3  nathanw 	sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
    273  1.8.2.3  nathanw 
    274      1.1    bjh21 	/* Now we can attach the interface. */
    275      1.1    bjh21 
    276      1.1    bjh21 	if_attach(ifp);
    277      1.1    bjh21 	ether_ifattach(ifp, myaddr);
    278      1.1    bjh21 
    279      1.8    bjh21 	printf("\n");
    280      1.1    bjh21 }
    281      1.1    bjh21 
    282  1.8.2.1  nathanw /*
    283  1.8.2.1  nathanw  * Media change callback.
    284  1.8.2.1  nathanw  */
    285  1.8.2.1  nathanw static int
    286  1.8.2.1  nathanw ea_mediachange(struct ifnet *ifp)
    287  1.8.2.1  nathanw {
    288  1.8.2.1  nathanw 	struct seeq8005_softc *sc = ifp->if_softc;
    289  1.8.2.1  nathanw 
    290  1.8.2.1  nathanw 	if (sc->sc_mediachange)
    291  1.8.2.1  nathanw 		return ((*sc->sc_mediachange)(sc));
    292  1.8.2.1  nathanw 	return (EINVAL);
    293  1.8.2.1  nathanw }
    294  1.8.2.1  nathanw 
    295  1.8.2.1  nathanw /*
    296  1.8.2.1  nathanw  * Media status callback.
    297  1.8.2.1  nathanw  */
    298  1.8.2.1  nathanw static void
    299  1.8.2.1  nathanw ea_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
    300  1.8.2.1  nathanw {
    301  1.8.2.1  nathanw 	struct seeq8005_softc *sc = ifp->if_softc;
    302  1.8.2.1  nathanw 
    303  1.8.2.1  nathanw 	if (sc->sc_enabled == 0) {
    304  1.8.2.1  nathanw 		ifmr->ifm_active = IFM_ETHER | IFM_NONE;
    305  1.8.2.1  nathanw 		ifmr->ifm_status = 0;
    306  1.8.2.1  nathanw 		return;
    307  1.8.2.1  nathanw 	}
    308  1.8.2.1  nathanw 
    309  1.8.2.1  nathanw 	if (sc->sc_mediastatus)
    310  1.8.2.1  nathanw 		(*sc->sc_mediastatus)(sc, ifmr);
    311  1.8.2.1  nathanw }
    312      1.1    bjh21 
    313      1.1    bjh21 /*
    314      1.1    bjh21  * Test the RAM on the ethernet card.
    315      1.1    bjh21  */
    316      1.1    bjh21 
    317      1.1    bjh21 void
    318      1.1    bjh21 ea_ramtest(struct seeq8005_softc *sc)
    319      1.1    bjh21 {
    320      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    321      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    322      1.1    bjh21 	int loop;
    323      1.1    bjh21 	u_int sum = 0;
    324      1.1    bjh21 
    325      1.1    bjh21 	/*
    326      1.1    bjh21 	 * Test the buffer memory on the board.
    327      1.1    bjh21 	 * Write simple pattens to it and read them back.
    328      1.1    bjh21 	 */
    329      1.1    bjh21 
    330      1.1    bjh21 	/* Set up the whole buffer RAM for writing */
    331      1.1    bjh21 
    332  1.8.2.1  nathanw 	ea_select_buffer(sc, SEEQ_BUFCODE_TX_EAP);
    333  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_BUFWIN, (SEEQ_MAX_BUFFER_SIZE >> 8) - 1);
    334  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_TX_PTR, 0x0000);
    335  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_RX_PTR, SEEQ_MAX_BUFFER_SIZE - 2);
    336      1.1    bjh21 
    337  1.8.2.1  nathanw #define SEEQ_RAMTEST_LOOP(value)						\
    338      1.3    bjh21 do {									\
    339      1.3    bjh21 	/* Set the write start address and write a pattern */		\
    340      1.3    bjh21 	ea_writebuf(sc, NULL, 0x0000, 0);				\
    341  1.8.2.1  nathanw 	for (loop = 0; loop < SEEQ_MAX_BUFFER_SIZE; loop += 2)		\
    342  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_BUFWIN, (value));	\
    343      1.3    bjh21 									\
    344      1.3    bjh21 	/* Set the read start address and verify the pattern */		\
    345      1.3    bjh21 	ea_readbuf(sc, NULL, 0x0000, 0);				\
    346  1.8.2.1  nathanw 	for (loop = 0; loop < SEEQ_MAX_BUFFER_SIZE; loop += 2)		\
    347  1.8.2.3  nathanw 		if (SEEQ_READ16(sc, iot, ioh, SEEQ_BUFWIN) != (value)) \
    348      1.3    bjh21 			++sum;						\
    349      1.3    bjh21 } while (/*CONSTCOND*/0)
    350      1.3    bjh21 
    351  1.8.2.1  nathanw 	SEEQ_RAMTEST_LOOP(loop);
    352  1.8.2.1  nathanw 	SEEQ_RAMTEST_LOOP(loop ^ (SEEQ_MAX_BUFFER_SIZE - 1));
    353  1.8.2.1  nathanw 	SEEQ_RAMTEST_LOOP(0xaa55);
    354  1.8.2.1  nathanw 	SEEQ_RAMTEST_LOOP(0x55aa);
    355      1.1    bjh21 
    356      1.1    bjh21 	/* Report */
    357      1.1    bjh21 
    358      1.2    bjh21 	if (sum > 0)
    359      1.2    bjh21 		printf("%s: buffer RAM failed self test, %d faults\n",
    360      1.2    bjh21 		       sc->sc_dev.dv_xname, sum);
    361      1.1    bjh21 }
    362      1.1    bjh21 
    363      1.1    bjh21 
    364      1.1    bjh21 /*
    365      1.1    bjh21  * Stop the tx interface.
    366      1.1    bjh21  *
    367      1.1    bjh21  * Returns 0 if the tx was already stopped or 1 if it was active
    368      1.1    bjh21  */
    369      1.1    bjh21 
    370      1.1    bjh21 static int
    371      1.1    bjh21 ea_stoptx(struct seeq8005_softc *sc)
    372      1.1    bjh21 {
    373      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    374      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    375      1.1    bjh21 	int timeout;
    376      1.1    bjh21 	int status;
    377      1.1    bjh21 
    378  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_TX, ("ea_stoptx()\n"));
    379  1.8.2.1  nathanw 
    380  1.8.2.1  nathanw 	sc->sc_enabled = 0;
    381      1.1    bjh21 
    382  1.8.2.3  nathanw 	status = SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS);
    383  1.8.2.1  nathanw 	if (!(status & SEEQ_STATUS_TX_ON))
    384      1.1    bjh21 		return 0;
    385      1.1    bjh21 
    386      1.1    bjh21 	/* Stop any tx and wait for confirmation */
    387  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    388  1.8.2.1  nathanw 			  sc->sc_command | SEEQ_CMD_TX_OFF);
    389      1.1    bjh21 
    390      1.1    bjh21 	timeout = 20000;
    391      1.1    bjh21 	do {
    392  1.8.2.3  nathanw 		status = SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS);
    393  1.8.2.1  nathanw 		delay(1);
    394  1.8.2.1  nathanw 	} while ((status & SEEQ_STATUS_TX_ON) && --timeout > 0);
    395  1.8.2.1  nathanw  	if (timeout == 0)
    396  1.8.2.1  nathanw 		log(LOG_ERR, "%s: timeout waiting for tx termination\n",
    397  1.8.2.1  nathanw 		    sc->sc_dev.dv_xname);
    398      1.1    bjh21 
    399      1.1    bjh21 	/* Clear any pending tx interrupt */
    400  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    401  1.8.2.1  nathanw 		   sc->sc_command | SEEQ_CMD_TX_INTACK);
    402      1.1    bjh21 	return 1;
    403      1.1    bjh21 }
    404      1.1    bjh21 
    405      1.1    bjh21 
    406      1.1    bjh21 /*
    407      1.1    bjh21  * Stop the rx interface.
    408      1.1    bjh21  *
    409      1.1    bjh21  * Returns 0 if the tx was already stopped or 1 if it was active
    410      1.1    bjh21  */
    411      1.1    bjh21 
    412      1.1    bjh21 static int
    413      1.1    bjh21 ea_stoprx(struct seeq8005_softc *sc)
    414      1.1    bjh21 {
    415      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    416      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    417      1.1    bjh21 	int timeout;
    418      1.1    bjh21 	int status;
    419      1.1    bjh21 
    420  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_RX, ("ea_stoprx()\n"));
    421      1.1    bjh21 
    422  1.8.2.3  nathanw 	status = SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS);
    423  1.8.2.1  nathanw 	if (!(status & SEEQ_STATUS_RX_ON))
    424      1.1    bjh21 		return 0;
    425      1.1    bjh21 
    426      1.1    bjh21 	/* Stop any rx and wait for confirmation */
    427      1.1    bjh21 
    428  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    429  1.8.2.1  nathanw 			  sc->sc_command | SEEQ_CMD_RX_OFF);
    430      1.1    bjh21 
    431      1.1    bjh21 	timeout = 20000;
    432      1.1    bjh21 	do {
    433  1.8.2.3  nathanw 		status = SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS);
    434  1.8.2.1  nathanw 	} while ((status & SEEQ_STATUS_RX_ON) && --timeout > 0);
    435      1.1    bjh21 	if (timeout == 0)
    436  1.8.2.1  nathanw 		log(LOG_ERR, "%s: timeout waiting for rx termination\n",
    437  1.8.2.1  nathanw 		    sc->sc_dev.dv_xname);
    438      1.1    bjh21 
    439      1.1    bjh21 	/* Clear any pending rx interrupt */
    440      1.1    bjh21 
    441  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    442  1.8.2.1  nathanw 		   sc->sc_command | SEEQ_CMD_RX_INTACK);
    443      1.1    bjh21 	return 1;
    444      1.1    bjh21 }
    445      1.1    bjh21 
    446      1.1    bjh21 
    447      1.1    bjh21 /*
    448      1.1    bjh21  * Stop interface.
    449      1.1    bjh21  * Stop all IO and shut the interface down
    450      1.1    bjh21  */
    451      1.1    bjh21 
    452      1.1    bjh21 static void
    453      1.5    bjh21 ea_stop(struct ifnet *ifp, int disable)
    454      1.1    bjh21 {
    455      1.5    bjh21 	struct seeq8005_softc *sc = ifp->if_softc;
    456      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    457      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    458      1.1    bjh21 
    459  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_MISC, ("ea_stop()\n"));
    460      1.1    bjh21 
    461      1.1    bjh21 	/* Stop all IO */
    462      1.1    bjh21 	ea_stoptx(sc);
    463      1.1    bjh21 	ea_stoprx(sc);
    464      1.1    bjh21 
    465      1.1    bjh21 	/* Disable rx and tx interrupts */
    466  1.8.2.1  nathanw 	sc->sc_command &= (SEEQ_CMD_RX_INTEN | SEEQ_CMD_TX_INTEN);
    467      1.1    bjh21 
    468      1.1    bjh21 	/* Clear any pending interrupts */
    469  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    470  1.8.2.1  nathanw 			  sc->sc_command | SEEQ_CMD_RX_INTACK |
    471  1.8.2.1  nathanw 			  SEEQ_CMD_TX_INTACK | SEEQ_CMD_DMA_INTACK |
    472  1.8.2.1  nathanw 			  SEEQ_CMD_BW_INTACK);
    473  1.8.2.1  nathanw 
    474  1.8.2.1  nathanw 	if (sc->sc_variant == SEEQ_8004) {
    475  1.8.2.1  nathanw 		/* Put the chip to sleep */
    476  1.8.2.1  nathanw 		ea_select_buffer(sc, SEEQ_BUFCODE_CONFIG3);
    477  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_BUFWIN,
    478  1.8.2.1  nathanw 		    sc->sc_config3 | SEEQ_CFG3_SLEEP);
    479  1.8.2.1  nathanw 	}
    480      1.1    bjh21 
    481      1.1    bjh21 	/* Cancel any watchdog timer */
    482      1.1    bjh21        	sc->sc_ethercom.ec_if.if_timer = 0;
    483      1.1    bjh21 }
    484      1.1    bjh21 
    485      1.1    bjh21 
    486      1.1    bjh21 /*
    487      1.1    bjh21  * Reset the chip
    488      1.1    bjh21  * Following this the software registers are reset
    489      1.1    bjh21  */
    490      1.1    bjh21 
    491      1.1    bjh21 static void
    492      1.1    bjh21 ea_chipreset(struct seeq8005_softc *sc)
    493      1.1    bjh21 {
    494      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    495      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    496      1.1    bjh21 
    497  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_MISC, ("ea_chipreset()\n"));
    498      1.1    bjh21 
    499      1.1    bjh21 	/* Reset the controller. Min of 4us delay here */
    500      1.1    bjh21 
    501  1.8.2.3  nathanw 	/*
    502  1.8.2.3  nathanw 	 * This can be called before we know whether the chip is in 8- or
    503  1.8.2.3  nathanw 	 * 16-bit mode, so we do a reset in both modes.  The 16-bit reset is
    504  1.8.2.3  nathanw 	 * harmless in 8-bit mode, so we do that second.
    505  1.8.2.3  nathanw 	 */
    506  1.8.2.3  nathanw 
    507  1.8.2.3  nathanw 	/* In 16-bit mode, this will munge the PreamSelect bit. */
    508  1.8.2.3  nathanw 	bus_space_write_1(iot, ioh, SEEQ_CONFIG2 + 1, SEEQ_CFG2_RESET >> 8);
    509  1.8.2.3  nathanw 	delay(4);
    510  1.8.2.3  nathanw 	/* In 8-bit mode, this will zero the bottom half of config reg 2. */
    511  1.8.2.1  nathanw 	bus_space_write_2(iot, ioh, SEEQ_CONFIG2, SEEQ_CFG2_RESET);
    512      1.3    bjh21 	delay(4);
    513      1.1    bjh21 
    514      1.1    bjh21 	sc->sc_command = 0;
    515      1.1    bjh21 	sc->sc_config1 = 0;
    516      1.1    bjh21 	sc->sc_config2 = 0;
    517  1.8.2.1  nathanw 	sc->sc_config3 = 0;
    518      1.1    bjh21 }
    519      1.1    bjh21 
    520      1.1    bjh21 
    521      1.1    bjh21 /*
    522      1.1    bjh21  * If the DMA FIFO's in write mode, wait for it to empty.  Needed when
    523      1.1    bjh21  * switching the FIFO from write to read.  We also use it when changing
    524      1.1    bjh21  * the address for writes.
    525      1.1    bjh21  */
    526      1.1    bjh21 static void
    527      1.1    bjh21 ea_await_fifo_empty(struct seeq8005_softc *sc)
    528      1.1    bjh21 {
    529      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    530      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    531      1.1    bjh21 	int timeout;
    532      1.1    bjh21 
    533      1.1    bjh21 	timeout = 20000;
    534  1.8.2.3  nathanw 	if ((SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS) &
    535  1.8.2.1  nathanw 	     SEEQ_STATUS_FIFO_DIR) != 0)
    536      1.1    bjh21 		return; /* FIFO is reading anyway. */
    537  1.8.2.1  nathanw 	while (--timeout > 0)
    538  1.8.2.3  nathanw 		if (SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS) &
    539  1.8.2.1  nathanw 		    SEEQ_STATUS_FIFO_EMPTY)
    540  1.8.2.1  nathanw 			return;
    541  1.8.2.1  nathanw 	log(LOG_ERR, "%s: DMA FIFO failed to empty\n", sc->sc_dev.dv_xname);
    542      1.1    bjh21 }
    543      1.1    bjh21 
    544      1.1    bjh21 /*
    545      1.1    bjh21  * Wait for the DMA FIFO to fill before reading from it.
    546      1.1    bjh21  */
    547      1.1    bjh21 static void
    548      1.1    bjh21 ea_await_fifo_full(struct seeq8005_softc *sc)
    549      1.1    bjh21 {
    550      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    551      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    552      1.1    bjh21 	int timeout;
    553      1.1    bjh21 
    554      1.1    bjh21 	timeout = 20000;
    555  1.8.2.1  nathanw 	while (--timeout > 0)
    556  1.8.2.3  nathanw 		if (SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS) &
    557  1.8.2.1  nathanw 		    SEEQ_STATUS_FIFO_FULL)
    558  1.8.2.1  nathanw 			return;
    559  1.8.2.1  nathanw 	log(LOG_ERR, "%s: DMA FIFO failed to fill\n", sc->sc_dev.dv_xname);
    560      1.1    bjh21 }
    561      1.1    bjh21 
    562      1.1    bjh21 /*
    563      1.1    bjh21  * write to the buffer memory on the interface
    564      1.1    bjh21  *
    565      1.1    bjh21  * The buffer address is set to ADDR.
    566      1.1    bjh21  * If len != 0 then data is copied from the address starting at buf
    567      1.1    bjh21  * to the interface buffer.
    568      1.1    bjh21  * BUF must be usable as a u_int16_t *.
    569      1.1    bjh21  * If LEN is odd, it must be safe to overwrite one extra byte.
    570      1.1    bjh21  */
    571      1.1    bjh21 
    572      1.1    bjh21 static void
    573  1.8.2.1  nathanw ea_writebuf(struct seeq8005_softc *sc, u_char *buf, int addr, size_t len)
    574      1.1    bjh21 {
    575      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    576      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    577      1.1    bjh21 
    578  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_MISC, ("writebuf: st=%04x\n",
    579  1.8.2.3  nathanw 	    SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS)));
    580      1.1    bjh21 
    581      1.1    bjh21 #ifdef DIAGNOSTIC
    582      1.1    bjh21 	if (__predict_false(!ALIGNED_POINTER(buf, u_int16_t)))
    583      1.1    bjh21 		panic("%s: unaligned writebuf", sc->sc_dev.dv_xname);
    584  1.8.2.1  nathanw 	if (__predict_false(addr >= SEEQ_MAX_BUFFER_SIZE))
    585      1.1    bjh21 		panic("%s: writebuf out of range", sc->sc_dev.dv_xname);
    586  1.8.2.1  nathanw #endif
    587      1.1    bjh21 
    588      1.1    bjh21 	/* Assume that copying too much is safe. */
    589      1.1    bjh21 	if (len % 2 != 0)
    590      1.1    bjh21 		len++;
    591      1.1    bjh21 
    592  1.8.2.1  nathanw 	if (addr != -1) {
    593  1.8.2.1  nathanw 		ea_await_fifo_empty(sc);
    594      1.1    bjh21 
    595  1.8.2.1  nathanw 		ea_select_buffer(sc, SEEQ_BUFCODE_LOCAL_MEM);
    596  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    597  1.8.2.1  nathanw 		    sc->sc_command | SEEQ_CMD_FIFO_WRITE);
    598  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_DMA_ADDR, addr);
    599  1.8.2.1  nathanw 	}
    600      1.1    bjh21 
    601  1.8.2.3  nathanw 	if (len > 0) {
    602  1.8.2.3  nathanw 		if (sc->sc_flags & SF_8BIT)
    603  1.8.2.3  nathanw 			bus_space_write_multi_1(iot, ioh, SEEQ_BUFWIN,
    604  1.8.2.3  nathanw 			    (u_int8_t *)buf, len);
    605  1.8.2.3  nathanw 		else
    606  1.8.2.3  nathanw 			bus_space_write_multi_2(iot, ioh, SEEQ_BUFWIN,
    607  1.8.2.3  nathanw 			    (u_int16_t *)buf, len / 2);
    608  1.8.2.3  nathanw 	}
    609      1.1    bjh21 	/* Leave FIFO to empty in the background */
    610      1.1    bjh21 }
    611      1.1    bjh21 
    612      1.1    bjh21 
    613      1.1    bjh21 /*
    614      1.1    bjh21  * read from the buffer memory on the interface
    615      1.1    bjh21  *
    616      1.1    bjh21  * The buffer address is set to ADDR.
    617      1.1    bjh21  * If len != 0 then data is copied from the interface buffer to the
    618      1.1    bjh21  * address starting at buf.
    619      1.1    bjh21  * BUF must be usable as a u_int16_t *.
    620      1.1    bjh21  * If LEN is odd, it must be safe to overwrite one extra byte.
    621      1.1    bjh21  */
    622      1.1    bjh21 
    623      1.1    bjh21 static void
    624  1.8.2.1  nathanw ea_readbuf(struct seeq8005_softc *sc, u_char *buf, int addr, size_t len)
    625      1.1    bjh21 {
    626      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    627      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    628  1.8.2.1  nathanw 	int runup;
    629      1.1    bjh21 
    630  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_MISC, ("readbuf: st=%04x addr=%04x len=%d\n",
    631  1.8.2.3  nathanw 	    SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS), addr, len));
    632      1.1    bjh21 
    633      1.1    bjh21 #ifdef DIAGNOSTIC
    634  1.8.2.1  nathanw 	if (__predict_false(!ALIGNED_POINTER(buf, u_int16_t)))
    635      1.1    bjh21 		panic("%s: unaligned readbuf", sc->sc_dev.dv_xname);
    636  1.8.2.1  nathanw 	if (__predict_false(addr >= SEEQ_MAX_BUFFER_SIZE))
    637  1.8.2.1  nathanw 		panic("%s: readbuf out of range", sc->sc_dev.dv_xname);
    638      1.1    bjh21 #endif
    639      1.1    bjh21 
    640      1.1    bjh21 	/* Assume that copying too much is safe. */
    641      1.1    bjh21 	if (len % 2 != 0)
    642      1.1    bjh21 		len++;
    643      1.1    bjh21 
    644  1.8.2.1  nathanw 	if (addr != -1) {
    645  1.8.2.1  nathanw 		/*
    646  1.8.2.1  nathanw 		 * SEEQ 80C04 bug:
    647  1.8.2.1  nathanw 		 * Starting reading from certain addresses seems to cause
    648  1.8.2.1  nathanw 		 * us to get bogus results, so we avoid them.
    649  1.8.2.1  nathanw 		 */
    650  1.8.2.1  nathanw 		runup = 0;
    651  1.8.2.1  nathanw 		if (sc->sc_variant == SEEQ_8004 &&
    652  1.8.2.1  nathanw 		    ((addr & 0x00ff) == 0x00ea ||
    653  1.8.2.1  nathanw 		     (addr & 0x00ff) == 0x00ee ||
    654  1.8.2.1  nathanw 		     (addr & 0x00ff) == 0x00f0))
    655  1.8.2.1  nathanw 			runup = (addr & 0x00ff) - 0x00e8;
    656      1.1    bjh21 
    657  1.8.2.1  nathanw 		ea_await_fifo_empty(sc);
    658      1.1    bjh21 
    659  1.8.2.1  nathanw 		ea_select_buffer(sc, SEEQ_BUFCODE_LOCAL_MEM);
    660  1.8.2.1  nathanw 
    661  1.8.2.1  nathanw 		/*
    662  1.8.2.1  nathanw 		 * 80C04 bug workaround.  I found this in the old arm32 "eb"
    663  1.8.2.1  nathanw 		 * driver.  I've no idea what it does, but it seems to stop
    664  1.8.2.1  nathanw 		 * the chip mangling data so often.
    665  1.8.2.1  nathanw 		 */
    666  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    667  1.8.2.1  nathanw 		    sc->sc_command | SEEQ_CMD_FIFO_WRITE);
    668  1.8.2.1  nathanw 		ea_await_fifo_empty(sc);
    669  1.8.2.1  nathanw 
    670  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_DMA_ADDR, addr - runup);
    671  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    672  1.8.2.1  nathanw 		    sc->sc_command | SEEQ_CMD_FIFO_READ);
    673  1.8.2.1  nathanw 
    674  1.8.2.1  nathanw 		ea_await_fifo_full(sc);
    675  1.8.2.1  nathanw 		while (runup > 0) {
    676  1.8.2.3  nathanw 			(void)SEEQ_READ16(sc, iot, ioh, SEEQ_BUFWIN);
    677  1.8.2.1  nathanw 			runup -= 2;
    678  1.8.2.1  nathanw 		}
    679  1.8.2.1  nathanw 	}
    680      1.1    bjh21 
    681  1.8.2.3  nathanw 	if (len > 0) {
    682  1.8.2.3  nathanw 		if (sc->sc_flags & SF_8BIT)
    683  1.8.2.3  nathanw 			bus_space_read_multi_1(iot, ioh, SEEQ_BUFWIN,
    684  1.8.2.3  nathanw 			    (u_int8_t *)buf, len);
    685  1.8.2.3  nathanw 		else
    686  1.8.2.3  nathanw 			bus_space_read_multi_2(iot, ioh, SEEQ_BUFWIN,
    687  1.8.2.3  nathanw 			    (u_int16_t *)buf, len / 2);
    688  1.8.2.3  nathanw 	}
    689      1.1    bjh21 }
    690      1.1    bjh21 
    691      1.3    bjh21 static void
    692      1.3    bjh21 ea_select_buffer(struct seeq8005_softc *sc, int bufcode)
    693      1.3    bjh21 {
    694      1.3    bjh21 
    695  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, sc->sc_iot, sc->sc_ioh, SEEQ_CONFIG1,
    696      1.3    bjh21 			  sc->sc_config1 | bufcode);
    697      1.3    bjh21 }
    698      1.1    bjh21 
    699      1.5    bjh21 /* Must be called at splnet */
    700      1.5    bjh21 static void
    701      1.5    bjh21 ea_set_address(struct seeq8005_softc *sc, int which, u_int8_t const *ea)
    702      1.5    bjh21 {
    703      1.5    bjh21 	int i;
    704      1.5    bjh21 
    705  1.8.2.1  nathanw 	ea_select_buffer(sc, SEEQ_BUFCODE_STATION_ADDR0 + which);
    706      1.5    bjh21 	for (i = 0; i < ETHER_ADDR_LEN; ++i)
    707  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, sc->sc_iot, sc->sc_ioh, SEEQ_BUFWIN,
    708      1.5    bjh21 				  ea[i]);
    709      1.5    bjh21 }
    710      1.5    bjh21 
    711      1.1    bjh21 /*
    712      1.1    bjh21  * Initialize interface.
    713      1.1    bjh21  *
    714      1.1    bjh21  * This should leave the interface in a state for packet reception and
    715      1.1    bjh21  * transmission.
    716      1.1    bjh21  */
    717      1.1    bjh21 
    718      1.1    bjh21 static int
    719      1.5    bjh21 ea_init(struct ifnet *ifp)
    720      1.1    bjh21 {
    721      1.5    bjh21 	struct seeq8005_softc *sc = ifp->if_softc;
    722      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    723      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    724      1.5    bjh21 	int s;
    725      1.1    bjh21 
    726  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_MISC, ("ea_init()\n"));
    727      1.1    bjh21 
    728      1.1    bjh21 	s = splnet();
    729      1.1    bjh21 
    730      1.1    bjh21 	/* First, reset the board. */
    731      1.1    bjh21 
    732      1.3    bjh21 	ea_chipreset(sc);
    733      1.3    bjh21 
    734      1.3    bjh21 	/* Set up defaults for the registers */
    735      1.3    bjh21 
    736  1.8.2.1  nathanw 	sc->sc_command = 0;
    737  1.8.2.1  nathanw 	sc->sc_config1 = 0;
    738      1.3    bjh21 #if BYTE_ORDER == BIG_ENDIAN
    739  1.8.2.1  nathanw 	sc->sc_config2 = SEEQ_CFG2_BYTESWAP;
    740      1.3    bjh21 #else
    741      1.3    bjh21 	sc->sc_config2 = 0;
    742      1.3    bjh21 #endif
    743  1.8.2.1  nathanw 	sc->sc_config3 = 0;
    744      1.1    bjh21 
    745  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND, sc->sc_command);
    746  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_CONFIG1, sc->sc_config1);
    747  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
    748  1.8.2.1  nathanw 	if (sc->sc_variant == SEEQ_8004) {
    749  1.8.2.1  nathanw 		ea_select_buffer(sc, SEEQ_BUFCODE_CONFIG3);
    750  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_BUFWIN, sc->sc_config3);
    751  1.8.2.1  nathanw 	}
    752      1.3    bjh21 
    753      1.3    bjh21 	/* Write the station address - the receiver must be off */
    754      1.5    bjh21 	ea_set_address(sc, 0, LLADDR(ifp->if_sadl));
    755      1.1    bjh21 
    756  1.8.2.1  nathanw 	/* Split board memory into Rx and Tx. */
    757  1.8.2.1  nathanw 	ea_select_buffer(sc, SEEQ_BUFCODE_TX_EAP);
    758  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_BUFWIN, (sc->sc_tx_bufsize>> 8) - 1);
    759  1.8.2.1  nathanw 
    760  1.8.2.3  nathanw 	if (sc->sc_variant == SEEQ_8004) {
    761  1.8.2.3  nathanw 		/* Make the interface IFF_SIMPLEX. */
    762  1.8.2.1  nathanw 		sc->sc_config2 |= SEEQ_CFG2_RX_TX_DISABLE;
    763  1.8.2.3  nathanw 		/* Enable reception of long packets (for vlan(4)). */
    764  1.8.2.3  nathanw 		sc->sc_config2 |= SEEQ_CFG2_PASS_LONGSHORT;
    765  1.8.2.3  nathanw 	}
    766  1.8.2.1  nathanw 
    767      1.1    bjh21 	/* Configure rx. */
    768  1.8.2.1  nathanw 	ea_mc_reset(sc);
    769      1.1    bjh21 	if (ifp->if_flags & IFF_PROMISC)
    770  1.8.2.1  nathanw 		sc->sc_config1 = SEEQ_CFG1_PROMISCUOUS;
    771  1.8.2.1  nathanw 	else if ((ifp->if_flags & IFF_ALLMULTI) || sc->sc_variant == SEEQ_8004)
    772  1.8.2.1  nathanw 		sc->sc_config1 = SEEQ_CFG1_MULTICAST;
    773      1.1    bjh21 	else
    774  1.8.2.1  nathanw 		sc->sc_config1 = SEEQ_CFG1_BROADCAST;
    775  1.8.2.1  nathanw 	sc->sc_config1 |= SEEQ_CFG1_STATION_ADDR0;
    776  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_CONFIG1, sc->sc_config1);
    777      1.3    bjh21 
    778      1.3    bjh21 	/* Setup the Rx pointers */
    779  1.8.2.1  nathanw 	sc->sc_rx_ptr = sc->sc_tx_bufsize;
    780      1.3    bjh21 
    781  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_RX_PTR, sc->sc_rx_ptr);
    782  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_RX_END, sc->sc_rx_ptr >> 8);
    783      1.3    bjh21 
    784      1.3    bjh21 
    785      1.3    bjh21 	/* Place a NULL header at the beginning of the receive area */
    786      1.3    bjh21 	ea_writebuf(sc, NULL, sc->sc_rx_ptr, 0);
    787      1.3    bjh21 
    788  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_BUFWIN, 0x0000);
    789  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_BUFWIN, 0x0000);
    790      1.1    bjh21 
    791      1.1    bjh21 
    792      1.1    bjh21 	/* Configure TX. */
    793  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_MISC, ("Configuring tx...\n"));
    794      1.1    bjh21 
    795  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_TX_PTR, 0x0000);
    796      1.1    bjh21 
    797  1.8.2.1  nathanw 	sc->sc_config2 |= SEEQ_CFG2_OUTPUT;
    798  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
    799      1.1    bjh21 
    800  1.8.2.1  nathanw 	/* Reset tx buffer pointers */
    801  1.8.2.1  nathanw 	sc->sc_tx_cur = 0;
    802  1.8.2.1  nathanw 	sc->sc_tx_used = 0;
    803  1.8.2.1  nathanw 	sc->sc_tx_next = 0;
    804      1.1    bjh21 
    805      1.1    bjh21 	/* Place a NULL header at the beginning of the transmit area */
    806      1.1    bjh21 	ea_writebuf(sc, NULL, 0x0000, 0);
    807      1.1    bjh21 
    808  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_BUFWIN, 0x0000);
    809  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_BUFWIN, 0x0000);
    810      1.1    bjh21 
    811  1.8.2.1  nathanw 	sc->sc_command |= SEEQ_CMD_TX_INTEN;
    812  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND, sc->sc_command);
    813  1.8.2.1  nathanw 
    814  1.8.2.1  nathanw 	/* Turn on Rx */
    815  1.8.2.1  nathanw 	sc->sc_command |= SEEQ_CMD_RX_INTEN;
    816  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    817  1.8.2.1  nathanw 			  sc->sc_command | SEEQ_CMD_RX_ON);
    818      1.1    bjh21 
    819      1.3    bjh21 	/* TX_ON gets set by ea_txpacket when there's something to transmit. */
    820      1.1    bjh21 
    821      1.1    bjh21 
    822      1.1    bjh21 	/* Set flags appropriately. */
    823      1.1    bjh21 	ifp->if_flags |= IFF_RUNNING;
    824      1.1    bjh21 	ifp->if_flags &= ~IFF_OACTIVE;
    825  1.8.2.1  nathanw 	sc->sc_enabled = 1;
    826      1.1    bjh21 
    827      1.1    bjh21 	/* And start output. */
    828      1.1    bjh21 	ea_start(ifp);
    829      1.1    bjh21 
    830      1.1    bjh21 	splx(s);
    831      1.1    bjh21 	return 0;
    832      1.1    bjh21 }
    833      1.1    bjh21 
    834      1.1    bjh21 /*
    835      1.1    bjh21  * Start output on interface. Get datagrams from the queue and output them,
    836      1.1    bjh21  * giving the receiver a chance between datagrams. Call only from splnet or
    837      1.1    bjh21  * interrupt level!
    838      1.1    bjh21  */
    839      1.1    bjh21 
    840      1.1    bjh21 static void
    841      1.1    bjh21 ea_start(struct ifnet *ifp)
    842      1.1    bjh21 {
    843      1.1    bjh21 	struct seeq8005_softc *sc = ifp->if_softc;
    844      1.1    bjh21 	int s;
    845      1.1    bjh21 
    846      1.1    bjh21 	s = splnet();
    847  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_TX, ("ea_start()...\n"));
    848      1.1    bjh21 
    849  1.8.2.1  nathanw 	/*
    850  1.8.2.1  nathanw 	 * Don't do anything if output is active.  seeq8005intr() will call
    851  1.8.2.1  nathanw 	 * us (actually eatxpacket()) back when the card's ready for more
    852  1.8.2.1  nathanw 	 * frames.
    853  1.8.2.1  nathanw 	 */
    854      1.1    bjh21 	if (ifp->if_flags & IFF_OACTIVE)
    855      1.1    bjh21 		return;
    856      1.1    bjh21 
    857      1.1    bjh21 	/* Mark interface as output active */
    858      1.1    bjh21 
    859      1.1    bjh21 	ifp->if_flags |= IFF_OACTIVE;
    860      1.1    bjh21 
    861      1.1    bjh21 	/* tx packets */
    862      1.1    bjh21 
    863      1.1    bjh21 	eatxpacket(sc);
    864      1.1    bjh21 	splx(s);
    865      1.1    bjh21 }
    866      1.1    bjh21 
    867      1.1    bjh21 
    868      1.1    bjh21 /*
    869      1.1    bjh21  * Transfer a packet to the interface buffer and start transmission
    870      1.1    bjh21  *
    871      1.1    bjh21  * Called at splnet()
    872      1.1    bjh21  */
    873      1.1    bjh21 
    874      1.1    bjh21 void
    875      1.1    bjh21 eatxpacket(struct seeq8005_softc *sc)
    876      1.1    bjh21 {
    877      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    878      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    879  1.8.2.1  nathanw 	struct mbuf *m0;
    880      1.1    bjh21 	struct ifnet *ifp;
    881      1.1    bjh21 
    882      1.1    bjh21 	ifp = &sc->sc_ethercom.ec_if;
    883      1.1    bjh21 
    884      1.1    bjh21 	/* Dequeue the next packet. */
    885      1.7  thorpej 	IFQ_DEQUEUE(&ifp->if_snd, m0);
    886      1.1    bjh21 
    887      1.1    bjh21 	/* If there's nothing to send, return. */
    888      1.1    bjh21 	if (!m0) {
    889      1.1    bjh21 		ifp->if_flags &= ~IFF_OACTIVE;
    890  1.8.2.1  nathanw 		sc->sc_config2 |= SEEQ_CFG2_OUTPUT;
    891  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
    892  1.8.2.1  nathanw 		DPRINTF(SEEQ_DEBUG_TX, ("tx finished\n"));
    893      1.1    bjh21 		return;
    894      1.1    bjh21 	}
    895      1.1    bjh21 
    896      1.1    bjh21 #if NBPFILTER > 0
    897      1.1    bjh21 	/* Give the packet to the bpf, if any. */
    898      1.1    bjh21 	if (ifp->if_bpf)
    899      1.1    bjh21 		bpf_mtap(ifp->if_bpf, m0);
    900      1.1    bjh21 #endif
    901      1.1    bjh21 
    902  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_TX, ("Tx new packet\n"));
    903      1.1    bjh21 
    904  1.8.2.1  nathanw 	sc->sc_config2 &= ~SEEQ_CFG2_OUTPUT;
    905  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
    906  1.8.2.1  nathanw 
    907  1.8.2.1  nathanw 	ea_writembuf(sc, m0, 0x0000);
    908  1.8.2.1  nathanw 	m_freem(m0);
    909  1.8.2.1  nathanw 
    910  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_TX_PTR, 0x0000);
    911  1.8.2.1  nathanw 
    912  1.8.2.1  nathanw 	/* Now transmit the datagram. */
    913  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    914  1.8.2.1  nathanw 			  sc->sc_command | SEEQ_CMD_TX_ON);
    915  1.8.2.1  nathanw 
    916  1.8.2.1  nathanw 	/* Make sure we notice if the chip goes silent on us. */
    917  1.8.2.1  nathanw 	ifp->if_timer = 5;
    918  1.8.2.1  nathanw 
    919  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_TX,
    920  1.8.2.3  nathanw 	    ("st=%04x\n", SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS)));
    921  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_TX, ("tx: queued\n"));
    922  1.8.2.1  nathanw }
    923  1.8.2.1  nathanw 
    924  1.8.2.1  nathanw /*
    925  1.8.2.1  nathanw  * Copy a packet from an mbuf to the transmit buffer on the card.
    926  1.8.2.1  nathanw  *
    927  1.8.2.1  nathanw  * Puts a valid Tx header at the start of the packet, and a null header at
    928  1.8.2.1  nathanw  * the end.
    929  1.8.2.1  nathanw  */
    930  1.8.2.1  nathanw static int
    931  1.8.2.1  nathanw ea_writembuf(struct seeq8005_softc *sc, struct mbuf *m0, int bufstart)
    932  1.8.2.1  nathanw {
    933  1.8.2.1  nathanw 	struct mbuf *m;
    934  1.8.2.1  nathanw 	int len, nextpacket;
    935  1.8.2.1  nathanw 	u_int8_t hdr[4];
    936      1.1    bjh21 
    937      1.1    bjh21 	/*
    938  1.8.2.1  nathanw 	 * Copy the datagram to the packet buffer.
    939      1.1    bjh21 	 */
    940      1.1    bjh21 	len = 0;
    941      1.1    bjh21 	for (m = m0; m; m = m->m_next) {
    942      1.1    bjh21 		if (m->m_len == 0)
    943      1.1    bjh21 			continue;
    944  1.8.2.1  nathanw 		ea_writebuf(sc, mtod(m, caddr_t), bufstart + 4 + len,
    945  1.8.2.1  nathanw 		    m->m_len);
    946      1.1    bjh21 		len += m->m_len;
    947      1.1    bjh21 	}
    948      1.1    bjh21 
    949      1.1    bjh21 	len = max(len, ETHER_MIN_LEN);
    950      1.1    bjh21 
    951      1.1    bjh21 	/* Follow it with a NULL packet header */
    952  1.8.2.1  nathanw 	memset(hdr, 0, 4);
    953  1.8.2.1  nathanw 	ea_writebuf(sc, hdr, bufstart + 4 + len, 4);
    954  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, sc->sc_iot, sc->sc_ioh, SEEQ_BUFWIN, 0x0000);
    955  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, sc->sc_iot, sc->sc_ioh, SEEQ_BUFWIN, 0x0000);
    956      1.1    bjh21 
    957  1.8.2.1  nathanw 	/* Ok we now have a packet len bytes long in our packet buffer */
    958  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_TX, ("ea_writembuf: length=%d\n", len));
    959      1.1    bjh21 
    960      1.1    bjh21 	/* Write the packet header */
    961      1.1    bjh21 	nextpacket = len + 4;
    962      1.1    bjh21 	hdr[0] = (nextpacket >> 8) & 0xff;
    963      1.1    bjh21 	hdr[1] = nextpacket & 0xff;
    964  1.8.2.1  nathanw 	hdr[2] = SEEQ_PKTCMD_TX | SEEQ_PKTCMD_DATA_FOLLOWS |
    965  1.8.2.1  nathanw 		SEEQ_TXCMD_XMIT_SUCCESS_INT | SEEQ_TXCMD_COLLISION_INT;
    966      1.1    bjh21 	hdr[3] = 0; /* Status byte -- will be update by hardware. */
    967      1.1    bjh21 	ea_writebuf(sc, hdr, 0x0000, 4);
    968      1.1    bjh21 
    969  1.8.2.1  nathanw 	return len;
    970      1.1    bjh21 }
    971      1.1    bjh21 
    972      1.1    bjh21 /*
    973      1.1    bjh21  * Ethernet controller interrupt.
    974      1.1    bjh21  */
    975      1.1    bjh21 
    976      1.1    bjh21 int
    977      1.1    bjh21 seeq8005intr(void *arg)
    978      1.1    bjh21 {
    979      1.1    bjh21 	struct seeq8005_softc *sc = arg;
    980      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
    981      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
    982  1.8.2.1  nathanw 	int status, handled;
    983      1.1    bjh21 
    984      1.1    bjh21 	handled = 0;
    985      1.1    bjh21 
    986      1.1    bjh21 	/* Get the controller status */
    987  1.8.2.3  nathanw 	status = SEEQ_READ16(sc, iot, ioh, SEEQ_STATUS);
    988      1.1    bjh21 
    989      1.1    bjh21 	/* Tx interrupt ? */
    990  1.8.2.1  nathanw 	if (status & SEEQ_STATUS_TX_INT) {
    991      1.1    bjh21 		handled = 1;
    992      1.1    bjh21 
    993      1.1    bjh21 		/* Acknowledge the interrupt */
    994  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
    995  1.8.2.1  nathanw 				  sc->sc_command | SEEQ_CMD_TX_INTACK);
    996      1.1    bjh21 
    997  1.8.2.1  nathanw 		ea_txint(sc);
    998  1.8.2.1  nathanw 	}
    999      1.1    bjh21 
   1000      1.1    bjh21 
   1001  1.8.2.1  nathanw 	/* Rx interrupt ? */
   1002  1.8.2.1  nathanw 	if (status & SEEQ_STATUS_RX_INT) {
   1003  1.8.2.1  nathanw 		handled = 1;
   1004      1.1    bjh21 
   1005  1.8.2.1  nathanw 		/* Acknowledge the interrupt */
   1006  1.8.2.3  nathanw 		SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
   1007  1.8.2.1  nathanw 				  sc->sc_command | SEEQ_CMD_RX_INTACK);
   1008      1.1    bjh21 
   1009  1.8.2.1  nathanw 		/* Processes the received packets */
   1010  1.8.2.1  nathanw 		ea_rxint(sc);
   1011      1.1    bjh21 	}
   1012      1.1    bjh21 
   1013  1.8.2.1  nathanw 	return handled;
   1014  1.8.2.1  nathanw }
   1015      1.1    bjh21 
   1016  1.8.2.1  nathanw static void
   1017  1.8.2.1  nathanw ea_txint(struct seeq8005_softc *sc)
   1018  1.8.2.1  nathanw {
   1019  1.8.2.1  nathanw 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1020  1.8.2.1  nathanw 	bus_space_tag_t iot = sc->sc_iot;
   1021  1.8.2.1  nathanw 	bus_space_handle_t ioh = sc->sc_ioh;
   1022  1.8.2.1  nathanw 	u_int8_t txhdr[4];
   1023  1.8.2.1  nathanw 	u_int txstatus;
   1024      1.1    bjh21 
   1025  1.8.2.1  nathanw 	ea_readbuf(sc, txhdr, 0x0000, 4);
   1026      1.1    bjh21 
   1027  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_TX, ("txstatus=%02x %02x %02x %02x\n",
   1028  1.8.2.1  nathanw 	    txhdr[0], txhdr[1], txhdr[2], txhdr[3]));
   1029  1.8.2.1  nathanw 	txstatus = txhdr[3];
   1030      1.1    bjh21 
   1031  1.8.2.1  nathanw 	/*
   1032  1.8.2.1  nathanw 	 * If SEEQ_TXSTAT_COLLISION is set then we received at least
   1033  1.8.2.1  nathanw 	 * one collision. On the 8004 we can find out exactly how many
   1034  1.8.2.1  nathanw 	 * collisions occurred.
   1035  1.8.2.1  nathanw 	 *
   1036  1.8.2.1  nathanw 	 * The SEEQ_PKTSTAT_DONE will be set if the transmission has
   1037  1.8.2.1  nathanw 	 * completed.
   1038  1.8.2.1  nathanw 	 *
   1039  1.8.2.1  nathanw 	 * If SEEQ_TXSTAT_COLLISION16 is set then 16 collisions
   1040  1.8.2.1  nathanw 	 * occurred and the packet transmission was aborted.
   1041  1.8.2.1  nathanw 	 * This situation is untested as present.
   1042  1.8.2.1  nathanw 	 *
   1043  1.8.2.3  nathanw 	 * The SEEQ_TXSTAT_BABBLE is untested as it should only be set
   1044  1.8.2.3  nathanw 	 * when we deliberately transmit oversized packets (e.g. for
   1045  1.8.2.3  nathanw 	 * 802.1Q).
   1046  1.8.2.1  nathanw 	 */
   1047  1.8.2.1  nathanw 	if (txstatus & SEEQ_TXSTAT_COLLISION) {
   1048  1.8.2.1  nathanw 		switch (sc->sc_variant) {
   1049  1.8.2.1  nathanw 		case SEEQ_8004: {
   1050  1.8.2.1  nathanw 			int colls;
   1051      1.1    bjh21 
   1052  1.8.2.1  nathanw 			/*
   1053  1.8.2.1  nathanw 			 * The 8004 contains a 4 bit collision count
   1054  1.8.2.1  nathanw 			 * in the status register.
   1055  1.8.2.1  nathanw 			 */
   1056      1.1    bjh21 
   1057  1.8.2.1  nathanw 			/* This appears to be broken on 80C04.AE */
   1058  1.8.2.1  nathanw /*			ifp->if_collisions +=
   1059  1.8.2.1  nathanw 			    (txstatus >> SEEQ_TXSTAT_COLLISIONS_SHIFT)
   1060  1.8.2.1  nathanw 			    & SEEQ_TXSTAT_COLLISION_MASK;*/
   1061  1.8.2.1  nathanw 
   1062  1.8.2.1  nathanw 			/* Use the TX Collision register */
   1063  1.8.2.1  nathanw 			ea_select_buffer(sc, SEEQ_BUFCODE_TX_COLLS);
   1064  1.8.2.1  nathanw 			colls = bus_space_read_1(iot, ioh, SEEQ_BUFWIN);
   1065  1.8.2.1  nathanw 			ifp->if_collisions += colls;
   1066  1.8.2.1  nathanw 			break;
   1067      1.1    bjh21 		}
   1068  1.8.2.1  nathanw 		case SEEQ_8005:
   1069  1.8.2.1  nathanw 			/* We known there was at least 1 collision */
   1070  1.8.2.1  nathanw 			ifp->if_collisions++;
   1071  1.8.2.1  nathanw 			break;
   1072  1.8.2.1  nathanw 		}
   1073  1.8.2.1  nathanw 	} else if (txstatus & SEEQ_TXSTAT_COLLISION16) {
   1074  1.8.2.1  nathanw 		printf("seeq_intr: col16 %x\n", txstatus);
   1075  1.8.2.1  nathanw 		ifp->if_collisions += 16;
   1076  1.8.2.1  nathanw 		ifp->if_oerrors++;
   1077      1.1    bjh21 	}
   1078      1.1    bjh21 
   1079  1.8.2.1  nathanw 	/* Have we completed transmission on the packet ? */
   1080  1.8.2.1  nathanw 	if (txstatus & SEEQ_PKTSTAT_DONE) {
   1081  1.8.2.1  nathanw 		/* Clear watchdog timer. */
   1082  1.8.2.1  nathanw 		ifp->if_timer = 0;
   1083  1.8.2.1  nathanw 		ifp->if_flags &= ~IFF_OACTIVE;
   1084      1.1    bjh21 
   1085  1.8.2.1  nathanw 		/* Update stats */
   1086  1.8.2.1  nathanw 		ifp->if_opackets++;
   1087      1.1    bjh21 
   1088  1.8.2.1  nathanw 		/* Tx next packet */
   1089  1.8.2.1  nathanw 
   1090  1.8.2.1  nathanw 		eatxpacket(sc);
   1091  1.8.2.1  nathanw 	}
   1092  1.8.2.1  nathanw }
   1093      1.1    bjh21 
   1094      1.1    bjh21 void
   1095  1.8.2.1  nathanw ea_rxint(struct seeq8005_softc *sc)
   1096      1.1    bjh21 {
   1097      1.1    bjh21 	bus_space_tag_t iot = sc->sc_iot;
   1098      1.1    bjh21 	bus_space_handle_t ioh = sc->sc_ioh;
   1099      1.1    bjh21 	u_int addr;
   1100      1.1    bjh21 	int len;
   1101      1.1    bjh21 	int ctrl;
   1102      1.1    bjh21 	int ptr;
   1103      1.1    bjh21 	int pack;
   1104      1.1    bjh21 	int status;
   1105      1.1    bjh21 	u_int8_t rxhdr[4];
   1106      1.1    bjh21 	struct ifnet *ifp;
   1107      1.1    bjh21 
   1108      1.1    bjh21 	ifp = &sc->sc_ethercom.ec_if;
   1109      1.1    bjh21 
   1110      1.1    bjh21 
   1111      1.1    bjh21 	/* We start from the last rx pointer position */
   1112      1.1    bjh21 	addr = sc->sc_rx_ptr;
   1113  1.8.2.1  nathanw 	sc->sc_config2 &= ~SEEQ_CFG2_OUTPUT;
   1114  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
   1115      1.1    bjh21 
   1116      1.1    bjh21 	do {
   1117      1.1    bjh21 		/* Read rx header */
   1118      1.1    bjh21 		ea_readbuf(sc, rxhdr, addr, 4);
   1119      1.1    bjh21 
   1120      1.1    bjh21 		/* Split the packet header */
   1121      1.1    bjh21 		ptr = (rxhdr[0] << 8) | rxhdr[1];
   1122      1.1    bjh21 		ctrl = rxhdr[2];
   1123      1.1    bjh21 		status = rxhdr[3];
   1124      1.1    bjh21 
   1125  1.8.2.1  nathanw 		DPRINTF(SEEQ_DEBUG_RX,
   1126  1.8.2.1  nathanw 		    ("addr=%04x ptr=%04x ctrl=%02x status=%02x\n",
   1127  1.8.2.1  nathanw 			addr, ptr, ctrl, status));
   1128      1.1    bjh21 
   1129      1.1    bjh21 		/* Zero packet ptr ? then must be null header so exit */
   1130      1.1    bjh21 		if (ptr == 0) break;
   1131      1.1    bjh21 
   1132  1.8.2.1  nathanw 		/* Sanity-check the next-packet pointer and flags. */
   1133  1.8.2.1  nathanw 		if (__predict_false(ptr < sc->sc_tx_bufsize ||
   1134  1.8.2.1  nathanw 		    (ctrl & SEEQ_PKTCMD_TX))) {
   1135  1.8.2.1  nathanw 			++ifp->if_ierrors;
   1136  1.8.2.1  nathanw 			log(LOG_ERR,
   1137  1.8.2.1  nathanw 			    "%s: Rx chain corrupt at %04x (ptr = %04x)\n",
   1138  1.8.2.1  nathanw 			    sc->sc_dev.dv_xname, addr, ptr);
   1139  1.8.2.1  nathanw 			ea_init(ifp);
   1140  1.8.2.1  nathanw 			return;
   1141  1.8.2.1  nathanw 		}
   1142      1.1    bjh21 
   1143      1.1    bjh21 		/* Get packet length */
   1144      1.1    bjh21        		len = (ptr - addr) - 4;
   1145      1.1    bjh21 
   1146      1.1    bjh21 		if (len < 0)
   1147  1.8.2.1  nathanw 			len += sc->sc_rx_bufsize;
   1148  1.8.2.1  nathanw 		DPRINTF(SEEQ_DEBUG_RX, ("len=%04x\n", len));
   1149      1.1    bjh21 
   1150      1.1    bjh21 		/* Has the packet rx completed ? if not then exit */
   1151  1.8.2.1  nathanw 		if ((status & SEEQ_PKTSTAT_DONE) == 0)
   1152      1.1    bjh21 			break;
   1153      1.1    bjh21 
   1154      1.1    bjh21 		/*
   1155      1.1    bjh21 		 * Did we have any errors? then note error and go to
   1156      1.1    bjh21 		 * next packet
   1157      1.1    bjh21 		 */
   1158  1.8.2.3  nathanw 		if (__predict_false(status &
   1159  1.8.2.3  nathanw 			(SEEQ_RXSTAT_CRC_ERROR | SEEQ_RXSTAT_DRIBBLE_ERROR |
   1160  1.8.2.3  nathanw 			 SEEQ_RXSTAT_SHORT_FRAME))) {
   1161      1.1    bjh21 			++ifp->if_ierrors;
   1162      1.1    bjh21 			log(LOG_WARNING,
   1163  1.8.2.1  nathanw 			    "%s: rx packet error at %04x (err=%02x)\n",
   1164  1.8.2.1  nathanw 			    sc->sc_dev.dv_xname, addr, status & 0x0f);
   1165  1.8.2.1  nathanw 			/* XXX shouldn't need to reset if it's genuine. */
   1166      1.5    bjh21 			ea_init(ifp);
   1167      1.1    bjh21 			return;
   1168      1.1    bjh21 		}
   1169      1.1    bjh21 		/*
   1170  1.8.2.3  nathanw 		 * Is the packet too big?  We allow slightly oversize packets
   1171  1.8.2.3  nathanw 		 * for vlan(4) and tcpdump purposes, but the rest of the world
   1172  1.8.2.3  nathanw 		 * wants incoming packets in a single mbuf cluster.
   1173      1.1    bjh21 		 */
   1174  1.8.2.3  nathanw 		if (__predict_false(len > MCLBYTES)) {
   1175      1.1    bjh21 			++ifp->if_ierrors;
   1176  1.8.2.1  nathanw 			log(LOG_ERR,
   1177  1.8.2.1  nathanw 			    "%s: rx packet size error at %04x (len=%d)\n",
   1178  1.8.2.1  nathanw 			    sc->sc_dev.dv_xname, addr, len);
   1179  1.8.2.1  nathanw 			sc->sc_config2 |= SEEQ_CFG2_OUTPUT;
   1180  1.8.2.3  nathanw 			SEEQ_WRITE16(sc, iot, ioh, SEEQ_CONFIG2,
   1181      1.1    bjh21 					  sc->sc_config2);
   1182      1.5    bjh21 			ea_init(ifp);
   1183      1.1    bjh21 			return;
   1184      1.1    bjh21 		}
   1185      1.1    bjh21 
   1186      1.1    bjh21 		ifp->if_ipackets++;
   1187      1.1    bjh21 		/* Pass data up to upper levels. */
   1188  1.8.2.1  nathanw 		ea_read(sc, addr + 4, len);
   1189      1.1    bjh21 
   1190      1.1    bjh21 		addr = ptr;
   1191      1.1    bjh21 		++pack;
   1192      1.1    bjh21 	} while (len != 0);
   1193      1.1    bjh21 
   1194  1.8.2.1  nathanw 	sc->sc_config2 |= SEEQ_CFG2_OUTPUT;
   1195  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
   1196      1.1    bjh21 
   1197  1.8.2.1  nathanw 	DPRINTF(SEEQ_DEBUG_RX, ("new rx ptr=%04x\n", addr));
   1198      1.1    bjh21 
   1199      1.1    bjh21 	/* Store new rx pointer */
   1200      1.1    bjh21 	sc->sc_rx_ptr = addr;
   1201  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_RX_END, sc->sc_rx_ptr >> 8);
   1202      1.1    bjh21 
   1203      1.1    bjh21 	/* Make sure the receiver is on */
   1204  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, iot, ioh, SEEQ_COMMAND,
   1205  1.8.2.1  nathanw 			  sc->sc_command | SEEQ_CMD_RX_ON);
   1206      1.1    bjh21 }
   1207      1.1    bjh21 
   1208      1.1    bjh21 
   1209      1.1    bjh21 /*
   1210      1.1    bjh21  * Pass a packet up to the higher levels.
   1211      1.1    bjh21  */
   1212      1.1    bjh21 
   1213      1.1    bjh21 static void
   1214  1.8.2.1  nathanw ea_read(struct seeq8005_softc *sc, int addr, int len)
   1215      1.1    bjh21 {
   1216      1.1    bjh21 	struct mbuf *m;
   1217      1.1    bjh21 	struct ifnet *ifp;
   1218      1.1    bjh21 
   1219      1.1    bjh21 	ifp = &sc->sc_ethercom.ec_if;
   1220      1.1    bjh21 
   1221      1.1    bjh21 	/* Pull packet off interface. */
   1222  1.8.2.1  nathanw 	m = ea_get(sc, addr, len, ifp);
   1223      1.1    bjh21 	if (m == 0)
   1224      1.1    bjh21 		return;
   1225      1.1    bjh21 
   1226      1.1    bjh21 #if NBPFILTER > 0
   1227      1.1    bjh21 	/*
   1228      1.1    bjh21 	 * Check if there's a BPF listener on this interface.
   1229      1.1    bjh21 	 * If so, hand off the raw packet to bpf.
   1230      1.1    bjh21 	 */
   1231      1.4  thorpej 	if (ifp->if_bpf)
   1232      1.1    bjh21 		bpf_mtap(ifp->if_bpf, m);
   1233      1.1    bjh21 #endif
   1234      1.1    bjh21 
   1235      1.1    bjh21 	(*ifp->if_input)(ifp, m);
   1236      1.1    bjh21 }
   1237      1.1    bjh21 
   1238      1.1    bjh21 /*
   1239      1.1    bjh21  * Pull read data off a interface.  Len is length of data, with local net
   1240      1.1    bjh21  * header stripped.  We copy the data into mbufs.  When full cluster sized
   1241      1.1    bjh21  * units are present we copy into clusters.
   1242      1.1    bjh21  */
   1243      1.1    bjh21 
   1244      1.1    bjh21 struct mbuf *
   1245  1.8.2.1  nathanw ea_get(struct seeq8005_softc *sc, int addr, int totlen, struct ifnet *ifp)
   1246      1.1    bjh21 {
   1247      1.1    bjh21         struct mbuf *top, **mp, *m;
   1248      1.1    bjh21         int len;
   1249      1.1    bjh21         u_int cp, epkt;
   1250      1.1    bjh21 
   1251      1.1    bjh21         cp = addr;
   1252      1.1    bjh21         epkt = cp + totlen;
   1253      1.1    bjh21 
   1254      1.1    bjh21         MGETHDR(m, M_DONTWAIT, MT_DATA);
   1255      1.1    bjh21         if (m == 0)
   1256      1.1    bjh21                 return 0;
   1257      1.1    bjh21         m->m_pkthdr.rcvif = ifp;
   1258      1.1    bjh21         m->m_pkthdr.len = totlen;
   1259      1.1    bjh21         m->m_len = MHLEN;
   1260      1.1    bjh21         top = 0;
   1261      1.1    bjh21         mp = &top;
   1262      1.1    bjh21 
   1263      1.1    bjh21         while (totlen > 0) {
   1264      1.1    bjh21                 if (top) {
   1265      1.1    bjh21                         MGET(m, M_DONTWAIT, MT_DATA);
   1266      1.1    bjh21                         if (m == 0) {
   1267      1.1    bjh21                                 m_freem(top);
   1268      1.1    bjh21                                 return 0;
   1269      1.1    bjh21                         }
   1270      1.1    bjh21                         m->m_len = MLEN;
   1271      1.1    bjh21                 }
   1272      1.1    bjh21                 len = min(totlen, epkt - cp);
   1273      1.1    bjh21                 if (len >= MINCLSIZE) {
   1274      1.1    bjh21                         MCLGET(m, M_DONTWAIT);
   1275      1.1    bjh21                         if (m->m_flags & M_EXT)
   1276      1.1    bjh21                                 m->m_len = len = min(len, MCLBYTES);
   1277      1.1    bjh21                         else
   1278      1.1    bjh21                                 len = m->m_len;
   1279      1.1    bjh21                 } else {
   1280      1.1    bjh21                         /*
   1281      1.1    bjh21                          * Place initial small packet/header at end of mbuf.
   1282      1.1    bjh21                          */
   1283      1.1    bjh21                         if (len < m->m_len) {
   1284      1.1    bjh21                                 if (top == 0 && len + max_linkhdr <= m->m_len)
   1285      1.1    bjh21                                         m->m_data += max_linkhdr;
   1286      1.1    bjh21                                 m->m_len = len;
   1287      1.1    bjh21                         } else
   1288      1.1    bjh21                                 len = m->m_len;
   1289      1.1    bjh21                 }
   1290      1.1    bjh21 		if (top == 0) {
   1291      1.1    bjh21 			/* Make sure the payload is aligned */
   1292      1.1    bjh21 			caddr_t newdata = (caddr_t)
   1293      1.1    bjh21 			    ALIGN(m->m_data + sizeof(struct ether_header)) -
   1294      1.1    bjh21 			    sizeof(struct ether_header);
   1295      1.1    bjh21 			len -= newdata - m->m_data;
   1296      1.1    bjh21 			m->m_len = len;
   1297      1.1    bjh21 			m->m_data = newdata;
   1298      1.1    bjh21 		}
   1299      1.1    bjh21                 ea_readbuf(sc, mtod(m, u_char *),
   1300  1.8.2.1  nathanw 		    cp < SEEQ_MAX_BUFFER_SIZE ? cp : cp - sc->sc_rx_bufsize,
   1301  1.8.2.1  nathanw 		    len);
   1302      1.1    bjh21                 cp += len;
   1303      1.1    bjh21                 *mp = m;
   1304      1.1    bjh21                 mp = &m->m_next;
   1305      1.1    bjh21                 totlen -= len;
   1306      1.1    bjh21                 if (cp == epkt)
   1307      1.1    bjh21                         cp = addr;
   1308      1.1    bjh21         }
   1309      1.1    bjh21 
   1310      1.1    bjh21         return top;
   1311      1.1    bjh21 }
   1312      1.1    bjh21 
   1313      1.1    bjh21 /*
   1314      1.3    bjh21  * Process an ioctl request.  Mostly boilerplate.
   1315      1.1    bjh21  */
   1316      1.1    bjh21 static int
   1317      1.1    bjh21 ea_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
   1318      1.1    bjh21 {
   1319      1.1    bjh21 	struct seeq8005_softc *sc = ifp->if_softc;
   1320      1.1    bjh21 	int s, error = 0;
   1321      1.1    bjh21 
   1322      1.1    bjh21 	s = splnet();
   1323      1.1    bjh21 	switch (cmd) {
   1324      1.1    bjh21 
   1325      1.5    bjh21 	default:
   1326      1.5    bjh21 		error = ether_ioctl(ifp, cmd, data);
   1327      1.5    bjh21 		if (error == ENETRESET) {
   1328      1.1    bjh21 			/*
   1329      1.5    bjh21 			 * Multicast list has changed; set the hardware filter
   1330      1.5    bjh21 			 * accordingly.
   1331      1.1    bjh21 			 */
   1332      1.5    bjh21 			ea_mc_reset(sc);
   1333      1.5    bjh21 			error = 0;
   1334      1.1    bjh21 		}
   1335      1.1    bjh21 		break;
   1336      1.1    bjh21 	}
   1337      1.1    bjh21 
   1338      1.1    bjh21 	splx(s);
   1339      1.1    bjh21 	return error;
   1340      1.1    bjh21 }
   1341      1.1    bjh21 
   1342      1.5    bjh21 /* Must be called at splnet() */
   1343  1.8.2.1  nathanw 
   1344      1.5    bjh21 static void
   1345      1.5    bjh21 ea_mc_reset(struct seeq8005_softc *sc)
   1346      1.5    bjh21 {
   1347  1.8.2.1  nathanw 
   1348  1.8.2.1  nathanw 	switch (sc->sc_variant) {
   1349  1.8.2.1  nathanw 	case SEEQ_8004:
   1350  1.8.2.1  nathanw 		ea_mc_reset_8004(sc);
   1351  1.8.2.1  nathanw 		return;
   1352  1.8.2.1  nathanw 	case SEEQ_8005:
   1353  1.8.2.1  nathanw 		ea_mc_reset_8005(sc);
   1354  1.8.2.1  nathanw 		return;
   1355  1.8.2.1  nathanw 	}
   1356  1.8.2.1  nathanw }
   1357  1.8.2.1  nathanw 
   1358  1.8.2.1  nathanw static void
   1359  1.8.2.1  nathanw ea_mc_reset_8004(struct seeq8005_softc *sc)
   1360  1.8.2.1  nathanw {
   1361  1.8.2.1  nathanw 	struct ethercom *ec = &sc->sc_ethercom;
   1362  1.8.2.1  nathanw 	struct ifnet *ifp = &ec->ec_if;
   1363  1.8.2.1  nathanw 	struct ether_multi *enm;
   1364  1.8.2.3  nathanw         u_int32_t crc;
   1365  1.8.2.3  nathanw         int i;
   1366  1.8.2.3  nathanw         struct ether_multistep step;
   1367  1.8.2.3  nathanw         u_int8_t af[8];
   1368  1.8.2.1  nathanw 
   1369  1.8.2.1  nathanw 	/*
   1370  1.8.2.1  nathanw 	 * Set up multicast address filter by passing all multicast addresses
   1371  1.8.2.1  nathanw 	 * through a crc generator, and then using bits 2 - 7 as an index
   1372  1.8.2.1  nathanw 	 * into the 64 bit logical address filter.  The high order bits
   1373  1.8.2.1  nathanw 	 * selects the word, while the rest of the bits select the bit within
   1374  1.8.2.1  nathanw 	 * the word.
   1375  1.8.2.1  nathanw 	 */
   1376  1.8.2.1  nathanw 
   1377  1.8.2.1  nathanw 	if (ifp->if_flags & IFF_PROMISC) {
   1378  1.8.2.1  nathanw 		ifp->if_flags |= IFF_ALLMULTI;
   1379  1.8.2.1  nathanw 		for (i = 0; i < 8; i++)
   1380  1.8.2.1  nathanw 			af[i] = 0xff;
   1381  1.8.2.1  nathanw 		return;
   1382  1.8.2.1  nathanw 	}
   1383  1.8.2.1  nathanw 	for (i = 0; i < 8; i++)
   1384  1.8.2.1  nathanw 		af[i] = 0;
   1385  1.8.2.1  nathanw 	ETHER_FIRST_MULTI(step, ec, enm);
   1386  1.8.2.1  nathanw 	while (enm != NULL) {
   1387  1.8.2.3  nathanw 		if (memcmp(enm->enm_addrlo, enm->enm_addrhi,
   1388  1.8.2.1  nathanw 		    sizeof(enm->enm_addrlo)) != 0) {
   1389  1.8.2.1  nathanw 			/*
   1390  1.8.2.1  nathanw 			 * We must listen to a range of multicast addresses.
   1391  1.8.2.1  nathanw 			 * For now, just accept all multicasts, rather than
   1392  1.8.2.1  nathanw 			 * trying to set only those filter bits needed to match
   1393  1.8.2.1  nathanw 			 * the range.  (At this time, the only use of address
   1394  1.8.2.1  nathanw 			 * ranges is for IP multicast routing, for which the
   1395  1.8.2.1  nathanw 			 * range is big enough to require all bits set.)
   1396  1.8.2.1  nathanw 			 */
   1397  1.8.2.1  nathanw 			ifp->if_flags |= IFF_ALLMULTI;
   1398  1.8.2.1  nathanw 			for (i = 0; i < 8; i++)
   1399  1.8.2.1  nathanw 				af[i] = 0xff;
   1400  1.8.2.1  nathanw 			break;
   1401  1.8.2.1  nathanw 		}
   1402  1.8.2.3  nathanw 
   1403  1.8.2.3  nathanw 		crc = ether_crc32_be(enm->enm_addrlo, sizeof(enm->enm_addrlo));
   1404  1.8.2.3  nathanw 
   1405  1.8.2.1  nathanw 		/* Just want the 6 most significant bits. */
   1406  1.8.2.1  nathanw 		crc = (crc >> 2) & 0x3f;
   1407  1.8.2.1  nathanw 
   1408  1.8.2.1  nathanw 		/* Turn on the corresponding bit in the filter. */
   1409  1.8.2.1  nathanw 		af[crc >> 3] |= 1 << (crc & 0x7);
   1410  1.8.2.1  nathanw 
   1411  1.8.2.1  nathanw 		ETHER_NEXT_MULTI(step, enm);
   1412  1.8.2.1  nathanw 	}
   1413  1.8.2.1  nathanw 	ifp->if_flags &= ~IFF_ALLMULTI;
   1414  1.8.2.1  nathanw 
   1415  1.8.2.1  nathanw 	ea_select_buffer(sc, SEEQ_BUFCODE_MULTICAST);
   1416  1.8.2.1  nathanw 		for (i = 0; i < 8; ++i)
   1417  1.8.2.1  nathanw 			bus_space_write_1(sc->sc_iot, sc->sc_ioh,
   1418  1.8.2.1  nathanw 			    SEEQ_BUFWIN, af[i]);
   1419  1.8.2.1  nathanw }
   1420  1.8.2.1  nathanw 
   1421  1.8.2.1  nathanw static void
   1422  1.8.2.1  nathanw ea_mc_reset_8005(struct seeq8005_softc *sc)
   1423  1.8.2.1  nathanw {
   1424      1.5    bjh21 	struct ether_multi *enm;
   1425      1.5    bjh21 	struct ether_multistep step;
   1426      1.5    bjh21 	int naddr, maxaddrs;
   1427      1.5    bjh21 
   1428      1.5    bjh21 	naddr = 0;
   1429  1.8.2.1  nathanw 	maxaddrs = 5;
   1430      1.5    bjh21 	ETHER_FIRST_MULTI(step, &sc->sc_ethercom, enm);
   1431      1.5    bjh21 	while (enm != NULL) {
   1432      1.5    bjh21 		/* Have we got space? */
   1433      1.5    bjh21 		if (naddr >= maxaddrs ||
   1434  1.8.2.3  nathanw 		    memcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0) {
   1435      1.5    bjh21 			sc->sc_ethercom.ec_if.if_flags |= IFF_ALLMULTI;
   1436      1.5    bjh21 			ea_ioctl(&sc->sc_ethercom.ec_if, SIOCSIFFLAGS, NULL);
   1437      1.5    bjh21 			return;
   1438      1.5    bjh21 		}
   1439  1.8.2.1  nathanw 		ea_set_address(sc, 1 + naddr, enm->enm_addrlo);
   1440  1.8.2.1  nathanw 		sc->sc_config1 |= SEEQ_CFG1_STATION_ADDR1 << naddr;
   1441      1.5    bjh21 		naddr++;
   1442      1.5    bjh21 		ETHER_NEXT_MULTI(step, enm);
   1443      1.5    bjh21 	}
   1444      1.5    bjh21 	for (; naddr < maxaddrs; naddr++)
   1445  1.8.2.1  nathanw 		sc->sc_config1 &= ~(SEEQ_CFG1_STATION_ADDR1 << naddr);
   1446  1.8.2.3  nathanw 	SEEQ_WRITE16(sc, sc->sc_iot, sc->sc_ioh, SEEQ_CONFIG1,
   1447      1.5    bjh21 			  sc->sc_config1);
   1448      1.5    bjh21 }
   1449      1.5    bjh21 
   1450      1.1    bjh21 /*
   1451      1.1    bjh21  * Device timeout routine.
   1452      1.1    bjh21  */
   1453      1.1    bjh21 
   1454      1.1    bjh21 static void
   1455      1.1    bjh21 ea_watchdog(struct ifnet *ifp)
   1456      1.1    bjh21 {
   1457      1.1    bjh21 	struct seeq8005_softc *sc = ifp->if_softc;
   1458      1.1    bjh21 
   1459  1.8.2.1  nathanw 	log(LOG_ERR, "%s: lost Tx interrupt (status = 0x%04x)\n",
   1460  1.8.2.1  nathanw 	    sc->sc_dev.dv_xname,
   1461  1.8.2.3  nathanw 	    SEEQ_READ16(sc, sc->sc_iot, sc->sc_ioh, SEEQ_STATUS));
   1462      1.1    bjh21 	ifp->if_oerrors++;
   1463      1.1    bjh21 
   1464      1.1    bjh21 	/* Kick the interface */
   1465      1.1    bjh21 
   1466      1.5    bjh21 	ea_init(ifp);
   1467      1.1    bjh21 
   1468      1.1    bjh21 	ifp->if_timer = 0;
   1469      1.1    bjh21 }
   1470      1.1    bjh21 
   1471      1.1    bjh21 /* End of if_ea.c */
   1472