Home | History | Annotate | Line # | Download | only in mca
if_elmc_mca.c revision 1.19.10.1
      1  1.19.10.1      elad /*	$NetBSD: if_elmc_mca.c,v 1.19.10.1 2006/04/19 03:25:18 elad Exp $	*/
      2        1.1  jdolecek 
      3        1.1  jdolecek /*-
      4        1.1  jdolecek  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5        1.1  jdolecek  * All rights reserved.
      6        1.1  jdolecek  *
      7        1.1  jdolecek  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1  jdolecek  * by Rafal K. Boni and Jaromir Dolecek.
      9        1.1  jdolecek  *
     10        1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     11        1.1  jdolecek  * modification, are permitted provided that the following conditions
     12        1.1  jdolecek  * are met:
     13        1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     14        1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     15        1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     17        1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     18        1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     19        1.1  jdolecek  *    must display the following acknowledgement:
     20        1.1  jdolecek  *	This product includes software developed by the NetBSD
     21        1.1  jdolecek  *	Foundation, Inc. and its contributors.
     22        1.1  jdolecek  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23        1.1  jdolecek  *    contributors may be used to endorse or promote products derived
     24        1.1  jdolecek  *    from this software without specific prior written permission.
     25        1.1  jdolecek  *
     26        1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27        1.1  jdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28        1.1  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29        1.1  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30        1.1  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31        1.1  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32        1.1  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33        1.1  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34        1.1  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35        1.1  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36        1.1  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     37        1.1  jdolecek  */
     38        1.1  jdolecek 
     39        1.1  jdolecek /*
     40        1.1  jdolecek  * 3Com 3c523 EtherLink/MC Ethernet card driver (uses i82586 Ethernet chip).
     41        1.1  jdolecek  *
     42        1.1  jdolecek  * The 3c523-specific hooks were derived from Linux driver (file
     43        1.1  jdolecek  * drivers/net/3c523.[ch]).
     44        1.1  jdolecek  *
     45        1.1  jdolecek  * This driver uses generic i82586 stuff. See also ai(4), ef(4), ix(4).
     46        1.1  jdolecek  */
     47        1.7     lukem 
     48        1.7     lukem #include <sys/cdefs.h>
     49  1.19.10.1      elad __KERNEL_RCSID(0, "$NetBSD: if_elmc_mca.c,v 1.19.10.1 2006/04/19 03:25:18 elad Exp $");
     50        1.1  jdolecek 
     51        1.1  jdolecek #include <sys/param.h>
     52        1.1  jdolecek #include <sys/systm.h>
     53        1.1  jdolecek #include <sys/mbuf.h>
     54        1.1  jdolecek #include <sys/errno.h>
     55        1.1  jdolecek #include <sys/device.h>
     56        1.1  jdolecek #include <sys/protosw.h>
     57        1.1  jdolecek #include <sys/socket.h>
     58        1.1  jdolecek 
     59        1.1  jdolecek #include <net/if.h>
     60        1.1  jdolecek #include <net/if_types.h>
     61        1.1  jdolecek #include <net/if_media.h>
     62        1.1  jdolecek #include <net/if_ether.h>
     63        1.1  jdolecek 
     64        1.1  jdolecek #include <machine/bus.h>
     65        1.1  jdolecek 
     66        1.1  jdolecek #include <dev/ic/i82586reg.h>
     67        1.1  jdolecek #include <dev/ic/i82586var.h>
     68        1.1  jdolecek #include <dev/mca/mcadevs.h>
     69        1.1  jdolecek #include <dev/mca/mcavar.h>
     70        1.1  jdolecek 
     71        1.1  jdolecek #include <dev/mca/3c523reg.h>
     72        1.1  jdolecek 
     73        1.1  jdolecek struct elmc_mca_softc {
     74        1.1  jdolecek 	struct ie_softc sc_ie;
     75        1.1  jdolecek 
     76        1.1  jdolecek 	bus_space_tag_t sc_regt;	/* space tag for registers */
     77        1.1  jdolecek 	bus_space_handle_t sc_regh;	/* space handle for registers */
     78        1.1  jdolecek 
     79        1.1  jdolecek 	void		*sc_ih;		/* interrupt handle */
     80        1.1  jdolecek };
     81        1.1  jdolecek 
     82       1.16     perry int	elmc_mca_match(struct device *, struct cfdata *, void *);
     83       1.16     perry void	elmc_mca_attach(struct device *, struct device *, void *);
     84        1.1  jdolecek 
     85       1.16     perry static void	elmc_mca_copyin(struct ie_softc *, void *, int, size_t);
     86       1.16     perry static void	elmc_mca_copyout(struct ie_softc *, const void *, int, size_t);
     87       1.16     perry static u_int16_t elmc_mca_read_16(struct ie_softc *, int);
     88       1.16     perry static void	elmc_mca_write_16(struct ie_softc *, int, u_int16_t);
     89       1.16     perry static void	elmc_mca_write_24(struct ie_softc *, int, int);
     90       1.16     perry static void	elmc_mca_attn(struct ie_softc *, int);
     91       1.16     perry static void	elmc_mca_hwreset(struct ie_softc *, int);
     92       1.16     perry static int	elmc_mca_intrhook(struct ie_softc *, int);
     93        1.1  jdolecek 
     94        1.1  jdolecek int
     95        1.1  jdolecek elmc_mca_match(struct device *parent, struct cfdata *cf, void *aux)
     96        1.1  jdolecek {
     97        1.1  jdolecek 	struct mca_attach_args *ma = aux;
     98        1.1  jdolecek 
     99        1.1  jdolecek 	switch (ma->ma_id) {
    100        1.1  jdolecek 	case MCA_PRODUCT_3C523:
    101        1.1  jdolecek 		return 1;
    102        1.1  jdolecek 	}
    103        1.1  jdolecek 
    104        1.1  jdolecek 	return 0;
    105        1.1  jdolecek }
    106        1.1  jdolecek 
    107        1.1  jdolecek void
    108        1.1  jdolecek elmc_mca_attach(struct device *parent, struct device *self, void *aux)
    109        1.1  jdolecek {
    110  1.19.10.1      elad 	struct elmc_mca_softc *asc = device_private(self);
    111        1.1  jdolecek 	struct ie_softc *sc = &asc->sc_ie;
    112        1.1  jdolecek 	struct mca_attach_args *ma = aux;
    113        1.1  jdolecek 	int pos2, pos3, i, revision;
    114        1.1  jdolecek 	int iobase, irq, pbram_addr;
    115        1.1  jdolecek 	bus_space_handle_t ioh, memh;
    116        1.1  jdolecek 	u_int8_t myaddr[ETHER_ADDR_LEN];
    117        1.1  jdolecek 
    118        1.1  jdolecek 	pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
    119        1.1  jdolecek 	pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
    120        1.1  jdolecek 
    121        1.1  jdolecek 	/*
    122        1.1  jdolecek 	 * POS register 2: (adf pos0)
    123       1.17     perry 	 *
    124        1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    125        1.1  jdolecek 	 *     \ \_/ \_/ \__ enable: 0=adapter disabled, 1=adapter enabled
    126        1.1  jdolecek 	 *      \  \   \____ I/O Address Range: 00=300-307, 01=1300-1307,
    127        1.1  jdolecek 	 *       \  \                           10=2300-2307, 11=3300-3307
    128        1.1  jdolecek 	 *        \  \______ Packet Buffer RAM Address Range:
    129        1.1  jdolecek 	 *         \            00=0x0c0000-0x0c5fff 01=0x0c8000-0x0cdfff
    130        1.1  jdolecek 	 *          \           10=0x0d0000-0x0d5fff 11=0x0d8000-0x0ddfff
    131        1.1  jdolecek 	 *           \______ Transceiver Type: 0=onboard(BNC) 1=ext(DIX)
    132        1.1  jdolecek 	 *
    133        1.1  jdolecek 	 * POS register 3: (adf pos1)
    134       1.17     perry 	 *
    135        1.1  jdolecek 	 * 7 6 5 4 3 2 1 0
    136        1.1  jdolecek 	 *          \____/
    137        1.1  jdolecek 	 *               \__ Interrupt level: 0100=3, 0010=7, 1000=9, 0001=12
    138        1.1  jdolecek 	 */
    139        1.1  jdolecek 
    140        1.1  jdolecek 	iobase = ELMC_IOADDR_BASE + (0x1000 * ((pos2 & 0x6) >> 1));
    141        1.1  jdolecek 
    142        1.1  jdolecek 	/* get irq */
    143        1.1  jdolecek 	switch (pos3 & 0x1f) {
    144        1.1  jdolecek 	case 4: irq = 3; break;
    145        1.1  jdolecek 	case 2: irq = 7; break;
    146        1.1  jdolecek 	case 8: irq = 9; break;
    147        1.1  jdolecek 	case 1: irq = 12; break;
    148       1.13  christos 	default:
    149       1.15  jdolecek 		printf(": cannot determine irq\n");
    150       1.14   mycroft 		return;
    151        1.1  jdolecek 	}
    152        1.1  jdolecek 
    153       1.15  jdolecek 	pbram_addr = ELMC_MADDR_BASE + (((pos2 & 0x18) >> 3) * 0x8000);
    154        1.1  jdolecek 
    155        1.5  jdolecek 	printf(" slot %d irq %d: 3Com EtherLink/MC Ethernet Adapter (3C523)\n",
    156        1.5  jdolecek 		ma->ma_slot + 1, irq);
    157        1.5  jdolecek 
    158        1.1  jdolecek 	/* map the pio registers */
    159        1.1  jdolecek 	if (bus_space_map(ma->ma_iot, iobase, ELMC_IOADDR_SIZE, 0, &ioh)) {
    160        1.1  jdolecek 		printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
    161        1.1  jdolecek 		return;
    162        1.1  jdolecek 	}
    163        1.1  jdolecek 
    164        1.1  jdolecek 	/*
    165        1.1  jdolecek 	 * 3c523 has a 24K memory. The first 16K is the shared memory, while
    166        1.1  jdolecek 	 * the last 8K is for the EtherStart BIOS ROM, which we don't care
    167        1.1  jdolecek 	 * about. Just use the first 16K.
    168        1.1  jdolecek 	 */
    169        1.1  jdolecek 	if (bus_space_map(ma->ma_memt, pbram_addr, ELMC_MADDR_SIZE, 0, &memh)) {
    170        1.1  jdolecek 		printf("%s: unable to map memory space\n", sc->sc_dev.dv_xname);
    171        1.1  jdolecek 		if (pbram_addr == 0xc0000) {
    172        1.1  jdolecek 			printf("%s: memory space 0xc0000 may conflict with vga\n",
    173        1.1  jdolecek 				sc->sc_dev.dv_xname);
    174        1.1  jdolecek 		}
    175       1.17     perry 
    176        1.1  jdolecek 		bus_space_unmap(ma->ma_iot, ioh, ELMC_IOADDR_SIZE);
    177        1.1  jdolecek 		return;
    178        1.1  jdolecek 	}
    179        1.1  jdolecek 
    180        1.1  jdolecek 	asc->sc_regt = ma->ma_iot;
    181        1.1  jdolecek 	asc->sc_regh = ioh;
    182        1.1  jdolecek 
    183        1.1  jdolecek 	sc->hwinit = NULL;
    184        1.1  jdolecek 	sc->intrhook = elmc_mca_intrhook;
    185        1.1  jdolecek 	sc->hwreset = elmc_mca_hwreset;
    186        1.1  jdolecek 	sc->chan_attn = elmc_mca_attn;
    187        1.1  jdolecek 
    188        1.1  jdolecek 	sc->ie_bus_barrier = NULL;
    189        1.1  jdolecek 
    190        1.1  jdolecek 	sc->memcopyin = elmc_mca_copyin;
    191        1.1  jdolecek 	sc->memcopyout = elmc_mca_copyout;
    192        1.1  jdolecek 	sc->ie_bus_read16 = elmc_mca_read_16;
    193        1.1  jdolecek 	sc->ie_bus_write16 = elmc_mca_write_16;
    194        1.1  jdolecek 	sc->ie_bus_write24 = elmc_mca_write_24;
    195        1.1  jdolecek 
    196        1.1  jdolecek 	sc->do_xmitnopchain = 0;
    197        1.1  jdolecek 
    198        1.1  jdolecek 	sc->sc_mediachange = NULL;
    199        1.1  jdolecek 	sc->sc_mediastatus = NULL;
    200        1.1  jdolecek 
    201        1.1  jdolecek 	sc->bt = ma->ma_memt;
    202        1.1  jdolecek 	sc->bh = memh;
    203        1.1  jdolecek 
    204        1.1  jdolecek 	/* Map i/o space. */
    205        1.1  jdolecek 	sc->sc_msize = ELMC_MADDR_SIZE;
    206        1.1  jdolecek 	sc->sc_maddr = (void *)memh;
    207        1.1  jdolecek 	sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24);
    208        1.1  jdolecek 
    209        1.1  jdolecek 	/* set up pointers to important on-card control structures */
    210        1.1  jdolecek 	sc->iscp = 0;
    211        1.1  jdolecek 	sc->scb = IE_ISCP_SZ;
    212        1.1  jdolecek 	sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24);
    213        1.1  jdolecek 
    214        1.1  jdolecek 	sc->buf_area = sc->scb + IE_SCB_SZ;
    215        1.1  jdolecek 	sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;
    216        1.1  jdolecek 
    217        1.2  jdolecek 	/*
    218        1.2  jdolecek 	 * According to docs, we might need to read the interrupt number and
    219        1.2  jdolecek 	 * write it back to the IRQ select register, since the POST might not
    220        1.2  jdolecek 	 * configure the IRQ properly.
    221        1.2  jdolecek 	 */
    222        1.2  jdolecek 	(void) mca_conf_write(ma->ma_mc, ma->ma_slot, 3, pos3 & 0x1f);
    223        1.2  jdolecek 
    224        1.1  jdolecek 	/* reset the card first */
    225        1.1  jdolecek 	elmc_mca_hwreset(sc, CARD_RESET);
    226        1.1  jdolecek 	delay(1000000 / ( 1<< 5));
    227        1.1  jdolecek 
    228        1.1  jdolecek 	/* zero card memory */
    229        1.1  jdolecek 	bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
    230        1.1  jdolecek 
    231        1.1  jdolecek 	/* set card to 16-bit bus mode */
    232        1.8  fredette 	bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp),
    233        1.8  fredette 			  IE_SYSBUS_16BIT);
    234        1.1  jdolecek 
    235        1.1  jdolecek 	/* set up pointers to key structures */
    236        1.1  jdolecek 	elmc_mca_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
    237        1.1  jdolecek 	elmc_mca_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
    238        1.1  jdolecek 	elmc_mca_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);
    239        1.1  jdolecek 
    240        1.1  jdolecek 	/* flush setup of pointers, check if chip answers */
    241        1.1  jdolecek 	bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
    242        1.1  jdolecek 			  BUS_SPACE_BARRIER_WRITE);
    243        1.1  jdolecek 	if (!i82586_proberam(sc)) {
    244        1.1  jdolecek 		printf("%s: can't talk to i82586!\n", sc->sc_dev.dv_xname);
    245        1.1  jdolecek 
    246        1.1  jdolecek 		bus_space_unmap(asc->sc_regt, asc->sc_regh, ELMC_IOADDR_SIZE);
    247        1.1  jdolecek 		bus_space_unmap(sc->bt, sc->bh, ELMC_MADDR_SIZE);
    248        1.1  jdolecek 		return;
    249        1.1  jdolecek 	}
    250        1.1  jdolecek 
    251        1.1  jdolecek 	/* revision is stored in the first 4 bits of the revision register */
    252        1.1  jdolecek 	revision = (int) bus_space_read_1(asc->sc_regt, asc->sc_regh,
    253        1.1  jdolecek 				ELMC_REVISION) & ELMC_REVISION_MASK;
    254        1.1  jdolecek 
    255        1.1  jdolecek 	/* dump known info */
    256        1.1  jdolecek 	printf("%s: rev %d, i/o %#04x-%#04x, mem %#06x-%#06x, %sternal xcvr\n",
    257        1.1  jdolecek 		sc->sc_dev.dv_xname, revision,
    258        1.1  jdolecek 		iobase, iobase + ELMC_IOADDR_SIZE - 1,
    259        1.1  jdolecek 		pbram_addr, pbram_addr + ELMC_MADDR_SIZE - 1,
    260        1.1  jdolecek 		(pos2 & 0x20) ? "ex" : "in");
    261        1.1  jdolecek 
    262        1.1  jdolecek 	/*
    263        1.1  jdolecek 	 * Hardware ethernet address is stored in the first six bytes
    264        1.1  jdolecek 	 * of the IO space.
    265        1.1  jdolecek 	 */
    266        1.1  jdolecek 	for(i=0; i < MIN(6, ETHER_ADDR_LEN); i++)
    267        1.1  jdolecek 		myaddr[i] = bus_space_read_1(asc->sc_regt, asc->sc_regh, i);
    268        1.1  jdolecek 
    269        1.1  jdolecek 	printf("%s:", sc->sc_dev.dv_xname);
    270        1.1  jdolecek 	i82586_attach((void *)sc, "3C523", myaddr, NULL, 0, 0);
    271        1.1  jdolecek 
    272        1.1  jdolecek 	/* establish interrupt handler */
    273        1.1  jdolecek 	asc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, i82586_intr,
    274        1.1  jdolecek 			sc);
    275        1.5  jdolecek 	if (asc->sc_ih == NULL) {
    276        1.1  jdolecek 		printf("%s: couldn't establish interrupt handler\n",
    277        1.1  jdolecek 		       sc->sc_dev.dv_xname);
    278        1.5  jdolecek 		return;
    279        1.5  jdolecek 	}
    280        1.1  jdolecek }
    281        1.1  jdolecek 
    282        1.1  jdolecek static void
    283        1.1  jdolecek elmc_mca_copyin (sc, dst, offset, size)
    284        1.1  jdolecek         struct ie_softc *sc;
    285        1.1  jdolecek         void *dst;
    286        1.1  jdolecek         int offset;
    287        1.1  jdolecek         size_t size;
    288        1.1  jdolecek {
    289        1.1  jdolecek 	int dribble;
    290        1.1  jdolecek 	u_int8_t* bptr = dst;
    291        1.1  jdolecek 
    292        1.1  jdolecek 	bus_space_barrier(sc->bt, sc->bh, offset, size,
    293        1.1  jdolecek 			  BUS_SPACE_BARRIER_READ);
    294        1.1  jdolecek 
    295        1.1  jdolecek 	if (offset % 2) {
    296        1.1  jdolecek 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    297        1.1  jdolecek 		offset++; bptr++; size--;
    298        1.1  jdolecek 	}
    299        1.1  jdolecek 
    300        1.1  jdolecek 	dribble = size % 2;
    301        1.1  jdolecek 	bus_space_read_region_2(sc->bt, sc->bh, offset, (u_int16_t *) bptr,
    302        1.1  jdolecek 				size >> 1);
    303        1.1  jdolecek 
    304        1.1  jdolecek 	if (dribble) {
    305        1.1  jdolecek 		bptr += size - 1;
    306        1.1  jdolecek 		offset += size - 1;
    307        1.1  jdolecek 		*bptr = bus_space_read_1(sc->bt, sc->bh, offset);
    308        1.1  jdolecek 	}
    309        1.1  jdolecek }
    310        1.1  jdolecek 
    311        1.1  jdolecek static void
    312        1.1  jdolecek elmc_mca_copyout (sc, src, offset, size)
    313        1.1  jdolecek         struct ie_softc *sc;
    314        1.1  jdolecek         const void *src;
    315        1.1  jdolecek         int offset;
    316        1.1  jdolecek         size_t size;
    317        1.1  jdolecek {
    318        1.1  jdolecek 	int dribble;
    319        1.1  jdolecek 	int osize = size;
    320        1.1  jdolecek 	int ooffset = offset;
    321        1.1  jdolecek 	const u_int8_t* bptr = src;
    322        1.1  jdolecek 
    323        1.1  jdolecek 	if (offset % 2) {
    324        1.1  jdolecek 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    325        1.1  jdolecek 		offset++; bptr++; size--;
    326        1.1  jdolecek 	}
    327        1.1  jdolecek 
    328        1.1  jdolecek 	dribble = size % 2;
    329       1.18  christos 	bus_space_write_region_2(sc->bt, sc->bh, offset,
    330       1.18  christos 	    (const u_int16_t *)bptr, size >> 1);
    331        1.1  jdolecek 	if (dribble) {
    332        1.1  jdolecek 		bptr += size - 1;
    333        1.1  jdolecek 		offset += size - 1;
    334        1.1  jdolecek 		bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
    335        1.1  jdolecek 	}
    336        1.1  jdolecek 
    337        1.1  jdolecek 	bus_space_barrier(sc->bt, sc->bh, ooffset, osize,
    338        1.1  jdolecek 			  BUS_SPACE_BARRIER_WRITE);
    339        1.1  jdolecek }
    340        1.1  jdolecek 
    341        1.1  jdolecek static u_int16_t
    342        1.1  jdolecek elmc_mca_read_16 (sc, offset)
    343        1.1  jdolecek         struct ie_softc *sc;
    344        1.1  jdolecek         int offset;
    345        1.1  jdolecek {
    346        1.1  jdolecek 	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
    347        1.1  jdolecek         return bus_space_read_2(sc->bt, sc->bh, offset);
    348        1.1  jdolecek }
    349        1.1  jdolecek 
    350        1.1  jdolecek static void
    351        1.1  jdolecek elmc_mca_write_16 (sc, offset, value)
    352        1.1  jdolecek         struct ie_softc *sc;
    353        1.1  jdolecek         int offset;
    354        1.1  jdolecek         u_int16_t value;
    355        1.1  jdolecek {
    356        1.1  jdolecek         bus_space_write_2(sc->bt, sc->bh, offset, value);
    357        1.1  jdolecek 	bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
    358        1.1  jdolecek }
    359        1.1  jdolecek 
    360        1.1  jdolecek static void
    361        1.1  jdolecek elmc_mca_write_24 (sc, offset, addr)
    362        1.1  jdolecek         struct ie_softc *sc;
    363        1.1  jdolecek         int offset, addr;
    364        1.1  jdolecek {
    365        1.1  jdolecek         bus_space_write_4(sc->bt, sc->bh, offset, addr +
    366        1.1  jdolecek                                 (u_long) sc->sc_maddr - (u_long) sc->sc_iobase);
    367        1.1  jdolecek 	bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
    368        1.1  jdolecek }
    369        1.1  jdolecek 
    370        1.1  jdolecek /*
    371        1.1  jdolecek  * Channel attention hook.
    372        1.1  jdolecek  */
    373        1.1  jdolecek static void
    374        1.1  jdolecek elmc_mca_attn(sc, why)
    375        1.1  jdolecek 	struct ie_softc *sc;
    376        1.1  jdolecek 	int why;
    377        1.1  jdolecek {
    378        1.1  jdolecek     struct elmc_mca_softc* asc = (struct elmc_mca_softc *) sc;
    379        1.1  jdolecek     int intr = 0;
    380        1.1  jdolecek 
    381        1.1  jdolecek     switch (why) {
    382        1.1  jdolecek     case CHIP_PROBE:
    383        1.1  jdolecek 	intr = 0;
    384        1.1  jdolecek 	break;
    385        1.1  jdolecek     case CARD_RESET:
    386        1.1  jdolecek 	intr = ELMC_CTRL_INT;
    387        1.1  jdolecek 	break;
    388        1.1  jdolecek     }
    389        1.1  jdolecek 
    390        1.1  jdolecek     bus_space_write_1(asc->sc_regt, asc->sc_regh, ELMC_CTRL,
    391        1.1  jdolecek 		ELMC_CTRL_RST | ELMC_CTRL_BS3 | ELMC_CTRL_CHA | intr);
    392        1.6  jdolecek     delay(1);	/* should be > 500 ns */
    393        1.1  jdolecek     bus_space_write_1(asc->sc_regt, asc->sc_regh, ELMC_CTRL,
    394        1.1  jdolecek 		ELMC_CTRL_RST | ELMC_CTRL_BS3 | intr);
    395        1.1  jdolecek }
    396        1.1  jdolecek 
    397        1.1  jdolecek /*
    398       1.17     perry  * Do full card hardware reset.
    399        1.1  jdolecek  */
    400        1.1  jdolecek static void
    401        1.1  jdolecek elmc_mca_hwreset(sc, why)
    402        1.1  jdolecek 	struct ie_softc *sc;
    403        1.1  jdolecek 	int why;
    404        1.1  jdolecek {
    405        1.1  jdolecek     struct elmc_mca_softc* asc = (struct elmc_mca_softc *) sc;
    406        1.1  jdolecek 
    407        1.1  jdolecek     /* toggle the RST bit low then high */
    408        1.1  jdolecek     bus_space_write_1(asc->sc_regt, asc->sc_regh, ELMC_CTRL,
    409        1.1  jdolecek 		ELMC_CTRL_BS3 | ELMC_CTRL_LOOP);
    410        1.6  jdolecek     delay(1);	/* should be > 500 ns */
    411        1.1  jdolecek     bus_space_write_1(asc->sc_regt, asc->sc_regh, ELMC_CTRL,
    412        1.1  jdolecek 		ELMC_CTRL_BS3 | ELMC_CTRL_LOOP | ELMC_CTRL_RST);
    413        1.1  jdolecek 
    414        1.1  jdolecek     elmc_mca_attn(sc, why);
    415        1.1  jdolecek }
    416        1.1  jdolecek 
    417        1.1  jdolecek /*
    418        1.1  jdolecek  * Interrupt hook.
    419        1.1  jdolecek  */
    420        1.1  jdolecek static int
    421        1.1  jdolecek elmc_mca_intrhook(sc, why)
    422        1.1  jdolecek 	struct ie_softc *sc;
    423        1.1  jdolecek 	int why;
    424        1.1  jdolecek {
    425        1.1  jdolecek 	switch (why) {
    426        1.1  jdolecek 	case INTR_ACK:
    427        1.1  jdolecek 		elmc_mca_attn(sc, CHIP_PROBE);
    428        1.1  jdolecek 		break;
    429        1.1  jdolecek 	default:
    430        1.1  jdolecek 		/* do nothing */
    431        1.1  jdolecek 		break;
    432        1.1  jdolecek 	}
    433        1.1  jdolecek 
    434        1.1  jdolecek 	return (0);
    435        1.1  jdolecek }
    436        1.1  jdolecek 
    437       1.10   thorpej CFATTACH_DECL(elmc_mca, sizeof(struct elmc_mca_softc),
    438       1.11   thorpej     elmc_mca_match, elmc_mca_attach, NULL, NULL);
    439