Home | History | Annotate | Line # | Download | only in ic
depca.c revision 1.9
      1  1.9  thorpej /*	$NetBSD: depca.c,v 1.9 2003/01/01 00:10:18 thorpej Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.1  thorpej  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  thorpej  * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
      9  1.1  thorpej  * Simulation Facility, NASA Ames Research Center.
     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 NetBSD
     22  1.1  thorpej  *	Foundation, Inc. and its contributors.
     23  1.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1  thorpej  *    contributors may be used to endorse or promote products derived
     25  1.1  thorpej  *    from this software without specific prior written permission.
     26  1.1  thorpej  *
     27  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1  thorpej  */
     39  1.1  thorpej 
     40  1.1  thorpej /*-
     41  1.1  thorpej  * Copyright (c) 1992, 1993
     42  1.1  thorpej  *	The Regents of the University of California.  All rights reserved.
     43  1.1  thorpej  *
     44  1.1  thorpej  * This code is derived from software contributed to Berkeley by
     45  1.1  thorpej  * Ralph Campbell and Rick Macklem.
     46  1.1  thorpej  *
     47  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     48  1.1  thorpej  * modification, are permitted provided that the following conditions
     49  1.1  thorpej  * are met:
     50  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     51  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     52  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     53  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     54  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     55  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     56  1.1  thorpej  *    must display the following acknowledgement:
     57  1.1  thorpej  *	This product includes software developed by the University of
     58  1.1  thorpej  *	California, Berkeley and its contributors.
     59  1.1  thorpej  * 4. Neither the name of the University nor the names of its contributors
     60  1.1  thorpej  *    may be used to endorse or promote products derived from this software
     61  1.1  thorpej  *    without specific prior written permission.
     62  1.1  thorpej  *
     63  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     64  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     65  1.1  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     66  1.1  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     67  1.1  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     68  1.1  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     69  1.1  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     70  1.1  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     71  1.1  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     72  1.1  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     73  1.1  thorpej  * SUCH DAMAGE.
     74  1.1  thorpej  *
     75  1.1  thorpej  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     76  1.1  thorpej  */
     77  1.4    lukem 
     78  1.4    lukem #include <sys/cdefs.h>
     79  1.9  thorpej __KERNEL_RCSID(0, "$NetBSD: depca.c,v 1.9 2003/01/01 00:10:18 thorpej Exp $");
     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.1  thorpej #include <net/if_ether.h>
     90  1.1  thorpej #include <net/if_media.h>
     91  1.1  thorpej 
     92  1.1  thorpej #include <machine/cpu.h>
     93  1.1  thorpej #include <machine/intr.h>
     94  1.1  thorpej #include <machine/bus.h>
     95  1.1  thorpej 
     96  1.1  thorpej #include <dev/isa/isareg.h>
     97  1.1  thorpej #include <dev/isa/isavar.h>
     98  1.1  thorpej 
     99  1.1  thorpej #include <dev/ic/lancereg.h>
    100  1.1  thorpej #include <dev/ic/lancevar.h>
    101  1.1  thorpej #include <dev/ic/am7990reg.h>
    102  1.1  thorpej #include <dev/ic/am7990var.h>
    103  1.1  thorpej #include <dev/ic/depcareg.h>
    104  1.1  thorpej #include <dev/ic/depcavar.h>
    105  1.1  thorpej 
    106  1.1  thorpej struct le_depca_softc {
    107  1.1  thorpej 	struct am7990_softc sc_am7990;	/* glue to MI code */
    108  1.1  thorpej 
    109  1.1  thorpej 	void *sc_ih;
    110  1.1  thorpej };
    111  1.1  thorpej 
    112  1.1  thorpej int	le_depca_match(struct device *, struct cfdata *, void *);
    113  1.1  thorpej void	le_depca_attach(struct device *, struct device *, void *);
    114  1.1  thorpej 
    115  1.7  thorpej CFATTACH_DECL(le_depca, sizeof(struct le_depca_softc),
    116  1.8  thorpej     le_depca_match, le_depca_attach, NULL, NULL);
    117  1.1  thorpej 
    118  1.1  thorpej void	depca_copytobuf(struct lance_softc *, void *, int, int);
    119  1.1  thorpej void	depca_copyfrombuf(struct lance_softc *, void *, int, int);
    120  1.1  thorpej void	depca_zerobuf(struct lance_softc *, int, int);
    121  1.1  thorpej 
    122  1.1  thorpej struct depca_attach_args {
    123  1.1  thorpej 	const char *da_name;
    124  1.1  thorpej };
    125  1.1  thorpej 
    126  1.1  thorpej int	depca_print(void *, const char *);
    127  1.1  thorpej 
    128  1.1  thorpej void
    129  1.1  thorpej depca_attach(struct depca_softc *sc)
    130  1.1  thorpej {
    131  1.1  thorpej 	struct depca_attach_args da;
    132  1.1  thorpej 
    133  1.1  thorpej 	da.da_name = "le";
    134  1.1  thorpej 
    135  1.1  thorpej 	(void) config_found(&sc->sc_dev, &da, depca_print);
    136  1.1  thorpej }
    137  1.1  thorpej 
    138  1.1  thorpej int
    139  1.1  thorpej depca_print(void *aux, const char *pnp)
    140  1.1  thorpej {
    141  1.1  thorpej 	struct depca_attach_args *da = aux;
    142  1.1  thorpej 
    143  1.1  thorpej 	if (pnp)
    144  1.9  thorpej 		aprint_normal("%s at %s", da->da_name, pnp);
    145  1.1  thorpej 
    146  1.1  thorpej 	return (UNCONF);
    147  1.1  thorpej }
    148  1.1  thorpej 
    149  1.1  thorpej void
    150  1.1  thorpej depca_wrcsr(struct lance_softc *sc, u_int16_t port, u_int16_t val)
    151  1.1  thorpej {
    152  1.1  thorpej 	struct depca_softc *dsc = (void *) sc->sc_dev.dv_parent;
    153  1.1  thorpej 
    154  1.1  thorpej 	bus_space_write_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_RAP, port);
    155  1.1  thorpej 	bus_space_write_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_RDP, val);
    156  1.1  thorpej }
    157  1.1  thorpej 
    158  1.1  thorpej u_int16_t
    159  1.1  thorpej depca_rdcsr(struct lance_softc *sc, u_int16_t port)
    160  1.1  thorpej {
    161  1.1  thorpej 	struct depca_softc *dsc = (void *) sc->sc_dev.dv_parent;
    162  1.1  thorpej 
    163  1.1  thorpej 	bus_space_write_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_RAP, port);
    164  1.1  thorpej 	return (bus_space_read_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_RDP));
    165  1.1  thorpej }
    166  1.1  thorpej 
    167  1.1  thorpej int
    168  1.1  thorpej depca_readprom(bus_space_tag_t iot, bus_space_handle_t ioh, u_int8_t *laddr)
    169  1.1  thorpej {
    170  1.1  thorpej 	int port, i;
    171  1.1  thorpej 
    172  1.1  thorpej 	/*
    173  1.1  thorpej 	 * Extract the physical MAC address from the ROM.
    174  1.1  thorpej 	 *
    175  1.1  thorpej 	 * The address PROM is 32 bytes wide, and we access it through
    176  1.1  thorpej 	 * a single I/O port.  On each read, it rotates to the next
    177  1.1  thorpej 	 * position.  We find the ethernet address by looking for a
    178  1.1  thorpej 	 * particular sequence of bytes (0xff, 0x00, 0x55, 0xaa, 0xff,
    179  1.1  thorpej 	 * 0x00, 0x55, 0xaa), and then reading the next 8 bytes (the
    180  1.1  thorpej 	 * ethernet address and a checksum).
    181  1.1  thorpej 	 *
    182  1.1  thorpej 	 * It appears that the PROM can be at one of two locations, so
    183  1.1  thorpej 	 * we just try both.
    184  1.1  thorpej 	 */
    185  1.1  thorpej 	port = DEPCA_ADP;
    186  1.1  thorpej 	for (i = 0; i < 32; i++)
    187  1.1  thorpej 		if (bus_space_read_1(iot, ioh, port) == 0xff &&
    188  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    189  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    190  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa &&
    191  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0xff &&
    192  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    193  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    194  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa)
    195  1.1  thorpej 			goto found;
    196  1.1  thorpej 	port = DEPCA_ADP + 1;
    197  1.1  thorpej 	for (i = 0; i < 32; i++)
    198  1.1  thorpej 		if (bus_space_read_1(iot, ioh, port) == 0xff &&
    199  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    200  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    201  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa &&
    202  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0xff &&
    203  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0x00 &&
    204  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0x55 &&
    205  1.1  thorpej 		    bus_space_read_1(iot, ioh, port) == 0xaa)
    206  1.1  thorpej 			goto found;
    207  1.1  thorpej 	printf("depca: address not found\n");
    208  1.1  thorpej 	return (-1);
    209  1.1  thorpej 
    210  1.1  thorpej found:
    211  1.1  thorpej 
    212  1.1  thorpej 	if (laddr) {
    213  1.1  thorpej 		for (i = 0; i < 6; i++)
    214  1.1  thorpej 			laddr[i] = bus_space_read_1(iot, ioh, port);
    215  1.1  thorpej 	}
    216  1.1  thorpej 
    217  1.1  thorpej #if 0
    218  1.1  thorpej 	sum =
    219  1.1  thorpej 	    (laddr[0] <<  2) +
    220  1.1  thorpej 	    (laddr[1] << 10) +
    221  1.1  thorpej 	    (laddr[2] <<  1) +
    222  1.1  thorpej 	    (laddr[3] <<  9) +
    223  1.1  thorpej 	    (laddr[4] <<  0) +
    224  1.1  thorpej 	    (laddr[5] <<  8);
    225  1.1  thorpej 	sum = (sum & 0xffff) + (sum >> 16);
    226  1.1  thorpej 	sum = (sum & 0xffff) + (sum >> 16);
    227  1.1  thorpej 
    228  1.1  thorpej 	rom_sum = bus_space_read_1(iot, ioh, port);
    229  1.1  thorpej 	rom_sum |= bus_space_read_1(iot, ioh, port) << 8;
    230  1.1  thorpej 
    231  1.1  thorpej 	if (sum != rom_sum) {
    232  1.1  thorpej 		printf("depca: checksum mismatch; calculated %04x != read %04x",
    233  1.1  thorpej 		       sum, rom_sum);
    234  1.1  thorpej 		return (-1);
    235  1.1  thorpej 	}
    236  1.1  thorpej #endif
    237  1.1  thorpej 
    238  1.1  thorpej 	return (0);
    239  1.1  thorpej }
    240  1.1  thorpej 
    241  1.1  thorpej int
    242  1.1  thorpej le_depca_match(struct device *parent, struct cfdata *match, void *aux)
    243  1.1  thorpej {
    244  1.1  thorpej 	struct depca_attach_args *da = aux;
    245  1.1  thorpej 
    246  1.5  thorpej 	return (strcmp(da->da_name, match->cf_name) == 0);
    247  1.1  thorpej }
    248  1.1  thorpej 
    249  1.1  thorpej void
    250  1.1  thorpej le_depca_attach(struct device *parent, struct device *self, void *aux)
    251  1.1  thorpej {
    252  1.1  thorpej 	struct depca_softc *dsc = (void *) parent;
    253  1.1  thorpej 	struct le_depca_softc *lesc = (void *) self;
    254  1.1  thorpej 	struct lance_softc *sc = &lesc->sc_am7990.lsc;
    255  1.1  thorpej 	u_int8_t val;
    256  1.1  thorpej 	int i;
    257  1.1  thorpej 
    258  1.1  thorpej 	printf("\n");
    259  1.1  thorpej 
    260  1.1  thorpej 	/* I/O and memory spaces already mapped. */
    261  1.1  thorpej 
    262  1.1  thorpej 	if (depca_readprom(dsc->sc_iot, dsc->sc_ioh, sc->sc_enaddr)) {
    263  1.1  thorpej 		printf("%s: can't read PROM\n", self->dv_xname);
    264  1.1  thorpej 		return;
    265  1.1  thorpej 	}
    266  1.1  thorpej 
    267  1.1  thorpej 	bus_space_write_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_CSR,
    268  1.1  thorpej 	    DEPCA_CSR_DUM | DEPCA_CSR_IEN | DEPCA_CSR_SHE |
    269  1.1  thorpej 	    (dsc->sc_memsize == 32*1024 ? DEPCA_CSR_LOW32K : 0));
    270  1.1  thorpej 
    271  1.1  thorpej 	val = 0xff;
    272  1.1  thorpej 	for (;;) {
    273  1.1  thorpej 		u_int8_t cv;
    274  1.1  thorpej 
    275  1.1  thorpej 		bus_space_set_region_1(dsc->sc_memt, dsc->sc_memh, 0, val,
    276  1.1  thorpej 		    dsc->sc_memsize);
    277  1.1  thorpej 		for (i = 0; i < dsc->sc_memsize; i++) {
    278  1.1  thorpej 			cv = bus_space_read_1(dsc->sc_memt, dsc->sc_memh, i);
    279  1.1  thorpej 			if (cv != val) {
    280  1.1  thorpej 				printf("%s: failed to clear memory at %d "
    281  1.1  thorpej 				    "(0x%02x != 0x%02x)\n",
    282  1.1  thorpej 				    sc->sc_dev.dv_xname, i, cv, val);
    283  1.1  thorpej 				return;
    284  1.1  thorpej 			}
    285  1.1  thorpej 		}
    286  1.1  thorpej 		if (val == 0x00)
    287  1.1  thorpej 			break;
    288  1.1  thorpej 		val -= 0x55;
    289  1.1  thorpej 	}
    290  1.1  thorpej 
    291  1.1  thorpej 	sc->sc_conf3 = LE_C3_ACON;
    292  1.1  thorpej 	sc->sc_mem = 0;			/* Not used. */
    293  1.1  thorpej 	sc->sc_addr = 0;
    294  1.1  thorpej 	sc->sc_memsize = dsc->sc_memsize;
    295  1.1  thorpej 
    296  1.1  thorpej 	sc->sc_copytodesc = depca_copytobuf;
    297  1.1  thorpej 	sc->sc_copyfromdesc = depca_copyfrombuf;
    298  1.1  thorpej 	sc->sc_copytobuf = depca_copytobuf;
    299  1.1  thorpej 	sc->sc_copyfrombuf = depca_copyfrombuf;
    300  1.1  thorpej 	sc->sc_zerobuf = depca_zerobuf;
    301  1.1  thorpej 
    302  1.1  thorpej 	sc->sc_rdcsr = depca_rdcsr;
    303  1.1  thorpej 	sc->sc_wrcsr = depca_wrcsr;
    304  1.1  thorpej 	sc->sc_hwinit = NULL;
    305  1.1  thorpej 
    306  1.1  thorpej 	printf("%s", sc->sc_dev.dv_xname);
    307  1.1  thorpej 	am7990_config(&lesc->sc_am7990);
    308  1.1  thorpej 
    309  1.1  thorpej 	lesc->sc_ih = (*dsc->sc_intr_establish)(dsc, sc);
    310  1.1  thorpej }
    311  1.1  thorpej 
    312  1.1  thorpej /*
    313  1.1  thorpej  * Controller interrupt.
    314  1.1  thorpej  */
    315  1.1  thorpej int
    316  1.1  thorpej depca_intredge(void *arg)
    317  1.1  thorpej {
    318  1.1  thorpej 
    319  1.1  thorpej 	if (am7990_intr(arg) == 0)
    320  1.1  thorpej 		return (0);
    321  1.1  thorpej 	for (;;)
    322  1.1  thorpej 		if (am7990_intr(arg) == 0)
    323  1.1  thorpej 			return (1);
    324  1.1  thorpej }
    325  1.1  thorpej 
    326  1.1  thorpej /*
    327  1.1  thorpej  * DEPCA shared memory access functions.
    328  1.1  thorpej  */
    329  1.1  thorpej 
    330  1.1  thorpej void
    331  1.1  thorpej depca_copytobuf(struct lance_softc *sc, void *from, int boff, int len)
    332  1.1  thorpej {
    333  1.1  thorpej 	struct depca_softc *dsc = (void *) sc->sc_dev.dv_parent;
    334  1.1  thorpej 
    335  1.1  thorpej 	bus_space_write_region_1(dsc->sc_memt, dsc->sc_memh, boff,
    336  1.1  thorpej 	    from, len);
    337  1.1  thorpej }
    338  1.1  thorpej 
    339  1.1  thorpej void
    340  1.1  thorpej depca_copyfrombuf(struct lance_softc *sc, void *to, int boff, int len)
    341  1.1  thorpej {
    342  1.1  thorpej 	struct depca_softc *dsc = (void *) sc->sc_dev.dv_parent;
    343  1.1  thorpej 
    344  1.1  thorpej 	bus_space_read_region_1(dsc->sc_memt, dsc->sc_memh, boff,
    345  1.1  thorpej 	    to, len);
    346  1.1  thorpej }
    347  1.1  thorpej 
    348  1.1  thorpej void
    349  1.1  thorpej depca_zerobuf(struct lance_softc *sc, int boff, int len)
    350  1.1  thorpej {
    351  1.1  thorpej 	struct depca_softc *dsc = (void *) sc->sc_dev.dv_parent;
    352  1.1  thorpej 
    353  1.1  thorpej 	bus_space_set_region_1(dsc->sc_memt, dsc->sc_memh, boff,
    354  1.1  thorpej 	    0x00, len);
    355  1.1  thorpej }
    356