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