2001-04-06 04:02:49 +04:00
|
|
|
/* $NetBSD: seeq8005.c,v 1.22 2001/04/06 00:02:49 bjh21 Exp $ */
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 Ben Harris
|
2001-03-24 23:38:41 +03:00
|
|
|
* Copyright (c) 1995-1998 Mark Brinicombe
|
2000-09-19 00:51:14 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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:
|
2001-03-24 23:38:41 +03:00
|
|
|
* This product includes software developed by Mark Brinicombe
|
|
|
|
* for the NetBSD Project.
|
2000-09-19 00:51:14 +04:00
|
|
|
* 4. The name of the company nor the name of the author may be used to
|
|
|
|
* endorse or promote products derived from this software without specific
|
|
|
|
* prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
/*
|
2000-09-22 02:20:38 +04:00
|
|
|
* seeq8005.c - SEEQ 8005 device driver
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This driver currently supports the following chip:
|
|
|
|
* SEEQ 8005 Advanced Ethernet Data Link Controller
|
2001-04-03 02:25:17 +04:00
|
|
|
* SEEQ 80C04 Ethernet Data Link Controller
|
|
|
|
* SEEQ 80C04A AutoDUPLEX CMOS Ethernet Data Link Controller
|
2000-09-22 02:20:38 +04:00
|
|
|
*/
|
2001-03-24 23:38:41 +03:00
|
|
|
/*
|
|
|
|
* More information on the 8004 and 8005 AEDLC controllers can be found in
|
|
|
|
* the SEEQ Technology Inc 1992 Data Comm Devices data book.
|
|
|
|
*
|
|
|
|
* This data book may no longer be available as these are rather old chips
|
|
|
|
* (1991 - 1993)
|
|
|
|
*/
|
2000-09-22 02:20:38 +04:00
|
|
|
/*
|
|
|
|
* This driver is based on the arm32 ea(4) driver, hence the names of many
|
|
|
|
* of the functions.
|
2000-09-19 00:51:14 +04:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Bugs/possible improvements:
|
|
|
|
* - Does not currently support DMA
|
|
|
|
* - Does not transmit multiple packets in one go
|
|
|
|
* - Does not support 8-bit busses
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_ns.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
2001-04-06 04:02:49 +04:00
|
|
|
__RCSID("$NetBSD: seeq8005.c,v 1.22 2001/04/06 00:02:49 bjh21 Exp $");
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_ether.h>
|
2001-03-24 23:38:41 +03:00
|
|
|
#include <net/if_media.h>
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/if_inarp.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "bpfilter.h"
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/ic/seeq8005reg.h>
|
|
|
|
#include <dev/ic/seeq8005var.h>
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
/*#define SEEQ_DEBUG*/
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* for debugging convenience */
|
2001-03-28 01:43:13 +04:00
|
|
|
#ifdef SEEQ8005_DEBUG
|
2001-03-24 23:38:41 +03:00
|
|
|
#define SEEQ_DEBUG_MISC 1
|
|
|
|
#define SEEQ_DEBUG_TX 2
|
|
|
|
#define SEEQ_DEBUG_RX 4
|
|
|
|
#define SEEQ_DEBUG_PKT 8
|
|
|
|
#define SEEQ_DEBUG_TXINT 16
|
|
|
|
#define SEEQ_DEBUG_RXINT 32
|
2001-03-28 01:43:13 +04:00
|
|
|
int seeq8005_debug = 0;
|
|
|
|
#define DPRINTF(f, x) { if (seeq8005_debug & (f)) printf x; }
|
2000-09-19 00:51:14 +04:00
|
|
|
#else
|
2001-03-24 23:38:41 +03:00
|
|
|
#define DPRINTF(f, x)
|
2000-09-19 00:51:14 +04:00
|
|
|
#endif
|
2001-03-24 23:38:41 +03:00
|
|
|
|
2001-03-25 03:31:06 +04:00
|
|
|
#define SEEQ_TX_BUFFER_SIZE 0x800 /* (> MAX_ETHER_LEN) */
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes
|
|
|
|
*/
|
|
|
|
|
2000-11-03 03:25:36 +03:00
|
|
|
static int ea_init(struct ifnet *);
|
2000-09-19 00:51:14 +04:00
|
|
|
static int ea_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static void ea_start(struct ifnet *);
|
|
|
|
static void ea_watchdog(struct ifnet *);
|
|
|
|
static void ea_chipreset(struct seeq8005_softc *);
|
|
|
|
static void ea_ramtest(struct seeq8005_softc *);
|
|
|
|
static int ea_stoptx(struct seeq8005_softc *);
|
|
|
|
static int ea_stoprx(struct seeq8005_softc *);
|
2000-11-03 03:25:36 +03:00
|
|
|
static void ea_stop(struct ifnet *, int);
|
2000-09-19 00:51:14 +04:00
|
|
|
static void ea_await_fifo_empty(struct seeq8005_softc *);
|
|
|
|
static void ea_await_fifo_full(struct seeq8005_softc *);
|
2001-03-24 23:38:41 +03:00
|
|
|
static void ea_writebuf(struct seeq8005_softc *, u_char *, int, size_t);
|
|
|
|
static void ea_readbuf(struct seeq8005_softc *, u_char *, int, size_t);
|
2000-09-23 19:13:02 +04:00
|
|
|
static void ea_select_buffer(struct seeq8005_softc *, int);
|
2000-11-03 03:25:36 +03:00
|
|
|
static void ea_set_address(struct seeq8005_softc *, int, const u_int8_t *);
|
2001-03-24 23:38:41 +03:00
|
|
|
static void ea_read(struct seeq8005_softc *, int, int);
|
|
|
|
static struct mbuf *ea_get(struct seeq8005_softc *, int, int, struct ifnet *);
|
2001-04-03 02:25:17 +04:00
|
|
|
static void ea_txint(struct seeq8005_softc *);
|
|
|
|
static void ea_rxint(struct seeq8005_softc *);
|
2000-09-19 00:51:14 +04:00
|
|
|
static void eatxpacket(struct seeq8005_softc *);
|
2001-03-25 03:31:06 +04:00
|
|
|
static int ea_writembuf(struct seeq8005_softc *, struct mbuf *, int);
|
2000-11-03 03:25:36 +03:00
|
|
|
static void ea_mc_reset(struct seeq8005_softc *);
|
2001-03-24 23:38:41 +03:00
|
|
|
static void ea_mc_reset_8004(struct seeq8005_softc *);
|
|
|
|
static void ea_mc_reset_8005(struct seeq8005_softc *);
|
|
|
|
static int ea_mediachange(struct ifnet *);
|
|
|
|
static void ea_mediastatus(struct ifnet *, struct ifmediareq *);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach chip.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2001-03-24 23:38:41 +03:00
|
|
|
seeq8005_attach(struct seeq8005_softc *sc, const u_int8_t *myaddr, int *media,
|
|
|
|
int nmedia, int defmedia)
|
2000-09-19 00:51:14 +04:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
2000-09-22 02:20:38 +04:00
|
|
|
u_int id;
|
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
KASSERT(myaddr != NULL);
|
2000-09-22 02:20:38 +04:00
|
|
|
printf(" address %s", ether_sprintf(myaddr));
|
|
|
|
|
2000-09-23 19:13:02 +04:00
|
|
|
/* Stop the board. */
|
|
|
|
|
|
|
|
ea_chipreset(sc);
|
|
|
|
|
2000-09-22 02:20:38 +04:00
|
|
|
/* Get the product ID */
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_PRODUCTID);
|
|
|
|
id = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SEEQ_BUFWIN);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
switch (id & SEEQ_PRODUCTID_MASK) {
|
|
|
|
case SEEQ_PRODUCTID_8004:
|
|
|
|
sc->sc_variant = SEEQ_8004;
|
2001-04-03 02:25:17 +04:00
|
|
|
switch (id & SEEQ_PRODUCTID_REV_MASK) {
|
|
|
|
case SEEQ_PRODUCTID_REV_80C04:
|
|
|
|
printf(", SEEQ 80C04\n");
|
|
|
|
break;
|
|
|
|
case SEEQ_PRODUCTID_REV_80C04A:
|
|
|
|
printf(", SEEQ 80C04A\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Unknown SEEQ 8004 variants */
|
|
|
|
printf(", SEEQ 8004 rev %x\n",
|
|
|
|
id & SEEQ_PRODUCTID_REV_MASK);
|
|
|
|
break;
|
|
|
|
}
|
2001-03-24 23:38:41 +03:00
|
|
|
break;
|
|
|
|
default: /* XXX */
|
|
|
|
sc->sc_variant = SEEQ_8005;
|
2001-04-03 02:25:17 +04:00
|
|
|
printf(", SEEQ 8005\n");
|
2001-03-24 23:38:41 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Both the 8004 and 8005 are designed for 64K Buffer memory */
|
|
|
|
sc->sc_buffersize = SEEQ_MAX_BUFFER_SIZE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up tx and rx buffers.
|
|
|
|
*
|
2001-03-25 03:31:06 +04:00
|
|
|
* We use approximately a quarter of the packet memory for TX
|
2001-03-24 23:38:41 +03:00
|
|
|
* buffers and the rest for RX buffers
|
|
|
|
*/
|
2001-03-25 03:31:06 +04:00
|
|
|
/* sc->sc_tx_bufs = sc->sc_buffersize / SEEQ_TX_BUFFER_SIZE / 4; */
|
|
|
|
sc->sc_tx_bufs = 1;
|
2001-03-24 23:38:41 +03:00
|
|
|
sc->sc_tx_bufsize = sc->sc_tx_bufs * SEEQ_TX_BUFFER_SIZE;
|
|
|
|
sc->sc_rx_bufsize = sc->sc_buffersize - sc->sc_tx_bufsize;
|
|
|
|
sc->sc_enabled = 0;
|
|
|
|
|
|
|
|
/* Test the RAM */
|
|
|
|
ea_ramtest(sc);
|
|
|
|
|
|
|
|
printf("%s: %dKB packet memory, txbuf=%dKB (%d buffers), rxbuf=%dKB",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_buffersize >> 10,
|
|
|
|
sc->sc_tx_bufsize >> 10, sc->sc_tx_bufs, sc->sc_rx_bufsize >> 10);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Initialise ifnet structure. */
|
|
|
|
|
|
|
|
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
|
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_start = ea_start;
|
|
|
|
ifp->if_ioctl = ea_ioctl;
|
2000-11-03 03:25:36 +03:00
|
|
|
ifp->if_init = ea_init;
|
|
|
|
ifp->if_stop = ea_stop;
|
2000-09-19 00:51:14 +04:00
|
|
|
ifp->if_watchdog = ea_watchdog;
|
2000-11-03 03:25:36 +03:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_MULTICAST | IFF_NOTRAILERS;
|
2001-03-24 23:38:41 +03:00
|
|
|
if (sc->sc_variant == SEEQ_8004)
|
|
|
|
ifp->if_flags |= IFF_SIMPLEX;
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
/* Initialize media goo. */
|
|
|
|
ifmedia_init(&sc->sc_media, 0, ea_mediachange, ea_mediastatus);
|
|
|
|
if (media != NULL) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nmedia; i++)
|
|
|
|
ifmedia_add(&sc->sc_media, media[i], 0, NULL);
|
|
|
|
ifmedia_set(&sc->sc_media, defmedia);
|
|
|
|
} else {
|
|
|
|
ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
|
|
|
|
ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
|
|
|
|
}
|
|
|
|
|
2000-09-19 00:51:14 +04:00
|
|
|
/* Now we can attach the interface. */
|
|
|
|
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, myaddr);
|
|
|
|
|
2000-12-23 19:37:20 +03:00
|
|
|
printf("\n");
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
/*
|
|
|
|
* Media change callback.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ea_mediachange(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct seeq8005_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
if (sc->sc_mediachange)
|
|
|
|
return ((*sc->sc_mediachange)(sc));
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Media status callback.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ea_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
|
|
|
|
{
|
|
|
|
struct seeq8005_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
if (sc->sc_enabled == 0) {
|
|
|
|
ifmr->ifm_active = IFM_ETHER | IFM_NONE;
|
|
|
|
ifmr->ifm_status = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_mediastatus)
|
|
|
|
(*sc->sc_mediastatus)(sc, ifmr);
|
|
|
|
}
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the RAM on the ethernet card.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
ea_ramtest(struct seeq8005_softc *sc)
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
int loop;
|
|
|
|
u_int sum = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test the buffer memory on the board.
|
|
|
|
* Write simple pattens to it and read them back.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Set up the whole buffer RAM for writing */
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_TX_EAP);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_BUFWIN, (SEEQ_MAX_BUFFER_SIZE >> 8) - 1);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_TX_PTR, 0x0000);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_RX_PTR, SEEQ_MAX_BUFFER_SIZE - 2);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
#define SEEQ_RAMTEST_LOOP(value) \
|
2000-09-23 19:13:02 +04:00
|
|
|
do { \
|
|
|
|
/* Set the write start address and write a pattern */ \
|
|
|
|
ea_writebuf(sc, NULL, 0x0000, 0); \
|
2001-03-24 16:40:41 +03:00
|
|
|
for (loop = 0; loop < SEEQ_MAX_BUFFER_SIZE; loop += 2) \
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_BUFWIN, (value)); \
|
2000-09-23 19:13:02 +04:00
|
|
|
\
|
|
|
|
/* Set the read start address and verify the pattern */ \
|
|
|
|
ea_readbuf(sc, NULL, 0x0000, 0); \
|
2001-03-24 16:40:41 +03:00
|
|
|
for (loop = 0; loop < SEEQ_MAX_BUFFER_SIZE; loop += 2) \
|
|
|
|
if (bus_space_read_2(iot, ioh, SEEQ_BUFWIN) != (value)) \
|
2000-09-23 19:13:02 +04:00
|
|
|
++sum; \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
SEEQ_RAMTEST_LOOP(loop);
|
|
|
|
SEEQ_RAMTEST_LOOP(loop ^ (SEEQ_MAX_BUFFER_SIZE - 1));
|
|
|
|
SEEQ_RAMTEST_LOOP(0xaa55);
|
|
|
|
SEEQ_RAMTEST_LOOP(0x55aa);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Report */
|
|
|
|
|
2000-09-22 02:20:38 +04:00
|
|
|
if (sum > 0)
|
|
|
|
printf("%s: buffer RAM failed self test, %d faults\n",
|
|
|
|
sc->sc_dev.dv_xname, sum);
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the tx interface.
|
|
|
|
*
|
|
|
|
* Returns 0 if the tx was already stopped or 1 if it was active
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
ea_stoptx(struct seeq8005_softc *sc)
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
int timeout;
|
|
|
|
int status;
|
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_TX, ("ea_stoptx()\n"));
|
2001-03-24 23:38:41 +03:00
|
|
|
|
|
|
|
sc->sc_enabled = 0;
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
status = bus_space_read_2(iot, ioh, SEEQ_STATUS);
|
|
|
|
if (!(status & SEEQ_STATUS_TX_ON))
|
2000-09-19 00:51:14 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Stop any tx and wait for confirmation */
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_TX_OFF);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
timeout = 20000;
|
|
|
|
do {
|
2001-03-24 16:40:41 +03:00
|
|
|
status = bus_space_read_2(iot, ioh, SEEQ_STATUS);
|
2001-03-24 23:38:41 +03:00
|
|
|
delay(1);
|
2001-03-24 16:40:41 +03:00
|
|
|
} while ((status & SEEQ_STATUS_TX_ON) && --timeout > 0);
|
2001-03-24 23:38:41 +03:00
|
|
|
if (timeout == 0)
|
|
|
|
log(LOG_ERR, "%s: timeout waiting for tx termination\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Clear any pending tx interrupt */
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_TX_INTACK);
|
2000-09-19 00:51:14 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the rx interface.
|
|
|
|
*
|
|
|
|
* Returns 0 if the tx was already stopped or 1 if it was active
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
ea_stoprx(struct seeq8005_softc *sc)
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
int timeout;
|
|
|
|
int status;
|
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_RX, ("ea_stoprx()\n"));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
status = bus_space_read_2(iot, ioh, SEEQ_STATUS);
|
|
|
|
if (!(status & SEEQ_STATUS_RX_ON))
|
2000-09-19 00:51:14 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Stop any rx and wait for confirmation */
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_RX_OFF);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
timeout = 20000;
|
|
|
|
do {
|
2001-03-24 16:40:41 +03:00
|
|
|
status = bus_space_read_2(iot, ioh, SEEQ_STATUS);
|
|
|
|
} while ((status & SEEQ_STATUS_RX_ON) && --timeout > 0);
|
2000-09-19 00:51:14 +04:00
|
|
|
if (timeout == 0)
|
2001-03-24 23:38:41 +03:00
|
|
|
log(LOG_ERR, "%s: timeout waiting for rx termination\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Clear any pending rx interrupt */
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_RX_INTACK);
|
2000-09-19 00:51:14 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop interface.
|
|
|
|
* Stop all IO and shut the interface down
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2000-11-03 03:25:36 +03:00
|
|
|
ea_stop(struct ifnet *ifp, int disable)
|
2000-09-19 00:51:14 +04:00
|
|
|
{
|
2000-11-03 03:25:36 +03:00
|
|
|
struct seeq8005_softc *sc = ifp->if_softc;
|
2000-09-19 00:51:14 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_MISC, ("ea_stop()\n"));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Stop all IO */
|
|
|
|
ea_stoptx(sc);
|
|
|
|
ea_stoprx(sc);
|
|
|
|
|
|
|
|
/* Disable rx and tx interrupts */
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_command &= (SEEQ_CMD_RX_INTEN | SEEQ_CMD_TX_INTEN);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Clear any pending interrupts */
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_RX_INTACK |
|
|
|
|
SEEQ_CMD_TX_INTACK | SEEQ_CMD_DMA_INTACK |
|
|
|
|
SEEQ_CMD_BW_INTACK);
|
2001-03-24 23:38:41 +03:00
|
|
|
|
|
|
|
if (sc->sc_variant == SEEQ_8004) {
|
|
|
|
/* Put the chip to sleep */
|
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_CONFIG3);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_BUFWIN,
|
|
|
|
sc->sc_config3 | SEEQ_CFG3_SLEEP);
|
|
|
|
}
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Cancel any watchdog timer */
|
|
|
|
sc->sc_ethercom.ec_if.if_timer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the chip
|
|
|
|
* Following this the software registers are reset
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
ea_chipreset(struct seeq8005_softc *sc)
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_MISC, ("ea_chipreset()\n"));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Reset the controller. Min of 4us delay here */
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG2, SEEQ_CFG2_RESET);
|
2000-09-23 19:13:02 +04:00
|
|
|
delay(4);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
sc->sc_command = 0;
|
|
|
|
sc->sc_config1 = 0;
|
|
|
|
sc->sc_config2 = 0;
|
2001-03-24 23:38:41 +03:00
|
|
|
sc->sc_config3 = 0;
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the DMA FIFO's in write mode, wait for it to empty. Needed when
|
|
|
|
* switching the FIFO from write to read. We also use it when changing
|
|
|
|
* the address for writes.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ea_await_fifo_empty(struct seeq8005_softc *sc)
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
int timeout;
|
|
|
|
|
|
|
|
timeout = 20000;
|
2001-03-24 16:40:41 +03:00
|
|
|
if ((bus_space_read_2(iot, ioh, SEEQ_STATUS) &
|
|
|
|
SEEQ_STATUS_FIFO_DIR) != 0)
|
2000-09-19 00:51:14 +04:00
|
|
|
return; /* FIFO is reading anyway. */
|
2001-03-29 21:46:39 +04:00
|
|
|
while (--timeout > 0)
|
|
|
|
if (bus_space_read_2(iot, ioh, SEEQ_STATUS) &
|
|
|
|
SEEQ_STATUS_FIFO_EMPTY)
|
|
|
|
return;
|
|
|
|
log(LOG_ERR, "%s: DMA FIFO failed to empty\n", sc->sc_dev.dv_xname);
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the DMA FIFO to fill before reading from it.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ea_await_fifo_full(struct seeq8005_softc *sc)
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
int timeout;
|
|
|
|
|
|
|
|
timeout = 20000;
|
2001-03-29 21:46:39 +04:00
|
|
|
while (--timeout > 0)
|
|
|
|
if (bus_space_read_2(iot, ioh, SEEQ_STATUS) &
|
|
|
|
SEEQ_STATUS_FIFO_FULL)
|
|
|
|
return;
|
|
|
|
log(LOG_ERR, "%s: DMA FIFO failed to fill\n", sc->sc_dev.dv_xname);
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* write to the buffer memory on the interface
|
|
|
|
*
|
|
|
|
* The buffer address is set to ADDR.
|
|
|
|
* If len != 0 then data is copied from the address starting at buf
|
|
|
|
* to the interface buffer.
|
|
|
|
* BUF must be usable as a u_int16_t *.
|
|
|
|
* If LEN is odd, it must be safe to overwrite one extra byte.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_writebuf(struct seeq8005_softc *sc, u_char *buf, int addr, size_t len)
|
2000-09-19 00:51:14 +04:00
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_MISC, ("writebuf: st=%04x\n",
|
|
|
|
bus_space_read_2(iot, ioh, SEEQ_STATUS)));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (__predict_false(!ALIGNED_POINTER(buf, u_int16_t)))
|
|
|
|
panic("%s: unaligned writebuf", sc->sc_dev.dv_xname);
|
2001-03-24 16:40:41 +03:00
|
|
|
if (__predict_false(addr >= SEEQ_MAX_BUFFER_SIZE))
|
2000-09-19 00:51:14 +04:00
|
|
|
panic("%s: writebuf out of range", sc->sc_dev.dv_xname);
|
2001-03-27 22:03:04 +04:00
|
|
|
#endif
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Assume that copying too much is safe. */
|
|
|
|
if (len % 2 != 0)
|
|
|
|
len++;
|
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
if (addr != -1) {
|
|
|
|
ea_await_fifo_empty(sc);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_LOCAL_MEM);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_FIFO_WRITE);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_DMA_ADDR, addr);
|
|
|
|
}
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
if (len > 0)
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_multi_2(iot, ioh, SEEQ_BUFWIN,
|
2000-09-19 00:51:14 +04:00
|
|
|
(u_int16_t *)buf, len / 2);
|
|
|
|
/* Leave FIFO to empty in the background */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read from the buffer memory on the interface
|
|
|
|
*
|
|
|
|
* The buffer address is set to ADDR.
|
|
|
|
* If len != 0 then data is copied from the interface buffer to the
|
|
|
|
* address starting at buf.
|
|
|
|
* BUF must be usable as a u_int16_t *.
|
|
|
|
* If LEN is odd, it must be safe to overwrite one extra byte.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_readbuf(struct seeq8005_softc *sc, u_char *buf, int addr, size_t len)
|
2000-09-19 00:51:14 +04:00
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2001-03-30 00:49:44 +04:00
|
|
|
int runup;
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_MISC, ("readbuf: st=%04x addr=%04x len=%d\n",
|
|
|
|
bus_space_read_2(iot, ioh, SEEQ_STATUS), addr, len));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
2001-03-27 22:03:04 +04:00
|
|
|
if (__predict_false(!ALIGNED_POINTER(buf, u_int16_t)))
|
2000-09-19 00:51:14 +04:00
|
|
|
panic("%s: unaligned readbuf", sc->sc_dev.dv_xname);
|
2001-03-27 22:03:04 +04:00
|
|
|
if (__predict_false(addr >= SEEQ_MAX_BUFFER_SIZE))
|
|
|
|
panic("%s: readbuf out of range", sc->sc_dev.dv_xname);
|
2000-09-19 00:51:14 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Assume that copying too much is safe. */
|
|
|
|
if (len % 2 != 0)
|
|
|
|
len++;
|
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
if (addr != -1) {
|
2001-03-30 00:49:44 +04:00
|
|
|
/*
|
|
|
|
* SEEQ 80C04 bug:
|
|
|
|
* Starting reading from certain addresses seems to cause
|
|
|
|
* us to get bogus results, so we avoid them.
|
|
|
|
*/
|
|
|
|
runup = 0;
|
|
|
|
if (sc->sc_variant == SEEQ_8004 &&
|
|
|
|
((addr & 0x00ff) == 0x00ea ||
|
|
|
|
(addr & 0x00ff) == 0x00ee ||
|
|
|
|
(addr & 0x00ff) == 0x00f0))
|
|
|
|
runup = (addr & 0x00ff) - 0x00e8;
|
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_await_fifo_empty(sc);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_LOCAL_MEM);
|
2001-04-06 02:55:46 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 80C04 bug workaround. I found this in the old arm32 "eb"
|
|
|
|
* driver. I've no idea what it does, but it seems to stop
|
|
|
|
* the chip mangling data so often.
|
|
|
|
*/
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_FIFO_WRITE);
|
|
|
|
ea_await_fifo_empty(sc);
|
|
|
|
|
2001-03-30 00:49:44 +04:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_DMA_ADDR, addr - runup);
|
2001-03-24 23:38:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_FIFO_READ);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_await_fifo_full(sc);
|
2001-03-30 00:49:44 +04:00
|
|
|
while (runup > 0) {
|
|
|
|
(void)bus_space_read_2(iot, ioh, SEEQ_BUFWIN);
|
|
|
|
runup -= 2;
|
|
|
|
}
|
2001-03-24 23:38:41 +03:00
|
|
|
}
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
if (len > 0)
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_read_multi_2(iot, ioh, SEEQ_BUFWIN,
|
2000-09-19 00:51:14 +04:00
|
|
|
(u_int16_t *)buf, len / 2);
|
|
|
|
}
|
|
|
|
|
2000-09-23 19:13:02 +04:00
|
|
|
static void
|
|
|
|
ea_select_buffer(struct seeq8005_softc *sc, int bufcode)
|
|
|
|
{
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh, SEEQ_CONFIG1,
|
2000-09-23 19:13:02 +04:00
|
|
|
sc->sc_config1 | bufcode);
|
|
|
|
}
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2000-11-03 03:25:36 +03:00
|
|
|
/* Must be called at splnet */
|
|
|
|
static void
|
|
|
|
ea_set_address(struct seeq8005_softc *sc, int which, u_int8_t const *ea)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_STATION_ADDR0 + which);
|
2000-11-03 03:25:36 +03:00
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; ++i)
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh, SEEQ_BUFWIN,
|
2000-11-03 03:25:36 +03:00
|
|
|
ea[i]);
|
|
|
|
}
|
|
|
|
|
2000-09-19 00:51:14 +04:00
|
|
|
/*
|
|
|
|
* Initialize interface.
|
|
|
|
*
|
|
|
|
* This should leave the interface in a state for packet reception and
|
|
|
|
* transmission.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
2000-11-03 03:25:36 +03:00
|
|
|
ea_init(struct ifnet *ifp)
|
2000-09-19 00:51:14 +04:00
|
|
|
{
|
2000-11-03 03:25:36 +03:00
|
|
|
struct seeq8005_softc *sc = ifp->if_softc;
|
2000-09-19 00:51:14 +04:00
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2000-11-03 03:25:36 +03:00
|
|
|
int s;
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_MISC, ("ea_init()\n"));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
|
|
|
|
/* First, reset the board. */
|
|
|
|
|
2000-09-23 19:13:02 +04:00
|
|
|
ea_chipreset(sc);
|
|
|
|
|
|
|
|
/* Set up defaults for the registers */
|
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
sc->sc_command = 0;
|
|
|
|
sc->sc_config1 = 0;
|
2000-09-23 19:13:02 +04:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2001-03-24 23:38:41 +03:00
|
|
|
sc->sc_config2 = SEEQ_CFG2_BYTESWAP;
|
2000-09-23 19:13:02 +04:00
|
|
|
#else
|
|
|
|
sc->sc_config2 = 0;
|
|
|
|
#endif
|
2001-03-24 23:38:41 +03:00
|
|
|
sc->sc_config3 = 0;
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND, sc->sc_command);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG1, sc->sc_config1);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
|
2001-03-24 23:38:41 +03:00
|
|
|
if (sc->sc_variant == SEEQ_8004) {
|
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_CONFIG3);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_BUFWIN, sc->sc_config3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the station address - the receiver must be off */
|
|
|
|
ea_set_address(sc, 0, LLADDR(ifp->if_sadl));
|
2000-09-23 19:13:02 +04:00
|
|
|
|
|
|
|
/* Split board memory into Rx and Tx. */
|
2001-03-24 16:40:41 +03:00
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_TX_EAP);
|
2001-03-24 23:38:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_BUFWIN, (sc->sc_tx_bufsize>> 8) - 1);
|
2000-09-23 19:13:02 +04:00
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
if (sc->sc_variant == SEEQ_8004)
|
|
|
|
sc->sc_config2 |= SEEQ_CFG2_RX_TX_DISABLE;
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Configure rx. */
|
2001-03-25 05:06:59 +04:00
|
|
|
ea_mc_reset(sc);
|
2000-09-19 00:51:14 +04:00
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_config1 = SEEQ_CFG1_PROMISCUOUS;
|
2001-03-25 05:06:59 +04:00
|
|
|
else if ((ifp->if_flags & IFF_ALLMULTI) || sc->sc_variant == SEEQ_8004)
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_config1 = SEEQ_CFG1_MULTICAST;
|
2000-09-19 00:51:14 +04:00
|
|
|
else
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_config1 = SEEQ_CFG1_BROADCAST;
|
|
|
|
sc->sc_config1 |= SEEQ_CFG1_STATION_ADDR0;
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG1, sc->sc_config1);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2000-09-23 19:13:02 +04:00
|
|
|
/* Setup the Rx pointers */
|
2001-03-24 23:38:41 +03:00
|
|
|
sc->sc_rx_ptr = sc->sc_tx_bufsize;
|
2000-09-23 19:13:02 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_RX_PTR, sc->sc_rx_ptr);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_RX_END, sc->sc_rx_ptr >> 8);
|
2000-09-23 19:13:02 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* Place a NULL header at the beginning of the receive area */
|
|
|
|
ea_writebuf(sc, NULL, sc->sc_rx_ptr, 0);
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_BUFWIN, 0x0000);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_BUFWIN, 0x0000);
|
2000-09-23 19:13:02 +04:00
|
|
|
|
|
|
|
|
2000-09-19 00:51:14 +04:00
|
|
|
/* Configure TX. */
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_MISC, ("Configuring tx...\n"));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_TX_PTR, 0x0000);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_config2 |= SEEQ_CFG2_OUTPUT;
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
/* Reset tx buffer pointers */
|
|
|
|
sc->sc_tx_cur = 0;
|
|
|
|
sc->sc_tx_used = 0;
|
|
|
|
sc->sc_tx_next = 0;
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Place a NULL header at the beginning of the transmit area */
|
|
|
|
ea_writebuf(sc, NULL, 0x0000, 0);
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_BUFWIN, 0x0000);
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_BUFWIN, 0x0000);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_command |= SEEQ_CMD_TX_INTEN;
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND, sc->sc_command);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 23:38:41 +03:00
|
|
|
/* Turn on Rx */
|
|
|
|
sc->sc_command |= SEEQ_CMD_RX_INTEN;
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_RX_ON);
|
|
|
|
|
2000-09-23 19:13:02 +04:00
|
|
|
/* TX_ON gets set by ea_txpacket when there's something to transmit. */
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* Set flags appropriately. */
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
2001-03-24 23:38:41 +03:00
|
|
|
sc->sc_enabled = 1;
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* And start output. */
|
|
|
|
ea_start(ifp);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start output on interface. Get datagrams from the queue and output them,
|
|
|
|
* giving the receiver a chance between datagrams. Call only from splnet or
|
|
|
|
* interrupt level!
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
ea_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct seeq8005_softc *sc = ifp->if_softc;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_TX, ("ea_start()...\n"));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-27 22:03:04 +04:00
|
|
|
/*
|
|
|
|
* Don't do anything if output is active. seeq8005intr() will call
|
|
|
|
* us (actually eatxpacket()) back when the card's ready for more
|
|
|
|
* frames.
|
|
|
|
*/
|
2000-09-19 00:51:14 +04:00
|
|
|
if (ifp->if_flags & IFF_OACTIVE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Mark interface as output active */
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
|
|
|
|
/* tx packets */
|
|
|
|
|
|
|
|
eatxpacket(sc);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transfer a packet to the interface buffer and start transmission
|
|
|
|
*
|
|
|
|
* Called at splnet()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
eatxpacket(struct seeq8005_softc *sc)
|
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2001-03-25 03:31:06 +04:00
|
|
|
struct mbuf *m0;
|
2000-09-19 00:51:14 +04:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
|
|
|
|
/* Dequeue the next packet. */
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m0);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* If there's nothing to send, return. */
|
|
|
|
if (!m0) {
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_config2 |= SEEQ_CFG2_OUTPUT;
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_TX, ("tx finished\n"));
|
2000-09-19 00:51:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/* Give the packet to the bpf, if any. */
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m0);
|
|
|
|
#endif
|
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_TX, ("Tx new packet\n"));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_config2 &= ~SEEQ_CFG2_OUTPUT;
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-25 03:31:06 +04:00
|
|
|
ea_writembuf(sc, m0, 0x0000);
|
|
|
|
m_freem(m0);
|
|
|
|
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_TX_PTR, 0x0000);
|
|
|
|
|
|
|
|
/* Now transmit the datagram. */
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_TX_ON);
|
2001-03-28 00:26:45 +04:00
|
|
|
|
|
|
|
/* Make sure we notice if the chip goes silent on us. */
|
|
|
|
ifp->if_timer = 5;
|
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_TX,
|
|
|
|
("st=%04x\n", bus_space_read_2(iot, ioh, SEEQ_STATUS)));
|
|
|
|
DPRINTF(SEEQ_DEBUG_TX, ("tx: queued\n"));
|
2001-03-25 03:31:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a packet from an mbuf to the transmit buffer on the card.
|
|
|
|
*
|
|
|
|
* Puts a valid Tx header at the start of the packet, and a null header at
|
|
|
|
* the end.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ea_writembuf(struct seeq8005_softc *sc, struct mbuf *m0, int bufstart)
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
int len, nextpacket;
|
|
|
|
u_int8_t hdr[4];
|
|
|
|
|
2000-09-19 00:51:14 +04:00
|
|
|
/*
|
2001-03-25 03:31:06 +04:00
|
|
|
* Copy the datagram to the packet buffer.
|
2000-09-19 00:51:14 +04:00
|
|
|
*/
|
|
|
|
len = 0;
|
|
|
|
for (m = m0; m; m = m->m_next) {
|
|
|
|
if (m->m_len == 0)
|
|
|
|
continue;
|
2001-04-06 04:02:49 +04:00
|
|
|
ea_writebuf(sc, mtod(m, caddr_t), bufstart + 4 + len,
|
|
|
|
m->m_len);
|
2000-09-19 00:51:14 +04:00
|
|
|
len += m->m_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = max(len, ETHER_MIN_LEN);
|
|
|
|
|
|
|
|
/* Follow it with a NULL packet header */
|
2001-04-06 04:02:49 +04:00
|
|
|
memset(hdr, 0, 4);
|
|
|
|
ea_writebuf(sc, hdr, bufstart + 4 + len, 4);
|
2001-03-25 03:31:06 +04:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh, SEEQ_BUFWIN, 0x0000);
|
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh, SEEQ_BUFWIN, 0x0000);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-25 03:31:06 +04:00
|
|
|
/* Ok we now have a packet len bytes long in our packet buffer */
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_TX, ("ea_writembuf: length=%d\n", len));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Write the packet header */
|
|
|
|
nextpacket = len + 4;
|
|
|
|
hdr[0] = (nextpacket >> 8) & 0xff;
|
|
|
|
hdr[1] = nextpacket & 0xff;
|
2001-03-24 16:40:41 +03:00
|
|
|
hdr[2] = SEEQ_PKTCMD_TX | SEEQ_PKTCMD_DATA_FOLLOWS |
|
|
|
|
SEEQ_TXCMD_XMIT_SUCCESS_INT | SEEQ_TXCMD_COLLISION_INT;
|
2000-09-19 00:51:14 +04:00
|
|
|
hdr[3] = 0; /* Status byte -- will be update by hardware. */
|
|
|
|
ea_writebuf(sc, hdr, 0x0000, 4);
|
|
|
|
|
2001-03-25 03:31:06 +04:00
|
|
|
return len;
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet controller interrupt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
seeq8005intr(void *arg)
|
|
|
|
{
|
|
|
|
struct seeq8005_softc *sc = arg;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
2001-03-24 23:38:41 +03:00
|
|
|
int status, handled;
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
handled = 0;
|
|
|
|
|
|
|
|
/* Get the controller status */
|
2001-03-24 16:40:41 +03:00
|
|
|
status = bus_space_read_2(iot, ioh, SEEQ_STATUS);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Tx interrupt ? */
|
2001-03-24 16:40:41 +03:00
|
|
|
if (status & SEEQ_STATUS_TX_INT) {
|
2000-09-19 00:51:14 +04:00
|
|
|
handled = 1;
|
|
|
|
|
|
|
|
/* Acknowledge the interrupt */
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_TX_INTACK);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-04-03 02:25:17 +04:00
|
|
|
ea_txint(sc);
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Rx interrupt ? */
|
2001-03-24 16:40:41 +03:00
|
|
|
if (status & SEEQ_STATUS_RX_INT) {
|
2000-09-19 00:51:14 +04:00
|
|
|
handled = 1;
|
|
|
|
|
|
|
|
/* Acknowledge the interrupt */
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_RX_INTACK);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Processes the received packets */
|
2001-04-03 02:25:17 +04:00
|
|
|
ea_rxint(sc);
|
|
|
|
}
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-04-03 02:25:17 +04:00
|
|
|
return handled;
|
|
|
|
}
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-04-03 02:25:17 +04:00
|
|
|
static void
|
|
|
|
ea_txint(struct seeq8005_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
u_int8_t txhdr[4];
|
|
|
|
u_int txstatus;
|
|
|
|
|
|
|
|
ea_readbuf(sc, txhdr, 0x0000, 4);
|
|
|
|
|
|
|
|
DPRINTF(SEEQ_DEBUG_TX, ("txstatus=%02x %02x %02x %02x\n",
|
|
|
|
txhdr[0], txhdr[1], txhdr[2], txhdr[3]));
|
|
|
|
txstatus = txhdr[3];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If SEEQ_TXSTAT_COLLISION is set then we received at least
|
|
|
|
* one collision. On the 8004 we can find out exactly how many
|
|
|
|
* collisions occurred.
|
|
|
|
*
|
|
|
|
* The SEEQ_PKTSTAT_DONE will be set if the transmission has
|
|
|
|
* completed.
|
|
|
|
*
|
|
|
|
* If SEEQ_TXSTAT_COLLISION16 is set then 16 collisions
|
|
|
|
* occurred and the packet transmission was aborted.
|
|
|
|
* This situation is untested as present.
|
|
|
|
*
|
|
|
|
* The SEEQ_TXSTAT_BABBLE should never be set and is untested
|
|
|
|
* as we should never xmit oversized packets.
|
|
|
|
*/
|
|
|
|
if (txstatus & SEEQ_TXSTAT_COLLISION) {
|
|
|
|
switch (sc->sc_variant) {
|
|
|
|
case SEEQ_8004: {
|
|
|
|
int colls;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The 8004 contains a 4 bit collision count
|
|
|
|
* in the status register.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* This appears to be broken on 80C04.AE */
|
|
|
|
/* ifp->if_collisions +=
|
|
|
|
(txstatus >> SEEQ_TXSTAT_COLLISIONS_SHIFT)
|
|
|
|
& SEEQ_TXSTAT_COLLISION_MASK;*/
|
|
|
|
|
|
|
|
/* Use the TX Collision register */
|
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_TX_COLLS);
|
|
|
|
colls = bus_space_read_1(iot, ioh, SEEQ_BUFWIN);
|
|
|
|
ifp->if_collisions += colls;
|
|
|
|
break;
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
2001-04-03 02:25:17 +04:00
|
|
|
case SEEQ_8005:
|
|
|
|
/* We known there was at least 1 collision */
|
|
|
|
ifp->if_collisions++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (txstatus & SEEQ_TXSTAT_COLLISION16) {
|
|
|
|
printf("seeq_intr: col16 %x\n", txstatus);
|
|
|
|
ifp->if_collisions += 16;
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
} else if (txstatus & SEEQ_TXSTAT_BABBLE) {
|
|
|
|
ifp->if_oerrors++;
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
|
2001-04-03 02:25:17 +04:00
|
|
|
/* Have we completed transmission on the packet ? */
|
|
|
|
if (txstatus & SEEQ_PKTSTAT_DONE) {
|
|
|
|
/* Clear watchdog timer. */
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
/* Update stats */
|
|
|
|
ifp->if_opackets++;
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-04-03 02:25:17 +04:00
|
|
|
/* Tx next packet */
|
|
|
|
|
|
|
|
eatxpacket(sc);
|
|
|
|
}
|
|
|
|
}
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
void
|
2001-04-03 02:25:17 +04:00
|
|
|
ea_rxint(struct seeq8005_softc *sc)
|
2000-09-19 00:51:14 +04:00
|
|
|
{
|
|
|
|
bus_space_tag_t iot = sc->sc_iot;
|
|
|
|
bus_space_handle_t ioh = sc->sc_ioh;
|
|
|
|
u_int addr;
|
|
|
|
int len;
|
|
|
|
int ctrl;
|
|
|
|
int ptr;
|
|
|
|
int pack;
|
|
|
|
int status;
|
|
|
|
u_int8_t rxhdr[4];
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
|
|
|
|
|
|
|
|
/* We start from the last rx pointer position */
|
|
|
|
addr = sc->sc_rx_ptr;
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_config2 &= ~SEEQ_CFG2_OUTPUT;
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
do {
|
|
|
|
/* Read rx header */
|
|
|
|
ea_readbuf(sc, rxhdr, addr, 4);
|
|
|
|
|
|
|
|
/* Split the packet header */
|
|
|
|
ptr = (rxhdr[0] << 8) | rxhdr[1];
|
|
|
|
ctrl = rxhdr[2];
|
|
|
|
status = rxhdr[3];
|
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_RX,
|
|
|
|
("addr=%04x ptr=%04x ctrl=%02x status=%02x\n",
|
|
|
|
addr, ptr, ctrl, status));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Zero packet ptr ? then must be null header so exit */
|
|
|
|
if (ptr == 0) break;
|
|
|
|
|
2001-03-28 00:26:45 +04:00
|
|
|
/* Sanity-check the next-packet pointer and flags. */
|
|
|
|
if (__predict_false(ptr < sc->sc_tx_bufsize ||
|
|
|
|
(ctrl & SEEQ_PKTCMD_TX))) {
|
|
|
|
++ifp->if_ierrors;
|
|
|
|
log(LOG_ERR,
|
|
|
|
"%s: Rx chain corrupt at %04x (ptr = %04x)\n",
|
|
|
|
sc->sc_dev.dv_xname, addr, ptr);
|
|
|
|
ea_init(ifp);
|
|
|
|
return;
|
|
|
|
}
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Get packet length */
|
|
|
|
len = (ptr - addr) - 4;
|
|
|
|
|
|
|
|
if (len < 0)
|
2001-03-24 23:38:41 +03:00
|
|
|
len += sc->sc_rx_bufsize;
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_RX, ("len=%04x\n", len));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Has the packet rx completed ? if not then exit */
|
2001-03-24 16:40:41 +03:00
|
|
|
if ((status & SEEQ_PKTSTAT_DONE) == 0)
|
2000-09-19 00:51:14 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Did we have any errors? then note error and go to
|
|
|
|
* next packet
|
|
|
|
*/
|
2001-03-24 23:38:41 +03:00
|
|
|
if (__predict_false(status & SEEQ_RXSTAT_ERROR_MASK)) {
|
2000-09-19 00:51:14 +04:00
|
|
|
++ifp->if_ierrors;
|
2001-03-28 00:26:45 +04:00
|
|
|
/* XXX oversize packets may be OK */
|
2000-09-19 00:51:14 +04:00
|
|
|
log(LOG_WARNING,
|
2001-03-28 02:17:51 +04:00
|
|
|
"%s: rx packet error at %04x (err=%02x)\n",
|
|
|
|
sc->sc_dev.dv_xname, addr, status & 0x0f);
|
2001-03-30 00:49:44 +04:00
|
|
|
/* XXX shouldn't need to reset if it's genuine. */
|
|
|
|
ea_init(ifp);
|
|
|
|
return;
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Is the packet too big ? - this will probably be trapped
|
2001-03-28 02:17:51 +04:00
|
|
|
* above as a receive error. If it's not, this is indicative
|
|
|
|
* of buffer corruption.
|
2000-09-19 00:51:14 +04:00
|
|
|
*/
|
|
|
|
if (__predict_false(len > (ETHER_MAX_LEN - ETHER_CRC_LEN))) {
|
|
|
|
++ifp->if_ierrors;
|
2001-03-28 02:17:51 +04:00
|
|
|
log(LOG_ERR,
|
|
|
|
"%s: rx packet size error at %04x (len=%d)\n",
|
|
|
|
sc->sc_dev.dv_xname, addr, len);
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_config2 |= SEEQ_CFG2_OUTPUT;
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG2,
|
2000-09-19 00:51:14 +04:00
|
|
|
sc->sc_config2);
|
2000-11-03 03:25:36 +03:00
|
|
|
ea_init(ifp);
|
2000-09-19 00:51:14 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
/* Pass data up to upper levels. */
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_read(sc, addr + 4, len);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
addr = ptr;
|
|
|
|
++pack;
|
|
|
|
} while (len != 0);
|
|
|
|
|
2001-03-24 16:40:41 +03:00
|
|
|
sc->sc_config2 |= SEEQ_CFG2_OUTPUT;
|
|
|
|
bus_space_write_2(iot, ioh, SEEQ_CONFIG2, sc->sc_config2);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
2001-03-28 01:43:13 +04:00
|
|
|
DPRINTF(SEEQ_DEBUG_RX, ("new rx ptr=%04x\n", addr));
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Store new rx pointer */
|
|
|
|
sc->sc_rx_ptr = addr;
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_RX_END, sc->sc_rx_ptr >> 8);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
/* Make sure the receiver is on */
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(iot, ioh, SEEQ_COMMAND,
|
|
|
|
sc->sc_command | SEEQ_CMD_RX_ON);
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass a packet up to the higher levels.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_read(struct seeq8005_softc *sc, int addr, int len)
|
2000-09-19 00:51:14 +04:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
|
|
|
|
/* Pull packet off interface. */
|
2001-03-24 23:38:41 +03:00
|
|
|
m = ea_get(sc, addr, len, ifp);
|
2000-09-19 00:51:14 +04:00
|
|
|
if (m == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* Check if there's a BPF listener on this interface.
|
|
|
|
* If so, hand off the raw packet to bpf.
|
|
|
|
*/
|
2000-10-02 03:32:39 +04:00
|
|
|
if (ifp->if_bpf)
|
2000-09-19 00:51:14 +04:00
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(*ifp->if_input)(ifp, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull read data off a interface. Len is length of data, with local net
|
|
|
|
* header stripped. We copy the data into mbufs. When full cluster sized
|
|
|
|
* units are present we copy into clusters.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct mbuf *
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_get(struct seeq8005_softc *sc, int addr, int totlen, struct ifnet *ifp)
|
2000-09-19 00:51:14 +04:00
|
|
|
{
|
|
|
|
struct mbuf *top, **mp, *m;
|
|
|
|
int len;
|
|
|
|
u_int cp, epkt;
|
|
|
|
|
|
|
|
cp = addr;
|
|
|
|
epkt = cp + totlen;
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0)
|
|
|
|
return 0;
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = totlen;
|
|
|
|
m->m_len = MHLEN;
|
|
|
|
top = 0;
|
|
|
|
mp = ⊤
|
|
|
|
|
|
|
|
while (totlen > 0) {
|
|
|
|
if (top) {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0) {
|
|
|
|
m_freem(top);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
m->m_len = MLEN;
|
|
|
|
}
|
|
|
|
len = min(totlen, epkt - cp);
|
|
|
|
if (len >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if (m->m_flags & M_EXT)
|
|
|
|
m->m_len = len = min(len, MCLBYTES);
|
|
|
|
else
|
|
|
|
len = m->m_len;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Place initial small packet/header at end of mbuf.
|
|
|
|
*/
|
|
|
|
if (len < m->m_len) {
|
|
|
|
if (top == 0 && len + max_linkhdr <= m->m_len)
|
|
|
|
m->m_data += max_linkhdr;
|
|
|
|
m->m_len = len;
|
|
|
|
} else
|
|
|
|
len = m->m_len;
|
|
|
|
}
|
|
|
|
if (top == 0) {
|
|
|
|
/* Make sure the payload is aligned */
|
|
|
|
caddr_t newdata = (caddr_t)
|
|
|
|
ALIGN(m->m_data + sizeof(struct ether_header)) -
|
|
|
|
sizeof(struct ether_header);
|
|
|
|
len -= newdata - m->m_data;
|
|
|
|
m->m_len = len;
|
|
|
|
m->m_data = newdata;
|
|
|
|
}
|
|
|
|
ea_readbuf(sc, mtod(m, u_char *),
|
2001-03-24 23:38:41 +03:00
|
|
|
cp < SEEQ_MAX_BUFFER_SIZE ? cp : cp - sc->sc_rx_bufsize,
|
|
|
|
len);
|
2000-09-19 00:51:14 +04:00
|
|
|
cp += len;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
|
|
|
totlen -= len;
|
|
|
|
if (cp == epkt)
|
|
|
|
cp = addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-09-23 19:13:02 +04:00
|
|
|
* Process an ioctl request. Mostly boilerplate.
|
2000-09-19 00:51:14 +04:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ea_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
|
|
|
{
|
|
|
|
struct seeq8005_softc *sc = ifp->if_softc;
|
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
switch (cmd) {
|
|
|
|
|
2000-11-03 03:25:36 +03:00
|
|
|
default:
|
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
|
|
|
if (error == ENETRESET) {
|
2000-09-19 00:51:14 +04:00
|
|
|
/*
|
2000-11-03 03:25:36 +03:00
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
2000-09-19 00:51:14 +04:00
|
|
|
*/
|
2000-11-03 03:25:36 +03:00
|
|
|
ea_mc_reset(sc);
|
|
|
|
error = 0;
|
2000-09-19 00:51:14 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-11-03 03:25:36 +03:00
|
|
|
/* Must be called at splnet() */
|
2001-03-24 23:38:41 +03:00
|
|
|
|
2000-11-03 03:25:36 +03:00
|
|
|
static void
|
|
|
|
ea_mc_reset(struct seeq8005_softc *sc)
|
2001-03-24 23:38:41 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (sc->sc_variant) {
|
|
|
|
case SEEQ_8004:
|
|
|
|
ea_mc_reset_8004(sc);
|
|
|
|
return;
|
|
|
|
case SEEQ_8005:
|
|
|
|
ea_mc_reset_8005(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ea_mc_reset_8004(struct seeq8005_softc *sc)
|
|
|
|
{
|
|
|
|
struct ethercom *ec = &sc->sc_ethercom;
|
|
|
|
struct ifnet *ifp = &ec->ec_if;
|
|
|
|
struct ether_multi *enm;
|
|
|
|
u_int8_t *cp, c;
|
|
|
|
u_int32_t crc;
|
|
|
|
int i, len;
|
|
|
|
struct ether_multistep step;
|
|
|
|
u_int8_t af[8];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up multicast address filter by passing all multicast addresses
|
|
|
|
* through a crc generator, and then using bits 2 - 7 as an index
|
|
|
|
* into the 64 bit logical address filter. The high order bits
|
|
|
|
* selects the word, while the rest of the bits select the bit within
|
|
|
|
* the word.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
af[i] = 0xff;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
af[i] = 0;
|
|
|
|
ETHER_FIRST_MULTI(step, ec, enm);
|
|
|
|
while (enm != NULL) {
|
|
|
|
if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
|
|
|
|
sizeof(enm->enm_addrlo)) != 0) {
|
|
|
|
/*
|
|
|
|
* We must listen to a range of multicast addresses.
|
|
|
|
* For now, just accept all multicasts, rather than
|
|
|
|
* trying to set only those filter bits needed to match
|
|
|
|
* the range. (At this time, the only use of address
|
|
|
|
* ranges is for IP multicast routing, for which the
|
|
|
|
* range is big enough to require all bits set.)
|
|
|
|
*/
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
af[i] = 0xff;
|
2001-03-25 05:06:59 +04:00
|
|
|
break;
|
2001-03-24 23:38:41 +03:00
|
|
|
}
|
|
|
|
cp = enm->enm_addrlo;
|
|
|
|
crc = 0xffffffff;
|
|
|
|
for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
|
|
|
|
c = *cp++;
|
|
|
|
for (i = 8; --i >= 0;) {
|
|
|
|
if (((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01)) {
|
|
|
|
crc <<= 1;
|
|
|
|
crc ^= 0x04c11db6 | 1;
|
|
|
|
} else
|
|
|
|
crc <<= 1;
|
|
|
|
c >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Just want the 6 most significant bits. */
|
|
|
|
crc = (crc >> 2) & 0x3f;
|
|
|
|
|
|
|
|
/* Turn on the corresponding bit in the filter. */
|
|
|
|
af[crc >> 3] |= 1 << (crc & 0x7);
|
|
|
|
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
|
|
|
|
ea_select_buffer(sc, SEEQ_BUFCODE_MULTICAST);
|
|
|
|
for (i = 0; i < 8; ++i)
|
|
|
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh,
|
|
|
|
SEEQ_BUFWIN, af[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ea_mc_reset_8005(struct seeq8005_softc *sc)
|
2000-11-03 03:25:36 +03:00
|
|
|
{
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
|
|
|
int naddr, maxaddrs;
|
|
|
|
|
|
|
|
naddr = 0;
|
2001-03-24 23:38:41 +03:00
|
|
|
maxaddrs = 5;
|
2000-11-03 03:25:36 +03:00
|
|
|
ETHER_FIRST_MULTI(step, &sc->sc_ethercom, enm);
|
|
|
|
while (enm != NULL) {
|
|
|
|
/* Have we got space? */
|
|
|
|
if (naddr >= maxaddrs ||
|
|
|
|
bcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0) {
|
|
|
|
sc->sc_ethercom.ec_if.if_flags |= IFF_ALLMULTI;
|
|
|
|
ea_ioctl(&sc->sc_ethercom.ec_if, SIOCSIFFLAGS, NULL);
|
|
|
|
return;
|
|
|
|
}
|
2001-03-24 23:38:41 +03:00
|
|
|
ea_set_address(sc, 1 + naddr, enm->enm_addrlo);
|
|
|
|
sc->sc_config1 |= SEEQ_CFG1_STATION_ADDR1 << naddr;
|
2000-11-03 03:25:36 +03:00
|
|
|
naddr++;
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
for (; naddr < maxaddrs; naddr++)
|
2001-03-24 23:38:41 +03:00
|
|
|
sc->sc_config1 &= ~(SEEQ_CFG1_STATION_ADDR1 << naddr);
|
2001-03-24 16:40:41 +03:00
|
|
|
bus_space_write_2(sc->sc_iot, sc->sc_ioh, SEEQ_CONFIG1,
|
2000-11-03 03:25:36 +03:00
|
|
|
sc->sc_config1);
|
|
|
|
}
|
|
|
|
|
2000-09-19 00:51:14 +04:00
|
|
|
/*
|
|
|
|
* Device timeout routine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
ea_watchdog(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct seeq8005_softc *sc = ifp->if_softc;
|
|
|
|
|
2001-03-28 00:26:45 +04:00
|
|
|
log(LOG_ERR, "%s: lost Tx interrupt (status = 0x%04x)\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
|
|
|
bus_space_read_2(sc->sc_iot, sc->sc_ioh, SEEQ_STATUS));
|
2000-09-19 00:51:14 +04:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
|
|
|
|
/* Kick the interface */
|
|
|
|
|
2000-11-03 03:25:36 +03:00
|
|
|
ea_init(ifp);
|
2000-09-19 00:51:14 +04:00
|
|
|
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* End of if_ea.c */
|