2012-02-02 23:42:57 +04:00
|
|
|
/* $NetBSD: am7990.c,v 1.74 2012/02/02 19:43:02 tls Exp $ */
|
1997-10-05 22:26:38 +04:00
|
|
|
|
|
|
|
/*-
|
1998-08-15 14:51:16 +04:00
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
1997-10-05 22:26:38 +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.
|
1997-10-05 22:26:38 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
1995-06-28 06:24:50 +04: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.
|
|
|
|
*
|
|
|
|
* 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
|
1995-06-28 06:24:50 +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>
|
2012-02-02 23:42:57 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: am7990.c,v 1.74 2012/02/02 19:43:02 tls Exp $");
|
1996-05-07 05:38:35 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2005-02-27 03:26:58 +03:00
|
|
|
#include <sys/mbuf.h>
|
1996-05-07 05:38:35 +04:00
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
1995-06-28 06:24:50 +04:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
1997-10-10 05:09:03 +04:00
|
|
|
#include <sys/rnd.h>
|
1995-06-28 06:24:50 +04:00
|
|
|
|
1996-05-07 05:38:35 +04:00
|
|
|
#include <net/if.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
1997-03-17 06:14:03 +03:00
|
|
|
#include <net/if_media.h>
|
1996-05-07 05:38:35 +04:00
|
|
|
|
1995-06-28 06:24:50 +04:00
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
#include <dev/ic/lancereg.h>
|
|
|
|
#include <dev/ic/lancevar.h>
|
1996-05-07 05:38:35 +04:00
|
|
|
#include <dev/ic/am7990reg.h>
|
|
|
|
#include <dev/ic/am7990var.h>
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static void am7990_meminit(struct lance_softc *);
|
|
|
|
static void am7990_start(struct ifnet *);
|
1996-05-07 05:38:35 +04:00
|
|
|
|
2001-05-30 15:40:35 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1998-07-21 21:26:45 +04:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
#endif
|
1996-05-07 05:38:35 +04:00
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
#ifdef LEDEBUG
|
2004-08-24 04:53:28 +04:00
|
|
|
static void am7990_recv_print(struct lance_softc *, int);
|
|
|
|
static void am7990_xmit_print(struct lance_softc *, int);
|
1997-10-15 20:34:10 +04:00
|
|
|
#endif
|
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
#define ifp (&sc->sc_ethercom.ec_if)
|
|
|
|
|
1995-06-28 06:24:50 +04:00
|
|
|
void
|
2004-08-24 04:53:28 +04:00
|
|
|
am7990_config(struct am7990_softc *sc)
|
1995-06-28 06:24:50 +04:00
|
|
|
{
|
1997-03-10 00:12:39 +03:00
|
|
|
int mem, i;
|
1995-06-28 06:24:50 +04:00
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
sc->lsc.sc_meminit = am7990_meminit;
|
|
|
|
sc->lsc.sc_start = am7990_start;
|
1997-03-17 06:14:03 +03:00
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
lance_config(&sc->lsc);
|
1996-05-07 05:38:35 +04:00
|
|
|
|
1995-06-28 06:24:50 +04:00
|
|
|
mem = 0;
|
1998-07-21 21:26:45 +04:00
|
|
|
sc->lsc.sc_initaddr = mem;
|
1995-06-28 06:24:50 +04:00
|
|
|
mem += sizeof(struct leinit);
|
1998-07-21 21:26:45 +04:00
|
|
|
sc->lsc.sc_rmdaddr = mem;
|
|
|
|
mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf;
|
|
|
|
sc->lsc.sc_tmdaddr = mem;
|
|
|
|
mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf;
|
|
|
|
for (i = 0; i < sc->lsc.sc_nrbuf; i++, mem += LEBLEN)
|
|
|
|
sc->lsc.sc_rbufaddr[i] = mem;
|
|
|
|
for (i = 0; i < sc->lsc.sc_ntbuf; i++, mem += LEBLEN)
|
|
|
|
sc->lsc.sc_tbufaddr[i] = mem;
|
1995-06-28 06:24:50 +04:00
|
|
|
#ifdef notyet
|
|
|
|
if (mem > ...)
|
|
|
|
panic(...);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the initialization block and the descriptor rings.
|
|
|
|
*/
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
|
|
|
am7990_meminit(struct lance_softc *sc)
|
1995-06-28 06:24:50 +04:00
|
|
|
{
|
|
|
|
u_long a;
|
|
|
|
int bix;
|
|
|
|
struct leinit init;
|
|
|
|
struct lermd rmd;
|
|
|
|
struct letmd tmd;
|
2008-04-04 16:25:06 +04:00
|
|
|
uint8_t *myaddr;
|
1995-06-28 06:24:50 +04:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM;
|
|
|
|
else
|
|
|
|
init.init_mode = LE_MODE_NORMAL;
|
1997-03-28 00:01:47 +03:00
|
|
|
if (sc->sc_initmodemedia == 1)
|
|
|
|
init.init_mode |= LE_MODE_PSEL0;
|
1997-03-17 21:29:56 +03:00
|
|
|
|
1997-10-15 20:34:10 +04:00
|
|
|
/*
|
|
|
|
* Update our private copy of the Ethernet address.
|
|
|
|
* We NEED the copy so we can ensure its alignment!
|
|
|
|
*/
|
2007-08-27 02:36:35 +04:00
|
|
|
memcpy(sc->sc_enaddr, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
|
1997-10-15 20:34:10 +04:00
|
|
|
myaddr = sc->sc_enaddr;
|
|
|
|
|
1997-03-17 21:29:56 +03:00
|
|
|
init.init_padr[0] = (myaddr[1] << 8) | myaddr[0];
|
|
|
|
init.init_padr[1] = (myaddr[3] << 8) | myaddr[2];
|
|
|
|
init.init_padr[2] = (myaddr[5] << 8) | myaddr[4];
|
1998-07-21 21:26:45 +04:00
|
|
|
lance_setladrf(&sc->sc_ethercom, init.init_ladrf);
|
1995-06-28 06:24:50 +04:00
|
|
|
|
|
|
|
sc->sc_last_rd = 0;
|
|
|
|
sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0;
|
|
|
|
|
|
|
|
a = sc->sc_addr + LE_RMDADDR(sc, 0);
|
|
|
|
init.init_rdra = a;
|
|
|
|
init.init_rlen = (a >> 16) | ((ffs(sc->sc_nrbuf) - 1) << 13);
|
|
|
|
|
|
|
|
a = sc->sc_addr + LE_TMDADDR(sc, 0);
|
|
|
|
init.init_tdra = a;
|
|
|
|
init.init_tlen = (a >> 16) | ((ffs(sc->sc_ntbuf) - 1) << 13);
|
|
|
|
|
|
|
|
(*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up receive ring descriptors.
|
|
|
|
*/
|
|
|
|
for (bix = 0; bix < sc->sc_nrbuf; bix++) {
|
|
|
|
a = sc->sc_addr + LE_RBUFADDR(sc, bix);
|
|
|
|
rmd.rmd0 = a;
|
|
|
|
rmd.rmd1_hadr = a >> 16;
|
|
|
|
rmd.rmd1_bits = LE_R1_OWN;
|
|
|
|
rmd.rmd2 = -LEBLEN | LE_XMD2_ONES;
|
|
|
|
rmd.rmd3 = 0;
|
|
|
|
(*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix),
|
|
|
|
sizeof(rmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up transmit ring descriptors.
|
|
|
|
*/
|
|
|
|
for (bix = 0; bix < sc->sc_ntbuf; bix++) {
|
|
|
|
a = sc->sc_addr + LE_TBUFADDR(sc, bix);
|
|
|
|
tmd.tmd0 = a;
|
|
|
|
tmd.tmd1_hadr = a >> 16;
|
|
|
|
tmd.tmd1_bits = 0;
|
|
|
|
tmd.tmd2 = 0 | LE_XMD2_ONES;
|
|
|
|
tmd.tmd3 = 0;
|
|
|
|
(*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix),
|
|
|
|
sizeof(tmd));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
|
|
|
am7990_rint(struct lance_softc *sc)
|
1995-06-28 06:24:50 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
int bix;
|
1995-06-28 06:24:50 +04:00
|
|
|
int rp;
|
|
|
|
struct lermd rmd;
|
|
|
|
|
|
|
|
bix = sc->sc_last_rd;
|
|
|
|
|
|
|
|
/* Process all buffers with valid data. */
|
|
|
|
for (;;) {
|
|
|
|
rp = LE_RMDADDR(sc, bix);
|
|
|
|
(*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd));
|
|
|
|
|
|
|
|
if (rmd.rmd1_bits & LE_R1_OWN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (rmd.rmd1_bits & LE_R1_ERR) {
|
|
|
|
if (rmd.rmd1_bits & LE_R1_ENP) {
|
1995-12-11 05:21:56 +03:00
|
|
|
#ifdef LEDEBUG
|
1995-06-28 06:24:50 +04:00
|
|
|
if ((rmd.rmd1_bits & LE_R1_OFLO) == 0) {
|
|
|
|
if (rmd.rmd1_bits & LE_R1_FRAM)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: framing error\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev));
|
1995-06-28 06:24:50 +04:00
|
|
|
if (rmd.rmd1_bits & LE_R1_CRC)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: crc mismatch\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev));
|
1995-06-28 06:24:50 +04:00
|
|
|
}
|
1995-12-11 05:21:56 +03:00
|
|
|
#endif
|
1995-06-28 06:24:50 +04:00
|
|
|
} else {
|
|
|
|
if (rmd.rmd1_bits & LE_R1_OFLO)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: overflow\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev));
|
1995-06-28 06:24:50 +04:00
|
|
|
}
|
|
|
|
if (rmd.rmd1_bits & LE_R1_BUFF)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: receive buffer error\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev));
|
1995-12-11 05:30:44 +03:00
|
|
|
ifp->if_ierrors++;
|
1996-03-17 02:19:14 +03:00
|
|
|
} else if ((rmd.rmd1_bits & (LE_R1_STP | LE_R1_ENP)) !=
|
1995-06-28 06:24:50 +04:00
|
|
|
(LE_R1_STP | LE_R1_ENP)) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: dropping chained buffer\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev));
|
1995-12-11 05:30:44 +03:00
|
|
|
ifp->if_ierrors++;
|
1995-06-28 06:24:50 +04:00
|
|
|
} else {
|
|
|
|
#ifdef LEDEBUG
|
2000-04-16 21:03:42 +04:00
|
|
|
if (sc->sc_debug > 1)
|
1996-05-07 05:38:35 +04:00
|
|
|
am7990_recv_print(sc, sc->sc_last_rd);
|
1995-06-28 06:24:50 +04:00
|
|
|
#endif
|
1998-07-21 21:26:45 +04:00
|
|
|
lance_read(sc, LE_RBUFADDR(sc, bix),
|
|
|
|
(int)rmd.rmd3 - 4);
|
1995-06-28 06:24:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
rmd.rmd1_bits = LE_R1_OWN;
|
|
|
|
rmd.rmd2 = -LEBLEN | LE_XMD2_ONES;
|
|
|
|
rmd.rmd3 = 0;
|
|
|
|
(*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd));
|
|
|
|
|
|
|
|
#ifdef LEDEBUG
|
|
|
|
if (sc->sc_debug)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("sc->sc_last_rd = %x, rmd: "
|
1996-04-09 19:21:59 +04:00
|
|
|
"ladr %04x, hadr %02x, flags %02x, "
|
|
|
|
"bcnt %04x, mcnt %04x\n",
|
|
|
|
sc->sc_last_rd,
|
|
|
|
rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits,
|
|
|
|
rmd.rmd2, rmd.rmd3);
|
1995-06-28 06:24:50 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (++bix == sc->sc_nrbuf)
|
|
|
|
bix = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_last_rd = bix;
|
|
|
|
}
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
|
|
|
am7990_tint(struct lance_softc *sc)
|
1995-06-28 06:24:50 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
int bix;
|
1995-06-28 06:24:50 +04:00
|
|
|
struct letmd tmd;
|
|
|
|
|
|
|
|
bix = sc->sc_first_td;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (sc->sc_no_td <= 0)
|
|
|
|
break;
|
|
|
|
|
1998-07-07 18:13:51 +04:00
|
|
|
(*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix),
|
|
|
|
sizeof(tmd));
|
|
|
|
|
1995-06-28 06:24:50 +04:00
|
|
|
#ifdef LEDEBUG
|
|
|
|
if (sc->sc_debug)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("trans tmd: "
|
1996-10-11 02:18:34 +04:00
|
|
|
"ladr %04x, hadr %02x, flags %02x, "
|
|
|
|
"bcnt %04x, mcnt %04x\n",
|
|
|
|
tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits,
|
|
|
|
tmd.tmd2, tmd.tmd3);
|
1995-06-28 06:24:50 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (tmd.tmd1_bits & LE_T1_OWN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
if (tmd.tmd1_bits & LE_T1_ERR) {
|
|
|
|
if (tmd.tmd3 & LE_T3_BUFF)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: transmit buffer error\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev));
|
1995-06-28 06:24:50 +04:00
|
|
|
else if (tmd.tmd3 & LE_T3_UFLO)
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: underflow\n",
|
|
|
|
device_xname(sc->sc_dev));
|
1995-06-28 06:24:50 +04:00
|
|
|
if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) {
|
1998-07-24 17:41:52 +04:00
|
|
|
lance_reset(sc);
|
1995-06-28 06:24:50 +04:00
|
|
|
return;
|
|
|
|
}
|
1996-07-06 03:56:57 +04:00
|
|
|
if (tmd.tmd3 & LE_T3_LCAR) {
|
1997-03-17 06:14:03 +03:00
|
|
|
sc->sc_havecarrier = 0;
|
1996-07-06 03:56:57 +04:00
|
|
|
if (sc->sc_nocarrier)
|
|
|
|
(*sc->sc_nocarrier)(sc);
|
|
|
|
else
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: lost carrier\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev));
|
1996-07-06 03:56:57 +04:00
|
|
|
}
|
1995-06-28 06:24:50 +04:00
|
|
|
if (tmd.tmd3 & LE_T3_LCOL)
|
|
|
|
ifp->if_collisions++;
|
|
|
|
if (tmd.tmd3 & LE_T3_RTRY) {
|
1999-12-01 03:40:53 +03:00
|
|
|
#ifdef LEDEBUG
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: excessive collisions, tdr %d\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev),
|
1996-05-07 05:38:35 +04:00
|
|
|
tmd.tmd3 & LE_T3_TDR_MASK);
|
1999-12-01 03:40:53 +03:00
|
|
|
#endif
|
1995-06-28 06:24:50 +04:00
|
|
|
ifp->if_collisions += 16;
|
|
|
|
}
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
} else {
|
|
|
|
if (tmd.tmd1_bits & LE_T1_ONE)
|
|
|
|
ifp->if_collisions++;
|
|
|
|
else if (tmd.tmd1_bits & LE_T1_MORE)
|
|
|
|
/* Real number is unknown. */
|
|
|
|
ifp->if_collisions += 2;
|
|
|
|
ifp->if_opackets++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (++bix == sc->sc_ntbuf)
|
|
|
|
bix = 0;
|
|
|
|
|
|
|
|
--sc->sc_no_td;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_first_td = bix;
|
|
|
|
|
1996-05-07 05:38:35 +04:00
|
|
|
am7990_start(ifp);
|
1995-06-28 06:24:50 +04:00
|
|
|
|
|
|
|
if (sc->sc_no_td == 0)
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Controller interrupt.
|
|
|
|
*/
|
|
|
|
int
|
2004-08-24 04:53:28 +04:00
|
|
|
am7990_intr(void *arg)
|
1995-06-28 06:24:50 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct lance_softc *sc = arg;
|
2008-04-04 16:25:06 +04:00
|
|
|
uint16_t isr;
|
1995-06-28 06:24:50 +04:00
|
|
|
|
1997-03-10 00:12:39 +03:00
|
|
|
isr = (*sc->sc_rdcsr)(sc, LE_CSR0) | sc->sc_saved_csr0;
|
|
|
|
sc->sc_saved_csr0 = 0;
|
2000-09-24 22:37:22 +04:00
|
|
|
#if defined(LEDEBUG) && LEDEBUG > 1
|
1995-06-28 06:24:50 +04:00
|
|
|
if (sc->sc_debug)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: am7990_intr entering with isr=%04x\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev), isr);
|
1995-06-28 06:24:50 +04:00
|
|
|
#endif
|
|
|
|
if ((isr & LE_C0_INTR) == 0)
|
|
|
|
return (0);
|
|
|
|
|
1999-10-29 23:50:07 +04:00
|
|
|
#ifdef __vax__
|
|
|
|
/*
|
|
|
|
* DEC needs this write order to the registers, don't know
|
|
|
|
* the results on other arch's. Ragge 991029
|
|
|
|
*/
|
|
|
|
isr &= ~LE_C0_INEA;
|
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR0, isr);
|
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA);
|
|
|
|
#else
|
1996-05-07 05:38:35 +04:00
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR0,
|
1995-06-28 06:24:50 +04:00
|
|
|
isr & (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR |
|
|
|
|
LE_C0_RINT | LE_C0_TINT | LE_C0_IDON));
|
1999-10-29 23:50:07 +04:00
|
|
|
#endif
|
1995-06-28 06:24:50 +04:00
|
|
|
if (isr & LE_C0_ERR) {
|
|
|
|
if (isr & LE_C0_BABL) {
|
1995-12-11 05:21:56 +03:00
|
|
|
#ifdef LEDEBUG
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: babble\n", device_xname(sc->sc_dev));
|
1995-12-11 05:21:56 +03:00
|
|
|
#endif
|
1995-12-11 05:30:44 +03:00
|
|
|
ifp->if_oerrors++;
|
1995-06-28 06:24:50 +04:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
if (isr & LE_C0_CERR) {
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: collision error\n",
|
|
|
|
device_xname(sc->sc_dev));
|
1995-12-11 05:30:44 +03:00
|
|
|
ifp->if_collisions++;
|
1995-06-28 06:24:50 +04:00
|
|
|
}
|
|
|
|
#endif
|
1995-12-11 05:21:56 +03:00
|
|
|
if (isr & LE_C0_MISS) {
|
|
|
|
#ifdef LEDEBUG
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: missed packet\n", device_xname(sc->sc_dev));
|
1995-12-11 05:21:56 +03:00
|
|
|
#endif
|
1995-12-11 05:30:44 +03:00
|
|
|
ifp->if_ierrors++;
|
1995-12-11 05:21:56 +03:00
|
|
|
}
|
1995-06-28 06:24:50 +04:00
|
|
|
if (isr & LE_C0_MERR) {
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: memory error\n", device_xname(sc->sc_dev));
|
1998-07-21 21:26:45 +04:00
|
|
|
lance_reset(sc);
|
1995-06-28 06:24:50 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((isr & LE_C0_RXON) == 0) {
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: receiver disabled\n", device_xname(sc->sc_dev));
|
1995-12-11 05:30:44 +03:00
|
|
|
ifp->if_ierrors++;
|
1998-07-21 21:26:45 +04:00
|
|
|
lance_reset(sc);
|
1995-06-28 06:24:50 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if ((isr & LE_C0_TXON) == 0) {
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: transmitter disabled\n", device_xname(sc->sc_dev));
|
1995-12-11 05:30:44 +03:00
|
|
|
ifp->if_oerrors++;
|
1998-07-21 21:26:45 +04:00
|
|
|
lance_reset(sc);
|
1995-06-28 06:24:50 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1997-03-17 06:14:03 +03:00
|
|
|
/*
|
|
|
|
* Pretend we have carrier; if we don't this will be cleared
|
|
|
|
* shortly.
|
|
|
|
*/
|
|
|
|
sc->sc_havecarrier = 1;
|
|
|
|
|
1995-06-28 06:24:50 +04:00
|
|
|
if (isr & LE_C0_RINT)
|
1996-05-07 05:38:35 +04:00
|
|
|
am7990_rint(sc);
|
1995-06-28 06:24:50 +04:00
|
|
|
if (isr & LE_C0_TINT)
|
1996-05-07 05:38:35 +04:00
|
|
|
am7990_tint(sc);
|
1995-06-28 06:24:50 +04:00
|
|
|
|
1997-10-10 05:09:03 +04:00
|
|
|
rnd_add_uint32(&sc->rnd_source, isr);
|
|
|
|
|
1995-06-28 06:24:50 +04:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
#undef ifp
|
1997-03-17 06:14:03 +03:00
|
|
|
|
1995-06-28 06:24:50 +04:00
|
|
|
/*
|
|
|
|
* Setup output on interface.
|
|
|
|
* Get another datagram to send off of the interface queue, and map it to the
|
|
|
|
* interface before starting the output.
|
1998-08-09 03:51:39 +04:00
|
|
|
* Called only at splnet or interrupt level.
|
1995-06-28 06:24:50 +04:00
|
|
|
*/
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
|
|
|
am7990_start(struct ifnet *ifp)
|
1995-06-28 06:24:50 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct lance_softc *sc = ifp->if_softc;
|
|
|
|
int bix;
|
|
|
|
struct mbuf *m;
|
1995-06-28 06:24:50 +04:00
|
|
|
struct letmd tmd;
|
|
|
|
int rp;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bix = sc->sc_last_td;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
rp = LE_TMDADDR(sc, bix);
|
|
|
|
(*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd));
|
|
|
|
|
|
|
|
if (tmd.tmd1_bits & LE_T1_OWN) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("missing buffer, no_td = %d, last_td = %d\n",
|
1995-06-28 06:24:50 +04:00
|
|
|
sc->sc_no_td, sc->sc_last_td);
|
|
|
|
}
|
|
|
|
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m);
|
1995-06-28 06:24:50 +04:00
|
|
|
if (m == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If BPF is listening on this interface, let it see the packet
|
|
|
|
* before we commit it to the wire.
|
|
|
|
*/
|
2010-04-05 11:19:28 +04:00
|
|
|
bpf_mtap(ifp, m);
|
1995-06-28 06:24:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the mbuf chain into the transmit buffer.
|
|
|
|
*/
|
1998-07-21 21:26:45 +04:00
|
|
|
len = lance_put(sc, LE_TBUFADDR(sc, bix), m);
|
1995-06-28 06:24:50 +04:00
|
|
|
|
|
|
|
#ifdef LEDEBUG
|
1995-07-24 08:34:51 +04:00
|
|
|
if (len > ETHERMTU + sizeof(struct ether_header))
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("packet length %d\n", len);
|
1995-06-28 06:24:50 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
ifp->if_timer = 5;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init transmit registers, and set transmit start flag.
|
|
|
|
*/
|
|
|
|
tmd.tmd1_bits = LE_T1_OWN | LE_T1_STP | LE_T1_ENP;
|
|
|
|
tmd.tmd2 = -len | LE_XMD2_ONES;
|
|
|
|
tmd.tmd3 = 0;
|
|
|
|
|
|
|
|
(*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd));
|
|
|
|
|
|
|
|
#ifdef LEDEBUG
|
2000-04-16 21:03:42 +04:00
|
|
|
if (sc->sc_debug > 1)
|
1996-05-07 05:38:35 +04:00
|
|
|
am7990_xmit_print(sc, sc->sc_last_td);
|
1995-06-28 06:24:50 +04:00
|
|
|
#endif
|
|
|
|
|
1996-05-07 05:38:35 +04:00
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD);
|
1995-06-28 06:24:50 +04:00
|
|
|
|
|
|
|
if (++bix == sc->sc_ntbuf)
|
|
|
|
bix = 0;
|
|
|
|
|
|
|
|
if (++sc->sc_no_td == sc->sc_ntbuf) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_last_td = bix;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef LEDEBUG
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
|
|
|
am7990_recv_print(struct lance_softc *sc, int no)
|
1995-06-28 06:24:50 +04:00
|
|
|
{
|
|
|
|
struct lermd rmd;
|
2008-04-04 16:25:06 +04:00
|
|
|
uint16_t len;
|
1995-06-28 06:24:50 +04:00
|
|
|
struct ether_header eh;
|
|
|
|
|
|
|
|
(*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd));
|
|
|
|
len = rmd.rmd3;
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: receive buffer %d, len = %d\n",
|
|
|
|
device_xname(sc->sc_dev), no, len);
|
|
|
|
printf("%s: status %04x\n", device_xname(sc->sc_dev),
|
1996-05-07 05:38:35 +04:00
|
|
|
(*sc->sc_rdcsr)(sc, LE_CSR0));
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev),
|
1995-06-28 06:24:50 +04:00
|
|
|
rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3);
|
|
|
|
if (len >= sizeof(eh)) {
|
|
|
|
(*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh));
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: dst %s", device_xname(sc->sc_dev),
|
1996-04-09 19:21:59 +04:00
|
|
|
ether_sprintf(eh.ether_dhost));
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
|
1996-04-09 19:21:59 +04:00
|
|
|
ntohs(eh.ether_type));
|
1995-06-28 06:24:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-24 04:53:28 +04:00
|
|
|
static void
|
|
|
|
am7990_xmit_print(struct lance_softc *sc, int no)
|
1995-06-28 06:24:50 +04:00
|
|
|
{
|
|
|
|
struct letmd tmd;
|
2008-04-04 16:25:06 +04:00
|
|
|
uint16_t len;
|
1995-06-28 06:24:50 +04:00
|
|
|
struct ether_header eh;
|
|
|
|
|
|
|
|
(*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd));
|
|
|
|
len = -tmd.tmd2;
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: transmit buffer %d, len = %d\n",
|
|
|
|
device_xname(sc->sc_dev), no, len);
|
|
|
|
printf("%s: status %04x\n", device_xname(sc->sc_dev),
|
1996-05-07 05:38:35 +04:00
|
|
|
(*sc->sc_rdcsr)(sc, LE_CSR0));
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",
|
2008-04-04 16:25:06 +04:00
|
|
|
device_xname(sc->sc_dev),
|
1995-06-28 06:24:50 +04:00
|
|
|
tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, tmd.tmd2, tmd.tmd3);
|
|
|
|
if (len >= sizeof(eh)) {
|
|
|
|
(*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh));
|
2008-04-04 16:25:06 +04:00
|
|
|
printf("%s: dst %s", device_xname(sc->sc_dev),
|
1996-04-09 19:21:59 +04:00
|
|
|
ether_sprintf(eh.ether_dhost));
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
|
1995-06-28 06:24:50 +04:00
|
|
|
ntohs(eh.ether_type));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* LEDEBUG */
|