2005-01-06 01:43:34 +00:00
|
|
|
|
/*-
|
1997-01-16 12:19:21 +00:00
|
|
|
|
* Copyright (c) 1996, Javier Mart<EFBFBD>n Rueda (jmrueda@diatel.upm.es)
|
|
|
|
|
* 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 unmodified, this list of conditions, and the following
|
|
|
|
|
* disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE 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.
|
1997-09-26 17:17:43 +00:00
|
|
|
|
*
|
1999-10-16 06:26:44 +00:00
|
|
|
|
*
|
|
|
|
|
* MAINTAINER: Matthew N. Dodd <winter@jurai.net>
|
|
|
|
|
* <mdodd@FreeBSD.org>
|
1997-01-16 12:19:21 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
1997-01-16 12:19:21 +00:00
|
|
|
|
/*
|
1997-09-26 17:17:43 +00:00
|
|
|
|
* Intel EtherExpress Pro/10, Pro/10+ Ethernet driver
|
1997-01-16 12:19:21 +00:00
|
|
|
|
*
|
|
|
|
|
* Revision history:
|
|
|
|
|
*
|
2003-03-28 02:15:01 +00:00
|
|
|
|
* dd-mmm-yyyy: Multicast support ported from NetBSD's if_iy driver.
|
1997-01-16 12:19:21 +00:00
|
|
|
|
* 30-Oct-1996: first beta version. Inet and BPF supported, but no multicast.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/systm.h>
|
1999-10-16 06:26:44 +00:00
|
|
|
|
#include <sys/kernel.h>
|
1997-03-24 11:33:46 +00:00
|
|
|
|
#include <sys/sockio.h>
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
#include <sys/module.h>
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#include <net/if.h>
|
2000-03-13 12:23:32 +00:00
|
|
|
|
#include <net/if_arp.h>
|
2003-03-28 02:15:01 +00:00
|
|
|
|
#include <net/if_dl.h>
|
2000-03-13 12:23:32 +00:00
|
|
|
|
#include <net/if_media.h>
|
2005-06-10 16:49:24 +00:00
|
|
|
|
#include <net/if_types.h>
|
2000-03-13 12:23:32 +00:00
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
|
#include <net/bpf.h>
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-08-18 22:14:24 +00:00
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
|
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
#include <isa/isavar.h>
|
|
|
|
|
#include <isa/pnpvar.h>
|
|
|
|
|
|
2000-01-14 07:14:17 +00:00
|
|
|
|
#include <dev/ex/if_exreg.h>
|
2000-05-01 09:05:19 +00:00
|
|
|
|
#include <dev/ex/if_exvar.h>
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
#ifdef EXDEBUG
|
1999-10-16 06:26:44 +00:00
|
|
|
|
# define Start_End 1
|
|
|
|
|
# define Rcvd_Pkts 2
|
|
|
|
|
# define Sent_Pkts 4
|
|
|
|
|
# define Status 8
|
1997-01-16 12:19:21 +00:00
|
|
|
|
static int debug_mask = 0;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
# define DODEBUG(level, action) if (level & debug_mask) action
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#else
|
1999-10-16 06:26:44 +00:00
|
|
|
|
# define DODEBUG(level, action)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2003-03-29 15:38:53 +00:00
|
|
|
|
devclass_t ex_devclass;
|
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
char irq2eemap[] =
|
1999-10-16 06:26:44 +00:00
|
|
|
|
{ -1, -1, 0, 1, -1, 2, -1, -1, -1, 0, 3, 4, -1, -1, -1, -1 };
|
2000-05-01 09:05:19 +00:00
|
|
|
|
u_char ee2irqmap[] =
|
1999-10-16 06:26:44 +00:00
|
|
|
|
{ 9, 3, 5, 10, 11, 0, 0, 0 };
|
2000-05-01 09:05:19 +00:00
|
|
|
|
|
|
|
|
|
char plus_irq2eemap[] =
|
1999-10-16 06:26:44 +00:00
|
|
|
|
{ -1, -1, -1, 0, 1, 2, -1, 3, -1, 4, 5, 6, 7, -1, -1, -1 };
|
2000-05-01 09:05:19 +00:00
|
|
|
|
u_char plus_ee2irqmap[] =
|
1999-10-16 06:26:44 +00:00
|
|
|
|
{ 3, 4, 5, 7, 9, 10, 11, 12 };
|
|
|
|
|
|
|
|
|
|
/* Network Interface Functions */
|
2004-06-27 13:10:20 +00:00
|
|
|
|
static void ex_init(void *);
|
|
|
|
|
static void ex_start(struct ifnet *);
|
|
|
|
|
static int ex_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
|
static void ex_watchdog(struct ifnet *);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
2000-03-13 12:23:32 +00:00
|
|
|
|
/* ifmedia Functions */
|
2004-06-27 13:10:20 +00:00
|
|
|
|
static int ex_ifmedia_upd(struct ifnet *);
|
|
|
|
|
static void ex_ifmedia_sts(struct ifnet *, struct ifmediareq *);
|
2000-03-13 12:23:32 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
static int ex_get_media(struct ex_softc *);
|
2000-05-01 09:05:19 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
static void ex_reset(struct ex_softc *);
|
|
|
|
|
static void ex_setmulti(struct ex_softc *);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
static void ex_tx_intr(struct ex_softc *);
|
|
|
|
|
static void ex_rx_intr(struct ex_softc *);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
void
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ex_get_address(struct ex_softc *sc, u_char *enaddr)
|
1999-10-16 06:26:44 +00:00
|
|
|
|
{
|
2004-06-27 13:10:20 +00:00
|
|
|
|
uint16_t eaddr_tmp;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
eaddr_tmp = ex_eeprom_read(sc, EE_Eth_Addr_Lo);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
enaddr[5] = eaddr_tmp & 0xff;
|
|
|
|
|
enaddr[4] = eaddr_tmp >> 8;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
eaddr_tmp = ex_eeprom_read(sc, EE_Eth_Addr_Mid);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
enaddr[3] = eaddr_tmp & 0xff;
|
|
|
|
|
enaddr[2] = eaddr_tmp >> 8;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
eaddr_tmp = ex_eeprom_read(sc, EE_Eth_Addr_Hi);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
enaddr[1] = eaddr_tmp & 0xff;
|
|
|
|
|
enaddr[0] = eaddr_tmp >> 8;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
int
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ex_card_type(u_char *enaddr)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
1999-10-16 06:26:44 +00:00
|
|
|
|
if ((enaddr[0] == 0x00) && (enaddr[1] == 0xA0) && (enaddr[2] == 0xC9))
|
|
|
|
|
return (CARD_TYPE_EX_10_PLUS);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
return (CARD_TYPE_EX_10);
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 06:52:51 +00:00
|
|
|
|
/*
|
2000-05-01 09:05:19 +00:00
|
|
|
|
* Caller is responsible for eventually calling
|
|
|
|
|
* ex_release_resources() on failure.
|
2000-01-13 06:52:51 +00:00
|
|
|
|
*/
|
2000-05-01 09:05:19 +00:00
|
|
|
|
int
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ex_alloc_resources(device_t dev)
|
2000-01-13 06:52:51 +00:00
|
|
|
|
{
|
2000-05-01 09:05:19 +00:00
|
|
|
|
struct ex_softc * sc = device_get_softc(dev);
|
|
|
|
|
int error = 0;
|
2000-01-13 06:52:51 +00:00
|
|
|
|
|
2004-03-17 17:50:55 +00:00
|
|
|
|
sc->ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT,
|
|
|
|
|
&sc->ioport_rid, RF_ACTIVE);
|
2000-05-01 09:05:19 +00:00
|
|
|
|
if (!sc->ioport) {
|
|
|
|
|
device_printf(dev, "No I/O space?!\n");
|
|
|
|
|
error = ENOMEM;
|
|
|
|
|
goto bad;
|
|
|
|
|
}
|
2004-06-27 13:10:20 +00:00
|
|
|
|
sc->bst = rman_get_bustag(sc->ioport);
|
|
|
|
|
sc->bsh = rman_get_bushandle(sc->ioport);
|
2000-01-13 06:52:51 +00:00
|
|
|
|
|
2004-03-17 17:50:55 +00:00
|
|
|
|
sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
|
|
|
|
|
RF_ACTIVE);
|
2000-03-13 12:27:21 +00:00
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
if (!sc->irq) {
|
|
|
|
|
device_printf(dev, "No IRQ?!\n");
|
|
|
|
|
error = ENOMEM;
|
|
|
|
|
goto bad;
|
2000-01-13 06:52:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
bad:
|
|
|
|
|
return (error);
|
2000-01-13 06:52:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
void
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ex_release_resources(device_t dev)
|
1999-10-16 06:26:44 +00:00
|
|
|
|
{
|
2000-05-01 09:05:19 +00:00
|
|
|
|
struct ex_softc * sc = device_get_softc(dev);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
if (sc->ih) {
|
|
|
|
|
bus_teardown_intr(dev, sc->irq, sc->ih);
|
|
|
|
|
sc->ih = NULL;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
if (sc->ioport) {
|
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT,
|
|
|
|
|
sc->ioport_rid, sc->ioport);
|
|
|
|
|
sc->ioport = NULL;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
if (sc->irq) {
|
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ,
|
|
|
|
|
sc->irq_rid, sc->irq);
|
|
|
|
|
sc->irq = NULL;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
return;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
int
|
|
|
|
|
ex_attach(device_t dev)
|
1999-10-16 06:26:44 +00:00
|
|
|
|
{
|
|
|
|
|
struct ex_softc * sc = device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
|
struct ifnet * ifp;
|
2000-03-13 12:23:32 +00:00
|
|
|
|
struct ifmedia * ifm;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
uint16_t temp;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
|
ifp = sc->ifp = if_alloc(IFT_ETHER);
|
|
|
|
|
if (ifp == NULL) {
|
|
|
|
|
device_printf(dev, "can not if_alloc()\n");
|
|
|
|
|
return (ENOSPC);
|
|
|
|
|
}
|
1997-09-26 17:17:43 +00:00
|
|
|
|
/* work out which set of irq <-> internal tables to use */
|
2005-06-10 16:49:24 +00:00
|
|
|
|
if (ex_card_type(sc->enaddr) == CARD_TYPE_EX_10_PLUS) {
|
1997-09-26 17:17:43 +00:00
|
|
|
|
sc->irq2ee = plus_irq2eemap;
|
|
|
|
|
sc->ee2irq = plus_ee2irqmap;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
} else {
|
1997-09-26 17:17:43 +00:00
|
|
|
|
sc->irq2ee = irq2eemap;
|
|
|
|
|
sc->ee2irq = ee2irqmap;
|
|
|
|
|
}
|
|
|
|
|
|
1997-01-16 12:19:21 +00:00
|
|
|
|
sc->mem_size = CARD_RAM_SIZE; /* XXX This should be read from the card itself. */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Initialize the ifnet structure.
|
|
|
|
|
*/
|
|
|
|
|
ifp->if_softc = sc;
|
2003-10-31 18:32:15 +00:00
|
|
|
|
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
|
2000-01-13 06:55:35 +00:00
|
|
|
|
ifp->if_mtu = ETHERMTU;
|
2004-08-13 23:06:55 +00:00
|
|
|
|
ifp->if_flags = IFF_SIMPLEX | IFF_BROADCAST | IFF_MULTICAST |
|
|
|
|
|
IFF_NEEDSGIANT;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
ifp->if_start = ex_start;
|
|
|
|
|
ifp->if_ioctl = ex_ioctl;
|
|
|
|
|
ifp->if_watchdog = ex_watchdog;
|
2000-01-13 06:55:35 +00:00
|
|
|
|
ifp->if_init = ex_init;
|
|
|
|
|
ifp->if_snd.ifq_maxlen = IFQ_MAXLEN;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
2000-03-13 12:23:32 +00:00
|
|
|
|
ifmedia_init(&sc->ifmedia, 0, ex_ifmedia_upd, ex_ifmedia_sts);
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
temp = ex_eeprom_read(sc, EE_W5);
|
2000-03-13 12:23:32 +00:00
|
|
|
|
if (temp & EE_W5_PORT_TPE)
|
|
|
|
|
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_T, 0, NULL);
|
|
|
|
|
if (temp & EE_W5_PORT_BNC)
|
|
|
|
|
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_2, 0, NULL);
|
|
|
|
|
if (temp & EE_W5_PORT_AUI)
|
|
|
|
|
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_10_5, 0, NULL);
|
|
|
|
|
|
2003-03-29 01:40:42 +00:00
|
|
|
|
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_AUTO, 0, NULL);
|
|
|
|
|
ifmedia_add(&sc->ifmedia, IFM_ETHER|IFM_NONE, 0, NULL);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ifmedia_set(&sc->ifmedia, ex_get_media(sc));
|
2000-03-13 12:23:32 +00:00
|
|
|
|
|
|
|
|
|
ifm = &sc->ifmedia;
|
|
|
|
|
ifm->ifm_media = ifm->ifm_cur->ifm_media;
|
|
|
|
|
ex_ifmedia_upd(ifp);
|
|
|
|
|
|
1997-01-16 12:19:21 +00:00
|
|
|
|
/*
|
|
|
|
|
* Attach the interface.
|
|
|
|
|
*/
|
2005-06-10 16:49:24 +00:00
|
|
|
|
ether_ifattach(ifp, sc->enaddr);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
return(0);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-29 15:34:26 +00:00
|
|
|
|
int
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ex_detach(device_t dev)
|
2003-03-29 15:34:26 +00:00
|
|
|
|
{
|
|
|
|
|
struct ex_softc *sc;
|
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
|
ifp = sc->ifp;
|
2003-03-29 15:34:26 +00:00
|
|
|
|
|
|
|
|
|
ex_stop(sc);
|
|
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
|
ether_ifdetach(ifp);
|
2005-06-10 16:49:24 +00:00
|
|
|
|
if_free(ifp);
|
2003-03-29 15:34:26 +00:00
|
|
|
|
|
|
|
|
|
ex_release_resources(dev);
|
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-13 06:55:35 +00:00
|
|
|
|
static void
|
|
|
|
|
ex_init(void *xsc)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
1999-10-16 06:26:44 +00:00
|
|
|
|
struct ex_softc * sc = (struct ex_softc *) xsc;
|
2005-06-10 16:49:24 +00:00
|
|
|
|
struct ifnet * ifp = sc->ifp;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
int s;
|
|
|
|
|
int i;
|
|
|
|
|
unsigned short temp_reg;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
2003-10-31 18:32:15 +00:00
|
|
|
|
DODEBUG(Start_End, printf("%s: ex_init: start\n", ifp->if_xname););
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
s = splimp();
|
2000-05-01 09:05:19 +00:00
|
|
|
|
ifp->if_timer = 0;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Load the ethernet address into the card.
|
|
|
|
|
*/
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank2_Sel);
|
|
|
|
|
temp_reg = CSR_READ_1(sc, EEPROM_REG);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
if (temp_reg & Trnoff_Enable) {
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, temp_reg & ~Trnoff_Enable);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++) {
|
2005-06-10 16:49:24 +00:00
|
|
|
|
CSR_WRITE_1(sc, I_ADDR_REG0 + i, IFP2ENADDR(sc->ifp)[i]);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
1997-01-16 12:19:21 +00:00
|
|
|
|
/*
|
|
|
|
|
* - Setup transmit chaining and discard bad received frames.
|
|
|
|
|
* - Match broadcast.
|
|
|
|
|
* - Clear test mode.
|
|
|
|
|
* - Set receiving mode.
|
|
|
|
|
* - Set IRQ number.
|
|
|
|
|
*/
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, REG1, CSR_READ_1(sc, REG1) | Tx_Chn_Int_Md | Tx_Chn_ErStp | Disc_Bad_Fr);
|
|
|
|
|
CSR_WRITE_1(sc, REG2, CSR_READ_1(sc, REG2) | No_SA_Ins | RX_CRC_InMem);
|
|
|
|
|
CSR_WRITE_1(sc, REG3, CSR_READ_1(sc, REG3) & 0x3f /* XXX constants. */ );
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank1_Sel);
|
|
|
|
|
CSR_WRITE_1(sc, INT_NO_REG, (CSR_READ_1(sc, INT_NO_REG) & 0xf8) | sc->irq2ee[sc->irq_no]);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Divide the available memory in the card into rcv and xmt buffers.
|
|
|
|
|
* By default, I use the first 3/4 of the memory for the rcv buffer,
|
|
|
|
|
* and the remaining 1/4 of the memory for the xmt buffer.
|
|
|
|
|
*/
|
|
|
|
|
sc->rx_mem_size = sc->mem_size * 3 / 4;
|
|
|
|
|
sc->tx_mem_size = sc->mem_size - sc->rx_mem_size;
|
|
|
|
|
sc->rx_lower_limit = 0x0000;
|
|
|
|
|
sc->rx_upper_limit = sc->rx_mem_size - 2;
|
|
|
|
|
sc->tx_lower_limit = sc->rx_mem_size;
|
|
|
|
|
sc->tx_upper_limit = sc->mem_size - 2;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, RCV_LOWER_LIMIT_REG, sc->rx_lower_limit >> 8);
|
|
|
|
|
CSR_WRITE_1(sc, RCV_UPPER_LIMIT_REG, sc->rx_upper_limit >> 8);
|
|
|
|
|
CSR_WRITE_1(sc, XMT_LOWER_LIMIT_REG, sc->tx_lower_limit >> 8);
|
|
|
|
|
CSR_WRITE_1(sc, XMT_UPPER_LIMIT_REG, sc->tx_upper_limit >> 8);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Enable receive and transmit interrupts, and clear any pending int.
|
|
|
|
|
*/
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, REG1, CSR_READ_1(sc, REG1) | TriST_INT);
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank0_Sel);
|
|
|
|
|
CSR_WRITE_1(sc, MASK_REG, All_Int & ~(Rx_Int | Tx_Int));
|
|
|
|
|
CSR_WRITE_1(sc, STATUS_REG, All_Int);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Initialize receive and transmit ring buffers.
|
|
|
|
|
*/
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, RCV_BAR, sc->rx_lower_limit);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
sc->rx_head = sc->rx_lower_limit;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, RCV_STOP_REG, sc->rx_upper_limit | 0xfe);
|
|
|
|
|
CSR_WRITE_2(sc, XMT_BAR, sc->tx_lower_limit);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
sc->tx_head = sc->tx_tail = sc->tx_lower_limit;
|
|
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
DODEBUG(Status, printf("OIDLE init\n"););
|
|
|
|
|
|
2003-03-28 02:15:01 +00:00
|
|
|
|
ex_setmulti(sc);
|
|
|
|
|
|
1997-01-16 12:19:21 +00:00
|
|
|
|
/*
|
|
|
|
|
* Final reset of the board, and enable operation.
|
|
|
|
|
*/
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Sel_Reset_CMD);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
DELAY(2);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Rcv_Enable_CMD);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
ex_start(ifp);
|
|
|
|
|
splx(s);
|
|
|
|
|
|
2003-10-31 18:32:15 +00:00
|
|
|
|
DODEBUG(Start_End, printf("%s: ex_init: finish\n", ifp->if_xname););
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 06:55:35 +00:00
|
|
|
|
static void
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ex_start(struct ifnet *ifp)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
1999-10-16 06:26:44 +00:00
|
|
|
|
struct ex_softc * sc = ifp->if_softc;
|
|
|
|
|
int i, s, len, data_len, avail, dest, next;
|
|
|
|
|
unsigned char tmp16[2];
|
|
|
|
|
struct mbuf * opkt;
|
|
|
|
|
struct mbuf * m;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
DODEBUG(Start_End, printf("ex_start%d: start\n", unit););
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
s = splimp();
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
/*
|
1999-10-16 06:26:44 +00:00
|
|
|
|
* Main loop: send outgoing packets to network card until there are no
|
|
|
|
|
* more packets left, or the card cannot accept any more yet.
|
1997-01-16 12:19:21 +00:00
|
|
|
|
*/
|
1999-10-16 06:26:44 +00:00
|
|
|
|
while (((opkt = ifp->if_snd.ifq_head) != NULL) &&
|
|
|
|
|
!(ifp->if_flags & IFF_OACTIVE)) {
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
/*
|
|
|
|
|
* Ensure there is enough free transmit buffer space for
|
|
|
|
|
* this packet, including its header. Note: the header
|
|
|
|
|
* cannot wrap around the end of the transmit buffer and
|
|
|
|
|
* must be kept together, so we allow space for twice the
|
|
|
|
|
* length of the header, just in case.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
for (len = 0, m = opkt; m != NULL; m = m->m_next) {
|
|
|
|
|
len += m->m_len;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
data_len = len;
|
|
|
|
|
|
|
|
|
|
DODEBUG(Sent_Pkts, printf("1. Sending packet with %d data bytes. ", data_len););
|
|
|
|
|
|
|
|
|
|
if (len & 1) {
|
|
|
|
|
len += XMT_HEADER_LEN + 1;
|
|
|
|
|
} else {
|
|
|
|
|
len += XMT_HEADER_LEN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((i = sc->tx_tail - sc->tx_head) >= 0) {
|
|
|
|
|
avail = sc->tx_mem_size - i;
|
|
|
|
|
} else {
|
|
|
|
|
avail = -i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DODEBUG(Sent_Pkts, printf("i=%d, avail=%d\n", i, avail););
|
|
|
|
|
|
|
|
|
|
if (avail >= len + XMT_HEADER_LEN) {
|
|
|
|
|
IF_DEQUEUE(&ifp->if_snd, opkt);
|
|
|
|
|
|
|
|
|
|
#ifdef EX_PSA_INTR
|
|
|
|
|
/*
|
|
|
|
|
* Disable rx and tx interrupts, to avoid corruption
|
|
|
|
|
* of the host address register by interrupt service
|
|
|
|
|
* routines.
|
|
|
|
|
* XXX Is this necessary with splimp() enabled?
|
|
|
|
|
*/
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, MASK_REG, All_Int);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Compute the start and end addresses of this
|
|
|
|
|
* frame in the tx buffer.
|
|
|
|
|
*/
|
|
|
|
|
dest = sc->tx_tail;
|
|
|
|
|
next = dest + len;
|
|
|
|
|
|
|
|
|
|
if (next > sc->tx_upper_limit) {
|
|
|
|
|
if ((sc->tx_upper_limit + 2 - sc->tx_tail) <=
|
|
|
|
|
XMT_HEADER_LEN) {
|
|
|
|
|
dest = sc->tx_lower_limit;
|
|
|
|
|
next = dest + len;
|
2000-01-13 06:46:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
next = sc->tx_lower_limit +
|
|
|
|
|
next - sc->tx_upper_limit - 2;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Build the packet frame in the card's ring buffer.
|
|
|
|
|
*/
|
|
|
|
|
DODEBUG(Sent_Pkts, printf("2. dest=%d, next=%d. ", dest, next););
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, HOST_ADDR_REG, dest);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, Transmit_CMD);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, 0);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, next);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, data_len);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Output the packet data to the card. Ensure all
|
|
|
|
|
* transfers are 16-bit wide, even if individual
|
|
|
|
|
* mbufs have odd length.
|
|
|
|
|
*/
|
|
|
|
|
for (m = opkt, i = 0; m != NULL; m = m->m_next) {
|
|
|
|
|
DODEBUG(Sent_Pkts, printf("[%d]", m->m_len););
|
|
|
|
|
if (i) {
|
|
|
|
|
tmp16[1] = *(mtod(m, caddr_t));
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_MULTI_2(sc, IO_PORT_REG,
|
|
|
|
|
(uint16_t *) tmp16, 1);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_MULTI_2(sc, IO_PORT_REG,
|
|
|
|
|
(uint16_t *) (mtod(m, caddr_t) + i),
|
|
|
|
|
(m->m_len - i) / 2);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
if ((i = (m->m_len - i) & 1) != 0) {
|
|
|
|
|
tmp16[0] = *(mtod(m, caddr_t) +
|
|
|
|
|
m->m_len - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-06-27 13:10:20 +00:00
|
|
|
|
if (i)
|
|
|
|
|
CSR_WRITE_MULTI_2(sc, IO_PORT_REG,
|
|
|
|
|
(uint16_t *) tmp16, 1);
|
2000-01-13 06:46:02 +00:00
|
|
|
|
/*
|
|
|
|
|
* If there were other frames chained, update the
|
|
|
|
|
* chain in the last one.
|
|
|
|
|
*/
|
|
|
|
|
if (sc->tx_head != sc->tx_tail) {
|
|
|
|
|
if (sc->tx_tail != dest) {
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, HOST_ADDR_REG,
|
2000-01-13 06:46:02 +00:00
|
|
|
|
sc->tx_last + XMT_Chain_Point);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, dest);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, HOST_ADDR_REG,
|
2000-01-13 06:46:02 +00:00
|
|
|
|
sc->tx_last + XMT_Byte_Count);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
i = CSR_READ_2(sc, IO_PORT_REG);
|
|
|
|
|
CSR_WRITE_2(sc, HOST_ADDR_REG,
|
2000-01-13 06:46:02 +00:00
|
|
|
|
sc->tx_last + XMT_Byte_Count);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, i | Ch_bit);
|
2000-01-13 06:46:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Resume normal operation of the card:
|
|
|
|
|
* - Make a dummy read to flush the DRAM write
|
|
|
|
|
* pipeline.
|
|
|
|
|
* - Enable receive and transmit interrupts.
|
|
|
|
|
* - Send Transmit or Resume_XMT command, as
|
|
|
|
|
* appropriate.
|
|
|
|
|
*/
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_READ_2(sc, IO_PORT_REG);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#ifdef EX_PSA_INTR
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, MASK_REG, All_Int & ~(Rx_Int | Tx_Int));
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#endif
|
2000-01-13 06:46:02 +00:00
|
|
|
|
if (sc->tx_head == sc->tx_tail) {
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, XMT_BAR, dest);
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Transmit_CMD);
|
2000-01-13 06:46:02 +00:00
|
|
|
|
sc->tx_head = dest;
|
|
|
|
|
DODEBUG(Sent_Pkts, printf("Transmit\n"););
|
1999-10-16 06:26:44 +00:00
|
|
|
|
} else {
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Resume_XMT_List_CMD);
|
2000-01-13 06:46:02 +00:00
|
|
|
|
DODEBUG(Sent_Pkts, printf("Resume\n"););
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
2000-01-13 06:46:02 +00:00
|
|
|
|
|
|
|
|
|
sc->tx_last = dest;
|
|
|
|
|
sc->tx_tail = next;
|
|
|
|
|
|
2002-11-14 23:54:55 +00:00
|
|
|
|
BPF_MTAP(ifp, opkt);
|
2000-01-13 06:46:02 +00:00
|
|
|
|
|
|
|
|
|
ifp->if_timer = 2;
|
|
|
|
|
ifp->if_opackets++;
|
|
|
|
|
m_freem(opkt);
|
|
|
|
|
} else {
|
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
|
DODEBUG(Status, printf("OACTIVE start\n"););
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
splx(s);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
DODEBUG(Start_End, printf("ex_start%d: finish\n", unit););
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-29 03:58:06 +00:00
|
|
|
|
void
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ex_stop(struct ex_softc *sc)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
2004-06-27 13:10:20 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
DODEBUG(Start_End, printf("ex_stop%d: start\n", unit););
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Disable card operation:
|
|
|
|
|
* - Disable the interrupt line.
|
|
|
|
|
* - Flush transmission and disable reception.
|
|
|
|
|
* - Mask and clear all interrupts.
|
|
|
|
|
* - Reset the 82595.
|
|
|
|
|
*/
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank1_Sel);
|
|
|
|
|
CSR_WRITE_1(sc, REG1, CSR_READ_1(sc, REG1) & ~TriST_INT);
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank0_Sel);
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Rcv_Stop);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
sc->tx_head = sc->tx_tail = sc->tx_lower_limit;
|
|
|
|
|
sc->tx_last = 0; /* XXX I think these two lines are not necessary, because ex_init will always be called again to reinit the interface. */
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, MASK_REG, All_Int);
|
|
|
|
|
CSR_WRITE_1(sc, STATUS_REG, All_Int);
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Reset_CMD);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
DELAY(200);
|
|
|
|
|
|
|
|
|
|
DODEBUG(Start_End, printf("ex_stop%d: finish\n", unit););
|
|
|
|
|
|
|
|
|
|
return;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
void
|
2000-01-13 06:55:35 +00:00
|
|
|
|
ex_intr(void *arg)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
2004-06-27 13:10:20 +00:00
|
|
|
|
struct ex_softc *sc = (struct ex_softc *)arg;
|
2005-06-10 16:49:24 +00:00
|
|
|
|
struct ifnet *ifp = sc->ifp;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
int int_status, send_pkts;
|
|
|
|
|
int loops = 100;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
2000-01-13 06:55:35 +00:00
|
|
|
|
DODEBUG(Start_End, printf("ex_intr%d: start\n", unit););
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
send_pkts = 0;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
while (loops-- > 0 &&
|
|
|
|
|
(int_status = CSR_READ_1(sc, STATUS_REG)) & (Tx_Int | Rx_Int)) {
|
|
|
|
|
/* don't loop forever */
|
|
|
|
|
if (int_status == 0xff)
|
|
|
|
|
break;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
if (int_status & Rx_Int) {
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, STATUS_REG, Rx_Int);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ex_rx_intr(sc);
|
|
|
|
|
} else if (int_status & Tx_Int) {
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, STATUS_REG, Tx_Int);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ex_tx_intr(sc);
|
|
|
|
|
send_pkts = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-06-27 13:10:20 +00:00
|
|
|
|
if (loops == 0)
|
|
|
|
|
printf("100 loops are not enough\n");
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If any packet has been transmitted, and there are queued packets to
|
|
|
|
|
* be sent, attempt to send more packets to the network card.
|
|
|
|
|
*/
|
2004-06-27 13:10:20 +00:00
|
|
|
|
if (send_pkts && (ifp->if_snd.ifq_head != NULL))
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ex_start(ifp);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
2000-01-13 06:55:35 +00:00
|
|
|
|
DODEBUG(Start_End, printf("ex_intr%d: finish\n", unit););
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
static void
|
|
|
|
|
ex_tx_intr(struct ex_softc *sc)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
|
struct ifnet * ifp = sc->ifp;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
int tx_status;
|
|
|
|
|
|
|
|
|
|
DODEBUG(Start_End, printf("ex_tx_intr%d: start\n", unit););
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* - Cancel the watchdog.
|
|
|
|
|
* For all packets transmitted since last transmit interrupt:
|
|
|
|
|
* - Advance chain pointer to next queued packet.
|
|
|
|
|
* - Update statistics.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
|
|
|
|
|
while (sc->tx_head != sc->tx_tail) {
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, HOST_ADDR_REG, sc->tx_head);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
if (! CSR_READ_2(sc, IO_PORT_REG) & Done_bit)
|
1999-10-16 06:26:44 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
tx_status = CSR_READ_2(sc, IO_PORT_REG);
|
|
|
|
|
sc->tx_head = CSR_READ_2(sc, IO_PORT_REG);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
if (tx_status & TX_OK_bit) {
|
|
|
|
|
ifp->if_opackets++;
|
|
|
|
|
} else {
|
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
|
}
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ifp->if_collisions += tx_status & No_Collisions_bits;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The card should be ready to accept more packets now.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
|
|
DODEBUG(Status, printf("OIDLE tx_intr\n"););
|
|
|
|
|
DODEBUG(Start_End, printf("ex_tx_intr%d: finish\n", unit););
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ex_rx_intr(struct ex_softc *sc)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
|
struct ifnet * ifp = sc->ifp;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
int rx_status;
|
|
|
|
|
int pkt_len;
|
|
|
|
|
int QQQ;
|
|
|
|
|
struct mbuf * m;
|
|
|
|
|
struct mbuf * ipkt;
|
|
|
|
|
struct ether_header * eh;
|
|
|
|
|
|
|
|
|
|
DODEBUG(Start_End, printf("ex_rx_intr%d: start\n", unit););
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* For all packets received since last receive interrupt:
|
|
|
|
|
* - If packet ok, read it into a new mbuf and queue it to interface,
|
|
|
|
|
* updating statistics.
|
|
|
|
|
* - If packet bad, just discard it, and update statistics.
|
|
|
|
|
* Finally, advance receive stop limit in card's memory to new location.
|
|
|
|
|
*/
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, HOST_ADDR_REG, sc->rx_head);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
while (CSR_READ_2(sc, IO_PORT_REG) == RCV_Done) {
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
rx_status = CSR_READ_2(sc, IO_PORT_REG);
|
|
|
|
|
sc->rx_head = CSR_READ_2(sc, IO_PORT_REG);
|
|
|
|
|
QQQ = pkt_len = CSR_READ_2(sc, IO_PORT_REG);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
if (rx_status & RCV_OK_bit) {
|
2003-02-19 05:47:46 +00:00
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ipkt = m;
|
|
|
|
|
if (ipkt == NULL) {
|
|
|
|
|
ifp->if_iqdrops++;
|
|
|
|
|
} else {
|
|
|
|
|
ipkt->m_pkthdr.rcvif = ifp;
|
|
|
|
|
ipkt->m_pkthdr.len = pkt_len;
|
|
|
|
|
ipkt->m_len = MHLEN;
|
|
|
|
|
|
|
|
|
|
while (pkt_len > 0) {
|
2004-10-17 21:44:11 +00:00
|
|
|
|
if (pkt_len >= MINCLSIZE) {
|
2003-02-19 05:47:46 +00:00
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
if (m->m_flags & M_EXT) {
|
|
|
|
|
m->m_len = MCLBYTES;
|
|
|
|
|
} else {
|
|
|
|
|
m_freem(ipkt);
|
|
|
|
|
ifp->if_iqdrops++;
|
|
|
|
|
goto rx_another;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m->m_len = min(m->m_len, pkt_len);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NOTE: I'm assuming that all mbufs allocated are of even length,
|
|
|
|
|
* except for the last one in an odd-length packet.
|
|
|
|
|
*/
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_READ_MULTI_2(sc, IO_PORT_REG,
|
|
|
|
|
mtod(m, uint16_t *), m->m_len / 2);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
if (m->m_len & 1) {
|
2004-06-27 13:10:20 +00:00
|
|
|
|
*(mtod(m, caddr_t) + m->m_len - 1) = CSR_READ_1(sc, IO_PORT_REG);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
}
|
|
|
|
|
pkt_len -= m->m_len;
|
|
|
|
|
|
|
|
|
|
if (pkt_len > 0) {
|
2003-02-19 05:47:46 +00:00
|
|
|
|
MGET(m->m_next, M_DONTWAIT, MT_DATA);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
if (m->m_next == NULL) {
|
|
|
|
|
m_freem(ipkt);
|
|
|
|
|
ifp->if_iqdrops++;
|
|
|
|
|
goto rx_another;
|
|
|
|
|
}
|
|
|
|
|
m = m->m_next;
|
|
|
|
|
m->m_len = MLEN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
eh = mtod(ipkt, struct ether_header *);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#ifdef EXDEBUG
|
1999-10-16 06:26:44 +00:00
|
|
|
|
if (debug_mask & Rcvd_Pkts) {
|
|
|
|
|
if ((eh->ether_dhost[5] != 0xff) || (eh->ether_dhost[0] != 0xff)) {
|
|
|
|
|
printf("Receive packet with %d data bytes: %6D -> ", QQQ, eh->ether_shost, ":");
|
|
|
|
|
printf("%6D\n", eh->ether_dhost, ":");
|
|
|
|
|
} /* QQQ */
|
|
|
|
|
}
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#endif
|
2002-11-14 23:54:55 +00:00
|
|
|
|
(*ifp->if_input)(ifp, ipkt);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ifp->if_ierrors++;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, HOST_ADDR_REG, sc->rx_head);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
rx_another: ;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
if (sc->rx_head < sc->rx_lower_limit + 2)
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, RCV_STOP_REG, sc->rx_upper_limit);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
else
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, RCV_STOP_REG, sc->rx_head - 2);
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
DODEBUG(Start_End, printf("ex_rx_intr%d: finish\n", unit););
|
|
|
|
|
|
|
|
|
|
return;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-13 06:55:35 +00:00
|
|
|
|
static int
|
|
|
|
|
ex_ioctl(register struct ifnet *ifp, u_long cmd, caddr_t data)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
1999-10-16 06:26:44 +00:00
|
|
|
|
struct ex_softc * sc = ifp->if_softc;
|
2000-03-13 12:23:32 +00:00
|
|
|
|
struct ifreq * ifr = (struct ifreq *)data;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
int s;
|
|
|
|
|
int error = 0;
|
|
|
|
|
|
2003-10-31 18:32:15 +00:00
|
|
|
|
DODEBUG(Start_End, printf("%s: ex_ioctl: start ", ifp->if_xname););
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
|
case SIOCSIFMTU:
|
|
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
|
DODEBUG(Start_End, printf("SIOCSIFFLAGS"););
|
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0 &&
|
|
|
|
|
(ifp->if_flags & IFF_RUNNING)) {
|
|
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
|
ex_stop(sc);
|
|
|
|
|
} else {
|
|
|
|
|
ex_init(sc);
|
|
|
|
|
}
|
|
|
|
|
break;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#ifdef NODEF
|
1999-10-16 06:26:44 +00:00
|
|
|
|
case SIOCGHWADDR:
|
|
|
|
|
DODEBUG(Start_End, printf("SIOCGHWADDR"););
|
|
|
|
|
bcopy((caddr_t)sc->sc_addr, (caddr_t)&ifr->ifr_data,
|
|
|
|
|
sizeof(sc->sc_addr));
|
|
|
|
|
break;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
#endif
|
1999-10-16 06:26:44 +00:00
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
|
case SIOCDELMULTI:
|
2003-03-28 02:15:01 +00:00
|
|
|
|
ex_init(sc);
|
|
|
|
|
error = 0;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
break;
|
2000-03-13 12:23:32 +00:00
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->ifmedia, cmd);
|
|
|
|
|
break;
|
1999-10-16 06:26:44 +00:00
|
|
|
|
default:
|
|
|
|
|
DODEBUG(Start_End, printf("unknown"););
|
|
|
|
|
error = EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
2003-10-31 18:32:15 +00:00
|
|
|
|
DODEBUG(Start_End, printf("\n%s: ex_ioctl: finish\n", ifp->if_xname););
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
return(error);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-28 02:15:01 +00:00
|
|
|
|
static void
|
|
|
|
|
ex_setmulti(struct ex_softc *sc)
|
|
|
|
|
{
|
|
|
|
|
struct ifnet *ifp;
|
|
|
|
|
struct ifmultiaddr *maddr;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
uint16_t *addr;
|
2003-03-28 02:15:01 +00:00
|
|
|
|
int count;
|
|
|
|
|
int timeout, status;
|
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
|
ifp = sc->ifp;
|
2003-03-28 02:15:01 +00:00
|
|
|
|
|
|
|
|
|
count = 0;
|
2005-08-03 00:18:35 +00:00
|
|
|
|
IF_ADDR_LOCK(ifp);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
TAILQ_FOREACH(maddr, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
|
if (maddr->ifma_addr->sa_family != AF_LINK)
|
|
|
|
|
continue;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
|
IF_ADDR_UNLOCK(ifp);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
|
|
|
|
|
if ((ifp->if_flags & IFF_PROMISC) || (ifp->if_flags & IFF_ALLMULTI)
|
|
|
|
|
|| count > 63) {
|
|
|
|
|
/* Interface is in promiscuous mode or there are too many
|
|
|
|
|
* multicast addresses for the card to handle */
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank2_Sel);
|
|
|
|
|
CSR_WRITE_1(sc, REG2, CSR_READ_1(sc, REG2) | Promisc_Mode);
|
|
|
|
|
CSR_WRITE_1(sc, REG3, CSR_READ_1(sc, REG3));
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank0_Sel);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
}
|
|
|
|
|
else if ((ifp->if_flags & IFF_MULTICAST) && (count > 0)) {
|
|
|
|
|
/* Program multicast addresses plus our MAC address
|
|
|
|
|
* into the filter */
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank2_Sel);
|
|
|
|
|
CSR_WRITE_1(sc, REG2, CSR_READ_1(sc, REG2) | Multi_IA);
|
|
|
|
|
CSR_WRITE_1(sc, REG3, CSR_READ_1(sc, REG3));
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank0_Sel);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
|
|
|
|
|
/* Borrow space from TX buffer; this should be safe
|
|
|
|
|
* as this is only called from ex_init */
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, HOST_ADDR_REG, sc->tx_lower_limit);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, MC_Setup_CMD);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, 0);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, 0);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, (count + 1) * 6);
|
2005-08-03 00:18:35 +00:00
|
|
|
|
|
|
|
|
|
IF_ADDR_LOCK(ifp);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
TAILQ_FOREACH(maddr, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
|
if (maddr->ifma_addr->sa_family != AF_LINK)
|
|
|
|
|
continue;
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
addr = (uint16_t*)LLADDR((struct sockaddr_dl *)
|
2003-03-28 02:15:01 +00:00
|
|
|
|
maddr->ifma_addr);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, *addr++);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, *addr++);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, *addr++);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
|
IF_ADDR_UNLOCK(ifp);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
|
|
|
|
|
/* Program our MAC address as well */
|
|
|
|
|
/* XXX: Is this necessary? The Linux driver does this
|
|
|
|
|
* but the NetBSD driver does not */
|
2005-06-10 16:49:24 +00:00
|
|
|
|
addr = (uint16_t*)(&IFP2ENADDR(sc->ifp));
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, *addr++);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, *addr++);
|
|
|
|
|
CSR_WRITE_2(sc, IO_PORT_REG, *addr++);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_READ_2(sc, IO_PORT_REG);
|
|
|
|
|
CSR_WRITE_2(sc, XMT_BAR, sc->tx_lower_limit);
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, MC_Setup_CMD);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
|
|
|
|
|
sc->tx_head = sc->tx_lower_limit;
|
|
|
|
|
sc->tx_tail = sc->tx_head + XMT_HEADER_LEN + (count + 1) * 6;
|
|
|
|
|
|
|
|
|
|
for (timeout=0; timeout<100; timeout++) {
|
|
|
|
|
DELAY(2);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
if ((CSR_READ_1(sc, STATUS_REG) & Exec_Int) == 0)
|
2003-03-28 02:15:01 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
status = CSR_READ_1(sc, CMD_REG);
|
|
|
|
|
CSR_WRITE_1(sc, STATUS_REG, Exec_Int);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sc->tx_head = sc->tx_tail;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* No multicast or promiscuous mode */
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank2_Sel);
|
|
|
|
|
CSR_WRITE_1(sc, REG2, CSR_READ_1(sc, REG2) & 0xDE);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
/* ~(Multi_IA | Promisc_Mode) */
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, REG3, CSR_READ_1(sc, REG3));
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank0_Sel);
|
2003-03-28 02:15:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
static void
|
|
|
|
|
ex_reset(struct ex_softc *sc)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
1999-10-16 06:26:44 +00:00
|
|
|
|
int s;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
DODEBUG(Start_End, printf("ex_reset%d: start\n", unit););
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
s = splimp();
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ex_stop(sc);
|
|
|
|
|
ex_init(sc);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
splx(s);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
DODEBUG(Start_End, printf("ex_reset%d: finish\n", unit););
|
|
|
|
|
|
|
|
|
|
return;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
static void
|
|
|
|
|
ex_watchdog(struct ifnet *ifp)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
1999-10-16 06:26:44 +00:00
|
|
|
|
struct ex_softc * sc = ifp->if_softc;
|
|
|
|
|
|
2003-10-31 18:32:15 +00:00
|
|
|
|
DODEBUG(Start_End, printf("%s: ex_watchdog: start\n", ifp->if_xname););
|
1999-10-16 06:26:44 +00:00
|
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
|
|
DODEBUG(Status, printf("OIDLE watchdog\n"););
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
|
ex_reset(sc);
|
|
|
|
|
ex_start(ifp);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
2003-10-31 18:32:15 +00:00
|
|
|
|
DODEBUG(Start_End, printf("%s: ex_watchdog: finish\n", ifp->if_xname););
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
1999-10-16 06:26:44 +00:00
|
|
|
|
return;
|
1997-01-16 12:19:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
static int
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ex_get_media(struct ex_softc *sc)
|
2000-05-01 09:05:19 +00:00
|
|
|
|
{
|
2003-03-29 01:40:42 +00:00
|
|
|
|
int current;
|
|
|
|
|
int media;
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
media = ex_eeprom_read(sc, EE_W5);
|
2000-05-01 09:05:19 +00:00
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank2_Sel);
|
|
|
|
|
current = CSR_READ_1(sc, REG3);
|
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank0_Sel);
|
2000-05-01 09:05:19 +00:00
|
|
|
|
|
2003-03-29 01:40:42 +00:00
|
|
|
|
if ((current & TPE_bit) && (media & EE_W5_PORT_TPE))
|
2000-05-01 09:05:19 +00:00
|
|
|
|
return(IFM_ETHER|IFM_10_T);
|
2003-03-29 01:40:42 +00:00
|
|
|
|
if ((current & BNC_bit) && (media & EE_W5_PORT_BNC))
|
2000-05-01 09:05:19 +00:00
|
|
|
|
return(IFM_ETHER|IFM_10_2);
|
|
|
|
|
|
2003-03-29 01:40:42 +00:00
|
|
|
|
if (media & EE_W5_PORT_AUI)
|
|
|
|
|
return (IFM_ETHER|IFM_10_5);
|
|
|
|
|
|
|
|
|
|
return (IFM_ETHER|IFM_AUTO);
|
2000-05-01 09:05:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-03-13 12:23:32 +00:00
|
|
|
|
static int
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ex_ifmedia_upd(ifp)
|
2000-03-13 12:23:32 +00:00
|
|
|
|
struct ifnet * ifp;
|
|
|
|
|
{
|
2003-03-29 01:40:42 +00:00
|
|
|
|
struct ex_softc * sc = ifp->if_softc;
|
|
|
|
|
|
|
|
|
|
if (IFM_TYPE(sc->ifmedia.ifm_media) != IFM_ETHER)
|
|
|
|
|
return EINVAL;
|
2000-03-13 12:23:32 +00:00
|
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ex_ifmedia_sts(ifp, ifmr)
|
|
|
|
|
struct ifnet * ifp;
|
|
|
|
|
struct ifmediareq * ifmr;
|
|
|
|
|
{
|
|
|
|
|
struct ex_softc * sc = ifp->if_softc;
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ifmr->ifm_active = ex_get_media(sc);
|
2003-03-29 01:40:42 +00:00
|
|
|
|
ifmr->ifm_status = IFM_AVALID | IFM_ACTIVE;
|
2000-03-13 12:23:32 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
2000-05-01 09:05:19 +00:00
|
|
|
|
u_short
|
2004-06-27 13:10:20 +00:00
|
|
|
|
ex_eeprom_read(struct ex_softc *sc, int location)
|
1997-01-16 12:19:21 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
u_short data = 0;
|
|
|
|
|
int read_cmd = location | EE_READ_CMD;
|
|
|
|
|
short ctrl_val = EECS;
|
|
|
|
|
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank2_Sel);
|
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, EECS);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
for (i = 8; i >= 0; i--) {
|
|
|
|
|
short outval = (read_cmd & (1 << i)) ? ctrl_val | EEDI : ctrl_val;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, outval);
|
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, outval | EESK);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
DELAY(3);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, outval);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
DELAY(2);
|
|
|
|
|
}
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, ctrl_val);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
|
|
|
|
|
for (i = 16; i > 0; i--) {
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, ctrl_val | EESK);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
DELAY(3);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
data = (data << 1) |
|
|
|
|
|
((CSR_READ_1(sc, EEPROM_REG) & EEDO) ? 1 : 0);
|
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, ctrl_val);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
DELAY(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ctrl_val &= ~EECS;
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, ctrl_val | EESK);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
DELAY(3);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, EEPROM_REG, ctrl_val);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
DELAY(2);
|
2004-06-27 13:10:20 +00:00
|
|
|
|
CSR_WRITE_1(sc, CMD_REG, Bank0_Sel);
|
1997-01-16 12:19:21 +00:00
|
|
|
|
return(data);
|
|
|
|
|
}
|