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