2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
1995-12-05 13:01:33 +00:00
|
|
|
* Copyright (c) 1995, David Greenman
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-11-14 17:16:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
1993-09-29 20:30:26 +00:00
|
|
|
* Device driver for National Semiconductor DS8390/WD83C690 based ethernet
|
1993-06-14 22:21:25 +00:00
|
|
|
* adapters. By David Greenman, 29-April-1993
|
|
|
|
*
|
1993-09-29 20:30:26 +00:00
|
|
|
* Currently supports the Western Digital/SMC 8003 and 8013 series,
|
1994-01-03 17:17:19 +00:00
|
|
|
* the SMC Elite Ultra (8216), the 3Com 3c503, the NE1000 and NE2000,
|
|
|
|
* and a variety of similar clones.
|
1993-09-29 22:15:53 +00:00
|
|
|
*
|
1993-09-22 17:47:43 +00:00
|
|
|
*/
|
|
|
|
|
2001-09-29 22:32:03 +00:00
|
|
|
#include "opt_ed.h"
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1997-03-24 11:33:46 +00:00
|
|
|
#include <sys/sockio.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/mbuf.h>
|
2001-03-03 08:31:37 +00:00
|
|
|
#include <sys/kernel.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/socket.h>
|
2006-06-12 04:30:42 +00:00
|
|
|
#include <sys/sysctl.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/syslog.h>
|
1993-06-14 22:21:25 +00:00
|
|
|
|
1999-09-03 19:10:56 +00:00
|
|
|
#include <sys/bus.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
1998-01-08 23:42:31 +00:00
|
|
|
#include <net/ethernet.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <net/if.h>
|
1998-01-08 23:42:31 +00:00
|
|
|
#include <net/if_arp.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <net/if_dl.h>
|
1996-10-11 15:19:23 +00:00
|
|
|
#include <net/if_mib.h>
|
2001-03-03 08:31:37 +00:00
|
|
|
#include <net/if_media.h>
|
2005-06-10 16:49:24 +00:00
|
|
|
#include <net/if_types.h>
|
2001-03-03 08:31:37 +00:00
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <net/bpf.h>
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
#include <dev/ed/if_edreg.h>
|
|
|
|
#include <dev/ed/if_edvar.h>
|
2005-08-28 23:56:25 +00:00
|
|
|
#include <sys/kdb.h>
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
devclass_t ed_devclass;
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
static void ed_init(void *);
|
2005-08-28 23:56:25 +00:00
|
|
|
static void ed_init_locked(struct ed_softc *);
|
2005-02-09 20:03:40 +00:00
|
|
|
static int ed_ioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
static void ed_start(struct ifnet *);
|
2005-08-28 23:56:25 +00:00
|
|
|
static void ed_start_locked(struct ifnet *);
|
2005-02-09 20:03:40 +00:00
|
|
|
static void ed_reset(struct ifnet *);
|
|
|
|
static void ed_watchdog(struct ifnet *);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
static void ed_ds_getmcaf(struct ed_softc *, uint32_t *);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
static void ed_get_packet(struct ed_softc *, bus_size_t, u_short);
|
|
|
|
static void ed_stop_hw(struct ed_softc *sc);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
static __inline void ed_rint(struct ed_softc *);
|
|
|
|
static __inline void ed_xmit(struct ed_softc *);
|
|
|
|
static __inline void ed_ring_copy(struct ed_softc *, bus_size_t, char *,
|
|
|
|
u_short);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
static void ed_setrcr(struct ed_softc *);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
|
|
|
/*
|
2005-02-09 20:03:40 +00:00
|
|
|
* Generic probe routine for testing for the existance of a DS8390.
|
|
|
|
* Must be called after the NIC has just been reset. This routine
|
|
|
|
* works by looking at certain register values that are guaranteed
|
|
|
|
* to be initialized a certain way after power-up or reset. Seems
|
|
|
|
* not to currently work on the 83C690.
|
|
|
|
*
|
|
|
|
* Specifically:
|
|
|
|
*
|
|
|
|
* Register reset bits set bits
|
|
|
|
* Command Register (CR) TXP, STA RD2, STP
|
|
|
|
* Interrupt Status (ISR) RST
|
|
|
|
* Interrupt Mask (IMR) All bits
|
|
|
|
* Data Control (DCR) LAS
|
|
|
|
* Transmit Config. (TCR) LB1, LB0
|
|
|
|
*
|
|
|
|
* We only look at the CR and ISR registers, however, because looking at
|
|
|
|
* the others would require changing register pages (which would be
|
|
|
|
* intrusive if this isn't an 8390).
|
|
|
|
*
|
|
|
|
* Return 1 if 8390 was found, 0 if not.
|
1996-08-07 11:18:23 +00:00
|
|
|
*/
|
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
int
|
|
|
|
ed_probe_generic8390(struct ed_softc *sc)
|
1996-08-07 11:18:23 +00:00
|
|
|
{
|
2005-02-09 20:03:40 +00:00
|
|
|
if ((ed_nic_inb(sc, ED_P0_CR) &
|
|
|
|
(ED_CR_RD2 | ED_CR_TXP | ED_CR_STA | ED_CR_STP)) !=
|
|
|
|
(ED_CR_RD2 | ED_CR_STP))
|
|
|
|
return (0);
|
|
|
|
if ((ed_nic_inb(sc, ED_P0_ISR) & ED_ISR_RST) != ED_ISR_RST)
|
|
|
|
return (0);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
return (1);
|
1996-08-07 11:18:23 +00:00
|
|
|
}
|
|
|
|
|
2005-02-10 23:48:13 +00:00
|
|
|
void
|
|
|
|
ed_disable_16bit_access(struct ed_softc *sc)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Disable 16 bit access to shared memory
|
|
|
|
*/
|
|
|
|
if (sc->isa16bit && sc->vendor == ED_VENDOR_WD_SMC) {
|
|
|
|
if (sc->chip_type == ED_CHIP_TYPE_WD790)
|
|
|
|
ed_asic_outb(sc, ED_WD_MSR, 0x00);
|
|
|
|
ed_asic_outb(sc, ED_WD_LAAR,
|
|
|
|
sc->wd_laar_proto & ~ED_WD_LAAR_M16EN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ed_enable_16bit_access(struct ed_softc *sc)
|
|
|
|
{
|
|
|
|
if (sc->isa16bit && sc->vendor == ED_VENDOR_WD_SMC) {
|
|
|
|
ed_asic_outb(sc, ED_WD_LAAR,
|
|
|
|
sc->wd_laar_proto | ED_WD_LAAR_M16EN);
|
|
|
|
if (sc->chip_type == ED_CHIP_TYPE_WD790)
|
|
|
|
ed_asic_outb(sc, ED_WD_MSR, ED_WD_MSR_MENB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-03 19:10:56 +00:00
|
|
|
/*
|
|
|
|
* Allocate a port resource with the given resource id.
|
|
|
|
*/
|
1999-10-15 03:12:48 +00:00
|
|
|
int
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_alloc_port(device_t dev, int rid, int size)
|
1999-09-03 19:10:56 +00:00
|
|
|
{
|
|
|
|
struct ed_softc *sc = device_get_softc(dev);
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
|
2005-02-09 20:03:40 +00:00
|
|
|
0ul, ~0ul, size, RF_ACTIVE);
|
1999-09-03 19:10:56 +00:00
|
|
|
if (res) {
|
|
|
|
sc->port_rid = rid;
|
|
|
|
sc->port_res = res;
|
1999-11-18 14:18:19 +00:00
|
|
|
sc->port_used = size;
|
2005-02-22 05:12:25 +00:00
|
|
|
sc->port_bst = rman_get_bustag(res);
|
|
|
|
sc->port_bsh = rman_get_bushandle(res);
|
1999-09-03 19:10:56 +00:00
|
|
|
return (0);
|
2000-08-17 12:15:45 +00:00
|
|
|
}
|
2005-02-11 07:50:03 +00:00
|
|
|
return (ENOENT);
|
1999-09-03 19:10:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a memory resource with the given resource id.
|
|
|
|
*/
|
1999-10-15 03:12:48 +00:00
|
|
|
int
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_alloc_memory(device_t dev, int rid, int size)
|
1999-09-03 19:10:56 +00:00
|
|
|
{
|
|
|
|
struct ed_softc *sc = device_get_softc(dev);
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
|
2005-02-09 20:03:40 +00:00
|
|
|
0ul, ~0ul, size, RF_ACTIVE);
|
1999-09-03 19:10:56 +00:00
|
|
|
if (res) {
|
|
|
|
sc->mem_rid = rid;
|
|
|
|
sc->mem_res = res;
|
1999-11-18 14:18:19 +00:00
|
|
|
sc->mem_used = size;
|
2005-02-22 05:12:25 +00:00
|
|
|
sc->mem_bst = rman_get_bustag(res);
|
|
|
|
sc->mem_bsh = rman_get_bushandle(res);
|
1999-09-03 19:10:56 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2005-02-11 07:50:03 +00:00
|
|
|
return (ENOENT);
|
1999-09-03 19:10:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate an irq resource with the given resource id.
|
|
|
|
*/
|
1999-10-15 03:12:48 +00:00
|
|
|
int
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_alloc_irq(device_t dev, int rid, int flags)
|
1999-09-03 19:10:56 +00:00
|
|
|
{
|
|
|
|
struct ed_softc *sc = device_get_softc(dev);
|
|
|
|
struct resource *res;
|
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE | flags);
|
1999-09-03 19:10:56 +00:00
|
|
|
if (res) {
|
|
|
|
sc->irq_rid = rid;
|
|
|
|
sc->irq_res = res;
|
|
|
|
return (0);
|
|
|
|
}
|
2005-02-11 07:50:03 +00:00
|
|
|
return (ENOENT);
|
1999-09-03 19:10:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release all resources
|
|
|
|
*/
|
1999-10-15 03:12:48 +00:00
|
|
|
void
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_release_resources(device_t dev)
|
1999-09-03 19:10:56 +00:00
|
|
|
{
|
|
|
|
struct ed_softc *sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
if (sc->port_res) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT,
|
2005-02-21 07:22:50 +00:00
|
|
|
sc->port_rid, sc->port_res);
|
1999-09-03 19:10:56 +00:00
|
|
|
sc->port_res = 0;
|
|
|
|
}
|
|
|
|
if (sc->mem_res) {
|
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY,
|
2005-02-21 07:22:50 +00:00
|
|
|
sc->mem_rid, sc->mem_res);
|
1999-09-03 19:10:56 +00:00
|
|
|
sc->mem_res = 0;
|
|
|
|
}
|
|
|
|
if (sc->irq_res) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ,
|
2005-02-21 07:22:50 +00:00
|
|
|
sc->irq_rid, sc->irq_res);
|
1999-09-03 19:10:56 +00:00
|
|
|
sc->irq_res = 0;
|
|
|
|
}
|
2005-09-16 11:25:19 +00:00
|
|
|
if (sc->ifp)
|
|
|
|
if_free(sc->ifp);
|
1999-09-03 19:10:56 +00:00
|
|
|
}
|
1996-08-07 11:18:23 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Install interface into kernel networking data structures
|
|
|
|
*/
|
1999-10-15 03:12:48 +00:00
|
|
|
int
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_attach(device_t dev)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
2003-10-31 18:32:15 +00:00
|
|
|
struct ed_softc *sc = device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
sc->dev = dev;
|
|
|
|
ED_LOCK_INIT(sc);
|
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");
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_LOCK_DESTROY(sc);
|
2005-06-10 16:49:24 +00:00
|
|
|
return (ENOSPC);
|
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
if (sc->readmem == NULL) {
|
|
|
|
if (sc->mem_shared) {
|
|
|
|
if (sc->isa16bit)
|
|
|
|
sc->readmem = ed_shmem_readmem16;
|
|
|
|
else
|
|
|
|
sc->readmem = ed_shmem_readmem8;
|
|
|
|
} else {
|
|
|
|
sc->readmem = ed_pio_readmem;
|
|
|
|
}
|
|
|
|
}
|
2006-01-27 19:10:13 +00:00
|
|
|
if (sc->sc_write_mbufs == NULL) {
|
|
|
|
device_printf(dev, "No write mbufs routine set\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
callout_init_mtx(&sc->tick_ch, ED_MUTEX(sc), 0);
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Set interface to stopped condition (reset)
|
|
|
|
*/
|
2005-08-28 23:56:25 +00:00
|
|
|
ed_stop_hw(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2003-10-30 19:45:58 +00:00
|
|
|
/*
|
|
|
|
* Initialize 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));
|
2003-10-30 19:45:58 +00:00
|
|
|
ifp->if_start = ed_start;
|
|
|
|
ifp->if_ioctl = ed_ioctl;
|
|
|
|
ifp->if_watchdog = ed_watchdog;
|
|
|
|
ifp->if_init = ed_init;
|
2004-11-21 02:42:09 +00:00
|
|
|
IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
|
|
|
|
ifp->if_snd.ifq_drv_maxlen = IFQ_MAXLEN;
|
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
2003-10-30 19:45:58 +00:00
|
|
|
ifp->if_linkmib = &sc->mibdata;
|
|
|
|
ifp->if_linkmiblen = sizeof sc->mibdata;
|
|
|
|
/*
|
|
|
|
* XXX - should do a better job.
|
|
|
|
*/
|
|
|
|
if (sc->chip_type == ED_CHIP_TYPE_WD790)
|
|
|
|
sc->mibdata.dot3StatsEtherChipSet =
|
|
|
|
DOT3CHIPSET(dot3VendorWesternDigital,
|
|
|
|
dot3ChipSetWesternDigital83C790);
|
|
|
|
else
|
|
|
|
sc->mibdata.dot3StatsEtherChipSet =
|
|
|
|
DOT3CHIPSET(dot3VendorNational,
|
|
|
|
dot3ChipSetNational8390);
|
|
|
|
sc->mibdata.dot3Compliance = DOT3COMPLIANCE_COLLS;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2006-01-27 08:00:40 +00:00
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
2003-10-30 19:45:58 +00:00
|
|
|
/*
|
2006-01-27 08:00:40 +00:00
|
|
|
* Set default state for LINK2 flag (used to disable the
|
2005-08-28 23:56:25 +00:00
|
|
|
* tranceiver for AUI operation), based on config option.
|
2006-01-27 08:00:40 +00:00
|
|
|
* We only set this flag before we attach the device, so there's
|
|
|
|
* no race. It is convenient to allow users to turn this off
|
|
|
|
* by default in the kernel config, but given our more advanced
|
|
|
|
* boot time configuration options, this might no longer be needed.
|
2003-10-30 19:45:58 +00:00
|
|
|
*/
|
2003-10-31 18:32:15 +00:00
|
|
|
if (device_get_flags(dev) & ED_FLAGS_DISABLE_TRANCEIVER)
|
2006-01-27 08:00:40 +00:00
|
|
|
ifp->if_flags |= IFF_LINK2;
|
1993-06-22 12:10:07 +00:00
|
|
|
|
2003-10-30 19:45:58 +00:00
|
|
|
/*
|
|
|
|
* Attach the interface
|
|
|
|
*/
|
2005-06-10 16:49:24 +00:00
|
|
|
ether_ifattach(ifp, sc->enaddr);
|
1995-01-15 00:18:17 +00:00
|
|
|
/* device attach does transition from UNCONFIGURED to IDLE state */
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2006-06-12 04:30:42 +00:00
|
|
|
sc->tx_mem = sc->txb_cnt * ED_PAGE_SIZE * ED_TXBUF_SIZE;
|
|
|
|
sc->rx_mem = (sc->rec_page_stop - sc->rec_page_start) * ED_PAGE_SIZE;
|
|
|
|
SYSCTL_ADD_STRING(device_get_sysctl_ctx(dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
|
|
|
|
0, "type", CTLTYPE_STRING | CTLFLAG_RD, sc->type_str, 0,
|
|
|
|
"Type of chip in card");
|
|
|
|
SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
|
|
|
|
1, "TxMem", CTLTYPE_STRING | CTLFLAG_RD, &sc->tx_mem, 0,
|
|
|
|
"Memory set aside for transmitting packets");
|
|
|
|
SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
|
|
|
|
2, "RxMem", CTLTYPE_STRING | CTLFLAG_RD, &sc->rx_mem, 0,
|
|
|
|
"Memory set aside for receiving packets");
|
|
|
|
SYSCTL_ADD_INT(device_get_sysctl_ctx(dev),
|
|
|
|
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
|
|
|
|
3, "Mem", CTLTYPE_STRING | CTLFLAG_RD, &sc->mem_size, 0,
|
|
|
|
"Total Card Memory");
|
|
|
|
if (bootverbose) {
|
2005-01-26 05:12:16 +00:00
|
|
|
if (sc->type_str && (*sc->type_str != 0))
|
|
|
|
device_printf(dev, "type %s ", sc->type_str);
|
|
|
|
else
|
|
|
|
device_printf(dev, "type unknown (0x%x) ", sc->type);
|
1993-09-22 17:47:43 +00:00
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
#ifdef ED_HPP
|
2005-01-26 05:12:16 +00:00
|
|
|
if (sc->vendor == ED_VENDOR_HP)
|
|
|
|
printf("(%s %s IO)",
|
|
|
|
(sc->hpp_id & ED_HPP_ID_16_BIT_ACCESS) ?
|
|
|
|
"16-bit" : "32-bit",
|
|
|
|
sc->hpp_mem_start ? "memory mapped" : "regular");
|
|
|
|
else
|
2005-02-09 20:03:40 +00:00
|
|
|
#endif
|
2006-01-27 08:00:40 +00:00
|
|
|
printf("%s", sc->isa16bit ? "(16 bit)" : "(8 bit)");
|
1993-07-20 23:16:50 +00:00
|
|
|
|
2005-02-20 18:44:45 +00:00
|
|
|
#if defined(ED_HPP) || defined(ED_3C503)
|
2005-08-28 23:56:25 +00:00
|
|
|
printf("%s", (((sc->vendor == ED_VENDOR_3COM) ||
|
2005-01-26 05:12:16 +00:00
|
|
|
(sc->vendor == ED_VENDOR_HP)) &&
|
2006-01-27 08:00:40 +00:00
|
|
|
(ifp->if_flags & IFF_LINK2)) ?
|
2005-01-26 05:12:16 +00:00
|
|
|
" tranceiver disabled" : "");
|
2005-02-20 18:44:45 +00:00
|
|
|
#endif
|
2005-02-22 22:03:52 +00:00
|
|
|
printf("\n");
|
2005-01-26 05:12:16 +00:00
|
|
|
}
|
1999-09-03 19:10:56 +00:00
|
|
|
return (0);
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
2005-02-08 05:45:35 +00:00
|
|
|
/*
|
|
|
|
* Detach the driver from the hardware and other systems in the kernel.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ed_detach(device_t dev)
|
|
|
|
{
|
|
|
|
struct ed_softc *sc = device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
2005-02-08 05:45:35 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_ASSERT_UNLOCKED(sc);
|
2008-08-06 22:22:27 +00:00
|
|
|
if (ifp) {
|
|
|
|
ED_LOCK(sc);
|
|
|
|
if (bus_child_present(dev))
|
|
|
|
ed_stop(sc);
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
|
|
|
ED_UNLOCK(sc);
|
|
|
|
callout_drain(&sc->tick_ch);
|
|
|
|
ether_ifdetach(ifp);
|
|
|
|
}
|
2005-02-08 05:45:35 +00:00
|
|
|
bus_teardown_intr(dev, sc->irq_res, sc->irq_handle);
|
|
|
|
ed_release_resources(dev);
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_LOCK_DESTROY(sc);
|
2005-09-26 18:22:24 +00:00
|
|
|
bus_generic_detach(dev);
|
2005-02-08 05:45:35 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Reset interface.
|
|
|
|
*/
|
1995-11-18 08:29:04 +00:00
|
|
|
static void
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_reset(struct ifnet *ifp)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
1996-02-06 18:51:28 +00:00
|
|
|
struct ed_softc *sc = ifp->if_softc;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_ASSERT_LOCKED(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Stop interface and re-initialize.
|
|
|
|
*/
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_stop(sc);
|
2005-08-28 23:56:25 +00:00
|
|
|
ed_init_locked(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
static void
|
|
|
|
ed_stop_hw(struct ed_softc *sc)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
1994-08-04 17:42:35 +00:00
|
|
|
int n = 5000;
|
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Stop everything on the interface, and select page 0 registers.
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* Wait for interface to enter stopped state, but limit # of checks to
|
|
|
|
* 'n' (about 5ms). It shouldn't even take 5us on modern DS8390's, but
|
|
|
|
* just in case it's an old one.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-07-23 15:15:43 +00:00
|
|
|
if (sc->chip_type != ED_CHIP_TYPE_AX88190)
|
2005-02-10 23:31:27 +00:00
|
|
|
while (((ed_nic_inb(sc, ED_P0_ISR) & ED_ISR_RST) == 0) && --n)
|
|
|
|
continue;
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
/*
|
|
|
|
* Take interface offline.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ed_stop(struct ed_softc *sc)
|
|
|
|
{
|
|
|
|
ED_ASSERT_LOCKED(sc);
|
2005-09-18 20:51:34 +00:00
|
|
|
if (sc->sc_tick)
|
|
|
|
callout_stop(&sc->tick_ch);
|
2005-08-28 23:56:25 +00:00
|
|
|
ed_stop_hw(sc);
|
|
|
|
}
|
|
|
|
|
1993-06-23 16:22:04 +00:00
|
|
|
/*
|
|
|
|
* Device timeout/watchdog routine. Entered if the device neglects to
|
|
|
|
* generate an interrupt after a transmit has been started on it.
|
|
|
|
*/
|
1995-11-18 08:29:04 +00:00
|
|
|
static void
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_watchdog(struct ifnet *ifp)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
1996-02-06 18:51:28 +00:00
|
|
|
struct ed_softc *sc = ifp->if_softc;
|
1993-10-23 04:52:41 +00:00
|
|
|
|
2003-10-31 18:32:15 +00:00
|
|
|
log(LOG_ERR, "%s: device timeout\n", ifp->if_xname);
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_oerrors++;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_LOCK(sc);
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_reset(ifp);
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_UNLOCK(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* Initialize device.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
1995-11-18 08:29:04 +00:00
|
|
|
static void
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_init(void *xsc)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
1996-10-11 15:19:23 +00:00
|
|
|
struct ed_softc *sc = xsc;
|
2005-08-28 23:56:25 +00:00
|
|
|
|
|
|
|
ED_ASSERT_UNLOCKED(sc);
|
|
|
|
ED_LOCK(sc);
|
|
|
|
ed_init_locked(sc);
|
|
|
|
ED_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ed_init_locked(struct ed_softc *sc)
|
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
2005-08-28 23:56:25 +00:00
|
|
|
int i;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_ASSERT_LOCKED(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the NIC in the exact order outlined in the NS manual.
|
1994-08-04 17:42:35 +00:00
|
|
|
* This init procedure is "mandatory"...don't change what or when
|
|
|
|
* things happen.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* reset transmitter flags */
|
|
|
|
sc->xmit_busy = 0;
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_timer = 0;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
1993-09-29 20:30:26 +00:00
|
|
|
sc->txb_inuse = 0;
|
|
|
|
sc->txb_new = 0;
|
|
|
|
sc->txb_next_tx = 0;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/* This variable is used below - don't move this assignment */
|
|
|
|
sc->next_packet = sc->rec_page_start + 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set interface for page 0, Remote DMA complete, Stopped
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
|
1994-09-07 06:11:29 +00:00
|
|
|
|
2005-02-21 07:22:50 +00:00
|
|
|
if (sc->isa16bit)
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* Set FIFO threshold to 8, No auto-init Remote DMA, byte
|
|
|
|
* order=80x86, word-wide DMA xfers,
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_WTS | ED_DCR_LS);
|
2005-02-21 07:22:50 +00:00
|
|
|
else
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Same as above, but byte-wide DMA xfers
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_DCR, ED_DCR_FT1 | ED_DCR_LS);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear Remote Byte Count Registers
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_RBCR0, 0);
|
|
|
|
ed_nic_outb(sc, ED_P0_RBCR1, 0);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* For the moment, don't store incoming packets in memory.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_RCR, ED_RCR_MON);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Place NIC in internal loopback mode
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_TCR, ED_TCR_LB0);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize transmit/receive (ring-buffer) Page Start
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_TPSR, sc->tx_page_start);
|
|
|
|
ed_nic_outb(sc, ED_P0_PSTART, sc->rec_page_start);
|
1993-11-22 11:08:16 +00:00
|
|
|
/* Set lower bits of byte addressable framing to 0 */
|
2000-07-23 15:15:43 +00:00
|
|
|
if (sc->chip_type == ED_CHIP_TYPE_WD790)
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, 0x09, 0);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize Receiver (ring-buffer) Page Stop and Boundry
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_PSTOP, sc->rec_page_stop);
|
|
|
|
ed_nic_outb(sc, ED_P0_BNRY, sc->rec_page_start);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear all interrupts. A '1' in each bit position clears the
|
1994-08-04 17:42:35 +00:00
|
|
|
* corresponding flag.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_ISR, 0xff);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable the following interrupts: receive/transmit complete,
|
1994-08-04 17:42:35 +00:00
|
|
|
* receive/transmit error, and Receiver OverWrite.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1993-06-14 22:21:25 +00:00
|
|
|
* Counter overflow and Remote DMA complete are *not* enabled.
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_IMR,
|
1994-08-04 17:42:35 +00:00
|
|
|
ED_IMR_PRXE | ED_IMR_PTXE | ED_IMR_RXEE | ED_IMR_TXEE | ED_IMR_OVWE);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Program Command Register for page 1
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STP);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Copy out our station address
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; ++i)
|
2005-11-11 16:04:59 +00:00
|
|
|
ed_nic_outb(sc, ED_P1_PAR(i), IF_LLADDR(sc->ifp)[i]);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set Current Page pointer to next_packet (initialized above)
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P1_CURR, sc->next_packet);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* Program Receiver Configuration Register and multicast filter. CR is
|
|
|
|
* set to page 0 on return.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_setrcr(sc);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Take interface out of loopback
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_TCR, 0);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-09-18 20:51:34 +00:00
|
|
|
if (sc->sc_mediachg)
|
2006-01-27 08:25:47 +00:00
|
|
|
sc->sc_mediachg(sc);
|
2005-09-18 20:51:34 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Set 'running' flag, and clear output active flag.
|
|
|
|
*/
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ...and attempt to start output
|
|
|
|
*/
|
2005-08-28 23:56:25 +00:00
|
|
|
ed_start_locked(ifp);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-09-18 20:51:34 +00:00
|
|
|
if (sc->sc_tick)
|
|
|
|
callout_reset(&sc->tick_ch, hz, sc->sc_tick, sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-23 16:22:04 +00:00
|
|
|
/*
|
|
|
|
* This routine actually starts the transmission on the interface
|
|
|
|
*/
|
1998-04-15 17:47:40 +00:00
|
|
|
static __inline void
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_xmit(struct ed_softc *sc)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
2005-06-15 20:23:40 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
1993-09-29 20:30:26 +00:00
|
|
|
unsigned short len;
|
|
|
|
|
|
|
|
len = sc->txb_len[sc->txb_next_tx];
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set NIC for page 0 register access
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Set TX buffer start page
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_TPSR, sc->tx_page_start +
|
|
|
|
sc->txb_next_tx * ED_TXBUF_SIZE);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set TX length
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_TBCR0, len);
|
|
|
|
ed_nic_outb(sc, ED_P0_TBCR1, len >> 8);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1993-06-23 16:22:04 +00:00
|
|
|
* Set page 0, Remote DMA complete, Transmit Packet, and *Start*
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_TXP | ED_CR_STA);
|
1993-06-14 22:21:25 +00:00
|
|
|
sc->xmit_busy = 1;
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-23 16:22:04 +00:00
|
|
|
/*
|
1993-09-29 20:30:26 +00:00
|
|
|
* Point to next transmit buffer slot and wrap if necessary.
|
1993-06-23 16:22:04 +00:00
|
|
|
*/
|
1993-09-29 20:30:26 +00:00
|
|
|
sc->txb_next_tx++;
|
|
|
|
if (sc->txb_next_tx == sc->txb_cnt)
|
|
|
|
sc->txb_next_tx = 0;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a timer just in case we never hear from the board again
|
|
|
|
*/
|
|
|
|
ifp->if_timer = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start output on interface.
|
|
|
|
* We make two assumptions here:
|
1993-11-22 11:08:16 +00:00
|
|
|
* 1) that the current priority is set to splimp _before_ this code
|
1993-06-14 22:21:25 +00:00
|
|
|
* is called *and* is returned to the appropriate priority after
|
|
|
|
* return
|
2005-08-09 10:20:02 +00:00
|
|
|
* 2) that the IFF_DRV_OACTIVE flag is checked before this code is called
|
1993-06-14 22:21:25 +00:00
|
|
|
* (i.e. that the output part of the interface is idle)
|
|
|
|
*/
|
1995-11-18 08:29:04 +00:00
|
|
|
static void
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_start(struct ifnet *ifp)
|
2005-08-28 23:56:25 +00:00
|
|
|
{
|
|
|
|
struct ed_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
ED_ASSERT_UNLOCKED(sc);
|
|
|
|
ED_LOCK(sc);
|
|
|
|
ed_start_locked(ifp);
|
|
|
|
ED_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ed_start_locked(struct ifnet *ifp)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
1996-02-06 18:51:28 +00:00
|
|
|
struct ed_softc *sc = ifp->if_softc;
|
1993-06-14 22:21:25 +00:00
|
|
|
struct mbuf *m0, *m;
|
2005-08-28 23:56:25 +00:00
|
|
|
bus_size_t buffer;
|
1994-08-04 17:42:35 +00:00
|
|
|
int len;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_ASSERT_LOCKED(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
outloop:
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-23 16:22:04 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* First, see if there are buffered packets and an idle transmitter -
|
|
|
|
* should never happen at this point.
|
1993-06-23 16:22:04 +00:00
|
|
|
*/
|
1993-09-29 20:30:26 +00:00
|
|
|
if (sc->txb_inuse && (sc->xmit_busy == 0)) {
|
1994-08-22 08:21:51 +00:00
|
|
|
printf("ed: packets buffered, but transmitter idle\n");
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_xmit(sc);
|
1993-09-29 20:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if there is room to put another packet in the buffer.
|
|
|
|
*/
|
|
|
|
if (sc->txb_inuse == sc->txb_cnt) {
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-09-29 20:30:26 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* No room. Indicate this to the outside world and exit.
|
1993-09-29 20:30:26 +00:00
|
|
|
*/
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
1993-09-29 20:30:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-11-21 02:42:09 +00:00
|
|
|
IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
|
1993-06-14 22:21:25 +00:00
|
|
|
if (m == 0) {
|
1994-08-04 17:42:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We are using the !OACTIVE flag to indicate to the outside
|
|
|
|
* world that we can accept an additional packet rather than
|
|
|
|
* that the transmitter is _actually_ active. Indeed, the
|
|
|
|
* transmitter may be active, but if we haven't filled all the
|
|
|
|
* buffers with data then we still want to accept more.
|
|
|
|
*/
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
1993-06-14 22:21:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the mbuf chain into the transmit buffer
|
|
|
|
*/
|
1993-10-15 11:06:41 +00:00
|
|
|
m0 = m;
|
|
|
|
|
1993-09-29 20:30:26 +00:00
|
|
|
/* txb_new points to next open buffer slot */
|
|
|
|
buffer = sc->mem_start + (sc->txb_new * ED_TXBUF_SIZE * ED_PAGE_SIZE);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2006-01-27 19:10:13 +00:00
|
|
|
len = sc->sc_write_mbufs(sc, m, buffer);
|
|
|
|
if (len == 0) {
|
|
|
|
m_freem(m0);
|
|
|
|
goto outloop;
|
1993-09-29 20:30:26 +00:00
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1996-08-06 21:14:36 +00:00
|
|
|
sc->txb_len[sc->txb_new] = max(len, (ETHER_MIN_LEN-ETHER_CRC_LEN));
|
1993-09-29 20:30:26 +00:00
|
|
|
|
|
|
|
sc->txb_inuse++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Point to next buffer slot and wrap if necessary.
|
|
|
|
*/
|
|
|
|
sc->txb_new++;
|
|
|
|
if (sc->txb_new == sc->txb_cnt)
|
|
|
|
sc->txb_new = 0;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
if (sc->xmit_busy == 0)
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_xmit(sc);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
1994-10-08 09:24:20 +00:00
|
|
|
* Tap off here if there is a bpf listener.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2002-11-14 23:54:55 +00:00
|
|
|
BPF_MTAP(ifp, m0);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
m_freem(m0);
|
|
|
|
|
1993-06-23 16:22:04 +00:00
|
|
|
/*
|
1993-09-29 20:30:26 +00:00
|
|
|
* Loop back to the top to possibly buffer more packets
|
1993-06-23 16:22:04 +00:00
|
|
|
*/
|
1993-09-29 20:30:26 +00:00
|
|
|
goto outloop;
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Ethernet interface receiver interrupt.
|
|
|
|
*/
|
1998-04-15 17:47:40 +00:00
|
|
|
static __inline void
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_rint(struct ed_softc *sc)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
1994-10-22 17:52:22 +00:00
|
|
|
u_char boundry;
|
1993-06-14 22:21:25 +00:00
|
|
|
u_short len;
|
1993-09-29 20:30:26 +00:00
|
|
|
struct ed_ring packet_hdr;
|
2005-08-28 23:56:25 +00:00
|
|
|
bus_size_t packet_ptr;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_ASSERT_LOCKED(sc);
|
1995-10-10 09:52:55 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Set NIC to page 1 registers to get 'current' pointer
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STA);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* 'sc->next_packet' is the logical beginning of the ring-buffer -
|
|
|
|
* i.e. it points to where new data has been buffered. The 'CURR'
|
|
|
|
* (current) register points to the logical end of the ring-buffer -
|
|
|
|
* i.e. it points to where additional new data will be added. We loop
|
|
|
|
* here until the logical beginning equals the logical end (or in
|
|
|
|
* other words, until the ring-buffer is empty).
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
while (sc->next_packet != ed_nic_inb(sc, ED_P1_CURR)) {
|
1993-06-14 22:21:25 +00:00
|
|
|
|
1993-09-29 20:30:26 +00:00
|
|
|
/* get pointer to this buffer's header structure */
|
2000-08-17 12:15:45 +00:00
|
|
|
packet_ptr = sc->mem_ring +
|
1994-01-03 17:17:19 +00:00
|
|
|
(sc->next_packet - sc->rec_page_start) * ED_PAGE_SIZE;
|
2005-02-21 07:22:50 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* The byte count includes a 4 byte header that was added by
|
|
|
|
* the NIC.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2005-08-28 23:56:25 +00:00
|
|
|
sc->readmem(sc, packet_ptr, (char *) &packet_hdr,
|
|
|
|
sizeof(packet_hdr));
|
1993-09-29 20:30:26 +00:00
|
|
|
len = packet_hdr.count;
|
1996-08-06 21:14:36 +00:00
|
|
|
if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN + sizeof(struct ed_ring)) ||
|
|
|
|
len < (ETHER_MIN_LEN - ETHER_CRC_LEN + sizeof(struct ed_ring))) {
|
1994-10-08 09:24:20 +00:00
|
|
|
/*
|
|
|
|
* Length is a wild value. There's a good chance that
|
|
|
|
* this was caused by the NIC being old and buggy.
|
|
|
|
* The bug is that the length low byte is duplicated in
|
|
|
|
* the high byte. Try to recalculate the length based on
|
|
|
|
* the pointer to the next packet.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* NOTE: sc->next_packet is pointing at the current packet.
|
|
|
|
*/
|
|
|
|
len &= ED_PAGE_SIZE - 1; /* preserve offset into page */
|
2005-02-21 07:22:50 +00:00
|
|
|
if (packet_hdr.next_packet >= sc->next_packet)
|
|
|
|
len += (packet_hdr.next_packet -
|
|
|
|
sc->next_packet) * ED_PAGE_SIZE;
|
|
|
|
else
|
|
|
|
len +=
|
|
|
|
((packet_hdr.next_packet - sc->rec_page_start) +
|
|
|
|
(sc->rec_page_stop - sc->next_packet)) * ED_PAGE_SIZE;
|
1999-03-17 16:44:53 +00:00
|
|
|
/*
|
|
|
|
* because buffers are aligned on 256-byte boundary,
|
|
|
|
* the length computed above is off by 256 in almost
|
|
|
|
* all cases. Fix it...
|
|
|
|
*/
|
|
|
|
if (len & 0xff)
|
2005-02-21 07:22:50 +00:00
|
|
|
len -= 256;
|
1996-10-11 15:19:23 +00:00
|
|
|
if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN
|
2005-02-21 07:22:50 +00:00
|
|
|
+ sizeof(struct ed_ring)))
|
1996-10-11 15:19:23 +00:00
|
|
|
sc->mibdata.dot3StatsFrameTooLongs++;
|
1994-10-08 09:24:20 +00:00
|
|
|
}
|
2005-02-21 07:22:50 +00:00
|
|
|
|
1994-10-08 09:24:20 +00:00
|
|
|
/*
|
|
|
|
* Be fairly liberal about what we allow as a "reasonable" length
|
|
|
|
* so that a [crufty] packet will make it to BPF (and can thus
|
|
|
|
* be analyzed). Note that all that is really important is that
|
|
|
|
* we have a length that will fit into one mbuf cluster or less;
|
|
|
|
* the upper layer protocols can then figure out the length from
|
|
|
|
* their own length field(s).
|
2001-02-08 22:21:30 +00:00
|
|
|
* But make sure that we have at least a full ethernet header
|
|
|
|
* or we would be unable to call ether_input() later.
|
1994-10-08 09:24:20 +00:00
|
|
|
*/
|
2001-02-08 22:54:57 +00:00
|
|
|
if ((len >= sizeof(struct ed_ring) + ETHER_HDR_LEN) &&
|
1995-07-28 12:15:16 +00:00
|
|
|
(len <= MCLBYTES) &&
|
1994-10-08 09:24:20 +00:00
|
|
|
(packet_hdr.next_packet >= sc->rec_page_start) &&
|
|
|
|
(packet_hdr.next_packet < sc->rec_page_stop)) {
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* Go get packet.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_get_packet(sc, packet_ptr + sizeof(struct ed_ring),
|
2000-05-14 02:18:43 +00:00
|
|
|
len - sizeof(struct ed_ring));
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_ipackets++;
|
1993-06-14 22:21:25 +00:00
|
|
|
} else {
|
|
|
|
/*
|
1994-10-08 09:24:20 +00:00
|
|
|
* Really BAD. The ring pointers are corrupted.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
|
|
|
log(LOG_ERR,
|
2003-10-31 18:32:15 +00:00
|
|
|
"%s: NIC memory corrupt - invalid packet length %d\n",
|
|
|
|
ifp->if_xname, len);
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
ed_reset(ifp);
|
1993-06-14 22:21:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update next packet pointer
|
|
|
|
*/
|
1993-09-29 20:30:26 +00:00
|
|
|
sc->next_packet = packet_hdr.next_packet;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* Update NIC boundry pointer - being careful to keep it one
|
|
|
|
* buffer behind. (as recommended by NS databook)
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
|
|
|
boundry = sc->next_packet - 1;
|
|
|
|
if (boundry < sc->rec_page_start)
|
|
|
|
boundry = sc->rec_page_stop - 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set NIC to page 0 registers to update boundry register
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
|
|
|
|
ed_nic_outb(sc, ED_P0_BNRY, boundry);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* Set NIC to page 1 registers before looping to top (prepare
|
|
|
|
* to get 'CURR' current pointer)
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STA);
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet interface interrupt processor
|
|
|
|
*/
|
1999-10-15 03:12:48 +00:00
|
|
|
void
|
2005-02-08 06:12:44 +00:00
|
|
|
edintr(void *arg)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
1999-09-03 19:10:56 +00:00
|
|
|
struct ed_softc *sc = (struct ed_softc*) arg;
|
2005-06-15 20:23:40 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
1994-08-04 17:42:35 +00:00
|
|
|
u_char isr;
|
2001-11-24 16:15:18 +00:00
|
|
|
int count;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_LOCK(sc);
|
2005-09-18 20:51:34 +00:00
|
|
|
if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_UNLOCK(sc);
|
1995-10-10 09:52:55 +00:00
|
|
|
return;
|
2005-08-28 23:56:25 +00:00
|
|
|
}
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Set NIC to page 0 registers
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
2001-11-24 16:15:18 +00:00
|
|
|
* loop until there are no more new interrupts. When the card
|
|
|
|
* goes away, the hardware will read back 0xff. Looking at
|
|
|
|
* the interrupts, it would appear that 0xff is impossible,
|
|
|
|
* or at least extremely unlikely.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2001-11-24 16:15:18 +00:00
|
|
|
while ((isr = ed_nic_inb(sc, ED_P0_ISR)) != 0 && isr != 0xff) {
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* reset all the bits that we are 'acknowledging' by writing a
|
|
|
|
* '1' to each bit position that was set (writing a '1'
|
|
|
|
* *clears* the bit)
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_ISR, isr);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2001-11-24 16:15:18 +00:00
|
|
|
/*
|
|
|
|
* XXX workaround for AX88190
|
|
|
|
* We limit this to 5000 iterations. At 1us per inb/outb,
|
|
|
|
* this translates to about 15ms, which should be plenty
|
|
|
|
* of time, and also gives protection in the card eject
|
|
|
|
* case.
|
|
|
|
*/
|
2000-07-23 15:15:43 +00:00
|
|
|
if (sc->chip_type == ED_CHIP_TYPE_AX88190) {
|
2001-11-24 16:15:18 +00:00
|
|
|
count = 5000; /* 15ms */
|
|
|
|
while (count-- && (ed_nic_inb(sc, ED_P0_ISR) & isr)) {
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_ISR,0);
|
|
|
|
ed_nic_outb(sc, ED_P0_ISR,isr);
|
2000-07-23 15:15:43 +00:00
|
|
|
}
|
2001-11-24 16:15:18 +00:00
|
|
|
if (count == 0)
|
|
|
|
break;
|
2000-07-23 15:15:43 +00:00
|
|
|
}
|
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* Handle transmitter interrupts. Handle these first because
|
|
|
|
* the receiver will reset the board under some conditions.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
1994-08-04 17:42:35 +00:00
|
|
|
if (isr & (ED_ISR_PTX | ED_ISR_TXE)) {
|
2000-08-17 12:15:45 +00:00
|
|
|
u_char collisions = ed_nic_inb(sc, ED_P0_NCR) & 0x0f;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1993-09-22 17:47:43 +00:00
|
|
|
* Check for transmit error. If a TX completed with an
|
|
|
|
* error, we end up throwing the packet away. Really
|
|
|
|
* the only error that is possible is excessive
|
1994-08-04 17:42:35 +00:00
|
|
|
* collisions, and in this case it is best to allow
|
|
|
|
* the automatic mechanisms of TCP to backoff the
|
|
|
|
* flow. Of course, with UDP we're screwed, but this
|
|
|
|
* is expected when a network is heavily loaded.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
(void) ed_nic_inb(sc, ED_P0_TSR);
|
1993-09-22 17:47:43 +00:00
|
|
|
if (isr & ED_ISR_TXE) {
|
1996-10-11 15:19:23 +00:00
|
|
|
u_char tsr;
|
1993-09-22 17:47:43 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
1993-09-22 17:47:43 +00:00
|
|
|
* Excessive collisions (16)
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
tsr = ed_nic_inb(sc, ED_P0_TSR);
|
1996-10-11 15:19:23 +00:00
|
|
|
if ((tsr & ED_TSR_ABT)
|
1994-01-03 17:17:19 +00:00
|
|
|
&& (collisions == 0)) {
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-09-22 17:47:43 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* When collisions total 16, the
|
1993-09-22 17:47:43 +00:00
|
|
|
* P0_NCR will indicate 0, and the
|
|
|
|
* TSR_ABT is set.
|
|
|
|
*/
|
|
|
|
collisions = 16;
|
1996-10-11 15:19:23 +00:00
|
|
|
sc->mibdata.dot3StatsExcessiveCollisions++;
|
|
|
|
sc->mibdata.dot3StatsCollFrequencies[15]++;
|
1993-09-22 17:47:43 +00:00
|
|
|
}
|
1996-10-11 15:19:23 +00:00
|
|
|
if (tsr & ED_TSR_OWC)
|
|
|
|
sc->mibdata.dot3StatsLateCollisions++;
|
|
|
|
if (tsr & ED_TSR_CDH)
|
|
|
|
sc->mibdata.dot3StatsSQETestErrors++;
|
|
|
|
if (tsr & ED_TSR_CRS)
|
|
|
|
sc->mibdata.dot3StatsCarrierSenseErrors++;
|
|
|
|
if (tsr & ED_TSR_FU)
|
|
|
|
sc->mibdata.dot3StatsInternalMacTransmitErrors++;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
1993-09-22 17:47:43 +00:00
|
|
|
/*
|
|
|
|
* update output errors counter
|
|
|
|
*/
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_oerrors++;
|
1993-09-22 17:47:43 +00:00
|
|
|
} else {
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-09-22 17:47:43 +00:00
|
|
|
/*
|
|
|
|
* Update total number of successfully
|
1994-08-04 17:42:35 +00:00
|
|
|
* transmitted packets.
|
1993-09-22 17:47:43 +00:00
|
|
|
*/
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_opackets++;
|
1993-09-22 17:47:43 +00:00
|
|
|
}
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* reset tx busy and output active flags
|
|
|
|
*/
|
|
|
|
sc->xmit_busy = 0;
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1993-06-23 16:22:04 +00:00
|
|
|
* clear watchdog timer
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_timer = 0;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1993-09-22 17:47:43 +00:00
|
|
|
* Add in total number of collisions on last
|
1994-08-04 17:42:35 +00:00
|
|
|
* transmission.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_collisions += collisions;
|
1996-10-11 15:19:23 +00:00
|
|
|
switch(collisions) {
|
|
|
|
case 0:
|
|
|
|
case 16:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sc->mibdata.dot3StatsSingleCollisionFrames++;
|
|
|
|
sc->mibdata.dot3StatsCollFrequencies[0]++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sc->mibdata.dot3StatsMultipleCollisionFrames++;
|
|
|
|
sc->mibdata.
|
|
|
|
dot3StatsCollFrequencies[collisions-1]
|
|
|
|
++;
|
|
|
|
break;
|
|
|
|
}
|
1993-09-22 17:47:43 +00:00
|
|
|
|
|
|
|
/*
|
1993-09-29 20:30:26 +00:00
|
|
|
* Decrement buffer in-use count if not zero (can only
|
1994-08-04 17:42:35 +00:00
|
|
|
* be zero if a transmitter interrupt occured while
|
|
|
|
* not actually transmitting). If data is ready to
|
|
|
|
* transmit, start it transmitting, otherwise defer
|
|
|
|
* until after handling receiver
|
1993-09-22 17:47:43 +00:00
|
|
|
*/
|
1993-09-29 20:30:26 +00:00
|
|
|
if (sc->txb_inuse && --sc->txb_inuse)
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_xmit(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1993-09-22 17:47:43 +00:00
|
|
|
* Handle receiver interrupts
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
1994-08-04 17:42:35 +00:00
|
|
|
if (isr & (ED_ISR_PRX | ED_ISR_RXE | ED_ISR_OVW)) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Overwrite warning. In order to make sure that a
|
|
|
|
* lockup of the local DMA hasn't occurred, we reset
|
|
|
|
* and re-init the NIC. The NSC manual suggests only a
|
|
|
|
* partial reset/re-init is necessary - but some chips
|
|
|
|
* seem to want more. The DMA lockup has been seen
|
|
|
|
* only with early rev chips - Methinks this bug was
|
|
|
|
* fixed in later revs. -DG
|
|
|
|
*/
|
1993-09-22 17:47:43 +00:00
|
|
|
if (isr & ED_ISR_OVW) {
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_ierrors++;
|
1993-09-29 20:30:26 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
1993-09-22 17:47:43 +00:00
|
|
|
log(LOG_WARNING,
|
2003-10-31 18:32:15 +00:00
|
|
|
"%s: warning - receiver ring buffer overrun\n",
|
|
|
|
ifp->if_xname);
|
1993-09-29 20:30:26 +00:00
|
|
|
#endif
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-09-22 17:47:43 +00:00
|
|
|
/*
|
|
|
|
* Stop/reset/re-init NIC
|
|
|
|
*/
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_reset(ifp);
|
1993-09-22 17:47:43 +00:00
|
|
|
} else {
|
1993-06-14 22:21:25 +00:00
|
|
|
|
1994-08-04 17:42:35 +00:00
|
|
|
/*
|
|
|
|
* Receiver Error. One or more of: CRC error,
|
|
|
|
* frame alignment error FIFO overrun, or
|
|
|
|
* missed packet.
|
|
|
|
*/
|
1993-09-22 17:47:43 +00:00
|
|
|
if (isr & ED_ISR_RXE) {
|
1996-10-11 15:19:23 +00:00
|
|
|
u_char rsr;
|
2000-08-17 12:15:45 +00:00
|
|
|
rsr = ed_nic_inb(sc, ED_P0_RSR);
|
1996-10-11 15:19:23 +00:00
|
|
|
if (rsr & ED_RSR_CRC)
|
|
|
|
sc->mibdata.dot3StatsFCSErrors++;
|
|
|
|
if (rsr & ED_RSR_FAE)
|
|
|
|
sc->mibdata.dot3StatsAlignmentErrors++;
|
|
|
|
if (rsr & ED_RSR_FO)
|
|
|
|
sc->mibdata.dot3StatsInternalMacReceiveErrors++;
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_ierrors++;
|
1993-09-22 17:47:43 +00:00
|
|
|
#ifdef ED_DEBUG
|
2002-10-01 00:49:28 +00:00
|
|
|
if_printf(ifp, "receive error %x\n",
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_inb(sc, ED_P0_RSR));
|
1993-09-22 17:47:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
1993-06-14 22:21:25 +00:00
|
|
|
|
1993-09-22 17:47:43 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* Go get the packet(s) XXX - Doing this on an
|
|
|
|
* error is dubious because there shouldn't be
|
|
|
|
* any data to get (we've configured the
|
|
|
|
* interface to not accept packets with
|
|
|
|
* errors).
|
1993-09-22 17:47:43 +00:00
|
|
|
*/
|
1993-06-14 22:21:25 +00:00
|
|
|
|
1993-09-22 17:47:43 +00:00
|
|
|
/*
|
|
|
|
* Enable 16bit access to shared memory first
|
1994-08-04 17:42:35 +00:00
|
|
|
* on WD/SMC boards.
|
1993-09-22 17:47:43 +00:00
|
|
|
*/
|
2005-02-10 23:48:13 +00:00
|
|
|
ed_enable_16bit_access(sc);
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_rint(sc);
|
2005-02-10 23:48:13 +00:00
|
|
|
ed_disable_16bit_access(sc);
|
1993-09-22 17:47:43 +00:00
|
|
|
}
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it looks like the transmitter can take more data,
|
1994-08-04 17:42:35 +00:00
|
|
|
* attempt to start output on the interface. This is done
|
|
|
|
* after handling the receiver to give the receiver priority.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2005-08-09 10:20:02 +00:00
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0)
|
2005-08-28 23:56:25 +00:00
|
|
|
ed_start_locked(ifp);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* return NIC CR to standard state: page 0, remote DMA
|
|
|
|
* complete, start (toggling the TXP bit off, even if was just
|
|
|
|
* set in the transmit routine, is *okay* - it is 'edge'
|
|
|
|
* triggered from low to high)
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-07-27 03:13:50 +00:00
|
|
|
/*
|
1994-08-04 17:42:35 +00:00
|
|
|
* If the Network Talley Counters overflow, read them to reset
|
|
|
|
* them. It appears that old 8390's won't clear the ISR flag
|
|
|
|
* otherwise - resulting in an infinite loop.
|
1993-07-27 03:13:50 +00:00
|
|
|
*/
|
|
|
|
if (isr & ED_ISR_CNT) {
|
2000-08-17 12:15:45 +00:00
|
|
|
(void) ed_nic_inb(sc, ED_P0_CNTR0);
|
|
|
|
(void) ed_nic_inb(sc, ED_P0_CNTR1);
|
|
|
|
(void) ed_nic_inb(sc, ED_P0_CNTR2);
|
1993-07-27 03:13:50 +00:00
|
|
|
}
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_UNLOCK(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
2005-02-08 06:12:44 +00:00
|
|
|
* Process an ioctl request.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
1995-11-18 08:29:04 +00:00
|
|
|
static int
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_ioctl(struct ifnet *ifp, u_long command, caddr_t data)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
1996-02-06 18:51:28 +00:00
|
|
|
struct ed_softc *sc = ifp->if_softc;
|
2001-03-03 08:31:37 +00:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
2005-08-28 23:56:25 +00:00
|
|
|
int error = 0;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
/*
|
|
|
|
* XXX really needed?
|
|
|
|
*/
|
|
|
|
if (sc == NULL) {
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
2005-08-28 23:56:25 +00:00
|
|
|
return (ENXIO);
|
1995-10-21 00:55:36 +00:00
|
|
|
}
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
/*
|
1995-12-05 13:01:33 +00:00
|
|
|
* If the interface is marked up and stopped, then start it.
|
2006-01-27 08:25:47 +00:00
|
|
|
* If we're up and already running, then it may be a mediachg.
|
1995-12-05 13:01:33 +00:00
|
|
|
* If it is marked down and running, then stop it.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_LOCK(sc);
|
1995-12-05 13:01:33 +00:00
|
|
|
if (ifp->if_flags & IFF_UP) {
|
2005-08-09 10:20:02 +00:00
|
|
|
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
|
2005-08-28 23:56:25 +00:00
|
|
|
ed_init_locked(sc);
|
2006-01-27 08:25:47 +00:00
|
|
|
else if (sc->sc_mediachg)
|
|
|
|
sc->sc_mediachg(sc);
|
1995-12-05 13:01:33 +00:00
|
|
|
} else {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
1995-12-05 13:01:33 +00:00
|
|
|
ed_stop(sc);
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
1995-12-05 13:01:33 +00:00
|
|
|
}
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Promiscuous flag may have changed, so reprogram the RCR.
|
|
|
|
*/
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_setrcr(sc);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_UNLOCK(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
break;
|
1994-09-07 06:11:29 +00:00
|
|
|
|
1994-08-04 17:42:35 +00:00
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
/*
|
1997-01-13 21:26:53 +00:00
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
1994-08-04 17:42:35 +00:00
|
|
|
*/
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_LOCK(sc);
|
1997-01-13 21:26:53 +00:00
|
|
|
ed_setrcr(sc);
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_UNLOCK(sc);
|
1997-01-13 21:26:53 +00:00
|
|
|
error = 0;
|
1994-08-04 17:42:35 +00:00
|
|
|
break;
|
1994-08-08 12:09:04 +00:00
|
|
|
|
2001-03-03 08:31:37 +00:00
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
2005-09-18 20:51:34 +00:00
|
|
|
if (sc->sc_media_ioctl == NULL) {
|
2001-03-03 08:31:37 +00:00
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2005-09-18 20:51:34 +00:00
|
|
|
sc->sc_media_ioctl(sc, ifr, command);
|
2001-03-03 08:31:37 +00:00
|
|
|
break;
|
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
default:
|
2002-11-14 23:54:55 +00:00
|
|
|
error = ether_ioctl(ifp, command, data);
|
2005-08-28 23:56:25 +00:00
|
|
|
break;
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1995-12-05 13:01:33 +00:00
|
|
|
/*
|
|
|
|
* Given a source and destination address, copy 'amount' of a packet from
|
|
|
|
* the ring buffer into a linear destination buffer. Takes into account
|
|
|
|
* ring-wrap.
|
|
|
|
*/
|
2005-08-28 23:56:25 +00:00
|
|
|
static __inline void
|
|
|
|
ed_ring_copy(struct ed_softc *sc, bus_size_t src, char *dst, u_short amount)
|
1995-12-05 13:01:33 +00:00
|
|
|
{
|
|
|
|
u_short tmp_amount;
|
|
|
|
|
|
|
|
/* does copy wrap to lower addr in ring buffer? */
|
|
|
|
if (src + amount > sc->mem_end) {
|
|
|
|
tmp_amount = sc->mem_end - src;
|
|
|
|
/* copy amount up to end of NIC memory */
|
2005-08-28 23:56:25 +00:00
|
|
|
sc->readmem(sc, src, dst, tmp_amount);
|
1995-12-05 13:01:33 +00:00
|
|
|
amount -= tmp_amount;
|
|
|
|
src = sc->mem_ring;
|
|
|
|
dst += tmp_amount;
|
|
|
|
}
|
2005-08-28 23:56:25 +00:00
|
|
|
sc->readmem(sc, src, dst, amount);
|
1995-12-05 13:01:33 +00:00
|
|
|
}
|
|
|
|
|
1993-06-14 22:21:25 +00:00
|
|
|
/*
|
|
|
|
* Retreive packet from shared memory and send to the next level up via
|
2000-05-14 02:18:43 +00:00
|
|
|
* ether_input().
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
1993-11-25 01:38:01 +00:00
|
|
|
static void
|
2005-08-28 23:56:25 +00:00
|
|
|
ed_get_packet(struct ed_softc *sc, bus_size_t buf, u_short len)
|
1993-06-14 22:21:25 +00:00
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
1993-06-14 22:21:25 +00:00
|
|
|
struct ether_header *eh;
|
1994-11-26 10:51:49 +00:00
|
|
|
struct mbuf *m;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/* Allocate a header mbuf */
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
1994-10-08 09:24:20 +00:00
|
|
|
if (m == NULL)
|
|
|
|
return;
|
2002-11-14 23:54:55 +00:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
1994-11-26 10:51:49 +00:00
|
|
|
m->m_pkthdr.len = m->m_len = len;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
1995-12-05 13:01:33 +00:00
|
|
|
/*
|
|
|
|
* We always put the received packet in a single buffer -
|
|
|
|
* either with just an mbuf header or in a cluster attached
|
|
|
|
* to the header. The +2 is to compensate for the alignment
|
|
|
|
* fixup below.
|
|
|
|
*/
|
|
|
|
if ((len + 2) > MHLEN) {
|
|
|
|
/* Attach an mbuf cluster */
|
2003-02-19 05:47:46 +00:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
1994-11-26 10:51:49 +00:00
|
|
|
|
1995-12-05 13:01:33 +00:00
|
|
|
/* Insist on getting a cluster */
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
1994-11-26 10:51:49 +00:00
|
|
|
}
|
1993-06-14 22:21:25 +00:00
|
|
|
|
|
|
|
/*
|
1994-11-26 10:51:49 +00:00
|
|
|
* The +2 is to longword align the start of the real packet.
|
|
|
|
* This is important for NFS.
|
1993-06-14 22:21:25 +00:00
|
|
|
*/
|
1994-11-26 10:51:49 +00:00
|
|
|
m->m_data += 2;
|
1994-10-08 09:24:20 +00:00
|
|
|
eh = mtod(m, struct ether_header *);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
1999-03-17 16:44:53 +00:00
|
|
|
/*
|
2004-09-06 21:14:32 +00:00
|
|
|
* Get packet, including link layer address, from interface.
|
1999-03-17 16:44:53 +00:00
|
|
|
*/
|
2004-09-06 21:14:32 +00:00
|
|
|
ed_ring_copy(sc, buf, (char *)eh, len);
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2002-11-14 23:54:55 +00:00
|
|
|
m->m_pkthdr.len = m->m_len = len;
|
1993-06-14 22:21:25 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_UNLOCK(sc);
|
2002-11-14 23:54:55 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_LOCK(sc);
|
1993-06-14 22:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Supporting routines
|
|
|
|
*/
|
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
/*
|
|
|
|
* Given a NIC memory source address and a host memory destination
|
|
|
|
* address, copy 'amount' from NIC to host using shared memory.
|
|
|
|
* The 'amount' is rounded up to a word - okay as long as mbufs
|
|
|
|
* are word sized. That's what the +1 is below.
|
|
|
|
* This routine accesses things as 16 bit quantities.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ed_shmem_readmem16(struct ed_softc *sc, bus_size_t src, uint8_t *dst,
|
|
|
|
uint16_t amount)
|
|
|
|
{
|
|
|
|
bus_space_read_region_2(sc->mem_bst, sc->mem_bsh, src, (uint16_t *)dst,
|
|
|
|
amount + 1 / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a NIC memory source address and a host memory destination
|
|
|
|
* address, copy 'amount' from NIC to host using shared memory.
|
|
|
|
* This routine accesses things as 8 bit quantities.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ed_shmem_readmem8(struct ed_softc *sc, bus_size_t src, uint8_t *dst,
|
|
|
|
uint16_t amount)
|
|
|
|
{
|
|
|
|
bus_space_read_region_1(sc->mem_bst, sc->mem_bsh, src, dst, amount);
|
|
|
|
}
|
|
|
|
|
1993-09-29 20:30:26 +00:00
|
|
|
/*
|
|
|
|
* Given a NIC memory source address and a host memory destination
|
|
|
|
* address, copy 'amount' from NIC to host using Programmed I/O.
|
|
|
|
* The 'amount' is rounded up to a word - okay as long as mbufs
|
|
|
|
* are word sized.
|
|
|
|
* This routine is currently Novell-specific.
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
void
|
2005-08-28 23:56:25 +00:00
|
|
|
ed_pio_readmem(struct ed_softc *sc, bus_size_t src, uint8_t *dst,
|
|
|
|
uint16_t amount)
|
1993-09-29 20:30:26 +00:00
|
|
|
{
|
1996-08-07 11:18:23 +00:00
|
|
|
/* Regular Novell cards */
|
1993-09-29 20:30:26 +00:00
|
|
|
/* select page 0 registers */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STA);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
|
|
|
/* round up to a word */
|
1994-08-04 17:42:35 +00:00
|
|
|
if (amount & 1)
|
|
|
|
++amount;
|
1993-09-29 20:30:26 +00:00
|
|
|
|
|
|
|
/* set up DMA byte count */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_RBCR0, amount);
|
|
|
|
ed_nic_outb(sc, ED_P0_RBCR1, amount >> 8);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
|
|
|
/* set up source address in NIC mem */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_RSAR0, src);
|
|
|
|
ed_nic_outb(sc, ED_P0_RSAR1, src >> 8);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, ED_CR_RD0 | ED_CR_STA);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
2005-02-21 07:22:50 +00:00
|
|
|
if (sc->isa16bit)
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_asic_insw(sc, ED_NOVELL_DATA, dst, amount / 2);
|
2005-02-21 07:22:50 +00:00
|
|
|
else
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_asic_insb(sc, ED_NOVELL_DATA, dst, amount);
|
1993-09-29 20:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stripped down routine for writing a linear buffer to NIC memory.
|
|
|
|
* Only used in the probe routine to test the memory. 'len' must
|
|
|
|
* be even.
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
void
|
2005-02-08 05:59:43 +00:00
|
|
|
ed_pio_writemem(struct ed_softc *sc, uint8_t *src, uint16_t dst, uint16_t len)
|
1993-09-29 20:30:26 +00:00
|
|
|
{
|
1995-02-26 20:03:53 +00:00
|
|
|
int maxwait = 200; /* about 240us */
|
1993-09-29 20:30:26 +00:00
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
/* select page 0 registers */
|
|
|
|
ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STA);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
/* reset remote DMA complete flag */
|
|
|
|
ed_nic_outb(sc, ED_P0_ISR, ED_ISR_RDC);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
/* set up DMA byte count */
|
|
|
|
ed_nic_outb(sc, ED_P0_RBCR0, len);
|
|
|
|
ed_nic_outb(sc, ED_P0_RBCR1, len >> 8);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
/* set up destination address in NIC mem */
|
|
|
|
ed_nic_outb(sc, ED_P0_RSAR0, dst);
|
|
|
|
ed_nic_outb(sc, ED_P0_RSAR1, dst >> 8);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
/* set remote DMA write */
|
|
|
|
ed_nic_outb(sc, ED_P0_CR, ED_CR_RD1 | ED_CR_STA);
|
1996-08-07 11:18:23 +00:00
|
|
|
|
2005-02-21 07:22:50 +00:00
|
|
|
if (sc->isa16bit)
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_asic_outsw(sc, ED_NOVELL_DATA, src, len / 2);
|
2005-02-21 07:22:50 +00:00
|
|
|
else
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_asic_outsb(sc, ED_NOVELL_DATA, src, len);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for remote DMA complete. This is necessary because on the
|
|
|
|
* transmit side, data is handled internally by the NIC in bursts and
|
|
|
|
* we can't start another remote DMA until this one completes. Not
|
|
|
|
* waiting causes really bad things to happen - like the NIC
|
|
|
|
* irrecoverably jamming the ISA bus.
|
|
|
|
*/
|
2005-02-10 23:31:27 +00:00
|
|
|
while (((ed_nic_inb(sc, ED_P0_ISR) & ED_ISR_RDC) != ED_ISR_RDC) &&
|
|
|
|
--maxwait)
|
|
|
|
continue;
|
1993-09-29 20:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write an mbuf chain to the destination NIC memory address using
|
|
|
|
* programmed I/O.
|
|
|
|
*/
|
2006-01-27 19:10:13 +00:00
|
|
|
u_short
|
2005-08-28 23:56:25 +00:00
|
|
|
ed_pio_write_mbufs(struct ed_softc *sc, struct mbuf *m, bus_size_t dst)
|
1993-09-29 20:30:26 +00:00
|
|
|
{
|
2005-06-15 20:23:40 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
1995-01-04 21:10:17 +00:00
|
|
|
unsigned short total_len, dma_len;
|
1993-09-29 20:30:26 +00:00
|
|
|
struct mbuf *mp;
|
1995-02-26 20:03:53 +00:00
|
|
|
int maxwait = 200; /* about 240us */
|
1993-09-29 20:30:26 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_ASSERT_LOCKED(sc);
|
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
/* Regular Novell cards */
|
1993-09-29 20:30:26 +00:00
|
|
|
/* First, count up the total number of bytes to copy */
|
1995-01-04 21:10:17 +00:00
|
|
|
for (total_len = 0, mp = m; mp; mp = mp->m_next)
|
|
|
|
total_len += mp->m_len;
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1995-01-04 21:10:17 +00:00
|
|
|
dma_len = total_len;
|
1995-01-01 06:38:14 +00:00
|
|
|
if (sc->isa16bit && (dma_len & 1))
|
|
|
|
dma_len++;
|
|
|
|
|
1993-09-29 20:30:26 +00:00
|
|
|
/* select page 0 registers */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, ED_CR_RD2 | ED_CR_STA);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
|
|
|
/* reset remote DMA complete flag */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_ISR, ED_ISR_RDC);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
|
|
|
/* set up DMA byte count */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_RBCR0, dma_len);
|
|
|
|
ed_nic_outb(sc, ED_P0_RBCR1, dma_len >> 8);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
|
|
|
/* set up destination address in NIC mem */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_RSAR0, dst);
|
|
|
|
ed_nic_outb(sc, ED_P0_RSAR1, dst >> 8);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
|
|
|
/* set remote DMA write */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, ED_CR_RD1 | ED_CR_STA);
|
1993-09-29 20:30:26 +00:00
|
|
|
|
1994-10-14 11:56:36 +00:00
|
|
|
/*
|
1995-05-30 08:16:23 +00:00
|
|
|
* Transfer the mbuf chain to the NIC memory.
|
1994-10-14 11:56:36 +00:00
|
|
|
* 16-bit cards require that data be transferred as words, and only words.
|
|
|
|
* So that case requires some extra code to patch over odd-length mbufs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!sc->isa16bit) {
|
|
|
|
/* NE1000s are easy */
|
|
|
|
while (m) {
|
2005-02-21 07:22:50 +00:00
|
|
|
if (m->m_len)
|
|
|
|
ed_asic_outsb(sc, ED_NOVELL_DATA,
|
|
|
|
m->m_data, m->m_len);
|
1994-10-14 11:56:36 +00:00
|
|
|
m = m->m_next;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* NE2000s are a pain */
|
|
|
|
unsigned char *data;
|
|
|
|
int len, wantbyte;
|
|
|
|
unsigned char savebyte[2];
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-10-14 11:56:36 +00:00
|
|
|
wantbyte = 0;
|
|
|
|
|
|
|
|
while (m) {
|
|
|
|
len = m->m_len;
|
|
|
|
if (len) {
|
1995-01-04 21:10:17 +00:00
|
|
|
data = mtod(m, caddr_t);
|
1994-10-14 11:56:36 +00:00
|
|
|
/* finish the last word */
|
|
|
|
if (wantbyte) {
|
|
|
|
savebyte[1] = *data;
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_asic_outw(sc, ED_NOVELL_DATA,
|
|
|
|
*(u_short *)savebyte);
|
1994-10-14 11:56:36 +00:00
|
|
|
data++;
|
|
|
|
len--;
|
|
|
|
wantbyte = 0;
|
|
|
|
}
|
|
|
|
/* output contiguous words */
|
|
|
|
if (len > 1) {
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_asic_outsw(sc, ED_NOVELL_DATA,
|
|
|
|
data, len >> 1);
|
1994-10-14 11:56:36 +00:00
|
|
|
data += len & ~1;
|
|
|
|
len &= 1;
|
|
|
|
}
|
|
|
|
/* save last byte, if necessary */
|
|
|
|
if (len == 1) {
|
|
|
|
savebyte[0] = *data;
|
|
|
|
wantbyte = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m = m->m_next;
|
1993-09-29 20:30:26 +00:00
|
|
|
}
|
1994-10-14 11:56:36 +00:00
|
|
|
/* spit last byte */
|
2005-02-21 07:22:50 +00:00
|
|
|
if (wantbyte)
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_asic_outw(sc, ED_NOVELL_DATA, *(u_short *)savebyte);
|
1993-09-29 20:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for remote DMA complete. This is necessary because on the
|
1994-08-04 17:42:35 +00:00
|
|
|
* transmit side, data is handled internally by the NIC in bursts and
|
|
|
|
* we can't start another remote DMA until this one completes. Not
|
|
|
|
* waiting causes really bad things to happen - like the NIC
|
|
|
|
* irrecoverably jamming the ISA bus.
|
1993-09-29 20:30:26 +00:00
|
|
|
*/
|
2005-02-10 23:31:27 +00:00
|
|
|
while (((ed_nic_inb(sc, ED_P0_ISR) & ED_ISR_RDC) != ED_ISR_RDC) &&
|
|
|
|
--maxwait)
|
|
|
|
continue;
|
1993-09-29 20:30:26 +00:00
|
|
|
|
|
|
|
if (!maxwait) {
|
2003-10-31 18:32:15 +00:00
|
|
|
log(LOG_WARNING, "%s: remote transmit DMA failed to complete\n",
|
|
|
|
ifp->if_xname);
|
1995-12-05 02:01:59 +00:00
|
|
|
ed_reset(ifp);
|
1995-01-04 21:10:17 +00:00
|
|
|
return(0);
|
1993-09-29 20:30:26 +00:00
|
|
|
}
|
1995-01-04 21:10:17 +00:00
|
|
|
return (total_len);
|
1993-09-29 20:30:26 +00:00
|
|
|
}
|
1994-08-04 17:42:35 +00:00
|
|
|
|
1995-11-18 08:29:04 +00:00
|
|
|
static void
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_setrcr(struct ed_softc *sc)
|
1994-08-04 17:42:35 +00:00
|
|
|
{
|
2005-06-15 20:23:40 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
1994-08-04 17:42:35 +00:00
|
|
|
int i;
|
2000-08-14 04:31:07 +00:00
|
|
|
u_char reg1;
|
2000-07-23 15:15:43 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
ED_ASSERT_LOCKED(sc);
|
|
|
|
|
2000-07-23 15:15:43 +00:00
|
|
|
/* Bit 6 in AX88190 RCR register must be set. */
|
|
|
|
if (sc->chip_type == ED_CHIP_TYPE_AX88190)
|
|
|
|
reg1 = ED_RCR_INTT;
|
|
|
|
else
|
|
|
|
reg1 = 0x00;
|
|
|
|
|
1994-08-04 17:42:35 +00:00
|
|
|
/* set page 1 registers */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_PAGE_1 | ED_CR_STP);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reconfigure the multicast filter.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 8; i++)
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P1_MAR(i), 0xff);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* And turn on promiscuous mode. Also enable reception of
|
|
|
|
* runts and packets with CRC & alignment errors.
|
|
|
|
*/
|
|
|
|
/* Set page 0 registers */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
|
1994-09-07 06:11:29 +00:00
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_RCR, ED_RCR_PRO | ED_RCR_AM |
|
|
|
|
ED_RCR_AB | ED_RCR_AR | ED_RCR_SEP | reg1);
|
1994-08-04 17:42:35 +00:00
|
|
|
} else {
|
|
|
|
/* set up multicast addresses and filter modes */
|
|
|
|
if (ifp->if_flags & IFF_MULTICAST) {
|
2005-01-19 07:37:32 +00:00
|
|
|
uint32_t mcaf[2];
|
1994-08-04 17:42:35 +00:00
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_ALLMULTI) {
|
|
|
|
mcaf[0] = 0xffffffff;
|
|
|
|
mcaf[1] = 0xffffffff;
|
|
|
|
} else
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_ds_getmcaf(sc, mcaf);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set multicast filter on chip.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 8; i++)
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P1_MAR(i), ((u_char *) mcaf)[i]);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
|
|
|
/* Set page 0 registers */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_RCR, ED_RCR_AM | ED_RCR_AB | reg1);
|
1994-08-04 17:42:35 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize multicast address hashing registers to
|
|
|
|
* not accept multicasts.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 8; ++i)
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P1_MAR(i), 0x00);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
|
|
|
/* Set page 0 registers */
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STP);
|
1994-08-04 17:42:35 +00:00
|
|
|
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_RCR, ED_RCR_AB | reg1);
|
1994-08-04 17:42:35 +00:00
|
|
|
}
|
|
|
|
}
|
1994-11-17 14:42:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start interface.
|
|
|
|
*/
|
2000-08-17 12:15:45 +00:00
|
|
|
ed_nic_outb(sc, ED_P0_CR, sc->cr_proto | ED_CR_STA);
|
1994-08-04 17:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the multicast address filter from the
|
|
|
|
* list of multicast addresses we need to listen to.
|
|
|
|
*/
|
1995-11-18 08:29:04 +00:00
|
|
|
static void
|
2005-02-08 06:12:44 +00:00
|
|
|
ed_ds_getmcaf(struct ed_softc *sc, uint32_t *mcaf)
|
1994-08-04 17:42:35 +00:00
|
|
|
{
|
2005-02-08 06:12:44 +00:00
|
|
|
uint32_t index;
|
|
|
|
u_char *af = (u_char *) mcaf;
|
1997-01-13 21:26:53 +00:00
|
|
|
struct ifmultiaddr *ifma;
|
1994-08-04 17:42:35 +00:00
|
|
|
|
|
|
|
mcaf[0] = 0;
|
|
|
|
mcaf[1] = 0;
|
|
|
|
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_LOCK(sc->ifp);
|
2005-06-10 16:49:24 +00:00
|
|
|
TAILQ_FOREACH(ifma, &sc->ifp->if_multiaddrs, ifma_link) {
|
1997-01-13 21:26:53 +00:00
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
2004-06-09 14:34:04 +00:00
|
|
|
index = ether_crc32_be(LLADDR((struct sockaddr_dl *)
|
|
|
|
ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
|
1994-08-04 17:42:35 +00:00
|
|
|
af[index >> 3] |= 1 << (index & 7);
|
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_UNLOCK(sc->ifp);
|
1994-08-04 17:42:35 +00:00
|
|
|
}
|
2005-02-08 23:57:43 +00:00
|
|
|
|
2005-02-09 20:03:40 +00:00
|
|
|
int
|
|
|
|
ed_isa_mem_ok(device_t dev, u_long pmem, u_int memsize)
|
|
|
|
{
|
|
|
|
if (pmem < 0xa0000 || pmem + memsize > 0x1000000) {
|
|
|
|
device_printf(dev, "Invalid ISA memory address range "
|
|
|
|
"configured: 0x%lx - 0x%lx\n", pmem, pmem + memsize);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-02-08 23:57:43 +00:00
|
|
|
int
|
|
|
|
ed_clear_memory(device_t dev)
|
|
|
|
{
|
|
|
|
struct ed_softc *sc = device_get_softc(dev);
|
2005-08-28 23:56:25 +00:00
|
|
|
bus_size_t i;
|
2005-02-08 23:57:43 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
bus_space_set_region_1(sc->mem_bst, sc->mem_bsh, sc->mem_start,
|
|
|
|
0, sc->mem_size);
|
2005-02-08 23:57:43 +00:00
|
|
|
|
2005-08-28 23:56:25 +00:00
|
|
|
for (i = 0; i < sc->mem_size; i++) {
|
|
|
|
if (bus_space_read_1(sc->mem_bst, sc->mem_bsh,
|
|
|
|
sc->mem_start + i)) {
|
2005-02-08 23:57:43 +00:00
|
|
|
device_printf(dev, "failed to clear shared memory at "
|
|
|
|
"0x%jx - check configuration\n",
|
|
|
|
(uintmax_t)rman_get_start(sc->mem_res) + i);
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
2006-01-27 19:10:13 +00:00
|
|
|
|
|
|
|
u_short
|
|
|
|
ed_shmem_write_mbufs(struct ed_softc *sc, struct mbuf *m, bus_size_t dst)
|
|
|
|
{
|
|
|
|
u_short len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Special case setup for 16 bit boards...
|
|
|
|
*/
|
|
|
|
if (sc->isa16bit) {
|
|
|
|
switch (sc->vendor) {
|
|
|
|
#ifdef ED_3C503
|
|
|
|
/*
|
|
|
|
* For 16bit 3Com boards (which have 16k of
|
|
|
|
* memory), we have the xmit buffers in a
|
|
|
|
* different page of memory ('page 0') - so
|
|
|
|
* change pages.
|
|
|
|
*/
|
|
|
|
case ED_VENDOR_3COM:
|
|
|
|
ed_asic_outb(sc, ED_3COM_GACFR, ED_3COM_GACFR_RSEL);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Enable 16bit access to shared memory on
|
|
|
|
* WD/SMC boards.
|
|
|
|
*
|
|
|
|
* XXX - same as ed_enable_16bit_access()
|
|
|
|
*/
|
|
|
|
case ED_VENDOR_WD_SMC:
|
|
|
|
ed_asic_outb(sc, ED_WD_LAAR,
|
|
|
|
sc->wd_laar_proto | ED_WD_LAAR_M16EN);
|
|
|
|
if (sc->chip_type == ED_CHIP_TYPE_WD790)
|
|
|
|
ed_asic_outb(sc, ED_WD_MSR, ED_WD_MSR_MENB);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (len = 0; m != 0; m = m->m_next) {
|
|
|
|
if (sc->isa16bit)
|
|
|
|
bus_space_write_region_2(sc->mem_bst,
|
|
|
|
sc->mem_bsh, dst,
|
|
|
|
mtod(m, uint16_t *), (m->m_len + 1)/ 2);
|
|
|
|
else
|
|
|
|
bus_space_write_region_1(sc->mem_bst,
|
|
|
|
sc->mem_bsh, dst,
|
|
|
|
mtod(m, uint8_t *), m->m_len);
|
|
|
|
dst += m->m_len;
|
|
|
|
len += m->m_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore previous shared memory access
|
|
|
|
*/
|
|
|
|
if (sc->isa16bit) {
|
|
|
|
switch (sc->vendor) {
|
|
|
|
#ifdef ED_3C503
|
|
|
|
case ED_VENDOR_3COM:
|
|
|
|
ed_asic_outb(sc, ED_3COM_GACFR,
|
|
|
|
ED_3COM_GACFR_RSEL | ED_3COM_GACFR_MBS0);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case ED_VENDOR_WD_SMC:
|
|
|
|
/* XXX - same as ed_disable_16bit_access() */
|
|
|
|
if (sc->chip_type == ED_CHIP_TYPE_WD790)
|
|
|
|
ed_asic_outb(sc, ED_WD_MSR, 0x00);
|
|
|
|
ed_asic_outb(sc, ED_WD_LAAR,
|
|
|
|
sc->wd_laar_proto & ~ED_WD_LAAR_M16EN);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (len);
|
|
|
|
}
|