1994-01-10 18:56:26 +00:00
|
|
|
/*
|
1995-01-08 10:47:23 +00:00
|
|
|
* Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1994-01-10 18:56:26 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
1995-01-08 10:47:23 +00:00
|
|
|
* 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 Herb Peyerl.
|
|
|
|
* 4. The name of Herb Peyerl may not 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 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-03-31 06:41:38 +00:00
|
|
|
* if_ep.c,v 1.19 1995/01/24 20:53:45 davidg Exp
|
1995-01-24 20:53:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Modified from the FreeBSD 1.1.5.1 version by:
|
1995-05-30 08:16:23 +00:00
|
|
|
* Andres Vega Garcia
|
1995-01-24 20:53:45 +00:00
|
|
|
* INRIA - Sophia Antipolis, France
|
|
|
|
* avega@sophia.inria.fr
|
1994-01-10 18:56:26 +00:00
|
|
|
*/
|
1994-05-02 22:27:33 +00:00
|
|
|
|
1995-03-31 06:41:38 +00:00
|
|
|
/*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1995-03-31 06:41:38 +00:00
|
|
|
*
|
|
|
|
* Promiscuous mode added and interrupt logic slightly changed
|
|
|
|
* to reduce the number of adapter failures. Transceiver select
|
|
|
|
* logic changed to use value from EEPROM. Autoconfiguration
|
|
|
|
* features added.
|
|
|
|
* Done by:
|
|
|
|
* Serge Babkin
|
|
|
|
* Chelindbank (Chelyabinsk, Russia)
|
|
|
|
* babkin@hq.icb.chel.su
|
|
|
|
*/
|
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
/*
|
|
|
|
* Pccard support for 3C589 by:
|
|
|
|
* HAMADA Naoki
|
|
|
|
* nao@tom-yam.or.jp
|
|
|
|
*/
|
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
/*
|
|
|
|
* MAINTAINER: Matthew N. Dodd <winter@jurai.net>
|
|
|
|
* <mdodd@FreeBSD.org>
|
|
|
|
*/
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1994-05-02 22:27:33 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
1997-03-24 11:33:46 +00:00
|
|
|
#include <sys/sockio.h>
|
1999-10-27 06:25:16 +00:00
|
|
|
|
1999-10-25 02:52:16 +00:00
|
|
|
#include <sys/bus.h>
|
1994-01-26 09:06:29 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
1994-05-02 22:27:33 +00:00
|
|
|
#include <net/if.h>
|
1999-10-27 06:25:16 +00:00
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
1995-03-28 07:58:53 +00:00
|
|
|
|
1999-09-26 06:42:36 +00:00
|
|
|
#include <dev/ep/if_epreg.h>
|
|
|
|
#include <dev/ep/if_epvar.h>
|
1999-01-31 22:41:51 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
/* Exported variables */
|
1999-10-25 02:52:16 +00:00
|
|
|
devclass_t ep_devclass;
|
1999-07-25 01:20:37 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
#if 0
|
|
|
|
static char * ep_conn_type[] = {"UTP", "AUI", "???", "BNC"};
|
|
|
|
static int if_media2ep_media[] = { 0, 0, 0, UTP, BNC, AUI };
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int ep_media2if_media[] =
|
|
|
|
{ IFM_10_T, IFM_10_5, IFM_NONE, IFM_10_2, IFM_NONE };
|
1996-06-14 22:11:38 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
/* if functions */
|
2002-03-20 02:08:01 +00:00
|
|
|
static void ep_if_init (void *);
|
|
|
|
static int ep_if_ioctl (struct ifnet *, u_long, caddr_t);
|
|
|
|
static void ep_if_start (struct ifnet *);
|
|
|
|
static void ep_if_watchdog (struct ifnet *);
|
1996-06-14 22:11:38 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
/* if_media functions */
|
2002-03-20 02:08:01 +00:00
|
|
|
static int ep_ifmedia_upd (struct ifnet *);
|
|
|
|
static void ep_ifmedia_sts (struct ifnet *, struct ifmediareq *);
|
1999-10-27 06:25:16 +00:00
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static void epstop (struct ep_softc *);
|
|
|
|
static void epread (struct ep_softc *);
|
|
|
|
static int eeprom_rdy (struct ep_softc *);
|
1999-10-27 06:25:16 +00:00
|
|
|
|
|
|
|
#define EP_FTST(sc, f) (sc->stat & (f))
|
|
|
|
#define EP_FSET(sc, f) (sc->stat |= (f))
|
|
|
|
#define EP_FRST(sc, f) (sc->stat &= ~(f))
|
1996-06-14 22:11:38 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
static int
|
1996-02-26 01:05:36 +00:00
|
|
|
eeprom_rdy(sc)
|
|
|
|
struct ep_softc *sc;
|
1994-11-13 10:12:37 +00:00
|
|
|
{
|
|
|
|
int i;
|
1994-09-03 18:10:44 +00:00
|
|
|
|
2000-01-15 05:21:43 +00:00
|
|
|
for (i = 0; is_eeprom_busy(BASE) && i < MAX_EEPROMBUSY; i++) {
|
|
|
|
DELAY(100);
|
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
if (i >= MAX_EEPROMBUSY) {
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("ep%d: eeprom failed to come ready.\n", sc->unit);
|
1994-11-13 10:12:37 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
1994-09-03 18:10:44 +00:00
|
|
|
|
1994-01-10 18:56:26 +00:00
|
|
|
/*
|
1994-11-13 10:12:37 +00:00
|
|
|
* get_e: gets a 16 bits word from the EEPROM. we must have set the window
|
|
|
|
* before
|
1994-01-10 18:56:26 +00:00
|
|
|
*/
|
1996-02-26 01:05:36 +00:00
|
|
|
u_int16_t
|
|
|
|
get_e(sc, offset)
|
|
|
|
struct ep_softc *sc;
|
2000-01-15 05:21:43 +00:00
|
|
|
u_int16_t offset;
|
1994-11-13 10:12:37 +00:00
|
|
|
{
|
1996-02-26 01:05:36 +00:00
|
|
|
if (!eeprom_rdy(sc))
|
2000-01-15 05:21:43 +00:00
|
|
|
return (0);
|
1999-10-27 06:25:16 +00:00
|
|
|
outw(BASE + EP_W0_EEPROM_COMMAND, (EEPROM_CMD_RD << sc->epb.cmd_off) | offset);
|
1996-02-26 01:05:36 +00:00
|
|
|
if (!eeprom_rdy(sc))
|
2000-01-15 05:21:43 +00:00
|
|
|
return (0);
|
1996-02-26 01:05:36 +00:00
|
|
|
return (inw(BASE + EP_W0_EEPROM_DATA));
|
|
|
|
}
|
|
|
|
|
2000-01-15 05:21:43 +00:00
|
|
|
void
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_get_macaddr(sc, addr)
|
|
|
|
struct ep_softc * sc;
|
|
|
|
u_char * addr;
|
1996-02-26 01:05:36 +00:00
|
|
|
{
|
1999-10-27 06:25:16 +00:00
|
|
|
int i;
|
|
|
|
u_int16_t * macaddr = (u_int16_t *)addr;
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
GO_WINDOW(0);
|
|
|
|
for(i = EEPROM_NODE_ADDR_0; i <= EEPROM_NODE_ADDR_2; i++) {
|
|
|
|
macaddr[i] = htons(get_e(sc, i));
|
|
|
|
}
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
return;
|
|
|
|
}
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
int
|
|
|
|
ep_alloc(device_t dev)
|
|
|
|
{
|
|
|
|
struct ep_softc * sc = device_get_softc(dev);
|
|
|
|
int rid;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
rid = 0;
|
|
|
|
sc->iobase = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
|
|
|
|
0, ~0, 1, RF_ACTIVE);
|
|
|
|
if (!sc->iobase) {
|
|
|
|
device_printf(dev, "No I/O space?!\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
rid = 0;
|
|
|
|
sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
|
|
|
|
0, ~0, 1, RF_ACTIVE);
|
|
|
|
if (!sc->irq) {
|
|
|
|
device_printf(dev, "No irq?!\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->dev = dev;
|
|
|
|
sc->unit = device_get_unit(dev);
|
|
|
|
sc->stat = 0; /* 16 bit access */
|
|
|
|
|
|
|
|
sc->ep_io_addr = rman_get_start(sc->iobase);
|
|
|
|
|
|
|
|
sc->ep_btag = rman_get_bustag(sc->iobase);
|
|
|
|
sc->ep_bhandle = rman_get_bushandle(sc->iobase);
|
|
|
|
|
|
|
|
sc->ep_connectors = 0;
|
|
|
|
sc->ep_connector = 0;
|
|
|
|
|
2000-01-15 05:21:43 +00:00
|
|
|
GO_WINDOW(0);
|
1999-10-27 06:25:16 +00:00
|
|
|
sc->epb.cmd_off = 0;
|
|
|
|
sc->epb.prod_id = get_e(sc, EEPROM_PROD_ID);
|
|
|
|
sc->epb.res_cfg = get_e(sc, EEPROM_RESOURCE_CFG);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
return (error);
|
1996-02-26 01:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_get_media(sc)
|
|
|
|
struct ep_softc * sc;
|
1996-02-26 01:05:36 +00:00
|
|
|
{
|
1999-10-27 06:25:16 +00:00
|
|
|
u_int16_t config;
|
|
|
|
|
|
|
|
GO_WINDOW(0);
|
|
|
|
config = inw(BASE + EP_W0_CONFIG_CTRL);
|
|
|
|
if (config & IS_AUI)
|
|
|
|
sc->ep_connectors |= AUI;
|
|
|
|
if (config & IS_BNC)
|
|
|
|
sc->ep_connectors |= BNC;
|
|
|
|
if (config & IS_UTP)
|
|
|
|
sc->ep_connectors |= UTP;
|
|
|
|
|
|
|
|
if (!(sc->ep_connectors & 7)) {
|
|
|
|
if (bootverbose)
|
|
|
|
device_printf(sc->dev, "no connectors!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This works for most of the cards so we'll do it here.
|
|
|
|
* The cards that require something different can override
|
|
|
|
* this later on.
|
|
|
|
*/
|
|
|
|
sc->ep_connector = inw(BASE + EP_W0_ADDRESS_CFG) >> ACF_CONNECTOR_BITS;
|
|
|
|
|
|
|
|
return;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
void
|
|
|
|
ep_free(device_t dev)
|
|
|
|
{
|
|
|
|
struct ep_softc * sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
if (sc->iobase)
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->iobase);
|
|
|
|
if (sc->irq)
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
int
|
|
|
|
ep_attach(sc)
|
1999-10-27 06:25:16 +00:00
|
|
|
struct ep_softc * sc;
|
1996-02-26 01:05:36 +00:00
|
|
|
{
|
1999-10-27 06:25:16 +00:00
|
|
|
struct ifnet * ifp = NULL;
|
|
|
|
struct ifmedia * ifm = NULL;
|
|
|
|
u_short * p;
|
|
|
|
int i;
|
|
|
|
int attached;
|
1996-06-14 22:11:38 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
sc->gone = 0;
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr);
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
/*
|
|
|
|
* Setup the station address
|
|
|
|
*/
|
|
|
|
p = (u_short *)&sc->arpcom.ac_enaddr;
|
|
|
|
GO_WINDOW(2);
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
outw(BASE + EP_W2_ADDR_0 + (i * 2), ntohs(p[i]));
|
|
|
|
}
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
device_printf(sc->dev, "Ethernet address %6D\n",
|
|
|
|
sc->arpcom.ac_enaddr, ":");
|
|
|
|
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
attached = (ifp->if_softc != 0);
|
|
|
|
|
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_unit = sc->unit;
|
|
|
|
ifp->if_name = "ep";
|
|
|
|
ifp->if_mtu = ETHERMTU;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_output = ether_output;
|
|
|
|
ifp->if_start = ep_if_start;
|
|
|
|
ifp->if_ioctl = ep_if_ioctl;
|
|
|
|
ifp->if_watchdog = ep_if_watchdog;
|
|
|
|
ifp->if_init = ep_if_init;
|
2000-01-12 05:27:08 +00:00
|
|
|
ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
|
1999-10-27 06:25:16 +00:00
|
|
|
|
|
|
|
if (!sc->epb.mii_trans) {
|
|
|
|
ifmedia_init(&sc->ifmedia, 0, ep_ifmedia_upd, ep_ifmedia_sts);
|
|
|
|
|
|
|
|
if (sc->ep_connectors & AUI)
|
|
|
|
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_5, 0, NULL);
|
|
|
|
if (sc->ep_connectors & UTP)
|
|
|
|
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL);
|
|
|
|
if (sc->ep_connectors & BNC)
|
|
|
|
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_2, 0, NULL);
|
|
|
|
if (!sc->ep_connectors)
|
|
|
|
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_NONE, 0, NULL);
|
|
|
|
|
|
|
|
ifmedia_set(&sc->ifmedia, IFM_ETHER|ep_media2if_media[sc->ep_connector]);
|
|
|
|
|
|
|
|
ifm = &sc->ifmedia;
|
|
|
|
ifm->ifm_media = ifm->ifm_cur->ifm_media;
|
|
|
|
ep_ifmedia_upd(ifp);
|
|
|
|
}
|
|
|
|
|
2000-07-13 22:54:34 +00:00
|
|
|
if (!attached)
|
2002-11-14 23:54:55 +00:00
|
|
|
ether_ifattach(ifp, sc->arpcom.ac_enaddr);
|
1996-01-29 03:16:14 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
#ifdef EP_LOCAL_STATS
|
1999-10-27 06:25:16 +00:00
|
|
|
sc->rx_no_first = sc->rx_no_mbuf = sc->rx_bpf_disc =
|
|
|
|
sc->rx_overrunf = sc->rx_overrunl = sc->tx_underrun = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
1999-10-27 06:25:16 +00:00
|
|
|
EP_FSET(sc, F_RX_FIRST);
|
|
|
|
sc->top = sc->mcur = 0;
|
1994-01-26 09:06:29 +00:00
|
|
|
|
2000-03-13 11:48:03 +00:00
|
|
|
epstop(sc);
|
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
return 0;
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1994-01-26 09:06:29 +00:00
|
|
|
/*
|
|
|
|
* The order in here seems important. Otherwise we may not receive
|
|
|
|
* interrupts. ?!
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_if_init(xsc)
|
1999-08-20 14:12:14 +00:00
|
|
|
void *xsc;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1999-08-20 14:12:14 +00:00
|
|
|
struct ep_softc *sc = xsc;
|
1994-11-13 10:12:37 +00:00
|
|
|
register struct ifnet *ifp = &sc->arpcom.ac_if;
|
1999-10-27 06:25:16 +00:00
|
|
|
int s, i;
|
1996-06-14 22:11:38 +00:00
|
|
|
|
|
|
|
if (sc->gone)
|
|
|
|
return;
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1995-04-05 13:12:13 +00:00
|
|
|
/*
|
1994-11-13 10:12:37 +00:00
|
|
|
if (ifp->if_addrlist == (struct ifaddr *) 0)
|
|
|
|
return;
|
1995-04-05 13:12:13 +00:00
|
|
|
*/
|
1994-01-10 19:13:50 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
s = splimp();
|
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1995-03-31 06:41:38 +00:00
|
|
|
GO_WINDOW(0);
|
|
|
|
outw(BASE + EP_COMMAND, STOP_TRANSCEIVER);
|
|
|
|
GO_WINDOW(4);
|
|
|
|
outw(BASE + EP_W4_MEDIA_TYPE, DISABLE_UTP);
|
1994-11-13 10:12:37 +00:00
|
|
|
GO_WINDOW(0);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Disable the card */
|
|
|
|
outw(BASE + EP_W0_CONFIG_CTRL, 0);
|
1994-01-26 09:13:56 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Enable the card */
|
|
|
|
outw(BASE + EP_W0_CONFIG_CTRL, ENABLE_DRQ_IRQ);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
GO_WINDOW(2);
|
1994-01-26 09:13:56 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Reload the ether_addr. */
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
outb(BASE + EP_W2_ADDR_0 + i, sc->arpcom.ac_enaddr[i]);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, RX_RESET);
|
|
|
|
outw(BASE + EP_COMMAND, TX_RESET);
|
1997-10-14 06:56:09 +00:00
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Window 1 is operating window */
|
|
|
|
GO_WINDOW(1);
|
|
|
|
for (i = 0; i < 31; i++)
|
|
|
|
inb(BASE + EP_W1_TX_STATUS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/* get rid of stray intr's */
|
|
|
|
outw(BASE + EP_COMMAND, ACK_INTR | 0xff);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RD_0_MASK | S_5_INTS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_INTR_MASK | S_5_INTS);
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
outw(BASE + EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
|
|
|
|
FIL_GROUP | FIL_BRDCST | FIL_ALL);
|
|
|
|
else
|
|
|
|
outw(BASE + EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
|
|
|
|
FIL_GROUP | FIL_BRDCST);
|
|
|
|
|
2000-01-15 05:21:43 +00:00
|
|
|
if (!sc->epb.mii_trans) {
|
|
|
|
ep_ifmedia_upd(ifp);
|
|
|
|
}
|
1995-03-31 06:41:38 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, RX_ENABLE);
|
|
|
|
outw(BASE + EP_COMMAND, TX_ENABLE);
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE; /* just in case */
|
|
|
|
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->rx_no_first = sc->rx_no_mbuf =
|
2000-05-14 02:18:43 +00:00
|
|
|
sc->rx_overrunf = sc->rx_overrunl = sc->tx_underrun = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
1999-09-26 06:42:36 +00:00
|
|
|
EP_FSET(sc, F_RX_FIRST);
|
1994-11-13 10:12:37 +00:00
|
|
|
if (sc->top) {
|
|
|
|
m_freem(sc->top);
|
|
|
|
sc->top = sc->mcur = 0;
|
|
|
|
}
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
1995-04-10 21:25:06 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_TX_START_THRESH | 16);
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/*
|
|
|
|
* Store up a bunch of mbuf's for use later. (MAX_MBS). First we free up
|
|
|
|
* any that we had in case we're being called from intr or somewhere
|
|
|
|
* else.
|
|
|
|
*/
|
|
|
|
|
1996-06-14 21:28:35 +00:00
|
|
|
GO_WINDOW(1);
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_if_start(ifp);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
|
|
|
splx(s);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_if_start(ifp)
|
1994-11-13 10:12:37 +00:00
|
|
|
struct ifnet *ifp;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
2000-01-12 06:42:49 +00:00
|
|
|
struct ep_softc *sc = ifp->if_softc;
|
|
|
|
u_int len;
|
|
|
|
struct mbuf *m;
|
1994-11-13 10:12:37 +00:00
|
|
|
struct mbuf *top;
|
|
|
|
int s, pad;
|
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
if (sc->gone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1996-02-13 15:55:33 +00:00
|
|
|
if (ifp->if_flags & IFF_OACTIVE) {
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-01-12 06:42:49 +00:00
|
|
|
|
1994-01-10 18:56:26 +00:00
|
|
|
startagain:
|
1994-11-13 10:12:37 +00:00
|
|
|
/* Sneak a peek at the next packet */
|
1996-02-13 15:55:33 +00:00
|
|
|
m = ifp->if_snd.ifq_head;
|
1994-11-13 10:12:37 +00:00
|
|
|
if (m == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (len = 0, top = m; m; m = m->m_next)
|
|
|
|
len += m->m_len;
|
1994-01-26 09:06:29 +00:00
|
|
|
|
2000-03-13 11:51:44 +00:00
|
|
|
pad = (4 - len) & 3;
|
1994-09-03 18:10:44 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
/*
|
|
|
|
* The 3c509 automatically pads short packets to minimum ethernet length,
|
|
|
|
* but we drop packets that are too large. Perhaps we should truncate
|
|
|
|
* them instead?
|
|
|
|
*/
|
|
|
|
if (len + pad > ETHER_MAX_LEN) {
|
|
|
|
/* packet is obviously too large: toss it */
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_oerrors;
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m);
|
1994-11-13 10:12:37 +00:00
|
|
|
m_freem(m);
|
|
|
|
goto readcheck;
|
|
|
|
}
|
|
|
|
if (inw(BASE + EP_W1_FREE_TX) < len + pad + 4) {
|
|
|
|
/* no room in FIFO */
|
|
|
|
outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4));
|
1997-10-14 06:56:09 +00:00
|
|
|
/* make sure */
|
|
|
|
if (inw(BASE + EP_W1_FREE_TX) < len + pad + 4) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
return;
|
|
|
|
}
|
2000-01-12 06:42:49 +00:00
|
|
|
} else {
|
|
|
|
outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | EP_THRESH_DISABLE);
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
2000-01-12 06:42:49 +00:00
|
|
|
|
1996-02-13 15:55:33 +00:00
|
|
|
IF_DEQUEUE(&ifp->if_snd, m);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2000-01-12 06:42:49 +00:00
|
|
|
s = splhigh();
|
|
|
|
|
1996-07-27 12:40:31 +00:00
|
|
|
outw(BASE + EP_W1_TX_PIO_WR_1, len);
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_W1_TX_PIO_WR_1, 0x0); /* Second dword meaningless */
|
|
|
|
|
2000-01-12 06:42:49 +00:00
|
|
|
if (EP_FTST(sc, F_ACCESS_32_BITS)) {
|
|
|
|
for (top = m; m != 0; m = m->m_next) {
|
2000-03-13 11:59:21 +00:00
|
|
|
if (m->m_len > 3)
|
|
|
|
outsl(BASE + EP_W1_TX_PIO_WR_1,
|
|
|
|
mtod(m, caddr_t), m->m_len / 4);
|
1994-11-13 10:12:37 +00:00
|
|
|
if (m->m_len & 3)
|
|
|
|
outsb(BASE + EP_W1_TX_PIO_WR_1,
|
2000-03-13 11:59:21 +00:00
|
|
|
mtod(m, caddr_t) + (m->m_len & (~3)), m->m_len & 3);
|
2000-01-12 06:42:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (top = m; m != 0; m = m->m_next) {
|
2000-03-24 23:31:42 +00:00
|
|
|
if (m->m_len > 1)
|
2000-03-13 11:59:21 +00:00
|
|
|
outsw(BASE + EP_W1_TX_PIO_WR_1,
|
|
|
|
mtod(m, caddr_t), m->m_len / 2);
|
1994-11-13 10:12:37 +00:00
|
|
|
if (m->m_len & 1)
|
|
|
|
outb(BASE + EP_W1_TX_PIO_WR_1,
|
2000-03-13 11:59:21 +00:00
|
|
|
*(mtod(m, caddr_t) + m->m_len - 1));
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
2000-01-12 06:42:49 +00:00
|
|
|
}
|
1994-09-03 18:10:44 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
while (pad--)
|
|
|
|
outb(BASE + EP_W1_TX_PIO_WR_1, 0); /* Padding */
|
1994-01-26 09:06:29 +00:00
|
|
|
|
2000-01-12 06:42:49 +00:00
|
|
|
splx(s);
|
|
|
|
|
2002-11-14 23:54:55 +00:00
|
|
|
BPF_MTAP(ifp, top);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
ifp->if_timer = 2;
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp->if_opackets++;
|
1994-11-13 10:12:37 +00:00
|
|
|
m_freem(top);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is another packet coming in? We don't want to overflow the tiny RX
|
|
|
|
* fifo.
|
|
|
|
*/
|
1994-01-26 09:06:29 +00:00
|
|
|
readcheck:
|
1994-11-13 10:12:37 +00:00
|
|
|
if (inw(BASE + EP_W1_RX_STATUS) & RX_BYTES_MASK) {
|
|
|
|
/*
|
|
|
|
* we check if we have packets left, in that case we prepare to come
|
|
|
|
* back later
|
|
|
|
*/
|
1996-02-13 15:55:33 +00:00
|
|
|
if (ifp->if_snd.ifq_head) {
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
goto startagain;
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
void
|
|
|
|
ep_intr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct ep_softc *sc;
|
1994-11-13 10:12:37 +00:00
|
|
|
register int status;
|
1996-02-13 15:55:33 +00:00
|
|
|
struct ifnet *ifp;
|
1995-04-10 21:25:06 +00:00
|
|
|
int x;
|
|
|
|
|
1997-10-14 06:56:09 +00:00
|
|
|
x = splbio();
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
sc = (struct ep_softc *)arg;
|
|
|
|
|
2001-06-05 22:29:16 +00:00
|
|
|
/*
|
|
|
|
* quick fix: Try to detect an interrupt when the card goes away.
|
|
|
|
*/
|
2002-02-12 05:32:58 +00:00
|
|
|
if (sc->gone || inw(BASE + EP_STATUS) == 0xffff) {
|
|
|
|
splx(x);
|
2001-06-05 22:29:16 +00:00
|
|
|
return;
|
2002-02-12 05:32:58 +00:00
|
|
|
}
|
1999-10-25 02:52:16 +00:00
|
|
|
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
1995-04-05 13:12:13 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_INTR_MASK); /* disable all Ints */
|
|
|
|
|
1995-03-23 06:53:39 +00:00
|
|
|
rescan:
|
1994-11-13 10:12:37 +00:00
|
|
|
|
|
|
|
while ((status = inw(BASE + EP_STATUS)) & S_5_INTS) {
|
1995-03-31 06:41:38 +00:00
|
|
|
|
|
|
|
/* first acknowledge all interrupt sources */
|
|
|
|
outw(BASE + EP_COMMAND, ACK_INTR | (status & S_MASK));
|
|
|
|
|
2002-02-12 05:32:58 +00:00
|
|
|
if (status & (S_RX_COMPLETE | S_RX_EARLY))
|
1994-11-13 10:12:37 +00:00
|
|
|
epread(sc);
|
1994-01-10 18:56:26 +00:00
|
|
|
if (status & S_TX_AVAIL) {
|
1994-11-13 10:12:37 +00:00
|
|
|
/* we need ACK */
|
1997-10-14 06:56:09 +00:00
|
|
|
ifp->if_timer = 0;
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1995-04-05 13:12:13 +00:00
|
|
|
GO_WINDOW(1);
|
|
|
|
inw(BASE + EP_W1_FREE_TX);
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_if_start(ifp);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
if (status & S_CARD_FAILURE) {
|
1997-10-14 06:56:09 +00:00
|
|
|
ifp->if_timer = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
#ifdef EP_LOCAL_STATS
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("\nep%d:\n\tStatus: %x\n", sc->unit, status);
|
1994-11-13 10:12:37 +00:00
|
|
|
GO_WINDOW(4);
|
|
|
|
printf("\tFIFO Diagnostic: %x\n", inw(BASE + EP_W4_FIFO_DIAG));
|
|
|
|
printf("\tStat: %x\n", sc->stat);
|
|
|
|
printf("\tIpackets=%d, Opackets=%d\n",
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp->if_ipackets, ifp->if_opackets);
|
2000-05-14 02:18:43 +00:00
|
|
|
printf("\tNOF=%d, NOMB=%d, RXOF=%d, RXOL=%d, TXU=%d\n",
|
|
|
|
sc->rx_no_first, sc->rx_no_mbuf, sc->rx_overrunf,
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->rx_overrunl, sc->tx_underrun);
|
|
|
|
#else
|
1996-01-29 03:16:14 +00:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
1996-02-26 01:05:36 +00:00
|
|
|
printf("ep%d: Status: %x (input buffer overflow)\n", sc->unit, status);
|
1996-01-29 03:16:14 +00:00
|
|
|
#else
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_ierrors;
|
1996-01-29 03:16:14 +00:00
|
|
|
#endif
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_if_init(sc);
|
1995-04-10 21:25:06 +00:00
|
|
|
splx(x);
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
if (status & S_TX_COMPLETE) {
|
1997-10-14 06:56:09 +00:00
|
|
|
ifp->if_timer = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
/* we need ACK. we do it at the end */
|
|
|
|
/*
|
|
|
|
* We need to read TX_STATUS until we get a 0 status in order to
|
|
|
|
* turn off the interrupt flag.
|
|
|
|
*/
|
|
|
|
while ((status = inb(BASE + EP_W1_TX_STATUS)) & TXS_COMPLETE) {
|
|
|
|
if (status & TXS_SUCCES_INTR_REQ);
|
|
|
|
else if (status & (TXS_UNDERRUN | TXS_JABBER | TXS_MAX_COLLISION)) {
|
|
|
|
outw(BASE + EP_COMMAND, TX_RESET);
|
|
|
|
if (status & TXS_UNDERRUN) {
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->tx_underrun++;
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
if (status & TXS_JABBER);
|
|
|
|
else /* TXS_MAX_COLLISION - we shouldn't get here */
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_collisions;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_oerrors;
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, TX_ENABLE);
|
|
|
|
/*
|
|
|
|
* To have a tx_avail_int but giving the chance to the
|
|
|
|
* Reception
|
|
|
|
*/
|
1996-02-13 15:55:33 +00:00
|
|
|
if (ifp->if_snd.ifq_head) {
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
|
|
|
|
}
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
outb(BASE + EP_W1_TX_STATUS, 0x0); /* pops up the next
|
|
|
|
* status */
|
|
|
|
} /* while */
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1995-04-05 13:12:13 +00:00
|
|
|
GO_WINDOW(1);
|
|
|
|
inw(BASE + EP_W1_FREE_TX);
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_if_start(ifp);
|
1994-11-13 10:12:37 +00:00
|
|
|
} /* end TX_COMPLETE */
|
|
|
|
}
|
1995-03-23 06:53:39 +00:00
|
|
|
|
|
|
|
outw(BASE + EP_COMMAND, C_INTR_LATCH); /* ACK int Latch */
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
if ((status = inw(BASE + EP_STATUS)) & S_5_INTS)
|
1995-03-23 06:53:39 +00:00
|
|
|
goto rescan;
|
1995-04-05 13:12:13 +00:00
|
|
|
|
|
|
|
/* re-enable Ints */
|
|
|
|
outw(BASE + EP_COMMAND, SET_INTR_MASK | S_5_INTS);
|
|
|
|
|
1995-04-10 21:25:06 +00:00
|
|
|
splx(x);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1994-01-26 09:06:29 +00:00
|
|
|
epread(sc)
|
1994-11-13 10:12:37 +00:00
|
|
|
register struct ep_softc *sc;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1994-11-13 10:12:37 +00:00
|
|
|
struct mbuf *top, *mcur, *m;
|
1996-02-13 15:55:33 +00:00
|
|
|
struct ifnet *ifp;
|
1994-11-13 10:12:37 +00:00
|
|
|
int lenthisone;
|
|
|
|
|
|
|
|
short rx_fifo2, status;
|
|
|
|
register short rx_fifo;
|
|
|
|
|
1996-02-13 15:55:33 +00:00
|
|
|
ifp = &sc->arpcom.ac_if;
|
1994-11-13 10:12:37 +00:00
|
|
|
status = inw(BASE + EP_W1_RX_STATUS);
|
|
|
|
|
|
|
|
read_again:
|
|
|
|
|
|
|
|
if (status & ERR_RX) {
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_ierrors;
|
1994-11-13 10:12:37 +00:00
|
|
|
if (status & ERR_RX_OVERRUN) {
|
|
|
|
/*
|
|
|
|
* we can think the rx latency is actually greather than we
|
|
|
|
* expect
|
|
|
|
*/
|
|
|
|
#ifdef EP_LOCAL_STATS
|
1999-09-26 06:42:36 +00:00
|
|
|
if (EP_FTST(sc, F_RX_FIRST))
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->rx_overrunf++;
|
|
|
|
else
|
|
|
|
sc->rx_overrunl++;
|
|
|
|
#endif
|
1994-01-26 09:06:29 +00:00
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
rx_fifo = rx_fifo2 = status & RX_BYTES_MASK;
|
|
|
|
|
1999-09-26 06:42:36 +00:00
|
|
|
if (EP_FTST(sc, F_RX_FIRST)) {
|
1997-10-14 06:56:09 +00:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (!m)
|
|
|
|
goto out;
|
|
|
|
if (rx_fifo >= MINCLSIZE)
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->top = sc->mcur = top = m;
|
1994-01-26 09:06:29 +00:00
|
|
|
#define EROUND ((sizeof(struct ether_header) + 3) & ~3)
|
|
|
|
#define EOFF (EROUND - sizeof(struct ether_header))
|
1994-11-13 10:12:37 +00:00
|
|
|
top->m_data += EOFF;
|
|
|
|
|
1994-01-10 18:56:26 +00:00
|
|
|
/* Read what should be the header. */
|
1994-01-26 09:06:29 +00:00
|
|
|
insw(BASE + EP_W1_RX_PIO_RD_1,
|
1994-11-13 10:12:37 +00:00
|
|
|
mtod(top, caddr_t), sizeof(struct ether_header) / 2);
|
|
|
|
top->m_len = sizeof(struct ether_header);
|
|
|
|
rx_fifo -= sizeof(struct ether_header);
|
|
|
|
sc->cur_len = rx_fifo2;
|
|
|
|
} else {
|
|
|
|
/* come here if we didn't have a complete packet last time */
|
|
|
|
top = sc->top;
|
|
|
|
m = sc->mcur;
|
|
|
|
sc->cur_len += rx_fifo2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reads what is left in the RX FIFO */
|
|
|
|
while (rx_fifo > 0) {
|
|
|
|
lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
|
|
|
|
if (lenthisone == 0) { /* no room in this one */
|
|
|
|
mcur = m;
|
1997-10-14 06:56:09 +00:00
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (!m)
|
|
|
|
goto out;
|
1994-11-13 10:12:37 +00:00
|
|
|
if (rx_fifo >= MINCLSIZE)
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
m->m_len = 0;
|
|
|
|
mcur->m_next = m;
|
|
|
|
lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
|
|
|
|
}
|
1999-09-26 06:42:36 +00:00
|
|
|
if (EP_FTST(sc, F_ACCESS_32_BITS)) { /* default for EISA configured cards*/
|
1994-11-13 10:12:37 +00:00
|
|
|
insl(BASE + EP_W1_RX_PIO_RD_1, mtod(m, caddr_t) + m->m_len,
|
|
|
|
lenthisone / 4);
|
|
|
|
m->m_len += (lenthisone & ~3);
|
|
|
|
if (lenthisone & 3)
|
|
|
|
insb(BASE + EP_W1_RX_PIO_RD_1,
|
|
|
|
mtod(m, caddr_t) + m->m_len,
|
|
|
|
lenthisone & 3);
|
|
|
|
m->m_len += (lenthisone & 3);
|
|
|
|
} else {
|
|
|
|
insw(BASE + EP_W1_RX_PIO_RD_1, mtod(m, caddr_t) + m->m_len,
|
|
|
|
lenthisone / 2);
|
|
|
|
m->m_len += lenthisone;
|
|
|
|
if (lenthisone & 1)
|
|
|
|
*(mtod(m, caddr_t) + m->m_len - 1) = inb(BASE + EP_W1_RX_PIO_RD_1);
|
|
|
|
}
|
|
|
|
rx_fifo -= lenthisone;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & ERR_RX_INCOMPLETE) { /* we haven't received the complete
|
|
|
|
* packet */
|
|
|
|
sc->mcur = m;
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->rx_no_first++; /* to know how often we come here */
|
|
|
|
#endif
|
1999-09-26 06:42:36 +00:00
|
|
|
EP_FRST(sc, F_RX_FIRST);
|
1994-11-13 10:12:37 +00:00
|
|
|
if (!((status = inw(BASE + EP_W1_RX_STATUS)) & ERR_RX_INCOMPLETE)) {
|
|
|
|
/* we see if by now, the packet has completly arrived */
|
|
|
|
goto read_again;
|
|
|
|
}
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_NEXT_EARLY_THRESH);
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
|
1996-02-13 15:55:33 +00:00
|
|
|
++ifp->if_ipackets;
|
1999-09-26 06:42:36 +00:00
|
|
|
EP_FSET(sc, F_RX_FIRST);
|
1994-11-13 10:12:37 +00:00
|
|
|
top->m_pkthdr.rcvif = &sc->arpcom.ac_if;
|
|
|
|
top->m_pkthdr.len = sc->cur_len;
|
1994-01-26 09:06:29 +00:00
|
|
|
|
2002-11-14 23:54:55 +00:00
|
|
|
(*ifp->if_input)(ifp, top);
|
1994-11-13 10:12:37 +00:00
|
|
|
sc->top = 0;
|
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
out:
|
|
|
|
outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
|
|
|
|
if (sc->top) {
|
|
|
|
m_freem(sc->top);
|
|
|
|
sc->top = 0;
|
|
|
|
#ifdef EP_LOCAL_STATS
|
|
|
|
sc->rx_no_mbuf++;
|
|
|
|
#endif
|
|
|
|
}
|
1999-09-26 06:42:36 +00:00
|
|
|
EP_FSET(sc, F_RX_FIRST);
|
1994-11-13 10:12:37 +00:00
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1997-10-14 06:56:09 +00:00
|
|
|
outw(BASE + EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
static int
|
|
|
|
ep_ifmedia_upd(ifp)
|
|
|
|
struct ifnet * ifp;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1999-10-27 06:25:16 +00:00
|
|
|
struct ep_softc * sc = ifp->if_softc;
|
|
|
|
int i = 0, j;
|
|
|
|
|
|
|
|
GO_WINDOW(0);
|
|
|
|
outw(BASE + EP_COMMAND, STOP_TRANSCEIVER);
|
|
|
|
GO_WINDOW(4);
|
|
|
|
outw(BASE + EP_W4_MEDIA_TYPE, DISABLE_UTP);
|
|
|
|
GO_WINDOW(0);
|
|
|
|
|
|
|
|
switch (IFM_SUBTYPE(sc->ifmedia.ifm_media)) {
|
|
|
|
case IFM_10_T:
|
|
|
|
if (sc->ep_connectors & UTP) {
|
|
|
|
i = ACF_CONNECTOR_UTP;
|
|
|
|
GO_WINDOW(4);
|
|
|
|
outw(BASE + EP_W4_MEDIA_TYPE, ENABLE_UTP);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IFM_10_2:
|
|
|
|
if (sc->ep_connectors & BNC) {
|
|
|
|
i = ACF_CONNECTOR_BNC;
|
|
|
|
outw(BASE + EP_COMMAND, START_TRANSCEIVER);
|
|
|
|
DELAY(DELAY_MULTIPLE * 1000);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IFM_10_5:
|
|
|
|
if (sc->ep_connectors & AUI)
|
|
|
|
i = ACF_CONNECTOR_AUI;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
i = sc->ep_connector;
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"strange connector type in EEPROM: assuming AUI\n");
|
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
GO_WINDOW(0);
|
|
|
|
j = inw(BASE + EP_W0_ADDRESS_CFG) & 0x3fff;
|
|
|
|
outw(BASE + EP_W0_ADDRESS_CFG, j | (i << ACF_CONNECTOR_BITS));
|
1995-07-05 07:21:34 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
return (0);
|
|
|
|
}
|
1999-08-18 06:12:00 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
static void
|
|
|
|
ep_ifmedia_sts(ifp, ifmr)
|
|
|
|
struct ifnet * ifp;
|
|
|
|
struct ifmediareq * ifmr;
|
|
|
|
{
|
|
|
|
struct ep_softc * sc = ifp->if_softc;
|
1996-01-29 03:16:14 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
ifmr->ifm_active = sc->ifmedia.ifm_media;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
1995-03-31 06:41:38 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
static int
|
|
|
|
ep_if_ioctl(ifp, cmd, data)
|
|
|
|
struct ifnet * ifp;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
|
|
|
struct ep_softc * sc = ifp->if_softc;
|
|
|
|
struct ifreq * ifr = (struct ifreq *)data;
|
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
if (((ifp->if_flags & IFF_UP) == 0) &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING)) {
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
epstop(sc);
|
|
|
|
} else {
|
|
|
|
/* reinitialize card on any parameter change */
|
|
|
|
ep_if_init(sc);
|
|
|
|
}
|
|
|
|
break;
|
1994-01-10 18:56:26 +00:00
|
|
|
#ifdef notdef
|
1999-10-27 06:25:16 +00:00
|
|
|
case SIOCGHWADDR:
|
|
|
|
bcopy((caddr_t) sc->sc_addr, (caddr_t) & ifr->ifr_data,
|
|
|
|
sizeof(sc->sc_addr));
|
|
|
|
break;
|
1994-01-10 18:56:26 +00:00
|
|
|
#endif
|
1996-01-29 03:16:14 +00:00
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
1999-10-27 06:25:16 +00:00
|
|
|
/*
|
|
|
|
* The Etherlink III has no programmable multicast
|
|
|
|
* filter. We always initialize the card to be
|
|
|
|
* promiscuous to multicast, since we're always a
|
|
|
|
* member of the ALL-SYSTEMS group, so there's no
|
|
|
|
* need to process SIOC*MULTI requests.
|
|
|
|
*/
|
|
|
|
error = 0;
|
|
|
|
break;
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
2000-01-15 05:21:43 +00:00
|
|
|
if (!sc->epb.mii_trans) {
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, cmd);
|
|
|
|
} else {
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
1999-10-27 06:25:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-11-14 23:54:55 +00:00
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
1999-10-27 06:25:16 +00:00
|
|
|
break;
|
|
|
|
}
|
1995-07-05 07:21:34 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
(void)splx(s);
|
1995-07-05 07:21:34 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
return (error);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_if_watchdog(ifp)
|
1995-12-05 02:01:59 +00:00
|
|
|
struct ifnet *ifp;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1996-06-14 22:11:38 +00:00
|
|
|
struct ep_softc *sc = ifp->if_softc;
|
|
|
|
|
1995-04-05 13:12:13 +00:00
|
|
|
/*
|
|
|
|
printf("ep: watchdog\n");
|
1994-01-26 09:13:56 +00:00
|
|
|
|
1995-12-05 02:01:59 +00:00
|
|
|
log(LOG_ERR, "ep%d: watchdog\n", ifp->if_unit);
|
|
|
|
ifp->if_oerrors++;
|
1995-04-05 13:12:13 +00:00
|
|
|
*/
|
|
|
|
|
1996-06-14 22:11:38 +00:00
|
|
|
if (sc->gone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-04-05 13:12:13 +00:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1999-10-27 06:25:16 +00:00
|
|
|
ep_if_start(ifp);
|
1996-02-26 01:05:36 +00:00
|
|
|
ep_intr(ifp->if_softc);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1996-02-26 01:05:36 +00:00
|
|
|
epstop(sc)
|
|
|
|
struct ep_softc *sc;
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
1996-06-14 22:11:38 +00:00
|
|
|
if (sc->gone) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, RX_DISABLE);
|
|
|
|
outw(BASE + EP_COMMAND, RX_DISCARD_TOP_PACK);
|
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
2000-03-13 11:55:09 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, TX_DISABLE);
|
|
|
|
outw(BASE + EP_COMMAND, STOP_TRANSCEIVER);
|
2000-03-13 11:55:09 +00:00
|
|
|
DELAY(800);
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, RX_RESET);
|
2000-03-13 11:55:09 +00:00
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, TX_RESET);
|
1997-10-14 06:56:09 +00:00
|
|
|
while (inw(BASE + EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
2000-03-13 11:55:09 +00:00
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
outw(BASE + EP_COMMAND, C_INTR_LATCH);
|
|
|
|
outw(BASE + EP_COMMAND, SET_RD_0_MASK);
|
|
|
|
outw(BASE + EP_COMMAND, SET_INTR_MASK);
|
|
|
|
outw(BASE + EP_COMMAND, SET_RX_FILTER);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|