Home | History | Annotate | Line # | Download | only in qbus
if_de.c revision 1.2
      1  1.2  ragge /*	$NetBSD: if_de.c,v 1.2 2000/05/28 17:23:44 ragge Exp $	*/
      2  1.1  ragge /*
      3  1.1  ragge  * Copyright (c) 1982, 1986, 1989 Regents of the University of California.
      4  1.1  ragge  * Copyright (c) 2000 Ludd, University of Lule}, Sweden.
      5  1.1  ragge  * All rights reserved.
      6  1.1  ragge  *
      7  1.1  ragge  *
      8  1.1  ragge  * Redistribution and use in source and binary forms, with or without
      9  1.1  ragge  * modification, are permitted provided that the following conditions
     10  1.1  ragge  * are met:
     11  1.1  ragge  * 1. Redistributions of source code must retain the above copyright
     12  1.1  ragge  *    notice, this list of conditions and the following disclaimer.
     13  1.1  ragge  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  ragge  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  ragge  *    documentation and/or other materials provided with the distribution.
     16  1.1  ragge  * 3. All advertising materials mentioning features or use of this software
     17  1.1  ragge  *    must display the following acknowledgement:
     18  1.1  ragge  *	This product includes software developed by the University of
     19  1.1  ragge  *	California, Berkeley and its contributors.
     20  1.1  ragge  * 4. Neither the name of the University nor the names of its contributors
     21  1.1  ragge  *    may be used to endorse or promote products derived from this software
     22  1.1  ragge  *    without specific prior written permission.
     23  1.1  ragge  *
     24  1.1  ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.1  ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.1  ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.1  ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.1  ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.1  ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.1  ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.1  ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.1  ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.1  ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.1  ragge  * SUCH DAMAGE.
     35  1.1  ragge  *
     36  1.1  ragge  *	@(#)if_de.c	7.12 (Berkeley) 12/16/90
     37  1.1  ragge  */
     38  1.1  ragge 
     39  1.1  ragge /*
     40  1.1  ragge  * DEC DEUNA interface
     41  1.1  ragge  *
     42  1.1  ragge  *	Lou Salkind
     43  1.1  ragge  *	New York University
     44  1.1  ragge  *
     45  1.2  ragge  *	Rewritten by Ragge 30 April 2000 to match new world.
     46  1.1  ragge  *
     47  1.1  ragge  * TODO:
     48  1.1  ragge  *	timeout routine (get statistics)
     49  1.1  ragge  */
     50  1.1  ragge 
     51  1.1  ragge #include "opt_inet.h"
     52  1.1  ragge #include "opt_iso.h"
     53  1.2  ragge #include "bpfilter.h"
     54  1.1  ragge 
     55  1.1  ragge #include <sys/param.h>
     56  1.1  ragge #include <sys/systm.h>
     57  1.1  ragge #include <sys/mbuf.h>
     58  1.1  ragge #include <sys/buf.h>
     59  1.1  ragge #include <sys/protosw.h>
     60  1.1  ragge #include <sys/socket.h>
     61  1.1  ragge #include <sys/ioctl.h>
     62  1.1  ragge #include <sys/errno.h>
     63  1.1  ragge #include <sys/syslog.h>
     64  1.1  ragge #include <sys/device.h>
     65  1.1  ragge 
     66  1.1  ragge #include <net/if.h>
     67  1.1  ragge #include <net/if_ether.h>
     68  1.1  ragge #include <net/if_dl.h>
     69  1.1  ragge 
     70  1.1  ragge #ifdef INET
     71  1.1  ragge #include <netinet/in.h>
     72  1.1  ragge #include <netinet/if_inarp.h>
     73  1.1  ragge #endif
     74  1.1  ragge 
     75  1.2  ragge #if NBPFILTER > 0
     76  1.2  ragge #include <net/bpf.h>
     77  1.2  ragge #include <net/bpfdesc.h>
     78  1.1  ragge #endif
     79  1.1  ragge 
     80  1.1  ragge #include <machine/bus.h>
     81  1.1  ragge 
     82  1.1  ragge #include <dev/qbus/ubavar.h>
     83  1.1  ragge #include <dev/qbus/if_dereg.h>
     84  1.1  ragge 
     85  1.1  ragge #include "ioconf.h"
     86  1.1  ragge 
     87  1.1  ragge /*
     88  1.1  ragge  * Be careful with transmit/receive buffers, each entry steals 4 map
     89  1.1  ragge  * registers, and there is only 496 on one unibus...
     90  1.1  ragge  */
     91  1.1  ragge #define NRCV	10	/* number of receive buffers (must be > 1) */
     92  1.2  ragge #define NXMT	10	/* number of transmit buffers */
     93  1.1  ragge 
     94  1.1  ragge /*
     95  1.1  ragge  * Structure containing the elements that must be in DMA-safe memory.
     96  1.1  ragge  */
     97  1.1  ragge struct	de_cdata {
     98  1.1  ragge 	/* the following structures are always mapped in */
     99  1.1  ragge 	struct	de_pcbb dc_pcbb;	/* port control block */
    100  1.1  ragge 	struct	de_ring dc_xrent[NXMT]; /* transmit ring entrys */
    101  1.1  ragge 	struct	de_ring dc_rrent[NRCV]; /* receive ring entrys */
    102  1.1  ragge 	struct	de_udbbuf dc_udbbuf;	/* UNIBUS data buffer */
    103  1.2  ragge 	char	dc_xbuf[NXMT][ETHER_MAX_LEN];
    104  1.1  ragge 	/* end mapped area */
    105  1.1  ragge };
    106  1.1  ragge 
    107  1.1  ragge /*
    108  1.1  ragge  * Ethernet software status per interface.
    109  1.1  ragge  *
    110  1.1  ragge  * Each interface is referenced by a network interface structure,
    111  1.1  ragge  * ds_if, which the routing code uses to locate the interface.
    112  1.1  ragge  * This structure contains the output queue for the interface, its address, ...
    113  1.1  ragge  * We also have, for each interface, a UBA interface structure, which
    114  1.1  ragge  * contains information about the UNIBUS resources held by the interface:
    115  1.1  ragge  * map registers, buffered data paths, etc.  Information is cached in this
    116  1.1  ragge  * structure for use by the if_uba.c routines in running the interface
    117  1.1  ragge  * efficiently.
    118  1.1  ragge  */
    119  1.1  ragge struct	de_softc {
    120  1.1  ragge 	struct	device sc_dev;		/* Configuration common part */
    121  1.1  ragge 	struct	ethercom sc_ec;		/* Ethernet common part */
    122  1.1  ragge #define sc_if	sc_ec.ec_if		/* network-visible interface */
    123  1.1  ragge 	bus_space_tag_t sc_iot;
    124  1.1  ragge 	bus_addr_t sc_ioh;
    125  1.1  ragge 	bus_dma_tag_t sc_dmat;
    126  1.2  ragge 	bus_dmamap_t sc_cmap;
    127  1.1  ragge 	struct de_cdata *sc_dedata;	/* Control structure */
    128  1.1  ragge 	struct de_cdata *sc_pdedata;	/* Bus-mapped control structure */
    129  1.2  ragge #ifdef notdef
    130  1.2  ragge 	bus_dmamap_t sc_xmtmap[NXMT];	/* unibus xmit maps */
    131  1.1  ragge 	struct mbuf *sc_txmbuf[NXMT];
    132  1.2  ragge #endif
    133  1.2  ragge 	bus_dmamap_t sc_rcvmap[NRCV];	/* unibus receive maps */
    134  1.1  ragge 	struct mbuf *sc_rxmbuf[NRCV];
    135  1.2  ragge 	int sc_nexttx;			/* next tx descriptor to put data on */
    136  1.2  ragge 	int sc_nextrx;			/* next rx descriptor for recv */
    137  1.2  ragge 	int sc_inq;			/* # if xmit packets in queue */
    138  1.2  ragge 	int sc_lastack;			/* Last handled rx descriptor */
    139  1.2  ragge 	void *sc_sh;			/* shutdownhook cookie */
    140  1.1  ragge };
    141  1.1  ragge 
    142  1.1  ragge static	int dematch(struct device *, struct cfdata *, void *);
    143  1.1  ragge static	void deattach(struct device *, struct device *, void *);
    144  1.2  ragge static	void dewait(struct de_softc *, char *);
    145  1.1  ragge static	void deinit(struct de_softc *);
    146  1.1  ragge static	int deioctl(struct ifnet *, u_long, caddr_t);
    147  1.1  ragge static	void dereset(struct device *);
    148  1.1  ragge static	void destart(struct ifnet *);
    149  1.1  ragge static	void derecv(struct de_softc *);
    150  1.1  ragge static	void dexmit(struct de_softc *);
    151  1.1  ragge static	void deintr(void *);
    152  1.1  ragge static	int de_add_rxbuf(struct de_softc *, int);
    153  1.2  ragge static	void desetup(struct de_softc *sc);
    154  1.2  ragge static	void deshutdown(void *);
    155  1.1  ragge 
    156  1.1  ragge struct	cfattach de_ca = {
    157  1.1  ragge 	sizeof(struct de_softc), dematch, deattach
    158  1.1  ragge };
    159  1.1  ragge 
    160  1.1  ragge #define DE_WCSR(csr, val) \
    161  1.1  ragge 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, csr, val)
    162  1.1  ragge #define DE_WLOW(val) \
    163  1.1  ragge 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, DE_PCSR0, val)
    164  1.1  ragge #define DE_WHIGH(val) \
    165  1.1  ragge 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, DE_PCSR0 + 1, val)
    166  1.1  ragge #define DE_RCSR(csr) \
    167  1.1  ragge 	bus_space_read_2(sc->sc_iot, sc->sc_ioh, csr)
    168  1.1  ragge 
    169  1.1  ragge #define LOWORD(x)	((int)(x) & 0xffff)
    170  1.1  ragge #define HIWORD(x)	(((int)(x) >> 16) & 0x3)
    171  1.1  ragge /*
    172  1.1  ragge  * Interface exists: make available by filling in network interface
    173  1.1  ragge  * record.  System will initialize the interface when it is ready
    174  1.1  ragge  * to accept packets.  We get the ethernet address here.
    175  1.1  ragge  */
    176  1.1  ragge void
    177  1.1  ragge deattach(struct device *parent, struct device *self, void *aux)
    178  1.1  ragge {
    179  1.1  ragge 	struct uba_attach_args *ua = aux;
    180  1.1  ragge 	struct de_softc *sc = (struct de_softc *)self;
    181  1.1  ragge 	struct ifnet *ifp = &sc->sc_if;
    182  1.1  ragge 	u_int8_t myaddr[ETHER_ADDR_LEN];
    183  1.2  ragge 	int csr1, rseg, error, i;
    184  1.1  ragge 	bus_dma_segment_t seg;
    185  1.1  ragge 	char *c;
    186  1.1  ragge 
    187  1.1  ragge 	sc->sc_iot = ua->ua_iot;
    188  1.1  ragge 	sc->sc_ioh = ua->ua_ioh;
    189  1.1  ragge 	sc->sc_dmat = ua->ua_dmat;
    190  1.1  ragge 
    191  1.1  ragge 	/*
    192  1.1  ragge 	 * What kind of a board is this?
    193  1.1  ragge 	 * The error bits 4-6 in pcsr1 are a device id as long as
    194  1.1  ragge 	 * the high byte is zero.
    195  1.1  ragge 	 */
    196  1.1  ragge 	csr1 = DE_RCSR(DE_PCSR1);
    197  1.1  ragge 	if (csr1 & 0xff60)
    198  1.1  ragge 		c = "broken";
    199  1.1  ragge 	else if (csr1 & 0x10)
    200  1.1  ragge 		c = "delua";
    201  1.1  ragge 	else
    202  1.1  ragge 		c = "deuna";
    203  1.1  ragge 
    204  1.1  ragge 	/*
    205  1.1  ragge 	 * Reset the board and temporarily map
    206  1.1  ragge 	 * the pcbb buffer onto the Unibus.
    207  1.1  ragge 	 */
    208  1.1  ragge 	DE_WCSR(DE_PCSR0, 0);		/* reset INTE */
    209  1.1  ragge 	DELAY(100);
    210  1.1  ragge 	DE_WCSR(DE_PCSR0, PCSR0_RSET);
    211  1.2  ragge 	dewait(sc, "reset");
    212  1.1  ragge 
    213  1.1  ragge 	if ((error = bus_dmamem_alloc(sc->sc_dmat,
    214  1.1  ragge 	    sizeof(struct de_cdata), NBPG, 0, &seg, 1, &rseg,
    215  1.1  ragge 	    BUS_DMA_NOWAIT)) != 0) {
    216  1.1  ragge 		printf(": unable to allocate control data, error = %d\n",
    217  1.1  ragge 		    error);
    218  1.1  ragge 		goto fail_0;
    219  1.1  ragge 	}
    220  1.1  ragge 	if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,
    221  1.1  ragge 	    sizeof(struct de_cdata), (caddr_t *)&sc->sc_dedata,
    222  1.1  ragge 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
    223  1.1  ragge 		printf(": unable to map control data, error = %d\n", error);
    224  1.1  ragge 		goto fail_1;
    225  1.1  ragge 	}
    226  1.1  ragge 
    227  1.2  ragge 	if ((error = bus_dmamap_create(sc->sc_dmat, sizeof(struct de_cdata),
    228  1.2  ragge 	    1, sizeof(struct de_cdata), 0, BUS_DMA_NOWAIT,
    229  1.2  ragge 	    &sc->sc_cmap)) != 0) {
    230  1.2  ragge 		printf(": unable to create control data DMA map, error = %d\n",
    231  1.2  ragge 		    error);
    232  1.2  ragge 		goto fail_2;
    233  1.2  ragge 	}
    234  1.2  ragge 
    235  1.2  ragge 	if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cmap,
    236  1.2  ragge 	    sc->sc_dedata, sizeof(struct de_cdata), NULL,
    237  1.2  ragge 	    BUS_DMA_NOWAIT)) != 0) {
    238  1.2  ragge 		printf(": unable to load control data DMA map, error = %d\n",
    239  1.2  ragge 		    error);
    240  1.2  ragge 		goto fail_3;
    241  1.2  ragge 	}
    242  1.2  ragge 
    243  1.2  ragge 	bzero(sc->sc_dedata, sizeof(struct de_cdata));
    244  1.2  ragge 	sc->sc_pdedata = (struct de_cdata *)sc->sc_cmap->dm_segs[0].ds_addr;
    245  1.2  ragge 
    246  1.2  ragge #ifdef notdef
    247  1.1  ragge 	/*
    248  1.1  ragge 	 * Create the transmit descriptor DMA maps.
    249  1.1  ragge 	 *
    250  1.1  ragge 	 * XXX - should allocate transmit map pages when needed, not here.
    251  1.1  ragge 	 */
    252  1.1  ragge 	for (i = 0; i < NXMT; i++) {
    253  1.2  ragge 		if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
    254  1.1  ragge 		    MCLBYTES, 0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW,
    255  1.1  ragge 		    &sc->sc_xmtmap[i]))) {
    256  1.1  ragge 			printf(": unable to create tx DMA map %d, error = %d\n",
    257  1.1  ragge 			    i, error);
    258  1.1  ragge 			goto fail_4;
    259  1.1  ragge 		}
    260  1.1  ragge 	}
    261  1.2  ragge #endif
    262  1.1  ragge 
    263  1.1  ragge 	/*
    264  1.1  ragge 	 * Create receive buffer DMA maps.
    265  1.1  ragge 	 */
    266  1.1  ragge 	for (i = 0; i < NRCV; i++) {
    267  1.1  ragge 		if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
    268  1.2  ragge 		    MCLBYTES, 0, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW,
    269  1.1  ragge 		    &sc->sc_rcvmap[i]))) {
    270  1.1  ragge 			printf(": unable to create rx DMA map %d, error = %d\n",
    271  1.1  ragge 			    i, error);
    272  1.1  ragge 			goto fail_5;
    273  1.1  ragge 		}
    274  1.1  ragge 	}
    275  1.1  ragge 
    276  1.1  ragge 	/*
    277  1.1  ragge 	 * Pre-allocate the receive buffers.
    278  1.1  ragge 	 */
    279  1.1  ragge 	for (i = 0; i < NRCV; i++) {
    280  1.1  ragge 		if ((error = de_add_rxbuf(sc, i)) != 0) {
    281  1.1  ragge 			printf(": unable to allocate or map rx buffer %d\n,"
    282  1.1  ragge 			    " error = %d\n", i, error);
    283  1.1  ragge 			goto fail_6;
    284  1.1  ragge 		}
    285  1.1  ragge 	}
    286  1.1  ragge 
    287  1.1  ragge 	/*
    288  1.1  ragge 	 * Tell the DEUNA about our PCB
    289  1.1  ragge 	 */
    290  1.1  ragge 	DE_WCSR(DE_PCSR2, LOWORD(sc->sc_pdedata));
    291  1.1  ragge 	DE_WCSR(DE_PCSR3, HIWORD(sc->sc_pdedata));
    292  1.1  ragge 	DE_WLOW(CMD_GETPCBB);
    293  1.2  ragge 	dewait(sc, "pcbb");
    294  1.1  ragge 
    295  1.1  ragge 	sc->sc_dedata->dc_pcbb.pcbb0 = FC_RDPHYAD;
    296  1.1  ragge 	DE_WLOW(CMD_GETCMD);
    297  1.2  ragge 	dewait(sc, "read addr ");
    298  1.1  ragge 
    299  1.1  ragge 	bcopy((caddr_t)&sc->sc_dedata->dc_pcbb.pcbb2, myaddr, sizeof (myaddr));
    300  1.2  ragge 	printf("\n%s: %s, hardware address %s\n", sc->sc_dev.dv_xname, c,
    301  1.1  ragge 		ether_sprintf(myaddr));
    302  1.1  ragge 
    303  1.1  ragge 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec, deintr, sc);
    304  1.1  ragge 	uba_reset_establish(dereset, &sc->sc_dev);
    305  1.1  ragge 
    306  1.1  ragge 	strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
    307  1.1  ragge 	ifp->if_softc = sc;
    308  1.1  ragge 	ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX;
    309  1.1  ragge 	ifp->if_ioctl = deioctl;
    310  1.1  ragge 	ifp->if_start = destart;
    311  1.1  ragge 	if_attach(ifp);
    312  1.1  ragge 	ether_ifattach(ifp, myaddr);
    313  1.1  ragge #if NBPFILTER > 0
    314  1.1  ragge 	bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
    315  1.1  ragge #endif
    316  1.2  ragge 	sc->sc_sh = shutdownhook_establish(deshutdown, sc);
    317  1.1  ragge 	return;
    318  1.1  ragge 
    319  1.1  ragge 	/*
    320  1.1  ragge 	 * Free any resources we've allocated during the failed attach
    321  1.1  ragge 	 * attempt.  Do this in reverse order and fall through.
    322  1.1  ragge 	 */
    323  1.1  ragge fail_6:
    324  1.1  ragge 	for (i = 0; i < NRCV; i++) {
    325  1.1  ragge 		if (sc->sc_rxmbuf[i] != NULL) {
    326  1.2  ragge 			bus_dmamap_unload(sc->sc_dmat, sc->sc_rcvmap[i]);
    327  1.1  ragge 			m_freem(sc->sc_rxmbuf[i]);
    328  1.1  ragge 		}
    329  1.1  ragge 	}
    330  1.1  ragge fail_5:
    331  1.1  ragge 	for (i = 0; i < NRCV; i++) {
    332  1.2  ragge 		if (sc->sc_rcvmap[i] != NULL)
    333  1.2  ragge 			bus_dmamap_destroy(sc->sc_dmat, sc->sc_rcvmap[i]);
    334  1.1  ragge 	}
    335  1.2  ragge #ifdef notdef
    336  1.1  ragge fail_4:
    337  1.1  ragge 	for (i = 0; i < NXMT; i++) {
    338  1.2  ragge 		if (sc->sc_xmtmap[i] != NULL)
    339  1.2  ragge 			bus_dmamap_destroy(sc->sc_dmat, sc->sc_xmtmap[i]);
    340  1.1  ragge 	}
    341  1.2  ragge 	bus_dmamap_unload(sc->sc_dmat, sc->sc_cmap);
    342  1.2  ragge #endif
    343  1.2  ragge fail_3:
    344  1.2  ragge 	bus_dmamap_destroy(sc->sc_dmat, sc->sc_cmap);
    345  1.2  ragge fail_2:
    346  1.1  ragge 	bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->sc_dedata,
    347  1.1  ragge 	    sizeof(struct de_cdata));
    348  1.1  ragge fail_1:
    349  1.1  ragge 	bus_dmamem_free(sc->sc_dmat, &seg, rseg);
    350  1.1  ragge fail_0:
    351  1.1  ragge 	return;
    352  1.1  ragge }
    353  1.1  ragge 
    354  1.1  ragge /*
    355  1.1  ragge  * Reset of interface after UNIBUS reset.
    356  1.1  ragge  */
    357  1.1  ragge void
    358  1.1  ragge dereset(struct device *dev)
    359  1.1  ragge {
    360  1.1  ragge 	struct de_softc *sc = (void *)dev;
    361  1.1  ragge 
    362  1.1  ragge 	sc->sc_if.if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
    363  1.1  ragge 	DE_WCSR(DE_PCSR0, PCSR0_RSET);
    364  1.2  ragge 	dewait(sc, "reset");
    365  1.1  ragge 	deinit(sc);
    366  1.1  ragge }
    367  1.1  ragge 
    368  1.1  ragge /*
    369  1.1  ragge  * Initialization of interface; clear recorded pending
    370  1.1  ragge  * operations, and reinitialize UNIBUS usage.
    371  1.1  ragge  */
    372  1.1  ragge void
    373  1.1  ragge deinit(struct de_softc *sc)
    374  1.1  ragge {
    375  1.2  ragge 	struct de_cdata *dc, *pdc;
    376  1.1  ragge 	int s, i;
    377  1.1  ragge 
    378  1.2  ragge 	if (sc->sc_if.if_flags & IFF_RUNNING)
    379  1.1  ragge 		return;
    380  1.1  ragge 	/*
    381  1.1  ragge 	 * Tell the DEUNA about our PCB
    382  1.1  ragge 	 */
    383  1.1  ragge 	DE_WCSR(DE_PCSR2, LOWORD(sc->sc_pdedata));
    384  1.1  ragge 	DE_WCSR(DE_PCSR3, HIWORD(sc->sc_pdedata));
    385  1.1  ragge 	DE_WLOW(0);		/* reset INTE */
    386  1.1  ragge 	DELAY(500);
    387  1.1  ragge 	DE_WLOW(CMD_GETPCBB);
    388  1.2  ragge 	dewait(sc, "pcbb");
    389  1.1  ragge 
    390  1.1  ragge 	dc = sc->sc_dedata;
    391  1.2  ragge 	pdc = sc->sc_pdedata;
    392  1.1  ragge 	/* set the transmit and receive ring header addresses */
    393  1.1  ragge 	dc->dc_pcbb.pcbb0 = FC_WTRING;
    394  1.2  ragge 	dc->dc_pcbb.pcbb2 = LOWORD(&pdc->dc_udbbuf);
    395  1.2  ragge 	dc->dc_pcbb.pcbb4 = HIWORD(&pdc->dc_udbbuf);
    396  1.1  ragge 
    397  1.2  ragge 	dc->dc_udbbuf.b_tdrbl = LOWORD(&pdc->dc_xrent[0]);
    398  1.2  ragge 	dc->dc_udbbuf.b_tdrbh = HIWORD(&pdc->dc_xrent[0]);
    399  1.1  ragge 	dc->dc_udbbuf.b_telen = sizeof (struct de_ring) / sizeof(u_int16_t);
    400  1.1  ragge 	dc->dc_udbbuf.b_trlen = NXMT;
    401  1.2  ragge 	dc->dc_udbbuf.b_rdrbl = LOWORD(&pdc->dc_rrent[0]);
    402  1.2  ragge 	dc->dc_udbbuf.b_rdrbh = HIWORD(&pdc->dc_rrent[0]);
    403  1.1  ragge 	dc->dc_udbbuf.b_relen = sizeof (struct de_ring) / sizeof(u_int16_t);
    404  1.1  ragge 	dc->dc_udbbuf.b_rrlen = NRCV;
    405  1.1  ragge 
    406  1.1  ragge 	DE_WLOW(CMD_GETCMD);
    407  1.2  ragge 	dewait(sc, "wtring");
    408  1.1  ragge 
    409  1.2  ragge 	desetup(sc);
    410  1.1  ragge 
    411  1.2  ragge 	/* Link the transmit buffers to the descriptors */
    412  1.1  ragge 	for (i = 0; i < NXMT; i++) {
    413  1.1  ragge 		dc->dc_xrent[i].r_flags = 0;
    414  1.2  ragge 		dc->dc_xrent[i].r_segbl = LOWORD(&pdc->dc_xbuf[i][0]);
    415  1.2  ragge 		dc->dc_xrent[i].r_segbh = HIWORD(&pdc->dc_xbuf[i][0]);
    416  1.1  ragge 	}
    417  1.2  ragge 
    418  1.1  ragge 	for (i = 0; i < NRCV; i++)
    419  1.1  ragge 		dc->dc_rrent[i].r_flags = RFLG_OWN;
    420  1.1  ragge 	sc->sc_nexttx = sc->sc_inq = sc->sc_lastack = sc->sc_nextrx = 0;
    421  1.1  ragge 
    422  1.1  ragge 	/* start up the board (rah rah) */
    423  1.1  ragge 	s = splnet();
    424  1.1  ragge 	sc->sc_if.if_flags |= IFF_RUNNING;
    425  1.2  ragge 	DE_WLOW(PCSR0_INTE);		/* Change to interrupts */
    426  1.2  ragge 	DELAY(500);
    427  1.1  ragge 	DE_WLOW(CMD_START|PCSR0_INTE);
    428  1.2  ragge 	dewait(sc, "start");
    429  1.2  ragge 	DE_WLOW(CMD_PDMD|PCSR0_INTE);
    430  1.2  ragge 	dewait(sc, "initpoll");
    431  1.1  ragge 	splx(s);
    432  1.1  ragge }
    433  1.1  ragge 
    434  1.1  ragge /*
    435  1.1  ragge  * Setup output on interface.
    436  1.1  ragge  * Get another datagram to send off of the interface queue,
    437  1.1  ragge  * and map it to the interface before starting the output.
    438  1.1  ragge  * Must be called from ipl >= our interrupt level.
    439  1.1  ragge  */
    440  1.1  ragge void
    441  1.1  ragge destart(struct ifnet *ifp)
    442  1.1  ragge {
    443  1.1  ragge 	struct de_softc *sc = ifp->if_softc;
    444  1.2  ragge 	struct de_cdata *dc;
    445  1.2  ragge 	struct mbuf *m;
    446  1.2  ragge 	int idx, s, running;
    447  1.1  ragge 
    448  1.1  ragge 	/*
    449  1.1  ragge 	 * the following test is necessary, since
    450  1.1  ragge 	 * the code is not reentrant and we have
    451  1.1  ragge 	 * multiple transmission buffers.
    452  1.1  ragge 	 */
    453  1.2  ragge 	if (ifp->if_flags & IFF_OACTIVE) /* Too much to do already */
    454  1.1  ragge 		return;
    455  1.2  ragge 
    456  1.2  ragge 	if (ifp->if_snd.ifq_head == 0)	 /* Nothing to do at all */
    457  1.2  ragge 		return;
    458  1.2  ragge 
    459  1.1  ragge 	s = splimp();
    460  1.2  ragge 	dc = sc->sc_dedata;
    461  1.2  ragge 	running = (sc->sc_inq != 0);
    462  1.1  ragge 	while (sc->sc_inq < (NXMT - 1)) {
    463  1.2  ragge 
    464  1.1  ragge 		idx = sc->sc_nexttx;
    465  1.1  ragge 		IF_DEQUEUE(&ifp->if_snd, m);
    466  1.1  ragge 		if (m == 0)
    467  1.1  ragge 			goto out;
    468  1.1  ragge 
    469  1.1  ragge #if NBPFILTER > 0
    470  1.1  ragge 		if (ifp->if_bpf)
    471  1.1  ragge 			bpf_mtap(ifp->if_bpf, m);
    472  1.1  ragge #endif
    473  1.2  ragge 		m_copydata(m, 0, m->m_pkthdr.len, &dc->dc_xbuf[idx][0]);
    474  1.2  ragge 		dc->dc_xrent[idx].r_slen = m->m_pkthdr.len;
    475  1.2  ragge 		dc->dc_xrent[idx].r_tdrerr = 0;
    476  1.2  ragge 		dc->dc_xrent[idx].r_flags = XFLG_STP|XFLG_ENP|XFLG_OWN;
    477  1.2  ragge 		m_freem(m);
    478  1.2  ragge 
    479  1.2  ragge 		sc->sc_inq++;
    480  1.2  ragge 		if (++sc->sc_nexttx == NXMT)
    481  1.2  ragge 			sc->sc_nexttx = 0;
    482  1.2  ragge 		ifp->if_timer = 5; /* If transmit logic dies */
    483  1.1  ragge 	}
    484  1.1  ragge 	if (sc->sc_inq == (NXMT - 1))
    485  1.1  ragge 		ifp->if_flags |= IFF_OACTIVE;
    486  1.1  ragge 
    487  1.2  ragge out:	if (running == 0) {
    488  1.2  ragge 		DE_WLOW(PCSR0_INTE|CMD_PDMD);
    489  1.2  ragge 		dewait(sc, "poll");
    490  1.2  ragge 	}
    491  1.1  ragge 
    492  1.1  ragge 	splx(s);
    493  1.1  ragge }
    494  1.1  ragge 
    495  1.1  ragge /*
    496  1.1  ragge  * Command done interrupt.
    497  1.1  ragge  */
    498  1.1  ragge void
    499  1.1  ragge deintr(void *arg)
    500  1.1  ragge {
    501  1.1  ragge 	struct de_softc *sc = arg;
    502  1.2  ragge 	short csr0, csr1;
    503  1.1  ragge 
    504  1.1  ragge 	/* save flags right away - clear out interrupt bits */
    505  1.1  ragge 	csr0 = DE_RCSR(DE_PCSR0);
    506  1.2  ragge 	csr1 = DE_RCSR(DE_PCSR1);
    507  1.1  ragge 	DE_WHIGH(csr0 >> 8);
    508  1.1  ragge 
    509  1.1  ragge 	if (csr0 & PCSR0_RXI)
    510  1.1  ragge 		derecv(sc);
    511  1.1  ragge 
    512  1.1  ragge 	if (csr0 & PCSR0_TXI)
    513  1.1  ragge 		dexmit(sc);
    514  1.1  ragge 
    515  1.2  ragge 	/* Should never end up here */
    516  1.2  ragge 	if (csr0 & PCSR0_PCEI) {
    517  1.2  ragge 		printf("%s: Port command error interrupt\n",
    518  1.2  ragge 		    sc->sc_dev.dv_xname);
    519  1.2  ragge 	}
    520  1.2  ragge 
    521  1.2  ragge 	if (csr0 & PCSR0_SERI) {
    522  1.2  ragge 		printf("%s: Status error interrupt\n", sc->sc_dev.dv_xname);
    523  1.2  ragge 	}
    524  1.2  ragge 
    525  1.2  ragge 	if (csr0 & PCSR0_RCBI) {
    526  1.2  ragge 		printf("%s: Receive buffer unavail interrupt\n",
    527  1.2  ragge 		    sc->sc_dev.dv_xname);
    528  1.2  ragge 		DE_WLOW(PCSR0_INTE|CMD_PDMD);
    529  1.2  ragge 		dewait(sc, "repoll");
    530  1.2  ragge 	}
    531  1.1  ragge 	destart(&sc->sc_if);
    532  1.1  ragge }
    533  1.1  ragge 
    534  1.1  ragge void
    535  1.1  ragge dexmit(struct de_softc *sc)
    536  1.1  ragge {
    537  1.1  ragge 	struct ifnet *ifp = &sc->sc_if;
    538  1.1  ragge 	struct de_ring *rp;
    539  1.1  ragge 
    540  1.1  ragge 	/*
    541  1.1  ragge 	 * Poll transmit ring and check status.
    542  1.1  ragge 	 * Then free buffer space and check for
    543  1.1  ragge 	 * more transmit requests.
    544  1.1  ragge 	 */
    545  1.1  ragge 	rp = &sc->sc_dedata->dc_xrent[sc->sc_lastack];
    546  1.1  ragge 	while ((rp->r_flags & XFLG_OWN) == 0) {
    547  1.2  ragge 		int idx = sc->sc_lastack;
    548  1.2  ragge 
    549  1.2  ragge 		if (idx == sc->sc_nexttx)
    550  1.2  ragge 			break;
    551  1.2  ragge 		if (rp->r_flags & XFLG_ENP)
    552  1.1  ragge 			ifp->if_opackets++;
    553  1.1  ragge 		if (rp->r_flags & (XFLG_ERRS|XFLG_MTCH|XFLG_ONE|XFLG_MORE)) {
    554  1.1  ragge 			if (rp->r_flags & XFLG_ERRS) {
    555  1.1  ragge 				ifp->if_oerrors++;
    556  1.1  ragge 			} else if (rp->r_flags & XFLG_ONE) {
    557  1.1  ragge 				ifp->if_collisions++;
    558  1.1  ragge 			} else if (rp->r_flags & XFLG_MORE) {
    559  1.1  ragge 				ifp->if_collisions += 3;
    560  1.1  ragge 			}
    561  1.1  ragge 			/* else if (rp->r_flags & XFLG_MTCH)
    562  1.1  ragge 			 * Matches ourself, but why care?
    563  1.1  ragge 			 * Let upper layer deal with this.
    564  1.1  ragge 			 */
    565  1.1  ragge 		}
    566  1.1  ragge 		if (++sc->sc_lastack == NXMT)
    567  1.1  ragge 			sc->sc_lastack = 0;
    568  1.1  ragge 		sc->sc_inq--;
    569  1.1  ragge 		rp = &sc->sc_dedata->dc_xrent[sc->sc_lastack];
    570  1.1  ragge 	}
    571  1.1  ragge 	ifp->if_flags &= ~IFF_OACTIVE;
    572  1.1  ragge 	if (sc->sc_inq == 0)
    573  1.1  ragge 		ifp->if_timer = 0;
    574  1.1  ragge }
    575  1.1  ragge 
    576  1.1  ragge /*
    577  1.1  ragge  * Ethernet interface receiver interface.
    578  1.1  ragge  * If input error just drop packet.
    579  1.1  ragge  * Otherwise purge input buffered data path and examine
    580  1.1  ragge  * packet to determine type.  If can't determine length
    581  1.1  ragge  * from type, then have to drop packet.	 Othewise decapsulate
    582  1.1  ragge  * packet based on type and pass to type specific higher-level
    583  1.1  ragge  * input routine.
    584  1.1  ragge  */
    585  1.1  ragge void
    586  1.1  ragge derecv(struct de_softc *sc)
    587  1.1  ragge {
    588  1.1  ragge 	struct ifnet *ifp = &sc->sc_if;
    589  1.1  ragge 	struct de_ring *rp;
    590  1.1  ragge 	struct mbuf *m;
    591  1.1  ragge 	int len;
    592  1.1  ragge 
    593  1.1  ragge 	rp = &sc->sc_dedata->dc_rrent[sc->sc_nextrx];
    594  1.1  ragge 	while ((rp->r_flags & RFLG_OWN) == 0) {
    595  1.1  ragge 		ifp->if_ipackets++;
    596  1.1  ragge 		/* check for errors */
    597  1.1  ragge 		if ((rp->r_flags & (RFLG_ERRS|RFLG_FRAM|RFLG_OFLO|RFLG_CRC)) ||
    598  1.1  ragge 		    (rp->r_flags&(RFLG_STP|RFLG_ENP)) != (RFLG_STP|RFLG_ENP) ||
    599  1.2  ragge 		    (rp->r_lenerr & (RERR_BUFL|RERR_UBTO))) {
    600  1.1  ragge 			ifp->if_ierrors++;
    601  1.1  ragge 			goto next;
    602  1.1  ragge 		}
    603  1.1  ragge 		m = sc->sc_rxmbuf[sc->sc_nextrx];
    604  1.2  ragge 		len = (rp->r_lenerr&RERR_MLEN) - ETHER_CRC_LEN;
    605  1.1  ragge 		de_add_rxbuf(sc, sc->sc_nextrx);
    606  1.1  ragge 		m->m_pkthdr.rcvif = ifp;
    607  1.1  ragge 		m->m_pkthdr.len = m->m_len = len;
    608  1.2  ragge 
    609  1.1  ragge #if NBPFILTER > 0
    610  1.1  ragge 		if (ifp->if_bpf) {
    611  1.2  ragge 			struct ether_header *eh;
    612  1.2  ragge 
    613  1.2  ragge 			eh = mtod(m, struct ether_header *);
    614  1.1  ragge 			bpf_mtap(ifp->if_bpf, m);
    615  1.1  ragge 			if ((ifp->if_flags & IFF_PROMISC) != 0 &&
    616  1.1  ragge 			    bcmp(LLADDR(ifp->if_sadl), eh->ether_dhost,
    617  1.1  ragge 			    ETHER_ADDR_LEN) != 0 &&
    618  1.2  ragge 			    (ETHER_IS_MULTICAST(eh->ether_dhost) == 0)) {
    619  1.1  ragge 				m_freem(m);
    620  1.1  ragge 				goto next;
    621  1.1  ragge 			}
    622  1.1  ragge 		}
    623  1.1  ragge #endif
    624  1.1  ragge 		(*ifp->if_input)(ifp, m);
    625  1.1  ragge 
    626  1.1  ragge 		/* hang the receive buffer again */
    627  1.1  ragge next:		rp->r_lenerr = 0;
    628  1.1  ragge 		rp->r_flags = RFLG_OWN;
    629  1.1  ragge 
    630  1.1  ragge 		/* check next receive buffer */
    631  1.1  ragge 		if (++sc->sc_nextrx == NRCV)
    632  1.1  ragge 			sc->sc_nextrx = 0;
    633  1.1  ragge 		rp = &sc->sc_dedata->dc_rrent[sc->sc_nextrx];
    634  1.1  ragge 	}
    635  1.1  ragge }
    636  1.1  ragge 
    637  1.1  ragge /*
    638  1.1  ragge  * Add a receive buffer to the indicated descriptor.
    639  1.1  ragge  */
    640  1.1  ragge int
    641  1.1  ragge de_add_rxbuf(sc, i)
    642  1.1  ragge 	struct de_softc *sc;
    643  1.1  ragge 	int i;
    644  1.1  ragge {
    645  1.1  ragge 	struct mbuf *m;
    646  1.1  ragge 	struct de_ring *rp;
    647  1.1  ragge 	vaddr_t addr;
    648  1.1  ragge 	int error;
    649  1.1  ragge 
    650  1.1  ragge 	MGETHDR(m, M_DONTWAIT, MT_DATA);
    651  1.1  ragge 	if (m == NULL)
    652  1.1  ragge 		return (ENOBUFS);
    653  1.1  ragge 
    654  1.1  ragge 	MCLGET(m, M_DONTWAIT);
    655  1.1  ragge 	if ((m->m_flags & M_EXT) == 0) {
    656  1.1  ragge 		m_freem(m);
    657  1.1  ragge 		return (ENOBUFS);
    658  1.1  ragge 	}
    659  1.1  ragge 
    660  1.1  ragge 	if (sc->sc_rxmbuf[i] != NULL)
    661  1.1  ragge 		bus_dmamap_unload(sc->sc_dmat, sc->sc_rcvmap[i]);
    662  1.1  ragge 
    663  1.1  ragge 	error = bus_dmamap_load(sc->sc_dmat, sc->sc_rcvmap[i],
    664  1.1  ragge 	    m->m_ext.ext_buf, m->m_ext.ext_size, NULL, BUS_DMA_NOWAIT);
    665  1.1  ragge 	if (error)
    666  1.1  ragge 		panic("%s: can't load rx DMA map %d, error = %d\n",
    667  1.1  ragge 		    sc->sc_dev.dv_xname, i, error);
    668  1.1  ragge 	sc->sc_rxmbuf[i] = m;
    669  1.1  ragge 
    670  1.1  ragge 	bus_dmamap_sync(sc->sc_dmat, sc->sc_rcvmap[i], 0,
    671  1.1  ragge 	    sc->sc_rcvmap[i]->dm_mapsize, BUS_DMASYNC_PREREAD);
    672  1.1  ragge 
    673  1.1  ragge 	/*
    674  1.1  ragge 	 * We know that the mbuf cluster is page aligned. Also, be sure
    675  1.1  ragge 	 * that the IP header will be longword aligned.
    676  1.1  ragge 	 */
    677  1.1  ragge 	m->m_data += 2;
    678  1.1  ragge 	addr = sc->sc_rcvmap[i]->dm_segs[0].ds_addr + 2;
    679  1.1  ragge 	rp = &sc->sc_dedata->dc_rrent[i];
    680  1.1  ragge 	rp->r_lenerr = 0;
    681  1.1  ragge 	rp->r_segbl = LOWORD(addr);
    682  1.1  ragge 	rp->r_segbh = HIWORD(addr);
    683  1.1  ragge 	rp->r_slen = m->m_ext.ext_size - 2;
    684  1.1  ragge 	rp->r_flags = RFLG_OWN;
    685  1.1  ragge 
    686  1.1  ragge 	return (0);
    687  1.1  ragge }
    688  1.1  ragge 
    689  1.1  ragge 
    690  1.1  ragge /*
    691  1.1  ragge  * Process an ioctl request.
    692  1.1  ragge  */
    693  1.1  ragge int
    694  1.1  ragge deioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
    695  1.1  ragge {
    696  1.1  ragge 	struct ifaddr *ifa = (struct ifaddr *)data;
    697  1.2  ragge 	struct ifreq *ifr = (struct ifreq *)data;
    698  1.1  ragge 	struct de_softc *sc = ifp->if_softc;
    699  1.1  ragge 	int s = splnet(), error = 0;
    700  1.1  ragge 
    701  1.1  ragge 	switch (cmd) {
    702  1.1  ragge 
    703  1.1  ragge 	case SIOCSIFADDR:
    704  1.1  ragge 		ifp->if_flags |= IFF_UP;
    705  1.1  ragge 		switch (ifa->ifa_addr->sa_family) {
    706  1.1  ragge #ifdef INET
    707  1.1  ragge 		case AF_INET:
    708  1.2  ragge 			deinit(sc);
    709  1.1  ragge 			arp_ifinit(ifp, ifa);
    710  1.1  ragge 			break;
    711  1.1  ragge #endif
    712  1.1  ragge 		}
    713  1.1  ragge 		break;
    714  1.1  ragge 
    715  1.1  ragge 	case SIOCSIFFLAGS:
    716  1.1  ragge 		if ((ifp->if_flags & IFF_UP) == 0 &&
    717  1.2  ragge 		    (ifp->if_flags & IFF_RUNNING) != 0) {
    718  1.2  ragge 			/*
    719  1.2  ragge 			 * If interface is marked down and it is running,
    720  1.2  ragge 			 * stop it.
    721  1.2  ragge 			 */
    722  1.2  ragge 			ifp->if_flags &= ~(IFF_RUNNING|IFF_OACTIVE);
    723  1.2  ragge 			DE_WCSR(DE_PCSR0, PCSR0_RSET);
    724  1.2  ragge 			dewait(sc, "down");
    725  1.2  ragge 		} else if ((ifp->if_flags & IFF_UP) != 0 &&
    726  1.2  ragge 			   (ifp->if_flags & IFF_RUNNING) == 0) {
    727  1.2  ragge 			/*
    728  1.2  ragge 			 * If interface it marked up and it is stopped, then
    729  1.2  ragge 			 * start it.
    730  1.2  ragge 			 */
    731  1.1  ragge 			deinit(sc);
    732  1.2  ragge 		} else if ((ifp->if_flags & IFF_UP) != 0) {
    733  1.2  ragge 			/*
    734  1.2  ragge 			 * Send a new setup packet to match any new changes.
    735  1.2  ragge 			 * (Like IFF_PROMISC etc)
    736  1.2  ragge 			 */
    737  1.2  ragge 			desetup(sc);
    738  1.2  ragge 		}
    739  1.2  ragge 		break;
    740  1.2  ragge 
    741  1.2  ragge 	case SIOCADDMULTI:
    742  1.2  ragge 	case SIOCDELMULTI:
    743  1.2  ragge 		/*
    744  1.2  ragge 		 * Update our multicast list.
    745  1.2  ragge 		 */
    746  1.2  ragge 		error = (cmd == SIOCADDMULTI) ?
    747  1.2  ragge 			ether_addmulti(ifr, &sc->sc_ec):
    748  1.2  ragge 			ether_delmulti(ifr, &sc->sc_ec);
    749  1.2  ragge 
    750  1.2  ragge 		if (error == ENETRESET) {
    751  1.2  ragge 			/*
    752  1.2  ragge 			 * Multicast list has changed; set the hardware filter
    753  1.2  ragge 			 * accordingly.
    754  1.2  ragge 			 */
    755  1.2  ragge 			desetup(sc);
    756  1.2  ragge 			error = 0;
    757  1.2  ragge 		}
    758  1.1  ragge 		break;
    759  1.1  ragge 
    760  1.1  ragge 	default:
    761  1.1  ragge 		error = EINVAL;
    762  1.1  ragge 	}
    763  1.1  ragge 	splx(s);
    764  1.1  ragge 	return (error);
    765  1.1  ragge }
    766  1.1  ragge 
    767  1.1  ragge /*
    768  1.1  ragge  * Await completion of the named function
    769  1.1  ragge  * and check for errors.
    770  1.1  ragge  */
    771  1.2  ragge void
    772  1.1  ragge dewait(struct de_softc *sc, char *fn)
    773  1.1  ragge {
    774  1.2  ragge 	int csr0, s;
    775  1.1  ragge 
    776  1.2  ragge 	s = splimp();
    777  1.1  ragge 	while ((DE_RCSR(DE_PCSR0) & PCSR0_INTR) == 0)
    778  1.1  ragge 		;
    779  1.1  ragge 	csr0 = DE_RCSR(DE_PCSR0);
    780  1.1  ragge 	DE_WHIGH(csr0 >> 8);
    781  1.1  ragge 	if (csr0 & PCSR0_PCEI) {
    782  1.1  ragge 		char bits[64];
    783  1.1  ragge 
    784  1.1  ragge 		printf("%s: %s failed, csr0=%s ", sc->sc_dev.dv_xname, fn,
    785  1.1  ragge 		    bitmask_snprintf(csr0, PCSR0_BITS, bits, sizeof(bits)));
    786  1.1  ragge 		printf("csr1=%s\n", bitmask_snprintf(DE_RCSR(DE_PCSR1),
    787  1.1  ragge 		    PCSR1_BITS, bits, sizeof(bits)));
    788  1.1  ragge 	}
    789  1.2  ragge 	splx(s);
    790  1.2  ragge }
    791  1.2  ragge 
    792  1.2  ragge /*
    793  1.2  ragge  * Changes multicast filter list/promiscous modes etc...
    794  1.2  ragge  */
    795  1.2  ragge void
    796  1.2  ragge desetup(struct de_softc *sc)
    797  1.2  ragge {
    798  1.2  ragge 	short mode, intr;
    799  1.2  ragge 
    800  1.2  ragge 	/*
    801  1.2  ragge 	 * XXX - so far use ALLMULTI to receive multicast packets.
    802  1.2  ragge 	 */
    803  1.2  ragge 	sc->sc_if.if_flags &= ~IFF_ALLMULTI;
    804  1.2  ragge 	if (sc->sc_ec.ec_multiaddrs.lh_first)
    805  1.2  ragge 		sc->sc_if.if_flags |= IFF_ALLMULTI;
    806  1.2  ragge 
    807  1.2  ragge 	mode = MOD_TPAD|MOD_HDX|MOD_DRDC;
    808  1.2  ragge 	if (sc->sc_if.if_flags & IFF_PROMISC)
    809  1.2  ragge 		mode |= MOD_PROM;
    810  1.2  ragge 	else if (sc->sc_if.if_flags & IFF_ALLMULTI)
    811  1.2  ragge 		mode |= MOD_ENAL;
    812  1.2  ragge 
    813  1.2  ragge 	sc->sc_dedata->dc_pcbb.pcbb0 = FC_WTMODE;
    814  1.2  ragge 	sc->sc_dedata->dc_pcbb.pcbb2 = mode;
    815  1.2  ragge 	intr = DE_RCSR(DE_PCSR0) & PCSR0_INTE;
    816  1.2  ragge 	DE_WLOW(CMD_GETCMD | intr);
    817  1.2  ragge 	dewait(sc, "wtmode");
    818  1.1  ragge }
    819  1.1  ragge 
    820  1.1  ragge int
    821  1.1  ragge dematch(struct device *parent, struct cfdata *cf, void *aux)
    822  1.1  ragge {
    823  1.1  ragge 	struct uba_attach_args *ua = aux;
    824  1.1  ragge 	struct de_softc ssc;
    825  1.1  ragge 	struct de_softc *sc = &ssc;
    826  1.1  ragge 	int i;
    827  1.1  ragge 
    828  1.1  ragge 	sc->sc_iot = ua->ua_iot;
    829  1.1  ragge 	sc->sc_ioh = ua->ua_ioh;
    830  1.1  ragge 	/*
    831  1.1  ragge 	 * Make sure self-test is finished before we screw with the board.
    832  1.1  ragge 	 * Self-test on a DELUA can take 15 seconds (argh).
    833  1.1  ragge 	 */
    834  1.1  ragge 	for (i = 0;
    835  1.1  ragge 	    (i < 160) &&
    836  1.1  ragge 	    (DE_RCSR(DE_PCSR0) & PCSR0_FATI) == 0 &&
    837  1.1  ragge 	    (DE_RCSR(DE_PCSR1) & PCSR1_STMASK) == STAT_RESET;
    838  1.1  ragge 	    ++i)
    839  1.1  ragge 		DELAY(50000);
    840  1.1  ragge 	if (((DE_RCSR(DE_PCSR0) & PCSR0_FATI) != 0) ||
    841  1.1  ragge 	    (((DE_RCSR(DE_PCSR1) & PCSR1_STMASK) != STAT_READY) &&
    842  1.1  ragge 	    ((DE_RCSR(DE_PCSR1) & PCSR1_STMASK) != STAT_RUN)))
    843  1.1  ragge 		return(0);
    844  1.1  ragge 
    845  1.1  ragge 	DE_WCSR(DE_PCSR0, 0);
    846  1.1  ragge 	DELAY(5000);
    847  1.1  ragge 	DE_WCSR(DE_PCSR0, PCSR0_RSET);
    848  1.1  ragge 	while ((DE_RCSR(DE_PCSR0) & PCSR0_INTR) == 0)
    849  1.1  ragge 		;
    850  1.1  ragge 	/* make board interrupt by executing a GETPCBB command */
    851  1.1  ragge 	DE_WCSR(DE_PCSR0, PCSR0_INTE);
    852  1.1  ragge 	DE_WCSR(DE_PCSR2, 0);
    853  1.1  ragge 	DE_WCSR(DE_PCSR3, 0);
    854  1.1  ragge 	DE_WCSR(DE_PCSR0, PCSR0_INTE|CMD_GETPCBB);
    855  1.1  ragge 	DELAY(50000);
    856  1.1  ragge 
    857  1.1  ragge 	return 1;
    858  1.1  ragge }
    859  1.2  ragge 
    860  1.2  ragge void
    861  1.2  ragge deshutdown(void *arg)
    862  1.2  ragge {
    863  1.2  ragge 	struct de_softc *sc = arg;
    864  1.2  ragge 
    865  1.2  ragge 	DE_WCSR(DE_PCSR0, PCSR0_RSET);
    866  1.2  ragge 	dewait(sc, "shutdown");
    867  1.2  ragge }
    868  1.2  ragge 
    869