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-01-24 20:53:45 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
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-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>
|
2003-07-17 19:37:56 +00:00
|
|
|
#include <sys/rman.h>
|
1999-10-27 06:25:16 +00:00
|
|
|
|
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>
|
2003-07-17 19:37:56 +00:00
|
|
|
#include <net/if_media.h>
|
1999-10-27 06:25:16 +00:00
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
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
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
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 */
|
2003-07-17 19:37:56 +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 */
|
2003-07-17 19:37:56 +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
|
|
|
|
2003-07-17 19:37:56 +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
|
2003-07-17 19:37:56 +00:00
|
|
|
eeprom_rdy(struct ep_softc *sc)
|
1994-11-13 10:12:37 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
int i;
|
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
for (i = 0; is_eeprom_busy(sc) && i < MAX_EEPROMBUSY; i++)
|
2003-07-17 19:37:56 +00:00
|
|
|
DELAY(100);
|
|
|
|
|
|
|
|
if (i >= MAX_EEPROMBUSY) {
|
|
|
|
printf("ep%d: eeprom failed to come ready.\n", sc->unit);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
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
|
|
|
*/
|
2003-03-29 21:44:46 +00:00
|
|
|
int
|
2003-07-17 19:37:56 +00:00
|
|
|
get_e(struct ep_softc *sc, u_int16_t offset, u_int16_t *result)
|
1994-11-13 10:12:37 +00:00
|
|
|
{
|
2003-03-29 21:44:46 +00:00
|
|
|
|
|
|
|
if (eeprom_rdy(sc))
|
|
|
|
return (ENXIO);
|
2003-07-17 19:37:56 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_W0_EEPROM_COMMAND,
|
2003-07-17 19:37:56 +00:00
|
|
|
(EEPROM_CMD_RD << sc->epb.cmd_off) | offset);
|
|
|
|
|
2003-03-29 21:44:46 +00:00
|
|
|
if (eeprom_rdy(sc))
|
|
|
|
return (ENXIO);
|
2003-07-17 19:37:56 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
(*result) = EP_READ_2(sc, EP_W0_EEPROM_DATA);
|
2003-03-29 21:44:46 +00:00
|
|
|
|
2000-01-15 05:21:43 +00:00
|
|
|
return (0);
|
1996-02-26 01:05:36 +00:00
|
|
|
}
|
|
|
|
|
2003-03-29 21:44:46 +00:00
|
|
|
int
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_get_macaddr(struct ep_softc *sc, u_char *addr)
|
1996-02-26 01:05:36 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
int i;
|
|
|
|
u_int16_t result;
|
|
|
|
int error;
|
|
|
|
u_int16_t *macaddr;
|
2003-03-29 21:44:46 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
macaddr = (u_int16_t *) addr;
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
GO_WINDOW(0);
|
2003-07-17 19:37:56 +00:00
|
|
|
for (i = EEPROM_NODE_ADDR_0; i <= EEPROM_NODE_ADDR_2; i++) {
|
2003-03-29 21:44:46 +00:00
|
|
|
error = get_e(sc, i, &result);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
macaddr[i] = htons(result);
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
1996-02-26 01:05:36 +00:00
|
|
|
|
2003-03-29 21:44:46 +00:00
|
|
|
return (0);
|
1999-10-27 06:25:16 +00:00
|
|
|
}
|
1996-02-26 01:05:36 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
int
|
|
|
|
ep_alloc(device_t dev)
|
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc = device_get_softc(dev);
|
|
|
|
int rid;
|
|
|
|
int error = 0;
|
|
|
|
u_int16_t result;
|
|
|
|
|
|
|
|
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");
|
1999-10-27 06:25:16 +00:00
|
|
|
error = ENXIO;
|
2003-07-17 19:37:56 +00:00
|
|
|
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");
|
1999-10-27 06:25:16 +00:00
|
|
|
error = ENXIO;
|
2003-07-17 19:37:56 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
sc->dev = dev;
|
|
|
|
sc->unit = device_get_unit(dev);
|
|
|
|
sc->stat = 0; /* 16 bit access */
|
1999-10-27 06:25:16 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
sc->bst = rman_get_bustag(sc->iobase);
|
|
|
|
sc->bsh = rman_get_bushandle(sc->iobase);
|
1999-10-27 06:25:16 +00:00
|
|
|
|
|
|
|
sc->ep_connectors = 0;
|
|
|
|
sc->ep_connector = 0;
|
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
GO_WINDOW(0);
|
1999-10-27 06:25:16 +00:00
|
|
|
sc->epb.cmd_off = 0;
|
2003-03-29 21:44:46 +00:00
|
|
|
|
|
|
|
error = get_e(sc, EEPROM_PROD_ID, &result);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
sc->epb.prod_id = result;
|
|
|
|
|
|
|
|
error = get_e(sc, EEPROM_RESOURCE_CFG, &result);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
sc->epb.res_cfg = result;
|
1999-10-27 06:25:16 +00:00
|
|
|
|
|
|
|
bad:
|
|
|
|
return (error);
|
1996-02-26 01:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_get_media(struct ep_softc *sc)
|
1996-02-26 01:05:36 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
u_int16_t config;
|
|
|
|
|
|
|
|
GO_WINDOW(0);
|
2003-10-18 15:22:43 +00:00
|
|
|
config = EP_READ_2(sc, EP_W0_CONFIG_CTRL);
|
2003-07-17 19:37:56 +00:00
|
|
|
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))
|
1999-10-27 06:25:16 +00:00
|
|
|
if (bootverbose)
|
2003-07-17 19:37:56 +00:00
|
|
|
device_printf(sc->dev, "no connectors!\n");
|
1999-10-27 06:25:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This works for most of the cards so we'll do it here.
|
|
|
|
* The cards that require something different can override
|
|
|
|
* this later on.
|
|
|
|
*/
|
2003-10-18 15:22:43 +00:00
|
|
|
sc->ep_connector = EP_READ_2(sc, EP_W0_ADDRESS_CFG) >> ACF_CONNECTOR_BITS;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
void
|
|
|
|
ep_free(device_t dev)
|
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc = device_get_softc(dev);
|
1999-10-27 06:25:16 +00:00
|
|
|
|
2003-03-29 22:27:41 +00:00
|
|
|
if (sc->ep_intrhand)
|
|
|
|
bus_teardown_intr(dev, sc->irq, sc->ep_intrhand);
|
1999-10-27 06:25:16 +00:00
|
|
|
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);
|
|
|
|
}
|
2003-07-17 19:37:56 +00:00
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
int
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_attach(struct ep_softc *sc)
|
1996-02-26 01:05:36 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ifnet *ifp = NULL;
|
|
|
|
struct ifmedia *ifm = NULL;
|
|
|
|
u_short *p;
|
|
|
|
int i;
|
|
|
|
int attached;
|
|
|
|
int error;
|
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
|
|
|
|
2003-03-29 21:44:46 +00:00
|
|
|
error = ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr);
|
|
|
|
if (error) {
|
2003-08-30 08:10:58 +00:00
|
|
|
device_printf(sc->dev, "Unable to get Ethernet address!\n");
|
2003-03-29 21:44:46 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
1999-10-27 06:25:16 +00:00
|
|
|
/*
|
|
|
|
* Setup the station address
|
|
|
|
*/
|
|
|
|
p = (u_short *)&sc->arpcom.ac_enaddr;
|
|
|
|
GO_WINDOW(2);
|
2003-07-17 19:37:56 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, 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",
|
2003-07-17 19:37:56 +00:00
|
|
|
sc->arpcom.ac_enaddr, ":");
|
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
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)
|
2003-08-30 08:10:58 +00:00
|
|
|
ifmedia_add(&sc->ifmedia,
|
|
|
|
IFM_ETHER | IFM_10_5, 0, NULL);
|
1999-10-27 06:25:16 +00:00
|
|
|
if (sc->ep_connectors & UTP)
|
2003-08-30 08:10:58 +00:00
|
|
|
ifmedia_add(&sc->ifmedia,
|
|
|
|
IFM_ETHER | IFM_10_T, 0, NULL);
|
1999-10-27 06:25:16 +00:00
|
|
|
if (sc->ep_connectors & BNC)
|
2003-08-30 08:10:58 +00:00
|
|
|
ifmedia_add(&sc->ifmedia,
|
|
|
|
IFM_ETHER | IFM_10_2, 0, NULL);
|
1999-10-27 06:25:16 +00:00
|
|
|
if (!sc->ep_connectors)
|
2003-08-30 08:10:58 +00:00
|
|
|
ifmedia_add(&sc->ifmedia,
|
|
|
|
IFM_ETHER | IFM_NONE, 0, NULL);
|
2003-07-17 19:37:56 +00:00
|
|
|
|
2003-08-30 08:10:58 +00:00
|
|
|
ifmedia_set(&sc->ifmedia,
|
|
|
|
IFM_ETHER | ep_media2if_media[sc->ep_connector]);
|
2003-07-17 19:37:56 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
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 =
|
2003-07-17 19:37:56 +00:00
|
|
|
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);
|
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
return (0);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
2003-03-29 22:27:41 +00:00
|
|
|
int
|
|
|
|
ep_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct ep_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
|
|
|
|
if (sc->gone) {
|
|
|
|
device_printf(dev, "already unloaded\n");
|
|
|
|
return (0);
|
|
|
|
}
|
2003-08-19 14:06:42 +00:00
|
|
|
if (bus_child_present(dev))
|
|
|
|
epstop(sc);
|
2003-03-29 22:27:41 +00:00
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
ether_ifdetach(ifp);
|
|
|
|
|
|
|
|
sc->gone = 1;
|
|
|
|
ep_free(dev);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
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
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_if_init(void *xsc)
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc = xsc;
|
|
|
|
struct ifnet *ifp = &sc->arpcom.ac_if;
|
|
|
|
int s, i;
|
1996-06-14 22:11:38 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
if (sc->gone)
|
|
|
|
return;
|
1994-01-10 19:13:50 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
s = splimp();
|
2003-10-18 15:22:43 +00:00
|
|
|
while (EP_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
GO_WINDOW(0);
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
|
2003-07-17 19:37:56 +00:00
|
|
|
GO_WINDOW(4);
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_W4_MEDIA_TYPE, DISABLE_UTP);
|
2003-07-17 19:37:56 +00:00
|
|
|
GO_WINDOW(0);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/* Disable the card */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_W0_CONFIG_CTRL, 0);
|
1994-01-26 09:13:56 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/* Enable the card */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_W0_CONFIG_CTRL, ENABLE_DRQ_IRQ);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
GO_WINDOW(2);
|
1994-01-26 09:13:56 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/* Reload the ether_addr. */
|
|
|
|
for (i = 0; i < 6; i++)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_1(sc, EP_W2_ADDR_0 + i, sc->arpcom.ac_enaddr[i]);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, RX_RESET);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, TX_RESET);
|
|
|
|
while (EP_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/* Window 1 is operating window */
|
|
|
|
GO_WINDOW(1);
|
|
|
|
for (i = 0; i < 31; i++)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_READ_1(sc, EP_W1_TX_STATUS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/* get rid of stray intr's */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, ACK_INTR | 0xff);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK | S_5_INTS);
|
1994-01-10 18:56:26 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK | S_5_INTS);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
|
2003-07-17 19:37:56 +00:00
|
|
|
FIL_GROUP | FIL_BRDCST | FIL_ALL);
|
|
|
|
else
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER | FIL_INDIVIDUAL |
|
2003-07-17 19:37:56 +00:00
|
|
|
FIL_GROUP | FIL_BRDCST);
|
1997-10-14 06:56:09 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
if (!sc->epb.mii_trans)
|
|
|
|
ep_ifmedia_upd(ifp);
|
1995-03-31 06:41:38 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, RX_ENABLE);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, TX_ENABLE);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE; /* just in case */
|
1994-11-13 10:12:37 +00:00
|
|
|
|
|
|
|
#ifdef EP_LOCAL_STATS
|
2003-07-17 19:37:56 +00:00
|
|
|
sc->rx_no_first = sc->rx_no_mbuf =
|
|
|
|
sc->rx_overrunf = sc->rx_overrunl = sc->tx_underrun = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
2003-07-17 19:37:56 +00:00
|
|
|
EP_FSET(sc, F_RX_FIRST);
|
|
|
|
if (sc->top) {
|
|
|
|
m_freem(sc->top);
|
|
|
|
sc->top = sc->mcur = 0;
|
|
|
|
}
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_TX_START_THRESH | 16);
|
1995-04-10 21:25:06 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/*
|
2003-08-30 08:10:58 +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.
|
|
|
|
*/
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
GO_WINDOW(1);
|
|
|
|
ep_if_start(ifp);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
splx(s);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_if_start(struct ifnet *ifp)
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc;
|
|
|
|
u_int len;
|
|
|
|
struct mbuf *m, *m0;
|
|
|
|
int s, pad;
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
sc = ifp->if_softc;
|
|
|
|
if (sc->gone)
|
|
|
|
return;
|
1996-06-14 22:11:38 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
while (EP_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
2003-07-17 19:37:56 +00:00
|
|
|
if (ifp->if_flags & IFF_OACTIVE)
|
|
|
|
return;
|
2000-01-12 06:42:49 +00:00
|
|
|
|
1994-01-10 18:56:26 +00:00
|
|
|
startagain:
|
2003-07-17 19:37:56 +00:00
|
|
|
/* Sneak a peek at the next packet */
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, m0);
|
|
|
|
if (m0 == NULL)
|
|
|
|
return;
|
|
|
|
for (len = 0, m = m0; m != NULL; m = m->m_next)
|
|
|
|
len += m->m_len;
|
|
|
|
|
|
|
|
pad = (4 - len) & 3;
|
|
|
|
|
|
|
|
/*
|
2003-08-30 08:10:58 +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?
|
|
|
|
*/
|
2003-07-17 19:37:56 +00:00
|
|
|
if (len + pad > ETHER_MAX_LEN) {
|
|
|
|
/* packet is obviously too large: toss it */
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
m_freem(m0);
|
|
|
|
goto readcheck;
|
2000-01-12 06:42:49 +00:00
|
|
|
}
|
2003-10-18 15:22:43 +00:00
|
|
|
if (EP_READ_2(sc, EP_W1_FREE_TX) < len + pad + 4) {
|
2003-07-17 19:37:56 +00:00
|
|
|
/* no room in FIFO */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_TX_AVAIL_THRESH | (len + pad + 4));
|
2003-07-17 19:37:56 +00:00
|
|
|
/* make sure */
|
2003-10-18 15:22:43 +00:00
|
|
|
if (EP_READ_2(sc, EP_W1_FREE_TX) < len + pad + 4) {
|
2003-07-17 19:37:56 +00:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
IF_PREPEND(&ifp->if_snd, m0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND,
|
2003-08-30 08:10:58 +00:00
|
|
|
SET_TX_AVAIL_THRESH | EP_THRESH_DISABLE);
|
2003-07-17 19:37:56 +00:00
|
|
|
|
|
|
|
s = splhigh();
|
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_W1_TX_PIO_WR_1, len);
|
2003-08-30 08:10:58 +00:00
|
|
|
/* Second dword meaningless */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_W1_TX_PIO_WR_1, 0x0);
|
2003-07-17 19:37:56 +00:00
|
|
|
|
|
|
|
if (EP_FTST(sc, F_ACCESS_32_BITS)) {
|
|
|
|
for (m = m0; m != NULL; m = m->m_next) {
|
|
|
|
if (m->m_len > 3)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_MULTI_4(sc, EP_W1_TX_PIO_WR_1,
|
|
|
|
mtod(m, uint32_t *), m->m_len / 4);
|
2003-07-17 19:37:56 +00:00
|
|
|
if (m->m_len & 3)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_MULTI_1(sc, EP_W1_TX_PIO_WR_1,
|
|
|
|
mtod(m, uint8_t *)+(m->m_len & (~3)),
|
2003-08-30 08:10:58 +00:00
|
|
|
m->m_len & 3);
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (m = m0; m != NULL; m = m->m_next) {
|
|
|
|
if (m->m_len > 1)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_MULTI_2(sc, EP_W1_TX_PIO_WR_1,
|
|
|
|
mtod(m, uint16_t *), m->m_len / 2);
|
2003-07-17 19:37:56 +00:00
|
|
|
if (m->m_len & 1)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_1(sc, EP_W1_TX_PIO_WR_1,
|
|
|
|
*(mtod(m, uint8_t *)+m->m_len - 1));
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
1994-09-03 18:10:44 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
while (pad--)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_1(sc, EP_W1_TX_PIO_WR_1, 0); /* Padding */
|
1994-01-26 09:06:29 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
splx(s);
|
2000-01-12 06:42:49 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
BPF_MTAP(ifp, m0);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
ifp->if_timer = 2;
|
|
|
|
ifp->if_opackets++;
|
|
|
|
m_freem(m0);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
|
|
|
/*
|
2003-08-30 08:10:58 +00:00
|
|
|
* Is another packet coming in? We don't want to overflow
|
|
|
|
* the tiny RX fifo.
|
|
|
|
*/
|
2003-07-17 19:37:56 +00:00
|
|
|
readcheck:
|
2003-10-18 15:22:43 +00:00
|
|
|
if (EP_READ_2(sc, EP_W1_RX_STATUS) & RX_BYTES_MASK) {
|
2003-07-17 19:37:56 +00:00
|
|
|
/*
|
2003-08-30 08:10:58 +00:00
|
|
|
* we check if we have packets left, in that case
|
|
|
|
* we prepare to come back later
|
2003-07-17 19:37:56 +00:00
|
|
|
*/
|
|
|
|
if (ifp->if_snd.ifq_head)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_TX_AVAIL_THRESH | 8);
|
2003-07-17 19:37:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
goto startagain;
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1996-02-26 01:05:36 +00:00
|
|
|
void
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_intr(void *arg)
|
1996-02-26 01:05:36 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc;
|
|
|
|
int status;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int x;
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
x = splbio();
|
1996-02-26 01:05:36 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
sc = (struct ep_softc *) arg;
|
1999-10-25 02:52:16 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/*
|
2003-08-30 08:10:58 +00:00
|
|
|
* quick fix: Try to detect an interrupt when the card goes away.
|
|
|
|
*/
|
2003-10-18 15:22:43 +00:00
|
|
|
if (sc->gone || EP_READ_2(sc, EP_STATUS) == 0xffff) {
|
2003-07-17 19:37:56 +00:00
|
|
|
splx(x);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
1996-02-13 15:55:33 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK); /* disable all Ints */
|
1995-04-05 13:12:13 +00:00
|
|
|
|
1995-03-23 06:53:39 +00:00
|
|
|
rescan:
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
while ((status = EP_READ_2(sc, EP_STATUS)) & S_5_INTS) {
|
1995-03-31 06:41:38 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/* first acknowledge all interrupt sources */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, ACK_INTR | (status & S_MASK));
|
1995-03-31 06:41:38 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
if (status & (S_RX_COMPLETE | S_RX_EARLY))
|
|
|
|
epread(sc);
|
|
|
|
if (status & S_TX_AVAIL) {
|
|
|
|
/* we need ACK */
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
GO_WINDOW(1);
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_READ_2(sc, EP_W1_FREE_TX);
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_if_start(ifp);
|
|
|
|
}
|
|
|
|
if (status & S_CARD_FAILURE) {
|
|
|
|
ifp->if_timer = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
#ifdef EP_LOCAL_STATS
|
2003-07-17 19:37:56 +00:00
|
|
|
printf("\nep%d:\n\tStatus: %x\n", sc->unit, status);
|
|
|
|
GO_WINDOW(4);
|
2003-08-30 08:10:58 +00:00
|
|
|
printf("\tFIFO Diagnostic: %x\n",
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_READ_2(sc, EP_W4_FIFO_DIAG));
|
2003-07-17 19:37:56 +00:00
|
|
|
printf("\tStat: %x\n", sc->stat);
|
|
|
|
printf("\tIpackets=%d, Opackets=%d\n",
|
|
|
|
ifp->if_ipackets, ifp->if_opackets);
|
|
|
|
printf("\tNOF=%d, NOMB=%d, RXOF=%d, RXOL=%d, TXU=%d\n",
|
|
|
|
sc->rx_no_first, sc->rx_no_mbuf, sc->rx_overrunf,
|
|
|
|
sc->rx_overrunl, sc->tx_underrun);
|
1994-11-13 10:12:37 +00:00
|
|
|
#else
|
1996-01-29 03:16:14 +00:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
2003-08-30 08:10:58 +00:00
|
|
|
printf("ep%d: Status: %x (input buffer overflow)\n",
|
|
|
|
sc->unit, status);
|
1996-01-29 03:16:14 +00:00
|
|
|
#else
|
2003-07-17 19:37:56 +00:00
|
|
|
++ifp->if_ierrors;
|
1996-01-29 03:16:14 +00:00
|
|
|
#endif
|
|
|
|
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_if_init(sc);
|
|
|
|
splx(x);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (status & S_TX_COMPLETE) {
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
/*
|
2003-08-30 08:10:58 +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.
|
2003-07-17 19:37:56 +00:00
|
|
|
*/
|
2003-10-18 15:22:43 +00:00
|
|
|
while ((status = EP_READ_1(sc, EP_W1_TX_STATUS)) &
|
2003-08-30 08:10:58 +00:00
|
|
|
TXS_COMPLETE) {
|
2003-07-17 19:37:56 +00:00
|
|
|
if (status & TXS_SUCCES_INTR_REQ);
|
2003-08-30 08:10:58 +00:00
|
|
|
else if (status &
|
|
|
|
(TXS_UNDERRUN | TXS_JABBER |
|
|
|
|
TXS_MAX_COLLISION)) {
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, TX_RESET);
|
2003-07-17 19:37:56 +00:00
|
|
|
if (status & TXS_UNDERRUN) {
|
1994-11-13 10:12:37 +00:00
|
|
|
#ifdef EP_LOCAL_STATS
|
2003-07-17 19:37:56 +00:00
|
|
|
sc->tx_underrun++;
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
2003-07-17 19:37:56 +00:00
|
|
|
} else {
|
|
|
|
if (status & TXS_JABBER);
|
2003-08-30 08:10:58 +00:00
|
|
|
else
|
2003-07-17 19:37:56 +00:00
|
|
|
++ifp->if_collisions;
|
2003-08-30 08:10:58 +00:00
|
|
|
/* TXS_MAX_COLLISION
|
|
|
|
* we shouldn't get
|
|
|
|
* here
|
|
|
|
*/
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
|
|
|
++ifp->if_oerrors;
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, TX_ENABLE);
|
2003-07-17 19:37:56 +00:00
|
|
|
/*
|
2003-08-30 08:10:58 +00:00
|
|
|
* To have a tx_avail_int but giving
|
|
|
|
* the chance to the Reception
|
2003-07-17 19:37:56 +00:00
|
|
|
*/
|
|
|
|
if (ifp->if_snd.ifq_head)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND,
|
2003-08-30 08:10:58 +00:00
|
|
|
SET_TX_AVAIL_THRESH | 8);
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
2003-08-30 08:10:58 +00:00
|
|
|
/* pops up the next status */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_1(sc, EP_W1_TX_STATUS, 0x0);
|
2003-07-17 19:37:56 +00:00
|
|
|
} /* while */
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
GO_WINDOW(1);
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_READ_2(sc, EP_W1_FREE_TX);
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_if_start(ifp);
|
2003-08-30 08:10:58 +00:00
|
|
|
} /* end TX_COMPLETE */
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
1995-03-23 06:53:39 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, C_INTR_LATCH); /* ACK int Latch */
|
1995-03-23 06:53:39 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
if ((status = EP_READ_2(sc, EP_STATUS)) & S_5_INTS)
|
2003-07-17 19:37:56 +00:00
|
|
|
goto rescan;
|
1995-04-05 13:12:13 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/* re-enable Ints */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK | S_5_INTS);
|
1995-04-05 13:12:13 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
splx(x);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
2003-07-17 19:37:56 +00:00
|
|
|
epread(struct ep_softc *sc)
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct mbuf *top, *mcur, *m;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int lenthisone;
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
short rx_fifo2, status;
|
|
|
|
short rx_fifo;
|
1994-11-13 10:12:37 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
ifp = &sc->arpcom.ac_if;
|
2003-10-18 15:22:43 +00:00
|
|
|
status = EP_READ_2(sc, EP_W1_RX_STATUS);
|
1994-11-13 10:12:37 +00:00
|
|
|
|
|
|
|
read_again:
|
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
if (status & ERR_RX) {
|
|
|
|
++ifp->if_ierrors;
|
|
|
|
if (status & ERR_RX_OVERRUN) {
|
|
|
|
/*
|
2003-08-30 08:10:58 +00:00
|
|
|
* We can think the rx latency is actually
|
|
|
|
* greather than we expect
|
2003-07-17 19:37:56 +00:00
|
|
|
*/
|
1994-11-13 10:12:37 +00:00
|
|
|
#ifdef EP_LOCAL_STATS
|
2003-07-17 19:37:56 +00:00
|
|
|
if (EP_FTST(sc, F_RX_FIRST))
|
|
|
|
sc->rx_overrunf++;
|
|
|
|
else
|
|
|
|
sc->rx_overrunl++;
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
|
|
|
goto out;
|
1994-01-26 09:06:29 +00:00
|
|
|
}
|
2003-07-17 19:37:56 +00:00
|
|
|
rx_fifo = rx_fifo2 = status & RX_BYTES_MASK;
|
|
|
|
|
|
|
|
if (EP_FTST(sc, F_RX_FIRST)) {
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (!m)
|
|
|
|
goto out;
|
|
|
|
if (rx_fifo >= MINCLSIZE)
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
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))
|
2003-07-17 19:37:56 +00:00
|
|
|
top->m_data += EOFF;
|
|
|
|
|
|
|
|
/* Read what should be the header. */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_READ_MULTI_2(sc, EP_W1_RX_PIO_RD_1,
|
|
|
|
mtod(top, uint16_t *), sizeof(struct ether_header) / 2);
|
2003-07-17 19:37:56 +00:00
|
|
|
top->m_len = sizeof(struct ether_header);
|
|
|
|
rx_fifo -= sizeof(struct ether_header);
|
|
|
|
sc->cur_len = rx_fifo2;
|
1994-11-13 10:12:37 +00:00
|
|
|
} else {
|
2003-07-17 19:37:56 +00:00
|
|
|
/* come here if we didn't have a complete packet last time */
|
|
|
|
top = sc->top;
|
|
|
|
m = sc->mcur;
|
|
|
|
sc->cur_len += rx_fifo2;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/* 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;
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (!m)
|
|
|
|
goto out;
|
|
|
|
if (rx_fifo >= MINCLSIZE)
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
m->m_len = 0;
|
|
|
|
mcur->m_next = m;
|
|
|
|
lenthisone = min(rx_fifo, M_TRAILINGSPACE(m));
|
|
|
|
}
|
2003-08-30 08:10:58 +00:00
|
|
|
if (EP_FTST(sc, F_ACCESS_32_BITS)) {
|
|
|
|
/* default for EISA configured cards */
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_READ_MULTI_4(sc, EP_W1_RX_PIO_RD_1,
|
2003-10-23 03:42:47 +00:00
|
|
|
(uint32_t *)(mtod(m, caddr_t)+m->m_len),
|
2003-07-17 19:37:56 +00:00
|
|
|
lenthisone / 4);
|
|
|
|
m->m_len += (lenthisone & ~3);
|
|
|
|
if (lenthisone & 3)
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_READ_MULTI_1(sc, EP_W1_RX_PIO_RD_1,
|
2003-08-30 08:10:58 +00:00
|
|
|
mtod(m, caddr_t)+m->m_len, lenthisone & 3);
|
2003-07-17 19:37:56 +00:00
|
|
|
m->m_len += (lenthisone & 3);
|
|
|
|
} else {
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_READ_MULTI_2(sc, EP_W1_RX_PIO_RD_1,
|
2003-10-23 03:42:47 +00:00
|
|
|
(uint16_t *)mtod(m, caddr_t)+m->m_len),
|
|
|
|
lenthisone / 2);
|
2003-07-17 19:37:56 +00:00
|
|
|
m->m_len += lenthisone;
|
|
|
|
if (lenthisone & 1)
|
2003-08-30 08:10:58 +00:00
|
|
|
*(mtod(m, caddr_t)+m->m_len - 1) =
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_READ_1(sc, EP_W1_RX_PIO_RD_1);
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
|
|
|
rx_fifo -= lenthisone;
|
|
|
|
}
|
|
|
|
|
2003-08-30 08:10:58 +00:00
|
|
|
if (status & ERR_RX_INCOMPLETE) {
|
|
|
|
/* we haven't received the complete packet */
|
2003-07-17 19:37:56 +00:00
|
|
|
sc->mcur = m;
|
1994-11-13 10:12:37 +00:00
|
|
|
#ifdef EP_LOCAL_STATS
|
2003-08-30 08:10:58 +00:00
|
|
|
/* to know how often we come here */
|
|
|
|
sc->rx_no_first++;
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
2003-07-17 19:37:56 +00:00
|
|
|
EP_FRST(sc, F_RX_FIRST);
|
2003-10-18 15:22:43 +00:00
|
|
|
status = EP_READ_2(sc, EP_W1_RX_STATUS);
|
2003-08-30 08:10:58 +00:00
|
|
|
if (!status & ERR_RX_INCOMPLETE) {
|
2003-07-17 19:37:56 +00:00
|
|
|
/*
|
2003-08-30 08:10:58 +00:00
|
|
|
* We see if by now, the packet has completly
|
2003-07-17 19:37:56 +00:00
|
|
|
* arrived
|
|
|
|
*/
|
|
|
|
goto read_again;
|
|
|
|
}
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND,
|
2003-08-30 08:10:58 +00:00
|
|
|
SET_RX_EARLY_THRESH | RX_NEXT_EARLY_THRESH);
|
2003-07-17 19:37:56 +00:00
|
|
|
return;
|
1994-11-13 10:12:37 +00:00
|
|
|
}
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
|
2003-07-17 19:37:56 +00:00
|
|
|
++ifp->if_ipackets;
|
|
|
|
EP_FSET(sc, F_RX_FIRST);
|
|
|
|
top->m_pkthdr.rcvif = &sc->arpcom.ac_if;
|
|
|
|
top->m_pkthdr.len = sc->cur_len;
|
|
|
|
|
|
|
|
(*ifp->if_input) (ifp, top);
|
|
|
|
sc->top = 0;
|
2003-10-18 15:22:43 +00:00
|
|
|
while (EP_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
1994-11-13 10:12:37 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
out:
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
|
2003-07-17 19:37:56 +00:00
|
|
|
if (sc->top) {
|
|
|
|
m_freem(sc->top);
|
|
|
|
sc->top = 0;
|
1994-11-13 10:12:37 +00:00
|
|
|
#ifdef EP_LOCAL_STATS
|
2003-07-17 19:37:56 +00:00
|
|
|
sc->rx_no_mbuf++;
|
1994-11-13 10:12:37 +00:00
|
|
|
#endif
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
|
|
|
EP_FSET(sc, F_RX_FIRST);
|
2003-10-18 15:22:43 +00:00
|
|
|
while (EP_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_RX_EARLY_THRESH | RX_INIT_EARLY_THRESH);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
static int
|
|
|
|
ep_ifmedia_upd(struct ifnet *ifp)
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc = ifp->if_softc;
|
|
|
|
int i = 0, j;
|
1999-10-27 06:25:16 +00:00
|
|
|
|
|
|
|
GO_WINDOW(0);
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
|
1999-10-27 06:25:16 +00:00
|
|
|
GO_WINDOW(4);
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_W4_MEDIA_TYPE, DISABLE_UTP);
|
1999-10-27 06:25:16 +00:00
|
|
|
GO_WINDOW(0);
|
|
|
|
|
|
|
|
switch (IFM_SUBTYPE(sc->ifmedia.ifm_media)) {
|
2003-07-17 19:37:56 +00:00
|
|
|
case IFM_10_T:
|
|
|
|
if (sc->ep_connectors & UTP) {
|
|
|
|
i = ACF_CONNECTOR_UTP;
|
|
|
|
GO_WINDOW(4);
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_W4_MEDIA_TYPE, ENABLE_UTP);
|
2003-07-17 19:37:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IFM_10_2:
|
|
|
|
if (sc->ep_connectors & BNC) {
|
|
|
|
i = ACF_CONNECTOR_BNC;
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, START_TRANSCEIVER);
|
2003-07-17 19:37:56 +00:00
|
|
|
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");
|
1999-10-27 06:25:16 +00:00
|
|
|
}
|
1994-11-13 10:12:37 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
GO_WINDOW(0);
|
2003-10-18 15:22:43 +00:00
|
|
|
j = EP_READ_2(sc, EP_W0_ADDRESS_CFG) & 0x3fff;
|
|
|
|
EP_WRITE_2(sc, 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
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
|
1999-10-27 06:25:16 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
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;
|
|
|
|
}
|
1995-03-31 06:41:38 +00:00
|
|
|
|
1999-10-27 06:25:16 +00:00
|
|
|
static int
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_if_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
|
1999-10-27 06:25:16 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc = ifp->if_softc;
|
|
|
|
struct ifreq *ifr = (struct ifreq *) data;
|
1999-10-27 06:25:16 +00:00
|
|
|
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);
|
2003-07-17 19:37:56 +00:00
|
|
|
} else
|
1999-10-27 06:25:16 +00:00
|
|
|
/* 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:
|
2003-07-17 19:37:56 +00:00
|
|
|
bcopy((caddr_t)sc->sc_addr, (caddr_t)&ifr->ifr_data,
|
|
|
|
sizeof(sc->sc_addr));
|
1999-10-27 06:25:16 +00:00
|
|
|
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:
|
2003-07-17 19:37:56 +00:00
|
|
|
if (!sc->epb.mii_trans)
|
2000-01-15 05:21:43 +00:00
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, cmd);
|
2003-07-17 19:37:56 +00:00
|
|
|
else
|
2000-01-15 05:21:43 +00:00
|
|
|
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
|
2003-07-17 19:37:56 +00:00
|
|
|
ep_if_watchdog(struct ifnet *ifp)
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
struct ep_softc *sc = ifp->if_softc;
|
1994-01-26 09:13:56 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
/*
|
2003-08-30 08:10:58 +00:00
|
|
|
printf("ep: watchdog\n");
|
1995-04-05 13:12:13 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
log(LOG_ERR, "ep%d: watchdog\n", ifp->if_unit);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
*/
|
1996-06-14 22:11:38 +00:00
|
|
|
|
2003-07-17 19:37:56 +00:00
|
|
|
if (sc->gone)
|
|
|
|
return;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
ep_if_start(ifp);
|
|
|
|
ep_intr(ifp->if_softc);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
2003-07-17 19:37:56 +00:00
|
|
|
epstop(struct ep_softc *sc)
|
1994-01-10 18:56:26 +00:00
|
|
|
{
|
2003-07-17 19:37:56 +00:00
|
|
|
if (sc->gone)
|
|
|
|
return;
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, RX_DISABLE);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, RX_DISCARD_TOP_PACK);
|
|
|
|
while (EP_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
1996-06-14 22:11:38 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, TX_DISABLE);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, STOP_TRANSCEIVER);
|
2003-07-17 19:37:56 +00:00
|
|
|
DELAY(800);
|
2000-03-13 11:55:09 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, RX_RESET);
|
|
|
|
while (EP_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, TX_RESET);
|
|
|
|
while (EP_READ_2(sc, EP_STATUS) & S_COMMAND_IN_PROGRESS);
|
2000-03-13 11:55:09 +00:00
|
|
|
|
2003-10-18 15:22:43 +00:00
|
|
|
EP_WRITE_2(sc, EP_COMMAND, C_INTR_LATCH);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_RD_0_MASK);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_INTR_MASK);
|
|
|
|
EP_WRITE_2(sc, EP_COMMAND, SET_RX_FILTER);
|
1994-01-10 18:56:26 +00:00
|
|
|
}
|