2000-04-12 06:51:43 +00:00
|
|
|
/* $OpenBSD: if_tx.c,v 1.9.2.1 2000/02/21 22:29:13 niklas Exp $ */
|
1999-08-28 01:08:13 +00:00
|
|
|
/* $FreeBSD$ */
|
1998-11-01 07:44:33 +00:00
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/*-
|
2002-04-20 12:39:41 +00:00
|
|
|
* Copyright (c) 1997 Semen Ustimenko (semenu@FreeBSD.org)
|
1998-01-21 18:33:00 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EtherPower II 10/100 Fast Ethernet (tx0)
|
|
|
|
* (aka SMC9432TX based on SMC83c170 EPIC chip)
|
1998-11-01 07:44:33 +00:00
|
|
|
*
|
|
|
|
* Thanks are going to Steve Bauer and Jason Wright.
|
1998-01-21 18:33:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-04-12 06:51:43 +00:00
|
|
|
#include <sys/sockio.h>
|
1998-01-21 18:33:00 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
1998-11-01 07:44:33 +00:00
|
|
|
#include <sys/socket.h>
|
2000-04-12 06:51:43 +00:00
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
#define NBPFILTER 1
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
#include <net/ethernet.h>
|
2002-04-25 18:16:15 +00:00
|
|
|
#include <net/if_dl.h>
|
2000-04-12 06:51:43 +00:00
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
2001-08-13 18:32:39 +00:00
|
|
|
#include <net/if_vlan_var.h>
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
#include <vm/vm.h> /* for vtophys */
|
|
|
|
#include <vm/pmap.h> /* for vtophys */
|
|
|
|
#include <machine/bus_memio.h>
|
|
|
|
#include <machine/bus_pio.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <pci/pcireg.h>
|
|
|
|
#include <pci/pcivar.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
2001-02-07 20:11:02 +00:00
|
|
|
#include <dev/mii/miidevs.h>
|
|
|
|
|
|
|
|
#include <dev/mii/lxtphyreg.h>
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
#include "miibus_if.h"
|
|
|
|
|
2002-04-19 22:43:57 +00:00
|
|
|
#include <dev/tx/if_txreg.h>
|
|
|
|
#include <dev/tx/if_txvar.h>
|
2000-04-12 06:51:43 +00:00
|
|
|
#else /* __OpenBSD__ */
|
|
|
|
#include "bpfilter.h"
|
|
|
|
|
2001-08-13 18:32:39 +00:00
|
|
|
#define NVLAN 0 /* not sure if/how OpenBSD supports VLANs */
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
#include <sys/device.h>
|
1998-11-01 07:44:33 +00:00
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
#include <net/if.h>
|
1998-11-01 07:44:33 +00:00
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_types.h>
|
1998-02-20 18:08:46 +00:00
|
|
|
#include <net/if_media.h>
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
2000-04-12 06:51:43 +00:00
|
|
|
#include <netinet/if_ether.h>
|
1998-11-01 07:44:33 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IPX
|
|
|
|
#include <netipx/ipx.h>
|
|
|
|
#include <netipx/ipx_if.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
|
|
|
#endif
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
#if NBPFILTER > 0
|
1998-11-01 07:44:33 +00:00
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
2000-04-12 06:51:43 +00:00
|
|
|
#include <vm/pmap.h>
|
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
2001-02-07 20:11:02 +00:00
|
|
|
#include <dev/mii/miidevs.h>
|
|
|
|
#include <dev/mii/lxtphyreg.h>
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
|
|
|
#include <dev/pci/if_txvar.h>
|
|
|
|
#endif
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2000-04-29 13:41:57 +00:00
|
|
|
MODULE_DEPEND(tx, miibus, 1, 1, 1);
|
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
#define EPIC_INTR_RET_TYPE void
|
|
|
|
#else /* __OpenBSD__ */
|
|
|
|
#define EPIC_INTR_RET_TYPE int
|
|
|
|
#endif
|
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static int epic_ifioctl(register struct ifnet *, u_long, caddr_t);
|
|
|
|
static EPIC_INTR_RET_TYPE epic_intr(void *);
|
|
|
|
static int epic_common_attach(epic_softc_t *);
|
|
|
|
static void epic_ifstart(struct ifnet *);
|
|
|
|
static void epic_ifwatchdog(struct ifnet *);
|
2002-05-01 19:23:04 +00:00
|
|
|
static void epic_stats_update(epic_softc_t *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static int epic_init(epic_softc_t *);
|
|
|
|
static void epic_stop(epic_softc_t *);
|
|
|
|
static void epic_rx_done(epic_softc_t *);
|
|
|
|
static void epic_tx_done(epic_softc_t *);
|
|
|
|
static int epic_init_rings(epic_softc_t *);
|
|
|
|
static void epic_free_rings(epic_softc_t *);
|
|
|
|
static void epic_stop_activity(epic_softc_t *);
|
|
|
|
static void epic_start_activity(epic_softc_t *);
|
|
|
|
static void epic_set_rx_mode(epic_softc_t *);
|
|
|
|
static void epic_set_tx_mode(epic_softc_t *);
|
|
|
|
static void epic_set_mc_table(epic_softc_t *);
|
2002-04-25 18:16:15 +00:00
|
|
|
static u_int8_t epic_calchash(caddr_t);
|
2002-03-20 02:08:01 +00:00
|
|
|
static int epic_read_eeprom(epic_softc_t *,u_int16_t);
|
|
|
|
static void epic_output_eepromw(epic_softc_t *, u_int16_t);
|
|
|
|
static u_int16_t epic_input_eepromw(epic_softc_t *);
|
|
|
|
static u_int8_t epic_eeprom_clock(epic_softc_t *,u_int8_t);
|
|
|
|
static void epic_write_eepromreg(epic_softc_t *,u_int8_t);
|
|
|
|
static u_int8_t epic_read_eepromreg(epic_softc_t *);
|
|
|
|
|
|
|
|
static int epic_read_phy_reg(epic_softc_t *, int, int);
|
|
|
|
static void epic_write_phy_reg(epic_softc_t *, int, int, int);
|
|
|
|
|
|
|
|
static int epic_miibus_readreg(device_t, int, int);
|
|
|
|
static int epic_miibus_writereg(device_t, int, int, int);
|
|
|
|
static void epic_miibus_statchg(device_t);
|
|
|
|
static void epic_miibus_mediainit(device_t);
|
|
|
|
|
|
|
|
static int epic_ifmedia_upd(struct ifnet *);
|
|
|
|
static void epic_ifmedia_sts(struct ifnet *, struct ifmediareq *);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
/* -------------------------------------------------------------------------
|
|
|
|
OS-specific part
|
|
|
|
------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
/* -----------------------------OpenBSD------------------------------------- */
|
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
int epic_openbsd_probe(struct device *,void *,void *);
|
|
|
|
void epic_openbsd_attach(struct device *, struct device *, void *);
|
|
|
|
void epic_openbsd_shutdown(void *);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
struct cfattach tx_ca = {
|
|
|
|
sizeof(epic_softc_t), epic_openbsd_probe, epic_openbsd_attach
|
|
|
|
};
|
|
|
|
struct cfdriver tx_cd = {
|
|
|
|
NULL,"tx",DV_IFNET
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Synopsis: Check if device id corresponds with SMC83C170 id. */
|
2000-04-12 06:51:43 +00:00
|
|
|
int
|
1998-11-01 07:44:33 +00:00
|
|
|
epic_openbsd_probe(
|
|
|
|
struct device *parent,
|
|
|
|
void *match,
|
|
|
|
void *aux )
|
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
if( PCI_VENDOR(pa->pa_id) != SMC_VENDORID )
|
|
|
|
return 0;
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
if( PCI_PRODUCT(pa->pa_id) == SMC_DEVICEID_83C170 )
|
1998-11-01 07:44:33 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
void
|
1998-11-01 07:44:33 +00:00
|
|
|
epic_openbsd_attach(
|
|
|
|
struct device *parent,
|
|
|
|
struct device *self,
|
|
|
|
void *aux )
|
|
|
|
{
|
|
|
|
epic_softc_t *sc = (epic_softc_t*)self;
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
pci_chipset_tag_t pc = pa->pa_pc;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
const char *intrstr = NULL;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
bus_addr_t iobase;
|
|
|
|
bus_size_t iosize;
|
|
|
|
int i;
|
2000-04-12 06:51:43 +00:00
|
|
|
u_int32_t command;
|
|
|
|
|
|
|
|
command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
|
|
|
|
command |= PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
|
|
|
|
PCI_COMMAND_MASTER_ENABLE;
|
|
|
|
pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, command);
|
|
|
|
command = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
#ifdef EPIC_USEIOSPACE
|
|
|
|
if (!(command & PCI_COMMAND_IO_ENABLE)) {
|
|
|
|
printf(": failed to enable I/O ports\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( pci_io_find(pc, pa->pa_tag, PCI_BASEIO, &iobase, &iosize)) {
|
1998-11-01 07:44:33 +00:00
|
|
|
printf(": can't find i/o space\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-04-12 06:51:43 +00:00
|
|
|
if( bus_space_map(pa->pa_iot, iobase, iosize, 0, &sc->sc_sh)) {
|
1998-11-01 07:44:33 +00:00
|
|
|
printf(": can't map i/o space\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-04-12 06:51:43 +00:00
|
|
|
sc->sc_st = pa->pa_iot;
|
|
|
|
#else
|
|
|
|
if (!(command & PCI_COMMAND_MEM_ENABLE)) {
|
|
|
|
printf(": failed to enable memory mapping\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( pci_mem_find(pc, pa->pa_tag, PCI_BASEMEM, &iobase, &iosize, NULL)) {
|
|
|
|
printf(": can't find mem space\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( bus_space_map(pa->pa_memt, iobase, iosize, 0, &sc->sc_sh)) {
|
|
|
|
printf(": can't map i/o space\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sc->sc_st = pa->pa_memt;
|
|
|
|
#endif
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
ifp = &sc->sc_if;
|
2000-06-21 19:19:49 +00:00
|
|
|
bcopy(sc->dev.dv_xname, ifp->if_xname,IFNAMSIZ);
|
1998-11-01 07:44:33 +00:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_ioctl = epic_ifioctl;
|
|
|
|
ifp->if_start = epic_ifstart;
|
|
|
|
ifp->if_watchdog = epic_ifwatchdog;
|
|
|
|
|
|
|
|
/* Do common attach procedure */
|
|
|
|
if( epic_common_attach(sc) ) return;
|
|
|
|
|
|
|
|
/* Map interrupt */
|
|
|
|
if( pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
|
|
|
|
pa->pa_intrline, &ih)) {
|
|
|
|
printf(": can't map interrupt\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
intrstr = pci_intr_string(pc, ih);
|
|
|
|
sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epic_intr, sc,
|
|
|
|
self->dv_xname);
|
|
|
|
|
|
|
|
if( NULL == sc->sc_ih ) {
|
|
|
|
printf(": can't establish interrupt");
|
|
|
|
if( intrstr )printf(" at %s",intrstr);
|
|
|
|
printf("\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf(": %s",intrstr);
|
|
|
|
|
|
|
|
/* Display some info */
|
|
|
|
printf(" address %s",ether_sprintf(sc->sc_macaddr));
|
|
|
|
|
|
|
|
/* Init ifmedia interface */
|
2000-04-12 06:51:43 +00:00
|
|
|
ifmedia_init(&sc->sc_mii.mii_media, 0,
|
|
|
|
epic_ifmedia_upd, epic_ifmedia_sts);
|
|
|
|
sc->sc_mii.mii_ifp = ifp;
|
|
|
|
sc->sc_mii.mii_readreg = epic_miibus_readreg;
|
|
|
|
sc->sc_mii.mii_writereg = epic_miibus_writereg;
|
|
|
|
sc->sc_mii.mii_statchg = epic_miibus_statchg;
|
|
|
|
mii_phy_probe(self, &sc->sc_mii, 0xffffffff);
|
|
|
|
if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
|
|
|
|
ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE,0,NULL);
|
|
|
|
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
|
|
|
|
} else
|
|
|
|
ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
/* Attach os interface and bpf */
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp);
|
2000-04-12 06:51:43 +00:00
|
|
|
#if NBPFILTER > 0
|
1998-11-01 07:44:33 +00:00
|
|
|
bpfattach(&sc->sc_if.if_bpf, ifp, DLT_EN10MB,
|
|
|
|
sizeof(struct ether_header));
|
1998-01-21 18:33:00 +00:00
|
|
|
#endif
|
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
/* Set shutdown routine to stop DMA process */
|
2000-04-12 06:51:43 +00:00
|
|
|
shutdownhook_establish(epic_openbsd_shutdown, sc);
|
1998-11-01 07:44:33 +00:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Simple call epic_stop() */
|
2000-04-12 06:51:43 +00:00
|
|
|
void
|
|
|
|
epic_openbsd_shutdown(
|
1998-11-01 07:44:33 +00:00
|
|
|
void *sc)
|
|
|
|
{
|
|
|
|
epic_stop(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* __FreeBSD__ */
|
|
|
|
/* -----------------------------FreeBSD------------------------------------- */
|
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static int epic_freebsd_probe(device_t);
|
|
|
|
static int epic_freebsd_attach(device_t);
|
|
|
|
static void epic_freebsd_shutdown(device_t);
|
|
|
|
static int epic_freebsd_detach(device_t);
|
|
|
|
static struct epic_type *epic_devtype(device_t);
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
static device_method_t epic_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, epic_freebsd_probe),
|
|
|
|
DEVMETHOD(device_attach, epic_freebsd_attach),
|
|
|
|
DEVMETHOD(device_detach, epic_freebsd_detach),
|
|
|
|
DEVMETHOD(device_shutdown, epic_freebsd_shutdown),
|
|
|
|
|
|
|
|
/* bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, bus_generic_print_child),
|
|
|
|
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
|
|
|
|
|
|
|
/* MII interface */
|
|
|
|
DEVMETHOD(miibus_readreg, epic_miibus_readreg),
|
|
|
|
DEVMETHOD(miibus_writereg, epic_miibus_writereg),
|
|
|
|
DEVMETHOD(miibus_statchg, epic_miibus_statchg),
|
2000-06-21 19:19:49 +00:00
|
|
|
DEVMETHOD(miibus_mediainit, epic_miibus_mediainit),
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t epic_driver = {
|
|
|
|
"tx",
|
|
|
|
epic_methods,
|
|
|
|
sizeof(epic_softc_t)
|
1999-05-09 17:07:30 +00:00
|
|
|
};
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
static devclass_t epic_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(if_tx, pci, epic_driver, epic_devclass, 0, 0);
|
|
|
|
DRIVER_MODULE(miibus, tx, miibus_driver, miibus_devclass, 0, 0);
|
|
|
|
|
|
|
|
static struct epic_type epic_devs[] = {
|
|
|
|
{ SMC_VENDORID, SMC_DEVICEID_83C170,
|
2000-06-21 19:19:49 +00:00
|
|
|
"SMC EtherPower II 10/100" },
|
2000-04-12 06:51:43 +00:00
|
|
|
{ 0, 0, NULL }
|
|
|
|
};
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
static int
|
|
|
|
epic_freebsd_probe(dev)
|
|
|
|
device_t dev;
|
1998-11-01 07:44:33 +00:00
|
|
|
{
|
2000-04-12 06:51:43 +00:00
|
|
|
struct epic_type *t;
|
|
|
|
|
|
|
|
t = epic_devtype(dev);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
if (t != NULL) {
|
|
|
|
device_set_desc(dev, t->name);
|
|
|
|
return(0);
|
|
|
|
}
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
return(ENXIO);
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
static struct epic_type *
|
|
|
|
epic_devtype(dev)
|
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct epic_type *t;
|
|
|
|
|
|
|
|
t = epic_devs;
|
|
|
|
|
|
|
|
while(t->name != NULL) {
|
|
|
|
if ((pci_get_vendor(dev) == t->ven_id) &&
|
|
|
|
(pci_get_device(dev) == t->dev_id)) {
|
|
|
|
return(t);
|
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(EPIC_USEIOSPACE)
|
|
|
|
#define EPIC_RES SYS_RES_IOPORT
|
|
|
|
#define EPIC_RID PCIR_BASEIO
|
|
|
|
#else
|
|
|
|
#define EPIC_RES SYS_RES_MEMORY
|
|
|
|
#define EPIC_RID PCIR_BASEMEM
|
|
|
|
#endif
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/*
|
1998-11-01 07:44:33 +00:00
|
|
|
* Do FreeBSD-specific attach routine, like map registers, alloc softc
|
|
|
|
* structure and etc.
|
1998-01-21 18:33:00 +00:00
|
|
|
*/
|
2000-04-12 06:51:43 +00:00
|
|
|
static int
|
|
|
|
epic_freebsd_attach(dev)
|
|
|
|
device_t dev;
|
1998-11-01 07:44:33 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
epic_softc_t *sc;
|
1999-10-29 09:56:52 +00:00
|
|
|
u_int32_t command;
|
2000-04-12 06:51:43 +00:00
|
|
|
int unit, error;
|
|
|
|
int i, s, rid, tmp;
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
s = splimp ();
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
unit = device_get_unit(dev);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
/* Preinitialize softc structure */
|
|
|
|
bzero(sc, sizeof(epic_softc_t));
|
|
|
|
sc->unit = unit;
|
2000-06-21 19:19:49 +00:00
|
|
|
sc->dev = dev;
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
/* Fill ifnet structure */
|
|
|
|
ifp = &sc->sc_if;
|
|
|
|
ifp->if_unit = unit;
|
|
|
|
ifp->if_name = "tx";
|
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
|
|
|
|
ifp->if_ioctl = epic_ifioctl;
|
2000-04-12 06:51:43 +00:00
|
|
|
ifp->if_output = ether_output;
|
1998-11-01 07:44:33 +00:00
|
|
|
ifp->if_start = epic_ifstart;
|
|
|
|
ifp->if_watchdog = epic_ifwatchdog;
|
|
|
|
ifp->if_init = (if_init_f_t*)epic_init;
|
|
|
|
ifp->if_timer = 0;
|
2000-04-12 06:51:43 +00:00
|
|
|
ifp->if_baudrate = 10000000;
|
|
|
|
ifp->if_snd.ifq_maxlen = TX_RING_SIZE - 1;
|
|
|
|
|
|
|
|
/* Enable ports, memory and busmastering */
|
|
|
|
command = pci_read_config(dev, PCIR_COMMAND, 4);
|
|
|
|
command |= PCIM_CMD_PORTEN | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN;
|
|
|
|
pci_write_config(dev, PCIR_COMMAND, command, 4);
|
|
|
|
command = pci_read_config(dev, PCIR_COMMAND, 4);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
#if defined(EPIC_USEIOSPACE)
|
2000-04-12 06:51:43 +00:00
|
|
|
if (!(command & PCIM_CMD_PORTEN)) {
|
|
|
|
device_printf(dev, "failed to enable I/O mapping!\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
1999-10-29 09:56:52 +00:00
|
|
|
}
|
2000-04-12 06:51:43 +00:00
|
|
|
#else
|
|
|
|
if (!(command & PCIM_CMD_MEMEN)) {
|
|
|
|
device_printf(dev, "failed to enable memory mapping!\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
#endif
|
1999-10-29 09:56:52 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
rid = EPIC_RID;
|
|
|
|
sc->res = bus_alloc_resource(dev, EPIC_RES, &rid, 0, ~0, 1,
|
|
|
|
RF_ACTIVE);
|
|
|
|
|
|
|
|
if (sc->res == NULL) {
|
|
|
|
device_printf(dev, "couldn't map ports/memory\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
sc->sc_st = rman_get_bustag(sc->res);
|
|
|
|
sc->sc_sh = rman_get_bushandle(sc->res);
|
|
|
|
|
|
|
|
/* Allocate interrupt */
|
|
|
|
rid = 0;
|
|
|
|
sc->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
|
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
|
|
|
|
if (sc->irq == NULL) {
|
|
|
|
device_printf(dev, "couldn't map interrupt\n");
|
|
|
|
bus_release_resource(dev, EPIC_RES, EPIC_RID, sc->res);
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
1999-10-29 09:56:52 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET,
|
|
|
|
epic_intr, sc, &sc->sc_ih);
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
|
|
|
|
bus_release_resource(dev, EPIC_RES, EPIC_RID, sc->res);
|
|
|
|
device_printf(dev, "couldn't set up irq\n");
|
|
|
|
goto fail;
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/* Bring the chip out of low-power mode and reset it. */
|
|
|
|
CSR_WRITE_4( sc, GENCTL, GENCTL_SOFT_RESET );
|
|
|
|
DELAY(500);
|
|
|
|
|
|
|
|
/* Workaround for Application Note 7-15 */
|
|
|
|
for (i=0; i<16; i++) CSR_WRITE_4(sc, TEST1, TEST1_CLOCK_TEST);
|
|
|
|
|
2001-08-13 18:37:31 +00:00
|
|
|
/* Do OS independent part, including chip wakeup and reset */
|
|
|
|
if (epic_common_attach(sc)) {
|
|
|
|
device_printf(dev, "memory distribution error\n");
|
2000-04-12 06:51:43 +00:00
|
|
|
bus_teardown_intr(dev, sc->irq, sc->sc_ih);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
|
|
|
|
bus_release_resource(dev, EPIC_RES, EPIC_RID, sc->res);
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2001-08-13 18:37:31 +00:00
|
|
|
/* Do ifmedia setup */
|
|
|
|
if (mii_phy_probe(dev, &sc->miibus,
|
|
|
|
epic_ifmedia_upd, epic_ifmedia_sts)) {
|
|
|
|
device_printf(dev, "MII without any PHY!?\n");
|
2000-04-12 06:51:43 +00:00
|
|
|
bus_teardown_intr(dev, sc->irq, sc->sc_ih);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
|
|
|
|
bus_release_resource(dev, EPIC_RES, EPIC_RID, sc->res);
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-10-29 09:56:52 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
/* Display ethernet address ,... */
|
2000-04-12 06:51:43 +00:00
|
|
|
device_printf(dev, "address %6D,", sc->sc_macaddr, ":");
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
/* board type and ... */
|
|
|
|
printf(" type ");
|
|
|
|
for(i=0x2c;i<0x32;i++) {
|
|
|
|
tmp = epic_read_eeprom( sc, i );
|
|
|
|
if( ' ' == (u_int8_t)tmp ) break;
|
|
|
|
printf("%c",(u_int8_t)tmp);
|
|
|
|
tmp >>= 8;
|
|
|
|
if( ' ' == (u_int8_t)tmp ) break;
|
|
|
|
printf("%c",(u_int8_t)tmp);
|
|
|
|
}
|
2001-02-07 20:11:02 +00:00
|
|
|
printf("\n");
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/* Attach to OS's managers */
|
2000-07-13 22:54:34 +00:00
|
|
|
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
|
2001-08-13 18:32:39 +00:00
|
|
|
ifp->if_hdrlen = sizeof(struct ether_vlan_header);
|
2000-04-12 06:51:43 +00:00
|
|
|
callout_handle_init(&sc->stat_ch);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
fail:
|
|
|
|
splx(s);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
return(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Detach driver and free resources
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
epic_freebsd_detach(dev)
|
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
epic_softc_t *sc;
|
|
|
|
int s;
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-07-13 22:54:34 +00:00
|
|
|
ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_stop(sc);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
bus_generic_detach(dev);
|
|
|
|
device_delete_child(dev, sc->miibus);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
bus_teardown_intr(dev, sc->irq, sc->sc_ih);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, sc->irq);
|
|
|
|
bus_release_resource(dev, EPIC_RES, EPIC_RID, sc->res);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
free(sc->pool, M_DEVBUF);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return(0);
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
#undef EPIC_RES
|
|
|
|
#undef EPIC_RID
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop all chip I/O so that the kernel's probe routines don't
|
|
|
|
* get confused by errant DMAs when rebooting.
|
|
|
|
*/
|
1998-11-01 07:44:33 +00:00
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_freebsd_shutdown(dev)
|
|
|
|
device_t dev;
|
1998-11-01 07:44:33 +00:00
|
|
|
{
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_softc_t *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
epic_stop(sc);
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-11-01 07:44:33 +00:00
|
|
|
#endif /* __OpenBSD__ */
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------
|
|
|
|
OS-independing part
|
|
|
|
------------------------------------------------------------------------ */
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/*
|
1998-11-01 07:44:33 +00:00
|
|
|
* This is if_ioctl handler.
|
1998-02-04 15:04:09 +00:00
|
|
|
*/
|
1998-01-21 18:33:00 +00:00
|
|
|
static int
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_ifioctl(ifp, command, data)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
u_long command;
|
|
|
|
caddr_t data;
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
epic_softc_t *sc = ifp->if_softc;
|
2000-04-12 06:51:43 +00:00
|
|
|
struct mii_data *mii;
|
|
|
|
struct ifreq *ifr = (struct ifreq *) data;
|
1998-01-21 18:33:00 +00:00
|
|
|
int x, error = 0;
|
|
|
|
|
|
|
|
x = splimp();
|
|
|
|
|
|
|
|
switch (command) {
|
1998-11-01 07:44:33 +00:00
|
|
|
#if defined(__FreeBSD__)
|
1998-01-21 18:33:00 +00:00
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCGIFADDR:
|
1998-11-01 07:44:33 +00:00
|
|
|
error = ether_ioctl(ifp, command, data);
|
1998-01-21 18:33:00 +00:00
|
|
|
break;
|
2001-08-13 18:32:39 +00:00
|
|
|
case SIOCSIFMTU:
|
|
|
|
if (ifp->if_mtu == ifr->ifr_mtu)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* XXX Though the datasheet doesn't imply any
|
|
|
|
* limitations on RX and TX sizes beside max 64Kb
|
|
|
|
* DMA transfer, seems we can't send more then 1600
|
|
|
|
* data bytes per ethernet packet. (Transmitter hangs
|
|
|
|
* up if more data is sent)
|
|
|
|
*/
|
|
|
|
if (ifr->ifr_mtu + ifp->if_hdrlen <= EPIC_MAX_MTU) {
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
|
|
|
epic_stop(sc);
|
|
|
|
epic_init(sc);
|
|
|
|
} else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
1998-11-01 07:44:33 +00:00
|
|
|
#else /* __OpenBSD__ */
|
|
|
|
case SIOCSIFADDR: {
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
switch(ifa->ifa_addr->sa_family) {
|
|
|
|
#if INET
|
|
|
|
case AF_INET:
|
|
|
|
epic_stop(sc);
|
|
|
|
epic_init(sc);
|
|
|
|
arp_ifinit(&sc->arpcom,ifa);
|
|
|
|
break;
|
2000-04-12 06:51:43 +00:00
|
|
|
#endif
|
1998-11-01 07:44:33 +00:00
|
|
|
#if NS
|
|
|
|
case AF_NS: {
|
|
|
|
register struct ns_addr * ina = &IA_SNS(ifa)->sns_addr;
|
|
|
|
|
|
|
|
if( ns_nullhost(*ina) )
|
|
|
|
ina->x_host =
|
|
|
|
*(union ns_host *) LLADDR(ifp->if_sadl);
|
|
|
|
else
|
|
|
|
bcopy(ina->x_host.c_host, LLADDR(ifp->if_sadl),
|
|
|
|
ifp->if_addrlen);
|
|
|
|
|
|
|
|
epic_stop(sc);
|
|
|
|
epic_init(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
epic_stop(sc);
|
|
|
|
epic_init(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-04-12 06:51:43 +00:00
|
|
|
#endif /* __FreeBSD__ */
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
/*
|
|
|
|
* If the interface is marked up and stopped, then start it.
|
|
|
|
* If it is marked down and running, then stop it.
|
|
|
|
*/
|
|
|
|
if (ifp->if_flags & IFF_UP) {
|
1998-02-04 15:04:09 +00:00
|
|
|
if ((ifp->if_flags & IFF_RUNNING) == 0) {
|
1998-01-21 18:33:00 +00:00
|
|
|
epic_init(sc);
|
1998-02-04 15:04:09 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
} else {
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
|
|
|
epic_stop(sc);
|
1998-02-04 15:04:09 +00:00
|
|
|
break;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-25 18:16:15 +00:00
|
|
|
/* Handle IFF_PROMISC and IFF_ALLMULTI flags */
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_stop_activity(sc);
|
2002-04-25 18:16:15 +00:00
|
|
|
epic_set_mc_table(sc);
|
1998-02-04 15:04:09 +00:00
|
|
|
epic_set_rx_mode(sc);
|
1999-03-14 08:30:23 +00:00
|
|
|
epic_start_activity(sc);
|
1998-01-21 18:33:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
1998-01-29 10:31:45 +00:00
|
|
|
/* Update out multicast list */
|
1998-09-24 16:00:30 +00:00
|
|
|
#if defined(__FreeBSD__) && __FreeBSD_version >= 300000
|
1998-01-29 10:31:45 +00:00
|
|
|
epic_set_mc_table(sc);
|
|
|
|
error = 0;
|
|
|
|
#else
|
1998-01-21 18:33:00 +00:00
|
|
|
error = (command == SIOCADDMULTI) ?
|
1998-11-01 07:44:33 +00:00
|
|
|
ether_addmulti((struct ifreq *)data, &sc->arpcom) :
|
|
|
|
ether_delmulti((struct ifreq *)data, &sc->arpcom);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
if (error == ENETRESET) {
|
1998-01-29 10:31:45 +00:00
|
|
|
epic_set_mc_table(sc);
|
1998-01-21 18:33:00 +00:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
#endif
|
1998-01-29 10:31:45 +00:00
|
|
|
break;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-02-20 18:08:46 +00:00
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
2000-04-12 06:51:43 +00:00
|
|
|
mii = device_get_softc(sc->miibus);
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
|
1998-02-20 18:08:46 +00:00
|
|
|
break;
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
splx(x);
|
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OS-independed part of attach process. allocate memory for descriptors
|
|
|
|
* and frag lists, wake up chip, read MAC address and PHY identyfier.
|
|
|
|
* Return -1 on failure.
|
|
|
|
*/
|
|
|
|
static int
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_common_attach(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-11-01 07:44:33 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
caddr_t pool;
|
|
|
|
|
|
|
|
i = sizeof(struct epic_frag_list)*TX_RING_SIZE +
|
|
|
|
sizeof(struct epic_rx_desc)*RX_RING_SIZE +
|
|
|
|
sizeof(struct epic_tx_desc)*TX_RING_SIZE + PAGE_SIZE,
|
2000-12-08 21:51:06 +00:00
|
|
|
sc->pool = (epic_softc_t *) malloc(i, M_DEVBUF, M_NOWAIT | M_ZERO);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
if (sc->pool == NULL) {
|
|
|
|
printf(": can't allocate memory for buffers\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Align pool on PAGE_SIZE */
|
|
|
|
pool = (caddr_t)sc->pool;
|
2002-03-19 23:28:35 +00:00
|
|
|
pool = (caddr_t)((uintptr_t)(pool + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1));
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
/* Distribute memory */
|
|
|
|
sc->tx_flist = (void *)pool;
|
|
|
|
pool += sizeof(struct epic_frag_list)*TX_RING_SIZE;
|
|
|
|
sc->rx_desc = (void *)pool;
|
|
|
|
pool += sizeof(struct epic_rx_desc)*RX_RING_SIZE;
|
|
|
|
sc->tx_desc = (void *)pool;
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/* Bring the chip out of low-power mode. */
|
|
|
|
CSR_WRITE_4( sc, GENCTL, GENCTL_SOFT_RESET);
|
2000-11-09 17:25:49 +00:00
|
|
|
DELAY(500);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
/* Workaround for Application Note 7-15 */
|
|
|
|
for (i=0; i<16; i++) CSR_WRITE_4(sc, TEST1, TEST1_CLOCK_TEST);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
/* Read mac address from EEPROM */
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN / sizeof(u_int16_t); i++)
|
|
|
|
((u_int16_t *)sc->sc_macaddr)[i] = epic_read_eeprom(sc,i);
|
|
|
|
|
2001-06-23 19:30:26 +00:00
|
|
|
/* Set Non-Volatile Control Register from EEPROM */
|
|
|
|
CSR_WRITE_4(sc, NVCTL, epic_read_eeprom(sc, EEPROM_NVCTL) & 0x1F);
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/* Set defaults */
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->tx_threshold = TRANSMIT_THRESHOLD;
|
|
|
|
sc->txcon = TXCON_DEFAULT;
|
2001-02-07 20:11:02 +00:00
|
|
|
sc->miicfg = MIICFG_SMI_ENABLE;
|
|
|
|
sc->phyid = EPIC_UNKN_PHY;
|
|
|
|
sc->serinst = -1;
|
|
|
|
|
|
|
|
/* Fetch card id */
|
|
|
|
sc->cardvend = pci_read_config(sc->dev, PCIR_SUBVEND_0, 2);
|
|
|
|
sc->cardid = pci_read_config(sc->dev, PCIR_SUBDEV_0, 2);
|
|
|
|
|
|
|
|
if (sc->cardvend != SMC_VENDORID)
|
|
|
|
printf(EPIC_FORMAT ": unknown card vendor 0x%04x\n", EPIC_ARGS(sc), sc->cardvend);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
|
|
|
return 0;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-11-01 07:44:33 +00:00
|
|
|
* This is if_start handler. It takes mbufs from if_snd queue
|
2001-02-07 20:11:02 +00:00
|
|
|
* and queue them for transmit, one by one, until TX ring become full
|
|
|
|
* or queue become empty.
|
1998-01-21 18:33:00 +00:00
|
|
|
*/
|
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_ifstart(ifp)
|
|
|
|
struct ifnet * ifp;
|
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
epic_softc_t *sc = ifp->if_softc;
|
1998-07-04 08:02:46 +00:00
|
|
|
struct epic_tx_buffer *buf;
|
|
|
|
struct epic_tx_desc *desc;
|
|
|
|
struct epic_frag_list *flist;
|
1998-11-01 07:44:33 +00:00
|
|
|
struct mbuf *m0;
|
|
|
|
register struct mbuf *m;
|
|
|
|
register int i;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
while( sc->pending_txs < TX_RING_SIZE ){
|
|
|
|
buf = sc->tx_buffer + sc->cur_tx;
|
|
|
|
desc = sc->tx_desc + sc->cur_tx;
|
|
|
|
flist = sc->tx_flist + sc->cur_tx;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/* Get next packet to send */
|
1998-11-01 07:44:33 +00:00
|
|
|
IF_DEQUEUE( &ifp->if_snd, m0 );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* If nothing to send, return */
|
|
|
|
if( NULL == m0 ) return;
|
1998-04-13 14:15:40 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Fill fragments list */
|
1998-11-01 07:44:33 +00:00
|
|
|
for( m=m0, i=0;
|
|
|
|
(NULL != m) && (i < EPIC_MAX_FRAGS);
|
|
|
|
m = m->m_next, i++ ) {
|
|
|
|
flist->frag[i].fraglen = m->m_len;
|
|
|
|
flist->frag[i].fragaddr = vtophys( mtod(m, caddr_t) );
|
1998-02-04 15:04:09 +00:00
|
|
|
}
|
1998-11-01 07:44:33 +00:00
|
|
|
flist->numfrags = i;
|
1998-02-04 15:04:09 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
/* If packet was more than EPIC_MAX_FRAGS parts, */
|
1998-07-04 08:02:46 +00:00
|
|
|
/* recopy packet to new allocated mbuf cluster */
|
|
|
|
if( NULL != m ){
|
|
|
|
EPIC_MGETCLUSTER(m);
|
|
|
|
if( NULL == m ){
|
1998-04-13 14:15:40 +00:00
|
|
|
m_freem(m0);
|
1998-11-01 07:44:33 +00:00
|
|
|
ifp->if_oerrors++;
|
1998-04-13 14:15:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
m_copydata( m0, 0, m0->m_pkthdr.len, mtod(m,caddr_t) );
|
1998-11-01 07:44:33 +00:00
|
|
|
flist->frag[0].fraglen =
|
|
|
|
m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len;
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
1998-07-04 08:02:46 +00:00
|
|
|
|
1998-04-13 14:15:40 +00:00
|
|
|
flist->numfrags = 1;
|
1998-07-04 08:02:46 +00:00
|
|
|
flist->frag[0].fragaddr = vtophys( mtod(m, caddr_t) );
|
|
|
|
m_freem(m0);
|
|
|
|
m0 = m;
|
1998-04-13 14:15:40 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
buf->mbuf = m0;
|
|
|
|
sc->pending_txs++;
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->cur_tx = ( sc->cur_tx + 1 ) & TX_RING_MASK;
|
1998-07-04 08:02:46 +00:00
|
|
|
desc->control = 0x01;
|
1998-11-01 07:44:33 +00:00
|
|
|
desc->txlength =
|
|
|
|
max(m0->m_pkthdr.len,ETHER_MIN_LEN-ETHER_CRC_LEN);
|
1998-02-20 18:08:46 +00:00
|
|
|
desc->status = 0x8000;
|
1998-04-13 14:15:40 +00:00
|
|
|
CSR_WRITE_4( sc, COMMAND, COMMAND_TXQUEUED );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Set watchdog timer */
|
|
|
|
ifp->if_timer = 8;
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
#if NBPFILTER > 0
|
1998-11-01 07:44:33 +00:00
|
|
|
if( ifp->if_bpf )
|
2000-04-12 06:51:43 +00:00
|
|
|
bpf_mtap( EPIC_BPFTAP_ARG(ifp), m0 );
|
1998-07-04 08:02:46 +00:00
|
|
|
#endif
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/*
|
2000-04-12 06:51:43 +00:00
|
|
|
* Synopsis: Finish all received frames.
|
1998-02-04 15:04:09 +00:00
|
|
|
*/
|
2000-04-12 06:51:43 +00:00
|
|
|
static void
|
|
|
|
epic_rx_done(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-01-21 18:33:00 +00:00
|
|
|
{
|
|
|
|
u_int16_t len;
|
1998-02-20 18:08:46 +00:00
|
|
|
struct epic_rx_buffer *buf;
|
|
|
|
struct epic_rx_desc *desc;
|
1998-01-21 18:33:00 +00:00
|
|
|
struct mbuf *m;
|
|
|
|
struct ether_header *eh;
|
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
while( !(sc->rx_desc[sc->cur_rx].status & 0x8000) ) {
|
1998-01-21 18:33:00 +00:00
|
|
|
buf = sc->rx_buffer + sc->cur_rx;
|
1998-02-20 18:08:46 +00:00
|
|
|
desc = sc->rx_desc + sc->cur_rx;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Switch to next descriptor */
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->cur_rx = (sc->cur_rx+1) & RX_RING_MASK;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Check for errors, this should happend */
|
|
|
|
/* only if SAVE_ERRORED_PACKETS is set, */
|
|
|
|
/* normaly rx errors generate RXE interrupt */
|
1998-02-20 18:08:46 +00:00
|
|
|
if( !(desc->status & 1) ) {
|
1998-11-01 07:44:33 +00:00
|
|
|
dprintf((EPIC_FORMAT ": Rx error status: 0x%x\n",EPIC_ARGS(sc),desc->status));
|
|
|
|
sc->sc_if.if_ierrors++;
|
1998-07-04 08:02:46 +00:00
|
|
|
desc->status = 0x8000;
|
|
|
|
continue;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Save packet length and mbuf contained packet */
|
1998-02-20 18:08:46 +00:00
|
|
|
len = desc->rxlength - ETHER_CRC_LEN;
|
|
|
|
m = buf->mbuf;
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Try to get mbuf cluster */
|
|
|
|
EPIC_MGETCLUSTER( buf->mbuf );
|
|
|
|
if( NULL == buf->mbuf ) {
|
|
|
|
buf->mbuf = m;
|
|
|
|
desc->status = 0x8000;
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->sc_if.if_ierrors++;
|
1998-07-04 08:02:46 +00:00
|
|
|
continue;
|
1998-02-04 15:04:09 +00:00
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Point to new mbuf, and give descriptor to chip */
|
|
|
|
desc->bufaddr = vtophys( mtod( buf->mbuf, caddr_t ) );
|
|
|
|
desc->status = 0x8000;
|
1998-02-04 15:04:09 +00:00
|
|
|
|
|
|
|
/* First mbuf in packet holds the ethernet and packet headers */
|
1998-01-21 18:33:00 +00:00
|
|
|
eh = mtod( m, struct ether_header * );
|
1998-11-01 07:44:33 +00:00
|
|
|
m->m_pkthdr.rcvif = &(sc->sc_if);
|
1998-07-04 08:02:46 +00:00
|
|
|
m->m_pkthdr.len = m->m_len = len;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2000-05-24 00:05:44 +00:00
|
|
|
#if !defined(__FreeBSD__)
|
2000-04-12 06:51:43 +00:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
/* Give mbuf to BPFILTER */
|
1998-11-01 07:44:33 +00:00
|
|
|
if( sc->sc_if.if_bpf )
|
2000-04-12 06:51:43 +00:00
|
|
|
bpf_mtap( EPIC_BPFTAP_ARG(&sc->sc_if), m );
|
|
|
|
#endif /* NBPFILTER > 0 */
|
2000-05-24 00:05:44 +00:00
|
|
|
#endif /* !__FreeBSD__ */
|
1999-03-31 13:50:52 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/* Second mbuf holds packet ifself */
|
1998-07-04 08:02:46 +00:00
|
|
|
m->m_pkthdr.len = m->m_len = len - sizeof(struct ether_header);
|
1998-01-21 18:33:00 +00:00
|
|
|
m->m_data += sizeof( struct ether_header );
|
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/* Give mbuf to OS */
|
1998-11-01 07:44:33 +00:00
|
|
|
ether_input(&sc->sc_if, eh, m);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/* Successfuly received frame */
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->sc_if.if_ipackets++;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
return;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/*
|
1998-07-04 08:02:46 +00:00
|
|
|
* Synopsis: Do last phase of transmission. I.e. if desc is
|
|
|
|
* transmitted, decrease pending_txs counter, free mbuf contained
|
|
|
|
* packet, switch to next descriptor and repeat until no packets
|
1999-03-14 08:30:23 +00:00
|
|
|
* are pending or descriptor is not transmitted yet.
|
1998-02-04 15:04:09 +00:00
|
|
|
*/
|
2000-04-12 06:51:43 +00:00
|
|
|
static void
|
|
|
|
epic_tx_done(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-02-20 18:08:46 +00:00
|
|
|
{
|
1998-07-04 08:02:46 +00:00
|
|
|
struct epic_tx_buffer *buf;
|
|
|
|
struct epic_tx_desc *desc;
|
|
|
|
u_int16_t status;
|
|
|
|
|
|
|
|
while( sc->pending_txs > 0 ){
|
|
|
|
buf = sc->tx_buffer + sc->dirty_tx;
|
|
|
|
desc = sc->tx_desc + sc->dirty_tx;
|
|
|
|
status = desc->status;
|
|
|
|
|
|
|
|
/* If packet is not transmitted, thou followed */
|
|
|
|
/* packets are not transmitted too */
|
|
|
|
if( status & 0x8000 ) break;
|
|
|
|
|
|
|
|
/* Packet is transmitted. Switch to next and */
|
|
|
|
/* free mbuf */
|
|
|
|
sc->pending_txs--;
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->dirty_tx = (sc->dirty_tx + 1) & TX_RING_MASK;
|
1998-02-04 15:04:09 +00:00
|
|
|
m_freem( buf->mbuf );
|
|
|
|
buf->mbuf = NULL;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Check for errors and collisions */
|
1998-11-01 07:44:33 +00:00
|
|
|
if( status & 0x0001 ) sc->sc_if.if_opackets++;
|
|
|
|
else sc->sc_if.if_oerrors++;
|
|
|
|
sc->sc_if.if_collisions += (status >> 8) & 0x1F;
|
1998-07-04 08:02:46 +00:00
|
|
|
#if defined(EPIC_DEBUG)
|
|
|
|
if( (status & 0x1001) == 0x1001 )
|
1998-11-01 07:44:33 +00:00
|
|
|
dprintf((EPIC_FORMAT ": frame not transmitted due collisions\n",EPIC_ARGS(sc)));
|
1998-07-04 08:02:46 +00:00
|
|
|
#endif
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
if( sc->pending_txs < TX_RING_SIZE )
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->sc_if.if_flags &= ~IFF_OACTIVE;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-02-20 18:08:46 +00:00
|
|
|
/*
|
|
|
|
* Interrupt function
|
|
|
|
*/
|
1998-11-01 07:44:33 +00:00
|
|
|
static EPIC_INTR_RET_TYPE
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_intr(arg)
|
|
|
|
void *arg;
|
1998-02-20 18:08:46 +00:00
|
|
|
{
|
1998-11-01 07:44:33 +00:00
|
|
|
epic_softc_t * sc = (epic_softc_t *) arg;
|
|
|
|
int status,i=4;
|
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
int claimed = 0;
|
|
|
|
#endif
|
1998-02-20 18:08:46 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
while( i-- && ((status = CSR_READ_4(sc, INTSTAT)) & INTSTAT_INT_ACTV) ){
|
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
claimed = 1;
|
|
|
|
#endif
|
1998-07-04 08:02:46 +00:00
|
|
|
CSR_WRITE_4( sc, INTSTAT, status );
|
1998-02-20 18:08:46 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
if( status & (INTSTAT_RQE|INTSTAT_RCC|INTSTAT_OVW) ) {
|
1998-11-01 07:44:33 +00:00
|
|
|
epic_rx_done( sc );
|
|
|
|
if( status & (INTSTAT_RQE|INTSTAT_OVW) ){
|
1998-07-04 08:02:46 +00:00
|
|
|
#if defined(EPIC_DEBUG)
|
1998-11-01 07:44:33 +00:00
|
|
|
if( status & INTSTAT_OVW )
|
|
|
|
printf(EPIC_FORMAT ": RX buffer overflow\n",EPIC_ARGS(sc));
|
|
|
|
if( status & INTSTAT_RQE )
|
|
|
|
printf(EPIC_FORMAT ": RX FIFO overflow\n",EPIC_ARGS(sc));
|
1998-07-04 08:02:46 +00:00
|
|
|
#endif
|
1998-11-01 07:44:33 +00:00
|
|
|
if( !(CSR_READ_4( sc, COMMAND ) & COMMAND_RXQUEUED) )
|
|
|
|
CSR_WRITE_4( sc, COMMAND, COMMAND_RXQUEUED );
|
|
|
|
sc->sc_if.if_ierrors++;
|
|
|
|
}
|
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
if( status & (INTSTAT_TXC|INTSTAT_TCC|INTSTAT_TQE) ) {
|
|
|
|
epic_tx_done( sc );
|
|
|
|
if(!(sc->sc_if.if_flags & IFF_OACTIVE) &&
|
|
|
|
sc->sc_if.if_snd.ifq_head )
|
|
|
|
epic_ifstart( &sc->sc_if );
|
1998-07-04 08:02:46 +00:00
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Check for errors */
|
1998-11-01 07:44:33 +00:00
|
|
|
if( status & (INTSTAT_FATAL|INTSTAT_PMA|INTSTAT_PTA|
|
|
|
|
INTSTAT_APE|INTSTAT_DPE|INTSTAT_TXU|INTSTAT_RXE) ){
|
|
|
|
if( status & (INTSTAT_FATAL|INTSTAT_PMA|INTSTAT_PTA|
|
|
|
|
INTSTAT_APE|INTSTAT_DPE) ){
|
|
|
|
printf(EPIC_FORMAT ": PCI fatal error occured (%s%s%s%s)\n",
|
|
|
|
EPIC_ARGS(sc),
|
|
|
|
(status&INTSTAT_PMA)?"PMA":"",
|
|
|
|
(status&INTSTAT_PTA)?" PTA":"",
|
|
|
|
(status&INTSTAT_APE)?" APE":"",
|
|
|
|
(status&INTSTAT_DPE)?" DPE":""
|
|
|
|
);
|
1998-02-20 18:08:46 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
epic_stop(sc);
|
|
|
|
epic_init(sc);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & INTSTAT_RXE) {
|
|
|
|
dprintf((EPIC_FORMAT ": CRC/Alignment error\n",EPIC_ARGS(sc)));
|
|
|
|
sc->sc_if.if_ierrors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tx FIFO underflow. Increase tx threshold, */
|
|
|
|
/* if it grown above 2048, disable EARLY_TX */
|
|
|
|
if (status & INTSTAT_TXU) {
|
|
|
|
if( sc->tx_threshold > 0x800 ) {
|
|
|
|
sc->txcon &= ~TXCON_EARLY_TRANSMIT_ENABLE;
|
|
|
|
dprintf((EPIC_FORMAT ": TX underrun error, early tx disabled\n",EPIC_ARGS(sc)));
|
|
|
|
} else {
|
|
|
|
sc->tx_threshold += 0x40;
|
|
|
|
dprintf((EPIC_FORMAT ": TX underrun error, tx threshold increased to %d\n",EPIC_ARGS(sc),sc->tx_threshold));
|
1998-07-04 08:02:46 +00:00
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
CSR_WRITE_4(sc, COMMAND, COMMAND_TXUGO | COMMAND_TXQUEUED);
|
1998-11-01 07:44:33 +00:00
|
|
|
epic_stop_activity(sc);
|
|
|
|
epic_set_tx_mode(sc);
|
|
|
|
epic_start_activity(sc);
|
|
|
|
sc->sc_if.if_oerrors++;
|
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
}
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
/* If no packets are pending, thus no timeouts */
|
|
|
|
if( sc->pending_txs == 0 ) sc->sc_if.if_timer = 0;
|
1998-02-20 18:08:46 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
return claimed;
|
|
|
|
#endif
|
1998-02-20 18:08:46 +00:00
|
|
|
}
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/*
|
1998-07-04 08:02:46 +00:00
|
|
|
* Synopsis: This one is called if packets wasn't transmitted
|
|
|
|
* during timeout. Try to deallocate transmitted packets, and
|
|
|
|
* if success continue to work.
|
|
|
|
*/
|
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_ifwatchdog(ifp)
|
|
|
|
struct ifnet *ifp;
|
1998-07-04 08:02:46 +00:00
|
|
|
{
|
|
|
|
epic_softc_t *sc = ifp->if_softc;
|
|
|
|
int x;
|
|
|
|
|
|
|
|
x = splimp();
|
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
printf(EPIC_FORMAT ": device timeout %d packets, ",
|
|
|
|
EPIC_ARGS(sc),sc->pending_txs);
|
1998-07-04 08:02:46 +00:00
|
|
|
|
|
|
|
/* Try to finish queued packets */
|
|
|
|
epic_tx_done( sc );
|
|
|
|
|
|
|
|
/* If not successful */
|
|
|
|
if( sc->pending_txs > 0 ){
|
2000-04-12 06:51:43 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
ifp->if_oerrors+=sc->pending_txs;
|
|
|
|
|
|
|
|
/* Reinitialize board */
|
1998-11-01 07:44:33 +00:00
|
|
|
printf("reinitialization\n");
|
1998-07-04 08:02:46 +00:00
|
|
|
epic_stop(sc);
|
|
|
|
epic_init(sc);
|
|
|
|
|
|
|
|
} else
|
1998-11-01 07:44:33 +00:00
|
|
|
printf("seems we can continue normaly\n");
|
1998-07-04 08:02:46 +00:00
|
|
|
|
|
|
|
/* Start output */
|
1998-11-01 07:44:33 +00:00
|
|
|
if( ifp->if_snd.ifq_head ) epic_ifstart( ifp );
|
1998-07-04 08:02:46 +00:00
|
|
|
|
|
|
|
splx(x);
|
|
|
|
}
|
|
|
|
|
2002-05-01 19:23:04 +00:00
|
|
|
/*
|
|
|
|
* Despite the name of this function, it doesn't update statistics, it only
|
|
|
|
* helps in autonegotiation process.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
epic_stats_update(epic_softc_t * sc)
|
|
|
|
{
|
|
|
|
struct mii_data * mii;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
|
|
|
mii = device_get_softc(sc->miibus);
|
|
|
|
mii_tick(mii);
|
|
|
|
|
|
|
|
sc->stat_ch = timeout((timeout_t *)epic_stats_update, sc, hz);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/*
|
|
|
|
* Set media options.
|
|
|
|
*/
|
1998-02-20 18:08:46 +00:00
|
|
|
static int
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_ifmedia_upd(ifp)
|
|
|
|
struct ifnet *ifp;
|
1998-02-20 18:08:46 +00:00
|
|
|
{
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_softc_t *sc;
|
|
|
|
struct mii_data *mii;
|
2000-06-21 19:19:49 +00:00
|
|
|
struct ifmedia *ifm;
|
2001-02-07 20:11:02 +00:00
|
|
|
struct mii_softc *miisc;
|
|
|
|
int cfg, media;
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
sc = ifp->if_softc;
|
|
|
|
mii = device_get_softc(sc->miibus);
|
2000-06-21 19:19:49 +00:00
|
|
|
ifm = &mii->mii_media;
|
2001-02-07 20:11:02 +00:00
|
|
|
media = ifm->ifm_cur->ifm_media;
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2000-06-21 19:19:49 +00:00
|
|
|
/* Do not do anything if interface is not up */
|
|
|
|
if(!(ifp->if_flags & IFF_UP))
|
|
|
|
return (0);
|
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/*
|
|
|
|
* Lookup current selected PHY
|
|
|
|
*/
|
|
|
|
if (IFM_INST(media) == sc->serinst) {
|
|
|
|
sc->phyid = EPIC_SERIAL;
|
|
|
|
sc->physc = NULL;
|
|
|
|
} else {
|
|
|
|
/* If we're not selecting serial interface, select MII mode */
|
|
|
|
sc->miicfg &= ~MIICFG_SERIAL_ENABLE;
|
|
|
|
CSR_WRITE_4(sc, MIICFG, sc->miicfg);
|
2000-06-21 19:19:49 +00:00
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
dprintf((EPIC_FORMAT ": MII selected\n", EPIC_ARGS(sc)));
|
2000-06-21 19:19:49 +00:00
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/* Default to unknown PHY */
|
|
|
|
sc->phyid = EPIC_UNKN_PHY;
|
2000-06-21 19:19:49 +00:00
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/* Lookup selected PHY */
|
|
|
|
for (miisc = LIST_FIRST(&mii->mii_phys); miisc != NULL;
|
|
|
|
miisc = LIST_NEXT(miisc, mii_list)) {
|
|
|
|
if (IFM_INST(media) == miisc->mii_inst) {
|
|
|
|
sc->physc = miisc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-06-21 19:19:49 +00:00
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/* Identify selected PHY */
|
|
|
|
if (sc->physc) {
|
|
|
|
int id1, id2, model, oui;
|
2000-06-21 19:19:49 +00:00
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
id1 = PHY_READ(sc->physc, MII_PHYIDR1);
|
|
|
|
id2 = PHY_READ(sc->physc, MII_PHYIDR2);
|
|
|
|
|
|
|
|
oui = MII_OUI(id1, id2);
|
|
|
|
model = MII_MODEL(id2);
|
|
|
|
switch (oui) {
|
|
|
|
case MII_OUI_QUALSEMI:
|
|
|
|
if (model == MII_MODEL_QUALSEMI_QS6612)
|
|
|
|
sc->phyid = EPIC_QS6612_PHY;
|
|
|
|
break;
|
|
|
|
case MII_OUI_xxALTIMA:
|
|
|
|
if (model == MII_MODEL_xxALTIMA_AC101)
|
|
|
|
sc->phyid = EPIC_AC101_PHY;
|
|
|
|
break;
|
|
|
|
case MII_OUI_xxLEVEL1:
|
|
|
|
if (model == MII_MODEL_xxLEVEL1_LXT970)
|
|
|
|
sc->phyid = EPIC_LXT970_PHY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do PHY specific card setup
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Call this, to isolate all not selected PHYs and
|
|
|
|
* set up selected
|
|
|
|
*/
|
|
|
|
mii_mediachg(mii);
|
|
|
|
|
|
|
|
/* Do our own setup */
|
|
|
|
switch (sc->phyid) {
|
|
|
|
case EPIC_QS6612_PHY:
|
|
|
|
break;
|
|
|
|
case EPIC_AC101_PHY:
|
|
|
|
/* We have to powerup fiber tranceivers */
|
|
|
|
if (IFM_SUBTYPE(media) == IFM_100_FX)
|
|
|
|
sc->miicfg |= MIICFG_694_ENABLE;
|
|
|
|
else
|
|
|
|
sc->miicfg &= ~MIICFG_694_ENABLE;
|
|
|
|
CSR_WRITE_4(sc, MIICFG, sc->miicfg);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case EPIC_LXT970_PHY:
|
|
|
|
/* We have to powerup fiber tranceivers */
|
|
|
|
cfg = PHY_READ(sc->physc, MII_LXTPHY_CONFIG);
|
|
|
|
if (IFM_SUBTYPE(media) == IFM_100_FX)
|
|
|
|
cfg |= CONFIG_LEDC1 | CONFIG_LEDC0;
|
|
|
|
else
|
|
|
|
cfg &= ~(CONFIG_LEDC1 | CONFIG_LEDC0);
|
|
|
|
PHY_WRITE(sc->physc, MII_LXTPHY_CONFIG, cfg);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case EPIC_SERIAL:
|
|
|
|
/* Select serial PHY, (10base2/BNC usually) */
|
|
|
|
sc->miicfg |= MIICFG_694_ENABLE | MIICFG_SERIAL_ENABLE;
|
|
|
|
CSR_WRITE_4(sc, MIICFG, sc->miicfg);
|
|
|
|
|
|
|
|
/* There is no driver to fill this */
|
|
|
|
mii->mii_media_active = media;
|
|
|
|
mii->mii_media_status = 0;
|
|
|
|
|
|
|
|
/* We need to call this manualy as i wasn't called
|
|
|
|
* in mii_mediachg()
|
|
|
|
*/
|
|
|
|
epic_miibus_statchg(sc->dev);
|
|
|
|
|
|
|
|
dprintf((EPIC_FORMAT ": SERIAL selected\n", EPIC_ARGS(sc)));
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf(EPIC_FORMAT ": ERROR! Unknown PHY selected\n", EPIC_ARGS(sc));
|
|
|
|
return (EINVAL);
|
2000-06-21 19:19:49 +00:00
|
|
|
}
|
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
return(0);
|
2000-04-12 06:51:43 +00:00
|
|
|
}
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/*
|
|
|
|
* Report current media status.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
epic_ifmedia_sts(ifp, ifmr)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmediareq *ifmr;
|
|
|
|
{
|
|
|
|
epic_softc_t *sc;
|
|
|
|
struct mii_data *mii;
|
2000-06-21 19:19:49 +00:00
|
|
|
struct ifmedia *ifm;
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
mii = device_get_softc(sc->miibus);
|
2000-06-21 19:19:49 +00:00
|
|
|
ifm = &mii->mii_media;
|
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/* Nothing should be selected if interface is down */
|
2000-06-21 19:19:49 +00:00
|
|
|
if(!(ifp->if_flags & IFF_UP)) {
|
|
|
|
ifmr->ifm_active = IFM_NONE;
|
|
|
|
ifmr->ifm_status = 0;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/* Call underlying pollstat, if not serial PHY */
|
|
|
|
if (sc->phyid != EPIC_SERIAL)
|
2000-04-12 06:51:43 +00:00
|
|
|
mii_pollstat(mii);
|
2001-02-07 20:11:02 +00:00
|
|
|
|
|
|
|
/* Simply copy media info */
|
|
|
|
ifmr->ifm_active = mii->mii_media_active;
|
|
|
|
ifmr->ifm_status = mii->mii_media_status;
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
return;
|
1998-02-20 18:08:46 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/*
|
|
|
|
* Callback routine, called on media change.
|
|
|
|
*/
|
1998-02-20 18:08:46 +00:00
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_miibus_statchg(dev)
|
|
|
|
device_t dev;
|
1998-02-20 18:08:46 +00:00
|
|
|
{
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_softc_t *sc;
|
|
|
|
struct mii_data *mii;
|
2001-02-07 20:11:02 +00:00
|
|
|
int media;
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
mii = device_get_softc(sc->miibus);
|
2001-02-07 20:11:02 +00:00
|
|
|
media = mii->mii_media_active;
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
sc->txcon &= ~(TXCON_LOOPBACK_MODE | TXCON_FULL_DUPLEX);
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/* If we are in full-duplex mode or loopback operation,
|
2000-04-12 06:51:43 +00:00
|
|
|
* we need to decouple receiver and transmitter.
|
|
|
|
*/
|
2001-02-07 20:11:02 +00:00
|
|
|
if (IFM_OPTIONS(media) & (IFM_FDX | IFM_LOOP))
|
2000-04-12 06:51:43 +00:00
|
|
|
sc->txcon |= TXCON_FULL_DUPLEX;
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/* On some cards we need manualy set fullduplex led */
|
|
|
|
if (sc->cardid == SMC9432FTX ||
|
|
|
|
sc->cardid == SMC9432FTX_SC) {
|
|
|
|
if (IFM_OPTIONS(media) & IFM_FDX)
|
|
|
|
sc->miicfg |= MIICFG_694_ENABLE;
|
|
|
|
else
|
|
|
|
sc->miicfg &= ~MIICFG_694_ENABLE;
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, MIICFG, sc->miicfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update baudrate */
|
2002-04-20 12:35:38 +00:00
|
|
|
if (IFM_SUBTYPE(media) == IFM_100_TX ||
|
2001-02-07 20:11:02 +00:00
|
|
|
IFM_SUBTYPE(media) == IFM_100_FX)
|
2000-04-12 06:51:43 +00:00
|
|
|
sc->sc_if.if_baudrate = 100000000;
|
|
|
|
else
|
|
|
|
sc->sc_if.if_baudrate = 10000000;
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2002-05-01 19:23:04 +00:00
|
|
|
epic_stop_activity(sc);
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_set_tx_mode(sc);
|
2002-05-01 19:23:04 +00:00
|
|
|
epic_start_activity(sc);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
return;
|
1998-02-20 18:08:46 +00:00
|
|
|
}
|
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
static void
|
|
|
|
epic_miibus_mediainit(dev)
|
2000-06-21 19:19:49 +00:00
|
|
|
device_t dev;
|
|
|
|
{
|
|
|
|
epic_softc_t *sc;
|
|
|
|
struct mii_data *mii;
|
|
|
|
struct ifmedia *ifm;
|
|
|
|
int media;
|
2001-02-07 20:11:02 +00:00
|
|
|
|
2000-06-21 19:19:49 +00:00
|
|
|
sc = device_get_softc(dev);
|
|
|
|
mii = device_get_softc(sc->miibus);
|
|
|
|
ifm = &mii->mii_media;
|
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/* Add Serial Media Interface if present, this applies to
|
|
|
|
* SMC9432BTX serie
|
|
|
|
*/
|
2000-06-21 19:19:49 +00:00
|
|
|
if(CSR_READ_4(sc, MIICFG) & MIICFG_PHY_PRESENT) {
|
2001-02-07 20:11:02 +00:00
|
|
|
/* Store its instance */
|
|
|
|
sc->serinst = mii->mii_instance++;
|
|
|
|
|
|
|
|
/* Add as 10base2/BNC media */
|
|
|
|
media = IFM_MAKEWORD(IFM_ETHER, IFM_10_2, 0, sc->serinst);
|
2000-06-21 19:19:49 +00:00
|
|
|
ifmedia_add(ifm, media, 0, NULL);
|
2001-02-07 20:11:02 +00:00
|
|
|
|
|
|
|
/* Report to user */
|
|
|
|
printf(EPIC_FORMAT ": serial PHY detected (10Base2/BNC)\n",EPIC_ARGS(sc));
|
2000-06-21 19:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/*
|
2000-06-21 19:19:49 +00:00
|
|
|
* Reset chip, allocate rings, and update media.
|
1998-01-21 18:33:00 +00:00
|
|
|
*/
|
2000-04-12 06:51:43 +00:00
|
|
|
static int
|
|
|
|
epic_init(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-01-21 18:33:00 +00:00
|
|
|
{
|
1998-11-01 07:44:33 +00:00
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
1999-03-14 08:30:23 +00:00
|
|
|
int s,i;
|
1998-02-04 15:04:09 +00:00
|
|
|
|
|
|
|
s = splimp();
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/* If interface is already running, then we need not do anything */
|
|
|
|
if (ifp->if_flags & IFF_RUNNING) {
|
|
|
|
splx(s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
/* Soft reset the chip (we have to power up card before) */
|
|
|
|
CSR_WRITE_4( sc, GENCTL, 0 );
|
1998-04-13 14:15:40 +00:00
|
|
|
CSR_WRITE_4( sc, GENCTL, GENCTL_SOFT_RESET );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
/*
|
|
|
|
* Reset takes 15 pci ticks which depends on PCI bus speed.
|
|
|
|
* Assuming it >= 33000000 hz, we have wait at least 495e-6 sec.
|
|
|
|
*/
|
|
|
|
DELAY(500);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
/* Wake up */
|
1998-04-13 14:15:40 +00:00
|
|
|
CSR_WRITE_4( sc, GENCTL, 0 );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
/* Workaround for Application Note 7-15 */
|
|
|
|
for (i=0; i<16; i++) CSR_WRITE_4(sc, TEST1, TEST1_CLOCK_TEST);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/* Initialize rings */
|
1998-07-04 08:02:46 +00:00
|
|
|
if( epic_init_rings( sc ) ) {
|
1998-11-01 07:44:33 +00:00
|
|
|
printf(EPIC_FORMAT ": failed to init rings\n",EPIC_ARGS(sc));
|
1998-02-04 15:04:09 +00:00
|
|
|
splx(s);
|
|
|
|
return -1;
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Give rings to EPIC */
|
|
|
|
CSR_WRITE_4( sc, PRCDAR, vtophys( sc->rx_desc ) );
|
|
|
|
CSR_WRITE_4( sc, PTCDAR, vtophys( sc->tx_desc ) );
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/* Put node address to EPIC */
|
1998-11-01 07:44:33 +00:00
|
|
|
CSR_WRITE_4( sc, LAN0, ((u_int16_t *)sc->sc_macaddr)[0] );
|
|
|
|
CSR_WRITE_4( sc, LAN1, ((u_int16_t *)sc->sc_macaddr)[1] );
|
|
|
|
CSR_WRITE_4( sc, LAN2, ((u_int16_t *)sc->sc_macaddr)[2] );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
/* Set tx mode, includeing transmit threshold */
|
|
|
|
epic_set_tx_mode(sc);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-01-29 10:31:45 +00:00
|
|
|
/* Compute and set RXCON. */
|
|
|
|
epic_set_rx_mode( sc );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-01-29 10:31:45 +00:00
|
|
|
/* Set multicast table */
|
|
|
|
epic_set_mc_table( sc );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
/* Enable interrupts by setting the interrupt mask. */
|
1998-07-04 08:02:46 +00:00
|
|
|
CSR_WRITE_4( sc, INTMASK,
|
2001-02-07 20:11:02 +00:00
|
|
|
INTSTAT_RCC | /* INTSTAT_RQE | INTSTAT_OVW | INTSTAT_RXE | */
|
|
|
|
/* INTSTAT_TXC | */ INTSTAT_TCC | INTSTAT_TQE | INTSTAT_TXU |
|
2000-04-12 06:51:43 +00:00
|
|
|
INTSTAT_FATAL);
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/* Acknowledge all pending interrupts */
|
|
|
|
CSR_WRITE_4(sc, INTSTAT, CSR_READ_4(sc, INTSTAT));
|
|
|
|
|
1998-02-20 18:08:46 +00:00
|
|
|
/* Enable interrupts, set for PCI read multiple and etc */
|
1998-04-13 14:15:40 +00:00
|
|
|
CSR_WRITE_4( sc, GENCTL,
|
1998-02-20 18:08:46 +00:00
|
|
|
GENCTL_ENABLE_INTERRUPT | GENCTL_MEMORY_READ_MULTIPLE |
|
|
|
|
GENCTL_ONECOPY | GENCTL_RECEIVE_FIFO_THRESHOLD64 );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
/* Mark interface running ... */
|
|
|
|
if( ifp->if_flags & IFF_UP ) ifp->if_flags |= IFF_RUNNING;
|
|
|
|
else ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
|
|
|
|
/* ... and free */
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Start Rx process */
|
|
|
|
epic_start_activity(sc);
|
|
|
|
|
2000-06-21 19:19:49 +00:00
|
|
|
/* Set appropriate media */
|
|
|
|
epic_ifmedia_upd(ifp);
|
2000-04-12 06:51:43 +00:00
|
|
|
|
2002-05-01 19:23:04 +00:00
|
|
|
sc->stat_ch = timeout((timeout_t *)epic_stats_update, sc, hz);
|
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
splx(s);
|
2000-04-12 06:51:43 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
return 0;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-01-29 10:31:45 +00:00
|
|
|
/*
|
1999-03-14 08:30:23 +00:00
|
|
|
* Synopsis: calculate and set Rx mode. Chip must be in idle state to
|
|
|
|
* access RXCON.
|
1998-01-29 10:31:45 +00:00
|
|
|
*/
|
1998-01-21 18:33:00 +00:00
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_set_rx_mode(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-01-21 18:33:00 +00:00
|
|
|
{
|
2000-04-12 06:51:43 +00:00
|
|
|
u_int32_t flags = sc->sc_if.if_flags;
|
|
|
|
u_int32_t rxcon = RXCON_DEFAULT;
|
1998-01-29 10:31:45 +00:00
|
|
|
|
2002-04-19 22:43:57 +00:00
|
|
|
#if defined(EPIC_EARLY_RX)
|
|
|
|
rxcon |= RXCON_EARLY_RX;
|
|
|
|
#endif
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
rxcon |= (flags & IFF_PROMISC) ? RXCON_PROMISCUOUS_MODE : 0;
|
1998-01-29 10:31:45 +00:00
|
|
|
|
1998-04-13 14:15:40 +00:00
|
|
|
CSR_WRITE_4( sc, RXCON, rxcon );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-01-29 10:31:45 +00:00
|
|
|
return;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/*
|
2000-04-12 06:51:43 +00:00
|
|
|
* Synopsis: Set transmit control register. Chip must be in idle state to
|
|
|
|
* access TXCON.
|
1998-07-04 08:02:46 +00:00
|
|
|
*/
|
1998-04-13 14:15:40 +00:00
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_set_tx_mode(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-11-01 07:44:33 +00:00
|
|
|
{
|
2000-04-12 06:51:43 +00:00
|
|
|
if (sc->txcon & TXCON_EARLY_TRANSMIT_ENABLE)
|
|
|
|
CSR_WRITE_4 (sc, ETXTHR, sc->tx_threshold);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
CSR_WRITE_4 (sc, TXCON, sc->txcon);
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
|
|
|
|
1998-01-29 10:31:45 +00:00
|
|
|
/*
|
2002-04-25 18:16:15 +00:00
|
|
|
* Synopsis: Program multicast filter honoring IFF_ALLMULTI and IFF_PROMISC
|
|
|
|
* flags. (Note, that setting PROMISC bit in EPIC's RXCON will only touch
|
|
|
|
* individual frames, multicast filter must be manually programmed)
|
|
|
|
*
|
|
|
|
* Note: EPIC must be in idle state.
|
1998-01-29 10:31:45 +00:00
|
|
|
*/
|
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_set_mc_table(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-01-29 10:31:45 +00:00
|
|
|
{
|
1998-11-01 07:44:33 +00:00
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
2002-04-25 18:16:15 +00:00
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
u_int16_t filter[4];
|
|
|
|
u_int8_t h;
|
|
|
|
|
|
|
|
if (ifp->if_flags & (IFF_ALLMULTI | IFF_PROMISC)) {
|
|
|
|
CSR_WRITE_4(sc, MC0, 0xFFFF);
|
|
|
|
CSR_WRITE_4(sc, MC1, 0xFFFF);
|
|
|
|
CSR_WRITE_4(sc, MC2, 0xFFFF);
|
|
|
|
CSR_WRITE_4(sc, MC3, 0xFFFF);
|
1998-01-29 10:31:45 +00:00
|
|
|
|
2002-04-25 18:16:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
filter[0] = 0;
|
|
|
|
filter[1] = 0;
|
|
|
|
filter[2] = 0;
|
|
|
|
filter[3] = 0;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
|
|
|
h = epic_calchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
|
|
|
|
filter[h >> 4] |= 1 << (h & 0xF);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
2002-04-25 18:16:15 +00:00
|
|
|
CSR_WRITE_4(sc, MC0, filter[0]);
|
|
|
|
CSR_WRITE_4(sc, MC1, filter[1]);
|
|
|
|
CSR_WRITE_4(sc, MC2, filter[2]);
|
|
|
|
CSR_WRITE_4(sc, MC3, filter[3]);
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-25 18:16:15 +00:00
|
|
|
/*
|
|
|
|
* Synopsis: calculate EPIC's hash of multicast address.
|
|
|
|
*/
|
|
|
|
static u_int8_t
|
|
|
|
epic_calchash(addr)
|
|
|
|
caddr_t addr;
|
|
|
|
{
|
|
|
|
u_int32_t crc, carry;
|
|
|
|
int i, j;
|
|
|
|
u_int8_t c;
|
|
|
|
|
|
|
|
/* Compute CRC for the address value. */
|
|
|
|
crc = 0xFFFFFFFF; /* initial value */
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
c = *(addr + i);
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
carry = ((crc & 0x80000000) ? 1 : 0) ^ (c & 0x01);
|
|
|
|
crc <<= 1;
|
|
|
|
c >>= 1;
|
|
|
|
if (carry)
|
|
|
|
crc = (crc ^ 0x04c11db6) | carry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((crc >> 26) & 0x3F);
|
|
|
|
}
|
|
|
|
|
1998-02-20 18:08:46 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/*
|
1999-03-14 08:30:23 +00:00
|
|
|
* Synopsis: Start receive process and transmit one, if they need.
|
1998-07-04 08:02:46 +00:00
|
|
|
*/
|
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_start_activity(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-07-04 08:02:46 +00:00
|
|
|
{
|
2000-04-12 06:51:43 +00:00
|
|
|
/* Start rx process */
|
|
|
|
CSR_WRITE_4(sc, COMMAND,
|
|
|
|
COMMAND_RXQUEUED | COMMAND_START_RX |
|
|
|
|
(sc->pending_txs?COMMAND_TXQUEUED:0));
|
|
|
|
dprintf((EPIC_FORMAT ": activity started\n",EPIC_ARGS(sc)));
|
1998-07-04 08:02:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Synopsis: Completely stop Rx and Tx processes. If TQE is set additional
|
|
|
|
* packet needs to be queued to stop Tx DMA.
|
|
|
|
*/
|
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_stop_activity(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-07-04 08:02:46 +00:00
|
|
|
{
|
1998-11-01 07:44:33 +00:00
|
|
|
int i;
|
1998-07-04 08:02:46 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
/* Stop Tx and Rx DMA */
|
|
|
|
CSR_WRITE_4(sc,COMMAND,COMMAND_STOP_RX|COMMAND_STOP_RDMA|COMMAND_STOP_TDMA);
|
1998-07-04 08:02:46 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
/* Wait Rx and Tx DMA to stop (why 1 ms ??? XXX) */
|
|
|
|
dprintf((EPIC_FORMAT ": waiting Rx and Tx DMA to stop\n",EPIC_ARGS(sc)));
|
1998-11-01 07:44:33 +00:00
|
|
|
for(i=0;i<0x1000;i++) {
|
1999-03-14 08:30:23 +00:00
|
|
|
if((CSR_READ_4(sc,INTSTAT) & (INTSTAT_TXIDLE | INTSTAT_RXIDLE)) ==
|
|
|
|
(INTSTAT_TXIDLE | INTSTAT_RXIDLE) )
|
1998-11-01 07:44:33 +00:00
|
|
|
break;
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !(CSR_READ_4(sc,INTSTAT)&INTSTAT_RXIDLE) )
|
1999-03-14 08:30:23 +00:00
|
|
|
printf(EPIC_FORMAT ": can't stop Rx DMA\n",EPIC_ARGS(sc));
|
|
|
|
|
|
|
|
if( !(CSR_READ_4(sc,INTSTAT)&INTSTAT_TXIDLE) )
|
|
|
|
printf(EPIC_FORMAT ": can't stop Tx DMA\n",EPIC_ARGS(sc));
|
1998-11-01 07:44:33 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
/* Catch all finished packets */
|
|
|
|
epic_rx_done(sc);
|
|
|
|
epic_tx_done(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* May need to queue one more packet if TQE, this is rare but existing
|
|
|
|
* case.
|
|
|
|
*/
|
1998-11-01 07:44:33 +00:00
|
|
|
if( (CSR_READ_4( sc, INTSTAT ) & INTSTAT_TQE) &&
|
1999-03-14 08:30:23 +00:00
|
|
|
!(CSR_READ_4( sc, INTSTAT ) & INTSTAT_TXIDLE) ) {
|
|
|
|
struct epic_tx_desc *desc;
|
|
|
|
struct epic_frag_list *flist;
|
|
|
|
struct epic_tx_buffer *buf;
|
|
|
|
struct mbuf *m0;
|
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
dprintf((EPIC_FORMAT ": queue last packet\n",EPIC_ARGS(sc)));
|
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
desc = sc->tx_desc + sc->cur_tx;
|
|
|
|
flist = sc->tx_flist + sc->cur_tx;
|
|
|
|
buf = sc->tx_buffer + sc->cur_tx;
|
|
|
|
|
|
|
|
if ((desc->status & 0x8000) || (buf->mbuf != NULL))
|
|
|
|
return;
|
|
|
|
|
|
|
|
MGETHDR(m0,M_DONTWAIT,MT_DATA);
|
|
|
|
if (NULL == m0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Prepare mbuf */
|
|
|
|
m0->m_len = min(MHLEN,ETHER_MIN_LEN-ETHER_CRC_LEN);
|
|
|
|
flist->frag[0].fraglen = m0->m_len;
|
|
|
|
m0->m_pkthdr.len = m0->m_len;
|
|
|
|
m0->m_pkthdr.rcvif = &sc->sc_if;
|
|
|
|
bzero(mtod(m0,caddr_t),m0->m_len);
|
|
|
|
|
|
|
|
/* Fill fragments list */
|
|
|
|
flist->frag[0].fraglen = m0->m_len;
|
|
|
|
flist->frag[0].fragaddr = vtophys( mtod(m0, caddr_t) );
|
|
|
|
flist->numfrags = 1;
|
|
|
|
|
|
|
|
/* Fill in descriptor */
|
|
|
|
buf->mbuf = m0;
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->pending_txs++;
|
1999-03-14 08:30:23 +00:00
|
|
|
sc->cur_tx = (sc->cur_tx + 1) & TX_RING_MASK;
|
|
|
|
desc->control = 0x01;
|
|
|
|
desc->txlength = max(m0->m_pkthdr.len,ETHER_MIN_LEN-ETHER_CRC_LEN);
|
|
|
|
desc->status = 0x8000;
|
1998-11-01 07:44:33 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
/* Launch transmition */
|
|
|
|
CSR_WRITE_4(sc, COMMAND, COMMAND_STOP_TDMA | COMMAND_TXQUEUED);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
/* Wait Tx DMA to stop (for how long??? XXX) */
|
1998-11-01 07:44:33 +00:00
|
|
|
dprintf((EPIC_FORMAT ": waiting Tx DMA to stop\n",EPIC_ARGS(sc)));
|
1999-03-14 08:30:23 +00:00
|
|
|
for(i=0;i<1000;i++) {
|
|
|
|
if( (CSR_READ_4(sc,INTSTAT)&INTSTAT_TXIDLE) == INTSTAT_TXIDLE )
|
1998-11-01 07:44:33 +00:00
|
|
|
break;
|
|
|
|
DELAY(1);
|
|
|
|
}
|
1998-07-04 08:02:46 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
if( !(CSR_READ_4(sc,INTSTAT)&INTSTAT_TXIDLE) )
|
|
|
|
printf(EPIC_FORMAT ": can't stop TX DMA\n",EPIC_ARGS(sc));
|
1999-03-14 08:30:23 +00:00
|
|
|
else
|
|
|
|
epic_tx_done(sc);
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
1999-03-14 08:30:23 +00:00
|
|
|
|
|
|
|
dprintf((EPIC_FORMAT ": activity stoped\n",EPIC_ARGS(sc)));
|
1998-07-04 08:02:46 +00:00
|
|
|
}
|
|
|
|
|
1998-01-29 10:31:45 +00:00
|
|
|
/*
|
1998-07-04 08:02:46 +00:00
|
|
|
* Synopsis: Shut down board and deallocates rings.
|
1998-01-29 10:31:45 +00:00
|
|
|
*/
|
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_stop(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-01-29 10:31:45 +00:00
|
|
|
{
|
1998-11-01 07:44:33 +00:00
|
|
|
int s;
|
1998-02-04 15:04:09 +00:00
|
|
|
|
|
|
|
s = splimp();
|
1998-07-04 08:02:46 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->sc_if.if_timer = 0;
|
1998-01-29 10:31:45 +00:00
|
|
|
|
2002-05-01 19:23:04 +00:00
|
|
|
untimeout((timeout_t *)epic_stats_update, sc, sc->stat_ch);
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Disable interrupts */
|
1998-04-13 14:15:40 +00:00
|
|
|
CSR_WRITE_4( sc, INTMASK, 0 );
|
|
|
|
CSR_WRITE_4( sc, GENCTL, 0 );
|
1998-01-29 10:31:45 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Try to stop Rx and TX processes */
|
|
|
|
epic_stop_activity(sc);
|
1998-02-04 15:04:09 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Reset chip */
|
1998-04-13 14:15:40 +00:00
|
|
|
CSR_WRITE_4( sc, GENCTL, GENCTL_SOFT_RESET );
|
1999-03-14 08:30:23 +00:00
|
|
|
DELAY(1000);
|
|
|
|
|
|
|
|
/* Make chip go to bed */
|
|
|
|
CSR_WRITE_4(sc, GENCTL, GENCTL_POWER_DOWN);
|
1998-02-04 15:04:09 +00:00
|
|
|
|
|
|
|
/* Free memory allocated for rings */
|
1998-07-04 08:02:46 +00:00
|
|
|
epic_free_rings(sc);
|
1998-02-04 15:04:09 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Mark as stoped */
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->sc_if.if_flags &= ~IFF_RUNNING;
|
1998-01-29 10:31:45 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
1998-01-29 10:31:45 +00:00
|
|
|
}
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/*
|
1998-07-04 08:02:46 +00:00
|
|
|
* Synopsis: This function should free all memory allocated for rings.
|
1998-02-04 15:04:09 +00:00
|
|
|
*/
|
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_free_rings(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-07-04 08:02:46 +00:00
|
|
|
{
|
1998-02-04 15:04:09 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0;i<RX_RING_SIZE;i++){
|
|
|
|
struct epic_rx_buffer *buf = sc->rx_buffer + i;
|
1998-02-20 18:08:46 +00:00
|
|
|
struct epic_rx_desc *desc = sc->rx_desc + i;
|
1998-02-04 15:04:09 +00:00
|
|
|
|
1998-02-20 18:08:46 +00:00
|
|
|
desc->status = 0;
|
|
|
|
desc->buflength = 0;
|
|
|
|
desc->bufaddr = 0;
|
1998-02-04 15:04:09 +00:00
|
|
|
|
|
|
|
if( buf->mbuf ) m_freem( buf->mbuf );
|
|
|
|
buf->mbuf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<TX_RING_SIZE;i++){
|
|
|
|
struct epic_tx_buffer *buf = sc->tx_buffer + i;
|
1998-02-20 18:08:46 +00:00
|
|
|
struct epic_tx_desc *desc = sc->tx_desc + i;
|
1998-02-04 15:04:09 +00:00
|
|
|
|
1998-02-20 18:08:46 +00:00
|
|
|
desc->status = 0;
|
|
|
|
desc->buflength = 0;
|
|
|
|
desc->bufaddr = 0;
|
1998-02-04 15:04:09 +00:00
|
|
|
|
|
|
|
if( buf->mbuf ) m_freem( buf->mbuf );
|
|
|
|
buf->mbuf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-07-04 08:02:46 +00:00
|
|
|
* Synopsis: Allocates mbufs for Rx ring and point Rx descs to them.
|
|
|
|
* Point Tx descs to fragment lists. Check that all descs and fraglists
|
|
|
|
* are bounded and aligned properly.
|
1998-01-21 18:33:00 +00:00
|
|
|
*/
|
1998-02-04 15:04:09 +00:00
|
|
|
static int
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_init_rings(sc)
|
|
|
|
epic_softc_t *sc;
|
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
sc->cur_rx = sc->cur_tx = sc->dirty_tx = sc->pending_txs = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
|
|
|
struct epic_rx_buffer *buf = sc->rx_buffer + i;
|
1998-02-20 18:08:46 +00:00
|
|
|
struct epic_rx_desc *desc = sc->rx_desc + i;
|
|
|
|
|
|
|
|
desc->status = 0; /* Owned by driver */
|
1998-11-01 07:44:33 +00:00
|
|
|
desc->next = vtophys( sc->rx_desc + ((i+1) & RX_RING_MASK) );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
if( (desc->next & 3) || ((desc->next & 0xFFF) + sizeof(struct epic_rx_desc) > 0x1000 ) )
|
1998-11-01 07:44:33 +00:00
|
|
|
printf(EPIC_FORMAT ": WARNING! rx_desc is misbound or misaligned\n",EPIC_ARGS(sc));
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
EPIC_MGETCLUSTER( buf->mbuf );
|
|
|
|
if( NULL == buf->mbuf ) {
|
|
|
|
epic_free_rings(sc);
|
|
|
|
return -1;
|
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
desc->bufaddr = vtophys( mtod(buf->mbuf,caddr_t) );
|
1998-02-04 15:04:09 +00:00
|
|
|
|
2001-08-13 18:32:39 +00:00
|
|
|
desc->buflength = MCLBYTES; /* Max RX buffer length */
|
|
|
|
desc->status = 0x8000; /* Set owner bit to NIC */
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < TX_RING_SIZE; i++) {
|
|
|
|
struct epic_tx_buffer *buf = sc->tx_buffer + i;
|
1998-02-20 18:08:46 +00:00
|
|
|
struct epic_tx_desc *desc = sc->tx_desc + i;
|
|
|
|
|
|
|
|
desc->status = 0;
|
1998-11-01 07:44:33 +00:00
|
|
|
desc->next = vtophys( sc->tx_desc + ( (i+1) & TX_RING_MASK ) );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
if( (desc->next & 3) || ((desc->next & 0xFFF) + sizeof(struct epic_tx_desc) > 0x1000 ) )
|
1998-11-01 07:44:33 +00:00
|
|
|
printf(EPIC_FORMAT ": WARNING! tx_desc is misbound or misaligned\n",EPIC_ARGS(sc));
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
buf->mbuf = NULL;
|
1998-02-20 18:08:46 +00:00
|
|
|
desc->bufaddr = vtophys( sc->tx_flist + i );
|
1998-07-04 08:02:46 +00:00
|
|
|
if( (desc->bufaddr & 3) || ((desc->bufaddr & 0xFFF) + sizeof(struct epic_frag_list) > 0x1000 ) )
|
1998-11-01 07:44:33 +00:00
|
|
|
printf(EPIC_FORMAT ": WARNING! frag_list is misbound or misaligned\n",EPIC_ARGS(sc));
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
return 0;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EEPROM operation functions
|
|
|
|
*/
|
2000-04-12 06:51:43 +00:00
|
|
|
static void
|
|
|
|
epic_write_eepromreg(sc, val)
|
|
|
|
epic_softc_t *sc;
|
|
|
|
u_int8_t val;
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
u_int16_t i;
|
|
|
|
|
1998-04-13 14:15:40 +00:00
|
|
|
CSR_WRITE_1( sc, EECTL, val );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
for (i=0; i<0xFF; i++)
|
1998-04-13 14:15:40 +00:00
|
|
|
if( !(CSR_READ_1( sc, EECTL ) & 0x20) ) break;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static u_int8_t
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_read_eepromreg(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
2000-04-12 06:51:43 +00:00
|
|
|
return CSR_READ_1(sc, EECTL);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static u_int8_t
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_eeprom_clock(sc, val)
|
|
|
|
epic_softc_t *sc;
|
|
|
|
u_int8_t val;
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
|
|
|
epic_write_eepromreg( sc, val );
|
|
|
|
epic_write_eepromreg( sc, (val | 0x4) );
|
|
|
|
epic_write_eepromreg( sc, val );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-04-13 14:15:40 +00:00
|
|
|
return epic_read_eepromreg( sc );
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_output_eepromw(sc, val)
|
|
|
|
epic_softc_t *sc;
|
|
|
|
u_int16_t val;
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
int i;
|
|
|
|
for( i = 0xF; i >= 0; i--){
|
1998-04-13 14:15:40 +00:00
|
|
|
if( (val & (1 << i)) ) epic_eeprom_clock( sc, 0x0B );
|
|
|
|
else epic_eeprom_clock( sc, 3);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static u_int16_t
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_input_eepromw(sc)
|
|
|
|
epic_softc_t *sc;
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
int i;
|
|
|
|
int tmp;
|
|
|
|
u_int16_t retval = 0;
|
|
|
|
|
|
|
|
for( i = 0xF; i >= 0; i--) {
|
1998-04-13 14:15:40 +00:00
|
|
|
tmp = epic_eeprom_clock( sc, 0x3 );
|
1998-01-21 18:33:00 +00:00
|
|
|
if( tmp & 0x10 ){
|
|
|
|
retval |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static int
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_read_eeprom(sc, loc)
|
|
|
|
epic_softc_t *sc;
|
|
|
|
u_int16_t loc;
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
u_int16_t dataval;
|
|
|
|
u_int16_t read_cmd;
|
|
|
|
|
1998-04-13 14:15:40 +00:00
|
|
|
epic_write_eepromreg( sc , 3);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-04-13 14:15:40 +00:00
|
|
|
if( epic_read_eepromreg( sc ) & 0x40 )
|
1998-01-21 18:33:00 +00:00
|
|
|
read_cmd = ( loc & 0x3F ) | 0x180;
|
|
|
|
else
|
|
|
|
read_cmd = ( loc & 0xFF ) | 0x600;
|
|
|
|
|
1998-04-13 14:15:40 +00:00
|
|
|
epic_output_eepromw( sc, read_cmd );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-04-13 14:15:40 +00:00
|
|
|
dataval = epic_input_eepromw( sc );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-04-13 14:15:40 +00:00
|
|
|
epic_write_eepromreg( sc, 1 );
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
return dataval;
|
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/*
|
|
|
|
* Here goes MII read/write routines
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
epic_read_phy_reg(sc, phy, reg)
|
|
|
|
epic_softc_t *sc;
|
|
|
|
int phy, reg;
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
int i;
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
CSR_WRITE_4 (sc, MIICTL, ((reg << 4) | (phy << 9) | 0x01));
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1999-03-14 08:30:23 +00:00
|
|
|
for (i=0;i<0x100;i++) {
|
2000-04-12 06:51:43 +00:00
|
|
|
if( !(CSR_READ_4(sc, MIICTL) & 0x01) ) break;
|
1999-03-14 08:30:23 +00:00
|
|
|
DELAY(1);
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
return (CSR_READ_4 (sc, MIIDATA));
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static void
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_write_phy_reg(sc, phy, reg, val)
|
|
|
|
epic_softc_t *sc;
|
|
|
|
int phy, reg, val;
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
int i;
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
CSR_WRITE_4 (sc, MIIDATA, val);
|
|
|
|
CSR_WRITE_4 (sc, MIICTL, ((reg << 4) | (phy << 9) | 0x02));
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
for(i=0;i<0x100;i++) {
|
|
|
|
if( !(CSR_READ_4(sc, MIICTL) & 0x02) ) break;
|
1999-03-14 08:30:23 +00:00
|
|
|
DELAY(1);
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
1998-02-01 20:25:16 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
static int
|
|
|
|
epic_miibus_readreg(dev, phy, reg)
|
|
|
|
device_t dev;
|
|
|
|
int phy, reg;
|
1998-07-04 08:02:46 +00:00
|
|
|
{
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_softc_t *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
return (PHY_READ_2(sc, phy, reg));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
epic_miibus_writereg(dev, phy, reg, data)
|
|
|
|
device_t dev;
|
|
|
|
int phy, reg, data;
|
|
|
|
{
|
|
|
|
epic_softc_t *sc;
|
|
|
|
|
|
|
|
sc = device_get_softc(dev);
|
|
|
|
|
|
|
|
PHY_WRITE_2(sc, phy, reg, data);
|
|
|
|
|
|
|
|
return (0);
|
1998-07-04 08:02:46 +00:00
|
|
|
}
|