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