Home | History | Annotate | Line # | Download | only in isa
if_ef.c revision 1.9
      1 /*	$NetBSD: if_ef.c,v 1.9 2001/03/10 20:04:30 jdolecek Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Rafal K. Boni.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/mbuf.h>
     42 #include <sys/errno.h>
     43 #include <sys/device.h>
     44 #include <sys/protosw.h>
     45 #include <sys/socket.h>
     46 
     47 #include <net/if.h>
     48 #include <net/if_dl.h>
     49 #include <net/if_types.h>
     50 #include <net/if_media.h>
     51 #include <net/if_ether.h>
     52 
     53 #include <machine/cpu.h>
     54 #include <machine/bus.h>
     55 #include <machine/intr.h>
     56 
     57 #include <dev/isa/isareg.h>
     58 #include <dev/isa/isavar.h>
     59 
     60 #include <dev/ic/i82586reg.h>
     61 #include <dev/ic/i82586var.h>
     62 #include <dev/isa/if_efreg.h>
     63 #include <dev/isa/elink.h>
     64 
     65 #ifdef EF_DEBUG
     66 #define DPRINTF(x)	printf x
     67 #else
     68 #define DPRINTF(x)
     69 #endif
     70 
     71 struct ef_softc {
     72 	struct ie_softc sc_ie;
     73 
     74 	bus_space_tag_t sc_regt;	/* space tag for registers */
     75 	bus_space_handle_t sc_regh;	/* space handle for registers */
     76 
     77 	void* sc_ih;			/* interrupt handle */
     78 
     79 	u_int8_t card_rev;		/* hardware revision */
     80 	u_int8_t card_type;		/* card model -- AUI/BNC or TP */
     81 };
     82 
     83 int ef_media[] = {
     84 	IFM_ETHER | IFM_10_5,
     85 	IFM_ETHER | IFM_10_2,
     86 };
     87 #define NEF_MEDIA       (sizeof(ef_media) / sizeof(ef_media[0]))
     88 
     89 int eftp_media[] = {
     90 	IFM_ETHER | IFM_10_T,
     91 };
     92 #define NEFTP_MEDIA       (sizeof(eftp_media) / sizeof(eftp_media[0]))
     93 
     94 /* Routines required by the MI i82586 driver API */
     95 static void 	ef_reset __P((struct ie_softc *, int));
     96 static void 	ef_hwinit __P((struct ie_softc *));
     97 static void 	ef_atten __P((struct ie_softc *, int));
     98 static int 	ef_intrhook __P((struct ie_softc *, int));
     99 
    100 static void	ef_copyin __P((struct ie_softc *, void *, int, size_t));
    101 static void	ef_copyout __P((struct ie_softc *, const void *, int, size_t));
    102 
    103 static u_int16_t ef_read_16 __P((struct ie_softc *, int));
    104 static void	ef_write_16 __P((struct ie_softc *, int, u_int16_t));
    105 static void	ef_write_24 __P((struct ie_softc *, int, int));
    106 
    107 static void	ef_mediastatus __P((struct ie_softc *, struct ifmediareq *));
    108 
    109 /* Local routines */
    110 static int 	ef_port_check __P((bus_space_tag_t, bus_space_handle_t));
    111 
    112 int ef_match __P((struct device *, struct cfdata *, void *));
    113 void ef_attach __P((struct device *, struct device *, void *));
    114 
    115 /*
    116  * This keeps track of which ISAs have been through an ie probe sequence.
    117  * A simple static variable isn't enough, since it's conceivable that
    118  * a system might have more than one ISA bus.
    119  *
    120  * The "isa_bus" member is a pointer to the parent ISA bus device struct
    121  * which will unique per ISA bus.
    122  */
    123 
    124 #define MAXCARDS_PER_ISABUS     8       /* if you have more than 8, you lose */
    125 
    126 struct ef_isabus {
    127 	LIST_ENTRY(ef_isabus) isa_link;
    128 	struct device *isa_bus;
    129 
    130 	int bus_state;
    131 
    132 	struct card {
    133 		bus_addr_t iobase;
    134 		bus_addr_t maddr;
    135 		bus_size_t msize;
    136 		int irq;
    137 		int available;
    138 	} isa_cards[MAXCARDS_PER_ISABUS];
    139 };
    140 
    141 static LIST_HEAD(, ef_isabus) ef_isa_buses;
    142 static int ef_isa_buses_inited;
    143 
    144 static void
    145 ef_card_add(
    146     struct ef_isabus *bus,
    147     bus_addr_t iobase,
    148     bus_addr_t maddr,
    149     bus_size_t msize,
    150     int irq)
    151 {
    152 	int idx;
    153 
    154 	DPRINTF(("Adding 3c507 at 0x%x, IRQ %d, Mem 0x%lx/%ld\n",
    155 		 (u_int) iobase, irq, (u_long) maddr, msize));
    156 
    157 	for (idx = 0; idx < MAXCARDS_PER_ISABUS; idx++) {
    158 		if (bus->isa_cards[idx].available == 0) {
    159 			bus->isa_cards[idx].iobase = iobase;
    160 			bus->isa_cards[idx].maddr = maddr;
    161 			bus->isa_cards[idx].msize = msize;
    162 			bus->isa_cards[idx].irq = irq;
    163 			bus->isa_cards[idx].available = 1;
    164 			break;
    165 		}
    166 	}
    167 }
    168 
    169 /*
    170  * 3C507 support routines
    171  */
    172 static void
    173 ef_reset(sc, why)
    174 	struct ie_softc *sc;
    175 	int why;
    176 {
    177 	struct ef_softc* esc = (struct ef_softc *) sc;
    178 
    179 	switch (why) {
    180 	case CHIP_PROBE:
    181 		/* reset to chip to see if it responds */
    182 		bus_space_write_1(esc->sc_regt, esc->sc_regh,
    183 				  EF_CTRL, EF_CTRL_RESET);
    184 		DELAY(100);
    185 		bus_space_write_1(esc->sc_regt, esc->sc_regh,
    186 				  EF_CTRL, EF_CTRL_NORMAL);
    187 		DELAY(100);
    188 		break;
    189 
    190 	case CARD_RESET:
    191 		/*
    192 		 * this takes around 10sec, and we can get
    193 		 * by quite well w/out it...
    194 		 */
    195 		break;
    196 	}
    197 }
    198 
    199 static void
    200 ef_atten(sc, why)
    201 	struct ie_softc *sc;
    202 	int why;
    203 {
    204 	struct ef_softc* esc = (struct ef_softc *) sc;
    205 	bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ATTN, 1);
    206 }
    207 
    208 static void
    209 ef_hwinit(sc)
    210 	struct ie_softc *sc;
    211 {
    212 	struct ef_softc* esc = (struct ef_softc *) sc;
    213 	bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
    214 }
    215 
    216 static int
    217 ef_intrhook(sc, where)
    218 	struct ie_softc *sc;
    219 	int where;
    220 {
    221 	unsigned char cr;
    222 	struct ef_softc* esc = (struct ef_softc *) sc;
    223 
    224 	switch (where) {
    225 	case INTR_ENTER:
    226 		/* entering ISR: disable, ack card interrupts */
    227 		cr = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_CTRL);
    228 		bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL,
    229 				  cr & ~EF_CTRL_IEN);
    230 		bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
    231 		break;
    232 
    233 	case INTR_EXIT:
    234 		/* exiting ISR: re-enable card interrupts */
    235 		cr = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_CTRL);
    236 		bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL,
    237 				  cr | EF_CTRL_IEN);
    238 		break;
    239 
    240 	case INTR_LOOP:
    241 		/* looping in ISR: ack new interrupts */
    242 		bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
    243 		break;
    244     }
    245 
    246     return 1;
    247 }
    248 
    249 static u_int16_t
    250 ef_read_16 (sc, offset)
    251 	struct ie_softc *sc;
    252 	int offset;
    253 {
    254 	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
    255 	return bus_space_read_2(sc->bt, sc->bh, offset);
    256 }
    257 
    258 static void
    259 ef_copyin (sc, dst, offset, size)
    260 	struct ie_softc *sc;
    261 	void *dst;
    262 	int offset;
    263 	size_t size;
    264 {
    265 	int dribble;
    266 	u_int8_t* bptr = dst;
    267 
    268 	bus_space_barrier(sc->bt, sc->bh, offset, size,
    269 			  BUS_SPACE_BARRIER_READ);
    270 
    271 	if (offset % 2) {
    272 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    273 		offset++; bptr++; size--;
    274 	}
    275 
    276 	dribble = size % 2;
    277 	bus_space_read_region_2(sc->bt, sc->bh, offset, (u_int16_t *) bptr,
    278 				size >> 1);
    279 
    280 	if (dribble) {
    281 		bptr += size - 1;
    282 		offset += size - 1;
    283 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    284 	}
    285 }
    286 
    287 static void
    288 ef_copyout (sc, src, offset, size)
    289 	struct ie_softc *sc;
    290 	const void *src;
    291 	int offset;
    292 	size_t size;
    293 {
    294 	int dribble;
    295 	int osize = size;
    296 	int ooffset = offset;
    297 	const u_int8_t* bptr = src;
    298 
    299 	if (offset % 2) {
    300 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    301 		offset++; bptr++; size--;
    302 	}
    303 
    304 	dribble = size % 2;
    305 	bus_space_write_region_2(sc->bt, sc->bh, offset, (u_int16_t *)bptr,
    306 				 size >> 1);
    307 	if (dribble) {
    308 		bptr += size - 1;
    309 		offset += size - 1;
    310 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    311 	}
    312 
    313 	bus_space_barrier(sc->bt, sc->bh, ooffset, osize,
    314 			  BUS_SPACE_BARRIER_WRITE);
    315 }
    316 
    317 static void
    318 ef_write_16 (sc, offset, value)
    319 	struct ie_softc *sc;
    320 	int offset;
    321 	u_int16_t value;
    322 {
    323 	bus_space_write_2(sc->bt, sc->bh, offset, value);
    324 	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
    325 }
    326 
    327 static void
    328 ef_write_24 (sc, offset, addr)
    329 	struct ie_softc *sc;
    330 	int offset, addr;
    331 {
    332 	bus_space_write_4(sc->bt, sc->bh, offset, addr +
    333 			  (u_long) sc->sc_maddr - (u_long) sc->sc_iobase);
    334 	bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
    335 }
    336 
    337 static void
    338 ef_mediastatus(sc, ifmr)
    339         struct ie_softc *sc;
    340         struct ifmediareq *ifmr;
    341 {
    342         struct ifmedia *ifm = &sc->sc_media;
    343 
    344         /*
    345          * The currently selected media is always the active media.
    346          */
    347         ifmr->ifm_active = ifm->ifm_cur->ifm_media;
    348 }
    349 
    350 int
    351 ef_match(parent, cf, aux)
    352 	struct device *parent;
    353 	struct cfdata *cf;
    354 	void *aux;
    355 {
    356 	struct isa_attach_args * const ia = aux;
    357 
    358 	int idx;
    359 	struct ef_isabus *bus;
    360 
    361 	bus_space_handle_t ioh;
    362 	bus_space_tag_t iot = ia->ia_iot;
    363 
    364 	if (ef_isa_buses_inited == 0) {
    365 		LIST_INIT(&ef_isa_buses);
    366 		ef_isa_buses_inited = 1;
    367 	}
    368 
    369 	/*
    370 	* Probe this bus if we haven't done so already.
    371 	*/
    372 	for (bus = ef_isa_buses.lh_first; bus != NULL;
    373 	     bus = bus->isa_link.le_next) {
    374 		if (bus->isa_bus == parent)
    375 			break;
    376 	}
    377 
    378 	if (bus == NULL) {
    379 		bus_addr_t iobase;
    380 
    381 		/*
    382 		 * Mark this bus so we don't probe it again.
    383 		 */
    384 		bus = (struct ef_isabus *)
    385 			malloc(sizeof(struct ef_isabus), M_DEVBUF, M_NOWAIT);
    386 		if (bus == NULL)
    387 		    panic("ef_isa_probe: can't allocate state storage for %s",
    388 			  parent->dv_xname);
    389 
    390 		bus->bus_state = 0;		/* nothing done yet */
    391 		bus->isa_bus = parent;
    392 
    393 		LIST_INSERT_HEAD(&ef_isa_buses, bus, isa_link);
    394 
    395 		if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh)) {
    396 			DPRINTF(("3c507 probe: can't map Etherlink ID port\n"));
    397 			return 0;
    398 		}
    399 
    400 		/*
    401 		 * Reset and put card in CONFIG state without
    402 		 * changing address.
    403 		 */
    404 		elink_reset(iot, ioh, parent->dv_unit);
    405 		elink_idseq(iot, ioh, ELINK_507_POLY);
    406 		elink_idseq(iot, ioh, ELINK_507_POLY);
    407 		bus_space_write_1(iot, ioh, 0, 0xff);
    408 
    409 		/* Unmap the ID port */
    410 		bus_space_unmap(iot, ioh, 1);
    411 
    412 		bus->bus_state++;	/* cards now in CONFIG state */
    413 
    414 		for (iobase = EF_IOBASE_LOW; iobase <= EF_IOBASE_HIGH;
    415 		     iobase += EF_IOSIZE) {
    416 			/*
    417 			 * Map the 507's port-space for the probe sequence.
    418 			 */
    419 			if (bus_space_map(iot, iobase, EF_IOSIZE,
    420 					  0, &ioh) != 0)
    421 				continue;
    422 
    423 			/* Now look for the 3Com magic bytes */
    424 
    425 			if (ef_port_check(iot, ioh)) {
    426 				int irq;
    427 				u_int8_t v;
    428 				bus_addr_t maddr;
    429 				bus_addr_t msize;
    430 				bus_space_handle_t memh;
    431 
    432 				irq = bus_space_read_1(iot, ioh, EF_IRQ) &
    433 					EF_IRQ_MASK;
    434 
    435 				v = bus_space_read_1(iot, ioh, EF_MADDR);
    436 				maddr = EF_MADDR_BASE +
    437 				      ((v & EF_MADDR_MASK) << EF_MADDR_SHIFT);
    438 				msize = ((v & EF_MSIZE_MASK) + 1) *
    439 					EF_MSIZE_STEP;
    440 
    441 				if (bus_space_map(ia->ia_memt, maddr,
    442 						  msize, 0, &memh) == 0) {
    443 					    ef_card_add(bus, iobase, maddr,
    444 							msize, irq);
    445 					    bus_space_unmap(ia->ia_memt,
    446 							    memh, msize);
    447 				}
    448 			}
    449 			bus_space_unmap(iot, ioh, EF_IOSIZE);
    450 		}
    451 	}
    452 
    453 	for (idx = 0; idx < MAXCARDS_PER_ISABUS; idx++) {
    454 		if (bus->isa_cards[idx].available != 1)
    455 			continue;
    456 
    457 		if (ia->ia_iobase != IOBASEUNK &&
    458 		    ia->ia_iobase != bus->isa_cards[idx].iobase)
    459 			continue;
    460 
    461 		if (ia->ia_maddr != MADDRUNK &&
    462 		    ia->ia_maddr != bus->isa_cards[idx].maddr)
    463 			continue;
    464 
    465 		if (ia->ia_irq != IRQUNK &&
    466 		    ia->ia_irq != bus->isa_cards[idx].irq)
    467 			continue;
    468 
    469 		break;
    470 	}
    471 
    472 	if (idx == MAXCARDS_PER_ISABUS)
    473 		return (0);
    474 
    475 	bus->isa_cards[idx].available++;
    476 	ia->ia_iobase = bus->isa_cards[idx].iobase;
    477 	ia->ia_irq    = bus->isa_cards[idx].irq;
    478 	ia->ia_iosize = EF_IOSIZE;
    479 	ia->ia_maddr  = bus->isa_cards[idx].maddr;
    480 	ia->ia_msize  = bus->isa_cards[idx].msize;
    481 	return (1);
    482 }
    483 
    484 void
    485 ef_attach(parent, self, aux)
    486 	struct device *parent;
    487 	struct device *self;
    488 	void   *aux;
    489 {
    490 	struct ef_softc *esc = (void *)self;
    491 	struct ie_softc *sc = &esc->sc_ie;
    492 	struct isa_attach_args *ia = aux;
    493 	bus_space_tag_t iot = ia->ia_iot;
    494 
    495 	int i;
    496 	char version[20];
    497 	struct ef_isabus *bus;
    498 	u_int8_t partno[EF_TYPE_LEN];
    499 	bus_space_handle_t ioh, memh;
    500 	u_int8_t ethaddr[ETHER_ADDR_LEN];
    501 
    502 	sc->hwinit = ef_hwinit;
    503 	sc->hwreset = ef_reset;
    504 	sc->chan_attn = ef_atten;
    505 	sc->intrhook = ef_intrhook;
    506 
    507 	sc->ie_bus_barrier = NULL;
    508 
    509 	sc->memcopyin = ef_copyin;
    510 	sc->memcopyout = ef_copyout;
    511 	sc->ie_bus_read16 = ef_read_16;
    512 	sc->ie_bus_write16 = ef_write_16;
    513 	sc->ie_bus_write24 = ef_write_24;
    514 
    515 	sc->sc_msize = 0;
    516 
    517 	/*
    518 	 * NOP chains don't give any advantage on this card, in fact they
    519 	 * seem to slow it down some.  As the doctor says, "if it hurts,
    520 	 * don't do it".
    521 	 */
    522 	sc->do_xmitnopchain = 0;
    523 
    524 	sc->sc_mediachange = NULL;
    525 	sc->sc_mediastatus = ef_mediastatus;
    526 
    527 	/* Find the cards parent bus */
    528 	for (bus = ef_isa_buses.lh_first; bus != NULL;
    529 	     bus = bus->isa_link.le_next) {
    530 
    531 		if (bus->isa_bus == parent)
    532 			break;
    533 	}
    534 
    535 	if (bus == NULL)
    536 		panic("%s: Can't find parent bus!", sc->sc_dev.dv_xname);
    537 
    538 
    539 	/* If the bus hasn't been transitioned to the RUN state, do so now */
    540 	if (bus->bus_state == 1) {
    541 		if (bus_space_map(iot, ELINK_ID_PORT, 1, 0, &ioh) != 0) {
    542 			DPRINTF(("\n%s: Can't map Elink ID port!\n",
    543 				sc->sc_dev.dv_xname));
    544 			return;
    545 		}
    546 
    547 		bus_space_write_1(ia->ia_iot, ioh, 0, 0x00);
    548 		elink_idseq(ia->ia_iot, ioh, ELINK_507_POLY);
    549 		bus_space_write_1(ia->ia_iot, ioh, 0, 0x00);
    550 		bus_space_unmap(ia->ia_iot, ioh, 1);
    551 
    552 		bus->bus_state++;
    553 	}
    554 
    555 	/* Map i/o space. */
    556 	if (bus_space_map(ia->ia_iot, ia->ia_iobase,
    557 			  ia->ia_iosize, 0, &ioh) != 0) {
    558 
    559 		DPRINTF(("\n%s: can't map i/o space 0x%x-0x%x\n",
    560 			  sc->sc_dev.dv_xname, ia->ia_iobase,
    561 			  ia->ia_iobase + ia->ia_iosize - 1));
    562 		return;
    563 	}
    564 
    565 	esc->sc_regt = ia->ia_iot;
    566 	esc->sc_regh = ioh;
    567 
    568 	if (bus_space_map(ia->ia_memt, ia->ia_maddr,
    569 			  ia->ia_msize, 0, &memh) != 0) {
    570 
    571 		DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n",
    572 			sc->sc_dev.dv_xname, ia->ia_maddr,
    573 			ia->ia_maddr + ia->ia_msize - 1));
    574 		bus_space_unmap(ia->ia_iot, ioh, ia->ia_iosize);
    575 		return;
    576 	}
    577 
    578 	sc->bt = ia->ia_memt;
    579 	sc->bh = memh;
    580 
    581 	sc->sc_msize = ia->ia_msize;
    582 	sc->sc_maddr = (void *)memh;
    583 	sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24);
    584 
    585 	/* set up pointers to important on-card control structures */
    586 	sc->iscp = 0;
    587 	sc->scb = IE_ISCP_SZ;
    588 	sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24);
    589 
    590 	sc->buf_area = sc->scb + IE_SCB_SZ;
    591 	sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;
    592 
    593 	/* zero card memory */
    594 	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
    595 
    596 	/* set card to 16-bit bus mode */
    597 	bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp), 0);
    598 
    599 	/* set up pointers to key structures */
    600 	ef_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
    601 	ef_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
    602 	ef_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);
    603 
    604 	/* flush setup of pointers, check if chip answers */
    605 	bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
    606 			  BUS_SPACE_BARRIER_WRITE);
    607 	if (!i82586_proberam(sc)) {
    608 		DPRINTF(("\n%s: can't talk to i82586!\n",
    609 			sc->sc_dev.dv_xname));
    610 		bus_space_unmap(ia->ia_iot, ioh, ia->ia_iosize);
    611 		bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
    612 		return;
    613 	}
    614 
    615 	/* set bank 2 for card part number and revision */
    616 	bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_CTRL,
    617 			  EF_CTRL_NRST | EF_CTRL_BNK2);
    618 
    619 	/* card revision is encoded in BCD */
    620 	i = bus_space_read_1(esc->sc_regt, esc->sc_regh, EF_REV);
    621 	esc->card_rev = 10 * (i / 16) + (i % 16);
    622 
    623 	for (i = 0; i < EF_TYPE_LEN; i++)
    624 		partno[i] = bus_space_read_1(esc->sc_regt, esc->sc_regh,
    625 					     EF_TYPE + i);
    626 
    627 	/* use part number to guess if card is TP or AUI/BNC model */
    628 	esc->card_type = EF_IS_TP(partno) ? EF_CARD_TP : EF_CARD_BNC;
    629 
    630 	/* set bank 0 for ethernet address */
    631 	bus_space_write_1(esc->sc_regt, esc->sc_regh,
    632 			  EF_CTRL, EF_CTRL_NORMAL);
    633 
    634 	for (i = 0; i < EF_ADDR_LEN; i++)
    635 		ethaddr[i] = bus_space_read_1(esc->sc_regt, esc->sc_regh,
    636 					      EF_ADDR + i);
    637 
    638 	sprintf(version, "%s, rev. %d",
    639 		(esc->card_type == EF_CARD_TP) ? "3C507-TP" : "3C507",
    640 		esc->card_rev);
    641 
    642 	if (esc->card_type == EF_CARD_TP)
    643 		i82586_attach(sc, version, ethaddr, eftp_media, NEFTP_MEDIA,
    644 			      eftp_media[0]);
    645 	else {
    646 		u_int8_t media = bus_space_read_1(esc->sc_regt, esc->sc_regh,
    647 						  EF_MEDIA);
    648 		media = (media & EF_MEDIA_MASK) >> EF_MEDIA_SHIFT;
    649 
    650 		i82586_attach(sc, version, ethaddr, ef_media, NEF_MEDIA,
    651 			      ef_media[media]);
    652 	}
    653 
    654 	/* Clear the interrupt latch just in case. */
    655 	bus_space_write_1(esc->sc_regt, esc->sc_regh, EF_ICTRL, 1);
    656 
    657 	esc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    658 					IPL_NET, i82586_intr, sc);
    659 	if (esc->sc_ih == NULL) {
    660 		DPRINTF(("\n%s: can't establish interrupt\n",
    661 			sc->sc_dev.dv_xname));
    662 	}
    663 }
    664 
    665 static int
    666 ef_port_check(iot, ioh)
    667 	bus_space_tag_t iot;
    668 	bus_space_handle_t ioh;
    669 {
    670 	int i;
    671         u_char ch;
    672 	u_char* signature = EF_SIGNATURE;
    673 
    674 	for (i = 0; i < strlen(signature); i++) {
    675 		ch = bus_space_read_1(iot, ioh, i);
    676 		if (ch != signature[i])
    677 			return 0;
    678 	}
    679 
    680 	/* If card is mapped in high memory (above 15Meg), we can't use it */
    681 	ch = bus_space_read_1(iot, ioh, EF_MADDR);
    682 	if (ch & EF_MADDR_HIGH)
    683 	    return 0;			/* XXX: maybe we should panic?? */
    684 
    685 	return 1;
    686 }
    687 
    688 struct cfattach ef_ca = {
    689 	sizeof(struct ef_softc), ef_match, ef_attach
    690 };
    691 
    692