Home | History | Annotate | Line # | Download | only in ic
elinkxl.c revision 1.15.4.1
      1  1.15.4.1      fvdl /*	$NetBSD: elinkxl.c,v 1.15.4.1 1999/11/15 00:40:32 fvdl Exp $	*/
      2       1.1      fvdl 
      3       1.1      fvdl /*-
      4       1.1      fvdl  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.1      fvdl  * All rights reserved.
      6       1.1      fvdl  *
      7       1.1      fvdl  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      fvdl  * by Frank van der Linden.
      9       1.1      fvdl  *
     10       1.1      fvdl  * Redistribution and use in source and binary forms, with or without
     11       1.1      fvdl  * modification, are permitted provided that the following conditions
     12       1.1      fvdl  * are met:
     13       1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     14       1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     15       1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     18       1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     19       1.1      fvdl  *    must display the following acknowledgement:
     20       1.1      fvdl  *	This product includes software developed by the NetBSD
     21       1.1      fvdl  *	Foundation, Inc. and its contributors.
     22       1.1      fvdl  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1      fvdl  *    contributors may be used to endorse or promote products derived
     24       1.1      fvdl  *    from this software without specific prior written permission.
     25       1.1      fvdl  *
     26       1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1      fvdl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1      fvdl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1      fvdl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1      fvdl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1      fvdl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1      fvdl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1      fvdl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1      fvdl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1      fvdl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1      fvdl  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1      fvdl  */
     38       1.1      fvdl 
     39       1.1      fvdl #include "opt_inet.h"
     40       1.1      fvdl #include "opt_ns.h"
     41       1.1      fvdl #include "bpfilter.h"
     42       1.1      fvdl #include "rnd.h"
     43       1.1      fvdl 
     44       1.1      fvdl #include <sys/param.h>
     45       1.1      fvdl #include <sys/systm.h>
     46       1.1      fvdl #include <sys/kernel.h>
     47       1.1      fvdl #include <sys/mbuf.h>
     48       1.1      fvdl #include <sys/socket.h>
     49       1.1      fvdl #include <sys/ioctl.h>
     50       1.1      fvdl #include <sys/errno.h>
     51       1.1      fvdl #include <sys/syslog.h>
     52       1.1      fvdl #include <sys/select.h>
     53       1.1      fvdl #include <sys/device.h>
     54       1.1      fvdl #if NRND > 0
     55       1.1      fvdl #include <sys/rnd.h>
     56       1.1      fvdl #endif
     57       1.1      fvdl 
     58       1.1      fvdl #include <net/if.h>
     59       1.1      fvdl #include <net/if_dl.h>
     60       1.1      fvdl #include <net/if_ether.h>
     61       1.1      fvdl #include <net/if_media.h>
     62       1.1      fvdl 
     63       1.1      fvdl #ifdef INET
     64       1.1      fvdl #include <netinet/in.h>
     65       1.1      fvdl #include <netinet/in_systm.h>
     66       1.1      fvdl #include <netinet/in_var.h>
     67       1.1      fvdl #include <netinet/ip.h>
     68       1.1      fvdl #include <netinet/if_inarp.h>
     69       1.1      fvdl #endif
     70       1.1      fvdl 
     71       1.1      fvdl #ifdef NS
     72       1.1      fvdl #include <netns/ns.h>
     73       1.1      fvdl #include <netns/ns_if.h>
     74       1.1      fvdl #endif
     75       1.1      fvdl 
     76       1.1      fvdl #if NBPFILTER > 0
     77       1.1      fvdl #include <net/bpf.h>
     78       1.1      fvdl #include <net/bpfdesc.h>
     79       1.1      fvdl #endif
     80       1.1      fvdl 
     81       1.1      fvdl #include <machine/cpu.h>
     82       1.1      fvdl #include <machine/bus.h>
     83       1.1      fvdl #include <machine/intr.h>
     84       1.1      fvdl 
     85       1.9   thorpej #if BYTE_ORDER == BIG_ENDIAN
     86       1.9   thorpej #include <machine/bswap.h>
     87       1.9   thorpej #define	htopci(x)	bswap32(x)
     88       1.9   thorpej #define	pcitoh(x)	bswap32(x)
     89       1.9   thorpej #else
     90       1.9   thorpej #define	htopci(x)	(x)
     91       1.9   thorpej #define	pcitoh(x)	(x)
     92       1.9   thorpej #endif
     93       1.9   thorpej 
     94       1.1      fvdl #include <vm/vm.h>
     95       1.1      fvdl #include <vm/pmap.h>
     96       1.1      fvdl 
     97       1.1      fvdl #include <dev/mii/miivar.h>
     98       1.1      fvdl #include <dev/mii/mii.h>
     99       1.1      fvdl 
    100       1.1      fvdl #include <dev/ic/elink3reg.h>
    101       1.1      fvdl /* #include <dev/ic/elink3var.h> */
    102       1.1      fvdl #include <dev/ic/elinkxlreg.h>
    103       1.1      fvdl #include <dev/ic/elinkxlvar.h>
    104       1.1      fvdl 
    105       1.1      fvdl #ifdef DEBUG
    106       1.1      fvdl int exdebug = 0;
    107       1.1      fvdl #endif
    108       1.1      fvdl 
    109       1.1      fvdl /* ifmedia callbacks */
    110       1.1      fvdl int ex_media_chg __P((struct ifnet *ifp));
    111       1.1      fvdl void ex_media_stat __P((struct ifnet *ifp, struct ifmediareq *req));
    112       1.1      fvdl 
    113       1.1      fvdl void ex_probe_media __P((struct ex_softc *));
    114       1.1      fvdl void ex_set_filter __P((struct ex_softc *));
    115       1.1      fvdl void ex_set_media __P((struct ex_softc *));
    116       1.1      fvdl struct mbuf *ex_get __P((struct ex_softc *, int));
    117       1.1      fvdl u_int16_t ex_read_eeprom __P((struct ex_softc *, int));
    118       1.1      fvdl void ex_init __P((struct ex_softc *));
    119       1.1      fvdl void ex_read __P((struct ex_softc *));
    120       1.1      fvdl void ex_reset __P((struct ex_softc *));
    121       1.1      fvdl void ex_set_mc __P((struct ex_softc *));
    122       1.1      fvdl void ex_getstats __P((struct ex_softc *));
    123       1.1      fvdl void ex_printstats __P((struct ex_softc *));
    124       1.1      fvdl void ex_tick __P((void *));
    125       1.1      fvdl 
    126       1.1      fvdl static int ex_eeprom_busy __P((struct ex_softc *));
    127       1.1      fvdl static int ex_add_rxbuf __P((struct ex_softc *, struct ex_rxdesc *));
    128       1.1      fvdl static void ex_init_txdescs __P((struct ex_softc *));
    129       1.1      fvdl 
    130       1.1      fvdl static void ex_shutdown __P((void *));
    131       1.1      fvdl static void ex_start __P((struct ifnet *));
    132       1.1      fvdl static void ex_txstat __P((struct ex_softc *));
    133       1.1      fvdl static u_int16_t ex_mchash __P((u_char *));
    134       1.1      fvdl static void ex_mii_writebits __P((struct ex_softc *, u_int, int));
    135       1.1      fvdl 
    136       1.1      fvdl void ex_mii_setbit __P((void *, u_int16_t));
    137       1.1      fvdl void ex_mii_clrbit __P((void *, u_int16_t));
    138       1.1      fvdl u_int16_t ex_mii_readbit __P((void *, u_int16_t));
    139       1.1      fvdl int ex_mii_readreg __P((struct device *, int, int));
    140       1.1      fvdl void ex_mii_writereg __P((struct device *, int, int, int));
    141       1.1      fvdl void ex_mii_statchg __P((struct device *));
    142       1.1      fvdl 
    143       1.2   thorpej void ex_probemedia __P((struct ex_softc *));
    144       1.2   thorpej 
    145       1.2   thorpej /*
    146       1.2   thorpej  * Structure to map media-present bits in boards to ifmedia codes and
    147       1.2   thorpej  * printable media names.  Used for table-driven ifmedia initialization.
    148       1.2   thorpej  */
    149       1.2   thorpej struct ex_media {
    150       1.2   thorpej 	int	exm_mpbit;		/* media present bit */
    151       1.2   thorpej 	const char *exm_name;		/* name of medium */
    152       1.2   thorpej 	int	exm_ifmedia;		/* ifmedia word for medium */
    153       1.2   thorpej 	int	exm_epmedia;		/* ELINKMEDIA_* constant */
    154       1.2   thorpej };
    155       1.2   thorpej 
    156       1.2   thorpej /*
    157       1.2   thorpej  * Media table for 3c90x chips.  Note that chips with MII have no
    158       1.2   thorpej  * `native' media.
    159       1.2   thorpej  */
    160       1.2   thorpej struct ex_media ex_native_media[] = {
    161       1.2   thorpej 	{ ELINK_PCI_10BASE_T,	"10baseT",	IFM_ETHER|IFM_10_T,
    162       1.2   thorpej 	  ELINKMEDIA_10BASE_T },
    163       1.2   thorpej 	{ ELINK_PCI_10BASE_T,	"10baseT-FDX",	IFM_ETHER|IFM_10_T|IFM_FDX,
    164       1.2   thorpej 	  ELINKMEDIA_10BASE_T },
    165       1.2   thorpej 	{ ELINK_PCI_AUI,	"10base5",	IFM_ETHER|IFM_10_5,
    166       1.2   thorpej 	  ELINKMEDIA_AUI },
    167       1.2   thorpej 	{ ELINK_PCI_BNC,	"10base2",	IFM_ETHER|IFM_10_2,
    168       1.2   thorpej 	  ELINKMEDIA_10BASE_2 },
    169       1.2   thorpej 	{ ELINK_PCI_100BASE_TX,	"100baseTX",	IFM_ETHER|IFM_100_TX,
    170       1.2   thorpej 	  ELINKMEDIA_100BASE_TX },
    171       1.2   thorpej 	{ ELINK_PCI_100BASE_TX,	"100baseTX-FDX",IFM_ETHER|IFM_100_TX|IFM_FDX,
    172       1.2   thorpej 	  ELINKMEDIA_100BASE_TX },
    173       1.2   thorpej 	{ ELINK_PCI_100BASE_FX,	"100baseFX",	IFM_ETHER|IFM_100_FX,
    174       1.2   thorpej 	  ELINKMEDIA_100BASE_FX },
    175       1.2   thorpej 	{ ELINK_PCI_100BASE_MII,"manual",	IFM_ETHER|IFM_MANUAL,
    176       1.2   thorpej 	  ELINKMEDIA_MII },
    177       1.2   thorpej 	{ ELINK_PCI_100BASE_T4,	"100baseT4",	IFM_ETHER|IFM_100_T4,
    178       1.2   thorpej 	  ELINKMEDIA_100BASE_T4 },
    179       1.2   thorpej 	{ 0,			NULL,		0,
    180       1.2   thorpej 	  0 },
    181       1.2   thorpej };
    182       1.2   thorpej 
    183       1.1      fvdl /*
    184       1.1      fvdl  * Back-end attach and configure.
    185       1.1      fvdl  */
    186       1.1      fvdl void
    187       1.1      fvdl ex_config(sc)
    188       1.1      fvdl 	struct ex_softc *sc;
    189       1.1      fvdl {
    190       1.1      fvdl 	struct ifnet *ifp;
    191       1.1      fvdl 	u_int16_t val;
    192       1.1      fvdl 	u_int8_t macaddr[ETHER_ADDR_LEN] = {0};
    193       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
    194       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
    195       1.1      fvdl 	bus_dma_segment_t useg, dseg;
    196       1.1      fvdl 	int urseg, drseg, i, error, attach_stage;
    197       1.1      fvdl 
    198       1.1      fvdl 	ex_reset(sc);
    199       1.1      fvdl 
    200       1.1      fvdl 	val = ex_read_eeprom(sc, EEPROM_OEM_ADDR0);
    201       1.1      fvdl 	macaddr[0] = val >> 8;
    202       1.1      fvdl 	macaddr[1] = val & 0xff;
    203       1.1      fvdl 	val = ex_read_eeprom(sc, EEPROM_OEM_ADDR1);
    204       1.1      fvdl 	macaddr[2] = val >> 8;
    205       1.1      fvdl 	macaddr[3] = val & 0xff;
    206       1.1      fvdl 	val = ex_read_eeprom(sc, EEPROM_OEM_ADDR2);
    207       1.1      fvdl 	macaddr[4] = val >> 8;
    208       1.1      fvdl 	macaddr[5] = val & 0xff;
    209       1.1      fvdl 
    210       1.1      fvdl 	printf("%s: MAC address %s\n", sc->sc_dev.dv_xname,
    211       1.1      fvdl 	    ether_sprintf(macaddr));
    212       1.1      fvdl 
    213      1.15      haya 	if (sc->intr_ack) { /* 3C575BTX specific */
    214      1.15      haya 	    GO_WINDOW(2);
    215      1.15      haya 	    bus_space_write_2(sc->sc_iot, ioh, 12, 0x10|bus_space_read_2(sc->sc_iot, ioh, 12));
    216      1.15      haya 	}
    217      1.15      haya 
    218       1.1      fvdl 	attach_stage = 0;
    219       1.1      fvdl 
    220       1.1      fvdl 	/*
    221       1.1      fvdl 	 * Allocate the upload descriptors, and create and load the DMA
    222       1.1      fvdl 	 * map for them.
    223       1.1      fvdl 	 */
    224       1.1      fvdl 	if ((error = bus_dmamem_alloc(sc->sc_dmat,
    225       1.1      fvdl 	    EX_NUPD * sizeof (struct ex_upd), NBPG, 0, &useg, 1, &urseg,
    226       1.1      fvdl 	    BUS_DMA_NOWAIT)) != 0) {
    227       1.1      fvdl 		printf("%s: can't allocate upload descriptors, error = %d\n",
    228       1.1      fvdl 		    sc->sc_dev.dv_xname, error);
    229       1.1      fvdl 		goto fail;
    230       1.1      fvdl 	}
    231       1.1      fvdl 
    232       1.1      fvdl 	attach_stage = 1;
    233       1.1      fvdl 
    234       1.1      fvdl 	if ((error = bus_dmamem_map(sc->sc_dmat, &useg, urseg,
    235       1.1      fvdl 	    EX_NUPD * sizeof (struct ex_upd), (caddr_t *)&sc->sc_upd,
    236       1.1      fvdl 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
    237       1.1      fvdl 		printf("%s: can't map upload descriptors, error = %d\n",
    238       1.1      fvdl 		    sc->sc_dev.dv_xname, error);
    239       1.1      fvdl 		goto fail;
    240       1.1      fvdl 	}
    241       1.1      fvdl 
    242       1.1      fvdl 	attach_stage = 2;
    243       1.1      fvdl 
    244       1.1      fvdl 	if ((error = bus_dmamap_create(sc->sc_dmat,
    245       1.1      fvdl 	    EX_NUPD * sizeof (struct ex_upd), 1,
    246       1.1      fvdl 	    EX_NUPD * sizeof (struct ex_upd), 0, BUS_DMA_NOWAIT,
    247       1.1      fvdl 	    &sc->sc_upd_dmamap)) != 0) {
    248       1.1      fvdl 		printf("%s: can't create upload desc. DMA map, error = %d\n",
    249       1.1      fvdl 		    sc->sc_dev.dv_xname, error);
    250       1.1      fvdl 		goto fail;
    251       1.1      fvdl 	}
    252       1.1      fvdl 
    253       1.1      fvdl 	attach_stage = 3;
    254       1.1      fvdl 
    255       1.1      fvdl 	if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_upd_dmamap,
    256       1.1      fvdl 	    sc->sc_upd, EX_NUPD * sizeof (struct ex_upd), NULL,
    257       1.1      fvdl 	    BUS_DMA_NOWAIT)) != 0) {
    258       1.1      fvdl 		printf("%s: can't load upload desc. DMA map, error = %d\n",
    259       1.1      fvdl 		    sc->sc_dev.dv_xname, error);
    260       1.1      fvdl 		goto fail;
    261       1.1      fvdl 	}
    262       1.1      fvdl 
    263       1.1      fvdl 	attach_stage = 4;
    264       1.1      fvdl 
    265       1.1      fvdl 	/*
    266       1.1      fvdl 	 * Allocate the download descriptors, and create and load the DMA
    267       1.1      fvdl 	 * map for them.
    268       1.1      fvdl 	 */
    269       1.1      fvdl 	if ((error = bus_dmamem_alloc(sc->sc_dmat,
    270       1.1      fvdl 	    EX_NDPD * sizeof (struct ex_dpd), NBPG, 0, &dseg, 1, &drseg,
    271       1.1      fvdl 	    BUS_DMA_NOWAIT)) != 0) {
    272       1.1      fvdl 		printf("%s: can't allocate download descriptors, error = %d\n",
    273       1.1      fvdl 		    sc->sc_dev.dv_xname, error);
    274       1.1      fvdl 		goto fail;
    275       1.1      fvdl 	}
    276       1.1      fvdl 
    277       1.1      fvdl 	attach_stage = 5;
    278       1.1      fvdl 
    279       1.1      fvdl 	if ((error = bus_dmamem_map(sc->sc_dmat, &dseg, drseg,
    280       1.1      fvdl 	    EX_NDPD * sizeof (struct ex_dpd), (caddr_t *)&sc->sc_dpd,
    281       1.1      fvdl 	    BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
    282       1.1      fvdl 		printf("%s: can't map download descriptors, error = %d\n",
    283       1.1      fvdl 		    sc->sc_dev.dv_xname, error);
    284       1.1      fvdl 		goto fail;
    285       1.1      fvdl 	}
    286       1.1      fvdl 	bzero(sc->sc_dpd, EX_NDPD * sizeof (struct ex_dpd));
    287       1.1      fvdl 
    288       1.1      fvdl 	attach_stage = 6;
    289       1.1      fvdl 
    290       1.1      fvdl 	if ((error = bus_dmamap_create(sc->sc_dmat,
    291       1.1      fvdl 	    EX_NDPD * sizeof (struct ex_dpd), 1,
    292       1.1      fvdl 	    EX_NDPD * sizeof (struct ex_dpd), 0, BUS_DMA_NOWAIT,
    293       1.1      fvdl 	    &sc->sc_dpd_dmamap)) != 0) {
    294       1.1      fvdl 		printf("%s: can't create download desc. DMA map, error = %d\n",
    295       1.1      fvdl 		    sc->sc_dev.dv_xname, error);
    296       1.1      fvdl 		goto fail;
    297       1.1      fvdl 	}
    298       1.1      fvdl 
    299       1.1      fvdl 	attach_stage = 7;
    300       1.1      fvdl 
    301       1.1      fvdl 	if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_dpd_dmamap,
    302       1.1      fvdl 	    sc->sc_dpd, EX_NDPD * sizeof (struct ex_dpd), NULL,
    303       1.1      fvdl 	    BUS_DMA_NOWAIT)) != 0) {
    304       1.1      fvdl 		printf("%s: can't load download desc. DMA map, error = %d\n",
    305       1.1      fvdl 		    sc->sc_dev.dv_xname, error);
    306       1.1      fvdl 		goto fail;
    307       1.1      fvdl 	}
    308       1.1      fvdl 
    309       1.1      fvdl 	attach_stage = 8;
    310       1.1      fvdl 
    311       1.1      fvdl 
    312       1.1      fvdl 	/*
    313       1.1      fvdl 	 * Create the transmit buffer DMA maps.
    314       1.1      fvdl 	 */
    315       1.1      fvdl 	for (i = 0; i < EX_NDPD; i++) {
    316       1.1      fvdl 		if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES,
    317       1.1      fvdl 		    EX_NTFRAGS, MCLBYTES, 0, BUS_DMA_NOWAIT,
    318       1.1      fvdl 		    &sc->sc_tx_dmamaps[i])) != 0) {
    319       1.1      fvdl 			printf("%s: can't create tx DMA map %d, error = %d\n",
    320       1.1      fvdl 			    sc->sc_dev.dv_xname, i, error);
    321       1.1      fvdl 			goto fail;
    322       1.1      fvdl 		}
    323       1.1      fvdl 	}
    324       1.1      fvdl 
    325       1.1      fvdl 	attach_stage = 9;
    326       1.1      fvdl 
    327       1.1      fvdl 	/*
    328       1.1      fvdl 	 * Create the receive buffer DMA maps.
    329       1.1      fvdl 	 */
    330       1.1      fvdl 	for (i = 0; i < EX_NUPD; i++) {
    331       1.1      fvdl 		if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES,
    332       1.1      fvdl 		    EX_NRFRAGS, MCLBYTES, 0, BUS_DMA_NOWAIT,
    333       1.1      fvdl 		    &sc->sc_rx_dmamaps[i])) != 0) {
    334       1.1      fvdl 			printf("%s: can't create rx DMA map %d, error = %d\n",
    335       1.1      fvdl 			    sc->sc_dev.dv_xname, i, error);
    336       1.1      fvdl 			goto fail;
    337       1.1      fvdl 		}
    338       1.1      fvdl 	}
    339       1.1      fvdl 
    340       1.1      fvdl 	attach_stage = 10;
    341       1.1      fvdl 
    342       1.1      fvdl 	/*
    343       1.1      fvdl 	 * Create ring of upload descriptors, only once. The DMA engine
    344       1.1      fvdl 	 * will loop over this when receiving packets, stalling if it
    345       1.1      fvdl 	 * hits an UPD with a finished receive.
    346       1.1      fvdl 	 */
    347       1.1      fvdl 	for (i = 0; i < EX_NUPD; i++) {
    348       1.1      fvdl 		sc->sc_rxdescs[i].rx_dmamap = sc->sc_rx_dmamaps[i];
    349       1.1      fvdl 		sc->sc_rxdescs[i].rx_upd = &sc->sc_upd[i];
    350       1.9   thorpej 		sc->sc_upd[i].upd_frags[0].fr_len =
    351       1.9   thorpej 		    htopci((MCLBYTES - 2) | EX_FR_LAST);
    352       1.1      fvdl 		if (ex_add_rxbuf(sc, &sc->sc_rxdescs[i]) != 0) {
    353       1.1      fvdl 			printf("%s: can't allocate or map rx buffers\n",
    354       1.1      fvdl 			    sc->sc_dev.dv_xname);
    355       1.1      fvdl 			goto fail;
    356       1.1      fvdl 		}
    357       1.1      fvdl 	}
    358       1.1      fvdl 
    359       1.1      fvdl 	bus_dmamap_sync(sc->sc_dmat, sc->sc_upd_dmamap, 0,
    360       1.1      fvdl 	    EX_NUPD * sizeof (struct ex_upd),
    361       1.1      fvdl 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
    362       1.1      fvdl 
    363       1.1      fvdl 	ex_init_txdescs(sc);
    364       1.1      fvdl 
    365       1.1      fvdl 	attach_stage = 11;
    366       1.1      fvdl 
    367       1.1      fvdl 
    368       1.1      fvdl 	GO_WINDOW(3);
    369       1.1      fvdl 	val = bus_space_read_2(iot, ioh, ELINK_W3_RESET_OPTIONS);
    370       1.1      fvdl 	if (val & ELINK_MEDIACAP_MII)
    371       1.1      fvdl 		sc->ex_conf |= EX_CONF_MII;
    372       1.1      fvdl 
    373       1.1      fvdl 	ifp = &sc->sc_ethercom.ec_if;
    374       1.1      fvdl 
    375       1.2   thorpej 	/*
    376       1.2   thorpej 	 * Initialize our media structures and MII info.  We'll
    377       1.2   thorpej 	 * probe the MII if we discover that we have one.
    378       1.2   thorpej 	 */
    379       1.2   thorpej 	sc->ex_mii.mii_ifp = ifp;
    380       1.2   thorpej 	sc->ex_mii.mii_readreg = ex_mii_readreg;
    381       1.2   thorpej 	sc->ex_mii.mii_writereg = ex_mii_writereg;
    382       1.2   thorpej 	sc->ex_mii.mii_statchg = ex_mii_statchg;
    383       1.2   thorpej 	ifmedia_init(&sc->ex_mii.mii_media, 0, ex_media_chg,
    384       1.2   thorpej 	    ex_media_stat);
    385       1.2   thorpej 
    386       1.1      fvdl 	if (sc->ex_conf & EX_CONF_MII) {
    387       1.1      fvdl 		/*
    388       1.1      fvdl 		 * Find PHY, extract media information from it.
    389      1.14      fvdl 		 * First, select the right transceiver.
    390       1.1      fvdl 		 */
    391      1.14      fvdl 		u_int32_t icfg;
    392      1.14      fvdl 
    393      1.14      fvdl 		GO_WINDOW(3);
    394      1.14      fvdl 		icfg = bus_space_read_4(iot, ioh, ELINK_W3_INTERNAL_CONFIG);
    395      1.14      fvdl 		icfg &= ~(CONFIG_XCVR_SEL << 16);
    396      1.14      fvdl 		if (val & (ELINK_MEDIACAP_MII | ELINK_MEDIACAP_100BASET4))
    397      1.14      fvdl 			icfg |= ELINKMEDIA_MII << (CONFIG_XCVR_SEL_SHIFT + 16);
    398      1.14      fvdl 		if (val & ELINK_MEDIACAP_100BASETX)
    399      1.14      fvdl 			icfg |= ELINKMEDIA_AUTO << (CONFIG_XCVR_SEL_SHIFT + 16);
    400      1.14      fvdl 		if (val & ELINK_MEDIACAP_100BASEFX)
    401      1.14      fvdl 			icfg |= ELINKMEDIA_100BASE_FX
    402      1.14      fvdl 				<< (CONFIG_XCVR_SEL_SHIFT + 16);
    403      1.14      fvdl 		bus_space_write_4(iot, ioh, ELINK_W3_INTERNAL_CONFIG, icfg);
    404      1.14      fvdl 
    405  1.15.4.1      fvdl 		mii_phy_probe(&sc->sc_dev, &sc->ex_mii, 0xffffffff,
    406  1.15.4.1      fvdl 		    MII_PHY_ANY, MII_OFFSET_ANY);
    407       1.1      fvdl 		if (LIST_FIRST(&sc->ex_mii.mii_phys) == NULL) {
    408       1.1      fvdl 			ifmedia_add(&sc->ex_mii.mii_media, IFM_ETHER|IFM_NONE,
    409       1.1      fvdl 			    0, NULL);
    410       1.1      fvdl 			ifmedia_set(&sc->ex_mii.mii_media, IFM_ETHER|IFM_NONE);
    411       1.1      fvdl 		} else {
    412       1.1      fvdl 			ifmedia_set(&sc->ex_mii.mii_media, IFM_ETHER|IFM_AUTO);
    413       1.1      fvdl 		}
    414       1.2   thorpej 	} else
    415       1.2   thorpej 		ex_probemedia(sc);
    416       1.1      fvdl 
    417       1.1      fvdl 	bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
    418       1.1      fvdl 	ifp->if_softc = sc;
    419       1.1      fvdl 	ifp->if_start = ex_start;
    420       1.1      fvdl 	ifp->if_ioctl = ex_ioctl;
    421       1.1      fvdl 	ifp->if_watchdog = ex_watchdog;
    422       1.1      fvdl 	ifp->if_flags =
    423       1.1      fvdl 	    IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
    424       1.1      fvdl 
    425       1.1      fvdl 	if_attach(ifp);
    426       1.1      fvdl 	ether_ifattach(ifp, macaddr);
    427       1.1      fvdl 
    428       1.1      fvdl 	GO_WINDOW(1);
    429       1.1      fvdl 
    430       1.1      fvdl 	sc->tx_start_thresh = 20;
    431       1.1      fvdl 	sc->tx_succ_ok = 0;
    432       1.1      fvdl 
    433       1.1      fvdl 	/* TODO: set queues to 0 */
    434       1.1      fvdl 
    435       1.1      fvdl #if NBPFILTER > 0
    436       1.1      fvdl 	bpfattach(&sc->sc_ethercom.ec_if.if_bpf, ifp, DLT_EN10MB,
    437       1.1      fvdl 		  sizeof(struct ether_header));
    438       1.1      fvdl #endif
    439       1.1      fvdl 
    440       1.1      fvdl #if NRND > 0
    441       1.5  explorer 	rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
    442       1.5  explorer 			  RND_TYPE_NET, 0);
    443       1.1      fvdl #endif
    444       1.1      fvdl 
    445       1.1      fvdl 	/*  Establish callback to reset card when we reboot. */
    446       1.1      fvdl 	shutdownhook_establish(ex_shutdown, sc);
    447       1.1      fvdl 	return;
    448       1.1      fvdl 
    449       1.1      fvdl  fail:
    450       1.1      fvdl 	/*
    451       1.1      fvdl 	 * Free any resources we've allocated during the failed attach
    452       1.1      fvdl 	 * attempt.  Do this in reverse order and fall though.
    453       1.1      fvdl 	 */
    454       1.1      fvdl 	switch (attach_stage) {
    455       1.1      fvdl 	case 11:
    456       1.1      fvdl 	    {
    457       1.1      fvdl 		struct ex_rxdesc *rxd;
    458       1.1      fvdl 
    459       1.1      fvdl 		for (i = 0; i < EX_NUPD; i++) {
    460       1.1      fvdl 			rxd = &sc->sc_rxdescs[i];
    461       1.1      fvdl 			if (rxd->rx_mbhead != NULL) {
    462       1.1      fvdl 				bus_dmamap_unload(sc->sc_dmat, rxd->rx_dmamap);
    463       1.1      fvdl 				m_freem(rxd->rx_mbhead);
    464       1.1      fvdl 			}
    465       1.1      fvdl 		}
    466       1.1      fvdl 	    }
    467       1.1      fvdl 		/* FALLTHROUGH */
    468       1.1      fvdl 
    469       1.1      fvdl 	case 10:
    470       1.1      fvdl 		for (i = 0; i < EX_NUPD; i++)
    471       1.1      fvdl 			bus_dmamap_destroy(sc->sc_dmat, sc->sc_rx_dmamaps[i]);
    472       1.1      fvdl 		/* FALLTHROUGH */
    473       1.1      fvdl 
    474       1.1      fvdl 	case 9:
    475       1.1      fvdl 		for (i = 0; i < EX_NDPD; i++)
    476       1.1      fvdl 			bus_dmamap_destroy(sc->sc_dmat, sc->sc_tx_dmamaps[i]);
    477       1.1      fvdl 		/* FALLTHROUGH */
    478       1.1      fvdl 	case 8:
    479       1.1      fvdl 		bus_dmamap_unload(sc->sc_dmat, sc->sc_dpd_dmamap);
    480       1.1      fvdl 		/* FALLTHROUGH */
    481       1.1      fvdl 
    482       1.1      fvdl 	case 7:
    483       1.1      fvdl 		bus_dmamap_destroy(sc->sc_dmat, sc->sc_dpd_dmamap);
    484       1.1      fvdl 		/* FALLTHROUGH */
    485       1.1      fvdl 
    486       1.1      fvdl 	case 6:
    487       1.1      fvdl 		bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->sc_dpd,
    488       1.1      fvdl 		    EX_NDPD * sizeof (struct ex_dpd));
    489       1.1      fvdl 		/* FALLTHROUGH */
    490       1.1      fvdl 
    491       1.1      fvdl 	case 5:
    492       1.1      fvdl 		bus_dmamem_free(sc->sc_dmat, &dseg, drseg);
    493       1.1      fvdl 		break;
    494       1.1      fvdl 
    495       1.1      fvdl 	case 4:
    496       1.1      fvdl 		bus_dmamap_unload(sc->sc_dmat, sc->sc_upd_dmamap);
    497       1.1      fvdl 		/* FALLTHROUGH */
    498       1.1      fvdl 
    499       1.1      fvdl 	case 3:
    500       1.1      fvdl 		bus_dmamap_destroy(sc->sc_dmat, sc->sc_upd_dmamap);
    501       1.1      fvdl 		/* FALLTHROUGH */
    502       1.1      fvdl 
    503       1.1      fvdl 	case 2:
    504       1.1      fvdl 		bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->sc_upd,
    505       1.1      fvdl 		    EX_NUPD * sizeof (struct ex_upd));
    506       1.1      fvdl 		/* FALLTHROUGH */
    507       1.1      fvdl 
    508       1.1      fvdl 	case 1:
    509       1.1      fvdl 		bus_dmamem_free(sc->sc_dmat, &useg, urseg);
    510       1.1      fvdl 		break;
    511       1.1      fvdl 	}
    512       1.1      fvdl 
    513       1.2   thorpej }
    514       1.2   thorpej 
    515       1.2   thorpej /*
    516       1.2   thorpej  * Find the media present on non-MII chips.
    517       1.2   thorpej  */
    518       1.2   thorpej void
    519       1.2   thorpej ex_probemedia(sc)
    520       1.2   thorpej 	struct ex_softc *sc;
    521       1.2   thorpej {
    522       1.2   thorpej 	bus_space_tag_t iot = sc->sc_iot;
    523       1.2   thorpej 	bus_space_handle_t ioh = sc->sc_ioh;
    524       1.2   thorpej 	struct ifmedia *ifm = &sc->ex_mii.mii_media;
    525       1.2   thorpej 	struct ex_media *exm;
    526       1.2   thorpej 	u_int16_t config1, reset_options, default_media;
    527       1.2   thorpej 	int defmedia = 0;
    528       1.2   thorpej 	const char *sep = "", *defmedianame = NULL;
    529       1.2   thorpej 
    530       1.2   thorpej 	GO_WINDOW(3);
    531       1.2   thorpej 	config1 = bus_space_read_2(iot, ioh, ELINK_W3_INTERNAL_CONFIG + 2);
    532       1.2   thorpej 	reset_options = bus_space_read_1(iot, ioh, ELINK_W3_RESET_OPTIONS);
    533       1.2   thorpej 	GO_WINDOW(0);
    534       1.2   thorpej 
    535       1.2   thorpej 	default_media = (config1 & CONFIG_MEDIAMASK) >> CONFIG_MEDIAMASK_SHIFT;
    536       1.2   thorpej 
    537       1.2   thorpej 	printf("%s: ", sc->sc_dev.dv_xname);
    538       1.2   thorpej 
    539       1.2   thorpej 	/* Sanity check that there are any media! */
    540       1.2   thorpej 	if ((reset_options & ELINK_PCI_MEDIAMASK) == 0) {
    541       1.2   thorpej 		printf("no media present!\n");
    542       1.2   thorpej 		ifmedia_add(ifm, IFM_ETHER|IFM_NONE, 0, NULL);
    543       1.2   thorpej 		ifmedia_set(ifm, IFM_ETHER|IFM_NONE);
    544       1.2   thorpej 		return;
    545       1.2   thorpej 	}
    546       1.2   thorpej 
    547       1.2   thorpej #define	PRINT(s)	printf("%s%s", sep, s); sep = ", "
    548       1.2   thorpej 
    549       1.2   thorpej 	for (exm = ex_native_media; exm->exm_name != NULL; exm++) {
    550       1.2   thorpej 		if (reset_options & exm->exm_mpbit) {
    551       1.2   thorpej 			/*
    552       1.2   thorpej 			 * Default media is a little complicated.  We
    553       1.2   thorpej 			 * support full-duplex which uses the same
    554       1.2   thorpej 			 * reset options bit.
    555       1.2   thorpej 			 *
    556       1.2   thorpej 			 * XXX Check EEPROM for default to FDX?
    557       1.2   thorpej 			 */
    558       1.2   thorpej 			if (exm->exm_epmedia == default_media) {
    559       1.2   thorpej 				if ((exm->exm_ifmedia & IFM_FDX) == 0) {
    560       1.2   thorpej 					defmedia = exm->exm_ifmedia;
    561       1.2   thorpej 					defmedianame = exm->exm_name;
    562       1.2   thorpej 				}
    563       1.2   thorpej 			} else if (defmedia == 0) {
    564       1.2   thorpej 				defmedia = exm->exm_ifmedia;
    565       1.2   thorpej 				defmedianame = exm->exm_name;
    566       1.2   thorpej 			}
    567       1.2   thorpej 			ifmedia_add(ifm, exm->exm_ifmedia, exm->exm_epmedia,
    568       1.2   thorpej 			    NULL);
    569       1.2   thorpej 			PRINT(exm->exm_name);
    570       1.2   thorpej 		}
    571       1.2   thorpej 	}
    572       1.2   thorpej 
    573       1.2   thorpej #undef PRINT
    574       1.2   thorpej 
    575       1.2   thorpej #ifdef DIAGNOSTIC
    576       1.2   thorpej 	if (defmedia == 0)
    577       1.2   thorpej 		panic("ex_probemedia: impossible");
    578       1.2   thorpej #endif
    579       1.2   thorpej 
    580       1.2   thorpej 	printf(", default %s\n", defmedianame);
    581       1.2   thorpej 	ifmedia_set(ifm, defmedia);
    582       1.1      fvdl }
    583       1.1      fvdl 
    584       1.1      fvdl /*
    585       1.1      fvdl  * Bring device up.
    586       1.1      fvdl  */
    587       1.1      fvdl void
    588       1.1      fvdl ex_init(sc)
    589       1.1      fvdl 	struct ex_softc *sc;
    590       1.1      fvdl {
    591       1.1      fvdl 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    592       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
    593       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
    594       1.1      fvdl 	int s, i;
    595       1.1      fvdl 
    596       1.1      fvdl 	s = splnet();
    597       1.1      fvdl 
    598       1.1      fvdl 	ex_waitcmd(sc);
    599       1.1      fvdl 	ex_stop(sc);
    600       1.1      fvdl 
    601       1.1      fvdl 	/*
    602       1.1      fvdl 	 * Set the station address and clear the station mask. The latter
    603       1.1      fvdl 	 * is needed for 90x cards, 0 is the default for 90xB cards.
    604       1.1      fvdl 	 */
    605       1.1      fvdl 	GO_WINDOW(2);
    606       1.1      fvdl 	for (i = 0; i < ETHER_ADDR_LEN; i++) {
    607       1.1      fvdl 		bus_space_write_1(iot, ioh, ELINK_W2_ADDR_0 + i,
    608       1.1      fvdl 		    LLADDR(ifp->if_sadl)[i]);
    609       1.1      fvdl 		bus_space_write_1(iot, ioh, ELINK_W2_RECVMASK_0 + i, 0);
    610       1.1      fvdl 	}
    611       1.1      fvdl 
    612       1.1      fvdl 	GO_WINDOW(3);
    613       1.1      fvdl 
    614       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, RX_RESET);
    615       1.1      fvdl 	ex_waitcmd(sc);
    616       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, TX_RESET);
    617       1.1      fvdl 	ex_waitcmd(sc);
    618       1.1      fvdl 
    619       1.1      fvdl 	/*
    620       1.1      fvdl 	 * Disable reclaim threshold for 90xB, set free threshold to
    621       1.1      fvdl 	 * 6 * 256 = 1536 for 90x.
    622       1.1      fvdl 	 */
    623       1.1      fvdl 	if (sc->ex_conf & EX_CONF_90XB)
    624       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_COMMAND,
    625       1.1      fvdl 		    ELINK_TXRECLTHRESH | 255);
    626       1.1      fvdl 	else
    627       1.1      fvdl 		bus_space_write_1(iot, ioh, ELINK_TXFREETHRESH, 6);
    628       1.1      fvdl 
    629       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND,
    630       1.1      fvdl 	    SET_RX_EARLY_THRESH | ELINK_THRESH_DISABLE);
    631       1.1      fvdl 
    632       1.1      fvdl 	bus_space_write_4(iot, ioh, ELINK_DMACTRL,
    633       1.1      fvdl 	    bus_space_read_4(iot, ioh, ELINK_DMACTRL) | ELINK_DMAC_UPRXEAREN);
    634       1.1      fvdl 
    635       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, SET_RD_0_MASK | S_MASK);
    636       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, SET_INTR_MASK | S_MASK);
    637       1.1      fvdl 
    638       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, ACK_INTR | 0xff);
    639      1.15      haya 	if (sc->intr_ack)
    640      1.15      haya 	    (* sc->intr_ack)(sc);
    641       1.1      fvdl 	ex_set_media(sc);
    642       1.1      fvdl 	ex_set_mc(sc);
    643       1.1      fvdl 
    644       1.1      fvdl 
    645       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, STATS_ENABLE);
    646       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, TX_ENABLE);
    647       1.1      fvdl 	bus_space_write_4(iot, ioh, ELINK_UPLISTPTR, sc->sc_upddma);
    648       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, RX_ENABLE);
    649       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, ELINK_UPUNSTALL);
    650       1.1      fvdl 
    651       1.1      fvdl 	ifp->if_flags |= IFF_RUNNING;
    652       1.1      fvdl 	ifp->if_flags &= ~IFF_OACTIVE;
    653       1.1      fvdl 	ex_start(ifp);
    654       1.1      fvdl 
    655       1.1      fvdl 	GO_WINDOW(1);
    656       1.1      fvdl 
    657       1.1      fvdl 	splx(s);
    658       1.1      fvdl 
    659       1.1      fvdl 	timeout(ex_tick, sc, hz);
    660       1.1      fvdl }
    661       1.1      fvdl 
    662       1.1      fvdl /*
    663       1.1      fvdl  * Multicast hash filter according to the 3Com spec.
    664       1.1      fvdl  */
    665       1.1      fvdl static u_int16_t
    666       1.1      fvdl ex_mchash(addr)
    667       1.1      fvdl 	u_char *addr;
    668       1.1      fvdl {
    669       1.1      fvdl 	u_int32_t crc, carry;
    670       1.1      fvdl 	int i, j;
    671       1.1      fvdl 	u_char c;
    672       1.1      fvdl 
    673       1.1      fvdl 	/* Compute CRC for the address value. */
    674       1.1      fvdl 	crc = 0xffffffff; /* initial value */
    675       1.1      fvdl 
    676       1.1      fvdl 	for (i = 0; i < 6; i++) {
    677       1.1      fvdl 		c = addr[i];
    678       1.7      fvdl 		for (j = 0; j < 8; j++) {
    679       1.1      fvdl 			carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
    680       1.1      fvdl 			crc <<= 1;
    681       1.1      fvdl 			c >>= 1;
    682       1.1      fvdl 			if (carry)
    683       1.1      fvdl 				crc = (crc ^ 0x04c11db6) | carry;
    684       1.1      fvdl 		}
    685       1.1      fvdl 	}
    686       1.1      fvdl 
    687       1.1      fvdl 	/* Return the filter bit position. */
    688       1.1      fvdl 	return(crc & 0x000000ff);
    689       1.1      fvdl }
    690       1.1      fvdl 
    691       1.1      fvdl 
    692       1.1      fvdl /*
    693       1.1      fvdl  * Set multicast receive filter. Also take care of promiscuous mode
    694       1.1      fvdl  * here (XXX).
    695       1.1      fvdl  */
    696       1.1      fvdl void
    697       1.1      fvdl ex_set_mc(sc)
    698       1.1      fvdl 	register struct ex_softc *sc;
    699       1.1      fvdl {
    700       1.1      fvdl 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
    701       1.1      fvdl 	struct ethercom *ec = &sc->sc_ethercom;
    702       1.1      fvdl 	struct ether_multi *enm;
    703       1.1      fvdl 	struct ether_multistep estep;
    704       1.1      fvdl 	int i;
    705       1.1      fvdl 	u_int16_t mask = FIL_INDIVIDUAL | FIL_BRDCST;
    706       1.1      fvdl 
    707       1.1      fvdl 	if (ifp->if_flags & IFF_PROMISC)
    708       1.1      fvdl 		mask |= FIL_PROMISC;
    709       1.1      fvdl 
    710       1.1      fvdl 	if (!(ifp->if_flags & IFF_MULTICAST))
    711       1.1      fvdl 		goto out;
    712       1.1      fvdl 
    713       1.1      fvdl 	if (!(sc->ex_conf & EX_CONF_90XB) || ifp->if_flags & IFF_ALLMULTI) {
    714       1.1      fvdl 		mask |= (ifp->if_flags & IFF_MULTICAST) ? FIL_MULTICAST : 0;
    715       1.1      fvdl 	} else {
    716       1.1      fvdl 		ETHER_FIRST_MULTI(estep, ec, enm);
    717       1.1      fvdl 		while (enm != NULL) {
    718       1.1      fvdl 			if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
    719       1.1      fvdl 			    ETHER_ADDR_LEN) != 0)
    720       1.1      fvdl 				goto out;
    721       1.1      fvdl 			i = ex_mchash(enm->enm_addrlo);
    722       1.1      fvdl 			bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    723       1.1      fvdl 			    ELINK_COMMAND, ELINK_SETHASHFILBIT | i);
    724       1.1      fvdl 			ETHER_NEXT_MULTI(estep, enm);
    725       1.1      fvdl 		}
    726       1.1      fvdl 		mask |= FIL_MULTIHASH;
    727       1.1      fvdl 	}
    728       1.1      fvdl  out:
    729       1.1      fvdl 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, ELINK_COMMAND,
    730       1.1      fvdl 	    SET_RX_FILTER | mask);
    731       1.1      fvdl }
    732       1.1      fvdl 
    733       1.1      fvdl 
    734       1.1      fvdl static void
    735       1.1      fvdl ex_txstat(sc)
    736       1.1      fvdl 	struct ex_softc *sc;
    737       1.1      fvdl {
    738       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
    739       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
    740       1.1      fvdl 	int i;
    741       1.1      fvdl 
    742       1.1      fvdl 	/*
    743       1.1      fvdl 	 * We need to read+write TX_STATUS until we get a 0 status
    744       1.1      fvdl 	 * in order to turn off the interrupt flag.
    745       1.1      fvdl 	 */
    746       1.1      fvdl 	while ((i = bus_space_read_1(iot, ioh, ELINK_TXSTATUS)) & TXS_COMPLETE) {
    747       1.1      fvdl 		bus_space_write_1(iot, ioh, ELINK_TXSTATUS, 0x0);
    748       1.1      fvdl 
    749       1.1      fvdl 		if (i & TXS_JABBER) {
    750       1.1      fvdl 			++sc->sc_ethercom.ec_if.if_oerrors;
    751       1.1      fvdl 			if (sc->sc_ethercom.ec_if.if_flags & IFF_DEBUG)
    752       1.1      fvdl 				printf("%s: jabber (%x)\n",
    753       1.1      fvdl 				       sc->sc_dev.dv_xname, i);
    754       1.1      fvdl 			ex_init(sc);
    755       1.1      fvdl 			/* TODO: be more subtle here */
    756       1.1      fvdl 		} else if (i & TXS_UNDERRUN) {
    757       1.1      fvdl 			++sc->sc_ethercom.ec_if.if_oerrors;
    758       1.1      fvdl 			if (sc->sc_ethercom.ec_if.if_flags & IFF_DEBUG)
    759       1.1      fvdl 				printf("%s: fifo underrun (%x) @%d\n",
    760       1.1      fvdl 				       sc->sc_dev.dv_xname, i,
    761       1.1      fvdl 				       sc->tx_start_thresh);
    762       1.1      fvdl 			if (sc->tx_succ_ok < 100)
    763       1.1      fvdl 				    sc->tx_start_thresh = min(ETHER_MAX_LEN,
    764       1.1      fvdl 					    sc->tx_start_thresh + 20);
    765       1.1      fvdl 			sc->tx_succ_ok = 0;
    766       1.1      fvdl 			ex_init(sc);
    767       1.1      fvdl 			/* TODO: be more subtle here */
    768       1.1      fvdl 		} else if (i & TXS_MAX_COLLISION) {
    769       1.1      fvdl 			++sc->sc_ethercom.ec_if.if_collisions;
    770       1.1      fvdl 			bus_space_write_2(iot, ioh, ELINK_COMMAND, TX_ENABLE);
    771       1.1      fvdl 			sc->sc_ethercom.ec_if.if_flags &= ~IFF_OACTIVE;
    772       1.1      fvdl 		} else
    773       1.1      fvdl 			sc->tx_succ_ok = (sc->tx_succ_ok+1) & 127;
    774       1.1      fvdl 	}
    775       1.1      fvdl }
    776       1.1      fvdl 
    777       1.1      fvdl int
    778       1.1      fvdl ex_media_chg(ifp)
    779       1.1      fvdl 	struct ifnet *ifp;
    780       1.1      fvdl {
    781       1.1      fvdl 	struct ex_softc *sc = ifp->if_softc;
    782       1.1      fvdl 
    783       1.1      fvdl 	if (ifp->if_flags & IFF_UP)
    784       1.1      fvdl 		ex_init(sc);
    785       1.1      fvdl 	return 0;
    786       1.1      fvdl }
    787       1.1      fvdl 
    788       1.1      fvdl void
    789       1.1      fvdl ex_set_media(sc)
    790       1.1      fvdl 	struct ex_softc *sc;
    791       1.1      fvdl {
    792       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
    793       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
    794       1.1      fvdl 	int config0, config1;
    795       1.1      fvdl 
    796       1.1      fvdl 	if (((sc->ex_conf & EX_CONF_MII) &&
    797       1.1      fvdl 	    (sc->ex_mii.mii_media_active & IFM_FDX))
    798       1.1      fvdl 	    || (!(sc->ex_conf & EX_CONF_MII) &&
    799       1.1      fvdl 	    (sc->ex_mii.mii_media.ifm_media & IFM_FDX))) {
    800       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_W3_MAC_CONTROL,
    801       1.1      fvdl 		    MAC_CONTROL_FDX);
    802       1.1      fvdl 	} else {
    803       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_W3_MAC_CONTROL, 0);
    804       1.1      fvdl 	}
    805       1.1      fvdl 
    806       1.1      fvdl 	/*
    807       1.1      fvdl 	 * If the device has MII, select it, and then tell the
    808       1.1      fvdl 	 * PHY which media to use.
    809       1.1      fvdl 	 */
    810       1.1      fvdl 	if (sc->ex_conf & EX_CONF_MII) {
    811       1.1      fvdl 		GO_WINDOW(3);
    812       1.1      fvdl 
    813       1.1      fvdl 		config0 = (u_int)bus_space_read_2(iot, ioh,
    814       1.1      fvdl 		    ELINK_W3_INTERNAL_CONFIG);
    815       1.1      fvdl 		config1 = (u_int)bus_space_read_2(iot, ioh,
    816       1.1      fvdl 		    ELINK_W3_INTERNAL_CONFIG + 2);
    817       1.1      fvdl 
    818       1.1      fvdl 		config1 = config1 & ~CONFIG_MEDIAMASK;
    819       1.1      fvdl 		config1 |= (ELINKMEDIA_MII << CONFIG_MEDIAMASK_SHIFT);
    820       1.1      fvdl 
    821       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_W3_INTERNAL_CONFIG, config0);
    822       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_W3_INTERNAL_CONFIG + 2, config1);
    823       1.1      fvdl 		mii_mediachg(&sc->ex_mii);
    824       1.1      fvdl 		return;
    825       1.1      fvdl 	}
    826       1.1      fvdl 
    827       1.1      fvdl 	GO_WINDOW(4);
    828       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_W4_MEDIA_TYPE, 0);
    829       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, STOP_TRANSCEIVER);
    830       1.1      fvdl 	delay(800);
    831       1.1      fvdl 
    832       1.1      fvdl 	/*
    833       1.1      fvdl 	 * Now turn on the selected media/transceiver.
    834       1.1      fvdl 	 */
    835       1.1      fvdl 	switch (IFM_SUBTYPE(sc->ex_mii.mii_media.ifm_cur->ifm_media)) {
    836       1.1      fvdl 	case IFM_10_T:
    837       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_W4_MEDIA_TYPE,
    838       1.1      fvdl 		    JABBER_GUARD_ENABLE|LINKBEAT_ENABLE);
    839       1.1      fvdl 		break;
    840       1.1      fvdl 
    841       1.1      fvdl 	case IFM_10_2:
    842       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_COMMAND, START_TRANSCEIVER);
    843       1.1      fvdl 		DELAY(800);
    844       1.1      fvdl 		break;
    845       1.1      fvdl 
    846       1.1      fvdl 	case IFM_100_TX:
    847       1.1      fvdl 	case IFM_100_FX:
    848       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_W4_MEDIA_TYPE,
    849       1.1      fvdl 		    LINKBEAT_ENABLE);
    850       1.1      fvdl 		DELAY(800);
    851       1.1      fvdl 		break;
    852       1.1      fvdl 
    853       1.1      fvdl 	case IFM_10_5:
    854       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_W4_MEDIA_TYPE,
    855       1.1      fvdl 		    SQE_ENABLE);
    856       1.1      fvdl 		DELAY(800);
    857       1.1      fvdl 		break;
    858       1.1      fvdl 
    859       1.1      fvdl 	case IFM_MANUAL:
    860       1.1      fvdl 		break;
    861       1.1      fvdl 
    862       1.1      fvdl 	case IFM_NONE:
    863       1.1      fvdl 		return;
    864       1.1      fvdl 
    865       1.1      fvdl 	default:
    866       1.1      fvdl 		panic("ex_set_media: impossible");
    867       1.1      fvdl 	}
    868       1.1      fvdl 
    869       1.1      fvdl 	GO_WINDOW(3);
    870       1.1      fvdl 	config0 = (u_int)bus_space_read_2(iot, ioh, ELINK_W3_INTERNAL_CONFIG);
    871       1.1      fvdl 	config1 = (u_int)bus_space_read_2(iot, ioh, ELINK_W3_INTERNAL_CONFIG + 2);
    872       1.1      fvdl 
    873       1.1      fvdl 	config1 = config1 & ~CONFIG_MEDIAMASK;
    874       1.1      fvdl 	config1 |= (sc->ex_mii.mii_media.ifm_cur->ifm_data <<
    875       1.1      fvdl 	    CONFIG_MEDIAMASK_SHIFT);
    876       1.1      fvdl 
    877       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_W3_INTERNAL_CONFIG, config0);
    878       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_W3_INTERNAL_CONFIG + 2, config1);
    879       1.1      fvdl }
    880       1.1      fvdl 
    881       1.1      fvdl /*
    882       1.1      fvdl  * Get currently-selected media from card.
    883       1.1      fvdl  * (if_media callback, may be called before interface is brought up).
    884       1.1      fvdl  */
    885       1.1      fvdl void
    886       1.1      fvdl ex_media_stat(ifp, req)
    887       1.1      fvdl 	struct ifnet *ifp;
    888       1.1      fvdl 	struct ifmediareq *req;
    889       1.1      fvdl {
    890       1.1      fvdl 	struct ex_softc *sc = ifp->if_softc;
    891       1.1      fvdl 
    892       1.1      fvdl 	if (sc->ex_conf & EX_CONF_MII) {
    893       1.1      fvdl 		mii_pollstat(&sc->ex_mii);
    894       1.1      fvdl 		req->ifm_status = sc->ex_mii.mii_media_status;
    895       1.1      fvdl 		req->ifm_active = sc->ex_mii.mii_media_active;
    896       1.1      fvdl 	} else {
    897       1.1      fvdl 		GO_WINDOW(4);
    898       1.1      fvdl 		req->ifm_status = IFM_AVALID;
    899       1.1      fvdl 		req->ifm_active = sc->ex_mii.mii_media.ifm_cur->ifm_media;
    900       1.1      fvdl 		if (bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    901       1.1      fvdl 		    ELINK_W4_MEDIA_TYPE) & LINKBEAT_DETECT)
    902       1.1      fvdl 			req->ifm_status |= IFM_ACTIVE;
    903       1.1      fvdl                 GO_WINDOW(1);
    904       1.1      fvdl 	}
    905       1.1      fvdl }
    906       1.1      fvdl 
    907       1.1      fvdl 
    908       1.1      fvdl 
    909       1.1      fvdl /*
    910       1.1      fvdl  * Start outputting on the interface.
    911       1.1      fvdl  */
    912       1.1      fvdl static void
    913       1.1      fvdl ex_start(ifp)
    914       1.1      fvdl 	struct ifnet *ifp;
    915       1.1      fvdl {
    916       1.1      fvdl 	struct ex_softc *sc = ifp->if_softc;
    917       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
    918       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
    919       1.1      fvdl 	volatile struct ex_fraghdr *fr = NULL;
    920       1.1      fvdl 	volatile struct ex_dpd *dpd = NULL, *prevdpd = NULL;
    921       1.1      fvdl 	struct ex_txdesc *txp;
    922       1.1      fvdl 	bus_dmamap_t dmamap;
    923       1.1      fvdl 	int offset, totlen;
    924       1.1      fvdl 
    925       1.1      fvdl 	if (sc->tx_head || sc->tx_free == NULL)
    926       1.1      fvdl 		return;
    927       1.1      fvdl 
    928       1.1      fvdl 	txp = NULL;
    929       1.1      fvdl 
    930       1.1      fvdl 	/*
    931       1.1      fvdl 	 * We're finished if there is nothing more to add to the list or if
    932       1.1      fvdl 	 * we're all filled up with buffers to transmit.
    933       1.1      fvdl 	 */
    934       1.1      fvdl 	while (ifp->if_snd.ifq_head != NULL && sc->tx_free != NULL) {
    935       1.1      fvdl 		struct mbuf *mb_head;
    936       1.1      fvdl 		int segment, error;
    937       1.1      fvdl 
    938       1.1      fvdl 		/*
    939       1.1      fvdl 		 * Grab a packet to transmit.
    940       1.1      fvdl 		 */
    941       1.1      fvdl 		IF_DEQUEUE(&ifp->if_snd, mb_head);
    942       1.1      fvdl 
    943       1.1      fvdl 		/*
    944       1.1      fvdl 		 * Get pointer to next available tx desc.
    945       1.1      fvdl 		 */
    946       1.1      fvdl 		txp = sc->tx_free;
    947       1.1      fvdl 		sc->tx_free = txp->tx_next;
    948       1.1      fvdl 		txp->tx_next = NULL;
    949       1.1      fvdl 		dmamap = txp->tx_dmamap;
    950       1.1      fvdl 
    951       1.1      fvdl 		/*
    952       1.1      fvdl 		 * Go through each of the mbufs in the chain and initialize
    953       1.1      fvdl 		 * the transmit buffer descriptors with the physical address
    954       1.1      fvdl 		 * and size of the mbuf.
    955       1.1      fvdl 		 */
    956       1.1      fvdl  reload:
    957       1.1      fvdl 		error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap,
    958       1.1      fvdl 		    mb_head, BUS_DMA_NOWAIT);
    959       1.1      fvdl 		switch (error) {
    960       1.1      fvdl 		case 0:
    961       1.1      fvdl 			/* Success. */
    962       1.1      fvdl 			break;
    963       1.1      fvdl 
    964       1.1      fvdl 		case EFBIG:
    965       1.1      fvdl 		    {
    966       1.1      fvdl 			struct mbuf *mn;
    967       1.1      fvdl 
    968       1.1      fvdl 			/*
    969       1.1      fvdl 			 * We ran out of segments.  We have to recopy this
    970       1.1      fvdl 			 * mbuf chain first.  Bail out if we can't get the
    971       1.1      fvdl 			 * new buffers.
    972       1.1      fvdl 			 */
    973       1.1      fvdl 			printf("%s: too many segments, ", sc->sc_dev.dv_xname);
    974       1.1      fvdl 
    975       1.1      fvdl 			MGETHDR(mn, M_DONTWAIT, MT_DATA);
    976       1.1      fvdl 			if (mn == NULL) {
    977       1.1      fvdl 				m_freem(mb_head);
    978       1.1      fvdl 				printf("aborting\n");
    979       1.1      fvdl 				goto out;
    980       1.1      fvdl 			}
    981       1.1      fvdl 			if (mb_head->m_pkthdr.len > MHLEN) {
    982       1.1      fvdl 				MCLGET(mn, M_DONTWAIT);
    983       1.1      fvdl 				if ((mn->m_flags & M_EXT) == 0) {
    984       1.1      fvdl 					m_freem(mn);
    985       1.1      fvdl 					m_freem(mb_head);
    986       1.1      fvdl 					printf("aborting\n");
    987       1.1      fvdl 					goto out;
    988       1.1      fvdl 				}
    989       1.1      fvdl 			}
    990       1.1      fvdl 			m_copydata(mb_head, 0, mb_head->m_pkthdr.len,
    991       1.1      fvdl 			    mtod(mn, caddr_t));
    992       1.1      fvdl 			mn->m_pkthdr.len = mn->m_len = mb_head->m_pkthdr.len;
    993       1.1      fvdl 			m_freem(mb_head);
    994       1.1      fvdl 			mb_head = mn;
    995       1.1      fvdl 			printf("retrying\n");
    996       1.1      fvdl 			goto reload;
    997       1.1      fvdl 		    }
    998       1.1      fvdl 
    999       1.1      fvdl 		default:
   1000       1.1      fvdl 			/*
   1001       1.1      fvdl 			 * Some other problem; report it.
   1002       1.1      fvdl 			 */
   1003       1.1      fvdl 			printf("%s: can't load mbuf chain, error = %d\n",
   1004       1.1      fvdl 			    sc->sc_dev.dv_xname, error);
   1005       1.1      fvdl 			m_freem(mb_head);
   1006       1.1      fvdl 			goto out;
   1007       1.1      fvdl 		}
   1008       1.1      fvdl 
   1009       1.1      fvdl 		fr = &txp->tx_dpd->dpd_frags[0];
   1010       1.1      fvdl 		totlen = 0;
   1011       1.1      fvdl 		for (segment = 0; segment < dmamap->dm_nsegs; segment++, fr++) {
   1012       1.9   thorpej 			fr->fr_addr = htopci(dmamap->dm_segs[segment].ds_addr);
   1013       1.9   thorpej 			fr->fr_len = htopci(dmamap->dm_segs[segment].ds_len);
   1014       1.9   thorpej 			totlen += dmamap->dm_segs[segment].ds_len;
   1015       1.1      fvdl 		}
   1016       1.1      fvdl 		fr--;
   1017       1.9   thorpej 		fr->fr_len |= htopci(EX_FR_LAST);
   1018       1.1      fvdl 		txp->tx_mbhead = mb_head;
   1019       1.1      fvdl 
   1020       1.1      fvdl 		bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
   1021       1.1      fvdl 		    BUS_DMASYNC_PREWRITE);
   1022       1.1      fvdl 
   1023       1.1      fvdl 		dpd = txp->tx_dpd;
   1024       1.1      fvdl 		dpd->dpd_nextptr = 0;
   1025       1.9   thorpej 		dpd->dpd_fsh = htopci(totlen);
   1026       1.1      fvdl 
   1027       1.1      fvdl 		bus_dmamap_sync(sc->sc_dmat, sc->sc_dpd_dmamap,
   1028       1.1      fvdl 		    ((caddr_t)dpd - (caddr_t)sc->sc_dpd),
   1029       1.1      fvdl 		    sizeof (struct ex_dpd),
   1030       1.1      fvdl 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1031       1.1      fvdl 
   1032       1.1      fvdl 		/*
   1033       1.1      fvdl 		 * No need to stall the download engine, we know it's
   1034       1.1      fvdl 		 * not busy right now.
   1035       1.1      fvdl 		 *
   1036       1.1      fvdl 		 * Fix up pointers in both the "soft" tx and the physical
   1037       1.1      fvdl 		 * tx list.
   1038       1.1      fvdl 		 */
   1039       1.1      fvdl 		if (sc->tx_head != NULL) {
   1040       1.1      fvdl 			prevdpd = sc->tx_tail->tx_dpd;
   1041       1.1      fvdl 			offset = ((caddr_t)prevdpd - (caddr_t)sc->sc_dpd);
   1042       1.1      fvdl 			bus_dmamap_sync(sc->sc_dmat, sc->sc_dpd_dmamap,
   1043       1.1      fvdl 			    offset, sizeof (struct ex_dpd),
   1044       1.1      fvdl 			    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1045       1.9   thorpej 			prevdpd->dpd_nextptr = htopci(DPD_DMADDR(sc, txp));
   1046       1.1      fvdl 			bus_dmamap_sync(sc->sc_dmat, sc->sc_dpd_dmamap,
   1047       1.1      fvdl 			    offset, sizeof (struct ex_dpd),
   1048       1.1      fvdl 			    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1049       1.1      fvdl 			sc->tx_tail->tx_next = txp;
   1050       1.1      fvdl 			sc->tx_tail = txp;
   1051       1.1      fvdl 		} else {
   1052       1.1      fvdl 			sc->tx_tail = sc->tx_head = txp;
   1053       1.1      fvdl 		}
   1054       1.1      fvdl 
   1055       1.1      fvdl #if NBPFILTER > 0
   1056       1.1      fvdl 		/*
   1057       1.1      fvdl 		 * Pass packet to bpf if there is a listener.
   1058       1.1      fvdl 		 */
   1059       1.1      fvdl 		if (ifp->if_bpf)
   1060       1.1      fvdl 			bpf_mtap(ifp->if_bpf, mb_head);
   1061       1.1      fvdl #endif
   1062       1.1      fvdl 	}
   1063       1.1      fvdl  out:
   1064       1.1      fvdl 	if (sc->tx_head) {
   1065       1.9   thorpej 		sc->tx_tail->tx_dpd->dpd_fsh |= htopci(EX_DPD_DNIND);
   1066       1.1      fvdl 		bus_dmamap_sync(sc->sc_dmat, sc->sc_dpd_dmamap,
   1067       1.1      fvdl 		    ((caddr_t)sc->tx_tail->tx_dpd - (caddr_t)sc->sc_dpd),
   1068       1.1      fvdl 		    sizeof (struct ex_dpd),
   1069       1.1      fvdl 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1070       1.1      fvdl 		ifp->if_flags |= IFF_OACTIVE;
   1071       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_COMMAND, ELINK_DNUNSTALL);
   1072       1.1      fvdl 		bus_space_write_4(iot, ioh, ELINK_DNLISTPTR,
   1073       1.1      fvdl 		    DPD_DMADDR(sc, sc->tx_head));
   1074       1.3  drochner 
   1075       1.3  drochner 		/* trigger watchdog */
   1076       1.3  drochner 		ifp->if_timer = 5;
   1077       1.1      fvdl 	}
   1078       1.1      fvdl }
   1079       1.1      fvdl 
   1080       1.1      fvdl 
   1081       1.1      fvdl int
   1082       1.1      fvdl ex_intr(arg)
   1083       1.1      fvdl 	void *arg;
   1084       1.1      fvdl {
   1085       1.1      fvdl 	struct ex_softc *sc = arg;
   1086       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
   1087       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
   1088       1.1      fvdl 	u_int16_t stat;
   1089       1.1      fvdl 	int ret = 0;
   1090       1.1      fvdl 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1091       1.1      fvdl 
   1092      1.15      haya 	if (sc->enabled == 0) {
   1093      1.15      haya 	  return ret;
   1094      1.15      haya 	}
   1095       1.1      fvdl 	for (;;) {
   1096       1.1      fvdl 		stat = bus_space_read_2(iot, ioh, ELINK_STATUS);
   1097       1.1      fvdl 		if (!(stat & S_MASK))
   1098       1.1      fvdl 			break;
   1099       1.1      fvdl 		/*
   1100       1.1      fvdl 		 * Acknowledge interrupts.
   1101       1.1      fvdl 		 */
   1102       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_COMMAND, ACK_INTR |
   1103       1.1      fvdl 				      (stat & S_MASK));
   1104      1.15      haya 		if (sc->intr_ack)
   1105      1.15      haya 		    (*sc->intr_ack)(sc);
   1106       1.1      fvdl 		ret = 1;
   1107       1.1      fvdl 		if (stat & S_HOST_ERROR) {
   1108       1.1      fvdl 			printf("%s: adapter failure (%x)\n",
   1109       1.1      fvdl 			    sc->sc_dev.dv_xname, stat);
   1110       1.1      fvdl 			bus_space_write_2(iot, ioh, ELINK_COMMAND,
   1111       1.1      fvdl 			    C_INTR_LATCH);
   1112       1.1      fvdl 			ex_reset(sc);
   1113       1.1      fvdl 			ex_init(sc);
   1114       1.1      fvdl 			return 1;
   1115       1.1      fvdl 		}
   1116       1.1      fvdl 		if (stat & S_TX_COMPLETE) {
   1117       1.1      fvdl 			ex_txstat(sc);
   1118       1.1      fvdl 		}
   1119       1.1      fvdl 		if (stat & S_UPD_STATS) {
   1120       1.1      fvdl 			ex_getstats(sc);
   1121       1.1      fvdl 		}
   1122       1.1      fvdl 		if (stat & S_DN_COMPLETE) {
   1123       1.1      fvdl 			struct ex_txdesc *txp, *ptxp = NULL;
   1124       1.1      fvdl 			bus_dmamap_t txmap;
   1125       1.3  drochner 
   1126       1.3  drochner 			/* reset watchdog timer, was set in ex_start() */
   1127       1.3  drochner 			ifp->if_timer = 0;
   1128       1.3  drochner 
   1129       1.1      fvdl 			for (txp = sc->tx_head; txp != NULL;
   1130       1.1      fvdl 			    txp = txp->tx_next) {
   1131       1.1      fvdl 				bus_dmamap_sync(sc->sc_dmat,
   1132       1.1      fvdl 				    sc->sc_dpd_dmamap,
   1133       1.1      fvdl 				    (caddr_t)txp->tx_dpd - (caddr_t)sc->sc_dpd,
   1134       1.1      fvdl 				    sizeof (struct ex_dpd),
   1135       1.1      fvdl 				    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1136       1.1      fvdl 				if (txp->tx_mbhead != NULL) {
   1137       1.1      fvdl 					txmap = txp->tx_dmamap;
   1138       1.1      fvdl 					bus_dmamap_sync(sc->sc_dmat, txmap,
   1139       1.1      fvdl 					    0, txmap->dm_mapsize,
   1140       1.1      fvdl 					    BUS_DMASYNC_POSTWRITE);
   1141       1.1      fvdl 					bus_dmamap_unload(sc->sc_dmat, txmap);
   1142       1.1      fvdl 					m_freem(txp->tx_mbhead);
   1143       1.1      fvdl 					txp->tx_mbhead = NULL;
   1144       1.1      fvdl 				}
   1145       1.1      fvdl 				ptxp = txp;
   1146       1.1      fvdl 			}
   1147       1.1      fvdl 
   1148       1.1      fvdl 			/*
   1149       1.1      fvdl 			 * Move finished tx buffers back to the tx free list.
   1150       1.1      fvdl 			 */
   1151       1.1      fvdl 			if (sc->tx_free) {
   1152       1.1      fvdl 				sc->tx_ftail->tx_next = sc->tx_head;
   1153       1.1      fvdl 				sc->tx_ftail = ptxp;
   1154       1.1      fvdl 			} else
   1155       1.1      fvdl 				sc->tx_ftail = sc->tx_free = sc->tx_head;
   1156       1.1      fvdl 
   1157       1.1      fvdl 			sc->tx_head = sc->tx_tail = NULL;
   1158       1.1      fvdl 			ifp->if_flags &= ~IFF_OACTIVE;
   1159       1.1      fvdl 		}
   1160       1.1      fvdl 
   1161       1.1      fvdl 		if (stat & S_UP_COMPLETE) {
   1162       1.1      fvdl 			struct ex_rxdesc *rxd;
   1163       1.1      fvdl 			struct mbuf *m;
   1164       1.1      fvdl 			struct ex_upd *upd;
   1165       1.1      fvdl 			bus_dmamap_t rxmap;
   1166       1.1      fvdl 			u_int32_t pktstat;
   1167       1.1      fvdl 
   1168       1.1      fvdl  rcvloop:
   1169       1.1      fvdl 			rxd = sc->rx_head;
   1170       1.1      fvdl 			rxmap = rxd->rx_dmamap;
   1171       1.1      fvdl 			m = rxd->rx_mbhead;
   1172       1.1      fvdl 			upd = rxd->rx_upd;
   1173       1.9   thorpej 			pktstat = pcitoh(upd->upd_pktstatus);
   1174       1.1      fvdl 
   1175       1.1      fvdl 			bus_dmamap_sync(sc->sc_dmat, rxmap, 0,
   1176       1.1      fvdl 			    rxmap->dm_mapsize,
   1177       1.1      fvdl 			    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1178       1.1      fvdl 			bus_dmamap_sync(sc->sc_dmat, sc->sc_upd_dmamap,
   1179       1.1      fvdl 			    ((caddr_t)upd - (caddr_t)sc->sc_upd),
   1180       1.1      fvdl 			    sizeof (struct ex_upd),
   1181       1.1      fvdl 			    BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
   1182       1.1      fvdl 
   1183       1.1      fvdl 			if (pktstat & EX_UPD_COMPLETE) {
   1184       1.1      fvdl 				/*
   1185       1.1      fvdl 				 * Remove first packet from the chain.
   1186       1.1      fvdl 				 */
   1187       1.1      fvdl 				sc->rx_head = rxd->rx_next;
   1188       1.1      fvdl 				rxd->rx_next = NULL;
   1189       1.1      fvdl 
   1190       1.1      fvdl 				/*
   1191       1.1      fvdl 				 * Add a new buffer to the receive chain.
   1192       1.1      fvdl 				 * If this fails, the old buffer is recycled
   1193       1.1      fvdl 				 * instead.
   1194       1.1      fvdl 				 */
   1195       1.1      fvdl 				if (ex_add_rxbuf(sc, rxd) == 0) {
   1196       1.1      fvdl 					struct ether_header *eh;
   1197       1.1      fvdl 					u_int16_t total_len;
   1198       1.1      fvdl 
   1199       1.1      fvdl 
   1200       1.1      fvdl 					if (pktstat & EX_UPD_ERR) {
   1201       1.1      fvdl 						ifp->if_ierrors++;
   1202       1.1      fvdl 						m_freem(m);
   1203       1.1      fvdl 						goto rcvloop;
   1204       1.1      fvdl 					}
   1205       1.1      fvdl 
   1206       1.1      fvdl 					total_len = pktstat & EX_UPD_PKTLENMASK;
   1207       1.1      fvdl 					if (total_len <
   1208       1.1      fvdl 					    sizeof(struct ether_header)) {
   1209       1.1      fvdl 						m_freem(m);
   1210       1.1      fvdl 						goto rcvloop;
   1211       1.1      fvdl 					}
   1212       1.1      fvdl 					m->m_pkthdr.rcvif = ifp;
   1213      1.13   thorpej 					m->m_pkthdr.len = m->m_len = total_len;
   1214       1.1      fvdl 					eh = mtod(m, struct ether_header *);
   1215       1.1      fvdl #if NBPFILTER > 0
   1216       1.1      fvdl 					if (ifp->if_bpf) {
   1217       1.1      fvdl 						bpf_tap(ifp->if_bpf,
   1218       1.1      fvdl 						    mtod(m, caddr_t),
   1219       1.1      fvdl 						    total_len);
   1220       1.1      fvdl 						/*
   1221       1.1      fvdl 						 * Only pass this packet up
   1222       1.1      fvdl 						 * if it is for us.
   1223       1.1      fvdl 						 */
   1224       1.1      fvdl 						if ((ifp->if_flags &
   1225       1.1      fvdl 						    IFF_PROMISC) &&
   1226       1.1      fvdl 						    (eh->ether_dhost[0] & 1)
   1227       1.1      fvdl 						    == 0 &&
   1228       1.1      fvdl 						    bcmp(eh->ether_dhost,
   1229       1.1      fvdl 							LLADDR(ifp->if_sadl),
   1230       1.1      fvdl 							sizeof(eh->ether_dhost))
   1231       1.1      fvdl 							    != 0) {
   1232       1.1      fvdl 							m_freem(m);
   1233       1.1      fvdl 							goto rcvloop;
   1234       1.1      fvdl 						}
   1235       1.1      fvdl 					}
   1236       1.1      fvdl #endif /* NBPFILTER > 0 */
   1237      1.13   thorpej 					(*ifp->if_input)(ifp, m);
   1238       1.1      fvdl 				}
   1239       1.1      fvdl 				goto rcvloop;
   1240       1.1      fvdl 			}
   1241       1.1      fvdl 			/*
   1242       1.1      fvdl 			 * Just in case we filled up all UPDs and the DMA engine
   1243       1.3  drochner 			 * stalled. We could be more subtle about this.
   1244       1.1      fvdl 			 */
   1245       1.3  drochner 			if (bus_space_read_4(iot, ioh, ELINK_UPLISTPTR) == 0) {
   1246       1.3  drochner 				printf("%s: uplistptr was 0\n",
   1247       1.3  drochner 				       sc->sc_dev.dv_xname);
   1248       1.3  drochner 				ex_init(sc);
   1249       1.3  drochner 			} else if (bus_space_read_4(iot, ioh, ELINK_UPPKTSTATUS)
   1250       1.3  drochner 				   & 0x2000) {
   1251       1.3  drochner 				printf("%s: receive stalled\n",
   1252       1.3  drochner 				       sc->sc_dev.dv_xname);
   1253       1.3  drochner 				bus_space_write_2(iot, ioh, ELINK_COMMAND,
   1254       1.3  drochner 						  ELINK_UPUNSTALL);
   1255       1.3  drochner 			}
   1256       1.1      fvdl 		}
   1257       1.1      fvdl 	}
   1258       1.1      fvdl 	if (ret) {
   1259       1.1      fvdl 		bus_space_write_2(iot, ioh, ELINK_COMMAND, C_INTR_LATCH);
   1260       1.1      fvdl 		if (ifp->if_snd.ifq_head != NULL)
   1261       1.1      fvdl 			ex_start(ifp);
   1262       1.1      fvdl 	}
   1263       1.1      fvdl 	return ret;
   1264       1.1      fvdl }
   1265       1.1      fvdl 
   1266       1.1      fvdl int
   1267       1.1      fvdl ex_ioctl(ifp, cmd, data)
   1268       1.1      fvdl 	register struct ifnet *ifp;
   1269       1.1      fvdl 	u_long cmd;
   1270       1.1      fvdl 	caddr_t data;
   1271       1.1      fvdl {
   1272       1.1      fvdl 	struct ex_softc *sc = ifp->if_softc;
   1273       1.1      fvdl 	struct ifaddr *ifa = (struct ifaddr *)data;
   1274       1.1      fvdl 	struct ifreq *ifr = (struct ifreq *)data;
   1275       1.1      fvdl 	int s, error = 0;
   1276       1.1      fvdl 
   1277       1.1      fvdl 	s = splnet();
   1278       1.1      fvdl 
   1279       1.1      fvdl 	switch (cmd) {
   1280       1.1      fvdl 
   1281       1.1      fvdl 	case SIOCSIFADDR:
   1282       1.1      fvdl 		ifp->if_flags |= IFF_UP;
   1283       1.1      fvdl 		switch (ifa->ifa_addr->sa_family) {
   1284       1.1      fvdl #ifdef INET
   1285       1.1      fvdl 		case AF_INET:
   1286       1.1      fvdl 			ex_init(sc);
   1287       1.1      fvdl 			arp_ifinit(&sc->sc_ethercom.ec_if, ifa);
   1288       1.1      fvdl 			break;
   1289       1.1      fvdl #endif
   1290       1.1      fvdl #ifdef NS
   1291       1.1      fvdl 		case AF_NS:
   1292       1.1      fvdl 		    {
   1293       1.1      fvdl 			register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
   1294       1.1      fvdl 
   1295       1.1      fvdl 			if (ns_nullhost(*ina))
   1296       1.1      fvdl 				ina->x_host = *(union ns_host *)
   1297       1.1      fvdl 				    LLADDR(ifp->if_sadl);
   1298       1.1      fvdl 			else
   1299       1.1      fvdl 				bcopy(ina->x_host.c_host, LLADDR(ifp->if_sadl),
   1300       1.1      fvdl 				    ifp->if_addrlen);
   1301       1.1      fvdl 			/* Set new address. */
   1302       1.1      fvdl 			ex_init(sc);
   1303       1.1      fvdl 			break;
   1304       1.1      fvdl 		    }
   1305       1.1      fvdl #endif
   1306       1.1      fvdl 		default:
   1307       1.1      fvdl 			ex_init(sc);
   1308       1.1      fvdl 			break;
   1309       1.1      fvdl 		}
   1310       1.1      fvdl 		break;
   1311       1.1      fvdl 	case SIOCSIFMEDIA:
   1312       1.1      fvdl 	case SIOCGIFMEDIA:
   1313       1.1      fvdl 		error = ifmedia_ioctl(ifp, ifr, &sc->ex_mii.mii_media, cmd);
   1314       1.1      fvdl 		break;
   1315       1.1      fvdl 
   1316       1.1      fvdl 	case SIOCSIFFLAGS:
   1317       1.1      fvdl 		if ((ifp->if_flags & IFF_UP) == 0 &&
   1318       1.1      fvdl 		    (ifp->if_flags & IFF_RUNNING) != 0) {
   1319       1.1      fvdl 			/*
   1320       1.1      fvdl 			 * If interface is marked down and it is running, then
   1321       1.1      fvdl 			 * stop it.
   1322       1.1      fvdl 			 */
   1323       1.1      fvdl 			ex_stop(sc);
   1324       1.1      fvdl 			ifp->if_flags &= ~IFF_RUNNING;
   1325       1.1      fvdl 		} else if ((ifp->if_flags & IFF_UP) != 0 &&
   1326       1.1      fvdl 			   (ifp->if_flags & IFF_RUNNING) == 0) {
   1327       1.1      fvdl 			/*
   1328       1.1      fvdl 			 * If interface is marked up and it is stopped, then
   1329       1.1      fvdl 			 * start it.
   1330       1.1      fvdl 			 */
   1331       1.1      fvdl 			ex_init(sc);
   1332       1.4   thorpej 		} else if ((ifp->if_flags & IFF_UP) != 0) {
   1333       1.4   thorpej 			/*
   1334       1.4   thorpej 			 * Deal with other flags that change hardware
   1335       1.4   thorpej 			 * state, i.e. IFF_PROMISC.
   1336       1.4   thorpej 			 */
   1337       1.1      fvdl 			ex_set_mc(sc);
   1338       1.4   thorpej 		}
   1339       1.1      fvdl 		break;
   1340       1.1      fvdl 
   1341       1.1      fvdl 	case SIOCADDMULTI:
   1342       1.1      fvdl 	case SIOCDELMULTI:
   1343       1.1      fvdl 		error = (cmd == SIOCADDMULTI) ?
   1344       1.1      fvdl 		    ether_addmulti(ifr, &sc->sc_ethercom) :
   1345       1.1      fvdl 		    ether_delmulti(ifr, &sc->sc_ethercom);
   1346       1.1      fvdl 
   1347       1.1      fvdl 		if (error == ENETRESET) {
   1348       1.1      fvdl 			/*
   1349       1.1      fvdl 			 * Multicast list has changed; set the hardware filter
   1350       1.1      fvdl 			 * accordingly.
   1351       1.1      fvdl 			 */
   1352       1.1      fvdl 			ex_set_mc(sc);
   1353       1.1      fvdl 			error = 0;
   1354       1.1      fvdl 		}
   1355       1.1      fvdl 		break;
   1356       1.1      fvdl 
   1357       1.1      fvdl 	default:
   1358       1.1      fvdl 		error = EINVAL;
   1359       1.1      fvdl 		break;
   1360       1.1      fvdl 	}
   1361       1.1      fvdl 
   1362       1.1      fvdl 	splx(s);
   1363       1.1      fvdl 	return (error);
   1364       1.1      fvdl }
   1365       1.1      fvdl 
   1366       1.1      fvdl void
   1367       1.1      fvdl ex_getstats(sc)
   1368       1.1      fvdl 	struct ex_softc *sc;
   1369       1.1      fvdl {
   1370       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
   1371       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
   1372       1.1      fvdl 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1373       1.1      fvdl 	u_int8_t upperok;
   1374       1.1      fvdl 
   1375       1.1      fvdl 	GO_WINDOW(6);
   1376       1.1      fvdl 	upperok = bus_space_read_1(iot, ioh, UPPER_FRAMES_OK);
   1377       1.1      fvdl 	ifp->if_ipackets += bus_space_read_1(iot, ioh, RX_FRAMES_OK);
   1378       1.1      fvdl 	ifp->if_ipackets += (upperok & 0x03) << 8;
   1379       1.1      fvdl 	ifp->if_opackets += bus_space_read_1(iot, ioh, TX_FRAMES_OK);
   1380       1.1      fvdl 	ifp->if_opackets += (upperok & 0x30) << 4;
   1381       1.1      fvdl 	ifp->if_ierrors += bus_space_read_1(iot, ioh, RX_OVERRUNS);
   1382       1.1      fvdl 	ifp->if_collisions += bus_space_read_1(iot, ioh, TX_COLLISIONS);
   1383       1.1      fvdl 	/*
   1384       1.1      fvdl 	 * There seems to be no way to get the exact number of collisions,
   1385       1.1      fvdl 	 * this is the number that occured at the very least.
   1386       1.1      fvdl 	 */
   1387       1.1      fvdl 	ifp->if_collisions += 2 * bus_space_read_1(iot, ioh,
   1388       1.1      fvdl 	    TX_AFTER_X_COLLISIONS);
   1389       1.1      fvdl 	ifp->if_ibytes += bus_space_read_2(iot, ioh, RX_TOTAL_OK);
   1390       1.1      fvdl 	ifp->if_obytes += bus_space_read_2(iot, ioh, TX_TOTAL_OK);
   1391       1.1      fvdl 
   1392       1.1      fvdl 	/*
   1393       1.1      fvdl 	 * Clear the following to avoid stats overflow interrupts
   1394       1.1      fvdl 	 */
   1395      1.12  drochner 	bus_space_read_1(iot, ioh, TX_DEFERRALS);
   1396       1.1      fvdl 	bus_space_read_1(iot, ioh, TX_AFTER_1_COLLISION);
   1397       1.1      fvdl 	bus_space_read_1(iot, ioh, TX_NO_SQE);
   1398       1.1      fvdl 	bus_space_read_1(iot, ioh, TX_CD_LOST);
   1399       1.1      fvdl 	GO_WINDOW(4);
   1400       1.1      fvdl 	bus_space_read_1(iot, ioh, ELINK_W4_BADSSD);
   1401       1.1      fvdl 	upperok = bus_space_read_1(iot, ioh, ELINK_W4_UBYTESOK);
   1402       1.1      fvdl 	ifp->if_ibytes += (upperok & 0x0f) << 16;
   1403       1.1      fvdl 	ifp->if_obytes += (upperok & 0xf0) << 12;
   1404       1.1      fvdl 	GO_WINDOW(1);
   1405       1.1      fvdl }
   1406       1.1      fvdl 
   1407       1.1      fvdl void
   1408       1.1      fvdl ex_printstats(sc)
   1409       1.1      fvdl 	struct ex_softc *sc;
   1410       1.1      fvdl {
   1411       1.1      fvdl 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1412       1.1      fvdl 
   1413       1.1      fvdl 	ex_getstats(sc);
   1414       1.1      fvdl 	printf("in %ld out %ld ierror %ld oerror %ld ibytes %ld obytes %ld\n",
   1415       1.1      fvdl 	    ifp->if_ipackets, ifp->if_opackets, ifp->if_ierrors,
   1416       1.1      fvdl 	    ifp->if_oerrors, ifp->if_ibytes, ifp->if_obytes);
   1417       1.1      fvdl }
   1418       1.1      fvdl 
   1419       1.1      fvdl void
   1420       1.1      fvdl ex_tick(arg)
   1421       1.1      fvdl 	void *arg;
   1422       1.1      fvdl {
   1423       1.1      fvdl 	struct ex_softc *sc = arg;
   1424       1.1      fvdl 	int s = splnet();
   1425       1.1      fvdl 
   1426       1.1      fvdl 	if (sc->ex_conf & EX_CONF_MII)
   1427       1.1      fvdl 		mii_tick(&sc->ex_mii);
   1428       1.1      fvdl 
   1429       1.1      fvdl 	if (!(bus_space_read_2((sc)->sc_iot, (sc)->sc_ioh, ELINK_STATUS)
   1430       1.1      fvdl 	    & S_COMMAND_IN_PROGRESS))
   1431       1.1      fvdl 		ex_getstats(sc);
   1432       1.1      fvdl 
   1433       1.1      fvdl 	splx(s);
   1434       1.1      fvdl 
   1435       1.1      fvdl 	timeout(ex_tick, sc, hz);
   1436       1.1      fvdl }
   1437       1.1      fvdl 
   1438       1.1      fvdl 
   1439       1.1      fvdl void
   1440       1.1      fvdl ex_reset(sc)
   1441       1.1      fvdl 	struct ex_softc *sc;
   1442       1.1      fvdl {
   1443       1.1      fvdl 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, ELINK_COMMAND, GLOBAL_RESET);
   1444      1.10      dean 	delay(400);
   1445       1.1      fvdl 	ex_waitcmd(sc);
   1446       1.1      fvdl }
   1447       1.1      fvdl 
   1448       1.1      fvdl void
   1449       1.1      fvdl ex_watchdog(ifp)
   1450       1.1      fvdl 	struct ifnet *ifp;
   1451       1.1      fvdl {
   1452       1.1      fvdl 	struct ex_softc *sc = ifp->if_softc;
   1453       1.1      fvdl 
   1454       1.1      fvdl 	log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
   1455       1.1      fvdl 	++sc->sc_ethercom.ec_if.if_oerrors;
   1456       1.1      fvdl 
   1457       1.1      fvdl 	ex_reset(sc);
   1458       1.1      fvdl 	ex_init(sc);
   1459       1.1      fvdl }
   1460       1.1      fvdl 
   1461       1.1      fvdl void
   1462       1.1      fvdl ex_stop(sc)
   1463       1.1      fvdl 	struct ex_softc *sc;
   1464       1.1      fvdl {
   1465       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
   1466       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
   1467       1.1      fvdl 	struct ifnet *ifp = &sc->sc_ethercom.ec_if;
   1468       1.1      fvdl 	struct ex_txdesc *tx;
   1469       1.1      fvdl 	struct ex_rxdesc *rx;
   1470       1.1      fvdl 	int i;
   1471       1.1      fvdl 
   1472       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, RX_DISABLE);
   1473       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, TX_DISABLE);
   1474       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, STOP_TRANSCEIVER);
   1475       1.1      fvdl 
   1476       1.1      fvdl 	for (tx = sc->tx_head ; tx != NULL; tx = tx->tx_next) {
   1477       1.1      fvdl 		if (tx->tx_mbhead == NULL)
   1478       1.1      fvdl 			continue;
   1479       1.1      fvdl 		m_freem(tx->tx_mbhead);
   1480       1.1      fvdl 		tx->tx_mbhead = NULL;
   1481       1.1      fvdl 		bus_dmamap_unload(sc->sc_dmat, tx->tx_dmamap);
   1482       1.1      fvdl 		tx->tx_dpd->dpd_fsh = tx->tx_dpd->dpd_nextptr = 0;
   1483       1.1      fvdl 		bus_dmamap_sync(sc->sc_dmat, sc->sc_dpd_dmamap,
   1484       1.1      fvdl 		    ((caddr_t)tx->tx_dpd - (caddr_t)sc->sc_dpd),
   1485       1.1      fvdl 		    sizeof (struct ex_dpd),
   1486       1.1      fvdl 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1487       1.1      fvdl 	}
   1488       1.1      fvdl 	sc->tx_tail = sc->tx_head = NULL;
   1489       1.1      fvdl 	ex_init_txdescs(sc);
   1490       1.1      fvdl 
   1491       1.1      fvdl 	sc->rx_tail = sc->rx_head = 0;
   1492       1.1      fvdl 	for (i = 0; i < EX_NUPD; i++) {
   1493       1.1      fvdl 		rx = &sc->sc_rxdescs[i];
   1494       1.1      fvdl 		if (rx->rx_mbhead != NULL) {
   1495       1.1      fvdl 			bus_dmamap_unload(sc->sc_dmat, rx->rx_dmamap);
   1496       1.1      fvdl 			m_freem(rx->rx_mbhead);
   1497       1.1      fvdl 			rx->rx_mbhead = NULL;
   1498       1.1      fvdl 		}
   1499       1.1      fvdl 		ex_add_rxbuf(sc, rx);
   1500       1.1      fvdl 	}
   1501       1.1      fvdl 
   1502       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_COMMAND, C_INTR_LATCH);
   1503       1.1      fvdl 
   1504       1.1      fvdl 	untimeout(ex_tick, sc);
   1505  1.15.4.1      fvdl 	if (sc->ex_conf & EX_CONF_MII)
   1506  1.15.4.1      fvdl 		mii_down(&sc->ex_mii);
   1507       1.1      fvdl 
   1508       1.1      fvdl 	ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
   1509       1.1      fvdl 	ifp->if_timer = 0;
   1510       1.1      fvdl }
   1511       1.1      fvdl 
   1512       1.1      fvdl static void
   1513       1.1      fvdl ex_init_txdescs(sc)
   1514       1.1      fvdl 	struct ex_softc *sc;
   1515       1.1      fvdl {
   1516       1.1      fvdl 	int i;
   1517       1.1      fvdl 
   1518       1.1      fvdl 	for (i = 0; i < EX_NDPD; i++) {
   1519       1.1      fvdl 		sc->sc_txdescs[i].tx_dmamap = sc->sc_tx_dmamaps[i];
   1520       1.1      fvdl 		sc->sc_txdescs[i].tx_dpd = &sc->sc_dpd[i];
   1521       1.1      fvdl 		if (i < EX_NDPD - 1)
   1522       1.1      fvdl 			sc->sc_txdescs[i].tx_next = &sc->sc_txdescs[i + 1];
   1523       1.1      fvdl 		else
   1524       1.1      fvdl 			sc->sc_txdescs[i].tx_next = NULL;
   1525       1.1      fvdl 	}
   1526       1.1      fvdl 	sc->tx_free = &sc->sc_txdescs[0];
   1527       1.1      fvdl 	sc->tx_ftail = &sc->sc_txdescs[EX_NDPD-1];
   1528       1.1      fvdl }
   1529       1.1      fvdl 
   1530       1.1      fvdl 
   1531       1.1      fvdl /*
   1532       1.1      fvdl  * Before reboots, reset card completely.
   1533       1.1      fvdl  */
   1534       1.1      fvdl static void
   1535       1.1      fvdl ex_shutdown(arg)
   1536       1.1      fvdl 	void *arg;
   1537       1.1      fvdl {
   1538       1.1      fvdl 	register struct ex_softc *sc = arg;
   1539       1.1      fvdl 
   1540       1.1      fvdl 	ex_stop(sc);
   1541       1.1      fvdl }
   1542       1.1      fvdl 
   1543       1.1      fvdl /*
   1544       1.1      fvdl  * Read EEPROM data.
   1545       1.1      fvdl  * XXX what to do if EEPROM doesn't unbusy?
   1546       1.1      fvdl  */
   1547       1.1      fvdl u_int16_t
   1548       1.1      fvdl ex_read_eeprom(sc, offset)
   1549       1.1      fvdl 	struct ex_softc *sc;
   1550       1.1      fvdl 	int offset;
   1551       1.1      fvdl {
   1552       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
   1553       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
   1554       1.1      fvdl 	u_int16_t data = 0;
   1555       1.1      fvdl 
   1556       1.1      fvdl 	GO_WINDOW(0);
   1557       1.1      fvdl 	if (ex_eeprom_busy(sc))
   1558       1.1      fvdl 		goto out;
   1559       1.8  jonathan 	switch (sc->ex_bustype) {
   1560       1.8  jonathan 	case EX_BUS_PCI:
   1561       1.8  jonathan 		bus_space_write_1(iot, ioh, ELINK_W0_EEPROM_COMMAND,
   1562       1.8  jonathan  		    READ_EEPROM | (offset & 0x3f));
   1563       1.8  jonathan 		break;
   1564       1.8  jonathan 	case EX_BUS_CARDBUS:
   1565       1.8  jonathan 		bus_space_write_2(iot, ioh, ELINK_W0_EEPROM_COMMAND,
   1566       1.8  jonathan 		    0x230 + (offset & 0x3f));
   1567       1.8  jonathan 		break;
   1568       1.8  jonathan 	}
   1569       1.1      fvdl 	if (ex_eeprom_busy(sc))
   1570       1.1      fvdl 		goto out;
   1571       1.1      fvdl 	data = bus_space_read_2(iot, ioh, ELINK_W0_EEPROM_DATA);
   1572       1.1      fvdl out:
   1573       1.1      fvdl 	return data;
   1574       1.1      fvdl }
   1575       1.1      fvdl 
   1576       1.1      fvdl static int
   1577       1.1      fvdl ex_eeprom_busy(sc)
   1578       1.1      fvdl 	struct ex_softc *sc;
   1579       1.1      fvdl {
   1580       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
   1581       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
   1582       1.1      fvdl 	int i = 100;
   1583       1.1      fvdl 
   1584       1.1      fvdl 	while (i--) {
   1585       1.1      fvdl 		if (!(bus_space_read_2(iot, ioh, ELINK_W0_EEPROM_COMMAND) &
   1586       1.1      fvdl 		    EEPROM_BUSY))
   1587       1.1      fvdl 			return 0;
   1588       1.1      fvdl 		delay(100);
   1589       1.1      fvdl 	}
   1590       1.1      fvdl 	printf("\n%s: eeprom stays busy.\n", sc->sc_dev.dv_xname);
   1591       1.1      fvdl 	return (1);
   1592       1.1      fvdl }
   1593       1.1      fvdl 
   1594       1.1      fvdl /*
   1595       1.1      fvdl  * Create a new rx buffer and add it to the 'soft' rx list.
   1596       1.1      fvdl  */
   1597       1.1      fvdl static int
   1598       1.1      fvdl ex_add_rxbuf(sc, rxd)
   1599       1.1      fvdl 	struct ex_softc *sc;
   1600       1.1      fvdl 	struct ex_rxdesc *rxd;
   1601       1.1      fvdl {
   1602       1.1      fvdl 	struct mbuf *m, *oldm;
   1603       1.1      fvdl 	bus_dmamap_t rxmap;
   1604       1.1      fvdl 	int error, rval = 0;
   1605       1.1      fvdl 
   1606       1.1      fvdl 	oldm = rxd->rx_mbhead;
   1607       1.1      fvdl 	rxmap = rxd->rx_dmamap;
   1608       1.1      fvdl 
   1609       1.1      fvdl 	MGETHDR(m, M_DONTWAIT, MT_DATA);
   1610       1.1      fvdl 	if (m != NULL) {
   1611       1.1      fvdl 		MCLGET(m, M_DONTWAIT);
   1612       1.1      fvdl 		if ((m->m_flags & M_EXT) == 0) {
   1613       1.1      fvdl 			m_freem(m);
   1614       1.1      fvdl 			if (oldm == NULL)
   1615       1.1      fvdl 				return 1;
   1616       1.1      fvdl 			m = oldm;
   1617       1.1      fvdl 			m->m_data = m->m_ext.ext_buf;
   1618       1.1      fvdl 			rval = 1;
   1619       1.1      fvdl 		}
   1620       1.1      fvdl 	} else {
   1621       1.1      fvdl 		if (oldm == NULL)
   1622       1.1      fvdl 			return 1;
   1623       1.1      fvdl 		m = oldm;
   1624       1.1      fvdl 		m->m_data = m->m_ext.ext_buf;
   1625       1.1      fvdl 		rval = 1;
   1626       1.1      fvdl 	}
   1627       1.1      fvdl 
   1628       1.1      fvdl 	/*
   1629       1.1      fvdl 	 * Setup the DMA map for this receive buffer.
   1630       1.1      fvdl 	 */
   1631       1.1      fvdl 	if (m != oldm) {
   1632       1.1      fvdl 		if (oldm != NULL)
   1633       1.1      fvdl 			bus_dmamap_unload(sc->sc_dmat, rxmap);
   1634       1.1      fvdl 		error = bus_dmamap_load(sc->sc_dmat, rxmap,
   1635       1.1      fvdl 		    m->m_ext.ext_buf, MCLBYTES, NULL, BUS_DMA_NOWAIT);
   1636       1.1      fvdl 		if (error) {
   1637       1.1      fvdl 			printf("%s: can't load rx buffer, error = %d\n",
   1638       1.1      fvdl 			    sc->sc_dev.dv_xname, error);
   1639       1.1      fvdl 			panic("ex_add_rxbuf");	/* XXX */
   1640       1.1      fvdl 		}
   1641       1.1      fvdl 	}
   1642       1.1      fvdl 
   1643       1.1      fvdl 	/*
   1644       1.1      fvdl 	 * Align for data after 14 byte header.
   1645       1.1      fvdl 	 */
   1646       1.1      fvdl 	m->m_data += 2;
   1647       1.1      fvdl 
   1648       1.1      fvdl 	rxd->rx_mbhead = m;
   1649       1.9   thorpej 	rxd->rx_upd->upd_pktstatus = htopci(MCLBYTES - 2);
   1650       1.9   thorpej 	rxd->rx_upd->upd_frags[0].fr_addr =
   1651       1.9   thorpej 	    htopci(rxmap->dm_segs[0].ds_addr + 2);
   1652       1.1      fvdl 	rxd->rx_upd->upd_nextptr = 0;
   1653       1.1      fvdl 
   1654       1.1      fvdl 	/*
   1655       1.1      fvdl 	 * Attach it to the end of the list.
   1656       1.1      fvdl 	 */
   1657       1.1      fvdl 	if (sc->rx_head != NULL) {
   1658       1.1      fvdl 		sc->rx_tail->rx_next = rxd;
   1659       1.9   thorpej 		sc->rx_tail->rx_upd->upd_nextptr = htopci(sc->sc_upddma +
   1660       1.9   thorpej 		    ((caddr_t)rxd->rx_upd - (caddr_t)sc->sc_upd));
   1661       1.1      fvdl 		bus_dmamap_sync(sc->sc_dmat, sc->sc_upd_dmamap,
   1662       1.1      fvdl 		    (caddr_t)sc->rx_tail->rx_upd - (caddr_t)sc->sc_upd,
   1663       1.1      fvdl 		    sizeof (struct ex_upd),
   1664       1.1      fvdl 		    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1665       1.1      fvdl 	} else {
   1666       1.1      fvdl 		sc->rx_head = rxd;
   1667       1.1      fvdl 	}
   1668       1.1      fvdl 	sc->rx_tail = rxd;
   1669       1.1      fvdl 
   1670       1.1      fvdl 	bus_dmamap_sync(sc->sc_dmat, rxmap, 0, rxmap->dm_mapsize,
   1671       1.1      fvdl 	    BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1672       1.1      fvdl 	bus_dmamap_sync(sc->sc_dmat, sc->sc_upd_dmamap,
   1673       1.1      fvdl 	    ((caddr_t)rxd->rx_upd - (caddr_t)sc->sc_upd),
   1674       1.1      fvdl 	    sizeof (struct ex_upd), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
   1675       1.1      fvdl 	return (rval);
   1676       1.1      fvdl }
   1677       1.1      fvdl 
   1678       1.1      fvdl void
   1679       1.1      fvdl ex_mii_setbit(v, bit)
   1680       1.1      fvdl 	void *v;
   1681       1.1      fvdl 	u_int16_t bit;
   1682       1.1      fvdl {
   1683       1.1      fvdl 	struct ex_softc *sc = v;
   1684       1.1      fvdl 	u_int16_t val;
   1685       1.1      fvdl 
   1686       1.1      fvdl 	val = bus_space_read_2(sc->sc_iot, sc->sc_ioh, ELINK_W4_PHYSMGMT);
   1687       1.1      fvdl 	val |= bit;
   1688       1.1      fvdl 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, ELINK_W4_PHYSMGMT, val);
   1689       1.1      fvdl }
   1690       1.1      fvdl 
   1691       1.1      fvdl void
   1692       1.1      fvdl ex_mii_clrbit(v, bit)
   1693       1.1      fvdl 	void *v;
   1694       1.1      fvdl 	u_int16_t bit;
   1695       1.1      fvdl {
   1696       1.1      fvdl 	struct ex_softc *sc = v;
   1697       1.1      fvdl 	u_int16_t val;
   1698       1.1      fvdl 
   1699       1.1      fvdl 	val = bus_space_read_2(sc->sc_iot, sc->sc_ioh, ELINK_W4_PHYSMGMT);
   1700       1.1      fvdl 	val &= ~bit;
   1701       1.1      fvdl 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, ELINK_W4_PHYSMGMT, val);
   1702       1.1      fvdl }
   1703       1.1      fvdl 
   1704       1.1      fvdl u_int16_t
   1705       1.1      fvdl ex_mii_readbit(v, bit)
   1706       1.1      fvdl 	void *v;
   1707       1.1      fvdl 	u_int16_t bit;
   1708       1.1      fvdl {
   1709       1.1      fvdl 	struct ex_softc *sc = v;
   1710       1.1      fvdl 	u_int16_t val;
   1711       1.1      fvdl 
   1712       1.1      fvdl 	val = bus_space_read_2(sc->sc_iot, sc->sc_ioh, ELINK_W4_PHYSMGMT);
   1713       1.1      fvdl 	return (val & bit);
   1714       1.1      fvdl }
   1715       1.1      fvdl 
   1716       1.1      fvdl /*
   1717       1.1      fvdl  * The reason why all this stuff below is here, is that we need a special
   1718       1.1      fvdl  * readreg function. It needs to check if we're accessing the internal
   1719       1.1      fvdl  * PHY on 905B-TX boards, or not. If so, the read must fail immediately,
   1720       1.1      fvdl  * because 905B-TX boards seem to return garbage from the MII if you
   1721       1.1      fvdl  * try to access non-existing PHYs.
   1722       1.1      fvdl  */
   1723       1.1      fvdl 
   1724       1.1      fvdl int
   1725       1.1      fvdl ex_mii_readreg(v, phy, reg)
   1726       1.1      fvdl 	struct device *v;
   1727       1.1      fvdl 	int phy;
   1728       1.1      fvdl 	int reg;
   1729       1.1      fvdl {
   1730       1.1      fvdl 	struct ex_softc *sc = (struct ex_softc *)v;
   1731       1.1      fvdl 	int val = 0;
   1732       1.1      fvdl 	int err =0;
   1733       1.1      fvdl 	int i;
   1734       1.1      fvdl 
   1735       1.1      fvdl 	if ((sc->ex_conf & EX_CONF_INTPHY) && phy != ELINK_INTPHY_ID)
   1736       1.1      fvdl 		return 0;
   1737       1.1      fvdl 
   1738       1.1      fvdl 	GO_WINDOW(4);
   1739       1.1      fvdl 
   1740       1.1      fvdl 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, ELINK_W4_PHYSMGMT, 0);
   1741       1.1      fvdl 
   1742      1.14      fvdl 	ex_mii_setbit(sc, ELINK_PHY_DIR);
   1743      1.14      fvdl 	delay(1);
   1744      1.14      fvdl 	ex_mii_setbit(sc, ELINK_PHY_DIR|ELINK_PHY_DATA);
   1745      1.14      fvdl 	delay(1);
   1746      1.14      fvdl 
   1747       1.1      fvdl         for (i = 0; i < 32; i++) {
   1748      1.14      fvdl                 ex_mii_setbit(sc, ELINK_PHY_CLK);
   1749      1.14      fvdl 		delay(1);
   1750       1.1      fvdl                 ex_mii_clrbit(sc, ELINK_PHY_CLK);
   1751      1.14      fvdl 		delay(1);
   1752       1.1      fvdl         }
   1753       1.1      fvdl 	ex_mii_writebits(sc, MII_COMMAND_START, 2);
   1754       1.1      fvdl 	ex_mii_writebits(sc, MII_COMMAND_READ, 2);
   1755       1.1      fvdl 	ex_mii_writebits(sc, phy, 5);
   1756       1.1      fvdl 	ex_mii_writebits(sc, reg, 5);
   1757       1.1      fvdl 
   1758      1.14      fvdl 	ex_mii_clrbit(sc, ELINK_PHY_DATA|ELINK_PHY_CLK);
   1759      1.14      fvdl 	delay(1);
   1760      1.14      fvdl 	ex_mii_setbit(sc, ELINK_PHY_CLK);
   1761      1.14      fvdl 	delay(1);
   1762      1.14      fvdl 	ex_mii_clrbit(sc, ELINK_PHY_DIR|ELINK_PHY_CLK);
   1763      1.14      fvdl 	delay(1);
   1764       1.1      fvdl 	ex_mii_setbit(sc, ELINK_PHY_CLK);
   1765      1.14      fvdl 	delay(1);
   1766       1.1      fvdl 
   1767       1.1      fvdl 	err = ex_mii_readbit(sc, ELINK_PHY_DATA);
   1768       1.1      fvdl 
   1769       1.1      fvdl 	for (i = 0; i < 16; i++) {
   1770       1.1      fvdl 		val <<= 1;
   1771       1.1      fvdl 		ex_mii_clrbit(sc, ELINK_PHY_CLK);
   1772      1.14      fvdl 		delay(1);
   1773       1.1      fvdl 		if (err == 0 && ex_mii_readbit(sc, ELINK_PHY_DATA))
   1774       1.1      fvdl 				val |= 1;
   1775       1.1      fvdl 		ex_mii_setbit(sc, ELINK_PHY_CLK);
   1776      1.14      fvdl 		delay(1);
   1777       1.1      fvdl 	}
   1778       1.1      fvdl 	ex_mii_clrbit(sc, ELINK_PHY_CLK);
   1779      1.14      fvdl 	delay(1);
   1780       1.1      fvdl 	ex_mii_setbit(sc, ELINK_PHY_CLK);
   1781      1.14      fvdl 	delay(1);
   1782       1.1      fvdl 
   1783       1.1      fvdl 	GO_WINDOW(1);
   1784       1.1      fvdl 
   1785       1.1      fvdl 	return (err ? 0 : val);
   1786       1.1      fvdl }
   1787       1.1      fvdl 
   1788       1.1      fvdl static void
   1789       1.1      fvdl ex_mii_writebits(sc, data, nbits)
   1790       1.1      fvdl 	struct ex_softc *sc;
   1791       1.1      fvdl 	unsigned int data;
   1792       1.1      fvdl 	int nbits;
   1793       1.1      fvdl {
   1794       1.1      fvdl 	int i;
   1795       1.1      fvdl 
   1796       1.1      fvdl 	ex_mii_setbit(sc, ELINK_PHY_DIR);
   1797      1.14      fvdl 	ex_mii_clrbit(sc, ELINK_PHY_CLK);
   1798      1.14      fvdl 
   1799       1.1      fvdl 	for (i = 1 << (nbits -1); i; i = i >>  1) {
   1800       1.1      fvdl 		if (data & i)
   1801       1.1      fvdl 			ex_mii_setbit(sc, ELINK_PHY_DATA);
   1802       1.1      fvdl 		else
   1803       1.1      fvdl 			ex_mii_clrbit(sc, ELINK_PHY_DATA);
   1804      1.14      fvdl 		delay(1);
   1805      1.14      fvdl 		ex_mii_clrbit(sc, ELINK_PHY_CLK);
   1806      1.14      fvdl 		delay(1);
   1807       1.1      fvdl 		ex_mii_setbit(sc, ELINK_PHY_CLK);
   1808       1.1      fvdl 	}
   1809       1.1      fvdl }
   1810       1.1      fvdl 
   1811       1.1      fvdl void
   1812       1.1      fvdl ex_mii_writereg(v, phy, reg, data)
   1813       1.1      fvdl         struct device *v;
   1814       1.1      fvdl         int phy;
   1815       1.1      fvdl         int reg;
   1816       1.1      fvdl         int data;
   1817       1.1      fvdl {
   1818       1.1      fvdl 	struct ex_softc *sc = (struct ex_softc *)v;
   1819       1.1      fvdl 	int i;
   1820       1.1      fvdl 
   1821       1.1      fvdl 	GO_WINDOW(4);
   1822       1.1      fvdl 
   1823      1.14      fvdl 	ex_mii_setbit(sc, ELINK_PHY_DIR);
   1824      1.14      fvdl 	delay(1);
   1825      1.14      fvdl 	ex_mii_setbit(sc, ELINK_PHY_DIR|ELINK_PHY_DATA);
   1826      1.14      fvdl 	delay(1);
   1827       1.1      fvdl 	for (i = 0; i < 32; i++) {
   1828      1.14      fvdl                 ex_mii_setbit(sc, ELINK_PHY_CLK);
   1829      1.14      fvdl 		delay(1);
   1830      1.14      fvdl                 ex_mii_clrbit(sc, ELINK_PHY_CLK);
   1831      1.14      fvdl 		delay(1);
   1832       1.1      fvdl 	}
   1833       1.1      fvdl 	ex_mii_writebits(sc, MII_COMMAND_START, 2);
   1834       1.1      fvdl 	ex_mii_writebits(sc, MII_COMMAND_WRITE, 2);
   1835       1.1      fvdl 	ex_mii_writebits(sc, phy, 5);
   1836       1.1      fvdl 	ex_mii_writebits(sc, reg, 5);
   1837       1.1      fvdl 	ex_mii_writebits(sc, MII_COMMAND_ACK, 2);
   1838       1.1      fvdl 	ex_mii_writebits(sc, data, 16);
   1839       1.1      fvdl 
   1840      1.14      fvdl 	ex_mii_setbit(sc, ELINK_PHY_CLK);
   1841      1.14      fvdl 	delay(1);
   1842       1.1      fvdl 	ex_mii_clrbit(sc, ELINK_PHY_CLK);
   1843      1.14      fvdl 	delay(1);
   1844      1.14      fvdl 	ex_mii_clrbit(sc, ELINK_PHY_DIR);
   1845       1.1      fvdl 
   1846       1.1      fvdl 	GO_WINDOW(1);
   1847       1.1      fvdl }
   1848       1.1      fvdl 
   1849       1.1      fvdl void
   1850       1.1      fvdl ex_mii_statchg(v)
   1851       1.1      fvdl 	struct device *v;
   1852       1.1      fvdl {
   1853       1.1      fvdl 	struct ex_softc *sc = (struct ex_softc *)v;
   1854       1.1      fvdl 	bus_space_tag_t iot = sc->sc_iot;
   1855       1.1      fvdl 	bus_space_handle_t ioh = sc->sc_ioh;
   1856       1.1      fvdl 	int mctl;
   1857       1.1      fvdl 
   1858       1.1      fvdl 	/* XXX Update ifp->if_baudrate */
   1859       1.1      fvdl 
   1860       1.1      fvdl 	GO_WINDOW(3);
   1861       1.1      fvdl 	mctl = bus_space_read_2(iot, ioh, ELINK_W3_MAC_CONTROL);
   1862       1.1      fvdl 	if (sc->ex_mii.mii_media_active & IFM_FDX)
   1863       1.1      fvdl 		mctl |= MAC_CONTROL_FDX;
   1864       1.1      fvdl 	else
   1865       1.1      fvdl 		mctl &= ~MAC_CONTROL_FDX;
   1866       1.1      fvdl 	bus_space_write_2(iot, ioh, ELINK_W3_MAC_CONTROL, mctl);
   1867       1.1      fvdl 	GO_WINDOW(1);   /* back to operating window */
   1868       1.1      fvdl }
   1869