2007-10-19 15:59:34 +04:00
|
|
|
/* $NetBSD: depca.c,v 1.15 2007/10/19 11:59:50 ad Exp $ */
|
1998-04-16 22:00:14 +04:00
|
|
|
|
|
|
|
/*-
|
2000-08-11 06:27:07 +04:00
|
|
|
* Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
|
1998-04-16 22:00:14 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
1998-08-15 14:51:16 +04:00
|
|
|
* by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
|
|
|
|
* Simulation Facility, NASA Ames Research Center.
|
1998-04-16 22:00:14 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Ralph Campbell and Rick Macklem.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1998-04-16 22:00:14 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)if_le.c 8.2 (Berkeley) 11/16/93
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-10-19 15:59:34 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: depca.c,v 1.15 2007/10/19 11:59:50 ad Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
1998-04-16 22:00:14 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/cpu.h>
|
|
|
|
#include <sys/intr.h>
|
|
|
|
#include <sys/bus.h>
|
1998-04-16 22:00:14 +04:00
|
|
|
|
|
|
|
#include <dev/isa/isareg.h>
|
|
|
|
#include <dev/isa/isavar.h>
|
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
#include <dev/ic/lancereg.h>
|
|
|
|
#include <dev/ic/lancevar.h>
|
1998-04-16 22:00:14 +04:00
|
|
|
#include <dev/ic/am7990reg.h>
|
|
|
|
#include <dev/ic/am7990var.h>
|
2000-08-11 06:27:07 +04:00
|
|
|
#include <dev/ic/depcareg.h>
|
|
|
|
#include <dev/ic/depcavar.h>
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
struct le_depca_softc {
|
|
|
|
struct am7990_softc sc_am7990; /* glue to MI code */
|
|
|
|
|
|
|
|
void *sc_ih;
|
1998-04-16 22:00:14 +04:00
|
|
|
};
|
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
int le_depca_match(struct device *, struct cfdata *, void *);
|
|
|
|
void le_depca_attach(struct device *, struct device *, void *);
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2002-10-01 01:17:57 +04:00
|
|
|
CFATTACH_DECL(le_depca, sizeof(struct le_depca_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
le_depca_match, le_depca_attach, NULL, NULL);
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
void depca_copytobuf(struct lance_softc *, void *, int, int);
|
|
|
|
void depca_copyfrombuf(struct lance_softc *, void *, int, int);
|
|
|
|
void depca_zerobuf(struct lance_softc *, int, int);
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
struct depca_attach_args {
|
|
|
|
const char *da_name;
|
|
|
|
};
|
1998-07-21 21:36:01 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
int depca_print(void *, const char *);
|
|
|
|
|
|
|
|
void
|
|
|
|
depca_attach(struct depca_softc *sc)
|
|
|
|
{
|
|
|
|
struct depca_attach_args da;
|
|
|
|
|
|
|
|
da.da_name = "le";
|
|
|
|
|
|
|
|
(void) config_found(&sc->sc_dev, &da, depca_print);
|
|
|
|
}
|
1998-07-21 21:36:01 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
int
|
|
|
|
depca_print(void *aux, const char *pnp)
|
|
|
|
{
|
|
|
|
struct depca_attach_args *da = aux;
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
if (pnp)
|
2003-01-01 03:10:15 +03:00
|
|
|
aprint_normal("%s at %s", da->da_name, pnp);
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
return (UNCONF);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
depca_wrcsr(struct lance_softc *sc, u_int16_t port, u_int16_t val)
|
1998-04-16 22:00:14 +04:00
|
|
|
{
|
2006-03-26 01:55:55 +03:00
|
|
|
struct depca_softc *dsc = (void *) device_parent(&sc->sc_dev);
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
bus_space_write_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_RAP, port);
|
|
|
|
bus_space_write_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_RDP, val);
|
1998-04-16 22:00:14 +04:00
|
|
|
}
|
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
u_int16_t
|
|
|
|
depca_rdcsr(struct lance_softc *sc, u_int16_t port)
|
1998-04-16 22:00:14 +04:00
|
|
|
{
|
2006-03-26 01:55:55 +03:00
|
|
|
struct depca_softc *dsc = (void *) device_parent(&sc->sc_dev);
|
2000-08-11 06:27:07 +04:00
|
|
|
|
|
|
|
bus_space_write_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_RAP, port);
|
|
|
|
return (bus_space_read_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_RDP));
|
1998-04-16 22:00:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-08-11 06:27:07 +04:00
|
|
|
depca_readprom(bus_space_tag_t iot, bus_space_handle_t ioh, u_int8_t *laddr)
|
1998-04-16 22:00:14 +04:00
|
|
|
{
|
|
|
|
int port, i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Extract the physical MAC address from the ROM.
|
|
|
|
*
|
|
|
|
* The address PROM is 32 bytes wide, and we access it through
|
|
|
|
* a single I/O port. On each read, it rotates to the next
|
|
|
|
* position. We find the ethernet address by looking for a
|
|
|
|
* particular sequence of bytes (0xff, 0x00, 0x55, 0xaa, 0xff,
|
|
|
|
* 0x00, 0x55, 0xaa), and then reading the next 8 bytes (the
|
|
|
|
* ethernet address and a checksum).
|
|
|
|
*
|
|
|
|
* It appears that the PROM can be at one of two locations, so
|
|
|
|
* we just try both.
|
|
|
|
*/
|
|
|
|
port = DEPCA_ADP;
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
if (bus_space_read_1(iot, ioh, port) == 0xff &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0x00 &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0x55 &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0xaa &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0xff &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0x00 &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0x55 &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0xaa)
|
|
|
|
goto found;
|
|
|
|
port = DEPCA_ADP + 1;
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
if (bus_space_read_1(iot, ioh, port) == 0xff &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0x00 &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0x55 &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0xaa &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0xff &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0x00 &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0x55 &&
|
|
|
|
bus_space_read_1(iot, ioh, port) == 0xaa)
|
|
|
|
goto found;
|
|
|
|
printf("depca: address not found\n");
|
|
|
|
return (-1);
|
|
|
|
|
|
|
|
found:
|
|
|
|
|
|
|
|
if (laddr) {
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
laddr[i] = bus_space_read_1(iot, ioh, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
sum =
|
|
|
|
(laddr[0] << 2) +
|
|
|
|
(laddr[1] << 10) +
|
|
|
|
(laddr[2] << 1) +
|
|
|
|
(laddr[3] << 9) +
|
|
|
|
(laddr[4] << 0) +
|
|
|
|
(laddr[5] << 8);
|
|
|
|
sum = (sum & 0xffff) + (sum >> 16);
|
|
|
|
sum = (sum & 0xffff) + (sum >> 16);
|
|
|
|
|
|
|
|
rom_sum = bus_space_read_1(iot, ioh, port);
|
|
|
|
rom_sum |= bus_space_read_1(iot, ioh, port) << 8;
|
|
|
|
|
|
|
|
if (sum != rom_sum) {
|
|
|
|
printf("depca: checksum mismatch; calculated %04x != read %04x",
|
|
|
|
sum, rom_sum);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-11-16 04:32:37 +03:00
|
|
|
le_depca_match(struct device *parent, struct cfdata *match, void *aux)
|
1998-04-16 22:00:14 +04:00
|
|
|
{
|
2000-08-11 06:27:07 +04:00
|
|
|
struct depca_attach_args *da = aux;
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2002-09-27 06:24:06 +04:00
|
|
|
return (strcmp(da->da_name, match->cf_name) == 0);
|
1998-04-16 22:00:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-11-16 04:32:37 +03:00
|
|
|
le_depca_attach(struct device *parent, struct device *self, void *aux)
|
1998-04-16 22:00:14 +04:00
|
|
|
{
|
2000-08-11 06:27:07 +04:00
|
|
|
struct depca_softc *dsc = (void *) parent;
|
|
|
|
struct le_depca_softc *lesc = (void *) self;
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc = &lesc->sc_am7990.lsc;
|
2000-08-11 06:27:07 +04:00
|
|
|
u_int8_t val;
|
1998-04-16 22:00:14 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
/* I/O and memory spaces already mapped. */
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
if (depca_readprom(dsc->sc_iot, dsc->sc_ioh, sc->sc_enaddr)) {
|
1998-04-16 22:00:14 +04:00
|
|
|
printf("%s: can't read PROM\n", self->dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
bus_space_write_2(dsc->sc_iot, dsc->sc_ioh, DEPCA_CSR,
|
|
|
|
DEPCA_CSR_DUM | DEPCA_CSR_IEN | DEPCA_CSR_SHE |
|
|
|
|
(dsc->sc_memsize == 32*1024 ? DEPCA_CSR_LOW32K : 0));
|
1998-04-16 22:00:14 +04:00
|
|
|
|
|
|
|
val = 0xff;
|
|
|
|
for (;;) {
|
2000-08-11 06:27:07 +04:00
|
|
|
u_int8_t cv;
|
|
|
|
|
|
|
|
bus_space_set_region_1(dsc->sc_memt, dsc->sc_memh, 0, val,
|
|
|
|
dsc->sc_memsize);
|
|
|
|
for (i = 0; i < dsc->sc_memsize; i++) {
|
|
|
|
cv = bus_space_read_1(dsc->sc_memt, dsc->sc_memh, i);
|
|
|
|
if (cv != val) {
|
|
|
|
printf("%s: failed to clear memory at %d "
|
|
|
|
"(0x%02x != 0x%02x)\n",
|
|
|
|
sc->sc_dev.dv_xname, i, cv, val);
|
1998-04-16 22:00:14 +04:00
|
|
|
return;
|
|
|
|
}
|
2000-08-11 06:27:07 +04:00
|
|
|
}
|
1998-04-16 22:00:14 +04:00
|
|
|
if (val == 0x00)
|
|
|
|
break;
|
|
|
|
val -= 0x55;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_conf3 = LE_C3_ACON;
|
|
|
|
sc->sc_mem = 0; /* Not used. */
|
|
|
|
sc->sc_addr = 0;
|
2000-08-11 06:27:07 +04:00
|
|
|
sc->sc_memsize = dsc->sc_memsize;
|
1998-04-16 22:00:14 +04:00
|
|
|
|
|
|
|
sc->sc_copytodesc = depca_copytobuf;
|
|
|
|
sc->sc_copyfromdesc = depca_copyfrombuf;
|
|
|
|
sc->sc_copytobuf = depca_copytobuf;
|
|
|
|
sc->sc_copyfrombuf = depca_copyfrombuf;
|
|
|
|
sc->sc_zerobuf = depca_zerobuf;
|
|
|
|
|
|
|
|
sc->sc_rdcsr = depca_rdcsr;
|
|
|
|
sc->sc_wrcsr = depca_wrcsr;
|
|
|
|
sc->sc_hwinit = NULL;
|
|
|
|
|
|
|
|
printf("%s", sc->sc_dev.dv_xname);
|
1998-07-21 21:36:01 +04:00
|
|
|
am7990_config(&lesc->sc_am7990);
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
lesc->sc_ih = (*dsc->sc_intr_establish)(dsc, sc);
|
1998-04-16 22:00:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Controller interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2000-08-11 06:27:07 +04:00
|
|
|
depca_intredge(void *arg)
|
1998-04-16 22:00:14 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (am7990_intr(arg) == 0)
|
|
|
|
return (0);
|
|
|
|
for (;;)
|
|
|
|
if (am7990_intr(arg) == 0)
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DEPCA shared memory access functions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2000-08-11 06:27:07 +04:00
|
|
|
depca_copytobuf(struct lance_softc *sc, void *from, int boff, int len)
|
1998-04-16 22:00:14 +04:00
|
|
|
{
|
2006-03-26 01:55:55 +03:00
|
|
|
struct depca_softc *dsc = (void *) device_parent(&sc->sc_dev);
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
bus_space_write_region_1(dsc->sc_memt, dsc->sc_memh, boff,
|
1998-04-16 22:00:14 +04:00
|
|
|
from, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-11 06:27:07 +04:00
|
|
|
depca_copyfrombuf(struct lance_softc *sc, void *to, int boff, int len)
|
1998-04-16 22:00:14 +04:00
|
|
|
{
|
2006-03-26 01:55:55 +03:00
|
|
|
struct depca_softc *dsc = (void *) device_parent(&sc->sc_dev);
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
bus_space_read_region_1(dsc->sc_memt, dsc->sc_memh, boff,
|
1998-04-16 22:00:14 +04:00
|
|
|
to, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-11 06:27:07 +04:00
|
|
|
depca_zerobuf(struct lance_softc *sc, int boff, int len)
|
1998-04-16 22:00:14 +04:00
|
|
|
{
|
2006-03-26 01:55:55 +03:00
|
|
|
struct depca_softc *dsc = (void *) device_parent(&sc->sc_dev);
|
1998-04-16 22:00:14 +04:00
|
|
|
|
2000-08-11 06:27:07 +04:00
|
|
|
bus_space_set_region_1(dsc->sc_memt, dsc->sc_memh, boff,
|
1998-04-16 22:00:14 +04:00
|
|
|
0x00, len);
|
|
|
|
}
|