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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/*
|
2002-10-22 00:57:51 +00:00
|
|
|
* EtherPower II 10/100 Fast Ethernet (SMC 9432 serie)
|
|
|
|
*
|
|
|
|
* These cards are based on SMC83c17x (EPIC) chip and one of the various
|
|
|
|
* PHYs (QS6612, AC101 and LXT970 were seen). The media support depends on
|
|
|
|
* card model. All cards support 10baseT/UTP and 100baseTX half- and full-
|
|
|
|
* duplex (SMB9432TX). SMC9432BTX also supports 10baseT/BNC. SMC9432FTX also
|
|
|
|
* supports fibre optics.
|
|
|
|
*
|
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/kernel.h>
|
2004-05-30 20:08:47 +00:00
|
|
|
#include <sys/module.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>
|
|
|
|
|
|
|
|
#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>
|
2005-06-10 16:49:24 +00:00
|
|
|
#include <net/if_types.h>
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
#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 <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
2003-08-22 07:08:17 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
2003-01-19 02:59:34 +00:00
|
|
|
#include "miidevs.h"
|
2001-02-07 20:11:02 +00:00
|
|
|
|
|
|
|
#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>
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-15 06:37:30 +00:00
|
|
|
MODULE_DEPEND(tx, pci, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(tx, ether, 1, 1, 1);
|
2000-04-29 13:41:57 +00:00
|
|
|
MODULE_DEPEND(tx, miibus, 1, 1, 1);
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
static int epic_ifioctl(struct ifnet *, u_long, caddr_t);
|
2002-10-22 00:57:51 +00:00
|
|
|
static void epic_intr(void *);
|
|
|
|
static void epic_tx_underrun(epic_softc_t *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void epic_ifstart(struct ifnet *);
|
2008-06-10 17:59:43 +00:00
|
|
|
static void epic_ifstart_locked(struct ifnet *);
|
|
|
|
static void epic_timer(void *);
|
2003-04-19 13:51:24 +00:00
|
|
|
static void epic_init(void *);
|
2008-06-10 17:59:43 +00:00
|
|
|
static void epic_init_locked(epic_softc_t *);
|
2002-03-20 02:08:01 +00:00
|
|
|
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 *);
|
2002-10-22 00:57:51 +00:00
|
|
|
static int epic_queue_last_packet(epic_softc_t *);
|
2002-03-20 02:08:01 +00:00
|
|
|
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 *);
|
|
|
|
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 *);
|
2008-06-10 17:59:43 +00:00
|
|
|
static int epic_ifmedia_upd_locked(struct ifnet *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static void epic_ifmedia_sts(struct ifnet *, struct ifmediareq *);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
static int epic_probe(device_t);
|
|
|
|
static int epic_attach(device_t);
|
|
|
|
static void epic_shutdown(device_t);
|
|
|
|
static int epic_detach(device_t);
|
2003-04-20 18:08:00 +00:00
|
|
|
static void epic_release(epic_softc_t *);
|
2002-03-20 02:08:01 +00:00
|
|
|
static struct epic_type *epic_devtype(device_t);
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
static device_method_t epic_methods[] = {
|
2002-10-22 00:57:51 +00:00
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, epic_probe),
|
|
|
|
DEVMETHOD(device_attach, epic_attach),
|
|
|
|
DEVMETHOD(device_detach, epic_detach),
|
|
|
|
DEVMETHOD(device_shutdown, epic_shutdown),
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
/* 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 = {
|
2002-10-22 00:57:51 +00:00
|
|
|
"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;
|
|
|
|
|
2003-04-15 06:37:30 +00:00
|
|
|
DRIVER_MODULE(tx, pci, epic_driver, epic_devclass, 0, 0);
|
2000-04-12 06:51:43 +00:00
|
|
|
DRIVER_MODULE(miibus, tx, miibus_driver, miibus_devclass, 0, 0);
|
|
|
|
|
|
|
|
static struct epic_type epic_devs[] = {
|
2003-04-19 17:24:07 +00:00
|
|
|
{ SMC_VENDORID, SMC_DEVICEID_83C170, "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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_probe(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);
|
2005-03-01 07:50:12 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2000-04-12 06:51:43 +00:00
|
|
|
}
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
return (ENXIO);
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
static struct epic_type *
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_devtype(device_t dev)
|
2000-04-12 06:51:43 +00:00
|
|
|
{
|
|
|
|
struct epic_type *t;
|
|
|
|
|
|
|
|
t = epic_devs;
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
while (t->name != NULL) {
|
2000-04-12 06:51:43 +00:00
|
|
|
if ((pci_get_vendor(dev) == t->ven_id) &&
|
|
|
|
(pci_get_device(dev) == t->dev_id)) {
|
2003-04-19 17:24:07 +00:00
|
|
|
return (t);
|
2000-04-12 06:51:43 +00:00
|
|
|
}
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
#ifdef EPIC_USEIOSPACE
|
2000-04-12 06:51:43 +00:00
|
|
|
#define EPIC_RES SYS_RES_IOPORT
|
|
|
|
#define EPIC_RID PCIR_BASEIO
|
|
|
|
#else
|
|
|
|
#define EPIC_RES SYS_RES_MEMORY
|
|
|
|
#define EPIC_RID PCIR_BASEMEM
|
|
|
|
#endif
|
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
static void
|
|
|
|
epic_dma_map_addr(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
|
|
|
u_int32_t *addr;
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
KASSERT(nseg == 1, ("too many DMA segments, %d should be 1", nseg));
|
|
|
|
addr = arg;
|
|
|
|
*addr = segs->ds_addr;
|
|
|
|
}
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/*
|
2002-10-22 00:57:51 +00:00
|
|
|
* Attach routine: map registers, allocate softc, rings and descriptors.
|
|
|
|
* Reset to known state.
|
1998-01-21 18:33:00 +00:00
|
|
|
*/
|
2000-04-12 06:51:43 +00:00
|
|
|
static int
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_attach(device_t dev)
|
1998-11-01 07:44:33 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
epic_softc_t *sc;
|
2008-06-10 17:59:43 +00:00
|
|
|
int error;
|
|
|
|
int i, rid, tmp;
|
2005-06-10 16:49:24 +00:00
|
|
|
u_char eaddr[6];
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
sc = device_get_softc(dev);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Preinitialize softc structure. */
|
2000-06-21 19:19:49 +00:00
|
|
|
sc->dev = dev;
|
2008-06-10 17:59:43 +00:00
|
|
|
mtx_init(&sc->lock, device_get_nameunit(dev), MTX_NETWORK_LOCK,
|
|
|
|
MTX_DEF);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Fill ifnet structure. */
|
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");
|
|
|
|
error = ENOSPC;
|
|
|
|
goto fail;
|
|
|
|
}
|
2003-10-31 18:32:15 +00:00
|
|
|
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
|
1998-11-01 07:44:33 +00:00
|
|
|
ifp->if_softc = sc;
|
2008-06-10 17:59:43 +00:00
|
|
|
ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
|
1998-11-01 07:44:33 +00:00
|
|
|
ifp->if_ioctl = epic_ifioctl;
|
|
|
|
ifp->if_start = epic_ifstart;
|
2003-04-19 13:51:24 +00:00
|
|
|
ifp->if_init = epic_init;
|
2008-06-10 17:59:43 +00:00
|
|
|
IFQ_SET_MAXLEN(&ifp->if_snd, TX_RING_SIZE - 1);
|
2000-04-12 06:51:43 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Enable busmastering. */
|
2003-04-19 00:21:34 +00:00
|
|
|
pci_enable_busmaster(dev);
|
1999-10-29 09:56:52 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
rid = EPIC_RID;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->res = bus_alloc_resource_any(dev, EPIC_RES, &rid, RF_ACTIVE);
|
2000-04-12 06:51:43 +00:00
|
|
|
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
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Allocate interrupt. */
|
2000-04-12 06:51:43 +00:00
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
2000-04-12 06:51:43 +00:00
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
|
|
|
if (sc->irq == NULL) {
|
|
|
|
device_printf(dev, "couldn't map interrupt\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
1999-10-29 09:56:52 +00:00
|
|
|
}
|
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
/* Allocate DMA tags. */
|
2008-09-12 14:41:53 +00:00
|
|
|
error = bus_dma_tag_create(bus_get_dma_tag(dev), 4, 0,
|
|
|
|
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
|
|
|
|
MCLBYTES * EPIC_MAX_FRAGS, EPIC_MAX_FRAGS, MCLBYTES, 0, NULL, NULL,
|
|
|
|
&sc->mtag);
|
2002-08-19 20:36:08 +00:00
|
|
|
if (error) {
|
2003-04-20 18:08:00 +00:00
|
|
|
device_printf(dev, "couldn't allocate dma tag\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-09-12 14:41:53 +00:00
|
|
|
error = bus_dma_tag_create(bus_get_dma_tag(dev), 4, 0,
|
|
|
|
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
|
2003-04-20 18:08:00 +00:00
|
|
|
sizeof(struct epic_rx_desc) * RX_RING_SIZE,
|
2008-06-10 17:59:43 +00:00
|
|
|
1, sizeof(struct epic_rx_desc) * RX_RING_SIZE, 0, NULL,
|
|
|
|
NULL, &sc->rtag);
|
2003-04-20 18:08:00 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't allocate dma tag\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-09-12 14:41:53 +00:00
|
|
|
error = bus_dma_tag_create(bus_get_dma_tag(dev), 4, 0,
|
|
|
|
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
|
2003-04-20 18:08:00 +00:00
|
|
|
sizeof(struct epic_tx_desc) * TX_RING_SIZE,
|
2003-07-01 15:52:06 +00:00
|
|
|
1, sizeof(struct epic_tx_desc) * TX_RING_SIZE, 0,
|
2008-06-10 17:59:43 +00:00
|
|
|
NULL, NULL, &sc->ttag);
|
2003-04-20 18:08:00 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't allocate dma tag\n");
|
2000-04-12 06:51:43 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2008-09-12 14:41:53 +00:00
|
|
|
error = bus_dma_tag_create(bus_get_dma_tag(dev), 4, 0,
|
|
|
|
BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
|
2003-04-20 18:08:00 +00:00
|
|
|
sizeof(struct epic_frag_list) * TX_RING_SIZE,
|
2003-07-01 15:52:06 +00:00
|
|
|
1, sizeof(struct epic_frag_list) * TX_RING_SIZE, 0,
|
2008-06-10 17:59:43 +00:00
|
|
|
NULL, NULL, &sc->ftag);
|
2003-04-20 18:08:00 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't allocate dma tag\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate DMA safe memory and get the DMA addresses. */
|
|
|
|
error = bus_dmamem_alloc(sc->ftag, (void **)&sc->tx_flist,
|
2003-08-12 14:55:12 +00:00
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->fmap);
|
2003-04-20 18:08:00 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't allocate dma memory\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = bus_dmamap_load(sc->ftag, sc->fmap, sc->tx_flist,
|
|
|
|
sizeof(struct epic_frag_list) * TX_RING_SIZE, epic_dma_map_addr,
|
|
|
|
&sc->frag_addr, 0);
|
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't map dma memory\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = bus_dmamem_alloc(sc->ttag, (void **)&sc->tx_desc,
|
2003-08-12 14:55:12 +00:00
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->tmap);
|
2003-04-20 18:08:00 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't allocate dma memory\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = bus_dmamap_load(sc->ttag, sc->tmap, sc->tx_desc,
|
|
|
|
sizeof(struct epic_tx_desc) * TX_RING_SIZE, epic_dma_map_addr,
|
|
|
|
&sc->tx_addr, 0);
|
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't map dma memory\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = bus_dmamem_alloc(sc->rtag, (void **)&sc->rx_desc,
|
2003-08-12 14:55:12 +00:00
|
|
|
BUS_DMA_NOWAIT | BUS_DMA_ZERO, &sc->rmap);
|
2003-04-20 18:08:00 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't allocate dma memory\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
error = bus_dmamap_load(sc->rtag, sc->rmap, sc->rx_desc,
|
|
|
|
sizeof(struct epic_rx_desc) * RX_RING_SIZE, epic_dma_map_addr,
|
|
|
|
&sc->rx_addr, 0);
|
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't map dma memory\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bring the chip out of low-power mode. */
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* Read MAC address from EEPROM. */
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN / sizeof(u_int16_t); i++)
|
2005-06-10 16:49:24 +00:00
|
|
|
((u_int16_t *)eaddr)[i] = epic_read_eeprom(sc,i);
|
2003-04-20 18:08:00 +00:00
|
|
|
|
|
|
|
/* Set Non-Volatile Control Register from EEPROM. */
|
|
|
|
CSR_WRITE_4(sc, NVCTL, epic_read_eeprom(sc, EEPROM_NVCTL) & 0x1F);
|
|
|
|
|
|
|
|
/* Set defaults. */
|
|
|
|
sc->tx_threshold = TRANSMIT_THRESHOLD;
|
|
|
|
sc->txcon = TXCON_DEFAULT;
|
|
|
|
sc->miicfg = MIICFG_SMI_ENABLE;
|
|
|
|
sc->phyid = EPIC_UNKN_PHY;
|
|
|
|
sc->serinst = -1;
|
|
|
|
|
|
|
|
/* Fetch card id. */
|
|
|
|
sc->cardvend = pci_read_config(dev, PCIR_SUBVEND_0, 2);
|
|
|
|
sc->cardid = pci_read_config(dev, PCIR_SUBDEV_0, 2);
|
|
|
|
|
|
|
|
if (sc->cardvend != SMC_VENDORID)
|
|
|
|
device_printf(dev, "unknown card vendor %04xh\n", sc->cardvend);
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Do ifmedia setup. */
|
2001-08-13 18:37:31 +00:00
|
|
|
if (mii_phy_probe(dev, &sc->miibus,
|
|
|
|
epic_ifmedia_upd, epic_ifmedia_sts)) {
|
2002-10-22 00:57:51 +00:00
|
|
|
device_printf(dev, "ERROR! MII without any PHY!?\n");
|
2000-04-12 06:51:43 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-10-29 09:56:52 +00:00
|
|
|
|
1998-11-01 07:44:33 +00:00
|
|
|
/* board type and ... */
|
|
|
|
printf(" type ");
|
2003-04-19 13:51:24 +00:00
|
|
|
for(i = 0x2c; i < 0x32; i++) {
|
2002-10-22 00:57:51 +00:00
|
|
|
tmp = epic_read_eeprom(sc, i);
|
2003-04-19 13:51:24 +00:00
|
|
|
if (' ' == (u_int8_t)tmp)
|
|
|
|
break;
|
2002-10-22 00:57:51 +00:00
|
|
|
printf("%c", (u_int8_t)tmp);
|
1998-11-01 07:44:33 +00:00
|
|
|
tmp >>= 8;
|
2003-04-19 13:51:24 +00:00
|
|
|
if (' ' == (u_int8_t)tmp)
|
|
|
|
break;
|
2002-10-22 00:57:51 +00:00
|
|
|
printf("%c", (u_int8_t)tmp);
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
2001-02-07 20:11:02 +00:00
|
|
|
printf("\n");
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Initialize rings. */
|
2003-04-19 13:51:24 +00:00
|
|
|
if (epic_init_rings(sc)) {
|
|
|
|
device_printf(dev, "failed to init rings\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto fail;
|
2003-04-19 17:24:07 +00:00
|
|
|
}
|
2003-04-19 13:51:24 +00:00
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
ifp->if_hdrlen = sizeof(struct ether_vlan_header);
|
|
|
|
ifp->if_capabilities |= IFCAP_VLAN_MTU;
|
2004-05-23 19:21:48 +00:00
|
|
|
ifp->if_capenable |= IFCAP_VLAN_MTU;
|
2008-06-10 17:59:43 +00:00
|
|
|
callout_init_mtx(&sc->timer, &sc->lock, 0);
|
|
|
|
|
|
|
|
/* Attach to OS's managers. */
|
|
|
|
ether_ifattach(ifp, eaddr);
|
2003-04-20 18:08:00 +00:00
|
|
|
|
2003-04-19 13:51:24 +00:00
|
|
|
/* Activate our interrupt handler. */
|
2008-06-10 17:59:43 +00:00
|
|
|
error = bus_setup_intr(dev, sc->irq, INTR_TYPE_NET | INTR_MPSAFE,
|
2007-02-23 12:19:07 +00:00
|
|
|
NULL, epic_intr, sc, &sc->sc_ih);
|
2003-04-19 13:51:24 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "couldn't set up irq\n");
|
2008-06-10 17:59:43 +00:00
|
|
|
ether_ifdetach(ifp);
|
2003-04-19 13:51:24 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
return (0);
|
2000-04-12 06:51:43 +00:00
|
|
|
fail:
|
2003-04-20 18:08:00 +00:00
|
|
|
epic_release(sc);
|
2003-04-19 13:51:24 +00:00
|
|
|
return (error);
|
2000-04-12 06:51:43 +00:00
|
|
|
}
|
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
/*
|
|
|
|
* Free any resources allocated by the driver.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
epic_release(epic_softc_t *sc)
|
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
if (sc->ifp != NULL)
|
|
|
|
if_free(sc->ifp);
|
2003-04-20 18:08:00 +00:00
|
|
|
if (sc->irq)
|
|
|
|
bus_release_resource(sc->dev, SYS_RES_IRQ, 0, sc->irq);
|
|
|
|
if (sc->res)
|
|
|
|
bus_release_resource(sc->dev, EPIC_RES, EPIC_RID, sc->res);
|
|
|
|
epic_free_rings(sc);
|
|
|
|
if (sc->tx_flist) {
|
|
|
|
bus_dmamap_unload(sc->ftag, sc->fmap);
|
|
|
|
bus_dmamem_free(sc->ftag, sc->tx_flist, sc->fmap);
|
|
|
|
bus_dmamap_destroy(sc->ftag, sc->fmap);
|
|
|
|
}
|
|
|
|
if (sc->tx_desc) {
|
|
|
|
bus_dmamap_unload(sc->ttag, sc->tmap);
|
|
|
|
bus_dmamem_free(sc->ttag, sc->tx_desc, sc->tmap);
|
|
|
|
bus_dmamap_destroy(sc->ttag, sc->tmap);
|
|
|
|
}
|
|
|
|
if (sc->rx_desc) {
|
|
|
|
bus_dmamap_unload(sc->rtag, sc->rmap);
|
|
|
|
bus_dmamem_free(sc->rtag, sc->rx_desc, sc->rmap);
|
|
|
|
bus_dmamap_destroy(sc->rtag, sc->rmap);
|
|
|
|
}
|
|
|
|
if (sc->mtag)
|
|
|
|
bus_dma_tag_destroy(sc->mtag);
|
|
|
|
if (sc->ftag)
|
|
|
|
bus_dma_tag_destroy(sc->ftag);
|
|
|
|
if (sc->ttag)
|
|
|
|
bus_dma_tag_destroy(sc->ttag);
|
|
|
|
if (sc->rtag)
|
|
|
|
bus_dma_tag_destroy(sc->rtag);
|
2008-06-10 17:59:43 +00:00
|
|
|
mtx_destroy(&sc->lock);
|
2003-04-20 18:08:00 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/*
|
2003-04-19 17:24:07 +00:00
|
|
|
* Detach driver and free resources.
|
2000-04-12 06:51:43 +00:00
|
|
|
*/
|
|
|
|
static int
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_detach(device_t dev)
|
2000-04-12 06:51:43 +00:00
|
|
|
{
|
|
|
|
struct ifnet *ifp;
|
|
|
|
epic_softc_t *sc;
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
sc = device_get_softc(dev);
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->ifp;
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_LOCK(sc);
|
2000-04-12 06:51:43 +00:00
|
|
|
epic_stop(sc);
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_UNLOCK(sc);
|
|
|
|
callout_drain(&sc->timer);
|
|
|
|
ether_ifdetach(ifp);
|
|
|
|
bus_teardown_intr(dev, sc->irq, sc->sc_ih);
|
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
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
epic_release(sc);
|
2003-04-19 17:24:07 +00:00
|
|
|
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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_shutdown(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);
|
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_LOCK(sc);
|
1998-11-01 07:44:33 +00:00
|
|
|
epic_stop(sc);
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_UNLOCK(sc);
|
2000-04-12 06:51:43 +00:00
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/*
|
2002-10-22 00:57:51 +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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_ifioctl(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;
|
2008-06-10 17:59:43 +00:00
|
|
|
int error = 0;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
switch (command) {
|
2001-08-13 18:32:39 +00:00
|
|
|
case SIOCSIFMTU:
|
2002-10-22 00:57:51 +00:00
|
|
|
if (ifp->if_mtu == ifr->ifr_mtu)
|
2001-08-13 18:32:39 +00:00
|
|
|
break;
|
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
/* XXX Though the datasheet doesn't imply any
|
2001-08-13 18:32:39 +00:00
|
|
|
* limitations on RX and TX sizes beside max 64Kb
|
|
|
|
* DMA transfer, seems we can't send more then 1600
|
2003-04-19 17:24:07 +00:00
|
|
|
* data bytes per ethernet packet (transmitter hangs
|
|
|
|
* up if more data is sent).
|
2001-08-13 18:32:39 +00:00
|
|
|
*/
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_LOCK(sc);
|
2001-08-13 18:32:39 +00:00
|
|
|
if (ifr->ifr_mtu + ifp->if_hdrlen <= EPIC_MAX_MTU) {
|
|
|
|
ifp->if_mtu = ifr->ifr_mtu;
|
|
|
|
epic_stop(sc);
|
2008-06-10 17:59:43 +00:00
|
|
|
epic_init_locked(sc);
|
2001-08-13 18:32:39 +00:00
|
|
|
} else
|
|
|
|
error = EINVAL;
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_UNLOCK(sc);
|
2001-08-13 18:32:39 +00:00
|
|
|
break;
|
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.
|
|
|
|
*/
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_LOCK(sc);
|
1998-01-21 18:33:00 +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) {
|
2008-06-10 17:59:43 +00:00
|
|
|
epic_init_locked(sc);
|
|
|
|
EPIC_UNLOCK(sc);
|
1998-02-04 15:04:09 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
} else {
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
1998-01-21 18:33:00 +00:00
|
|
|
epic_stop(sc);
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_UNLOCK(sc);
|
1998-02-04 15:04:09 +00:00
|
|
|
break;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Handle IFF_PROMISC and IFF_ALLMULTI flags. */
|
|
|
|
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);
|
2003-04-19 17:24:07 +00:00
|
|
|
epic_start_activity(sc);
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_UNLOCK(sc);
|
1998-01-21 18:33:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_LOCK(sc);
|
1998-01-29 10:31:45 +00:00
|
|
|
epic_set_mc_table(sc);
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_UNLOCK(sc);
|
1998-01-29 10:31:45 +00:00
|
|
|
error = 0;
|
|
|
|
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:
|
2002-11-14 23:54:55 +00:00
|
|
|
error = ether_ioctl(ifp, command, data);
|
|
|
|
break;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
2003-04-19 17:24:07 +00:00
|
|
|
return (error);
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
static void
|
|
|
|
epic_dma_map_txbuf(void *arg, bus_dma_segment_t *segs, int nseg,
|
|
|
|
bus_size_t mapsize, int error)
|
1998-11-01 07:44:33 +00:00
|
|
|
{
|
2003-04-20 18:08:00 +00:00
|
|
|
struct epic_frag_list *flist;
|
1998-11-01 07:44:33 +00:00
|
|
|
int i;
|
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
if (error)
|
|
|
|
return;
|
2001-06-23 19:30:26 +00:00
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
KASSERT(nseg <= EPIC_MAX_FRAGS, ("too many DMA segments"));
|
|
|
|
flist = arg;
|
|
|
|
/* Fill fragments list. */
|
|
|
|
for (i = 0; i < nseg; i++) {
|
|
|
|
KASSERT(segs[i].ds_len <= MCLBYTES, ("segment size too large"));
|
|
|
|
flist->frag[i].fraglen = segs[i].ds_len;
|
|
|
|
flist->frag[i].fragaddr = segs[i].ds_addr;
|
|
|
|
}
|
|
|
|
flist->numfrags = nseg;
|
|
|
|
}
|
2001-02-07 20:11:02 +00:00
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
static void
|
|
|
|
epic_dma_map_rxbuf(void *arg, bus_dma_segment_t *segs, int nseg,
|
|
|
|
bus_size_t mapsize, int error)
|
|
|
|
{
|
|
|
|
struct epic_rx_desc *desc;
|
2001-02-07 20:11:02 +00:00
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
if (error)
|
|
|
|
return;
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
KASSERT(nseg == 1, ("too many DMA segments"));
|
|
|
|
desc = arg;
|
|
|
|
desc->bufaddr = segs->ds_addr;
|
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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_ifstart(struct ifnet * ifp)
|
2008-06-10 17:59:43 +00:00
|
|
|
{
|
|
|
|
epic_softc_t *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
EPIC_LOCK(sc);
|
|
|
|
epic_ifstart_locked(ifp);
|
|
|
|
EPIC_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
epic_ifstart_locked(struct ifnet * ifp)
|
2000-04-12 06:51:43 +00:00
|
|
|
{
|
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;
|
2003-04-19 17:24:07 +00:00
|
|
|
struct mbuf *m0, *m;
|
2003-04-20 18:08:00 +00:00
|
|
|
int error;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
while (sc->pending_txs < TX_RING_SIZE) {
|
1998-07-04 08:02:46 +00:00
|
|
|
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
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Get next packet to send. */
|
2002-10-22 00:57:51 +00:00
|
|
|
IF_DEQUEUE(&ifp->if_snd, m0);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* If nothing to send, return. */
|
|
|
|
if (m0 == NULL)
|
|
|
|
return;
|
1998-04-13 14:15:40 +00:00
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
error = bus_dmamap_load_mbuf(sc->mtag, buf->map, m0,
|
|
|
|
epic_dma_map_txbuf, flist, 0);
|
|
|
|
|
|
|
|
if (error && error != EFBIG) {
|
|
|
|
m_freem(m0);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
1998-02-04 15:04:09 +00:00
|
|
|
}
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/*
|
|
|
|
* If packet was more than EPIC_MAX_FRAGS parts,
|
|
|
|
* recopy packet to a newly allocated mbuf cluster.
|
|
|
|
*/
|
2003-04-20 18:08:00 +00:00
|
|
|
if (error) {
|
|
|
|
m = m_defrag(m0, M_DONTWAIT);
|
2003-04-19 17:24:07 +00:00
|
|
|
if (m == NULL) {
|
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_freem(m0);
|
|
|
|
m0 = m;
|
2003-04-20 18:08:00 +00:00
|
|
|
|
|
|
|
error = bus_dmamap_load_mbuf(sc->mtag, buf->map, m,
|
|
|
|
epic_dma_map_txbuf, flist, 0);
|
|
|
|
if (error) {
|
|
|
|
m_freem(m);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
continue;
|
|
|
|
}
|
1998-04-13 14:15:40 +00:00
|
|
|
}
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREWRITE);
|
1998-04-13 14:15:40 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
buf->mbuf = m0;
|
|
|
|
sc->pending_txs++;
|
2002-10-22 00:57:51 +00:00
|
|
|
sc->cur_tx = (sc->cur_tx + 1) & TX_RING_MASK;
|
1998-07-04 08:02:46 +00:00
|
|
|
desc->control = 0x01;
|
2002-10-22 00:57:51 +00:00
|
|
|
desc->txlength =
|
2003-04-20 18:08:00 +00:00
|
|
|
max(m0->m_pkthdr.len, ETHER_MIN_LEN - ETHER_CRC_LEN);
|
1998-02-20 18:08:46 +00:00
|
|
|
desc->status = 0x8000;
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->ttag, sc->tmap,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
bus_dmamap_sync(sc->ftag, sc->fmap, BUS_DMASYNC_PREWRITE);
|
2002-10-22 00:57:51 +00:00
|
|
|
CSR_WRITE_4(sc, COMMAND, COMMAND_TXQUEUED);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Set watchdog timer. */
|
2008-06-10 17:59:43 +00:00
|
|
|
sc->tx_timeout = 8;
|
1998-07-04 08:02:46 +00:00
|
|
|
|
2002-11-14 23:54:55 +00:00
|
|
|
BPF_MTAP(ifp, m0);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_OACTIVE;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_rx_done(epic_softc_t *sc)
|
1998-01-21 18:33:00 +00:00
|
|
|
{
|
2005-06-10 16:49:24 +00:00
|
|
|
struct ifnet *ifp = sc->ifp;
|
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;
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_t map;
|
|
|
|
int error;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->rtag, sc->rmap, BUS_DMASYNC_POSTREAD);
|
2002-10-22 00:57:51 +00:00
|
|
|
while ((sc->rx_desc[sc->cur_rx].status & 0x8000) == 0) {
|
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
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Switch to next descriptor. */
|
|
|
|
sc->cur_rx = (sc->cur_rx + 1) & RX_RING_MASK;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
/*
|
|
|
|
* Check for RX errors. This should only happen if
|
|
|
|
* SAVE_ERRORED_PACKETS is set. RX errors generate
|
|
|
|
* RXE interrupt usually.
|
|
|
|
*/
|
|
|
|
if ((desc->status & 1) == 0) {
|
2002-10-25 22:06:03 +00:00
|
|
|
ifp->if_ierrors++;
|
1998-07-04 08:02:46 +00:00
|
|
|
desc->status = 0x8000;
|
|
|
|
continue;
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Save packet length and mbuf contained packet. */
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTREAD);
|
1998-02-20 18:08:46 +00:00
|
|
|
len = desc->rxlength - ETHER_CRC_LEN;
|
|
|
|
m = buf->mbuf;
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Try to get an mbuf cluster. */
|
2003-02-19 05:47:46 +00:00
|
|
|
buf->mbuf = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
|
2003-04-19 17:24:07 +00:00
|
|
|
if (buf->mbuf == NULL) {
|
1998-07-04 08:02:46 +00:00
|
|
|
buf->mbuf = m;
|
|
|
|
desc->status = 0x8000;
|
2002-10-25 22:06:03 +00:00
|
|
|
ifp->if_ierrors++;
|
1998-07-04 08:02:46 +00:00
|
|
|
continue;
|
1998-02-04 15:04:09 +00:00
|
|
|
}
|
2002-10-25 22:06:03 +00:00
|
|
|
buf->mbuf->m_len = buf->mbuf->m_pkthdr.len = MCLBYTES;
|
|
|
|
m_adj(buf->mbuf, ETHER_ALIGN);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Point to new mbuf, and give descriptor to chip. */
|
2003-04-20 18:08:00 +00:00
|
|
|
error = bus_dmamap_load_mbuf(sc->mtag, sc->sparemap, buf->mbuf,
|
|
|
|
epic_dma_map_rxbuf, desc, 0);
|
|
|
|
if (error) {
|
|
|
|
buf->mbuf = m;
|
|
|
|
desc->status = 0x8000;
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
desc->status = 0x8000;
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_unload(sc->mtag, buf->map);
|
|
|
|
map = buf->map;
|
|
|
|
buf->map = sc->sparemap;
|
|
|
|
sc->sparemap = map;
|
|
|
|
bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREREAD);
|
2003-04-19 17:24:07 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/* First mbuf in packet holds the ethernet and packet headers */
|
2002-10-25 22:06:03 +00:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
2002-11-14 23:54:55 +00:00
|
|
|
m->m_pkthdr.len = m->m_len = len;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Give mbuf to OS. */
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_UNLOCK(sc);
|
2002-11-14 23:54:55 +00:00
|
|
|
(*ifp->if_input)(ifp, m);
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_LOCK(sc);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/* Successfuly received frame */
|
2002-10-25 22:06:03 +00:00
|
|
|
ifp->if_ipackets++;
|
|
|
|
}
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->rtag, sc->rmap,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
/*
|
2002-10-22 00:57:51 +00:00
|
|
|
* Synopsis: Do last phase of transmission. I.e. if desc is
|
1998-07-04 08:02:46 +00:00
|
|
|
* 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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_tx_done(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;
|
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->ttag, sc->tmap, BUS_DMASYNC_POSTREAD);
|
2002-10-22 00:57:51 +00:00
|
|
|
while (sc->pending_txs > 0) {
|
1998-07-04 08:02:46 +00:00
|
|
|
buf = sc->tx_buffer + sc->dirty_tx;
|
|
|
|
desc = sc->tx_desc + sc->dirty_tx;
|
|
|
|
status = desc->status;
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/*
|
|
|
|
* If packet is not transmitted, thou followed
|
|
|
|
* packets are not transmitted too.
|
|
|
|
*/
|
|
|
|
if (status & 0x8000)
|
|
|
|
break;
|
1998-07-04 08:02:46 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Packet is transmitted. Switch to next and free mbuf. */
|
1998-07-04 08:02:46 +00:00
|
|
|
sc->pending_txs--;
|
1998-11-01 07:44:33 +00:00
|
|
|
sc->dirty_tx = (sc->dirty_tx + 1) & TX_RING_MASK;
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->mtag, buf->map);
|
2002-10-22 00:57:51 +00:00
|
|
|
m_freem(buf->mbuf);
|
1998-02-04 15:04:09 +00:00
|
|
|
buf->mbuf = NULL;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Check for errors and collisions. */
|
|
|
|
if (status & 0x0001)
|
2005-06-10 16:49:24 +00:00
|
|
|
sc->ifp->if_opackets++;
|
2003-04-19 17:24:07 +00:00
|
|
|
else
|
2005-06-10 16:49:24 +00:00
|
|
|
sc->ifp->if_oerrors++;
|
|
|
|
sc->ifp->if_collisions += (status >> 8) & 0x1F;
|
2003-04-19 17:24:07 +00:00
|
|
|
#ifdef EPIC_DIAG
|
2002-10-22 00:57:51 +00:00
|
|
|
if ((status & 0x1001) == 0x1001)
|
2003-04-19 17:24:07 +00:00
|
|
|
device_printf(sc->dev,
|
|
|
|
"Tx ERROR: excessive coll. number\n");
|
1998-07-04 08:02:46 +00:00
|
|
|
#endif
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
if (sc->pending_txs < TX_RING_SIZE)
|
2005-08-09 10:20:02 +00:00
|
|
|
sc->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->ttag, sc->tmap,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-02-20 18:08:46 +00:00
|
|
|
/*
|
|
|
|
* Interrupt function
|
|
|
|
*/
|
2002-10-22 00:57:51 +00:00
|
|
|
static void
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_intr(void *arg)
|
1998-02-20 18:08:46 +00:00
|
|
|
{
|
2003-04-19 17:24:07 +00:00
|
|
|
epic_softc_t *sc;
|
|
|
|
int status, i;
|
2002-10-22 00:57:51 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
sc = arg;
|
|
|
|
i = 4;
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_LOCK(sc);
|
2002-10-22 00:57:51 +00:00
|
|
|
while (i-- && ((status = CSR_READ_4(sc, INTSTAT)) & INTSTAT_INT_ACTV)) {
|
|
|
|
CSR_WRITE_4(sc, INTSTAT, status);
|
|
|
|
|
|
|
|
if (status & (INTSTAT_RQE|INTSTAT_RCC|INTSTAT_OVW)) {
|
|
|
|
epic_rx_done(sc);
|
|
|
|
if (status & (INTSTAT_RQE|INTSTAT_OVW)) {
|
2003-04-19 17:24:07 +00:00
|
|
|
#ifdef EPIC_DIAG
|
2002-10-22 00:57:51 +00:00
|
|
|
if (status & INTSTAT_OVW)
|
|
|
|
device_printf(sc->dev, "RX buffer overflow\n");
|
|
|
|
if (status & INTSTAT_RQE)
|
|
|
|
device_printf(sc->dev, "RX FIFO overflow\n");
|
1998-11-01 07:44:33 +00:00
|
|
|
#endif
|
2002-10-22 00:57:51 +00:00
|
|
|
if ((CSR_READ_4(sc, COMMAND) & COMMAND_RXQUEUED) == 0)
|
|
|
|
CSR_WRITE_4(sc, COMMAND, COMMAND_RXQUEUED);
|
2005-06-10 16:49:24 +00:00
|
|
|
sc->ifp->if_ierrors++;
|
2002-10-22 00:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
if (status & (INTSTAT_TXC|INTSTAT_TCC|INTSTAT_TQE)) {
|
|
|
|
epic_tx_done(sc);
|
2005-06-10 16:49:24 +00:00
|
|
|
if (sc->ifp->if_snd.ifq_head != NULL)
|
2008-06-10 17:59:43 +00:00
|
|
|
epic_ifstart_locked(sc->ifp);
|
1998-07-04 08:02:46 +00:00
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
/* Check for rare errors */
|
|
|
|
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)) {
|
|
|
|
device_printf(sc->dev, "PCI fatal errors occured: %s%s%s%s\n",
|
2003-04-19 17:24:07 +00:00
|
|
|
(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);
|
2008-06-10 17:59:43 +00:00
|
|
|
epic_init_locked(sc);
|
1998-11-01 07:44:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & INTSTAT_RXE) {
|
2003-04-19 17:24:07 +00:00
|
|
|
#ifdef EPIC_DIAG
|
2002-10-22 00:57:51 +00:00
|
|
|
device_printf(sc->dev, "CRC/Alignment error\n");
|
|
|
|
#endif
|
2005-06-10 16:49:24 +00:00
|
|
|
sc->ifp->if_ierrors++;
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status & INTSTAT_TXU) {
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_tx_underrun(sc);
|
2005-06-10 16:49:24 +00:00
|
|
|
sc->ifp->if_oerrors++;
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
}
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* If no packets are pending, then no timeouts. */
|
|
|
|
if (sc->pending_txs == 0)
|
2008-06-10 17:59:43 +00:00
|
|
|
sc->tx_timeout = 0;
|
|
|
|
EPIC_UNLOCK(sc);
|
2002-10-22 00:57:51 +00:00
|
|
|
}
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
/*
|
|
|
|
* Handle the TX underrun error: increase the TX threshold
|
|
|
|
* and restart the transmitter.
|
|
|
|
*/
|
|
|
|
static void
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_tx_underrun(epic_softc_t *sc)
|
2002-10-22 00:57:51 +00:00
|
|
|
{
|
|
|
|
if (sc->tx_threshold > TRANSMIT_THRESHOLD_MAX) {
|
|
|
|
sc->txcon &= ~TXCON_EARLY_TRANSMIT_ENABLE;
|
2003-04-19 17:24:07 +00:00
|
|
|
#ifdef EPIC_DIAG
|
2002-10-22 00:57:51 +00:00
|
|
|
device_printf(sc->dev, "Tx UNDERRUN: early TX disabled\n");
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
sc->tx_threshold += 0x40;
|
2003-04-19 17:24:07 +00:00
|
|
|
#ifdef EPIC_DIAG
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Tx UNDERRUN: TX threshold increased to %d\n",
|
2002-10-22 00:57:51 +00:00
|
|
|
sc->tx_threshold);
|
1998-11-01 07:44:33 +00:00
|
|
|
#endif
|
2002-10-22 00:57:51 +00:00
|
|
|
}
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* We must set TXUGO to reset the stuck transmitter. */
|
2002-10-22 00:57:51 +00:00
|
|
|
CSR_WRITE_4(sc, COMMAND, COMMAND_TXUGO);
|
|
|
|
|
|
|
|
/* Update the TX threshold */
|
|
|
|
epic_stop_activity(sc);
|
|
|
|
epic_set_tx_mode(sc);
|
|
|
|
epic_start_activity(sc);
|
1998-02-20 18:08:46 +00:00
|
|
|
}
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/*
|
2008-06-10 17:59:43 +00:00
|
|
|
* This function is called once a second when the interface is running
|
|
|
|
* and performs two functions. First, it provides a timer for the mii
|
|
|
|
* to help with autonegotiation. Second, it checks for transmit
|
|
|
|
* timeouts.
|
1998-07-04 08:02:46 +00:00
|
|
|
*/
|
|
|
|
static void
|
2008-06-10 17:59:43 +00:00
|
|
|
epic_timer(void *arg)
|
1998-07-04 08:02:46 +00:00
|
|
|
{
|
2008-06-10 17:59:43 +00:00
|
|
|
epic_softc_t *sc = arg;
|
|
|
|
struct mii_data *mii;
|
|
|
|
struct ifnet *ifp;
|
1998-07-04 08:02:46 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
ifp = sc->ifp;
|
|
|
|
EPIC_ASSERT_LOCKED(sc);
|
|
|
|
if (sc->tx_timeout && --sc->tx_timeout == 0) {
|
|
|
|
device_printf(sc->dev, "device timeout %d packets\n",
|
|
|
|
sc->pending_txs);
|
1998-07-04 08:02:46 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
/* Try to finish queued packets. */
|
|
|
|
epic_tx_done(sc);
|
1998-07-04 08:02:46 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
/* If not successful. */
|
|
|
|
if (sc->pending_txs > 0) {
|
|
|
|
ifp->if_oerrors += sc->pending_txs;
|
1998-07-04 08:02:46 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
/* Reinitialize board. */
|
|
|
|
device_printf(sc->dev, "reinitialization\n");
|
|
|
|
epic_stop(sc);
|
|
|
|
epic_init_locked(sc);
|
|
|
|
} else
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"seems we can continue normaly\n");
|
2002-05-01 19:23:04 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
/* Start output. */
|
|
|
|
if (ifp->if_snd.ifq_head)
|
|
|
|
epic_ifstart_locked(ifp);
|
|
|
|
}
|
2002-05-01 19:23:04 +00:00
|
|
|
|
|
|
|
mii = device_get_softc(sc->miibus);
|
|
|
|
mii_tick(mii);
|
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
callout_reset(&sc->timer, hz, epic_timer, sc);
|
2002-05-01 19:23:04 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/*
|
|
|
|
* Set media options.
|
|
|
|
*/
|
1998-02-20 18:08:46 +00:00
|
|
|
static int
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_ifmedia_upd(struct ifnet *ifp)
|
2008-06-10 17:59:43 +00:00
|
|
|
{
|
|
|
|
epic_softc_t *sc;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
EPIC_LOCK(sc);
|
|
|
|
error = epic_ifmedia_upd_locked(ifp);
|
|
|
|
EPIC_UNLOCK(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
epic_ifmedia_upd_locked(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
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Do not do anything if interface is not up. */
|
2002-10-22 00:57:51 +00:00
|
|
|
if ((ifp->if_flags & IFF_UP) == 0)
|
2000-06-21 19:19:49 +00:00
|
|
|
return (0);
|
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
/*
|
2003-04-19 17:24:07 +00:00
|
|
|
* Lookup current selected PHY.
|
2001-02-07 20:11:02 +00:00
|
|
|
*/
|
|
|
|
if (IFM_INST(media) == sc->serinst) {
|
|
|
|
sc->phyid = EPIC_SERIAL;
|
|
|
|
sc->physc = NULL;
|
|
|
|
} else {
|
2003-04-19 17:24:07 +00:00
|
|
|
/* If we're not selecting serial interface, select MII mode. */
|
2001-02-07 20:11:02 +00:00
|
|
|
sc->miicfg &= ~MIICFG_SERIAL_ENABLE;
|
|
|
|
CSR_WRITE_4(sc, MIICFG, sc->miicfg);
|
2000-06-21 19:19:49 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Default to unknown PHY. */
|
2001-02-07 20:11:02 +00:00
|
|
|
sc->phyid = EPIC_UNKN_PHY;
|
2000-06-21 19:19:49 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Lookup selected PHY. */
|
2001-02-07 20:11:02 +00:00
|
|
|
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
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Identify selected PHY. */
|
2001-02-07 20:11:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-04-19 17:24:07 +00:00
|
|
|
* Do PHY specific card setup.
|
2001-02-07 20:11:02 +00:00
|
|
|
*/
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/*
|
|
|
|
* Call this, to isolate all not selected PHYs and
|
|
|
|
* set up selected.
|
2001-02-07 20:11:02 +00:00
|
|
|
*/
|
|
|
|
mii_mediachg(mii);
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Do our own setup. */
|
2001-02-07 20:11:02 +00:00
|
|
|
switch (sc->phyid) {
|
|
|
|
case EPIC_QS6612_PHY:
|
|
|
|
break;
|
|
|
|
case EPIC_AC101_PHY:
|
2003-04-19 17:24:07 +00:00
|
|
|
/* We have to powerup fiber tranceivers. */
|
2001-02-07 20:11:02 +00:00
|
|
|
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);
|
2003-04-19 17:24:07 +00:00
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
break;
|
|
|
|
case EPIC_LXT970_PHY:
|
2003-04-19 17:24:07 +00:00
|
|
|
/* We have to powerup fiber tranceivers. */
|
2001-02-07 20:11:02 +00:00
|
|
|
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:
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Select serial PHY (10base2/BNC usually). */
|
2001-02-07 20:11:02 +00:00
|
|
|
sc->miicfg |= MIICFG_694_ENABLE | MIICFG_SERIAL_ENABLE;
|
|
|
|
CSR_WRITE_4(sc, MIICFG, sc->miicfg);
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* There is no driver to fill this. */
|
2001-02-07 20:11:02 +00:00
|
|
|
mii->mii_media_active = media;
|
|
|
|
mii->mii_media_status = 0;
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/*
|
|
|
|
* We need to call this manually as it wasn't called
|
|
|
|
* in mii_mediachg().
|
2001-02-07 20:11:02 +00:00
|
|
|
*/
|
|
|
|
epic_miibus_statchg(sc->dev);
|
|
|
|
break;
|
|
|
|
default:
|
2002-10-22 00:57:51 +00:00
|
|
|
device_printf(sc->dev, "ERROR! Unknown PHY selected\n");
|
2001-02-07 20:11:02 +00:00
|
|
|
return (EINVAL);
|
2000-06-21 19:19:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-19 17:24:07 +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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_ifmedia_sts(struct ifnet *ifp, struct ifmediareq *ifmr)
|
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;
|
2000-04-12 06:51:43 +00:00
|
|
|
|
|
|
|
sc = ifp->if_softc;
|
|
|
|
mii = device_get_softc(sc->miibus);
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_LOCK(sc);
|
2000-06-21 19:19:49 +00:00
|
|
|
ifm = &mii->mii_media;
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Nothing should be selected if interface is down. */
|
2002-10-22 00:57:51 +00:00
|
|
|
if ((ifp->if_flags & IFF_UP) == 0) {
|
2000-06-21 19:19:49 +00:00
|
|
|
ifmr->ifm_active = IFM_NONE;
|
|
|
|
ifmr->ifm_status = 0;
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_UNLOCK(sc);
|
2000-06-21 19:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Call underlying pollstat, if not serial PHY. */
|
2001-02-07 20:11:02 +00:00
|
|
|
if (sc->phyid != EPIC_SERIAL)
|
2000-04-12 06:51:43 +00:00
|
|
|
mii_pollstat(mii);
|
2001-02-07 20:11:02 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Simply copy media info. */
|
2001-02-07 20:11:02 +00:00
|
|
|
ifmr->ifm_active = mii->mii_media_active;
|
|
|
|
ifmr->ifm_status = mii->mii_media_status;
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_UNLOCK(sc);
|
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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_miibus_statchg(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
|
|
|
|
2003-04-19 17:24:07 +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
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* On some cards we need manualy set fullduplex led. */
|
2001-02-07 20:11:02 +00:00
|
|
|
if (sc->cardid == SMC9432FTX ||
|
|
|
|
sc->cardid == SMC9432FTX_SC) {
|
2002-10-22 00:57:51 +00:00
|
|
|
if (IFM_OPTIONS(media) & IFM_FDX)
|
2001-02-07 20:11:02 +00:00
|
|
|
sc->miicfg |= MIICFG_694_ENABLE;
|
|
|
|
else
|
|
|
|
sc->miicfg &= ~MIICFG_694_ENABLE;
|
|
|
|
|
|
|
|
CSR_WRITE_4(sc, MIICFG, sc->miicfg);
|
|
|
|
}
|
|
|
|
|
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);
|
1998-02-20 18:08:46 +00:00
|
|
|
}
|
|
|
|
|
2001-02-07 20:11:02 +00:00
|
|
|
static void
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_miibus_mediainit(device_t dev)
|
2000-06-21 19:19:49 +00:00
|
|
|
{
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_softc_t *sc;
|
|
|
|
struct mii_data *mii;
|
2000-06-21 19:19:49 +00:00
|
|
|
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;
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/*
|
|
|
|
* Add Serial Media Interface if present, this applies to
|
|
|
|
* SMC9432BTX serie.
|
2001-02-07 20:11:02 +00:00
|
|
|
*/
|
2002-10-22 00:57:51 +00:00
|
|
|
if (CSR_READ_4(sc, MIICFG) & MIICFG_PHY_PRESENT) {
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Store its instance. */
|
2001-02-07 20:11:02 +00:00
|
|
|
sc->serinst = mii->mii_instance++;
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Add as 10base2/BNC media. */
|
2001-02-07 20:11:02 +00:00
|
|
|
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
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Report to user. */
|
2002-10-22 00:57:51 +00:00
|
|
|
device_printf(sc->dev, "serial PHY detected (10Base2/BNC)\n");
|
2000-06-21 19:19:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-21 18:33:00 +00:00
|
|
|
/*
|
2003-04-20 18:08:00 +00:00
|
|
|
* Reset chip and update media.
|
1998-01-21 18:33:00 +00:00
|
|
|
*/
|
2003-04-19 13:51:24 +00:00
|
|
|
static void
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_init(void *xsc)
|
2002-10-22 00:57:51 +00:00
|
|
|
{
|
2003-04-19 13:51:24 +00:00
|
|
|
epic_softc_t *sc = xsc;
|
2002-10-22 00:57:51 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_LOCK(sc);
|
|
|
|
epic_init_locked(sc);
|
|
|
|
EPIC_UNLOCK(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
epic_init_locked(epic_softc_t *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = sc->ifp;
|
|
|
|
int i;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* If interface is already running, then we need not do anything. */
|
2005-08-09 10:20:02 +00:00
|
|
|
if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
|
2003-04-19 13:51:24 +00:00
|
|
|
return;
|
2000-04-12 06:51:43 +00:00
|
|
|
}
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Soft reset the chip (we have to power up card before). */
|
2002-10-22 00:57:51 +00:00
|
|
|
CSR_WRITE_4(sc, GENCTL, 0);
|
|
|
|
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 */
|
2002-10-22 00:57:51 +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 */
|
2003-04-19 17:24:07 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
CSR_WRITE_4(sc, TEST1, TEST1_CLOCK_TEST);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Give rings to EPIC */
|
2003-04-20 18:08:00 +00:00
|
|
|
CSR_WRITE_4(sc, PRCDAR, sc->rx_addr);
|
|
|
|
CSR_WRITE_4(sc, PTCDAR, sc->tx_addr);
|
1998-07-04 08:02:46 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Put node address to EPIC. */
|
2005-11-11 16:04:59 +00:00
|
|
|
CSR_WRITE_4(sc, LAN0, ((u_int16_t *)IF_LLADDR(sc->ifp))[0]);
|
|
|
|
CSR_WRITE_4(sc, LAN1, ((u_int16_t *)IF_LLADDR(sc->ifp))[1]);
|
|
|
|
CSR_WRITE_4(sc, LAN2, ((u_int16_t *)IF_LLADDR(sc->ifp))[2]);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Set tx mode, includeing transmit threshold. */
|
1998-11-01 07:44:33 +00:00
|
|
|
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. */
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_set_rx_mode(sc);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Set multicast table. */
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_set_mc_table(sc);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
/* Enable interrupts by setting the interrupt mask. */
|
2002-10-22 00:57:51 +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
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Acknowledge all pending interrupts. */
|
2001-02-07 20:11:02 +00:00
|
|
|
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 */
|
2002-10-22 00:57:51 +00:00
|
|
|
CSR_WRITE_4(sc, GENCTL,
|
1998-02-20 18:08:46 +00:00
|
|
|
GENCTL_ENABLE_INTERRUPT | GENCTL_MEMORY_READ_MULTIPLE |
|
2002-10-22 00:57:51 +00:00
|
|
|
GENCTL_ONECOPY | GENCTL_RECEIVE_FIFO_THRESHOLD64);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
/* Mark interface running ... */
|
2003-04-19 17:24:07 +00:00
|
|
|
if (ifp->if_flags & IFF_UP)
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags |= IFF_DRV_RUNNING;
|
2003-04-19 17:24:07 +00:00
|
|
|
else
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
/* ... and free */
|
2005-08-09 10:20:02 +00:00
|
|
|
ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
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 */
|
2008-06-10 17:59:43 +00:00
|
|
|
epic_ifmedia_upd_locked(ifp);
|
2002-05-01 19:23:04 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
callout_reset(&sc->timer, hz, epic_timer, sc);
|
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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_set_rx_mode(epic_softc_t *sc)
|
1998-01-21 18:33:00 +00:00
|
|
|
{
|
2003-04-19 17:24:07 +00:00
|
|
|
u_int32_t flags;
|
|
|
|
u_int32_t rxcon;
|
1998-01-29 10:31:45 +00:00
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
flags = sc->ifp->if_flags;
|
2003-04-19 17:24:07 +00:00
|
|
|
rxcon = RXCON_DEFAULT;
|
|
|
|
|
|
|
|
#ifdef EPIC_EARLY_RX
|
2002-04-19 22:43:57 +00:00
|
|
|
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
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
CSR_WRITE_4(sc, RXCON, rxcon);
|
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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_set_tx_mode(epic_softc_t *sc)
|
1998-11-01 07:44:33 +00:00
|
|
|
{
|
2003-04-19 17:24:07 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
if (sc->txcon & TXCON_EARLY_TRANSMIT_ENABLE)
|
2002-10-22 00:57:51 +00:00
|
|
|
CSR_WRITE_4(sc, ETXTHR, sc->tx_threshold);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2002-10-22 00:57:51 +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
|
2003-04-20 17:36:26 +00:00
|
|
|
* flags (note that setting PROMISC bit in EPIC's RXCON will only touch
|
|
|
|
* individual frames, multicast filter must be manually programmed).
|
2002-04-25 18:16:15 +00:00
|
|
|
*
|
|
|
|
* Note: EPIC must be in idle state.
|
1998-01-29 10:31:45 +00:00
|
|
|
*/
|
|
|
|
static void
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_set_mc_table(epic_softc_t *sc)
|
1998-01-29 10:31:45 +00:00
|
|
|
{
|
2003-04-19 17:24:07 +00:00
|
|
|
struct ifnet *ifp;
|
2002-04-25 18:16:15 +00:00
|
|
|
struct ifmultiaddr *ifma;
|
|
|
|
u_int16_t filter[4];
|
|
|
|
u_int8_t h;
|
|
|
|
|
2005-06-10 16:49:24 +00:00
|
|
|
ifp = sc->ifp;
|
2002-04-25 18:16:15 +00:00
|
|
|
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);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
filter[0] = 0;
|
|
|
|
filter[1] = 0;
|
|
|
|
filter[2] = 0;
|
|
|
|
filter[3] = 0;
|
|
|
|
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_LOCK(ifp);
|
2002-04-25 18:16:15 +00:00
|
|
|
TAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) {
|
|
|
|
if (ifma->ifma_addr->sa_family != AF_LINK)
|
|
|
|
continue;
|
2004-06-09 14:34:04 +00:00
|
|
|
h = ether_crc32_be(LLADDR((struct sockaddr_dl *)
|
|
|
|
ifma->ifma_addr), ETHER_ADDR_LEN) >> 26;
|
2002-04-25 18:16:15 +00:00
|
|
|
filter[h >> 4] |= 1 << (h & 0xF);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
2005-08-03 00:18:35 +00:00
|
|
|
IF_ADDR_UNLOCK(ifp);
|
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
|
|
|
}
|
|
|
|
|
1998-02-20 18:08:46 +00:00
|
|
|
|
2002-10-22 00:57:51 +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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_start_activity(epic_softc_t *sc)
|
1998-07-04 08:02:46 +00:00
|
|
|
{
|
2003-04-19 17:24:07 +00:00
|
|
|
|
|
|
|
/* Start rx process. */
|
2003-04-20 18:08:00 +00:00
|
|
|
CSR_WRITE_4(sc, COMMAND, COMMAND_RXQUEUED | COMMAND_START_RX |
|
|
|
|
(sc->pending_txs ? COMMAND_TXQUEUED : 0));
|
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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_stop_activity(epic_softc_t *sc)
|
1998-07-04 08:02:46 +00:00
|
|
|
{
|
2002-10-22 00:57:51 +00:00
|
|
|
int status, i;
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Stop Tx and Rx DMA. */
|
2002-10-22 00:57:51 +00:00
|
|
|
CSR_WRITE_4(sc, COMMAND,
|
|
|
|
COMMAND_STOP_RX | COMMAND_STOP_RDMA | COMMAND_STOP_TDMA);
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Wait Rx and Tx DMA to stop (why 1 ms ??? XXX). */
|
2003-04-20 17:36:26 +00:00
|
|
|
for (i = 0; i < 0x1000; i++) {
|
2003-04-19 17:24:07 +00:00
|
|
|
status = CSR_READ_4(sc, INTSTAT) &
|
|
|
|
(INTSTAT_TXIDLE | INTSTAT_RXIDLE);
|
2002-10-22 00:57:51 +00:00
|
|
|
if (status == (INTSTAT_TXIDLE | INTSTAT_RXIDLE))
|
|
|
|
break;
|
|
|
|
DELAY(1);
|
|
|
|
}
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Catch all finished packets. */
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_rx_done(sc);
|
|
|
|
epic_tx_done(sc);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
status = CSR_READ_4(sc, INTSTAT);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
if ((status & INTSTAT_RXIDLE) == 0)
|
|
|
|
device_printf(sc->dev, "ERROR! Can't stop Rx DMA\n");
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
if ((status & INTSTAT_TXIDLE) == 0)
|
|
|
|
device_printf(sc->dev, "ERROR! Can't stop Tx DMA\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* May need to queue one more packet if TQE, this is rare
|
|
|
|
* but existing case.
|
|
|
|
*/
|
|
|
|
if ((status & INTSTAT_TQE) && !(status & INTSTAT_TXIDLE))
|
2003-04-19 17:24:07 +00:00
|
|
|
(void)epic_queue_last_packet(sc);
|
2002-10-22 00:57:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The EPIC transmitter may stuck in TQE state. It will not go IDLE until
|
|
|
|
* a packet from current descriptor will be copied to internal RAM. We
|
|
|
|
* compose a dummy packet here and queue it for transmission.
|
|
|
|
*
|
|
|
|
* XXX the packet will then be actually sent over network...
|
|
|
|
*/
|
|
|
|
static int
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_queue_last_packet(epic_softc_t *sc)
|
2002-10-22 00:57:51 +00:00
|
|
|
{
|
1999-03-14 08:30:23 +00:00
|
|
|
struct epic_tx_desc *desc;
|
|
|
|
struct epic_frag_list *flist;
|
|
|
|
struct epic_tx_buffer *buf;
|
|
|
|
struct mbuf *m0;
|
2003-04-20 18:08:00 +00:00
|
|
|
int error, i;
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
device_printf(sc->dev, "queue last packet\n");
|
1998-11-01 07:44:33 +00:00
|
|
|
|
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))
|
2002-10-22 00:57:51 +00:00
|
|
|
return (EBUSY);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
MGETHDR(m0, M_DONTWAIT, MT_DATA);
|
2003-04-19 17:24:07 +00:00
|
|
|
if (m0 == NULL)
|
2002-10-22 00:57:51 +00:00
|
|
|
return (ENOBUFS);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Prepare mbuf. */
|
2003-04-20 18:08:00 +00:00
|
|
|
m0->m_len = min(MHLEN, ETHER_MIN_LEN - ETHER_CRC_LEN);
|
1999-03-14 08:30:23 +00:00
|
|
|
m0->m_pkthdr.len = m0->m_len;
|
2005-06-10 16:49:24 +00:00
|
|
|
m0->m_pkthdr.rcvif = sc->ifp;
|
2003-04-19 17:24:07 +00:00
|
|
|
bzero(mtod(m0, caddr_t), m0->m_len);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Fill fragments list. */
|
2003-04-20 18:08:00 +00:00
|
|
|
error = bus_dmamap_load_mbuf(sc->mtag, buf->map, m0,
|
|
|
|
epic_dma_map_txbuf, flist, 0);
|
|
|
|
if (error) {
|
|
|
|
m_freem(m0);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREWRITE);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Fill in descriptor. */
|
1999-03-14 08:30:23 +00:00
|
|
|
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;
|
2003-04-20 18:08:00 +00:00
|
|
|
desc->txlength = max(m0->m_pkthdr.len, ETHER_MIN_LEN - ETHER_CRC_LEN);
|
1999-03-14 08:30:23 +00:00
|
|
|
desc->status = 0x8000;
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->ttag, sc->tmap,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
bus_dmamap_sync(sc->ftag, sc->fmap, BUS_DMASYNC_PREWRITE);
|
1998-11-01 07:44:33 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
/* Launch transmission. */
|
1999-03-14 08:30:23 +00:00
|
|
|
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) */
|
2003-04-19 17:24:07 +00:00
|
|
|
for (i = 0; i < 1000; i++) {
|
2002-10-22 00:57:51 +00:00
|
|
|
if (CSR_READ_4(sc, INTSTAT) & INTSTAT_TXIDLE)
|
|
|
|
break;
|
|
|
|
DELAY(1);
|
1998-11-01 07:44:33 +00:00
|
|
|
}
|
1998-07-04 08:02:46 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
if ((CSR_READ_4(sc, INTSTAT) & INTSTAT_TXIDLE) == 0)
|
|
|
|
device_printf(sc->dev, "ERROR! can't stop Tx DMA (2)\n");
|
1999-03-14 08:30:23 +00:00
|
|
|
else
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_tx_done(sc);
|
1999-03-14 08:30:23 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
return (0);
|
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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_stop(epic_softc_t *sc)
|
1998-01-29 10:31:45 +00:00
|
|
|
{
|
1998-02-04 15:04:09 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
EPIC_ASSERT_LOCKED(sc);
|
1998-07-04 08:02:46 +00:00
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
sc->tx_timeout = 0;
|
|
|
|
callout_stop(&sc->timer);
|
2002-05-01 19:23:04 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
/* Disable interrupts */
|
2002-10-22 00:57:51 +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 */
|
2002-10-22 00:57:51 +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
|
|
|
|
2008-06-10 17:59:43 +00:00
|
|
|
/* Mark as stopped */
|
|
|
|
sc->ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
|
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.
|
2002-10-22 00:57:51 +00:00
|
|
|
*/
|
1998-02-04 15:04:09 +00:00
|
|
|
static void
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_free_rings(epic_softc_t *sc)
|
1998-07-04 08:02:46 +00:00
|
|
|
{
|
1998-02-04 15:04:09 +00:00
|
|
|
int i;
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
1998-02-04 15:04:09 +00:00
|
|
|
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;
|
2003-04-19 17:24:07 +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
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
if (buf->mbuf) {
|
|
|
|
bus_dmamap_unload(sc->mtag, buf->map);
|
|
|
|
bus_dmamap_destroy(sc->mtag, buf->map);
|
2003-04-19 17:24:07 +00:00
|
|
|
m_freem(buf->mbuf);
|
2003-04-20 18:08:00 +00:00
|
|
|
}
|
1998-02-04 15:04:09 +00:00
|
|
|
buf->mbuf = NULL;
|
|
|
|
}
|
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
if (sc->sparemap != NULL)
|
|
|
|
bus_dmamap_destroy(sc->mtag, sc->sparemap);
|
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
for (i = 0; i < TX_RING_SIZE; i++) {
|
1998-02-04 15:04:09 +00:00
|
|
|
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
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
if (buf->mbuf) {
|
|
|
|
bus_dmamap_unload(sc->mtag, buf->map);
|
|
|
|
bus_dmamap_destroy(sc->mtag, buf->map);
|
2003-04-19 17:24:07 +00:00
|
|
|
m_freem(buf->mbuf);
|
2003-04-20 18:08:00 +00:00
|
|
|
}
|
1998-02-04 15:04:09 +00:00
|
|
|
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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_init_rings(epic_softc_t *sc)
|
2000-04-12 06:51:43 +00:00
|
|
|
{
|
2003-04-20 18:08:00 +00:00
|
|
|
int error, i;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
|
|
|
sc->cur_rx = sc->cur_tx = sc->dirty_tx = sc->pending_txs = 0;
|
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
/* Initialize the RX descriptor ring. */
|
1998-01-21 18:33:00 +00:00
|
|
|
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 */
|
2003-04-20 18:08:00 +00:00
|
|
|
desc->next = sc->rx_addr +
|
|
|
|
((i + 1) & RX_RING_MASK) * sizeof(struct epic_rx_desc);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
if ((desc->next & 3) ||
|
|
|
|
((desc->next & PAGE_MASK) + sizeof *desc) > PAGE_SIZE) {
|
|
|
|
epic_free_rings(sc);
|
2003-04-19 17:24:07 +00:00
|
|
|
return (EFAULT);
|
2002-10-22 00:57:51 +00:00
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
buf->mbuf = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
|
2003-04-20 18:08:00 +00:00
|
|
|
if (buf->mbuf == NULL) {
|
1998-07-04 08:02:46 +00:00
|
|
|
epic_free_rings(sc);
|
2003-04-19 17:24:07 +00:00
|
|
|
return (ENOBUFS);
|
1998-07-04 08:02:46 +00:00
|
|
|
}
|
2002-10-25 22:06:03 +00:00
|
|
|
buf->mbuf->m_len = buf->mbuf->m_pkthdr.len = MCLBYTES;
|
|
|
|
m_adj(buf->mbuf, ETHER_ALIGN);
|
1998-02-04 15:04:09 +00:00
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
error = bus_dmamap_create(sc->mtag, 0, &buf->map);
|
|
|
|
if (error) {
|
|
|
|
epic_free_rings(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
error = bus_dmamap_load_mbuf(sc->mtag, buf->map, buf->mbuf,
|
|
|
|
epic_dma_map_rxbuf, desc, 0);
|
|
|
|
if (error) {
|
|
|
|
epic_free_rings(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(sc->mtag, buf->map, BUS_DMASYNC_PREREAD);
|
|
|
|
|
|
|
|
desc->buflength = buf->mbuf->m_len; /* Max RX buffer length */
|
2001-08-13 18:32:39 +00:00
|
|
|
desc->status = 0x8000; /* Set owner bit to NIC */
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->rtag, sc->rmap,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
/* Create the spare DMA map. */
|
|
|
|
error = bus_dmamap_create(sc->mtag, 0, &sc->sparemap);
|
|
|
|
if (error) {
|
|
|
|
epic_free_rings(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-20 18:08:00 +00:00
|
|
|
/* Initialize the TX descriptor ring. */
|
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;
|
2003-04-20 18:08:00 +00:00
|
|
|
desc->next = sc->tx_addr +
|
|
|
|
((i + 1) & TX_RING_MASK) * sizeof(struct epic_tx_desc);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
if ((desc->next & 3) ||
|
|
|
|
((desc->next & PAGE_MASK) + sizeof *desc) > PAGE_SIZE) {
|
|
|
|
epic_free_rings(sc);
|
2003-04-19 17:24:07 +00:00
|
|
|
return (EFAULT);
|
2002-10-22 00:57:51 +00:00
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-02-04 15:04:09 +00:00
|
|
|
buf->mbuf = NULL;
|
2003-04-20 18:08:00 +00:00
|
|
|
desc->bufaddr = sc->frag_addr +
|
|
|
|
i * sizeof(struct epic_frag_list);
|
2002-10-22 00:57:51 +00:00
|
|
|
|
|
|
|
if ((desc->bufaddr & 3) ||
|
2003-04-19 17:24:07 +00:00
|
|
|
((desc->bufaddr & PAGE_MASK) +
|
|
|
|
sizeof(struct epic_frag_list)) > PAGE_SIZE) {
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_free_rings(sc);
|
2003-04-19 17:24:07 +00:00
|
|
|
return (EFAULT);
|
2002-10-22 00:57:51 +00:00
|
|
|
}
|
2003-04-20 18:08:00 +00:00
|
|
|
|
|
|
|
error = bus_dmamap_create(sc->mtag, 0, &buf->map);
|
|
|
|
if (error) {
|
|
|
|
epic_free_rings(sc);
|
|
|
|
return (error);
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
2003-04-20 18:08:00 +00:00
|
|
|
bus_dmamap_sync(sc->ttag, sc->tmap,
|
|
|
|
BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
|
|
|
|
bus_dmamap_sync(sc->ftag, sc->fmap, BUS_DMASYNC_PREWRITE);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_write_eepromreg(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;
|
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
CSR_WRITE_1(sc, EECTL, val);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-20 17:36:26 +00:00
|
|
|
for (i = 0; i < 0xFF; i++) {
|
2003-04-19 17:24:07 +00:00
|
|
|
if ((CSR_READ_1(sc, EECTL) & 0x20) == 0)
|
|
|
|
break;
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static u_int8_t
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_read_eepromreg(epic_softc_t *sc)
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
2003-04-19 17:24:07 +00:00
|
|
|
|
|
|
|
return (CSR_READ_1(sc, EECTL));
|
2002-10-22 00:57:51 +00:00
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static u_int8_t
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_eeprom_clock(epic_softc_t *sc, u_int8_t val)
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
2003-04-19 17:24:07 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_write_eepromreg(sc, val);
|
|
|
|
epic_write_eepromreg(sc, (val | 0x4));
|
|
|
|
epic_write_eepromreg(sc, val);
|
2003-04-19 17:24:07 +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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_output_eepromw(epic_softc_t *sc, u_int16_t val)
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
2002-10-22 00:57:51 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0xF; i >= 0; i--) {
|
|
|
|
if (val & (1 << i))
|
|
|
|
epic_eeprom_clock(sc, 0x0B);
|
|
|
|
else
|
|
|
|
epic_eeprom_clock(sc, 0x03);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static u_int16_t
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_input_eepromw(epic_softc_t *sc)
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
u_int16_t retval = 0;
|
2002-10-22 00:57:51 +00:00
|
|
|
int i;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
for (i = 0xF; i >= 0; i--) {
|
2002-10-22 00:57:51 +00:00
|
|
|
if (epic_eeprom_clock(sc, 0x3) & 0x10)
|
1998-01-21 18:33:00 +00:00
|
|
|
retval |= (1 << i);
|
|
|
|
}
|
2002-10-22 00:57:51 +00:00
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
return (retval);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
1998-07-04 08:02:46 +00:00
|
|
|
static int
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_read_eeprom(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;
|
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_write_eepromreg(sc, 3);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
if (epic_read_eepromreg(sc) & 0x40)
|
|
|
|
read_cmd = (loc & 0x3F) | 0x180;
|
1998-01-21 18:33:00 +00:00
|
|
|
else
|
2002-10-22 00:57:51 +00:00
|
|
|
read_cmd = (loc & 0xFF) | 0x600;
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_output_eepromw(sc, read_cmd);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
dataval = epic_input_eepromw(sc);
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
epic_write_eepromreg(sc, 1);
|
2003-04-19 17:24:07 +00:00
|
|
|
|
|
|
|
return (dataval);
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
/*
|
2003-04-19 17:24:07 +00:00
|
|
|
* Here goes MII read/write routines.
|
2000-04-12 06:51:43 +00:00
|
|
|
*/
|
|
|
|
static int
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_read_phy_reg(epic_softc_t *sc, int phy, int reg)
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
int i;
|
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
CSR_WRITE_4(sc, MIICTL, ((reg << 4) | (phy << 9) | 0x01));
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +00:00
|
|
|
for (i = 0; i < 0x100; i++) {
|
2003-04-19 17:24:07 +00:00
|
|
|
if ((CSR_READ_4(sc, MIICTL) & 0x01) == 0)
|
|
|
|
break;
|
1999-03-14 08:30:23 +00:00
|
|
|
DELAY(1);
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
|
2002-10-22 00:57:51 +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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_write_phy_reg(epic_softc_t *sc, int phy, int reg, int val)
|
1998-04-13 14:15:40 +00:00
|
|
|
{
|
1998-01-21 18:33:00 +00:00
|
|
|
int i;
|
|
|
|
|
2002-10-22 00:57:51 +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
|
|
|
|
2003-04-19 17:24:07 +00:00
|
|
|
for(i = 0; i < 0x100; i++) {
|
|
|
|
if ((CSR_READ_4(sc, MIICTL) & 0x02) == 0)
|
|
|
|
break;
|
1999-03-14 08:30:23 +00:00
|
|
|
DELAY(1);
|
|
|
|
}
|
1998-01-21 18:33:00 +00:00
|
|
|
}
|
1998-02-01 20:25:16 +00:00
|
|
|
|
2000-04-12 06:51:43 +00:00
|
|
|
static int
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_miibus_readreg(device_t dev, int phy, int 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
|
2006-01-21 20:07:19 +00:00
|
|
|
epic_miibus_writereg(device_t dev, int phy, int reg, int data)
|
2000-04-12 06:51:43 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|