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