1998-08-15 14:51:16 +04:00
|
|
|
/* $NetBSD: if_le.c,v 1.47 1998/08/15 10:51:16 mycroft Exp $ */
|
1998-01-12 00:57:02 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* 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.
|
1998-01-12 00:57:02 +03: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.
|
|
|
|
*/
|
1994-10-26 10:22:45 +03:00
|
|
|
|
1995-12-10 03:49:33 +03:00
|
|
|
/*-
|
|
|
|
* 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.
|
1993-05-13 17:56:20 +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 University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University 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 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.
|
|
|
|
*
|
1995-12-10 03:49:33 +03:00
|
|
|
* @(#)if_le.c 8.2 (Berkeley) 11/16/93
|
1993-05-13 17:56:20 +04:00
|
|
|
*/
|
|
|
|
|
1998-07-05 04:51:04 +04:00
|
|
|
#include "opt_inet.h"
|
1993-05-13 17:56:20 +04:00
|
|
|
#include "bpfilter.h"
|
|
|
|
|
1994-02-05 08:06:54 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/syslog.h>
|
1995-12-10 03:49:33 +03:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
1994-02-05 08:06:54 +03:00
|
|
|
|
|
|
|
#include <net/if.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <net/if_ether.h>
|
1997-03-17 06:17:34 +03:00
|
|
|
#include <net/if_media.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
|
|
|
#ifdef INET
|
1994-02-05 08:06:54 +03:00
|
|
|
#include <netinet/in.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
#endif
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
#include <machine/autoconf.h>
|
1994-02-05 08:06:54 +03:00
|
|
|
#include <machine/cpu.h>
|
1997-04-14 06:33:16 +04:00
|
|
|
#include <machine/intr.h>
|
1995-12-31 00:03:02 +03:00
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
#include <dev/ic/lancereg.h>
|
|
|
|
#include <dev/ic/lancevar.h>
|
1995-12-10 03:49:33 +03:00
|
|
|
#include <dev/ic/am7990reg.h>
|
|
|
|
#include <dev/ic/am7990var.h>
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
#include <hp300/dev/dioreg.h>
|
|
|
|
#include <hp300/dev/diovar.h>
|
|
|
|
#include <hp300/dev/diodevs.h>
|
1996-05-07 04:57:58 +04:00
|
|
|
#include <hp300/dev/if_lereg.h>
|
|
|
|
#include <hp300/dev/if_levar.h>
|
|
|
|
|
1997-05-06 01:05:32 +04:00
|
|
|
#include "opt_useleds.h"
|
|
|
|
|
|
|
|
#ifdef USELEDS
|
|
|
|
#include <hp300/hp300/leds.h>
|
|
|
|
#endif
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
int lematch __P((struct device *, struct cfdata *, void *));
|
|
|
|
void leattach __P((struct device *, struct device *, void *));
|
|
|
|
|
|
|
|
struct cfattach le_ca = {
|
|
|
|
sizeof(struct le_softc), lematch, leattach
|
|
|
|
};
|
|
|
|
|
|
|
|
int leintr __P((void *));
|
1994-02-06 03:46:02 +03:00
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
#if defined(_KERNEL) && !defined(_LKM)
|
|
|
|
#include "opt_ddb.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DDB
|
|
|
|
#define integrate
|
|
|
|
#define hide
|
|
|
|
#else
|
|
|
|
#define integrate static __inline
|
|
|
|
#define hide static
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hide void le_copytobuf __P((struct lance_softc *, void *, int, int));
|
|
|
|
hide void le_copyfrombuf __P((struct lance_softc *, void *, int, int));
|
|
|
|
hide void le_zerobuf __P((struct lance_softc *, int, int));
|
1998-01-12 00:57:02 +03:00
|
|
|
|
1995-12-10 03:49:33 +03:00
|
|
|
/* offsets for: ID, REGS, MEM, NVRAM */
|
|
|
|
int lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
|
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
hide void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
|
|
|
|
hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
|
1996-04-22 06:25:54 +04:00
|
|
|
|
1996-05-07 04:57:58 +04:00
|
|
|
hide void
|
1994-07-06 05:36:23 +04:00
|
|
|
lewrcsr(sc, port, val)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1995-12-10 03:49:33 +03:00
|
|
|
u_int16_t port, val;
|
1994-07-06 05:36:23 +04:00
|
|
|
{
|
1998-01-12 00:57:02 +03:00
|
|
|
struct le_softc *lesc = (struct le_softc *)sc;
|
|
|
|
bus_space_tag_t bst = lesc->sc_bst;
|
|
|
|
bus_space_handle_t bsh0 = lesc->sc_bsh0;
|
|
|
|
bus_space_handle_t bsh1 = lesc->sc_bsh1;
|
1994-07-06 05:36:23 +04:00
|
|
|
|
|
|
|
do {
|
1998-01-12 00:57:02 +03:00
|
|
|
bus_space_write_2(bst, bsh1, LER1_RAP, port);
|
|
|
|
} while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
|
1994-07-06 05:36:23 +04:00
|
|
|
do {
|
1998-01-12 00:57:02 +03:00
|
|
|
bus_space_write_2(bst, bsh1, LER1_RDP, val);
|
|
|
|
} while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
|
1994-07-06 05:36:23 +04:00
|
|
|
}
|
|
|
|
|
1996-05-07 04:57:58 +04:00
|
|
|
hide u_int16_t
|
1994-07-06 05:36:23 +04:00
|
|
|
lerdcsr(sc, port)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1995-12-10 03:49:33 +03:00
|
|
|
u_int16_t port;
|
1994-07-06 05:36:23 +04:00
|
|
|
{
|
1998-01-12 00:57:02 +03:00
|
|
|
struct le_softc *lesc = (struct le_softc *)sc;
|
|
|
|
bus_space_tag_t bst = lesc->sc_bst;
|
|
|
|
bus_space_handle_t bsh0 = lesc->sc_bsh0;
|
|
|
|
bus_space_handle_t bsh1 = lesc->sc_bsh1;
|
1995-12-10 03:49:33 +03:00
|
|
|
u_int16_t val;
|
1994-07-06 05:36:23 +04:00
|
|
|
|
|
|
|
do {
|
1998-01-12 00:57:02 +03:00
|
|
|
bus_space_write_2(bst, bsh1, LER1_RAP, port);
|
|
|
|
} while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
|
1994-07-06 05:36:23 +04:00
|
|
|
do {
|
1998-01-12 00:57:02 +03:00
|
|
|
val = bus_space_read_2(bst, bsh1, LER1_RDP);
|
|
|
|
} while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
|
|
|
|
|
1994-07-06 05:36:23 +04:00
|
|
|
return (val);
|
|
|
|
}
|
|
|
|
|
1996-12-17 11:40:56 +03:00
|
|
|
int
|
|
|
|
lematch(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct dio_attach_args *da = aux;
|
|
|
|
|
|
|
|
if (da->da_id == DIO_DEVICE_ID_LAN)
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
1995-12-02 21:21:49 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
|
|
|
* Interface exists: make available by filling in network interface
|
|
|
|
* record. System will initialize the interface when it is ready
|
|
|
|
* to accept packets.
|
|
|
|
*/
|
1996-12-17 11:40:56 +03:00
|
|
|
void
|
|
|
|
leattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-05-13 17:56:20 +04:00
|
|
|
{
|
1996-12-17 11:40:56 +03:00
|
|
|
struct dio_attach_args *da = aux;
|
|
|
|
struct le_softc *lesc = (struct le_softc *)self;
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc = &lesc->sc_am7990.lsc;
|
1998-01-12 00:57:02 +03:00
|
|
|
bus_space_tag_t bst = da->da_bst;
|
|
|
|
bus_space_handle_t bsh0, bsh1, bsh2;
|
|
|
|
bus_size_t offset;
|
1996-12-17 11:40:56 +03:00
|
|
|
int i, ipl;
|
|
|
|
|
1998-01-12 00:57:02 +03:00
|
|
|
if (bus_space_map(bst, (bus_addr_t)dio_scodetopa(da->da_scode),
|
|
|
|
da->da_size, 0, &bsh0)) {
|
1996-12-17 11:40:56 +03:00
|
|
|
printf("\n%s: can't map LANCE registers\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1998-01-12 00:57:02 +03:00
|
|
|
if (bus_space_subregion(bst, bsh0, lestd[1], LER1_SIZE, &bsh1)) {
|
|
|
|
printf("\n%s: can't subregion LANCE space\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bus_space_subregion(bst, bsh0, lestd[2], LE_BUFSIZE, &bsh2)) {
|
|
|
|
printf("\n%s: can't subregion buffer space\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lesc->sc_bst = bst;
|
|
|
|
lesc->sc_bsh0 = bsh0;
|
|
|
|
lesc->sc_bsh1 = bsh1;
|
|
|
|
lesc->sc_bsh2 = bsh2;
|
|
|
|
|
|
|
|
bus_space_write_1(bst, bsh0, LER0_ID, 0xff);
|
1993-05-13 17:56:20 +04:00
|
|
|
DELAY(100);
|
|
|
|
|
1998-01-12 00:57:02 +03:00
|
|
|
ipl = DIO_IPL((caddr_t)bsh0); /* XXX */
|
1996-12-17 11:40:56 +03:00
|
|
|
printf(" ipl %d", ipl);
|
1995-12-10 03:49:33 +03:00
|
|
|
|
|
|
|
sc->sc_conf3 = LE_C3_BSWP;
|
|
|
|
sc->sc_addr = 0;
|
1998-01-12 00:57:02 +03:00
|
|
|
sc->sc_memsize = LE_BUFSIZE;
|
1995-12-10 03:49:33 +03:00
|
|
|
|
1993-05-13 17:56:20 +04:00
|
|
|
/*
|
|
|
|
* Read the ethernet address off the board, one nibble at a time.
|
|
|
|
*/
|
1998-01-12 00:57:02 +03:00
|
|
|
offset = lestd[3];
|
1997-03-15 21:09:08 +03:00
|
|
|
for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
|
1998-01-12 00:57:02 +03:00
|
|
|
sc->sc_enaddr[i] =
|
|
|
|
(bus_space_read_1(bst, bsh0, ++offset) & 0xf) << 4;
|
|
|
|
offset++;
|
|
|
|
sc->sc_enaddr[i] |=
|
|
|
|
(bus_space_read_1(bst, bsh0, ++offset) & 0xf);
|
|
|
|
offset++;
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
1994-07-06 05:36:23 +04:00
|
|
|
|
1998-01-12 00:57:02 +03:00
|
|
|
sc->sc_copytodesc = le_copytobuf;
|
|
|
|
sc->sc_copyfromdesc = le_copyfrombuf;
|
|
|
|
sc->sc_copytobuf = le_copytobuf;
|
|
|
|
sc->sc_copyfrombuf = le_copyfrombuf;
|
|
|
|
sc->sc_zerobuf = le_zerobuf;
|
1993-05-13 17:56:20 +04:00
|
|
|
|
1996-05-07 04:57:58 +04:00
|
|
|
sc->sc_rdcsr = lerdcsr;
|
|
|
|
sc->sc_wrcsr = lewrcsr;
|
|
|
|
sc->sc_hwinit = NULL;
|
|
|
|
|
1998-07-21 21:36:01 +04:00
|
|
|
am7990_config(&lesc->sc_am7990);
|
1994-07-06 05:36:23 +04:00
|
|
|
|
1996-02-14 05:43:54 +03:00
|
|
|
/* Establish the interrupt handler. */
|
1997-05-06 01:05:32 +04:00
|
|
|
(void) dio_intr_establish(leintr, sc, ipl, IPL_NET);
|
1998-01-12 00:57:02 +03:00
|
|
|
bus_space_write_1(bst, bsh0, LER0_STATUS, LE_IE);
|
1993-05-13 17:56:20 +04:00
|
|
|
}
|
1994-07-07 05:31:00 +04:00
|
|
|
|
1996-05-07 04:57:58 +04:00
|
|
|
int
|
|
|
|
leintr(arg)
|
1996-02-14 05:43:54 +03:00
|
|
|
void *arg;
|
1996-01-03 00:56:21 +03:00
|
|
|
{
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc = arg;
|
1997-05-03 11:09:57 +04:00
|
|
|
#ifdef USELEDS
|
1996-01-03 00:56:21 +03:00
|
|
|
u_int16_t isr;
|
|
|
|
|
|
|
|
isr = lerdcsr(sc, LE_CSR0);
|
|
|
|
|
|
|
|
if ((isr & LE_C0_INTR) == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (isr & LE_C0_RINT)
|
1997-05-06 01:05:32 +04:00
|
|
|
ledcontrol(0, 0, LED_LANRCV);
|
1996-01-03 00:56:21 +03:00
|
|
|
|
|
|
|
if (isr & LE_C0_TINT)
|
1997-05-06 01:05:32 +04:00
|
|
|
ledcontrol(0, 0, LED_LANXMT);
|
1996-01-03 00:56:21 +03:00
|
|
|
#endif /* USELEDS */
|
|
|
|
|
1996-05-07 04:57:58 +04:00
|
|
|
return (am7990_intr(sc));
|
1996-01-03 00:56:21 +03:00
|
|
|
}
|
1998-01-12 00:57:02 +03:00
|
|
|
|
|
|
|
hide void
|
|
|
|
le_copytobuf(sc, from, boff, len)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1998-01-12 00:57:02 +03:00
|
|
|
void *from;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
struct le_softc *lesc = (struct le_softc *)sc;
|
|
|
|
|
|
|
|
bus_space_write_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, from, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
hide void
|
|
|
|
le_copyfrombuf(sc, to, boff, len)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1998-01-12 00:57:02 +03:00
|
|
|
void *to;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
struct le_softc *lesc = (struct le_softc *)sc;
|
|
|
|
|
|
|
|
bus_space_read_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, to, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
hide void
|
|
|
|
le_zerobuf(sc, boff, len)
|
1998-07-21 21:36:01 +04:00
|
|
|
struct lance_softc *sc;
|
1998-01-12 00:57:02 +03:00
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
struct le_softc *lesc = (struct le_softc *)sc;
|
|
|
|
|
|
|
|
bus_space_set_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, 0, len);
|
|
|
|
}
|