Home | History | Annotate | Line # | Download | only in isa
if_le_isa.c revision 1.5
      1  1.5  christos /*	$NetBSD: if_le_isa.c,v 1.5 1996/10/13 01:37:52 christos Exp $	*/
      2  1.1   thorpej 
      3  1.1   thorpej /*-
      4  1.1   thorpej  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
      5  1.1   thorpej  * Copyright (c) 1992, 1993
      6  1.1   thorpej  *	The Regents of the University of California.  All rights reserved.
      7  1.1   thorpej  *
      8  1.1   thorpej  * This code is derived from software contributed to Berkeley by
      9  1.1   thorpej  * Ralph Campbell and Rick Macklem.
     10  1.1   thorpej  *
     11  1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.1   thorpej  * modification, are permitted provided that the following conditions
     13  1.1   thorpej  * are met:
     14  1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.1   thorpej  *    must display the following acknowledgement:
     21  1.1   thorpej  *	This product includes software developed by the University of
     22  1.1   thorpej  *	California, Berkeley and its contributors.
     23  1.1   thorpej  * 4. Neither the name of the University nor the names of its contributors
     24  1.1   thorpej  *    may be used to endorse or promote products derived from this software
     25  1.1   thorpej  *    without specific prior written permission.
     26  1.1   thorpej  *
     27  1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  1.1   thorpej  * SUCH DAMAGE.
     38  1.1   thorpej  *
     39  1.1   thorpej  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     40  1.1   thorpej  */
     41  1.1   thorpej 
     42  1.1   thorpej #include "bpfilter.h"
     43  1.1   thorpej 
     44  1.1   thorpej #include <sys/param.h>
     45  1.1   thorpej #include <sys/systm.h>
     46  1.1   thorpej #include <sys/mbuf.h>
     47  1.1   thorpej #include <sys/syslog.h>
     48  1.1   thorpej #include <sys/socket.h>
     49  1.1   thorpej #include <sys/device.h>
     50  1.1   thorpej 
     51  1.1   thorpej #include <net/if.h>
     52  1.1   thorpej 
     53  1.1   thorpej #ifdef INET
     54  1.1   thorpej #include <netinet/in.h>
     55  1.1   thorpej #include <netinet/if_ether.h>
     56  1.1   thorpej #endif
     57  1.1   thorpej 
     58  1.1   thorpej #include <vm/vm.h>
     59  1.1   thorpej 
     60  1.1   thorpej #include <machine/cpu.h>
     61  1.2   mycroft #include <machine/intr.h>
     62  1.1   thorpej #include <machine/pio.h>
     63  1.1   thorpej 
     64  1.1   thorpej #include <dev/isa/isareg.h>
     65  1.1   thorpej #include <dev/isa/isavar.h>
     66  1.1   thorpej #include <dev/isa/isadmavar.h>
     67  1.1   thorpej #include <i386/isa/isa_machdep.h>
     68  1.1   thorpej 
     69  1.1   thorpej #include <dev/ic/am7990reg.h>
     70  1.1   thorpej #include <dev/ic/am7990var.h>
     71  1.1   thorpej 
     72  1.1   thorpej #include <dev/isa/if_levar.h>
     73  1.1   thorpej 
     74  1.1   thorpej static char *card_type[] =
     75  1.1   thorpej     { "unknown", "BICC Isolan", "NE2100", "DEPCA", "PCnet-ISA" };
     76  1.1   thorpej 
     77  1.1   thorpej int le_isa_probe __P((struct device *, void *, void *));
     78  1.1   thorpej void le_isa_attach __P((struct device *, struct device *, void *));
     79  1.1   thorpej 
     80  1.1   thorpej struct cfattach le_isa_ca = {
     81  1.1   thorpej 	sizeof(struct le_softc), le_isa_probe, le_isa_attach
     82  1.1   thorpej };
     83  1.1   thorpej 
     84  1.1   thorpej int depca_isa_probe __P((struct le_softc *, struct isa_attach_args *));
     85  1.1   thorpej int ne2100_isa_probe __P((struct le_softc *, struct isa_attach_args *));
     86  1.1   thorpej int bicc_isa_probe __P((struct le_softc *, struct isa_attach_args *));
     87  1.1   thorpej int lance_isa_probe __P((struct am7990_softc *));
     88  1.1   thorpej 
     89  1.1   thorpej int le_isa_intredge __P((void *));
     90  1.1   thorpej 
     91  1.1   thorpej hide void le_isa_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
     92  1.1   thorpej hide u_int16_t le_isa_rdcsr __P((struct am7990_softc *, u_int16_t));
     93  1.1   thorpej 
     94  1.1   thorpej hide void
     95  1.1   thorpej le_isa_wrcsr(sc, port, val)
     96  1.1   thorpej 	struct am7990_softc *sc;
     97  1.1   thorpej 	u_int16_t port, val;
     98  1.1   thorpej {
     99  1.1   thorpej 
    100  1.1   thorpej 	outw(((struct le_softc *)sc)->sc_rap, port);
    101  1.1   thorpej 	outw(((struct le_softc *)sc)->sc_rdp, val);
    102  1.1   thorpej }
    103  1.1   thorpej 
    104  1.1   thorpej hide u_int16_t
    105  1.1   thorpej le_isa_rdcsr(sc, port)
    106  1.1   thorpej 	struct am7990_softc *sc;
    107  1.1   thorpej 	u_int16_t port;
    108  1.1   thorpej {
    109  1.1   thorpej 	u_int16_t val;
    110  1.1   thorpej 
    111  1.1   thorpej 	outw(((struct le_softc *)sc)->sc_rap, port);
    112  1.1   thorpej 	val = inw(((struct le_softc *)sc)->sc_rdp);
    113  1.1   thorpej 	return (val);
    114  1.1   thorpej }
    115  1.1   thorpej 
    116  1.1   thorpej int
    117  1.1   thorpej le_isa_probe(parent, match, aux)
    118  1.1   thorpej 	struct device *parent;
    119  1.1   thorpej 	void *match, *aux;
    120  1.1   thorpej {
    121  1.1   thorpej 	struct le_softc *lesc = match;
    122  1.1   thorpej 	struct isa_attach_args *ia = aux;
    123  1.1   thorpej 
    124  1.1   thorpej 	if (bicc_isa_probe(lesc, ia))
    125  1.1   thorpej 		return (1);
    126  1.1   thorpej 	if (ne2100_isa_probe(lesc, ia))
    127  1.1   thorpej 		return (1);
    128  1.1   thorpej 	if (depca_isa_probe(lesc, ia))
    129  1.1   thorpej 		return (1);
    130  1.1   thorpej 
    131  1.1   thorpej 	return (0);
    132  1.1   thorpej }
    133  1.1   thorpej 
    134  1.1   thorpej int
    135  1.1   thorpej depca_isa_probe(lesc, ia)
    136  1.1   thorpej 	struct le_softc *lesc;
    137  1.1   thorpej 	struct isa_attach_args *ia;
    138  1.1   thorpej {
    139  1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    140  1.1   thorpej 	int iobase = ia->ia_iobase, port;
    141  1.4  christos #if 0
    142  1.1   thorpej 	u_long sum, rom_sum;
    143  1.1   thorpej 	u_char x;
    144  1.4  christos #endif
    145  1.1   thorpej 	int i;
    146  1.1   thorpej 
    147  1.1   thorpej 	lesc->sc_rap = iobase + DEPCA_RAP;
    148  1.1   thorpej 	lesc->sc_rdp = iobase + DEPCA_RDP;
    149  1.1   thorpej 	lesc->sc_card = DEPCA;
    150  1.1   thorpej 
    151  1.1   thorpej 	if (lance_isa_probe(sc) == 0)
    152  1.1   thorpej 		return 0;
    153  1.1   thorpej 
    154  1.1   thorpej 	outb(iobase + DEPCA_CSR, DEPCA_CSR_DUM);
    155  1.1   thorpej 
    156  1.1   thorpej 	/*
    157  1.1   thorpej 	 * Extract the physical MAC address from the ROM.
    158  1.1   thorpej 	 *
    159  1.1   thorpej 	 * The address PROM is 32 bytes wide, and we access it through
    160  1.1   thorpej 	 * a single I/O port.  On each read, it rotates to the next
    161  1.1   thorpej 	 * position.  We find the ethernet address by looking for a
    162  1.1   thorpej 	 * particular sequence of bytes (0xff, 0x00, 0x55, 0xaa, 0xff,
    163  1.1   thorpej 	 * 0x00, 0x55, 0xaa), and then reading the next 8 bytes (the
    164  1.1   thorpej 	 * ethernet address and a checksum).
    165  1.1   thorpej 	 *
    166  1.1   thorpej 	 * It appears that the PROM can be at one of two locations, so
    167  1.1   thorpej 	 * we just try both.
    168  1.1   thorpej 	 */
    169  1.1   thorpej 	port = iobase + DEPCA_ADP;
    170  1.1   thorpej 	for (i = 0; i < 32; i++)
    171  1.1   thorpej 		if (inb(port) == 0xff && inb(port) == 0x00 &&
    172  1.1   thorpej 		    inb(port) == 0x55 && inb(port) == 0xaa &&
    173  1.1   thorpej 		    inb(port) == 0xff && inb(port) == 0x00 &&
    174  1.1   thorpej 		    inb(port) == 0x55 && inb(port) == 0xaa)
    175  1.1   thorpej 			goto found;
    176  1.1   thorpej 	port = iobase + DEPCA_ADP + 1;
    177  1.1   thorpej 	for (i = 0; i < 32; i++)
    178  1.1   thorpej 		if (inb(port) == 0xff && inb(port) == 0x00 &&
    179  1.1   thorpej 		    inb(port) == 0x55 && inb(port) == 0xaa &&
    180  1.1   thorpej 		    inb(port) == 0xff && inb(port) == 0x00 &&
    181  1.1   thorpej 		    inb(port) == 0x55 && inb(port) == 0xaa)
    182  1.1   thorpej 			goto found;
    183  1.5  christos 	printf("%s: address not found\n", sc->sc_dev.dv_xname);
    184  1.1   thorpej 	return 0;
    185  1.1   thorpej 
    186  1.1   thorpej found:
    187  1.1   thorpej 	for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++)
    188  1.1   thorpej 		sc->sc_arpcom.ac_enaddr[i] = inb(port);
    189  1.1   thorpej 
    190  1.1   thorpej #if 0
    191  1.1   thorpej 	sum =
    192  1.1   thorpej 	    (sc->sc_arpcom.ac_enaddr[0] <<  2) +
    193  1.1   thorpej 	    (sc->sc_arpcom.ac_enaddr[1] << 10) +
    194  1.1   thorpej 	    (sc->sc_arpcom.ac_enaddr[2] <<  1) +
    195  1.1   thorpej 	    (sc->sc_arpcom.ac_enaddr[3] <<  9) +
    196  1.1   thorpej 	    (sc->sc_arpcom.ac_enaddr[4] <<  0) +
    197  1.1   thorpej 	    (sc->sc_arpcom.ac_enaddr[5] <<  8);
    198  1.1   thorpej 	sum = (sum & 0xffff) + (sum >> 16);
    199  1.1   thorpej 	sum = (sum & 0xffff) + (sum >> 16);
    200  1.1   thorpej 
    201  1.1   thorpej 	rom_sum = inb(port);
    202  1.1   thorpej 	rom_sum |= inb(port) << 8;
    203  1.1   thorpej 
    204  1.1   thorpej 	if (sum != rom_sum) {
    205  1.5  christos 		printf("%s: checksum mismatch; calculated %04x != read %04x",
    206  1.1   thorpej 		    sc->sc_dev.dv_xname, sum, rom_sum);
    207  1.1   thorpej 		return 0;
    208  1.1   thorpej 	}
    209  1.1   thorpej #endif
    210  1.1   thorpej 
    211  1.1   thorpej 	outb(iobase + DEPCA_CSR, DEPCA_CSR_NORMAL);
    212  1.1   thorpej 
    213  1.1   thorpej 	ia->ia_iosize = 16;
    214  1.1   thorpej 	ia->ia_drq = DRQUNK;
    215  1.1   thorpej 	return 1;
    216  1.1   thorpej }
    217  1.1   thorpej 
    218  1.1   thorpej int
    219  1.1   thorpej ne2100_isa_probe(lesc, ia)
    220  1.1   thorpej 	struct le_softc *lesc;
    221  1.1   thorpej 	struct isa_attach_args *ia;
    222  1.1   thorpej {
    223  1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    224  1.1   thorpej 	int iobase = ia->ia_iobase;
    225  1.1   thorpej 	int i;
    226  1.1   thorpej 
    227  1.1   thorpej 	lesc->sc_rap = iobase + NE2100_RAP;
    228  1.1   thorpej 	lesc->sc_rdp = iobase + NE2100_RDP;
    229  1.1   thorpej 	lesc->sc_card = NE2100;
    230  1.1   thorpej 
    231  1.1   thorpej 	if (lance_isa_probe(sc) == 0)
    232  1.1   thorpej 		return 0;
    233  1.1   thorpej 
    234  1.1   thorpej 	/*
    235  1.1   thorpej 	 * Extract the physical MAC address from the ROM.
    236  1.1   thorpej 	 */
    237  1.1   thorpej 	for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++)
    238  1.1   thorpej 		sc->sc_arpcom.ac_enaddr[i] = inb(iobase + i);
    239  1.1   thorpej 
    240  1.1   thorpej 	ia->ia_iosize = 24;
    241  1.1   thorpej 	return 1;
    242  1.1   thorpej }
    243  1.1   thorpej 
    244  1.1   thorpej int
    245  1.1   thorpej bicc_isa_probe(lesc, ia)
    246  1.1   thorpej 	struct le_softc *lesc;
    247  1.1   thorpej 	struct isa_attach_args *ia;
    248  1.1   thorpej {
    249  1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    250  1.1   thorpej 	int iobase = ia->ia_iobase;
    251  1.1   thorpej 	int i;
    252  1.1   thorpej 
    253  1.1   thorpej 	lesc->sc_rap = iobase + BICC_RAP;
    254  1.1   thorpej 	lesc->sc_rdp = iobase + BICC_RDP;
    255  1.1   thorpej 	lesc->sc_card = BICC;
    256  1.1   thorpej 
    257  1.1   thorpej 	if (lance_isa_probe(sc) == 0)
    258  1.1   thorpej 		return 0;
    259  1.1   thorpej 
    260  1.1   thorpej 	/*
    261  1.1   thorpej 	 * Extract the physical MAC address from the ROM.
    262  1.1   thorpej 	 */
    263  1.1   thorpej 	for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++)
    264  1.1   thorpej 		sc->sc_arpcom.ac_enaddr[i] = inb(iobase + i * 2);
    265  1.1   thorpej 
    266  1.1   thorpej 	ia->ia_iosize = 16;
    267  1.1   thorpej 	return 1;
    268  1.1   thorpej }
    269  1.1   thorpej 
    270  1.1   thorpej /*
    271  1.1   thorpej  * Determine which chip is present on the card.
    272  1.1   thorpej  */
    273  1.1   thorpej int
    274  1.1   thorpej lance_isa_probe(sc)
    275  1.1   thorpej 	struct am7990_softc *sc;
    276  1.1   thorpej {
    277  1.1   thorpej 
    278  1.1   thorpej 	/* Stop the LANCE chip and put it in a known state. */
    279  1.1   thorpej 	le_isa_wrcsr(sc, LE_CSR0, LE_C0_STOP);
    280  1.1   thorpej 	delay(100);
    281  1.1   thorpej 
    282  1.1   thorpej 	if (le_isa_rdcsr(sc, LE_CSR0) != LE_C0_STOP)
    283  1.1   thorpej 		return 0;
    284  1.1   thorpej 
    285  1.1   thorpej 	le_isa_wrcsr(sc, LE_CSR3, sc->sc_conf3);
    286  1.1   thorpej 	return 1;
    287  1.1   thorpej }
    288  1.1   thorpej 
    289  1.1   thorpej void
    290  1.1   thorpej le_isa_attach(parent, self, aux)
    291  1.1   thorpej 	struct device *parent, *self;
    292  1.1   thorpej 	void *aux;
    293  1.1   thorpej {
    294  1.1   thorpej 	struct le_softc *lesc = (void *)self;
    295  1.1   thorpej 	struct am7990_softc *sc = &lesc->sc_am7990;
    296  1.1   thorpej 	struct isa_attach_args *ia = aux;
    297  1.1   thorpej 
    298  1.5  christos 	printf(": %s Ethernet\n", card_type[lesc->sc_card]);
    299  1.1   thorpej 
    300  1.1   thorpej 	if (lesc->sc_card == DEPCA) {
    301  1.1   thorpej 		u_char *mem, val;
    302  1.1   thorpej 		int i;
    303  1.1   thorpej 
    304  1.1   thorpej 		mem = sc->sc_mem = ISA_HOLE_VADDR(ia->ia_maddr);
    305  1.1   thorpej 
    306  1.1   thorpej 		val = 0xff;
    307  1.1   thorpej 		for (;;) {
    308  1.1   thorpej 			for (i = 0; i < ia->ia_msize; i++)
    309  1.1   thorpej 				mem[i] = val;
    310  1.1   thorpej 			for (i = 0; i < ia->ia_msize; i++)
    311  1.1   thorpej 				if (mem[i] != val) {
    312  1.5  christos 					printf("%s: failed to clear memory\n",
    313  1.1   thorpej 					    sc->sc_dev.dv_xname);
    314  1.1   thorpej 					return;
    315  1.1   thorpej 				}
    316  1.1   thorpej 			if (val == 0x00)
    317  1.1   thorpej 				break;
    318  1.1   thorpej 			val -= 0x55;
    319  1.1   thorpej 		}
    320  1.1   thorpej 
    321  1.1   thorpej 		sc->sc_conf3 = LE_C3_ACON;
    322  1.1   thorpej 		sc->sc_addr = 0;
    323  1.1   thorpej 		sc->sc_memsize = ia->ia_msize;
    324  1.1   thorpej 	} else {
    325  1.1   thorpej 		sc->sc_mem = malloc(16384, M_DEVBUF, M_NOWAIT);
    326  1.1   thorpej 		if (sc->sc_mem == 0) {
    327  1.5  christos 			printf("%s: couldn't allocate memory for card\n",
    328  1.1   thorpej 			    sc->sc_dev.dv_xname);
    329  1.1   thorpej 			return;
    330  1.1   thorpej 		}
    331  1.1   thorpej 
    332  1.1   thorpej 		sc->sc_conf3 = 0;
    333  1.1   thorpej 		sc->sc_addr = kvtop(sc->sc_mem);
    334  1.1   thorpej 		sc->sc_memsize = 16384;
    335  1.1   thorpej 	}
    336  1.1   thorpej 
    337  1.1   thorpej 	sc->sc_copytodesc = am7990_copytobuf_contig;
    338  1.1   thorpej 	sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    339  1.1   thorpej 	sc->sc_copytobuf = am7990_copytobuf_contig;
    340  1.1   thorpej 	sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    341  1.1   thorpej 	sc->sc_zerobuf = am7990_zerobuf_contig;
    342  1.1   thorpej 
    343  1.1   thorpej 	sc->sc_rdcsr = le_isa_rdcsr;
    344  1.1   thorpej 	sc->sc_wrcsr = le_isa_wrcsr;
    345  1.1   thorpej 	sc->sc_hwinit = NULL;
    346  1.1   thorpej 
    347  1.5  christos 	printf("%s", sc->sc_dev.dv_xname);
    348  1.1   thorpej 	am7990_config(sc);
    349  1.1   thorpej 
    350  1.1   thorpej 	if (ia->ia_drq != DRQUNK)
    351  1.1   thorpej 		isa_dmacascade(ia->ia_drq);
    352  1.1   thorpej 
    353  1.1   thorpej 	lesc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    354  1.1   thorpej 	    IPL_NET, le_isa_intredge, sc);
    355  1.1   thorpej }
    356  1.1   thorpej 
    357  1.1   thorpej /*
    358  1.1   thorpej  * Controller interrupt.
    359  1.1   thorpej  */
    360  1.3   thorpej int
    361  1.1   thorpej le_isa_intredge(arg)
    362  1.1   thorpej 	void *arg;
    363  1.1   thorpej {
    364  1.1   thorpej 
    365  1.1   thorpej 	if (am7990_intr(arg) == 0)
    366  1.1   thorpej 		return (0);
    367  1.1   thorpej 	for (;;)
    368  1.1   thorpej 		if (am7990_intr(arg) == 0)
    369  1.1   thorpej 			return (1);
    370  1.1   thorpej }
    371