Home | History | Annotate | Line # | Download | only in isa
if_ix.c revision 1.3
      1 /*	$NetBSD: if_ix.c,v 1.3 1998/03/03 20:51:20 pk Exp $ */
      2 /*	$Id: if_ix.c,v 1.3 1998/03/03 20:51:20 pk Exp $ */
      3 
      4 /*-
      5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software contributed to The NetBSD Foundation
      9  * by Rafal K. Boni.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/mbuf.h>
     43 #include <sys/errno.h>
     44 #include <sys/device.h>
     45 #include <sys/protosw.h>
     46 #include <sys/socket.h>
     47 
     48 #include <net/if.h>
     49 #include <net/if_dl.h>
     50 #include <net/if_types.h>
     51 #include <net/if_media.h>
     52 #include <net/if_ether.h>
     53 
     54 #include <vm/vm.h>
     55 
     56 #include <machine/cpu.h>
     57 #include <machine/bus.h>
     58 #include <machine/intr.h>
     59 
     60 #include <dev/isa/isareg.h>
     61 #include <dev/isa/isavar.h>
     62 
     63 #include <dev/ic/i82586reg.h>
     64 #include <dev/ic/i82586var.h>
     65 #include <dev/isa/if_ixreg.h>
     66 
     67 #ifdef IX_DEBUG
     68 #define DPRINTF(x)	printf x
     69 #else
     70 #define DPRINTF(x)
     71 #endif
     72 
     73 int ix_media[] = {
     74 	IFM_ETHER | IFM_10_5,
     75 	IFM_ETHER | IFM_10_2,
     76 	IFM_ETHER | IFM_10_T,
     77 };
     78 #define NIX_MEDIA       (sizeof(ix_media) / sizeof(ix_media[0]))
     79 
     80 struct ix_softc {
     81 	struct ie_softc sc_ie;
     82 
     83 	bus_space_tag_t sc_regt;	/* space tag for registers */
     84 	bus_space_handle_t sc_regh;	/* space handle for registers */
     85 
     86 	u_int16_t	irq_encoded;	/* encoded IRQ */
     87 	void		*sc_ih;		/* interrupt handle */
     88 };
     89 
     90 static void 	ix_reset __P((struct ie_softc *, int));
     91 static void 	ix_atten __P((struct ie_softc *));
     92 static int 	ix_intrhook __P((struct ie_softc *, int));
     93 
     94 static void     ix_copyin __P((struct ie_softc *, void *, int, size_t));
     95 static void     ix_copyout __P((struct ie_softc *, const void *, int, size_t));
     96 
     97 static u_int16_t ix_read_16 __P((struct ie_softc *, int));
     98 static void	ix_write_16 __P((struct ie_softc *, int, u_int16_t));
     99 static void	ix_write_24 __P((struct ie_softc *, int, int));
    100 
    101 static void	ix_mediastatus __P((struct ie_softc *, struct ifmediareq *));
    102 
    103 static u_int16_t ix_read_eeprom __P((bus_space_tag_t, bus_space_handle_t, int));
    104 static void	ix_eeprom_outbits __P((bus_space_tag_t, bus_space_handle_t, int, int));
    105 static int	ix_eeprom_inbits  __P((bus_space_tag_t, bus_space_handle_t));
    106 static void	ix_eeprom_clock   __P((bus_space_tag_t, bus_space_handle_t, int));
    107 
    108 #ifdef __BROKEN_INDIRECT_CONFIG
    109 int ix_match __P((struct device *, void*, void *));
    110 #else
    111 int ix_match __P((struct device *, struct cfdata *, void *));
    112 #endif
    113 void ix_attach __P((struct device *, struct device *, void *));
    114 
    115 /*
    116  * EtherExpress/16 support routines
    117  */
    118 static void
    119 ix_reset(sc, why)
    120 	struct ie_softc *sc;
    121 	int why;
    122 {
    123 	struct ix_softc* isc = (struct ix_softc *) sc;
    124 
    125 	switch (why) {
    126 	case CHIP_PROBE:
    127 		bus_space_write_1(isc->sc_regt, isc->sc_regh, IX_ECTRL,
    128 				  IX_RESET_586);
    129 		delay(100);
    130 		bus_space_write_1(isc->sc_regt, isc->sc_regh, IX_ECTRL, 0);
    131 		delay(100);
    132 		break;
    133 
    134 	case CARD_RESET:
    135 		break;
    136     }
    137 }
    138 
    139 static void
    140 ix_atten(sc)
    141 	struct ie_softc *sc;
    142 {
    143 	struct ix_softc* isc = (struct ix_softc *) sc;
    144 	bus_space_write_1(isc->sc_regt, isc->sc_regh, IX_ATTN, 0);
    145 }
    146 
    147 static u_int16_t
    148 ix_read_eeprom(iot, ioh, location)
    149 	bus_space_tag_t iot;
    150 	bus_space_handle_t ioh;
    151 	int location;
    152 {
    153 	int ectrl, edata;
    154 
    155 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    156 	ectrl &= IX_ECTRL_MASK;
    157 	ectrl |= IX_ECTRL_EECS;
    158 	bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    159 
    160 	ix_eeprom_outbits(iot, ioh, IX_EEPROM_READ, IX_EEPROM_OPSIZE1);
    161 	ix_eeprom_outbits(iot, ioh, location, IX_EEPROM_ADDR_SIZE);
    162 	edata = ix_eeprom_inbits(iot, ioh);
    163 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    164 	ectrl &= ~(IX_RESET_ASIC | IX_ECTRL_EEDI | IX_ECTRL_EECS);
    165 	bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    166 	ix_eeprom_clock(iot, ioh, 1);
    167 	ix_eeprom_clock(iot, ioh, 0);
    168 	return (edata);
    169 }
    170 
    171 static void
    172 ix_eeprom_outbits(iot, ioh, edata, count)
    173 	bus_space_tag_t iot;
    174 	bus_space_handle_t ioh;
    175 	int edata, count;
    176 {
    177 	int ectrl, i;
    178 
    179 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    180 	ectrl &= ~IX_RESET_ASIC;
    181 	for (i = count - 1; i >= 0; i--) {
    182 		ectrl &= ~IX_ECTRL_EEDI;
    183 		if (edata & (1 << i)) {
    184 			ectrl |= IX_ECTRL_EEDI;
    185 		}
    186 		bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    187 		delay(1);	/* eeprom data must be setup for 0.4 uSec */
    188 		ix_eeprom_clock(iot, ioh, 1);
    189 		ix_eeprom_clock(iot, ioh, 0);
    190 	}
    191 	ectrl &= ~IX_ECTRL_EEDI;
    192 	bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    193 	delay(1);		/* eeprom data must be held for 0.4 uSec */
    194 }
    195 
    196 static int
    197 ix_eeprom_inbits(iot, ioh)
    198 	bus_space_tag_t iot;
    199 	bus_space_handle_t ioh;
    200 {
    201 	int ectrl, edata, i;
    202 
    203 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    204 	ectrl &= ~IX_RESET_ASIC;
    205 	for (edata = 0, i = 0; i < 16; i++) {
    206 		edata = edata << 1;
    207 		ix_eeprom_clock(iot, ioh, 1);
    208 		ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    209 		if (ectrl & IX_ECTRL_EEDO) {
    210 			edata |= 1;
    211 		}
    212 		ix_eeprom_clock(iot, ioh, 0);
    213 	}
    214 	return (edata);
    215 }
    216 
    217 static void
    218 ix_eeprom_clock(iot, ioh, state)
    219 	bus_space_tag_t iot;
    220 	bus_space_handle_t ioh;
    221 	int state;
    222 {
    223 	int ectrl;
    224 
    225 	ectrl = bus_space_read_1(iot, ioh, IX_ECTRL);
    226 	ectrl &= ~(IX_RESET_ASIC | IX_ECTRL_EESK);
    227 	if (state) {
    228 		ectrl |= IX_ECTRL_EESK;
    229 	}
    230 	bus_space_write_1(iot, ioh, IX_ECTRL, ectrl);
    231 	delay(9);		/* EESK must be stable for 8.38 uSec */
    232 }
    233 
    234 static int
    235 ix_intrhook(sc, where)
    236 	struct ie_softc *sc;
    237 	int where;
    238 {
    239 	struct ix_softc* isc = (struct ix_softc *) sc;
    240 
    241 	switch (where) {
    242 	case INTR_ENTER:
    243 		/* entering ISR: disable card interrupts */
    244 		bus_space_write_1(isc->sc_regt, isc->sc_regh,
    245 				  IX_IRQ, isc->irq_encoded);
    246 		break;
    247 
    248 	case INTR_EXIT:
    249 		/* exiting ISR: re-enable card interrupts */
    250 		bus_space_write_1(isc->sc_regt, isc->sc_regh, IX_IRQ,
    251     				  isc->irq_encoded | IX_IRQ_ENABLE);
    252 	break;
    253     }
    254 
    255     return 1;
    256 }
    257 
    258 
    259 static void
    260 ix_copyin (sc, dst, offset, size)
    261         struct ie_softc *sc;
    262         void *dst;
    263         int offset;
    264         size_t size;
    265 {
    266 	int dribble;
    267 	u_int8_t* bptr = dst;
    268 
    269 	bus_space_barrier(sc->bt, sc->bh, offset, size,
    270 			  BUS_SPACE_BARRIER_READ);
    271 
    272 	if (offset % 2) {
    273 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    274 		offset++; bptr++; size--;
    275 	}
    276 
    277 	dribble = size % 2;
    278 	bus_space_read_region_2(sc->bt, sc->bh, offset, (u_int16_t *) bptr,
    279 				size >> 1);
    280 
    281 	if (dribble) {
    282 		bptr += size - 1;
    283 		offset += size - 1;
    284 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    285 	}
    286 }
    287 
    288 static void
    289 ix_copyout (sc, src, offset, size)
    290         struct ie_softc *sc;
    291         const void *src;
    292         int offset;
    293         size_t size;
    294 {
    295 	int dribble;
    296 	int osize = size;
    297 	int ooffset = offset;
    298 	const u_int8_t* bptr = src;
    299 
    300 	if (offset % 2) {
    301 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    302 		offset++; bptr++; size--;
    303 	}
    304 
    305 	dribble = size % 2;
    306 	bus_space_write_region_2(sc->bt, sc->bh, offset, (u_int16_t *)bptr,
    307 				 size >> 1);
    308 	if (dribble) {
    309 		bptr += size - 1;
    310 		offset += size - 1;
    311 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    312 	}
    313 
    314 	bus_space_barrier(sc->bt, sc->bh, ooffset, osize,
    315 			  BUS_SPACE_BARRIER_WRITE);
    316 }
    317 
    318 static u_int16_t
    319 ix_read_16 (sc, offset)
    320         struct ie_softc *sc;
    321         int offset;
    322 {
    323 	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
    324         return bus_space_read_2(sc->bt, sc->bh, offset);
    325 }
    326 
    327 static void
    328 ix_write_16 (sc, offset, value)
    329         struct ie_softc *sc;
    330         int offset;
    331         u_int16_t value;
    332 {
    333         bus_space_write_2(sc->bt, sc->bh, offset, value);
    334 	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
    335 }
    336 
    337 static void
    338 ix_write_24 (sc, offset, addr)
    339         struct ie_softc *sc;
    340         int offset, addr;
    341 {
    342         bus_space_write_4(sc->bt, sc->bh, offset, addr +
    343 			  (u_long) sc->sc_maddr - (u_long) sc->sc_iobase);
    344 	bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
    345 }
    346 
    347 static void
    348 ix_mediastatus(sc, ifmr)
    349         struct ie_softc *sc;
    350         struct ifmediareq *ifmr;
    351 {
    352         struct ifmedia *ifm = &sc->sc_media;
    353 
    354         /*
    355          * The currently selected media is always the active media.
    356          */
    357         ifmr->ifm_active = ifm->ifm_cur->ifm_media;
    358 }
    359 
    360 int
    361 ix_match(parent, cf, aux)
    362 	struct device *parent;
    363 #ifdef __BROKEN_INDIRECT_CONFIG
    364         void *cf;
    365 #else
    366 	struct cfdata *cf;
    367 #endif
    368 	void *aux;
    369 {
    370 	int i;
    371 	int rv = 0;
    372 	bus_addr_t maddr;
    373 	bus_size_t msize;
    374 	u_short checksum = 0;
    375 	bus_space_handle_t ioh;
    376 	bus_space_tag_t iot;
    377 	u_int8_t val, bart_config;
    378 	u_short pg, adjust, decode, edecode;
    379 	u_short board_id, id_var1, id_var2, irq, irq_encoded;
    380 	struct isa_attach_args * const ia = aux;
    381 	short irq_translate[] = {0, 0x09, 0x03, 0x04, 0x05, 0x0a, 0x0b, 0};
    382 
    383 	iot = ia->ia_iot;
    384 
    385 	if (bus_space_map(iot, ia->ia_iobase,
    386 			  IX_IOSIZE, 0, &ioh) != 0) {
    387 		DPRINTF(("Can't map io space at 0x%x\n", ia->ia_iobase));
    388 		return (0);
    389 	}
    390 
    391 	/* XXX: reset any ee16 at the current iobase */
    392 	bus_space_write_1(iot, ioh, IX_ECTRL, IX_RESET_ASIC);
    393 	bus_space_write_1(iot, ioh, IX_ECTRL, 0);
    394 	delay(240);
    395 
    396 	/* now look for ee16. */
    397 	board_id = id_var1 = id_var2 = 0;
    398 	for (i = 0; i < 4 ; i++) {
    399 		id_var1 = bus_space_read_1(iot, ioh, IX_ID_PORT);
    400 		id_var2 = ((id_var1 & 0x03) << 2);
    401 		board_id |= (( id_var1 >> 4)  << id_var2);
    402 	}
    403 
    404 	if (board_id != IX_ID) {
    405 		DPRINTF(("BART ID mismatch (got 0x%04x, expected 0x%04x)\n",
    406 			board_id, IX_ID));
    407 		goto out;
    408 	}
    409 
    410 	/*
    411 	 * The shared RAM size and location of the EE16 is encoded into
    412 	 * EEPROM location 6.  The location of the first set bit tells us
    413 	 * the memory address (0xc0000 + (0x4000 * FSB)), where FSB is the
    414 	 * number of the first set bit.  The zeroes are then shifted out,
    415 	 * and the results is the memory size (1 = 16k, 3 = 32k, 7 = 48k,
    416 	 * 0x0f = 64k).
    417 	 *
    418 	 * Examples:
    419 	 *   0x3c -> 64k@0xc8000, 0x70 -> 48k@0xd0000, 0xc0 -> 32k@0xd8000
    420 	 *   0x80 -> 16k@0xdc000.
    421 	 *
    422 	 * Side note: this comes from reading the old driver rather than
    423 	 * from a more definitive source, so it could be out-of-whack
    424 	 * with what the card can do...
    425 	 */
    426 
    427 	val = ix_read_eeprom(iot, ioh, 6) & 0xff;
    428 	DPRINTF(("memory config: 0x%02x\n", val));
    429 
    430 	for(i = 0; i < 8; i++) {
    431 		if (val & 1)
    432 			break;
    433 		val = val >> 1;
    434 	}
    435 
    436 	if (i == 8) {
    437 		DPRINTF(("Invalid or unsupported memory config\n"));
    438 		goto out;
    439 	}
    440 
    441 	maddr = 0xc0000 + (i * 0x4000);
    442 
    443 	switch (val) {
    444 	case 0x01:
    445 		msize = 16 * 1024;
    446 		break;
    447 
    448 	case 0x03:
    449 		msize = 32 * 1024;
    450 		break;
    451 
    452 	case 0x07:
    453 		msize = 48 * 1024;
    454 		break;
    455 
    456 	case 0x0f:
    457 		msize = 64 * 1024;
    458 		break;
    459 
    460 	default:
    461 		DPRINTF(("invalid memory size %02x\n", val));
    462 		goto out;
    463 	}
    464 
    465 	if (ia->ia_maddr == ISACF_IOMEM_DEFAULT)
    466 		ia->ia_maddr = maddr;
    467 	else if (ia->ia_maddr != maddr) {
    468 		DPRINTF((
    469 		  "ix_match: memaddr of board @ 0x%x doesn't match config\n",
    470 		  ia->ia_iobase));
    471 		goto out;
    472 	}
    473 
    474 	if (ia->ia_msize == ISACF_IOSIZ_DEFAULT)
    475 		ia->ia_msize = msize;
    476 	else if (ia->ia_msize != msize) {
    477 		DPRINTF((
    478 		   "ix_match: memsize of board @ 0x%x doesn't match config\n",
    479 		   ia->ia_iobase));
    480 		goto out;
    481 	}
    482 
    483 	DPRINTF(("found %d byte memory region at %x\n",
    484 		ia->ia_msize, ia->ia_maddr));
    485 
    486 	/* need to put the 586 in RESET, and leave it */
    487 	bus_space_write_1(iot, ioh, IX_ECTRL, IX_RESET_586);
    488 
    489 	/* read the eeprom and checksum it, should == IX_ID */
    490 	for(i = 0; i < 0x40; i++)
    491 		checksum += ix_read_eeprom(iot, ioh, i);
    492 
    493 	if (checksum != IX_ID) {
    494 		DPRINTF(("checksum mismatch (got 0x%04x, expected 0x%04x\n",
    495 			checksum, IX_ID));
    496 		goto out;
    497 	}
    498 
    499 	/*
    500 	 * Size and test the memory on the board.  The size of the memory
    501 	 * can be one of 16k, 32k, 48k or 64k.  It can be located in the
    502 	 * address range 0xC0000 to 0xEFFFF on 16k boundaries.
    503 	 */
    504 	pg = (ia->ia_maddr & 0x3C000) >> 14;
    505 	adjust = IX_MCTRL_FMCS16 | (pg & 0x3) << 2;
    506 	decode = ((1 << (ia->ia_msize / 16384)) - 1) << pg;
    507 	edecode = ((~decode >> 4) & 0xF0) | (decode >> 8);
    508 
    509 	/* ZZZ This should be checked against eeprom location 6, low byte */
    510 	bus_space_write_1(iot, ioh, IX_MEMDEC, decode & 0xFF);
    511 
    512 	/* ZZZ This should be checked against eeprom location 1, low byte */
    513 	bus_space_write_1(iot, ioh, IX_MCTRL, adjust);
    514 
    515 	/* ZZZ Now if I could find this one I would have it made */
    516 	bus_space_write_1(iot, ioh, IX_MPCTRL, (~decode & 0xFF));
    517 
    518 	/* ZZZ I think this is location 6, high byte */
    519 	bus_space_write_1(iot, ioh, IX_MECTRL, edecode); /*XXX disable Exxx */
    520 
    521 	/*
    522 	 * Get the encoded interrupt number from the EEPROM, check it
    523 	 * against the passed in IRQ.  Issue a warning if they do not
    524 	 * match, and fail the probe.  If irq is 'IRQUNK' then we
    525 	 * use the EEPROM irq, and continue.
    526 	 */
    527 	irq_encoded = ix_read_eeprom(iot, ioh, IX_EEPROM_CONFIG1);
    528 	irq_encoded = (irq_encoded & IX_EEPROM_IRQ) >> IX_EEPROM_IRQ_SHIFT;
    529 	irq = irq_translate[irq_encoded];
    530 	if (ia->ia_irq == ISACF_IRQ_DEFAULT)
    531 		ia->ia_irq = irq;
    532 	else if (irq != ia->ia_irq) {
    533 		DPRINTF(("board IRQ %d does not match config\n", irq));
    534 		goto out;
    535 	}
    536 
    537 	/* disable the board interrupts */
    538 	bus_space_write_1(iot, ioh, IX_IRQ, irq_encoded);
    539 
    540 	bart_config = bus_space_read_1(iot, ioh, IX_CONFIG);
    541 	bart_config |= IX_BART_LOOPBACK;
    542 	bart_config |= IX_BART_MCS16_TEST; /* inb doesn't get bit! */
    543 	bus_space_write_1(iot, ioh, IX_CONFIG, bart_config);
    544 	bart_config = bus_space_read_1(iot, ioh, IX_CONFIG);
    545 
    546 	bus_space_write_1(iot, ioh, IX_ECTRL, 0);
    547 	delay(100);
    548 
    549 	rv = 1;
    550 	ia->ia_iosize = IX_IOSIZE;
    551 	DPRINTF(("ix_match: found board @ 0x%x\n", ia->ia_iobase));
    552 
    553 out:
    554 	bus_space_unmap(iot, ioh, IX_IOSIZE);
    555 	return (rv);
    556 }
    557 
    558 void
    559 ix_attach(parent, self, aux)
    560 	struct device *parent;
    561 	struct device *self;
    562 	void   *aux;
    563 {
    564 	struct ix_softc *isc = (void *)self;
    565 	struct ie_softc *sc = &isc->sc_ie;
    566 	struct isa_attach_args *ia = aux;
    567 
    568 	int media;
    569 	u_short eaddrtemp;
    570 	u_int8_t bart_config;
    571 	bus_space_tag_t iot;
    572 	bus_space_handle_t ioh, memh;
    573 	u_short irq_encoded;
    574 	u_int8_t ethaddr[ETHER_ADDR_LEN];
    575 
    576 	iot = ia->ia_iot;
    577 
    578 	if (bus_space_map(iot, ia->ia_iobase,
    579 			  ia->ia_iosize, 0, &ioh) != 0) {
    580 
    581 		DPRINTF(("\n%s: can't map i/o space 0x%x-0x%x\n",
    582 			  sc->sc_dev.dv_xname, ia->ia_iobase,
    583 			  ia->ia_iobase + ia->ia_iosize - 1));
    584 		return;
    585 	}
    586 
    587 	if (bus_space_map(ia->ia_memt, ia->ia_maddr,
    588 			  ia->ia_msize, 0, &memh) != 0) {
    589 
    590 		DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n",
    591 			sc->sc_dev.dv_xname, ia->ia_maddr,
    592 			ia->ia_maddr + ia->ia_msize - 1));
    593 		bus_space_unmap(iot, ioh, ia->ia_iosize);
    594 		return;
    595 	}
    596 
    597 	isc->sc_regt = iot;
    598 	isc->sc_regh = ioh;
    599 
    600 	/*
    601 	 * Get the hardware ethernet address from the EEPROM and
    602 	 * save it in the softc for use by the 586 setup code.
    603 	 */
    604 	eaddrtemp = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_HIGH);
    605 	ethaddr[1] = eaddrtemp & 0xFF;
    606 	ethaddr[0] = eaddrtemp >> 8;
    607 	eaddrtemp = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_MID);
    608 	ethaddr[3] = eaddrtemp & 0xFF;
    609 	ethaddr[2] = eaddrtemp >> 8;
    610 	eaddrtemp = ix_read_eeprom(iot, ioh, IX_EEPROM_ENET_LOW);
    611 	ethaddr[5] = eaddrtemp & 0xFF;
    612 	ethaddr[4] = eaddrtemp >> 8;
    613 
    614 	sc->hwinit = NULL;
    615 	sc->hwreset = ix_reset;
    616 	sc->chan_attn = ix_atten;
    617 	sc->intrhook = ix_intrhook;
    618 
    619 	sc->memcopyin = ix_copyin;
    620 	sc->memcopyout = ix_copyout;
    621 	sc->ie_bus_read16 = ix_read_16;
    622 	sc->ie_bus_write16 = ix_write_16;
    623 	sc->ie_bus_write24 = ix_write_24;
    624 
    625 	sc->do_xmitnopchain = 0;
    626 
    627 	sc->sc_mediachange = NULL;
    628 	sc->sc_mediastatus = ix_mediastatus;
    629 
    630 	sc->bt = ia->ia_memt;
    631 	sc->bh = memh;
    632 
    633 	/* Map i/o space. */
    634 	sc->sc_msize = ia->ia_msize;
    635 	sc->sc_maddr = (void* ) memh;
    636 	sc->sc_iobase = sc->sc_maddr + sc->sc_msize - (1 << 24);
    637 
    638 	/* set up pointers to important on-card control structures */
    639 	sc->iscp = 0;
    640 	sc->scb = IE_ISCP_SZ;
    641 	sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24);
    642 
    643 	sc->buf_area = sc->scb + IE_SCB_SZ;
    644 	sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;
    645 
    646 	/* zero card memory */
    647 	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, 32);
    648 	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
    649 
    650 	/* set card to 16-bit bus mode */
    651 	bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp), 0);
    652 
    653 	/* set up pointers to key structures */
    654 	ix_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
    655 	ix_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
    656 	ix_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);
    657 
    658 	/* flush setup of pointers, check if chip answers */
    659 	bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
    660 			  BUS_SPACE_BARRIER_WRITE);
    661 	if (!i82586_proberam(sc)) {
    662 		DPRINTF(("\n%s: Can't talk to i82586!\n",
    663 			sc->sc_dev.dv_xname));
    664 		bus_space_unmap(iot, ioh, ia->ia_iosize);
    665 		bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
    666 		return;
    667 	}
    668 
    669 	/* Figure out which media is being used... */
    670 	if (ix_read_eeprom(iot, ioh, IX_EEPROM_CONFIG1) &
    671 				IX_EEPROM_MEDIA_EXT) {
    672 		if (ix_read_eeprom(iot, ioh, IX_EEPROM_MEDIA) &
    673 				IX_EEPROM_MEDIA_TP)
    674 			media = IFM_ETHER | IFM_10_T;
    675 		else
    676 			media = IFM_ETHER | IFM_10_2;
    677 	} else
    678 		media = IFM_ETHER | IFM_10_5;
    679 
    680 	/* Take the card out of lookback */
    681 	bart_config = bus_space_read_1(iot, ioh, IX_CONFIG);
    682 	bart_config &= ~IX_BART_LOOPBACK;
    683 	bart_config |= IX_BART_MCS16_TEST; /* inb doesn't get bit! */
    684 	bus_space_write_1(iot, ioh, IX_CONFIG, bart_config);
    685 	bart_config = bus_space_read_1(iot, ioh, IX_CONFIG);
    686 
    687 	irq_encoded = ix_read_eeprom(iot, ioh,
    688 				     IX_EEPROM_CONFIG1);
    689 	irq_encoded = (irq_encoded & IX_EEPROM_IRQ) >> IX_EEPROM_IRQ_SHIFT;
    690 
    691 	/* Enable interrupts */
    692 	bus_space_write_1(iot, ioh, IX_IRQ,
    693 			  irq_encoded | IX_IRQ_ENABLE);
    694 
    695 	isc->irq_encoded = irq_encoded;
    696 
    697 	i82586_attach(sc, "EtherExpress/16", ethaddr,
    698 		      ix_media, NIX_MEDIA, media);
    699 
    700 	isc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    701 					IPL_NET, i82586_intr, sc);
    702 	if (isc->sc_ih == NULL)
    703 		DPRINTF(("\n%s: can't establish interrupt\n",
    704 			sc->sc_dev.dv_xname));
    705 }
    706 
    707 struct cfattach ix_ca = {
    708 	sizeof(struct ix_softc), ix_match, ix_attach
    709 };
    710