Home | History | Annotate | Line # | Download | only in isa
if_ix.c revision 1.6.8.2
      1  1.6.8.2    bouyer /*	$NetBSD: if_ix.c,v 1.6.8.2 2001/02/11 19:15:44 bouyer Exp $	*/
      2      1.1        pk 
      3      1.1        pk /*-
      4      1.1        pk  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5      1.1        pk  * All rights reserved.
      6      1.1        pk  *
      7      1.1        pk  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1        pk  * by Rafal K. Boni.
      9      1.1        pk  *
     10      1.1        pk  * Redistribution and use in source and binary forms, with or without
     11      1.1        pk  * modification, are permitted provided that the following conditions
     12      1.1        pk  * are met:
     13      1.1        pk  * 1. Redistributions of source code must retain the above copyright
     14      1.1        pk  *    notice, this list of conditions and the following disclaimer.
     15      1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     17      1.1        pk  *    documentation and/or other materials provided with the distribution.
     18      1.1        pk  * 3. All advertising materials mentioning features or use of this software
     19      1.1        pk  *    must display the following acknowledgement:
     20      1.1        pk  *	This product includes software developed by the NetBSD
     21      1.1        pk  *	Foundation, Inc. and its contributors.
     22      1.1        pk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1        pk  *    contributors may be used to endorse or promote products derived
     24      1.1        pk  *    from this software without specific prior written permission.
     25      1.1        pk  *
     26      1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1        pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1        pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1        pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1        pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1        pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1        pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1        pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1        pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1        pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1        pk  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1        pk  */
     38      1.1        pk 
     39      1.1        pk #include <sys/param.h>
     40      1.1        pk #include <sys/systm.h>
     41      1.1        pk #include <sys/mbuf.h>
     42      1.1        pk #include <sys/errno.h>
     43      1.1        pk #include <sys/device.h>
     44      1.1        pk #include <sys/protosw.h>
     45      1.1        pk #include <sys/socket.h>
     46      1.1        pk 
     47      1.1        pk #include <net/if.h>
     48      1.1        pk #include <net/if_dl.h>
     49      1.1        pk #include <net/if_types.h>
     50      1.1        pk #include <net/if_media.h>
     51      1.1        pk #include <net/if_ether.h>
     52      1.1        pk 
     53      1.1        pk #include <machine/cpu.h>
     54      1.1        pk #include <machine/bus.h>
     55      1.1        pk #include <machine/intr.h>
     56      1.1        pk 
     57      1.1        pk #include <dev/isa/isareg.h>
     58      1.1        pk #include <dev/isa/isavar.h>
     59      1.1        pk 
     60      1.1        pk #include <dev/ic/i82586reg.h>
     61      1.1        pk #include <dev/ic/i82586var.h>
     62      1.1        pk #include <dev/isa/if_ixreg.h>
     63      1.1        pk 
     64      1.1        pk #ifdef IX_DEBUG
     65      1.1        pk #define DPRINTF(x)	printf x
     66      1.1        pk #else
     67      1.2        pk #define DPRINTF(x)
     68      1.1        pk #endif
     69      1.1        pk 
     70      1.2        pk int ix_media[] = {
     71      1.1        pk 	IFM_ETHER | IFM_10_5,
     72      1.1        pk 	IFM_ETHER | IFM_10_2,
     73      1.1        pk 	IFM_ETHER | IFM_10_T,
     74      1.1        pk };
     75      1.1        pk #define NIX_MEDIA       (sizeof(ix_media) / sizeof(ix_media[0]))
     76      1.1        pk 
     77      1.1        pk struct ix_softc {
     78      1.2        pk 	struct ie_softc sc_ie;
     79      1.1        pk 
     80      1.2        pk 	bus_space_tag_t sc_regt;	/* space tag for registers */
     81      1.2        pk 	bus_space_handle_t sc_regh;	/* space handle for registers */
     82      1.1        pk 
     83  1.6.8.2    bouyer 	u_int8_t	use_pio;	/* use PIO rather than shared mem */
     84      1.2        pk 	u_int16_t	irq_encoded;	/* encoded IRQ */
     85      1.2        pk 	void		*sc_ih;		/* interrupt handle */
     86      1.1        pk };
     87      1.1        pk 
     88      1.1        pk static void 	ix_reset __P((struct ie_softc *, int));
     89      1.1        pk static void 	ix_atten __P((struct ie_softc *));
     90      1.1        pk static int 	ix_intrhook __P((struct ie_softc *, int));
     91      1.1        pk 
     92      1.2        pk static void     ix_copyin __P((struct ie_softc *, void *, int, size_t));
     93      1.1        pk static void     ix_copyout __P((struct ie_softc *, const void *, int, size_t));
     94      1.2        pk 
     95  1.6.8.2    bouyer static void	ix_bus_barrier __P((struct ie_softc *, int, int, int));
     96  1.6.8.2    bouyer 
     97      1.1        pk static u_int16_t ix_read_16 __P((struct ie_softc *, int));
     98      1.1        pk static void	ix_write_16 __P((struct ie_softc *, int, u_int16_t));
     99      1.1        pk static void	ix_write_24 __P((struct ie_softc *, int, int));
    100  1.6.8.2    bouyer static void	ix_zeromem  __P((struct ie_softc *, int, int));
    101      1.2        pk 
    102      1.1        pk static void	ix_mediastatus __P((struct ie_softc *, struct ifmediareq *));
    103      1.1        pk 
    104      1.3        pk static u_int16_t ix_read_eeprom __P((bus_space_tag_t, bus_space_handle_t, int));
    105      1.3        pk static void	ix_eeprom_outbits __P((bus_space_tag_t, bus_space_handle_t, int, int));
    106      1.3        pk static int	ix_eeprom_inbits  __P((bus_space_tag_t, bus_space_handle_t));
    107      1.3        pk static void	ix_eeprom_clock   __P((bus_space_tag_t, bus_space_handle_t, int));
    108      1.1        pk 
    109      1.1        pk int ix_match __P((struct device *, struct cfdata *, void *));
    110      1.1        pk void ix_attach __P((struct device *, struct device *, void *));
    111      1.1        pk 
    112      1.1        pk /*
    113      1.1        pk  * EtherExpress/16 support routines
    114      1.1        pk  */
    115      1.1        pk static void
    116      1.1        pk ix_reset(sc, why)
    117      1.2        pk 	struct ie_softc *sc;
    118      1.2        pk 	int why;
    119      1.1        pk {
    120      1.2        pk 	struct ix_softc* isc = (struct ix_softc *) sc;
    121      1.1        pk 
    122      1.2        pk 	switch (why) {
    123      1.2        pk 	case CHIP_PROBE:
    124      1.2        pk 		bus_space_write_1(isc->sc_regt, isc->sc_regh, IX_ECTRL,
    125      1.2        pk 				  IX_RESET_586);
    126      1.2        pk 		delay(100);
    127      1.2        pk 		bus_space_write_1(isc->sc_regt, isc->sc_regh, IX_ECTRL, 0);
    128      1.2        pk 		delay(100);
    129      1.2        pk 		break;
    130      1.1        pk 
    131      1.2        pk 	case CARD_RESET:
    132      1.2        pk 		break;
    133      1.1        pk     }
    134      1.1        pk }
    135      1.1        pk 
    136      1.1        pk static void
    137      1.1        pk ix_atten(sc)
    138      1.2        pk 	struct ie_softc *sc;
    139      1.1        pk {
    140      1.2        pk 	struct ix_softc* isc = (struct ix_softc *) sc;
    141      1.2        pk 	bus_space_write_1(isc->sc_regt, isc->sc_regh, IX_ATTN, 0);
    142      1.1        pk }
    143      1.1        pk 
    144      1.1        pk static u_int16_t
    145      1.3        pk ix_read_eeprom(iot, ioh, location)
    146      1.3        pk 	bus_space_tag_t iot;
    147      1.3        pk 	bus_space_handle_t ioh;
    148      1.2        pk 	int location;
    149      1.1        pk {
    150      1.2        pk 	int ectrl, edata;
    151      1.1        pk 
    152      1.3        pk 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    153      1.2        pk 	ectrl &= IX_ECTRL_MASK;
    154      1.2        pk 	ectrl |= IX_ECTRL_EECS;
    155      1.3        pk 	bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    156      1.2        pk 
    157      1.3        pk 	ix_eeprom_outbits(iot, ioh, IX_EEPROM_READ, IX_EEPROM_OPSIZE1);
    158      1.3        pk 	ix_eeprom_outbits(iot, ioh, location, IX_EEPROM_ADDR_SIZE);
    159      1.3        pk 	edata = ix_eeprom_inbits(iot, ioh);
    160      1.3        pk 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    161      1.2        pk 	ectrl &= ~(IX_RESET_ASIC | IX_ECTRL_EEDI | IX_ECTRL_EECS);
    162      1.3        pk 	bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    163      1.3        pk 	ix_eeprom_clock(iot, ioh, 1);
    164      1.3        pk 	ix_eeprom_clock(iot, ioh, 0);
    165      1.2        pk 	return (edata);
    166      1.1        pk }
    167      1.1        pk 
    168      1.1        pk static void
    169      1.3        pk ix_eeprom_outbits(iot, ioh, edata, count)
    170      1.3        pk 	bus_space_tag_t iot;
    171      1.3        pk 	bus_space_handle_t ioh;
    172      1.2        pk 	int edata, count;
    173      1.1        pk {
    174      1.2        pk 	int ectrl, i;
    175      1.1        pk 
    176      1.3        pk 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    177      1.2        pk 	ectrl &= ~IX_RESET_ASIC;
    178      1.2        pk 	for (i = count - 1; i >= 0; i--) {
    179      1.2        pk 		ectrl &= ~IX_ECTRL_EEDI;
    180      1.2        pk 		if (edata & (1 << i)) {
    181      1.2        pk 			ectrl |= IX_ECTRL_EEDI;
    182      1.2        pk 		}
    183      1.3        pk 		bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    184      1.2        pk 		delay(1);	/* eeprom data must be setup for 0.4 uSec */
    185      1.3        pk 		ix_eeprom_clock(iot, ioh, 1);
    186      1.3        pk 		ix_eeprom_clock(iot, ioh, 0);
    187      1.2        pk 	}
    188      1.2        pk 	ectrl &= ~IX_ECTRL_EEDI;
    189      1.3        pk 	bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    190      1.2        pk 	delay(1);		/* eeprom data must be held for 0.4 uSec */
    191      1.1        pk }
    192      1.1        pk 
    193      1.1        pk static int
    194      1.3        pk ix_eeprom_inbits(iot, ioh)
    195      1.3        pk 	bus_space_tag_t iot;
    196      1.3        pk 	bus_space_handle_t ioh;
    197      1.1        pk {
    198      1.2        pk 	int ectrl, edata, i;
    199      1.1        pk 
    200      1.3        pk 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    201      1.2        pk 	ectrl &= ~IX_RESET_ASIC;
    202      1.2        pk 	for (edata = 0, i = 0; i < 16; i++) {
    203      1.2        pk 		edata = edata << 1;
    204      1.3        pk 		ix_eeprom_clock(iot, ioh, 1);
    205      1.3        pk 		ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    206      1.2        pk 		if (ectrl & IX_ECTRL_EEDO) {
    207      1.2        pk 			edata |= 1;
    208      1.2        pk 		}
    209      1.3        pk 		ix_eeprom_clock(iot, ioh, 0);
    210      1.2        pk 	}
    211      1.2        pk 	return (edata);
    212      1.1        pk }
    213      1.1        pk 
    214      1.1        pk static void
    215      1.3        pk ix_eeprom_clock(iot, ioh, state)
    216      1.3        pk 	bus_space_tag_t iot;
    217      1.3        pk 	bus_space_handle_t ioh;
    218      1.2        pk 	int state;
    219      1.1        pk {
    220      1.2        pk 	int ectrl;
    221      1.1        pk 
    222      1.3        pk 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    223      1.2        pk 	ectrl &= ~(IX_RESET_ASIC | IX_ECTRL_EESK);
    224      1.2        pk 	if (state) {
    225      1.2        pk 		ectrl |= IX_ECTRL_EESK;
    226      1.2        pk 	}
    227      1.3        pk 	bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    228      1.2        pk 	delay(9);		/* EESK must be stable for 8.38 uSec */
    229      1.1        pk }
    230      1.1        pk 
    231      1.1        pk static int
    232      1.1        pk ix_intrhook(sc, where)
    233      1.1        pk 	struct ie_softc *sc;
    234      1.1        pk 	int where;
    235      1.1        pk {
    236      1.2        pk 	struct ix_softc* isc = (struct ix_softc *) sc;
    237      1.1        pk 
    238      1.2        pk 	switch (where) {
    239      1.2        pk 	case INTR_ENTER:
    240      1.2        pk 		/* entering ISR: disable card interrupts */
    241      1.2        pk 		bus_space_write_1(isc->sc_regt, isc->sc_regh,
    242      1.2        pk 				  IX_IRQ, isc->irq_encoded);
    243      1.2        pk 		break;
    244      1.2        pk 
    245      1.2        pk 	case INTR_EXIT:
    246      1.2        pk 		/* exiting ISR: re-enable card interrupts */
    247      1.2        pk 		bus_space_write_1(isc->sc_regt, isc->sc_regh, IX_IRQ,
    248      1.2        pk     				  isc->irq_encoded | IX_IRQ_ENABLE);
    249      1.1        pk 	break;
    250      1.1        pk     }
    251      1.1        pk 
    252      1.1        pk     return 1;
    253      1.1        pk }
    254      1.1        pk 
    255      1.1        pk 
    256      1.1        pk static void
    257      1.1        pk ix_copyin (sc, dst, offset, size)
    258      1.1        pk         struct ie_softc *sc;
    259      1.1        pk         void *dst;
    260      1.1        pk         int offset;
    261      1.1        pk         size_t size;
    262      1.1        pk {
    263  1.6.8.2    bouyer 	int i, dribble;
    264      1.2        pk 	u_int8_t* bptr = dst;
    265  1.6.8.2    bouyer 	u_int16_t* wptr = dst;
    266  1.6.8.2    bouyer 	struct ix_softc* isc = (struct ix_softc *) sc;
    267      1.1        pk 
    268  1.6.8.2    bouyer 	if (isc->use_pio) {
    269  1.6.8.2    bouyer 		/* Reset read pointer to the specified offset */
    270  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
    271  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_READ);
    272  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_READPTR, offset);
    273  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_READPTR, 2,
    274  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    275  1.6.8.2    bouyer 	} else {
    276      1.2        pk 	bus_space_barrier(sc->bt, sc->bh, offset, size,
    277      1.2        pk 			  BUS_SPACE_BARRIER_READ);
    278  1.6.8.2    bouyer 	}
    279      1.1        pk 
    280      1.2        pk 	if (offset % 2) {
    281  1.6.8.2    bouyer 		if (isc->use_pio)
    282  1.6.8.2    bouyer 			*bptr = bus_space_read_1(sc->bt, sc->bh, IX_DATAPORT);
    283  1.6.8.2    bouyer 		else
    284      1.2        pk 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    285      1.2        pk 		offset++; bptr++; size--;
    286      1.2        pk 	}
    287      1.2        pk 
    288      1.2        pk 	dribble = size % 2;
    289  1.6.8.2    bouyer 	wptr = (u_int16_t*) bptr;
    290  1.6.8.2    bouyer 
    291  1.6.8.2    bouyer 	if (isc->use_pio) {
    292  1.6.8.2    bouyer 		for(i = 0; i <  size / 2; i++) {
    293  1.6.8.2    bouyer 			*wptr = bus_space_read_2(sc->bt, sc->bh, IX_DATAPORT);
    294  1.6.8.2    bouyer 			wptr++;
    295  1.6.8.2    bouyer 		}
    296  1.6.8.2    bouyer 	} else {
    297  1.6.8.2    bouyer 		bus_space_read_region_2(sc->bt, sc->bh, offset,
    298  1.6.8.2    bouyer 					(u_int16_t *) bptr, size / 2);
    299  1.6.8.2    bouyer 	}
    300      1.2        pk 
    301      1.2        pk 	if (dribble) {
    302      1.2        pk 		bptr += size - 1;
    303      1.2        pk 		offset += size - 1;
    304  1.6.8.2    bouyer 
    305  1.6.8.2    bouyer 		if (isc->use_pio)
    306  1.6.8.2    bouyer 			*bptr = bus_space_read_1(sc->bt, sc->bh, IX_DATAPORT);
    307  1.6.8.2    bouyer 		else
    308      1.2        pk 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    309      1.2        pk 	}
    310      1.1        pk }
    311      1.1        pk 
    312      1.1        pk static void
    313      1.2        pk ix_copyout (sc, src, offset, size)
    314      1.1        pk         struct ie_softc *sc;
    315      1.1        pk         const void *src;
    316      1.1        pk         int offset;
    317      1.1        pk         size_t size;
    318      1.1        pk {
    319  1.6.8.2    bouyer 	int i, dribble;
    320      1.2        pk 	int osize = size;
    321      1.2        pk 	int ooffset = offset;
    322      1.2        pk 	const u_int8_t* bptr = src;
    323  1.6.8.2    bouyer 	const u_int16_t* wptr = src;
    324  1.6.8.2    bouyer 	struct ix_softc* isc = (struct ix_softc *) sc;
    325  1.6.8.2    bouyer 
    326  1.6.8.2    bouyer 	if (isc->use_pio) {
    327  1.6.8.2    bouyer 		/* Reset write pointer to the specified offset */
    328  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
    329  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2,
    330  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    331  1.6.8.2    bouyer 	}
    332      1.2        pk 
    333      1.2        pk 	if (offset % 2) {
    334  1.6.8.2    bouyer 		if (isc->use_pio)
    335  1.6.8.2    bouyer 			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, *bptr);
    336  1.6.8.2    bouyer 		else
    337      1.2        pk 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    338      1.2        pk 		offset++; bptr++; size--;
    339      1.2        pk 	}
    340      1.2        pk 
    341      1.2        pk 	dribble = size % 2;
    342  1.6.8.2    bouyer 	wptr = (u_int16_t*) bptr;
    343  1.6.8.2    bouyer 
    344  1.6.8.2    bouyer 	if (isc->use_pio) {
    345  1.6.8.2    bouyer 		for(i = 0; i < size / 2; i++) {
    346  1.6.8.2    bouyer 			bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, *wptr);
    347  1.6.8.2    bouyer 			wptr++;
    348  1.6.8.2    bouyer 		}
    349  1.6.8.2    bouyer 	} else {
    350  1.6.8.2    bouyer 		bus_space_write_region_2(sc->bt, sc->bh, offset,
    351  1.6.8.2    bouyer 					 (u_int16_t *)bptr, size / 2);
    352  1.6.8.2    bouyer 	}
    353  1.6.8.2    bouyer 
    354      1.2        pk 	if (dribble) {
    355      1.2        pk 		bptr += size - 1;
    356      1.2        pk 		offset += size - 1;
    357  1.6.8.2    bouyer 
    358  1.6.8.2    bouyer 		if (isc->use_pio)
    359  1.6.8.2    bouyer 			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, *bptr);
    360  1.6.8.2    bouyer 		else
    361      1.2        pk 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    362      1.2        pk 	}
    363      1.1        pk 
    364  1.6.8.2    bouyer 	if (isc->use_pio)
    365  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
    366  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    367  1.6.8.2    bouyer 	else
    368      1.2        pk 	bus_space_barrier(sc->bt, sc->bh, ooffset, osize,
    369      1.2        pk 			  BUS_SPACE_BARRIER_WRITE);
    370      1.1        pk }
    371      1.1        pk 
    372  1.6.8.2    bouyer static void
    373  1.6.8.2    bouyer ix_bus_barrier(sc, offset, length, flags)
    374  1.6.8.2    bouyer         struct ie_softc *sc;
    375  1.6.8.2    bouyer         int offset, length, flags;
    376  1.6.8.2    bouyer {
    377  1.6.8.2    bouyer 	struct ix_softc* isc = (struct ix_softc *) sc;
    378  1.6.8.2    bouyer 
    379  1.6.8.2    bouyer 	if (isc->use_pio)
    380  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2, flags);
    381  1.6.8.2    bouyer 	else
    382  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, offset, length, flags);
    383  1.6.8.2    bouyer }
    384  1.6.8.2    bouyer 
    385      1.1        pk static u_int16_t
    386      1.1        pk ix_read_16 (sc, offset)
    387      1.1        pk         struct ie_softc *sc;
    388      1.1        pk         int offset;
    389      1.1        pk {
    390  1.6.8.2    bouyer 	struct ix_softc* isc = (struct ix_softc *) sc;
    391  1.6.8.2    bouyer 
    392  1.6.8.2    bouyer 	if (isc->use_pio) {
    393  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
    394  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_READ);
    395  1.6.8.2    bouyer 
    396  1.6.8.2    bouyer 		/* Reset read pointer to the specified offset */
    397  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_READPTR, offset);
    398  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_READPTR, 2,
    399  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    400  1.6.8.2    bouyer 
    401  1.6.8.2    bouyer 		return bus_space_read_2(sc->bt, sc->bh, IX_DATAPORT);
    402  1.6.8.2    bouyer 	} else {
    403  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, offset, 2,
    404  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_READ);
    405      1.1        pk         return bus_space_read_2(sc->bt, sc->bh, offset);
    406  1.6.8.2    bouyer 	}
    407      1.1        pk }
    408      1.1        pk 
    409      1.1        pk static void
    410      1.2        pk ix_write_16 (sc, offset, value)
    411      1.1        pk         struct ie_softc *sc;
    412      1.1        pk         int offset;
    413      1.1        pk         u_int16_t value;
    414      1.1        pk {
    415  1.6.8.2    bouyer 	struct ix_softc* isc = (struct ix_softc *) sc;
    416  1.6.8.2    bouyer 
    417  1.6.8.2    bouyer 	if (isc->use_pio) {
    418  1.6.8.2    bouyer 		/* Reset write pointer to the specified offset */
    419  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
    420  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2,
    421  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    422  1.6.8.2    bouyer 
    423  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, value);
    424  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
    425  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    426  1.6.8.2    bouyer 	} else {
    427      1.1        pk         bus_space_write_2(sc->bt, sc->bh, offset, value);
    428  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, offset, 2,
    429  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    430  1.6.8.2    bouyer 	}
    431      1.1        pk }
    432      1.1        pk 
    433      1.1        pk static void
    434      1.1        pk ix_write_24 (sc, offset, addr)
    435      1.1        pk         struct ie_softc *sc;
    436      1.1        pk         int offset, addr;
    437      1.1        pk {
    438  1.6.8.2    bouyer 	char* ptr;
    439  1.6.8.2    bouyer 	struct ix_softc* isc = (struct ix_softc *) sc;
    440  1.6.8.2    bouyer 	int val = addr + (u_long) sc->sc_maddr - (u_long) sc->sc_iobase;
    441  1.6.8.2    bouyer 
    442  1.6.8.2    bouyer 	if (isc->use_pio) {
    443  1.6.8.2    bouyer 		/* Reset write pointer to the specified offset */
    444  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
    445  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2,
    446  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    447  1.6.8.2    bouyer 
    448  1.6.8.2    bouyer 		ptr = (char*) &val;
    449  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT,
    450  1.6.8.2    bouyer 						  *((u_int16_t *)ptr));
    451  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT,
    452  1.6.8.2    bouyer 						  *((u_int16_t *)(ptr + 2)));
    453  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
    454  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    455  1.6.8.2    bouyer 	} else {
    456  1.6.8.2    bouyer         	bus_space_write_4(sc->bt, sc->bh, offset, val);
    457  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, offset, 4,
    458  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    459  1.6.8.2    bouyer 	}
    460  1.6.8.2    bouyer }
    461  1.6.8.2    bouyer 
    462  1.6.8.2    bouyer static void
    463  1.6.8.2    bouyer ix_zeromem(sc, offset, count)
    464  1.6.8.2    bouyer         struct ie_softc *sc;
    465  1.6.8.2    bouyer         int offset, count;
    466  1.6.8.2    bouyer {
    467  1.6.8.2    bouyer 	int i;
    468  1.6.8.2    bouyer 	int dribble;
    469  1.6.8.2    bouyer 	struct ix_softc* isc = (struct ix_softc *) sc;
    470  1.6.8.2    bouyer 
    471  1.6.8.2    bouyer 	if (isc->use_pio) {
    472  1.6.8.2    bouyer 		/* Reset write pointer to the specified offset */
    473  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR, offset);
    474  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2,
    475  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    476  1.6.8.2    bouyer 
    477  1.6.8.2    bouyer 		if (offset % 2) {
    478  1.6.8.2    bouyer 			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, 0);
    479  1.6.8.2    bouyer 			count--;
    480  1.6.8.2    bouyer 		}
    481  1.6.8.2    bouyer 
    482  1.6.8.2    bouyer 	        dribble = count % 2;
    483  1.6.8.2    bouyer 		for(i = 0; i < count / 2; i++)
    484  1.6.8.2    bouyer 			bus_space_write_2(sc->bt, sc->bh, IX_DATAPORT, 0);
    485  1.6.8.2    bouyer 
    486  1.6.8.2    bouyer 		if (dribble)
    487  1.6.8.2    bouyer 			bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, 0);
    488  1.6.8.2    bouyer 
    489  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_DATAPORT, 2,
    490  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    491  1.6.8.2    bouyer 	} else {
    492  1.6.8.2    bouyer 		bus_space_set_region_1(sc->bt, sc->bh, offset, 0, count);
    493  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, offset, count,
    494  1.6.8.2    bouyer 						  BUS_SPACE_BARRIER_WRITE);
    495  1.6.8.2    bouyer 	}
    496      1.1        pk }
    497      1.1        pk 
    498      1.1        pk static void
    499      1.1        pk ix_mediastatus(sc, ifmr)
    500      1.2        pk         struct ie_softc *sc;
    501      1.2        pk         struct ifmediareq *ifmr;
    502      1.1        pk {
    503      1.1        pk         struct ifmedia *ifm = &sc->sc_media;
    504      1.1        pk 
    505      1.1        pk         /*
    506      1.2        pk          * The currently selected media is always the active media.
    507      1.1        pk          */
    508      1.1        pk         ifmr->ifm_active = ifm->ifm_cur->ifm_media;
    509      1.1        pk }
    510      1.1        pk 
    511      1.1        pk int
    512      1.1        pk ix_match(parent, cf, aux)
    513      1.2        pk 	struct device *parent;
    514      1.2        pk 	struct cfdata *cf;
    515      1.2        pk 	void *aux;
    516      1.1        pk {
    517      1.2        pk 	int i;
    518      1.2        pk 	int rv = 0;
    519      1.2        pk 	bus_addr_t maddr;
    520      1.2        pk 	bus_size_t msize;
    521      1.2        pk 	u_short checksum = 0;
    522      1.2        pk 	bus_space_handle_t ioh;
    523      1.3        pk 	bus_space_tag_t iot;
    524      1.2        pk 	u_int8_t val, bart_config;
    525      1.2        pk 	u_short pg, adjust, decode, edecode;
    526      1.3        pk 	u_short board_id, id_var1, id_var2, irq, irq_encoded;
    527      1.2        pk 	struct isa_attach_args * const ia = aux;
    528      1.2        pk 	short irq_translate[] = {0, 0x09, 0x03, 0x04, 0x05, 0x0a, 0x0b, 0};
    529      1.2        pk 
    530      1.3        pk 	iot = ia->ia_iot;
    531      1.3        pk 
    532      1.3        pk 	if (bus_space_map(iot, ia->ia_iobase,
    533      1.2        pk 			  IX_IOSIZE, 0, &ioh) != 0) {
    534      1.2        pk 		DPRINTF(("Can't map io space at 0x%x\n", ia->ia_iobase));
    535      1.2        pk 		return (0);
    536      1.2        pk 	}
    537      1.2        pk 
    538      1.2        pk 	/* XXX: reset any ee16 at the current iobase */
    539      1.3        pk 	bus_space_write_1(iot, ioh, IX_ECTRL, IX_RESET_ASIC);
    540      1.3        pk 	bus_space_write_1(iot, ioh, IX_ECTRL, 0);
    541      1.2        pk 	delay(240);
    542      1.2        pk 
    543      1.2        pk 	/* now look for ee16. */
    544      1.2        pk 	board_id = id_var1 = id_var2 = 0;
    545      1.2        pk 	for (i = 0; i < 4 ; i++) {
    546      1.3        pk 		id_var1 = bus_space_read_1(iot, ioh, IX_ID_PORT);
    547      1.2        pk 		id_var2 = ((id_var1 & 0x03) << 2);
    548      1.2        pk 		board_id |= (( id_var1 >> 4)  << id_var2);
    549      1.2        pk 	}
    550      1.2        pk 
    551      1.2        pk 	if (board_id != IX_ID) {
    552      1.2        pk 		DPRINTF(("BART ID mismatch (got 0x%04x, expected 0x%04x)\n",
    553      1.2        pk 			board_id, IX_ID));
    554      1.2        pk 		goto out;
    555      1.2        pk 	}
    556      1.2        pk 
    557      1.2        pk 	/*
    558      1.2        pk 	 * The shared RAM size and location of the EE16 is encoded into
    559      1.2        pk 	 * EEPROM location 6.  The location of the first set bit tells us
    560      1.2        pk 	 * the memory address (0xc0000 + (0x4000 * FSB)), where FSB is the
    561      1.2        pk 	 * number of the first set bit.  The zeroes are then shifted out,
    562      1.2        pk 	 * and the results is the memory size (1 = 16k, 3 = 32k, 7 = 48k,
    563      1.2        pk 	 * 0x0f = 64k).
    564      1.2        pk 	 *
    565      1.2        pk 	 * Examples:
    566      1.2        pk 	 *   0x3c -> 64k@0xc8000, 0x70 -> 48k@0xd0000, 0xc0 -> 32k@0xd8000
    567      1.2        pk 	 *   0x80 -> 16k@0xdc000.
    568      1.2        pk 	 *
    569      1.2        pk 	 * Side note: this comes from reading the old driver rather than
    570      1.2        pk 	 * from a more definitive source, so it could be out-of-whack
    571      1.2        pk 	 * with what the card can do...
    572      1.2        pk 	 */
    573      1.2        pk 
    574      1.3        pk 	val = ix_read_eeprom(iot, ioh, 6) & 0xff;
    575  1.6.8.2    bouyer 	for(pg = 0; pg < 8; pg++) {
    576      1.2        pk 		if (val & 1)
    577      1.2        pk 			break;
    578      1.2        pk 		val = val >> 1;
    579      1.2        pk 	}
    580      1.2        pk 
    581  1.6.8.2    bouyer 	if (pg == 8) {
    582      1.2        pk 		DPRINTF(("Invalid or unsupported memory config\n"));
    583      1.2        pk 		goto out;
    584      1.2        pk 	}
    585      1.2        pk 
    586  1.6.8.2    bouyer 	maddr = 0xc0000 + (pg * 0x4000);
    587      1.2        pk 
    588      1.2        pk 	switch (val) {
    589  1.6.8.2    bouyer 	case 0x00:
    590  1.6.8.2    bouyer 		msize = 0;
    591  1.6.8.2    bouyer 		break;
    592  1.6.8.2    bouyer 
    593      1.2        pk 	case 0x01:
    594      1.2        pk 		msize = 16 * 1024;
    595      1.2        pk 		break;
    596      1.2        pk 
    597      1.2        pk 	case 0x03:
    598      1.2        pk 		msize = 32 * 1024;
    599      1.2        pk 		break;
    600      1.2        pk 
    601      1.2        pk 	case 0x07:
    602      1.2        pk 		msize = 48 * 1024;
    603      1.2        pk 		break;
    604      1.2        pk 
    605      1.2        pk 	case 0x0f:
    606      1.2        pk 		msize = 64 * 1024;
    607      1.2        pk 		break;
    608      1.2        pk 
    609      1.2        pk 	default:
    610      1.2        pk 		DPRINTF(("invalid memory size %02x\n", val));
    611      1.2        pk 		goto out;
    612      1.2        pk 	}
    613      1.2        pk 
    614      1.2        pk 	if (ia->ia_maddr == ISACF_IOMEM_DEFAULT)
    615      1.2        pk 		ia->ia_maddr = maddr;
    616      1.2        pk 	else if (ia->ia_maddr != maddr) {
    617      1.2        pk 		DPRINTF((
    618      1.2        pk 		  "ix_match: memaddr of board @ 0x%x doesn't match config\n",
    619      1.2        pk 		  ia->ia_iobase));
    620      1.2        pk 		goto out;
    621      1.2        pk 	}
    622      1.2        pk 
    623      1.2        pk 	if (ia->ia_msize == ISACF_IOSIZ_DEFAULT)
    624      1.2        pk 		ia->ia_msize = msize;
    625      1.2        pk 	else if (ia->ia_msize != msize) {
    626      1.2        pk 		DPRINTF((
    627      1.2        pk 		   "ix_match: memsize of board @ 0x%x doesn't match config\n",
    628      1.2        pk 		   ia->ia_iobase));
    629      1.2        pk 		goto out;
    630      1.2        pk 	}
    631      1.2        pk 
    632      1.2        pk 	/* need to put the 586 in RESET, and leave it */
    633      1.3        pk 	bus_space_write_1(iot, ioh, IX_ECTRL, IX_RESET_586);
    634      1.2        pk 
    635      1.2        pk 	/* read the eeprom and checksum it, should == IX_ID */
    636      1.2        pk 	for(i = 0; i < 0x40; i++)
    637      1.3        pk 		checksum += ix_read_eeprom(iot, ioh, i);
    638      1.2        pk 
    639      1.2        pk 	if (checksum != IX_ID) {
    640      1.2        pk 		DPRINTF(("checksum mismatch (got 0x%04x, expected 0x%04x\n",
    641      1.2        pk 			checksum, IX_ID));
    642      1.2        pk 		goto out;
    643      1.2        pk 	}
    644      1.2        pk 
    645      1.2        pk 	/*
    646  1.6.8.2    bouyer 	 * Only do the following bit if using memory-mapped access.  For
    647  1.6.8.2    bouyer 	 * boards with no mapped memory, we use PIO.  We also use PIO for
    648  1.6.8.2    bouyer 	 * boards with 16K of mapped memory, as those setups don't seem
    649  1.6.8.2    bouyer 	 * to work otherwise.
    650      1.2        pk 	 */
    651  1.6.8.2    bouyer 	if (msize != 0 && msize != 16384) {
    652  1.6.8.2    bouyer 		/* Set board up with memory-mapping info */
    653      1.2        pk 	adjust = IX_MCTRL_FMCS16 | (pg & 0x3) << 2;
    654      1.2        pk 	decode = ((1 << (ia->ia_msize / 16384)) - 1) << pg;
    655      1.2        pk 	edecode = ((~decode >> 4) & 0xF0) | (decode >> 8);
    656      1.2        pk 
    657      1.3        pk 	bus_space_write_1(iot, ioh, IX_MEMDEC, decode & 0xFF);
    658      1.3        pk 	bus_space_write_1(iot, ioh, IX_MCTRL, adjust);
    659      1.3        pk 	bus_space_write_1(iot, ioh, IX_MPCTRL, (~decode & 0xFF));
    660      1.2        pk 
    661  1.6.8.2    bouyer 		/* XXX disable Exxx */
    662  1.6.8.2    bouyer 		bus_space_write_1(iot, ioh, IX_MECTRL, edecode);
    663  1.6.8.2    bouyer 	}
    664      1.2        pk 
    665      1.2        pk 	/*
    666      1.2        pk 	 * Get the encoded interrupt number from the EEPROM, check it
    667      1.2        pk 	 * against the passed in IRQ.  Issue a warning if they do not
    668      1.2        pk 	 * match, and fail the probe.  If irq is 'IRQUNK' then we
    669      1.2        pk 	 * use the EEPROM irq, and continue.
    670      1.2        pk 	 */
    671      1.3        pk 	irq_encoded = ix_read_eeprom(iot, ioh, IX_EEPROM_CONFIG1);
    672      1.3        pk 	irq_encoded = (irq_encoded & IX_EEPROM_IRQ) >> IX_EEPROM_IRQ_SHIFT;
    673      1.3        pk 	irq = irq_translate[irq_encoded];
    674      1.2        pk 	if (ia->ia_irq == ISACF_IRQ_DEFAULT)
    675      1.2        pk 		ia->ia_irq = irq;
    676      1.2        pk 	else if (irq != ia->ia_irq) {
    677      1.2        pk 		DPRINTF(("board IRQ %d does not match config\n", irq));
    678      1.2        pk 		goto out;
    679      1.2        pk 	}
    680      1.2        pk 
    681      1.2        pk 	/* disable the board interrupts */
    682      1.3        pk 	bus_space_write_1(iot, ioh, IX_IRQ, irq_encoded);
    683      1.2        pk 
    684      1.3        pk 	bart_config = bus_space_read_1(iot, ioh, IX_CONFIG);
    685      1.2        pk 	bart_config |= IX_BART_LOOPBACK;
    686      1.2        pk 	bart_config |= IX_BART_MCS16_TEST; /* inb doesn't get bit! */
    687      1.3        pk 	bus_space_write_1(iot, ioh, IX_CONFIG, bart_config);
    688      1.3        pk 	bart_config = bus_space_read_1(iot, ioh, IX_CONFIG);
    689      1.2        pk 
    690      1.3        pk 	bus_space_write_1(iot, ioh, IX_ECTRL, 0);
    691      1.2        pk 	delay(100);
    692      1.2        pk 
    693      1.2        pk 	rv = 1;
    694      1.2        pk 	ia->ia_iosize = IX_IOSIZE;
    695      1.2        pk 	DPRINTF(("ix_match: found board @ 0x%x\n", ia->ia_iobase));
    696      1.1        pk 
    697      1.1        pk out:
    698      1.3        pk 	bus_space_unmap(iot, ioh, IX_IOSIZE);
    699      1.2        pk 	return (rv);
    700      1.1        pk }
    701      1.1        pk 
    702      1.1        pk void
    703      1.1        pk ix_attach(parent, self, aux)
    704      1.2        pk 	struct device *parent;
    705      1.2        pk 	struct device *self;
    706      1.2        pk 	void   *aux;
    707      1.2        pk {
    708      1.2        pk 	struct ix_softc *isc = (void *)self;
    709      1.2        pk 	struct ie_softc *sc = &isc->sc_ie;
    710      1.2        pk 	struct isa_attach_args *ia = aux;
    711      1.2        pk 
    712      1.2        pk 	int media;
    713  1.6.8.2    bouyer 	int i, memsize;
    714      1.2        pk 	u_int8_t bart_config;
    715      1.3        pk 	bus_space_tag_t iot;
    716  1.6.8.2    bouyer 	u_int8_t bpat, bval;
    717  1.6.8.2    bouyer 	u_int16_t wpat, wval;
    718      1.2        pk 	bus_space_handle_t ioh, memh;
    719      1.3        pk 	u_short irq_encoded;
    720      1.2        pk 	u_int8_t ethaddr[ETHER_ADDR_LEN];
    721      1.2        pk 
    722      1.3        pk 	iot = ia->ia_iot;
    723      1.3        pk 
    724  1.6.8.2    bouyer 	/*
    725  1.6.8.2    bouyer 	 * Shared memory access seems to fail on 16K mapped boards, so
    726  1.6.8.2    bouyer 	 * disable shared memory access if the board is in 16K mode.  If
    727  1.6.8.2    bouyer 	 * no memory is mapped, we have no choice but to use PIO
    728  1.6.8.2    bouyer 	 */
    729  1.6.8.2    bouyer 	isc->use_pio = (ia->ia_msize <= (16 * 1024));
    730  1.6.8.2    bouyer 
    731      1.3        pk 	if (bus_space_map(iot, ia->ia_iobase,
    732      1.2        pk 			  ia->ia_iosize, 0, &ioh) != 0) {
    733      1.2        pk 
    734      1.2        pk 		DPRINTF(("\n%s: can't map i/o space 0x%x-0x%x\n",
    735      1.2        pk 			  sc->sc_dev.dv_xname, ia->ia_iobase,
    736      1.2        pk 			  ia->ia_iobase + ia->ia_iosize - 1));
    737      1.2        pk 		return;
    738      1.2        pk 	}
    739      1.2        pk 
    740  1.6.8.2    bouyer 	/* We map memory even if using PIO so something else doesn't grab it */
    741  1.6.8.2    bouyer 	if (ia->ia_msize) {
    742      1.2        pk 	if (bus_space_map(ia->ia_memt, ia->ia_maddr,
    743      1.2        pk 			  ia->ia_msize, 0, &memh) != 0) {
    744      1.2        pk 		DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n",
    745      1.2        pk 			sc->sc_dev.dv_xname, ia->ia_maddr,
    746      1.2        pk 			ia->ia_maddr + ia->ia_msize - 1));
    747      1.3        pk 		bus_space_unmap(iot, ioh, ia->ia_iosize);
    748      1.2        pk 		return;
    749      1.2        pk 	}
    750  1.6.8.2    bouyer 	}
    751      1.2        pk 
    752      1.3        pk 	isc->sc_regt = iot;
    753      1.2        pk 	isc->sc_regh = ioh;
    754      1.2        pk 
    755      1.2        pk 	/*
    756      1.2        pk 	 * Get the hardware ethernet address from the EEPROM and
    757      1.2        pk 	 * save it in the softc for use by the 586 setup code.
    758      1.2        pk 	 */
    759  1.6.8.2    bouyer 	wval = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_HIGH);
    760  1.6.8.2    bouyer 	ethaddr[1] = wval & 0xFF;
    761  1.6.8.2    bouyer 	ethaddr[0] = wval >> 8;
    762  1.6.8.2    bouyer 	wval = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_MID);
    763  1.6.8.2    bouyer 	ethaddr[3] = wval & 0xFF;
    764  1.6.8.2    bouyer 	ethaddr[2] = wval >> 8;
    765  1.6.8.2    bouyer 	wval = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_LOW);
    766  1.6.8.2    bouyer 	ethaddr[5] = wval & 0xFF;
    767  1.6.8.2    bouyer 	ethaddr[4] = wval >> 8;
    768      1.2        pk 
    769      1.2        pk 	sc->hwinit = NULL;
    770      1.2        pk 	sc->hwreset = ix_reset;
    771      1.2        pk 	sc->chan_attn = ix_atten;
    772      1.2        pk 	sc->intrhook = ix_intrhook;
    773      1.2        pk 
    774      1.2        pk 	sc->memcopyin = ix_copyin;
    775      1.2        pk 	sc->memcopyout = ix_copyout;
    776  1.6.8.2    bouyer 
    777  1.6.8.2    bouyer 	/* If using PIO, make sure to setup single-byte read/write functions */
    778  1.6.8.2    bouyer 	if (isc->use_pio) {
    779  1.6.8.2    bouyer 		sc->ie_bus_barrier = ix_bus_barrier;
    780  1.6.8.2    bouyer 	} else {
    781  1.6.8.2    bouyer 		sc->ie_bus_barrier = NULL;
    782  1.6.8.2    bouyer 	}
    783  1.6.8.2    bouyer 
    784      1.2        pk 	sc->ie_bus_read16 = ix_read_16;
    785      1.2        pk 	sc->ie_bus_write16 = ix_write_16;
    786      1.2        pk 	sc->ie_bus_write24 = ix_write_24;
    787      1.2        pk 
    788      1.2        pk 	sc->do_xmitnopchain = 0;
    789      1.2        pk 
    790      1.2        pk 	sc->sc_mediachange = NULL;
    791      1.2        pk 	sc->sc_mediastatus = ix_mediastatus;
    792      1.2        pk 
    793  1.6.8.2    bouyer 	if (isc->use_pio) {
    794  1.6.8.2    bouyer 		sc->bt = iot;
    795  1.6.8.2    bouyer 		sc->bh = ioh;
    796  1.6.8.2    bouyer 
    797  1.6.8.2    bouyer 		/*
    798  1.6.8.2    bouyer 		 * If using PIO, the memory size is bounded by on-card memory,
    799  1.6.8.2    bouyer 		 * not by how much is mapped into the memory-mapped region, so
    800  1.6.8.2    bouyer 		 * determine how much total memory we have to play with here.
    801  1.6.8.2    bouyer 		 */
    802  1.6.8.2    bouyer 		for(memsize = 64 * 1024; memsize; memsize -= 16 * 1024) {
    803  1.6.8.2    bouyer 			/* warm up shared memory, the zero it all out */
    804  1.6.8.2    bouyer 			ix_zeromem(sc, 0, 32);
    805  1.6.8.2    bouyer 			ix_zeromem(sc, 0, memsize);
    806  1.6.8.2    bouyer 
    807  1.6.8.2    bouyer 			/* Reset write pointer to the start of RAM */
    808  1.6.8.2    bouyer 			bus_space_write_2(iot, ioh, IX_WRITEPTR, 0);
    809  1.6.8.2    bouyer 			bus_space_barrier(iot, ioh, IX_WRITEPTR, 2,
    810  1.6.8.2    bouyer 						    BUS_SPACE_BARRIER_WRITE);
    811  1.6.8.2    bouyer 
    812  1.6.8.2    bouyer 			/* write test pattern */
    813  1.6.8.2    bouyer 			for(i = 0; i < memsize; i += 2) {
    814  1.6.8.2    bouyer 				bus_space_write_2(iot, ioh, IX_DATAPORT, wpat);
    815  1.6.8.2    bouyer 				wpat += 3;
    816  1.6.8.2    bouyer 			}
    817  1.6.8.2    bouyer 
    818  1.6.8.2    bouyer 			/* Flush all reads & writes to data port */
    819  1.6.8.2    bouyer 			bus_space_barrier(iot, ioh, IX_DATAPORT, 2,
    820  1.6.8.2    bouyer 						    BUS_SPACE_BARRIER_READ |
    821  1.6.8.2    bouyer 						    BUS_SPACE_BARRIER_WRITE);
    822  1.6.8.2    bouyer 
    823  1.6.8.2    bouyer 			/* Reset read pointer to beginning of card RAM */
    824  1.6.8.2    bouyer 			bus_space_write_2(iot, ioh, IX_READPTR, 0);
    825  1.6.8.2    bouyer 			bus_space_barrier(iot, ioh, IX_READPTR, 2,
    826  1.6.8.2    bouyer 						    BUS_SPACE_BARRIER_WRITE);
    827  1.6.8.2    bouyer 
    828  1.6.8.2    bouyer 			/* read and verify test pattern */
    829  1.6.8.2    bouyer 			for(i = 0, wpat = 1; i < memsize; i += 2) {
    830  1.6.8.2    bouyer 				wval = bus_space_read_2(iot, ioh, IX_DATAPORT);
    831  1.6.8.2    bouyer 
    832  1.6.8.2    bouyer 				if (wval != wpat)
    833  1.6.8.2    bouyer 					break;
    834  1.6.8.2    bouyer 
    835  1.6.8.2    bouyer 				wpat += 3;
    836  1.6.8.2    bouyer 			}
    837  1.6.8.2    bouyer 
    838  1.6.8.2    bouyer 			/* If we failed, try next size down */
    839  1.6.8.2    bouyer 			if (i != memsize)
    840  1.6.8.2    bouyer 				continue;
    841  1.6.8.2    bouyer 
    842  1.6.8.2    bouyer 			/* Now try it all with byte reads/writes */
    843  1.6.8.2    bouyer 			ix_zeromem(sc, 0, 32);
    844  1.6.8.2    bouyer 			ix_zeromem(sc, 0, memsize);
    845  1.6.8.2    bouyer 
    846  1.6.8.2    bouyer 			/* Reset write pointer to start of card RAM */
    847  1.6.8.2    bouyer 			bus_space_write_2(iot, ioh, IX_WRITEPTR, 0);
    848  1.6.8.2    bouyer 			bus_space_barrier(iot, ioh, IX_WRITEPTR, 2,
    849  1.6.8.2    bouyer 						    BUS_SPACE_BARRIER_WRITE);
    850  1.6.8.2    bouyer 
    851  1.6.8.2    bouyer 			/* write out test pattern */
    852  1.6.8.2    bouyer 			for(i = 0, bpat = 1; i < memsize; i++) {
    853  1.6.8.2    bouyer 				bus_space_write_1(iot, ioh, IX_DATAPORT, bpat);
    854  1.6.8.2    bouyer 				bpat += 3;
    855  1.6.8.2    bouyer 			}
    856  1.6.8.2    bouyer 
    857  1.6.8.2    bouyer 			/* Flush all reads & writes to data port */
    858  1.6.8.2    bouyer 			bus_space_barrier(iot, ioh, IX_DATAPORT, 2,
    859  1.6.8.2    bouyer 						    BUS_SPACE_BARRIER_READ |
    860  1.6.8.2    bouyer 						    BUS_SPACE_BARRIER_WRITE);
    861  1.6.8.2    bouyer 
    862  1.6.8.2    bouyer 			/* Reset read pointer to beginning of card RAM */
    863  1.6.8.2    bouyer 			bus_space_write_2(iot, ioh, IX_READPTR, 0);
    864  1.6.8.2    bouyer 			bus_space_barrier(iot, ioh, IX_READPTR, 2,
    865  1.6.8.2    bouyer 						    BUS_SPACE_BARRIER_WRITE);
    866  1.6.8.2    bouyer 
    867  1.6.8.2    bouyer 			/* read and verify test pattern */
    868  1.6.8.2    bouyer 			for(i = 0, bpat = 1; i < memsize; i++) {
    869  1.6.8.2    bouyer 				bval = bus_space_read_1(iot, ioh, IX_DATAPORT);
    870  1.6.8.2    bouyer 
    871  1.6.8.2    bouyer 				if (bval != bpat)
    872  1.6.8.2    bouyer 				bpat += 3;
    873  1.6.8.2    bouyer 			}
    874  1.6.8.2    bouyer 
    875  1.6.8.2    bouyer 			/* If we got through all of memory, we're done! */
    876  1.6.8.2    bouyer 			if (i == memsize)
    877  1.6.8.2    bouyer 				break;
    878  1.6.8.2    bouyer 		}
    879  1.6.8.2    bouyer 
    880  1.6.8.2    bouyer 		/* Memory tests failed, punt... */
    881  1.6.8.2    bouyer 		if (memsize == 0)  {
    882  1.6.8.2    bouyer 			DPRINTF(("\n%s: can't determine size of on-card RAM\n",
    883  1.6.8.2    bouyer 				sc->sc_dev.dv_xname));
    884  1.6.8.2    bouyer 			bus_space_unmap(iot, ioh, ia->ia_iosize);
    885  1.6.8.2    bouyer 			return;
    886  1.6.8.2    bouyer 		}
    887  1.6.8.2    bouyer 
    888  1.6.8.2    bouyer 		sc->bt = iot;
    889  1.6.8.2    bouyer 		sc->bh = ioh;
    890  1.6.8.2    bouyer 
    891  1.6.8.2    bouyer 		sc->sc_msize = memsize;
    892  1.6.8.2    bouyer 		sc->sc_maddr = (void*) 0;
    893  1.6.8.2    bouyer 	} else {
    894      1.2        pk 	sc->bt = ia->ia_memt;
    895      1.2        pk 	sc->bh = memh;
    896      1.2        pk 
    897      1.2        pk 	sc->sc_msize = ia->ia_msize;
    898      1.6  augustss 	sc->sc_maddr = (void *)memh;
    899  1.6.8.2    bouyer 	}
    900  1.6.8.2    bouyer 
    901  1.6.8.2    bouyer 	/* Map i/o space. */
    902      1.6  augustss 	sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24);
    903      1.2        pk 
    904      1.2        pk 	/* set up pointers to important on-card control structures */
    905      1.2        pk 	sc->iscp = 0;
    906      1.2        pk 	sc->scb = IE_ISCP_SZ;
    907      1.2        pk 	sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24);
    908      1.2        pk 
    909      1.2        pk 	sc->buf_area = sc->scb + IE_SCB_SZ;
    910      1.2        pk 	sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;
    911      1.2        pk 
    912      1.2        pk 	/* zero card memory */
    913  1.6.8.2    bouyer 	ix_zeromem(sc, 0, 32);
    914  1.6.8.2    bouyer 	ix_zeromem(sc, 0, sc->sc_msize);
    915      1.2        pk 
    916      1.2        pk 	/* set card to 16-bit bus mode */
    917  1.6.8.2    bouyer 	if (isc->use_pio) {
    918  1.6.8.2    bouyer 		bus_space_write_2(sc->bt, sc->bh, IX_WRITEPTR,
    919  1.6.8.2    bouyer 				  	    IE_SCP_BUS_USE((u_long)sc->scp));
    920  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, IX_WRITEPTR, 2,
    921  1.6.8.2    bouyer 					          BUS_SPACE_BARRIER_WRITE);
    922  1.6.8.2    bouyer 
    923  1.6.8.2    bouyer 		bus_space_write_1(sc->bt, sc->bh, IX_DATAPORT, 0);
    924  1.6.8.2    bouyer 	} else {
    925  1.6.8.2    bouyer 		bus_space_write_1(sc->bt, sc->bh,
    926  1.6.8.2    bouyer 				  IE_SCP_BUS_USE((u_long)sc->scp), 0);
    927  1.6.8.2    bouyer 	}
    928      1.2        pk 
    929      1.2        pk 	/* set up pointers to key structures */
    930      1.2        pk 	ix_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
    931      1.2        pk 	ix_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
    932      1.2        pk 	ix_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);
    933      1.2        pk 
    934      1.2        pk 	/* flush setup of pointers, check if chip answers */
    935  1.6.8.2    bouyer 	if (isc->use_pio) {
    936  1.6.8.2    bouyer 		bus_space_barrier(sc->bt, sc->bh, 0, IX_IOSIZE,
    937  1.6.8.2    bouyer 				  BUS_SPACE_BARRIER_WRITE);
    938  1.6.8.2    bouyer 	} else {
    939      1.2        pk 	bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
    940      1.2        pk 			  BUS_SPACE_BARRIER_WRITE);
    941  1.6.8.2    bouyer 	}
    942  1.6.8.2    bouyer 
    943      1.2        pk 	if (!i82586_proberam(sc)) {
    944      1.2        pk 		DPRINTF(("\n%s: Can't talk to i82586!\n",
    945      1.2        pk 			sc->sc_dev.dv_xname));
    946      1.3        pk 		bus_space_unmap(iot, ioh, ia->ia_iosize);
    947  1.6.8.2    bouyer 
    948  1.6.8.2    bouyer 		if (ia->ia_msize)
    949      1.2        pk 		bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
    950      1.2        pk 		return;
    951      1.2        pk 	}
    952      1.2        pk 
    953      1.2        pk 	/* Figure out which media is being used... */
    954      1.3        pk 	if (ix_read_eeprom(iot, ioh, IX_EEPROM_CONFIG1) &
    955      1.3        pk 				IX_EEPROM_MEDIA_EXT) {
    956      1.3        pk 		if (ix_read_eeprom(iot, ioh, IX_EEPROM_MEDIA) &
    957      1.3        pk 				IX_EEPROM_MEDIA_TP)
    958      1.2        pk 			media = IFM_ETHER | IFM_10_T;
    959      1.2        pk 		else
    960      1.2        pk 			media = IFM_ETHER | IFM_10_2;
    961      1.2        pk 	} else
    962      1.2        pk 		media = IFM_ETHER | IFM_10_5;
    963      1.2        pk 
    964      1.2        pk 	/* Take the card out of lookback */
    965      1.3        pk 	bart_config = bus_space_read_1(iot, ioh, IX_CONFIG);
    966      1.2        pk 	bart_config &= ~IX_BART_LOOPBACK;
    967      1.2        pk 	bart_config |= IX_BART_MCS16_TEST; /* inb doesn't get bit! */
    968      1.3        pk 	bus_space_write_1(iot, ioh, IX_CONFIG, bart_config);
    969      1.3        pk 	bart_config = bus_space_read_1(iot, ioh, IX_CONFIG);
    970      1.3        pk 
    971      1.3        pk 	irq_encoded = ix_read_eeprom(iot, ioh,
    972      1.3        pk 				     IX_EEPROM_CONFIG1);
    973      1.3        pk 	irq_encoded = (irq_encoded & IX_EEPROM_IRQ) >> IX_EEPROM_IRQ_SHIFT;
    974      1.2        pk 
    975      1.2        pk 	/* Enable interrupts */
    976      1.3        pk 	bus_space_write_1(iot, ioh, IX_IRQ,
    977      1.3        pk 			  irq_encoded | IX_IRQ_ENABLE);
    978      1.3        pk 
    979  1.6.8.2    bouyer 	/* Flush all writes to registers */
    980  1.6.8.2    bouyer 	bus_space_barrier(iot, ioh, 0, ia->ia_iosize, BUS_SPACE_BARRIER_WRITE);
    981  1.6.8.2    bouyer 
    982      1.3        pk 	isc->irq_encoded = irq_encoded;
    983      1.2        pk 
    984      1.2        pk 	i82586_attach(sc, "EtherExpress/16", ethaddr,
    985      1.2        pk 		      ix_media, NIX_MEDIA, media);
    986  1.6.8.2    bouyer 
    987  1.6.8.2    bouyer 	if (isc->use_pio)
    988  1.6.8.2    bouyer 		printf("%s: unsupported memory config, using PIO to access %d bytes of memory\n", sc->sc_dev.dv_xname, sc->sc_msize);
    989      1.2        pk 
    990      1.2        pk 	isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    991      1.2        pk 					IPL_NET, i82586_intr, sc);
    992      1.2        pk 	if (isc->sc_ih == NULL)
    993      1.2        pk 		DPRINTF(("\n%s: can't establish interrupt\n",
    994      1.2        pk 			sc->sc_dev.dv_xname));
    995      1.1        pk }
    996      1.1        pk 
    997      1.1        pk struct cfattach ix_ca = {
    998      1.2        pk 	sizeof(struct ix_softc), ix_match, ix_attach
    999      1.1        pk };
   1000