Home | History | Annotate | Line # | Download | only in isa
if_ai.c revision 1.9.2.6
      1  1.9.2.6   nathanw /*	$NetBSD: if_ai.c,v 1.9.2.6 2002/02/28 04:13:41 nathanw 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.9.2.3   nathanw 
     39  1.9.2.3   nathanw #include <sys/cdefs.h>
     40  1.9.2.6   nathanw __KERNEL_RCSID(0, "$NetBSD: if_ai.c,v 1.9.2.6 2002/02/28 04:13:41 nathanw Exp $");
     41      1.1        pk 
     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_aireg.h>
     66      1.1        pk 
     67      1.1        pk #ifdef AI_DEBUG
     68      1.1        pk #define DPRINTF(x)	printf x
     69      1.1        pk #else
     70      1.2        pk #define DPRINTF(x)
     71      1.1        pk #endif
     72      1.1        pk 
     73      1.1        pk struct ai_softc {
     74      1.1        pk 	struct ie_softc sc_ie;
     75      1.1        pk 
     76      1.1        pk 	bus_space_tag_t sc_regt;	/* space tag for registers */
     77      1.1        pk 	bus_space_handle_t sc_regh;	/* space handle for registers */
     78      1.1        pk 
     79      1.1        pk 	u_int8_t	card_rev;
     80      1.1        pk 	u_int8_t	card_type;
     81      1.1        pk 
     82      1.2        pk 	void		*sc_ih;		/* interrupt handle */
     83      1.1        pk };
     84      1.1        pk 
     85      1.1        pk const char *ai_names[] = {
     86      1.1        pk         "StarLAN 10",
     87      1.1        pk         "EN100",
     88      1.1        pk         "StarLAN Fiber",
     89      1.1        pk };
     90      1.1        pk 
     91      1.1        pk /* Functions required by the i82586 MI driver */
     92      1.1        pk static void 	ai_reset __P((struct ie_softc *, int));
     93  1.9.2.1   nathanw static void 	ai_atten __P((struct ie_softc *, int));
     94      1.1        pk 
     95      1.2        pk static void	ai_copyin __P((struct ie_softc *, void *, int, size_t));
     96      1.1        pk static void	ai_copyout __P((struct ie_softc *, const void *, int, size_t));
     97      1.2        pk 
     98      1.1        pk static u_int16_t ai_read_16 __P((struct ie_softc *, int));
     99      1.1        pk static void	ai_write_16 __P((struct ie_softc *, int, u_int16_t));
    100      1.1        pk static void	ai_write_24 __P((struct ie_softc *, int, int));
    101      1.2        pk 
    102      1.1        pk /* Local support functions */
    103      1.1        pk static int 	check_ie_present __P((struct ie_softc*, bus_space_tag_t,
    104      1.1        pk 					bus_space_handle_t, bus_size_t));
    105      1.2        pk static int	ai_find_mem_size __P((struct ai_softc*, bus_space_tag_t,
    106      1.1        pk 					bus_size_t));
    107      1.1        pk 
    108      1.1        pk int ai_match __P((struct device *, struct cfdata *, void *));
    109      1.1        pk void ai_attach __P((struct device *, struct device *, void *));
    110      1.1        pk 
    111      1.1        pk /*
    112      1.1        pk  * AT&T StarLan support routines
    113      1.1        pk  */
    114      1.1        pk static void
    115      1.1        pk ai_reset(sc, why)
    116      1.1        pk 	struct ie_softc *sc;
    117      1.1        pk 	int why;
    118      1.1        pk {
    119      1.2        pk 	struct ai_softc* asc = (struct ai_softc *) sc;
    120      1.1        pk 
    121      1.2        pk 	switch (why) {
    122      1.2        pk 	case CHIP_PROBE:
    123      1.2        pk 		/* reset to chip to see if it responds */
    124      1.2        pk 		bus_space_write_1(asc->sc_regt, asc->sc_regh, AI_RESET, 0);
    125      1.2        pk 		DELAY(100);
    126      1.2        pk 		break;
    127      1.2        pk 
    128      1.2        pk 	case CARD_RESET:
    129      1.2        pk 		/*
    130      1.2        pk 		 * this takes around 10sec, and we can get
    131      1.2        pk 		 * by quite well w/out it...
    132      1.2        pk 		 */
    133      1.2        pk 		break;
    134      1.2        pk 	}
    135      1.1        pk }
    136      1.1        pk 
    137      1.1        pk static void
    138  1.9.2.1   nathanw ai_atten(sc, why)
    139      1.1        pk 	struct ie_softc *sc;
    140  1.9.2.1   nathanw 	int why;
    141      1.1        pk {
    142      1.1        pk     struct ai_softc* asc = (struct ai_softc *) sc;
    143      1.1        pk     bus_space_write_1(asc->sc_regt, asc->sc_regh, AI_ATTN, 0);
    144      1.1        pk }
    145      1.1        pk 
    146      1.1        pk static void
    147      1.1        pk ai_copyin (sc, dst, offset, size)
    148      1.1        pk         struct ie_softc *sc;
    149      1.1        pk         void *dst;
    150      1.1        pk         int offset;
    151      1.1        pk         size_t size;
    152      1.1        pk {
    153      1.2        pk 	int dribble;
    154      1.2        pk 	u_int8_t* bptr = dst;
    155      1.1        pk 
    156      1.2        pk 	bus_space_barrier(sc->bt, sc->bh, offset, size,
    157      1.2        pk 			  BUS_SPACE_BARRIER_READ);
    158      1.1        pk 
    159      1.2        pk 	if (offset % 2) {
    160      1.2        pk 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    161      1.2        pk 		offset++; bptr++; size--;
    162      1.2        pk 	}
    163      1.2        pk 
    164      1.2        pk 	dribble = size % 2;
    165      1.2        pk 	bus_space_read_region_2(sc->bt, sc->bh, offset, (u_int16_t *) bptr,
    166      1.2        pk 				size >> 1);
    167      1.2        pk 
    168      1.2        pk 	if (dribble) {
    169      1.2        pk 		bptr += size - 1;
    170      1.2        pk 		offset += size - 1;
    171      1.2        pk 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    172      1.2        pk 	}
    173      1.1        pk }
    174      1.1        pk 
    175      1.1        pk static void
    176      1.2        pk ai_copyout (sc, src, offset, size)
    177      1.1        pk         struct ie_softc *sc;
    178      1.1        pk         const void *src;
    179      1.1        pk         int offset;
    180      1.1        pk         size_t size;
    181      1.1        pk {
    182      1.2        pk 	int dribble;
    183      1.2        pk 	int osize = size;
    184      1.2        pk 	int ooffset = offset;
    185      1.2        pk 	const u_int8_t* bptr = src;
    186      1.2        pk 
    187      1.2        pk 	if (offset % 2) {
    188      1.2        pk 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    189      1.2        pk 		offset++; bptr++; size--;
    190      1.2        pk 	}
    191      1.2        pk 
    192      1.2        pk 	dribble = size % 2;
    193      1.2        pk 	bus_space_write_region_2(sc->bt, sc->bh, offset, (u_int16_t *)bptr,
    194      1.2        pk 				 size >> 1);
    195      1.2        pk 	if (dribble) {
    196      1.2        pk 		bptr += size - 1;
    197      1.2        pk 		offset += size - 1;
    198      1.2        pk 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    199      1.2        pk 	}
    200      1.1        pk 
    201      1.2        pk 	bus_space_barrier(sc->bt, sc->bh, ooffset, osize,
    202      1.2        pk 			  BUS_SPACE_BARRIER_WRITE);
    203      1.1        pk }
    204      1.1        pk 
    205      1.1        pk static u_int16_t
    206      1.1        pk ai_read_16 (sc, offset)
    207      1.1        pk         struct ie_softc *sc;
    208      1.1        pk         int offset;
    209      1.1        pk {
    210      1.1        pk 	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
    211      1.1        pk         return bus_space_read_2(sc->bt, sc->bh, offset);
    212      1.1        pk }
    213      1.1        pk 
    214      1.1        pk static void
    215      1.2        pk ai_write_16 (sc, offset, value)
    216      1.1        pk         struct ie_softc *sc;
    217      1.1        pk         int offset;
    218      1.1        pk         u_int16_t value;
    219      1.1        pk {
    220      1.1        pk         bus_space_write_2(sc->bt, sc->bh, offset, value);
    221      1.1        pk 	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
    222      1.1        pk }
    223      1.1        pk 
    224      1.1        pk static void
    225      1.1        pk ai_write_24 (sc, offset, addr)
    226      1.1        pk         struct ie_softc *sc;
    227      1.1        pk         int offset, addr;
    228      1.1        pk {
    229      1.1        pk         bus_space_write_4(sc->bt, sc->bh, offset, addr +
    230      1.1        pk                                 (u_long) sc->sc_maddr - (u_long) sc->sc_iobase);
    231      1.1        pk 	bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
    232      1.1        pk }
    233      1.1        pk 
    234      1.1        pk int
    235      1.1        pk ai_match(parent, cf, aux)
    236      1.1        pk 	struct device *parent;
    237      1.1        pk 	struct cfdata *cf;
    238      1.1        pk 	void *aux;
    239      1.1        pk {
    240      1.2        pk 	int rv = 0;
    241      1.2        pk 	u_int8_t val, type;
    242      1.2        pk 	bus_size_t memsize;
    243      1.3        pk 	bus_space_tag_t iot;
    244      1.2        pk 	bus_space_handle_t ioh;
    245      1.2        pk 	struct isa_attach_args * const ia = aux;
    246      1.3        pk 	struct ai_softc asc;
    247      1.2        pk 
    248  1.9.2.5   nathanw 	if (ia->ia_nio < 1)
    249  1.9.2.5   nathanw 		return (0);
    250  1.9.2.5   nathanw 	if (ia->ia_niomem < 1)
    251  1.9.2.5   nathanw 		return (0);
    252  1.9.2.5   nathanw 	if (ia->ia_nirq < 1)
    253  1.9.2.5   nathanw 		return (0);
    254  1.9.2.5   nathanw 
    255  1.9.2.5   nathanw 	if (ISA_DIRECT_CONFIG(ia))
    256  1.9.2.5   nathanw 		return (0);
    257      1.2        pk 
    258      1.2        pk 	/* Punt if wildcarded port, IRQ or memory address */
    259  1.9.2.5   nathanw 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT ||
    260  1.9.2.5   nathanw 	    ia->ia_iomem[0].ir_addr == ISACF_IRQ_DEFAULT ||
    261  1.9.2.5   nathanw 	    ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT) {
    262      1.2        pk 		DPRINTF((
    263      1.2        pk 		 "ai_match: wildcarded IRQ, IOAddr, or memAddr, skipping\n"));
    264      1.2        pk 		return (0);
    265      1.2        pk 	}
    266      1.2        pk 
    267      1.3        pk 	iot = ia->ia_iot;
    268      1.3        pk 
    269      1.2        pk 	/*
    270      1.2        pk 	 * This probe is horribly bad, but I have no info on this card other
    271      1.2        pk 	 * than the former driver, and it was just as bad!
    272      1.2        pk 	 */
    273  1.9.2.5   nathanw 	if (bus_space_map(iot, ia->ia_io[0].ir_addr,
    274      1.2        pk 			  AI_IOSIZE, 0, &ioh) != 0) {
    275      1.2        pk 
    276      1.2        pk 		DPRINTF(("ai_match: cannot map %d IO ports @ 0x%x\n",
    277      1.2        pk 			 AI_IOSIZE, ia->ia_iobase));
    278      1.2        pk 		return (0);
    279      1.2        pk 	}
    280      1.2        pk 
    281      1.3        pk 	val = bus_space_read_1(iot, ioh, AI_REVISION);
    282      1.2        pk 
    283      1.2        pk 	type = SL_BOARD(val);
    284      1.5        pk 	if (type != SL10_BOARD && type != EN100_BOARD &&
    285      1.2        pk 	    type != SLFIBER_BOARD) {
    286      1.2        pk 		DPRINTF(("ai_match: unknown board code 0x%02x @ 0x%x\n",
    287      1.2        pk 			 type, ia->ia_iobase));
    288      1.2        pk 		goto out;
    289      1.2        pk 	}
    290      1.1        pk 
    291      1.3        pk 	/*
    292      1.3        pk 	 * Fill in just about enough of our local `ai_softc' for
    293      1.3        pk 	 * ai_find_mem_size() to do its job.
    294      1.3        pk 	 */
    295  1.9.2.2   nathanw 	memset(&asc, 0, sizeof asc);
    296      1.3        pk 	asc.sc_regt = iot;
    297      1.3        pk 	asc.sc_regh = ioh;
    298      1.1        pk 
    299  1.9.2.5   nathanw 	if ((memsize = ai_find_mem_size(&asc, ia->ia_memt,
    300  1.9.2.5   nathanw 	     ia->ia_iomem[0].ir_addr)) == 0) {
    301      1.2        pk 		DPRINTF(("ai_match: cannot size memory of board @ 0x%x\n",
    302  1.9.2.5   nathanw 			 ia->ia_io[0].ir_addr));
    303      1.3        pk 		goto out;
    304      1.2        pk 	}
    305      1.1        pk 
    306  1.9.2.5   nathanw 	if (ia->ia_iomem[0].ir_size != 0 &&
    307  1.9.2.5   nathanw 	    ia->ia_iomem[0].ir_size != memsize) {
    308      1.2        pk 		DPRINTF((
    309      1.2        pk 		   "ai_match: memsize of board @ 0x%x doesn't match config\n",
    310      1.2        pk 		   ia->ia_iobase));
    311      1.2        pk 		goto out;
    312      1.2        pk 	}
    313      1.2        pk 
    314      1.2        pk 	rv = 1;
    315  1.9.2.5   nathanw 
    316  1.9.2.5   nathanw 	ia->ia_nio = 1;
    317  1.9.2.5   nathanw 	ia->ia_io[0].ir_size = AI_IOSIZE;
    318  1.9.2.5   nathanw 
    319  1.9.2.5   nathanw 	ia->ia_niomem = 1;
    320  1.9.2.5   nathanw 	ia->ia_iomem[0].ir_size = memsize;
    321  1.9.2.5   nathanw 
    322  1.9.2.5   nathanw 	ia->ia_nirq = 1;
    323  1.9.2.5   nathanw 
    324  1.9.2.5   nathanw 	ia->ia_ndrq = 0;
    325  1.9.2.5   nathanw 
    326      1.2        pk 	DPRINTF(("ai_match: found board @ 0x%x\n", ia->ia_iobase));
    327      1.1        pk 
    328      1.1        pk out:
    329      1.3        pk 	bus_space_unmap(iot, ioh, AI_IOSIZE);
    330      1.2        pk 	return rv;
    331      1.1        pk }
    332      1.1        pk 
    333      1.1        pk void
    334      1.1        pk ai_attach(parent, self, aux)
    335      1.1        pk 	struct device *parent;
    336      1.1        pk 	struct device *self;
    337      1.1        pk 	void   *aux;
    338      1.1        pk {
    339      1.2        pk 	struct ai_softc *asc = (void *)self;
    340      1.2        pk 	struct ie_softc *sc = &asc->sc_ie;
    341      1.2        pk 	struct isa_attach_args *ia = aux;
    342      1.2        pk 
    343      1.2        pk 	u_int8_t val = 0;
    344      1.2        pk 	bus_space_handle_t ioh, memh;
    345      1.2        pk 	u_int8_t ethaddr[ETHER_ADDR_LEN];
    346      1.5        pk 	char name[80];
    347      1.2        pk 
    348  1.9.2.5   nathanw 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr,
    349  1.9.2.5   nathanw 			  ia->ia_io[0].ir_size, 0, &ioh) != 0) {
    350      1.2        pk 		DPRINTF(("\n%s: can't map i/o space 0x%x-0x%x\n",
    351      1.2        pk 			 sc->sc_dev.dv_xname,
    352  1.9.2.5   nathanw 		         ia->ia_io[0].ir_addr, ia->ia_io[0].ir_addr +
    353  1.9.2.5   nathanw 		         ia->ia_io[0].ir_size - 1));
    354      1.2        pk 		return;
    355      1.2        pk 	}
    356      1.2        pk 
    357  1.9.2.5   nathanw 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
    358  1.9.2.5   nathanw 			  ia->ia_iomem[0].ir_size, 0, &memh) != 0) {
    359      1.2        pk 		DPRINTF(("\n%s: can't map iomem space 0x%x-0x%x\n",
    360      1.2        pk 			 sc->sc_dev.dv_xname,
    361  1.9.2.5   nathanw 			 ia->ia_iomem[0].ir_addr, ia->ia_iomem[0].ir_addr +
    362  1.9.2.5   nathanw 			 ia->ia_iomem[0].ir_size - 1));
    363  1.9.2.5   nathanw 		bus_space_unmap(ia->ia_iot, ioh, ia->ia_io[0].ir_size);
    364      1.2        pk 		return;
    365      1.2        pk 	}
    366      1.2        pk 
    367      1.2        pk 	asc->sc_regt = ia->ia_iot;
    368      1.2        pk 	asc->sc_regh = ioh;
    369      1.2        pk 
    370      1.2        pk 	sc->hwinit = NULL;
    371      1.2        pk 	sc->intrhook = NULL;
    372      1.2        pk 	sc->hwreset = ai_reset;
    373      1.2        pk 	sc->chan_attn = ai_atten;
    374      1.9     bjh21 
    375      1.9     bjh21 	sc->ie_bus_barrier = NULL;
    376      1.2        pk 
    377      1.2        pk 	sc->memcopyin = ai_copyin;
    378      1.2        pk 	sc->memcopyout = ai_copyout;
    379      1.2        pk 	sc->ie_bus_read16 = ai_read_16;
    380      1.2        pk 	sc->ie_bus_write16 = ai_write_16;
    381      1.2        pk 	sc->ie_bus_write24 = ai_write_24;
    382      1.2        pk 
    383      1.2        pk 	sc->do_xmitnopchain = 0;
    384      1.2        pk 
    385      1.2        pk 	sc->sc_mediachange = NULL;
    386      1.2        pk 	sc->sc_mediastatus = NULL;
    387      1.2        pk 
    388      1.2        pk 	sc->bt = ia->ia_memt;
    389      1.2        pk 	sc->bh = memh;
    390      1.2        pk 
    391      1.2        pk 	/* Map i/o space. */
    392  1.9.2.5   nathanw 	sc->sc_msize = ia->ia_iomem[0].ir_size;
    393      1.7  augustss 	sc->sc_maddr = (void *)memh;
    394      1.7  augustss 	sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24);
    395      1.2        pk 
    396      1.2        pk 	/* set up pointers to important on-card control structures */
    397      1.2        pk 	sc->iscp = 0;
    398      1.2        pk 	sc->scb = IE_ISCP_SZ;
    399      1.2        pk 	sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24);
    400      1.2        pk 
    401      1.2        pk 	sc->buf_area = sc->scb + IE_SCB_SZ;
    402      1.2        pk 	sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;
    403      1.2        pk 
    404      1.2        pk 	/* zero card memory */
    405      1.2        pk 	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
    406      1.2        pk 
    407      1.2        pk 	/* set card to 16-bit bus mode */
    408  1.9.2.4   nathanw 	bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp),
    409  1.9.2.4   nathanw 			  IE_SYSBUS_16BIT);
    410      1.2        pk 
    411      1.2        pk 	/* set up pointers to key structures */
    412      1.2        pk 	ai_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
    413      1.2        pk 	ai_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
    414      1.2        pk 	ai_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);
    415      1.2        pk 
    416      1.2        pk 	/* flush setup of pointers, check if chip answers */
    417      1.2        pk 	bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
    418      1.2        pk 			  BUS_SPACE_BARRIER_WRITE);
    419      1.2        pk 	if (!i82586_proberam(sc)) {
    420      1.2        pk 		DPRINTF(("\n%s: can't talk to i82586!\n",
    421      1.2        pk 			sc->sc_dev.dv_xname));
    422  1.9.2.5   nathanw 		bus_space_unmap(ia->ia_iot, ioh, ia->ia_io[0].ir_size);
    423  1.9.2.5   nathanw 		bus_space_unmap(ia->ia_memt, memh, ia->ia_iomem[0].ir_size);
    424      1.2        pk 		return;
    425      1.2        pk 	}
    426      1.2        pk 
    427      1.2        pk 	val = bus_space_read_1(asc->sc_regt, asc->sc_regh, AI_REVISION);
    428      1.2        pk 	asc->card_rev = SL_REV(val);
    429      1.2        pk 	asc->card_type = SL_BOARD(val) - 1;
    430      1.5        pk 	sprintf(name, "%s, rev. %d",
    431      1.2        pk 		ai_names[asc->card_type], asc->card_rev);
    432      1.2        pk 
    433      1.5        pk 	i82586_attach(sc, name, ethaddr, NULL, 0, 0);
    434      1.2        pk 
    435  1.9.2.5   nathanw 	asc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
    436  1.9.2.5   nathanw 	    IST_EDGE, IPL_NET, i82586_intr, sc);
    437      1.2        pk 	if (asc->sc_ih == NULL) {
    438      1.2        pk 		DPRINTF(("\n%s: can't establish interrupt\n",
    439      1.2        pk 			sc->sc_dev.dv_xname));
    440      1.2        pk 	}
    441      1.1        pk }
    442      1.1        pk 
    443      1.1        pk /*
    444      1.1        pk  * Divine the memory size of this board.
    445      1.1        pk  * Better hope there's nothing important hiding just below the card...
    446      1.1        pk  */
    447      1.1        pk static int
    448      1.1        pk ai_find_mem_size(asc, memt, maddr)
    449      1.1        pk 	struct ai_softc* asc;
    450      1.1        pk 	bus_space_tag_t memt;
    451      1.1        pk 	bus_size_t maddr;
    452      1.1        pk {
    453      1.1        pk 	int size;
    454      1.1        pk 	bus_space_handle_t memh;
    455      1.1        pk 	struct ie_softc* sc = &asc->sc_ie;
    456      1.1        pk 
    457      1.1        pk 	for (size = 65536; size >= 16384; size -= 16384) {
    458      1.2        pk 		if (bus_space_map(memt, maddr, size, 0, &memh) == 0) {
    459      1.2        pk 			size = check_ie_present(sc, memt, maddr, size);
    460      1.2        pk 			bus_space_unmap(memt, memh, size);
    461      1.2        pk 
    462      1.2        pk 			if (size != 0)
    463      1.2        pk 				return size;
    464      1.2        pk 		}
    465      1.1        pk 	}
    466      1.1        pk 
    467      1.2        pk 	return (0);
    468      1.1        pk }
    469      1.1        pk 
    470      1.1        pk /*
    471      1.1        pk  * Check to see if there's an 82586 out there.
    472      1.1        pk  */
    473      1.1        pk static int
    474      1.1        pk check_ie_present(sc, memt, memh, size)
    475      1.1        pk 	struct ie_softc* sc;
    476      1.1        pk 	bus_space_tag_t memt;
    477      1.1        pk 	bus_space_handle_t memh;
    478      1.1        pk 	bus_size_t size;
    479      1.1        pk {
    480      1.2        pk 	sc->hwreset = ai_reset;
    481      1.2        pk 	sc->chan_attn = ai_atten;
    482      1.2        pk 	sc->ie_bus_read16 = ai_read_16;
    483      1.2        pk 	sc->ie_bus_write16 = ai_write_16;
    484      1.2        pk 
    485      1.2        pk 	sc->bt = memt;
    486      1.2        pk 	sc->bh = memh;
    487      1.7  augustss 	sc->sc_iobase = (char *)memh + size - (1 << 24);
    488      1.2        pk 
    489      1.2        pk 	sc->scp = size + IE_SCP_ADDR - (1 << 24);
    490      1.2        pk 	bus_space_set_region_1(memt, memh, (u_long) sc->scp, 0, IE_SCP_SZ);
    491      1.2        pk 
    492      1.2        pk 	sc->iscp = 0;
    493      1.2        pk 	bus_space_set_region_1(memt, memh, (u_long) sc->iscp, 0, IE_ISCP_SZ);
    494      1.2        pk 
    495      1.2        pk 	sc->scb = IE_ISCP_SZ;
    496      1.2        pk 	bus_space_set_region_1(memt, memh, sc->scb, 0, IE_SCB_SZ);
    497      1.2        pk 
    498      1.2        pk 	/* set card to 16-bit bus mode */
    499  1.9.2.4   nathanw 	bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp),
    500  1.9.2.4   nathanw 			  IE_SYSBUS_16BIT);
    501      1.2        pk 
    502      1.2        pk 	/* set up pointers to key structures */
    503      1.2        pk 	ai_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
    504      1.2        pk 	ai_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
    505      1.2        pk 	ai_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);
    506      1.2        pk 
    507      1.2        pk 	/* flush setup of pointers, check if chip answers */
    508      1.2        pk 	bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
    509      1.2        pk 			  BUS_SPACE_BARRIER_WRITE);
    510      1.2        pk 
    511      1.2        pk 	if (!i82586_proberam(sc))
    512      1.2        pk 		return (0);
    513      1.1        pk 
    514      1.2        pk 	return (size);
    515      1.1        pk }
    516      1.1        pk 
    517      1.1        pk struct cfattach ai_ca = {
    518      1.1        pk 	sizeof(struct ai_softc), ai_match, ai_attach
    519      1.1        pk };
    520