Home | History | Annotate | Line # | Download | only in isa
if_le_isa.c revision 1.13
      1  1.13   mycroft /*	$NetBSD: if_le_isa.c,v 1.13 1997/09/10 03:31:31 mycroft Exp $	*/
      2  1.11   thorpej 
      3  1.11   thorpej /*-
      4  1.11   thorpej  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  1.11   thorpej  * All rights reserved.
      6  1.11   thorpej  *
      7  1.11   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.11   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.11   thorpej  * NASA Ames Research Center.
     10  1.11   thorpej  *
     11  1.11   thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.11   thorpej  * modification, are permitted provided that the following conditions
     13  1.11   thorpej  * are met:
     14  1.11   thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.11   thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.11   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.11   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.11   thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.11   thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.11   thorpej  *    must display the following acknowledgement:
     21  1.11   thorpej  *	This product includes software developed by the NetBSD
     22  1.11   thorpej  *	Foundation, Inc. and its contributors.
     23  1.11   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.11   thorpej  *    contributors may be used to endorse or promote products derived
     25  1.11   thorpej  *    from this software without specific prior written permission.
     26  1.11   thorpej  *
     27  1.11   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.11   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.11   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.11   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.11   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.11   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.11   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.11   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.11   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.11   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.11   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38  1.11   thorpej  */
     39   1.1   thorpej 
     40   1.1   thorpej /*-
     41   1.1   thorpej  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
     42   1.1   thorpej  * Copyright (c) 1992, 1993
     43   1.1   thorpej  *	The Regents of the University of California.  All rights reserved.
     44   1.1   thorpej  *
     45   1.1   thorpej  * This code is derived from software contributed to Berkeley by
     46   1.1   thorpej  * Ralph Campbell and Rick Macklem.
     47   1.1   thorpej  *
     48   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     49   1.1   thorpej  * modification, are permitted provided that the following conditions
     50   1.1   thorpej  * are met:
     51   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     52   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     53   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     54   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     55   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     56   1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     57   1.1   thorpej  *    must display the following acknowledgement:
     58   1.1   thorpej  *	This product includes software developed by the University of
     59   1.1   thorpej  *	California, Berkeley and its contributors.
     60   1.1   thorpej  * 4. Neither the name of the University nor the names of its contributors
     61   1.1   thorpej  *    may be used to endorse or promote products derived from this software
     62   1.1   thorpej  *    without specific prior written permission.
     63   1.1   thorpej  *
     64   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     65   1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     66   1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     67   1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     68   1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     69   1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     70   1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     71   1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     72   1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     73   1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     74   1.1   thorpej  * SUCH DAMAGE.
     75   1.1   thorpej  *
     76   1.1   thorpej  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     77   1.1   thorpej  */
     78   1.1   thorpej 
     79   1.1   thorpej #include "bpfilter.h"
     80   1.1   thorpej 
     81   1.1   thorpej #include <sys/param.h>
     82   1.1   thorpej #include <sys/systm.h>
     83   1.1   thorpej #include <sys/mbuf.h>
     84   1.1   thorpej #include <sys/syslog.h>
     85   1.1   thorpej #include <sys/socket.h>
     86   1.1   thorpej #include <sys/device.h>
     87   1.1   thorpej 
     88   1.1   thorpej #include <net/if.h>
     89   1.9        is #include <net/if_ether.h>
     90  1.10   thorpej #include <net/if_media.h>
     91   1.1   thorpej 
     92   1.1   thorpej #ifdef INET
     93   1.1   thorpej #include <netinet/in.h>
     94   1.9        is #include <netinet/if_inarp.h>
     95   1.1   thorpej #endif
     96   1.1   thorpej 
     97   1.1   thorpej #include <vm/vm.h>
     98   1.1   thorpej 
     99   1.1   thorpej #include <machine/cpu.h>
    100   1.2   mycroft #include <machine/intr.h>
    101   1.6   thorpej #include <machine/bus.h>
    102   1.1   thorpej 
    103   1.1   thorpej #include <dev/isa/isareg.h>
    104   1.1   thorpej #include <dev/isa/isavar.h>
    105   1.1   thorpej #include <dev/isa/isadmavar.h>
    106   1.1   thorpej 
    107   1.1   thorpej #include <dev/ic/am7990reg.h>
    108   1.1   thorpej #include <dev/ic/am7990var.h>
    109   1.1   thorpej 
    110   1.1   thorpej #include <dev/isa/if_levar.h>
    111   1.1   thorpej 
    112   1.1   thorpej static char *card_type[] =
    113   1.1   thorpej     { "unknown", "BICC Isolan", "NE2100", "DEPCA", "PCnet-ISA" };
    114   1.1   thorpej 
    115   1.1   thorpej int le_isa_probe __P((struct device *, void *, void *));
    116   1.1   thorpej void le_isa_attach __P((struct device *, struct device *, void *));
    117   1.1   thorpej 
    118   1.1   thorpej struct cfattach le_isa_ca = {
    119   1.1   thorpej 	sizeof(struct le_softc), le_isa_probe, le_isa_attach
    120   1.1   thorpej };
    121   1.1   thorpej 
    122   1.1   thorpej int depca_isa_probe __P((struct le_softc *, struct isa_attach_args *));
    123   1.1   thorpej int ne2100_isa_probe __P((struct le_softc *, struct isa_attach_args *));
    124   1.1   thorpej int bicc_isa_probe __P((struct le_softc *, struct isa_attach_args *));
    125   1.1   thorpej int lance_isa_probe __P((struct am7990_softc *));
    126   1.1   thorpej 
    127   1.1   thorpej int le_isa_intredge __P((void *));
    128   1.1   thorpej 
    129   1.1   thorpej hide void le_isa_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
    130   1.1   thorpej hide u_int16_t le_isa_rdcsr __P((struct am7990_softc *, u_int16_t));
    131   1.1   thorpej 
    132   1.6   thorpej void	depca_copytobuf __P((struct am7990_softc *, void *, int, int));
    133   1.6   thorpej void	depca_copyfrombuf __P((struct am7990_softc *, void *, int, int));
    134   1.6   thorpej void	depca_zerobuf __P((struct am7990_softc *, int, int));
    135   1.6   thorpej 
    136  1.11   thorpej #define	LE_ISA_MEMSIZE	16384
    137  1.11   thorpej 
    138   1.1   thorpej hide void
    139   1.1   thorpej le_isa_wrcsr(sc, port, val)
    140   1.1   thorpej 	struct am7990_softc *sc;
    141   1.1   thorpej 	u_int16_t port, val;
    142   1.1   thorpej {
    143   1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    144   1.6   thorpej 	bus_space_tag_t iot = lesc->sc_iot;
    145   1.6   thorpej 	bus_space_handle_t ioh = lesc->sc_ioh;
    146   1.1   thorpej 
    147   1.6   thorpej 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    148   1.6   thorpej 	bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
    149   1.1   thorpej }
    150   1.1   thorpej 
    151   1.1   thorpej hide u_int16_t
    152   1.1   thorpej le_isa_rdcsr(sc, port)
    153   1.1   thorpej 	struct am7990_softc *sc;
    154   1.1   thorpej 	u_int16_t port;
    155   1.1   thorpej {
    156   1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    157   1.6   thorpej 	bus_space_tag_t iot = lesc->sc_iot;
    158   1.6   thorpej 	bus_space_handle_t ioh = lesc->sc_ioh;
    159   1.1   thorpej 	u_int16_t val;
    160   1.1   thorpej 
    161   1.6   thorpej 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    162   1.6   thorpej 	val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
    163   1.1   thorpej 	return (val);
    164   1.1   thorpej }
    165   1.1   thorpej 
    166   1.1   thorpej int
    167   1.1   thorpej le_isa_probe(parent, match, aux)
    168   1.1   thorpej 	struct device *parent;
    169   1.1   thorpej 	void *match, *aux;
    170   1.1   thorpej {
    171   1.1   thorpej 	struct le_softc *lesc = match;
    172   1.1   thorpej 	struct isa_attach_args *ia = aux;
    173   1.1   thorpej 
    174   1.1   thorpej 	if (bicc_isa_probe(lesc, ia))
    175   1.1   thorpej 		return (1);
    176   1.1   thorpej 	if (ne2100_isa_probe(lesc, ia))
    177   1.1   thorpej 		return (1);
    178   1.1   thorpej 	if (depca_isa_probe(lesc, ia))
    179   1.1   thorpej 		return (1);
    180   1.1   thorpej 
    181   1.1   thorpej 	return (0);
    182   1.1   thorpej }
    183   1.1   thorpej 
    184   1.1   thorpej int
    185   1.1   thorpej depca_isa_probe(lesc, ia)
    186   1.1   thorpej 	struct le_softc *lesc;
    187   1.1   thorpej 	struct isa_attach_args *ia;
    188   1.1   thorpej {
    189   1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    190   1.1   thorpej 	int iobase = ia->ia_iobase, port;
    191   1.6   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    192   1.6   thorpej 	bus_space_handle_t ioh;
    193   1.6   thorpej 	bus_space_handle_t memh;
    194  1.12   mycroft 	u_int8_t csr;
    195   1.4  christos #if 0
    196   1.6   thorpej 	u_int32_t sum, rom_sum;
    197   1.6   thorpej 	u_int8_t x;
    198   1.4  christos #endif
    199   1.1   thorpej 	int i;
    200   1.1   thorpej 
    201   1.6   thorpej 	/* Map i/o space. */
    202   1.6   thorpej 	if (bus_space_map(iot, iobase, 16, 0, &ioh))
    203   1.6   thorpej 		return 0;
    204   1.6   thorpej 
    205   1.6   thorpej 	if (ia->ia_maddr == MADDRUNK || ia->ia_msize == -1)
    206   1.6   thorpej 		goto bad;
    207   1.6   thorpej 
    208  1.12   mycroft 	switch (ia->ia_msize) {
    209  1.12   mycroft 	case 65536:
    210  1.12   mycroft 		csr = DEPCA_CSR_SHE;
    211  1.12   mycroft 		break;
    212  1.12   mycroft 	case 32768:
    213  1.12   mycroft 		csr = DEPCA_CSR_SHE | DEPCA_CSR_LOW32K;
    214  1.12   mycroft 		break;
    215  1.12   mycroft 	default:
    216  1.12   mycroft 		goto bad;
    217  1.12   mycroft 	}
    218  1.12   mycroft 
    219   1.6   thorpej 	/* Map card RAM. */
    220  1.12   mycroft 	if (bus_space_map(ia->ia_memt, ia->ia_maddr, ia->ia_msize, 0, &memh))
    221   1.6   thorpej 		goto bad;
    222   1.6   thorpej 
    223   1.6   thorpej 	/* Just needed to check mapability; don't need it anymore. */
    224   1.8   thorpej 	bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
    225   1.6   thorpej 
    226   1.7   thorpej 	lesc->sc_iot = iot;
    227   1.7   thorpej 	lesc->sc_ioh = ioh;
    228   1.6   thorpej 	lesc->sc_rap = DEPCA_RAP;
    229   1.6   thorpej 	lesc->sc_rdp = DEPCA_RDP;
    230   1.1   thorpej 	lesc->sc_card = DEPCA;
    231   1.1   thorpej 
    232   1.1   thorpej 	if (lance_isa_probe(sc) == 0)
    233   1.6   thorpej 		goto bad;
    234   1.1   thorpej 
    235   1.6   thorpej 	bus_space_write_1(iot, ioh, DEPCA_CSR, DEPCA_CSR_DUM);
    236   1.1   thorpej 
    237   1.1   thorpej 	/*
    238   1.1   thorpej 	 * Extract the physical MAC address from the ROM.
    239   1.1   thorpej 	 *
    240   1.1   thorpej 	 * The address PROM is 32 bytes wide, and we access it through
    241   1.1   thorpej 	 * a single I/O port.  On each read, it rotates to the next
    242   1.1   thorpej 	 * position.  We find the ethernet address by looking for a
    243   1.1   thorpej 	 * particular sequence of bytes (0xff, 0x00, 0x55, 0xaa, 0xff,
    244   1.1   thorpej 	 * 0x00, 0x55, 0xaa), and then reading the next 8 bytes (the
    245   1.1   thorpej 	 * ethernet address and a checksum).
    246   1.1   thorpej 	 *
    247   1.1   thorpej 	 * It appears that the PROM can be at one of two locations, so
    248   1.1   thorpej 	 * we just try both.
    249   1.1   thorpej 	 */
    250   1.6   thorpej 	port = DEPCA_ADP;
    251   1.1   thorpej 	for (i = 0; i < 32; i++)
    252   1.6   thorpej 		if (bus_space_read_1(iot, ioh, port) == 0xff &&
    253   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    254   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    255   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa &&
    256   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xff &&
    257   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    258   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    259   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa)
    260   1.1   thorpej 			goto found;
    261   1.6   thorpej 	port = DEPCA_ADP + 1;
    262   1.1   thorpej 	for (i = 0; i < 32; i++)
    263   1.6   thorpej 		if (bus_space_read_1(iot, ioh, port) == 0xff &&
    264   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    265   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    266   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa &&
    267   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xff &&
    268   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    269   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    270   1.6   thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa)
    271   1.1   thorpej 			goto found;
    272   1.5  christos 	printf("%s: address not found\n", sc->sc_dev.dv_xname);
    273   1.6   thorpej 	goto bad;
    274   1.1   thorpej 
    275   1.1   thorpej found:
    276   1.9        is 	for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    277   1.9        is 		sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, port);
    278   1.1   thorpej 
    279   1.1   thorpej #if 0
    280   1.1   thorpej 	sum =
    281   1.9        is 	    (sc->sc_enaddr[0] <<  2) +
    282   1.9        is 	    (sc->sc_enaddr[1] << 10) +
    283   1.9        is 	    (sc->sc_enaddr[2] <<  1) +
    284   1.9        is 	    (sc->sc_enaddr[3] <<  9) +
    285   1.9        is 	    (sc->sc_enaddr[4] <<  0) +
    286   1.9        is 	    (sc->sc_enaddr[5] <<  8);
    287   1.1   thorpej 	sum = (sum & 0xffff) + (sum >> 16);
    288   1.1   thorpej 	sum = (sum & 0xffff) + (sum >> 16);
    289   1.1   thorpej 
    290   1.6   thorpej 	rom_sum = bus_space_read_1(iot, ioh, port);
    291   1.6   thorpej 	rom_sum |= bus_space_read_1(iot, ioh, port) << 8;
    292   1.1   thorpej 
    293   1.1   thorpej 	if (sum != rom_sum) {
    294   1.5  christos 		printf("%s: checksum mismatch; calculated %04x != read %04x",
    295   1.1   thorpej 		    sc->sc_dev.dv_xname, sum, rom_sum);
    296   1.6   thorpej 		goto bad;
    297   1.1   thorpej 	}
    298   1.1   thorpej #endif
    299   1.1   thorpej 
    300   1.6   thorpej 	/*
    301   1.6   thorpej 	 * XXX INDIRECT BROKENNESS!
    302   1.6   thorpej 	 * XXX Should always unmap, and re-map in if_le_isa_attach().
    303   1.6   thorpej 	 */
    304  1.12   mycroft 
    305  1.13   mycroft 	bus_space_write_1(iot, ioh, DEPCA_CSR, DEPCA_CSR_DUM | DEPCA_CSR_IEN |
    306  1.13   mycroft 	    csr);
    307   1.1   thorpej 
    308   1.1   thorpej 	ia->ia_iosize = 16;
    309   1.1   thorpej 	ia->ia_drq = DRQUNK;
    310   1.1   thorpej 	return 1;
    311   1.6   thorpej 
    312   1.6   thorpej  bad:
    313   1.6   thorpej 	bus_space_unmap(iot, ioh, 16);
    314   1.6   thorpej 	return 0;
    315   1.1   thorpej }
    316   1.1   thorpej 
    317   1.1   thorpej int
    318   1.1   thorpej ne2100_isa_probe(lesc, ia)
    319   1.1   thorpej 	struct le_softc *lesc;
    320   1.1   thorpej 	struct isa_attach_args *ia;
    321   1.1   thorpej {
    322   1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    323   1.1   thorpej 	int iobase = ia->ia_iobase;
    324   1.6   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    325   1.6   thorpej 	bus_space_handle_t ioh;
    326   1.1   thorpej 	int i;
    327   1.1   thorpej 
    328   1.6   thorpej 	/* Map i/o space. */
    329   1.6   thorpej 	if (bus_space_map(iot, iobase, 24, 0, &ioh))
    330   1.6   thorpej 		return 0;
    331   1.6   thorpej 
    332   1.7   thorpej 	lesc->sc_iot = iot;
    333   1.7   thorpej 	lesc->sc_ioh = ioh;
    334   1.6   thorpej 	lesc->sc_rap = NE2100_RAP;
    335   1.6   thorpej 	lesc->sc_rdp = NE2100_RDP;
    336   1.1   thorpej 	lesc->sc_card = NE2100;
    337   1.1   thorpej 
    338   1.6   thorpej 	if (lance_isa_probe(sc) == 0) {
    339   1.6   thorpej 		bus_space_unmap(iot, ioh, 24);
    340   1.1   thorpej 		return 0;
    341   1.6   thorpej 	}
    342   1.1   thorpej 
    343   1.1   thorpej 	/*
    344   1.1   thorpej 	 * Extract the physical MAC address from the ROM.
    345   1.1   thorpej 	 */
    346   1.9        is 	for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    347   1.9        is 		sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, i);
    348   1.6   thorpej 
    349   1.6   thorpej 	/*
    350   1.6   thorpej 	 * XXX INDIRECT BROKENNESS!
    351   1.6   thorpej 	 * XXX Should always unmap, and re-map in if_le_isa_attach().
    352   1.6   thorpej 	 */
    353   1.1   thorpej 
    354   1.1   thorpej 	ia->ia_iosize = 24;
    355   1.1   thorpej 	return 1;
    356   1.1   thorpej }
    357   1.1   thorpej 
    358   1.1   thorpej int
    359   1.1   thorpej bicc_isa_probe(lesc, ia)
    360   1.1   thorpej 	struct le_softc *lesc;
    361   1.1   thorpej 	struct isa_attach_args *ia;
    362   1.1   thorpej {
    363   1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    364   1.1   thorpej 	int iobase = ia->ia_iobase;
    365   1.6   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    366   1.6   thorpej 	bus_space_handle_t ioh;
    367   1.1   thorpej 	int i;
    368   1.1   thorpej 
    369   1.6   thorpej 	/* Map i/o space. */
    370   1.6   thorpej 	if (bus_space_map(iot, iobase, 16, 0, &ioh))
    371   1.6   thorpej 		return 0;
    372   1.6   thorpej 
    373   1.7   thorpej 	lesc->sc_iot = iot;
    374   1.7   thorpej 	lesc->sc_ioh = ioh;
    375   1.6   thorpej 	lesc->sc_rap = BICC_RAP;
    376   1.6   thorpej 	lesc->sc_rdp = BICC_RDP;
    377   1.1   thorpej 	lesc->sc_card = BICC;
    378   1.1   thorpej 
    379   1.6   thorpej 	if (lance_isa_probe(sc) == 0) {
    380   1.6   thorpej 		bus_space_unmap(iot, ioh, 16);
    381   1.1   thorpej 		return 0;
    382   1.6   thorpej 	}
    383   1.1   thorpej 
    384   1.1   thorpej 	/*
    385   1.1   thorpej 	 * Extract the physical MAC address from the ROM.
    386   1.1   thorpej 	 */
    387   1.9        is 	for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    388   1.9        is 		sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, i * 2);
    389   1.6   thorpej 
    390   1.6   thorpej 	/*
    391   1.6   thorpej 	 * XXX INDIRECT BROKENNESS!
    392   1.6   thorpej 	 * XXX Should always unmap, and re-map in if_le_isa_attach().
    393   1.6   thorpej 	 */
    394   1.1   thorpej 
    395   1.1   thorpej 	ia->ia_iosize = 16;
    396   1.1   thorpej 	return 1;
    397   1.1   thorpej }
    398   1.1   thorpej 
    399   1.1   thorpej /*
    400   1.1   thorpej  * Determine which chip is present on the card.
    401   1.1   thorpej  */
    402   1.1   thorpej int
    403   1.1   thorpej lance_isa_probe(sc)
    404   1.1   thorpej 	struct am7990_softc *sc;
    405   1.1   thorpej {
    406   1.1   thorpej 
    407   1.1   thorpej 	/* Stop the LANCE chip and put it in a known state. */
    408   1.1   thorpej 	le_isa_wrcsr(sc, LE_CSR0, LE_C0_STOP);
    409   1.1   thorpej 	delay(100);
    410   1.1   thorpej 
    411   1.1   thorpej 	if (le_isa_rdcsr(sc, LE_CSR0) != LE_C0_STOP)
    412   1.1   thorpej 		return 0;
    413   1.1   thorpej 
    414   1.1   thorpej 	le_isa_wrcsr(sc, LE_CSR3, sc->sc_conf3);
    415   1.1   thorpej 	return 1;
    416   1.1   thorpej }
    417   1.1   thorpej 
    418   1.1   thorpej void
    419   1.1   thorpej le_isa_attach(parent, self, aux)
    420   1.1   thorpej 	struct device *parent, *self;
    421   1.1   thorpej 	void *aux;
    422   1.1   thorpej {
    423   1.1   thorpej 	struct le_softc *lesc = (void *)self;
    424   1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    425   1.1   thorpej 	struct isa_attach_args *ia = aux;
    426   1.6   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    427   1.6   thorpej 	bus_space_tag_t memt = ia->ia_memt;
    428  1.11   thorpej 	bus_dma_tag_t dmat = ia->ia_dmat;
    429   1.6   thorpej 	bus_space_handle_t memh;
    430  1.11   thorpej 	bus_dma_segment_t seg;
    431  1.11   thorpej 	int rseg;
    432   1.1   thorpej 
    433   1.5  christos 	printf(": %s Ethernet\n", card_type[lesc->sc_card]);
    434   1.1   thorpej 
    435   1.6   thorpej 	lesc->sc_iot = iot;
    436   1.6   thorpej 	lesc->sc_memt = memt;
    437  1.11   thorpej 	lesc->sc_dmat = dmat;
    438   1.6   thorpej 
    439   1.6   thorpej 	/* XXX SHOULD RE-MAP I/O SPACE HERE. */
    440   1.6   thorpej 
    441   1.1   thorpej 	if (lesc->sc_card == DEPCA) {
    442   1.6   thorpej 		u_char val;
    443   1.1   thorpej 		int i;
    444   1.1   thorpej 
    445   1.6   thorpej 		/* Map shared memory. */
    446   1.6   thorpej 		if (bus_space_map(memt, ia->ia_maddr, ia->ia_msize,
    447   1.6   thorpej 		    0, &memh))
    448   1.6   thorpej 			panic("le_isa_attach: can't map shared memory");
    449   1.6   thorpej 
    450   1.6   thorpej 		lesc->sc_memh = memh;
    451   1.1   thorpej 
    452   1.1   thorpej 		val = 0xff;
    453   1.1   thorpej 		for (;;) {
    454  1.11   thorpej 			bus_space_set_region_1(memt, memh, 0, val,
    455  1.11   thorpej 			    ia->ia_msize);
    456   1.1   thorpej 			for (i = 0; i < ia->ia_msize; i++)
    457   1.6   thorpej 				if (bus_space_read_1(memt, memh, 1) != val) {
    458   1.5  christos 					printf("%s: failed to clear memory\n",
    459   1.1   thorpej 					    sc->sc_dev.dv_xname);
    460   1.1   thorpej 					return;
    461   1.1   thorpej 				}
    462   1.1   thorpej 			if (val == 0x00)
    463   1.1   thorpej 				break;
    464   1.1   thorpej 			val -= 0x55;
    465   1.1   thorpej 		}
    466   1.1   thorpej 
    467   1.1   thorpej 		sc->sc_conf3 = LE_C3_ACON;
    468   1.6   thorpej 		sc->sc_mem = 0;			/* Not used. */
    469   1.1   thorpej 		sc->sc_addr = 0;
    470   1.1   thorpej 		sc->sc_memsize = ia->ia_msize;
    471   1.1   thorpej 	} else {
    472  1.11   thorpej 		/*
    473  1.11   thorpej 		 * Allocate a DMA area for the card.
    474  1.11   thorpej 		 */
    475  1.11   thorpej 		if (bus_dmamem_alloc(dmat, LE_ISA_MEMSIZE, NBPG, 0, &seg, 1,
    476  1.11   thorpej 		    &rseg, BUS_DMA_NOWAIT)) {
    477   1.5  christos 			printf("%s: couldn't allocate memory for card\n",
    478   1.1   thorpej 			    sc->sc_dev.dv_xname);
    479   1.1   thorpej 			return;
    480   1.1   thorpej 		}
    481  1.11   thorpej 		if (bus_dmamem_map(dmat, &seg, rseg, LE_ISA_MEMSIZE,
    482  1.11   thorpej 		    (caddr_t *)&sc->sc_mem,
    483  1.11   thorpej 		    BUS_DMA_NOWAIT|BUS_DMAMEM_NOSYNC)) {
    484  1.11   thorpej 			printf("%s: couldn't map memory for card\n",
    485  1.11   thorpej 			    sc->sc_dev.dv_xname);
    486  1.11   thorpej 			return;
    487  1.11   thorpej 		}
    488  1.11   thorpej 
    489  1.11   thorpej 		/*
    490  1.11   thorpej 		 * Create and load the DMA map for the DMA area.
    491  1.11   thorpej 		 */
    492  1.11   thorpej 		if (bus_dmamap_create(dmat, LE_ISA_MEMSIZE, 1,
    493  1.11   thorpej 		    LE_ISA_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) {
    494  1.11   thorpej 			printf("%s: couldn't create DMA map\n",
    495  1.11   thorpej 			    sc->sc_dev.dv_xname);
    496  1.11   thorpej 			bus_dmamem_free(dmat, &seg, rseg);
    497  1.11   thorpej 			return;
    498  1.11   thorpej 		}
    499  1.11   thorpej 		if (bus_dmamap_load(dmat, lesc->sc_dmam,
    500  1.11   thorpej 		    sc->sc_mem, LE_ISA_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
    501  1.11   thorpej 			printf("%s: coundn't load DMA map\n",
    502  1.11   thorpej 			    sc->sc_dev.dv_xname);
    503  1.11   thorpej 			bus_dmamem_free(dmat, &seg, rseg);
    504  1.11   thorpej 			return;
    505  1.11   thorpej 		}
    506   1.1   thorpej 
    507   1.1   thorpej 		sc->sc_conf3 = 0;
    508  1.11   thorpej 		sc->sc_addr = lesc->sc_dmam->dm_segs[0].ds_addr;
    509  1.11   thorpej 		sc->sc_memsize = LE_ISA_MEMSIZE;
    510   1.1   thorpej 	}
    511   1.1   thorpej 
    512   1.6   thorpej 	if (lesc->sc_card == DEPCA) {
    513   1.6   thorpej 		sc->sc_copytodesc = depca_copytobuf;
    514   1.6   thorpej 		sc->sc_copyfromdesc = depca_copyfrombuf;
    515   1.6   thorpej 		sc->sc_copytobuf = depca_copytobuf;
    516   1.6   thorpej 		sc->sc_copyfrombuf = depca_copyfrombuf;
    517   1.6   thorpej 		sc->sc_zerobuf = depca_zerobuf;
    518   1.6   thorpej 	} else {
    519   1.6   thorpej 		sc->sc_copytodesc = am7990_copytobuf_contig;
    520   1.6   thorpej 		sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    521   1.6   thorpej 		sc->sc_copytobuf = am7990_copytobuf_contig;
    522   1.6   thorpej 		sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    523   1.6   thorpej 		sc->sc_zerobuf = am7990_zerobuf_contig;
    524   1.6   thorpej 	}
    525   1.1   thorpej 
    526   1.1   thorpej 	sc->sc_rdcsr = le_isa_rdcsr;
    527   1.1   thorpej 	sc->sc_wrcsr = le_isa_wrcsr;
    528   1.1   thorpej 	sc->sc_hwinit = NULL;
    529   1.1   thorpej 
    530   1.5  christos 	printf("%s", sc->sc_dev.dv_xname);
    531   1.1   thorpej 	am7990_config(sc);
    532   1.1   thorpej 
    533   1.1   thorpej 	if (ia->ia_drq != DRQUNK)
    534  1.11   thorpej 		isa_dmacascade(parent, ia->ia_drq);
    535   1.1   thorpej 
    536   1.1   thorpej 	lesc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    537   1.1   thorpej 	    IPL_NET, le_isa_intredge, sc);
    538   1.1   thorpej }
    539   1.1   thorpej 
    540   1.1   thorpej /*
    541   1.1   thorpej  * Controller interrupt.
    542   1.1   thorpej  */
    543   1.3   thorpej int
    544   1.1   thorpej le_isa_intredge(arg)
    545   1.1   thorpej 	void *arg;
    546   1.1   thorpej {
    547   1.1   thorpej 
    548   1.1   thorpej 	if (am7990_intr(arg) == 0)
    549   1.1   thorpej 		return (0);
    550   1.1   thorpej 	for (;;)
    551   1.1   thorpej 		if (am7990_intr(arg) == 0)
    552   1.1   thorpej 			return (1);
    553   1.6   thorpej }
    554   1.6   thorpej 
    555   1.6   thorpej /*
    556   1.6   thorpej  * DEPCA shared memory access functions.
    557   1.6   thorpej  */
    558   1.6   thorpej 
    559   1.6   thorpej void
    560   1.6   thorpej depca_copytobuf(sc, from, boff, len)
    561   1.6   thorpej 	struct am7990_softc *sc;
    562   1.6   thorpej 	void *from;
    563   1.6   thorpej 	int boff, len;
    564   1.6   thorpej {
    565   1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    566   1.6   thorpej 
    567   1.6   thorpej 	bus_space_write_region_1(lesc->sc_memt, lesc->sc_memh, boff,
    568   1.6   thorpej 	    from, len);
    569   1.6   thorpej }
    570   1.6   thorpej 
    571   1.6   thorpej void
    572   1.6   thorpej depca_copyfrombuf(sc, to, boff, len)
    573   1.6   thorpej 	struct am7990_softc *sc;
    574   1.6   thorpej 	void *to;
    575   1.6   thorpej 	int boff, len;
    576   1.6   thorpej {
    577   1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    578   1.6   thorpej 
    579   1.6   thorpej 	bus_space_read_region_1(lesc->sc_memt, lesc->sc_memh, boff,
    580   1.6   thorpej 	    to, len);
    581   1.6   thorpej }
    582   1.6   thorpej 
    583   1.6   thorpej void
    584   1.6   thorpej depca_zerobuf(sc, boff, len)
    585   1.6   thorpej 	struct am7990_softc *sc;
    586   1.6   thorpej 	int boff, len;
    587   1.6   thorpej {
    588   1.6   thorpej 	struct le_softc *lesc = (struct le_softc *)sc;
    589   1.6   thorpej 
    590   1.6   thorpej #if 0	/* XXX !! */
    591   1.6   thorpej 	bus_space_set_region_1(lesc->sc_memt, lesc->sc_memh, boff,
    592   1.6   thorpej 	    0x00, len);
    593   1.6   thorpej #else
    594   1.6   thorpej 	for (; len != 0; boff++, len--)
    595   1.6   thorpej 		bus_space_write_1(lesc->sc_memt, lesc->sc_memh, boff, 0x00);
    596   1.6   thorpej #endif
    597   1.1   thorpej }
    598