2003-11-08 19:08:13 +03:00
|
|
|
/* $NetBSD: smc83c170.c,v 1.55 2003/11/08 16:08:13 tsutsui Exp $ */
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*-
|
1999-02-12 08:55:27 +03:00
|
|
|
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
|
1998-06-02 05:29:41 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device driver for the Standard Microsystems Corp. 83C170
|
|
|
|
* Ethernet PCI Integrated Controller (EPIC/100).
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-11-08 19:08:13 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: smc83c170.c,v 1.55 2003/11/08 16:08:13 tsutsui Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1998-06-02 05:29:41 +04:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/device.h>
|
2000-11-14 21:21:00 +03:00
|
|
|
|
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
1998-08-11 04:12:52 +04:00
|
|
|
#include <dev/mii/miivar.h>
|
2001-05-17 21:32:47 +04:00
|
|
|
#include <dev/mii/lxtphyreg.h>
|
1998-08-11 04:12:52 +04:00
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
#include <dev/ic/smc83c170reg.h>
|
|
|
|
#include <dev/ic/smc83c170var.h>
|
|
|
|
|
|
|
|
void epic_start __P((struct ifnet *));
|
|
|
|
void epic_watchdog __P((struct ifnet *));
|
|
|
|
int epic_ioctl __P((struct ifnet *, u_long, caddr_t));
|
2000-10-11 20:57:45 +04:00
|
|
|
int epic_init __P((struct ifnet *));
|
|
|
|
void epic_stop __P((struct ifnet *, int));
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
void epic_shutdown __P((void *));
|
|
|
|
|
|
|
|
void epic_reset __P((struct epic_softc *));
|
1999-08-03 21:25:51 +04:00
|
|
|
void epic_rxdrain __P((struct epic_softc *));
|
1998-06-02 05:29:41 +04:00
|
|
|
int epic_add_rxbuf __P((struct epic_softc *, int));
|
|
|
|
void epic_read_eeprom __P((struct epic_softc *, int, int, u_int16_t *));
|
|
|
|
void epic_set_mchash __P((struct epic_softc *));
|
1998-07-23 21:37:38 +04:00
|
|
|
void epic_fixup_clock_source __P((struct epic_softc *));
|
1998-08-11 04:12:52 +04:00
|
|
|
int epic_mii_read __P((struct device *, int, int));
|
|
|
|
void epic_mii_write __P((struct device *, int, int, int));
|
|
|
|
int epic_mii_wait __P((struct epic_softc *, u_int32_t));
|
|
|
|
void epic_tick __P((void *));
|
|
|
|
|
|
|
|
void epic_statchg __P((struct device *));
|
|
|
|
int epic_mediachange __P((struct ifnet *));
|
|
|
|
void epic_mediastatus __P((struct ifnet *, struct ifmediareq *));
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
#define INTMASK (INTSTAT_FATAL_INT | INTSTAT_TXU | \
|
1999-08-27 23:13:00 +04:00
|
|
|
INTSTAT_TXC | INTSTAT_RXE | INTSTAT_RQE | INTSTAT_RCC)
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-08-03 21:25:51 +04:00
|
|
|
int epic_copy_small = 0;
|
|
|
|
|
2003-01-13 20:00:18 +03:00
|
|
|
#define ETHER_PAD_LEN (ETHER_MIN_LEN - ETHER_CRC_LEN)
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
|
|
|
* Attach an EPIC interface to the system.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_attach(sc)
|
|
|
|
struct epic_softc *sc;
|
|
|
|
{
|
|
|
|
bus_space_tag_t st = sc->sc_st;
|
|
|
|
bus_space_handle_t sh = sc->sc_sh;
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
2002-11-07 10:46:39 +03:00
|
|
|
int rseg, error, miiflags;
|
|
|
|
u_int i;
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_dma_segment_t seg;
|
|
|
|
u_int8_t enaddr[ETHER_ADDR_LEN], devname[12 + 1];
|
|
|
|
u_int16_t myea[ETHER_ADDR_LEN / 2], mydevname[6];
|
2003-01-13 20:00:18 +03:00
|
|
|
char *nullbuf;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_init(&sc->sc_mii_callout);
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
|
|
|
* Allocate the control data structures, and create and load the
|
|
|
|
* DMA map for it.
|
|
|
|
*/
|
|
|
|
if ((error = bus_dmamem_alloc(sc->sc_dmat,
|
2003-01-13 20:00:18 +03:00
|
|
|
sizeof(struct epic_control_data) + ETHER_PAD_LEN, PAGE_SIZE, 0,
|
|
|
|
&seg, 1, &rseg, BUS_DMA_NOWAIT)) != 0) {
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_error(
|
|
|
|
"%s: unable to allocate control data, error = %d\n",
|
1998-06-02 05:29:41 +04:00
|
|
|
sc->sc_dev.dv_xname, error);
|
1999-02-18 05:24:30 +03:00
|
|
|
goto fail_0;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,
|
2003-01-13 20:00:18 +03:00
|
|
|
sizeof(struct epic_control_data) + ETHER_PAD_LEN,
|
|
|
|
(caddr_t *)&sc->sc_control_data,
|
1998-06-02 05:29:41 +04:00
|
|
|
BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) != 0) {
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_error("%s: unable to map control data, error = %d\n",
|
1998-06-02 05:29:41 +04:00
|
|
|
sc->sc_dev.dv_xname, error);
|
1999-02-18 05:24:30 +03:00
|
|
|
goto fail_1;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
2003-01-13 20:00:18 +03:00
|
|
|
nullbuf =
|
|
|
|
(char *)sc->sc_control_data + sizeof(struct epic_control_data);
|
|
|
|
memset(nullbuf, 0, ETHER_PAD_LEN);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat,
|
|
|
|
sizeof(struct epic_control_data), 1,
|
|
|
|
sizeof(struct epic_control_data), 0, BUS_DMA_NOWAIT,
|
|
|
|
&sc->sc_cddmamap)) != 0) {
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_error("%s: unable to create control data DMA map, "
|
1998-06-02 05:29:41 +04:00
|
|
|
"error = %d\n", sc->sc_dev.dv_xname, error);
|
1999-02-18 05:24:30 +03:00
|
|
|
goto fail_2;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cddmamap,
|
|
|
|
sc->sc_control_data, sizeof(struct epic_control_data), NULL,
|
|
|
|
BUS_DMA_NOWAIT)) != 0) {
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_error(
|
|
|
|
"%s: unable to load control data DMA map, error = %d\n",
|
1998-06-02 05:29:41 +04:00
|
|
|
sc->sc_dev.dv_xname, error);
|
1999-02-18 05:24:30 +03:00
|
|
|
goto fail_3;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the transmit buffer DMA maps.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < EPIC_NTXDESC; i++) {
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES,
|
|
|
|
EPIC_NFRAGS, MCLBYTES, 0, BUS_DMA_NOWAIT,
|
1999-02-12 08:55:27 +03:00
|
|
|
&EPIC_DSTX(sc, i)->ds_dmamap)) != 0) {
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_error("%s: unable to create tx DMA map %d, "
|
1998-06-02 05:29:41 +04:00
|
|
|
"error = %d\n", sc->sc_dev.dv_xname, i, error);
|
1999-02-18 05:24:30 +03:00
|
|
|
goto fail_4;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-03-15 16:45:00 +03:00
|
|
|
* Create the receive buffer DMA maps.
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
|
|
|
for (i = 0; i < EPIC_NRXDESC; i++) {
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
|
|
|
|
MCLBYTES, 0, BUS_DMA_NOWAIT,
|
1999-02-12 08:55:27 +03:00
|
|
|
&EPIC_DSRX(sc, i)->ds_dmamap)) != 0) {
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_error("%s: unable to create rx DMA map %d, "
|
1998-06-02 05:29:41 +04:00
|
|
|
"error = %d\n", sc->sc_dev.dv_xname, i, error);
|
1999-02-18 05:24:30 +03:00
|
|
|
goto fail_5;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
1999-08-03 21:25:51 +04:00
|
|
|
EPIC_DSRX(sc, i)->ds_mbuf = NULL;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
2003-01-13 20:00:18 +03:00
|
|
|
/*
|
|
|
|
* create and map the pad buffer
|
|
|
|
*/
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, ETHER_PAD_LEN, 1,
|
|
|
|
ETHER_PAD_LEN, 0, BUS_DMA_NOWAIT,&sc->sc_nulldmamap)) != 0) {
|
|
|
|
printf("%s: unable to create pad buffer DMA map, "
|
|
|
|
"error = %d\n", sc->sc_dev.dv_xname, error);
|
|
|
|
goto fail_5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_nulldmamap,
|
|
|
|
nullbuf, ETHER_PAD_LEN, NULL, BUS_DMA_NOWAIT)) != 0) {
|
|
|
|
printf("%s: unable to load pad buffer DMA map, "
|
|
|
|
"error = %d\n", sc->sc_dev.dv_xname, error);
|
|
|
|
goto fail_6;
|
|
|
|
}
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, sc->sc_nulldmamap, 0, ETHER_PAD_LEN,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bring the chip out of low-power mode and reset it to a known state.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, EPIC_GENCTL, 0);
|
|
|
|
epic_reset(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the Ethernet address from the EEPROM.
|
|
|
|
*/
|
|
|
|
epic_read_eeprom(sc, 0, (sizeof(myea) / sizeof(myea[0])), myea);
|
2000-05-26 04:14:41 +04:00
|
|
|
for (i = 0; i < sizeof(myea)/ sizeof(myea[0]); i++) {
|
|
|
|
enaddr[i * 2] = myea[i] & 0xff;
|
|
|
|
enaddr[i * 2 + 1] = myea[i] >> 8;
|
|
|
|
}
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ...and the device name.
|
|
|
|
*/
|
|
|
|
epic_read_eeprom(sc, 0x2c, (sizeof(mydevname) / sizeof(mydevname[0])),
|
|
|
|
mydevname);
|
2000-05-26 04:14:41 +04:00
|
|
|
for (i = 0; i < sizeof(mydevname) / sizeof(mydevname[0]); i++) {
|
|
|
|
devname[i * 2] = mydevname[i] & 0xff;
|
|
|
|
devname[i * 2 + 1] = mydevname[i] >> 8;
|
|
|
|
}
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
devname[sizeof(mydevname)] = '\0';
|
|
|
|
for (i = sizeof(mydevname) - 1; i >= 0; i--) {
|
|
|
|
if (devname[i] == ' ')
|
|
|
|
devname[i] = '\0';
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_normal("%s: %s, Ethernet address %s\n", sc->sc_dev.dv_xname,
|
1998-06-02 05:29:41 +04:00
|
|
|
devname, ether_sprintf(enaddr));
|
|
|
|
|
2001-05-17 21:32:47 +04:00
|
|
|
miiflags = 0;
|
|
|
|
if (sc->sc_hwflags & EPIC_HAS_MII_FIBER)
|
|
|
|
miiflags |= MIIF_HAVEFIBER;
|
|
|
|
|
1998-08-11 04:12:52 +04:00
|
|
|
/*
|
|
|
|
* Initialize our media structures and probe the MII.
|
|
|
|
*/
|
|
|
|
sc->sc_mii.mii_ifp = ifp;
|
|
|
|
sc->sc_mii.mii_readreg = epic_mii_read;
|
|
|
|
sc->sc_mii.mii_writereg = epic_mii_write;
|
|
|
|
sc->sc_mii.mii_statchg = epic_statchg;
|
2002-10-22 04:01:55 +04:00
|
|
|
ifmedia_init(&sc->sc_mii.mii_media, IFM_IMASK, epic_mediachange,
|
1998-08-11 04:12:52 +04:00
|
|
|
epic_mediastatus);
|
2000-02-02 11:05:26 +03:00
|
|
|
mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
|
2001-05-17 21:32:47 +04:00
|
|
|
MII_OFFSET_ANY, miiflags);
|
1998-08-11 04:12:52 +04:00
|
|
|
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);
|
|
|
|
|
2001-05-17 21:32:47 +04:00
|
|
|
if (sc->sc_hwflags & EPIC_HAS_BNC) {
|
|
|
|
/* use the next free media instance */
|
|
|
|
sc->sc_serinst = sc->sc_mii.mii_instance++;
|
|
|
|
ifmedia_add(&sc->sc_mii.mii_media,
|
|
|
|
IFM_MAKEWORD(IFM_ETHER, IFM_10_2, 0,
|
|
|
|
sc->sc_serinst),
|
|
|
|
0, NULL);
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_normal("%s: 10base2/BNC\n", sc->sc_dev.dv_xname);
|
2001-05-17 21:32:47 +04:00
|
|
|
} else
|
|
|
|
sc->sc_serinst = -1;
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
|
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_ioctl = epic_ioctl;
|
|
|
|
ifp->if_start = epic_start;
|
|
|
|
ifp->if_watchdog = epic_watchdog;
|
2000-10-11 20:57:45 +04:00
|
|
|
ifp->if_init = epic_init;
|
|
|
|
ifp->if_stop = epic_stop;
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
2000-10-18 20:49:13 +04:00
|
|
|
/*
|
|
|
|
* We can support 802.1Q VLAN-sized frames.
|
|
|
|
*/
|
|
|
|
sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
|
|
|
* Attach the interface.
|
|
|
|
*/
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, enaddr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the interface is shutdown during reboot.
|
|
|
|
*/
|
|
|
|
sc->sc_sdhook = shutdownhook_establish(epic_shutdown, sc);
|
|
|
|
if (sc->sc_sdhook == NULL)
|
2003-01-31 03:26:25 +03:00
|
|
|
aprint_error("%s: WARNING: unable to establish shutdown hook\n",
|
1998-06-02 05:29:41 +04:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free any resources we've allocated during the failed attach
|
|
|
|
* attempt. Do this in reverse order and fall through.
|
|
|
|
*/
|
2003-01-13 20:00:18 +03:00
|
|
|
fail_6:
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_nulldmamap);
|
1999-02-18 05:24:30 +03:00
|
|
|
fail_5:
|
|
|
|
for (i = 0; i < EPIC_NRXDESC; i++) {
|
|
|
|
if (EPIC_DSRX(sc, i)->ds_dmamap != NULL)
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_dmamap_destroy(sc->sc_dmat,
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_DSRX(sc, i)->ds_dmamap);
|
1999-02-18 05:24:30 +03:00
|
|
|
}
|
|
|
|
fail_4:
|
|
|
|
for (i = 0; i < EPIC_NTXDESC; i++) {
|
|
|
|
if (EPIC_DSTX(sc, i)->ds_dmamap != NULL)
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_dmamap_destroy(sc->sc_dmat,
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_DSTX(sc, i)->ds_dmamap);
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
1999-02-18 05:24:30 +03:00
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_cddmamap);
|
|
|
|
fail_3:
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_cddmamap);
|
|
|
|
fail_2:
|
|
|
|
bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->sc_control_data,
|
|
|
|
sizeof(struct epic_control_data));
|
|
|
|
fail_1:
|
|
|
|
bus_dmamem_free(sc->sc_dmat, &seg, rseg);
|
|
|
|
fail_0:
|
|
|
|
return;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shutdown hook. Make sure the interface is stopped at reboot.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_shutdown(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct epic_softc *sc = arg;
|
|
|
|
|
2000-10-11 20:57:45 +04:00
|
|
|
epic_stop(&sc->sc_ethercom.ec_if, 1);
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start packet transmission on the interface.
|
|
|
|
* [ifnet interface function]
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_start(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct epic_softc *sc = ifp->if_softc;
|
1999-02-12 08:55:27 +03:00
|
|
|
struct mbuf *m0, *m;
|
1998-06-02 05:29:41 +04:00
|
|
|
struct epic_txdesc *txd;
|
|
|
|
struct epic_descsoft *ds;
|
|
|
|
struct epic_fraglist *fr;
|
|
|
|
bus_dmamap_t dmamap;
|
1999-02-12 08:55:27 +03:00
|
|
|
int error, firsttx, nexttx, opending, seg;
|
2003-11-08 19:08:13 +03:00
|
|
|
u_int len;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
/*
|
|
|
|
* Remember the previous txpending and the first transmit
|
|
|
|
* descriptor we use.
|
|
|
|
*/
|
|
|
|
opending = sc->sc_txpending;
|
|
|
|
firsttx = EPIC_NEXTTX(sc->sc_txlast);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through the send queue, setting up transmit descriptors
|
|
|
|
* until we drain the queue, or use up all available transmit
|
|
|
|
* descriptors.
|
|
|
|
*/
|
1999-02-12 08:55:27 +03:00
|
|
|
while (sc->sc_txpending < EPIC_NTXDESC) {
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
|
|
|
* Grab a packet off the queue.
|
|
|
|
*/
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_POLL(&ifp->if_snd, m0);
|
1999-02-12 08:55:27 +03:00
|
|
|
if (m0 == NULL)
|
|
|
|
break;
|
2000-12-19 03:06:01 +03:00
|
|
|
m = NULL;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the last and next available transmit descriptor.
|
|
|
|
*/
|
|
|
|
nexttx = EPIC_NEXTTX(sc->sc_txlast);
|
1999-02-12 08:55:27 +03:00
|
|
|
txd = EPIC_CDTX(sc, nexttx);
|
|
|
|
fr = EPIC_CDFL(sc, nexttx);
|
|
|
|
ds = EPIC_DSTX(sc, nexttx);
|
1998-06-02 05:29:41 +04:00
|
|
|
dmamap = ds->ds_dmamap;
|
|
|
|
|
|
|
|
/*
|
1999-02-12 08:55:27 +03:00
|
|
|
* Load the DMA map. If this fails, the packet either
|
|
|
|
* didn't fit in the alloted number of frags, or we were
|
|
|
|
* short on resources. In this case, we'll copy and try
|
|
|
|
* again.
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
2003-01-13 20:00:18 +03:00
|
|
|
if ((error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, m0,
|
|
|
|
BUS_DMA_WRITE|BUS_DMA_NOWAIT)) != 0 ||
|
|
|
|
(m0->m_pkthdr.len < ETHER_PAD_LEN &&
|
|
|
|
dmamap-> dm_nsegs == EPIC_NFRAGS)) {
|
|
|
|
if (error == 0)
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, dmamap);
|
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL) {
|
|
|
|
printf("%s: unable to allocate Tx mbuf\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
break;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
if (m0->m_pkthdr.len > MHLEN) {
|
1999-02-12 08:55:27 +03:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
printf("%s: unable to allocate Tx "
|
|
|
|
"cluster\n", sc->sc_dev.dv_xname);
|
|
|
|
m_freem(m);
|
|
|
|
break;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
}
|
1999-02-12 08:55:27 +03:00
|
|
|
m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, caddr_t));
|
|
|
|
m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len;
|
|
|
|
error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap,
|
2001-07-19 20:25:23 +04:00
|
|
|
m, BUS_DMA_WRITE|BUS_DMA_NOWAIT);
|
1999-02-12 08:55:27 +03:00
|
|
|
if (error) {
|
|
|
|
printf("%s: unable to load Tx buffer, "
|
|
|
|
"error = %d\n", sc->sc_dev.dv_xname, error);
|
|
|
|
break;
|
|
|
|
}
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m0);
|
2000-12-19 03:06:01 +03:00
|
|
|
if (m != NULL) {
|
|
|
|
m_freem(m0);
|
|
|
|
m0 = m;
|
|
|
|
}
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
/* Initialize the fraglist. */
|
1998-06-02 05:29:41 +04:00
|
|
|
for (seg = 0; seg < dmamap->dm_nsegs; seg++) {
|
|
|
|
fr->ef_frags[seg].ef_addr =
|
|
|
|
dmamap->dm_segs[seg].ds_addr;
|
|
|
|
fr->ef_frags[seg].ef_length =
|
|
|
|
dmamap->dm_segs[seg].ds_len;
|
|
|
|
}
|
2003-11-08 19:08:13 +03:00
|
|
|
len = m0->m_pkthdr.len;
|
|
|
|
if (len < ETHER_PAD_LEN) {
|
2003-01-13 20:00:18 +03:00
|
|
|
fr->ef_frags[seg].ef_addr = sc->sc_nulldma;
|
2003-11-08 19:08:13 +03:00
|
|
|
fr->ef_frags[seg].ef_length = ETHER_PAD_LEN - len;
|
|
|
|
len = ETHER_PAD_LEN;
|
2003-01-13 20:00:18 +03:00
|
|
|
seg++;
|
|
|
|
}
|
|
|
|
fr->ef_nfrags = seg;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_CDFLSYNC(sc, nexttx, BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
/* Sync the DMA map. */
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store a pointer to the packet so we can free it later.
|
|
|
|
*/
|
|
|
|
ds->ds_mbuf = m0;
|
|
|
|
|
|
|
|
/*
|
2003-01-13 20:00:18 +03:00
|
|
|
* Fill in the transmit descriptor.
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
1999-02-12 08:55:27 +03:00
|
|
|
txd->et_control = ET_TXCTL_LASTDESC | ET_TXCTL_FRAGLIST;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
1999-02-12 08:55:27 +03:00
|
|
|
* If this is the first descriptor we're enqueueing,
|
|
|
|
* don't give it to the EPIC yet. That could cause
|
|
|
|
* a race condition. We'll do it below.
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
1999-02-12 08:55:27 +03:00
|
|
|
if (nexttx == firsttx)
|
2003-11-08 19:08:13 +03:00
|
|
|
txd->et_txstatus = TXSTAT_TXLENGTH(len);
|
1999-02-12 08:55:27 +03:00
|
|
|
else
|
2003-11-08 19:08:13 +03:00
|
|
|
txd->et_txstatus =
|
|
|
|
TXSTAT_TXLENGTH(len) | ET_TXSTAT_OWNER;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_CDTXSYNC(sc, nexttx,
|
|
|
|
BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
/* Advance the tx pointer. */
|
|
|
|
sc->sc_txpending++;
|
|
|
|
sc->sc_txlast = nexttx;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* Pass the packet to any BPF listeners.
|
|
|
|
*/
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
if (sc->sc_txpending == EPIC_NTXDESC) {
|
|
|
|
/* No more slots left; notify upper layer. */
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_txpending != opending) {
|
|
|
|
/*
|
|
|
|
* We enqueued packets. If the transmitter was idle,
|
|
|
|
* reset the txdirty pointer.
|
|
|
|
*/
|
|
|
|
if (opending == 0)
|
|
|
|
sc->sc_txdirty = firsttx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cause a transmit interrupt to happen on the
|
|
|
|
* last packet we enqueued.
|
|
|
|
*/
|
|
|
|
EPIC_CDTX(sc, sc->sc_txlast)->et_control |= ET_TXCTL_IAF;
|
|
|
|
EPIC_CDTXSYNC(sc, sc->sc_txlast,
|
|
|
|
BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
1999-02-12 08:55:27 +03:00
|
|
|
* The entire packet chain is set up. Give the
|
|
|
|
* first descriptor to the EPIC now.
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
2003-11-08 19:08:13 +03:00
|
|
|
EPIC_CDTX(sc, firsttx)->et_txstatus |= ET_TXSTAT_OWNER;
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_CDTXSYNC(sc, firsttx,
|
|
|
|
BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
/* Start the transmitter. */
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_COMMAND,
|
|
|
|
COMMAND_TXQUEUED);
|
|
|
|
|
|
|
|
/* Set a watchdog timer in case the chip flakes out. */
|
1998-06-02 05:29:41 +04:00
|
|
|
ifp->if_timer = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Watchdog timer handler.
|
|
|
|
* [ifnet interface function]
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_watchdog(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct epic_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
printf("%s: device timeout\n", sc->sc_dev.dv_xname);
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
|
2000-10-11 20:57:45 +04:00
|
|
|
(void) epic_init(ifp);
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle control requests from the operator.
|
|
|
|
* [ifnet interface function]
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
epic_ioctl(ifp, cmd, data)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
|
|
|
struct epic_softc *sc = ifp->if_softc;
|
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
2000-10-11 20:57:45 +04:00
|
|
|
int s, error;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1998-08-09 03:51:39 +04:00
|
|
|
s = splnet();
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
2000-10-11 20:57:45 +04:00
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->sc_mii.mii_media, cmd);
|
1998-06-02 05:29:41 +04:00
|
|
|
break;
|
|
|
|
|
2000-10-11 20:57:45 +04:00
|
|
|
default:
|
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
1998-06-02 05:29:41 +04:00
|
|
|
if (error == ENETRESET) {
|
|
|
|
/*
|
|
|
|
* Multicast list has changed; set the hardware filter
|
1999-02-18 05:12:09 +03:00
|
|
|
* accordingly. Update our idea of the current media;
|
|
|
|
* epic_set_mchash() needs to know what it is.
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
1999-02-18 05:12:09 +03:00
|
|
|
mii_pollstat(&sc->sc_mii);
|
|
|
|
epic_set_mchash(sc);
|
1998-06-02 05:29:41 +04:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt handler.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
epic_intr(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct epic_softc *sc = arg;
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct epic_rxdesc *rxd;
|
|
|
|
struct epic_txdesc *txd;
|
|
|
|
struct epic_descsoft *ds;
|
|
|
|
struct mbuf *m;
|
2003-11-08 19:08:13 +03:00
|
|
|
u_int32_t intstat, rxstatus, txstatus;
|
2002-11-07 10:46:39 +03:00
|
|
|
int i, claimed = 0;
|
|
|
|
u_int len;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
top:
|
|
|
|
/*
|
|
|
|
* Get the interrupt status from the EPIC.
|
|
|
|
*/
|
|
|
|
intstat = bus_space_read_4(sc->sc_st, sc->sc_sh, EPIC_INTSTAT);
|
|
|
|
if ((intstat & INTSTAT_INT_ACTV) == 0)
|
|
|
|
return (claimed);
|
|
|
|
|
|
|
|
claimed = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Acknowledge the interrupt.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_INTSTAT,
|
|
|
|
intstat & INTMASK);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for receive interrupts.
|
|
|
|
*/
|
1999-08-27 23:13:00 +04:00
|
|
|
if (intstat & (INTSTAT_RCC | INTSTAT_RXE | INTSTAT_RQE)) {
|
1998-06-02 05:29:41 +04:00
|
|
|
for (i = sc->sc_rxptr;; i = EPIC_NEXTRX(i)) {
|
1999-02-12 08:55:27 +03:00
|
|
|
rxd = EPIC_CDRX(sc, i);
|
|
|
|
ds = EPIC_DSRX(sc, i);
|
|
|
|
|
|
|
|
EPIC_CDRXSYNC(sc, i,
|
|
|
|
BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
2003-11-08 19:08:13 +03:00
|
|
|
rxstatus = rxd->er_rxstatus;
|
|
|
|
if (rxstatus & ER_RXSTAT_OWNER) {
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
|
|
|
* We have processed all of the
|
|
|
|
* receive buffers.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-02-12 08:55:27 +03:00
|
|
|
* Make sure the packet arrived intact. If an error
|
|
|
|
* occurred, update stats and reset the descriptor.
|
|
|
|
* The buffer will be reused the next time the
|
|
|
|
* descriptor comes up in the ring.
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
2003-11-08 19:08:13 +03:00
|
|
|
if ((rxstatus & ER_RXSTAT_PKTINTACT) == 0) {
|
|
|
|
if (rxstatus & ER_RXSTAT_CRCERROR)
|
1998-06-02 05:29:41 +04:00
|
|
|
printf("%s: CRC error\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
2003-11-08 19:08:13 +03:00
|
|
|
if (rxstatus & ER_RXSTAT_ALIGNERROR)
|
1998-06-02 05:29:41 +04:00
|
|
|
printf("%s: alignment error\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
ifp->if_ierrors++;
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_INIT_RXDESC(sc, i);
|
|
|
|
continue;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
|
|
|
|
ds->ds_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
|
|
|
|
|
1999-08-27 23:13:00 +04:00
|
|
|
/*
|
2000-10-15 23:56:31 +04:00
|
|
|
* The EPIC includes the CRC with every packet.
|
1999-08-27 23:13:00 +04:00
|
|
|
*/
|
2003-11-08 19:08:13 +03:00
|
|
|
len = RXSTAT_RXLENGTH(rxstatus);
|
1999-08-27 23:13:00 +04:00
|
|
|
|
1999-08-03 21:25:51 +04:00
|
|
|
if (len < sizeof(struct ether_header)) {
|
|
|
|
/*
|
|
|
|
* Runt packet; drop it now.
|
|
|
|
*/
|
1999-02-12 08:55:27 +03:00
|
|
|
ifp->if_ierrors++;
|
|
|
|
EPIC_INIT_RXDESC(sc, i);
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
|
|
|
|
ds->ds_dmamap->dm_mapsize,
|
|
|
|
BUS_DMASYNC_PREREAD);
|
|
|
|
continue;
|
|
|
|
}
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-08-03 21:25:51 +04:00
|
|
|
/*
|
|
|
|
* If the packet is small enough to fit in a
|
|
|
|
* single header mbuf, allocate one and copy
|
|
|
|
* the data into it. This greatly reduces
|
|
|
|
* memory consumption when we receive lots
|
|
|
|
* of small packets.
|
|
|
|
*
|
|
|
|
* Otherwise, we add a new buffer to the receive
|
|
|
|
* chain. If this fails, we drop the packet and
|
|
|
|
* recycle the old buffer.
|
|
|
|
*/
|
|
|
|
if (epic_copy_small != 0 && len <= MHLEN) {
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == NULL)
|
|
|
|
goto dropit;
|
|
|
|
memcpy(mtod(m, caddr_t),
|
|
|
|
mtod(ds->ds_mbuf, caddr_t), len);
|
|
|
|
EPIC_INIT_RXDESC(sc, i);
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
|
|
|
|
ds->ds_dmamap->dm_mapsize,
|
|
|
|
BUS_DMASYNC_PREREAD);
|
|
|
|
} else {
|
|
|
|
m = ds->ds_mbuf;
|
|
|
|
if (epic_add_rxbuf(sc, i) != 0) {
|
|
|
|
dropit:
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
EPIC_INIT_RXDESC(sc, i);
|
|
|
|
bus_dmamap_sync(sc->sc_dmat,
|
|
|
|
ds->ds_dmamap, 0,
|
|
|
|
ds->ds_dmamap->dm_mapsize,
|
|
|
|
BUS_DMASYNC_PREREAD);
|
|
|
|
continue;
|
|
|
|
}
|
1999-02-12 08:55:27 +03:00
|
|
|
}
|
|
|
|
|
2000-10-15 23:56:31 +04:00
|
|
|
m->m_flags |= M_HASFCS;
|
1999-02-12 08:55:27 +03:00
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = m->m_len = len;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
1999-02-12 08:55:27 +03:00
|
|
|
/*
|
|
|
|
* Pass this up to any BPF listeners, but only
|
|
|
|
* pass it up the stack if its for us.
|
|
|
|
*/
|
2000-10-02 03:32:39 +04:00
|
|
|
if (ifp->if_bpf)
|
1999-02-12 08:55:27 +03:00
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
2000-10-02 03:32:39 +04:00
|
|
|
#endif
|
|
|
|
|
1999-05-19 03:52:51 +04:00
|
|
|
/* Pass it on. */
|
|
|
|
(*ifp->if_input)(ifp, m);
|
1999-06-18 21:44:06 +04:00
|
|
|
ifp->if_ipackets++;
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
1999-02-12 08:55:27 +03:00
|
|
|
|
2001-03-15 16:45:00 +03:00
|
|
|
/* Update the receive pointer. */
|
1998-06-02 05:29:41 +04:00
|
|
|
sc->sc_rxptr = i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for receive queue underflow.
|
|
|
|
*/
|
|
|
|
if (intstat & INTSTAT_RQE) {
|
|
|
|
printf("%s: receiver queue empty\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
/*
|
|
|
|
* Ring is already built; just restart the
|
|
|
|
* receiver.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_PRCDAR,
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_CDRXADDR(sc, sc->sc_rxptr));
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_COMMAND,
|
|
|
|
COMMAND_RXQUEUED | COMMAND_START_RX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for transmission complete interrupts.
|
|
|
|
*/
|
|
|
|
if (intstat & (INTSTAT_TXC | INTSTAT_TXU)) {
|
1999-02-12 08:55:27 +03:00
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
for (i = sc->sc_txdirty; sc->sc_txpending != 0;
|
|
|
|
i = EPIC_NEXTTX(i), sc->sc_txpending--) {
|
|
|
|
txd = EPIC_CDTX(sc, i);
|
|
|
|
ds = EPIC_DSTX(sc, i);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_CDTXSYNC(sc, i,
|
|
|
|
BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
|
|
|
|
|
2003-11-08 19:08:13 +03:00
|
|
|
txstatus = txd->et_txstatus;
|
|
|
|
if (txstatus & ET_TXSTAT_OWNER)
|
1998-06-02 05:29:41 +04:00
|
|
|
break;
|
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_CDFLSYNC(sc, i, BUS_DMASYNC_POSTWRITE);
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap,
|
|
|
|
0, ds->ds_dmamap->dm_mapsize,
|
|
|
|
BUS_DMASYNC_POSTWRITE);
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
|
|
|
|
m_freem(ds->ds_mbuf);
|
|
|
|
ds->ds_mbuf = NULL;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for errors and collisions.
|
|
|
|
*/
|
2003-11-08 19:08:13 +03:00
|
|
|
if ((txstatus & ET_TXSTAT_PACKETTX) == 0)
|
1998-06-02 05:29:41 +04:00
|
|
|
ifp->if_oerrors++;
|
1999-02-12 08:55:27 +03:00
|
|
|
else
|
|
|
|
ifp->if_opackets++;
|
1998-06-02 05:29:41 +04:00
|
|
|
ifp->if_collisions +=
|
2003-11-08 19:08:13 +03:00
|
|
|
TXSTAT_COLLISIONS(txstatus);
|
|
|
|
if (txstatus & ET_TXSTAT_CARSENSELOST)
|
1998-06-02 05:29:41 +04:00
|
|
|
printf("%s: lost carrier\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
}
|
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
/* Update the dirty transmit buffer pointer. */
|
1998-06-02 05:29:41 +04:00
|
|
|
sc->sc_txdirty = i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel the watchdog timer if there are no pending
|
|
|
|
* transmissions.
|
|
|
|
*/
|
|
|
|
if (sc->sc_txpending == 0)
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kick the transmitter after a DMA underrun.
|
|
|
|
*/
|
|
|
|
if (intstat & INTSTAT_TXU) {
|
|
|
|
printf("%s: transmit underrun\n", sc->sc_dev.dv_xname);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh,
|
|
|
|
EPIC_COMMAND, COMMAND_TXUGO);
|
|
|
|
if (sc->sc_txpending)
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh,
|
|
|
|
EPIC_COMMAND, COMMAND_TXQUEUED);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to get more packets going.
|
|
|
|
*/
|
|
|
|
epic_start(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for fatal interrupts.
|
|
|
|
*/
|
|
|
|
if (intstat & INTSTAT_FATAL_INT) {
|
1999-08-27 23:13:00 +04:00
|
|
|
if (intstat & INTSTAT_PTA)
|
|
|
|
printf("%s: PCI target abort error\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
else if (intstat & INTSTAT_PMA)
|
|
|
|
printf("%s: PCI master abort error\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
else if (intstat & INTSTAT_APE)
|
|
|
|
printf("%s: PCI address parity error\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
else if (intstat & INTSTAT_DPE)
|
|
|
|
printf("%s: PCI data parity error\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
else
|
|
|
|
printf("%s: unknown fatal error\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
2000-10-11 20:57:45 +04:00
|
|
|
(void) epic_init(ifp);
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for more interrupts.
|
|
|
|
*/
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
|
1998-08-11 04:12:52 +04:00
|
|
|
/*
|
|
|
|
* One second timer, used to tick the MII.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_tick(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct epic_softc *sc = arg;
|
|
|
|
int s;
|
|
|
|
|
1999-02-17 12:11:29 +03:00
|
|
|
s = splnet();
|
1998-08-11 04:12:52 +04:00
|
|
|
mii_tick(&sc->sc_mii);
|
|
|
|
splx(s);
|
|
|
|
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_mii_callout, hz, epic_tick, sc);
|
1998-08-11 04:12:52 +04:00
|
|
|
}
|
|
|
|
|
1998-07-23 21:37:38 +04:00
|
|
|
/*
|
|
|
|
* Fixup the clock source on the EPIC.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_fixup_clock_source(sc)
|
|
|
|
struct epic_softc *sc;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* According to SMC Application Note 7-15, the EPIC's clock
|
|
|
|
* source is incorrect following a reset. This manifests itself
|
|
|
|
* as failure to recognize when host software has written to
|
|
|
|
* a register on the EPIC. The appnote recommends issuing at
|
|
|
|
* least 16 consecutive writes to the CLOCK TEST bit to correctly
|
|
|
|
* configure the clock source.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_TEST,
|
|
|
|
TEST_CLOCKTEST);
|
|
|
|
}
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
|
|
|
* Perform a soft reset on the EPIC.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_reset(sc)
|
|
|
|
struct epic_softc *sc;
|
|
|
|
{
|
|
|
|
|
1998-07-23 21:37:38 +04:00
|
|
|
epic_fixup_clock_source(sc);
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_GENCTL, 0);
|
|
|
|
delay(100);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_GENCTL, GENCTL_SOFTRESET);
|
|
|
|
delay(100);
|
1998-07-23 21:37:38 +04:00
|
|
|
|
|
|
|
epic_fixup_clock_source(sc);
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-08-09 03:51:39 +04:00
|
|
|
* Initialize the interface. Must be called at splnet().
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
1999-08-03 21:25:51 +04:00
|
|
|
int
|
2000-10-11 20:57:45 +04:00
|
|
|
epic_init(ifp)
|
|
|
|
struct ifnet *ifp;
|
1998-06-02 05:29:41 +04:00
|
|
|
{
|
2000-10-11 20:57:45 +04:00
|
|
|
struct epic_softc *sc = ifp->if_softc;
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_space_tag_t st = sc->sc_st;
|
|
|
|
bus_space_handle_t sh = sc->sc_sh;
|
|
|
|
u_int8_t *enaddr = LLADDR(ifp->if_sadl);
|
|
|
|
struct epic_txdesc *txd;
|
1999-08-03 21:25:51 +04:00
|
|
|
struct epic_descsoft *ds;
|
1998-06-02 05:29:41 +04:00
|
|
|
u_int32_t genctl, reg0;
|
1999-08-03 21:25:51 +04:00
|
|
|
int i, error = 0;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel any pending I/O.
|
|
|
|
*/
|
2000-10-11 20:57:45 +04:00
|
|
|
epic_stop(ifp, 0);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the EPIC to a known state.
|
|
|
|
*/
|
|
|
|
epic_reset(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Magical mystery initialization.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, EPIC_TXTEST, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the EPIC genctl register:
|
|
|
|
*
|
|
|
|
* - 64 byte receive FIFO threshold
|
|
|
|
* - automatic advance to next receive frame
|
|
|
|
*/
|
|
|
|
genctl = GENCTL_RX_FIFO_THRESH0 | GENCTL_ONECOPY;
|
1999-07-27 04:55:34 +04:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
|
|
|
genctl |= GENCTL_BIG_ENDIAN;
|
|
|
|
#endif
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_space_write_4(st, sh, EPIC_GENCTL, genctl);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the MII bus and PHY.
|
|
|
|
*/
|
|
|
|
reg0 = bus_space_read_4(st, sh, EPIC_NVCTL);
|
|
|
|
bus_space_write_4(st, sh, EPIC_NVCTL, reg0 | NVCTL_GPIO1 | NVCTL_GPOE1);
|
|
|
|
bus_space_write_4(st, sh, EPIC_MIICFG, MIICFG_ENASER);
|
|
|
|
bus_space_write_4(st, sh, EPIC_GENCTL, genctl | GENCTL_RESET_PHY);
|
|
|
|
delay(100);
|
|
|
|
bus_space_write_4(st, sh, EPIC_GENCTL, genctl);
|
2001-05-17 23:00:18 +04:00
|
|
|
delay(1000);
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_space_write_4(st, sh, EPIC_NVCTL, reg0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize Ethernet address.
|
|
|
|
*/
|
|
|
|
reg0 = enaddr[1] << 8 | enaddr[0];
|
|
|
|
bus_space_write_4(st, sh, EPIC_LAN0, reg0);
|
|
|
|
reg0 = enaddr[3] << 8 | enaddr[2];
|
|
|
|
bus_space_write_4(st, sh, EPIC_LAN1, reg0);
|
|
|
|
reg0 = enaddr[5] << 8 | enaddr[4];
|
|
|
|
bus_space_write_4(st, sh, EPIC_LAN2, reg0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize receive control. Remember the external buffer
|
|
|
|
* size setting.
|
|
|
|
*/
|
|
|
|
reg0 = bus_space_read_4(st, sh, EPIC_RXCON) &
|
|
|
|
(RXCON_EXTBUFSIZESEL1 | RXCON_EXTBUFSIZESEL0);
|
|
|
|
reg0 |= (RXCON_RXMULTICAST | RXCON_RXBROADCAST);
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
reg0 |= RXCON_PROMISCMODE;
|
|
|
|
bus_space_write_4(st, sh, EPIC_RXCON, reg0);
|
|
|
|
|
1999-02-18 05:12:09 +03:00
|
|
|
/* Set the current media. */
|
2001-05-17 21:32:47 +04:00
|
|
|
epic_mediachange(ifp);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-02-18 05:12:09 +03:00
|
|
|
/* Set up the multicast hash table. */
|
|
|
|
epic_set_mchash(sc);
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
1999-02-12 08:55:27 +03:00
|
|
|
* Initialize the transmit descriptor ring. txlast is initialized
|
|
|
|
* to the end of the list so that it will wrap around to the first
|
|
|
|
* descriptor when the first packet is transmitted.
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
|
|
|
for (i = 0; i < EPIC_NTXDESC; i++) {
|
1999-02-12 08:55:27 +03:00
|
|
|
txd = EPIC_CDTX(sc, i);
|
|
|
|
memset(txd, 0, sizeof(struct epic_txdesc));
|
|
|
|
txd->et_bufaddr = EPIC_CDFLADDR(sc, i);
|
|
|
|
txd->et_nextdesc = EPIC_CDTXADDR(sc, EPIC_NEXTTX(i));
|
|
|
|
EPIC_CDTXSYNC(sc, i, BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
1999-02-12 08:55:27 +03:00
|
|
|
sc->sc_txpending = 0;
|
|
|
|
sc->sc_txdirty = 0;
|
|
|
|
sc->sc_txlast = EPIC_NTXDESC - 1;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
1999-08-03 21:25:51 +04:00
|
|
|
* Initialize the receive descriptor ring.
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
1999-08-03 21:25:51 +04:00
|
|
|
for (i = 0; i < EPIC_NRXDESC; i++) {
|
|
|
|
ds = EPIC_DSRX(sc, i);
|
|
|
|
if (ds->ds_mbuf == NULL) {
|
|
|
|
if ((error = epic_add_rxbuf(sc, i)) != 0) {
|
|
|
|
printf("%s: unable to allocate or map rx "
|
|
|
|
"buffer %d error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, i, error);
|
|
|
|
/*
|
|
|
|
* XXX Should attempt to run with fewer receive
|
|
|
|
* XXX buffers instead of just failing.
|
|
|
|
*/
|
|
|
|
epic_rxdrain(sc);
|
|
|
|
goto out;
|
|
|
|
}
|
2001-07-23 21:20:03 +04:00
|
|
|
} else
|
|
|
|
EPIC_INIT_RXDESC(sc, i);
|
1999-08-03 21:25:51 +04:00
|
|
|
}
|
1999-02-12 08:55:27 +03:00
|
|
|
sc->sc_rxptr = 0;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the interrupt mask and enable interrupts.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, EPIC_INTMASK, INTMASK);
|
|
|
|
bus_space_write_4(st, sh, EPIC_GENCTL, genctl | GENCTL_INTENA);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give the transmit and receive rings to the EPIC.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, EPIC_PTCDAR,
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_CDTXADDR(sc, EPIC_NEXTTX(sc->sc_txlast)));
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_space_write_4(st, sh, EPIC_PRCDAR,
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_CDRXADDR(sc, sc->sc_rxptr));
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the EPIC in motion.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, EPIC_COMMAND,
|
|
|
|
COMMAND_RXQUEUED | COMMAND_START_RX);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ...all done!
|
|
|
|
*/
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1998-08-11 04:12:52 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the one second clock.
|
|
|
|
*/
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_mii_callout, hz, epic_tick, sc);
|
1998-10-05 23:10:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to start output on the interface.
|
|
|
|
*/
|
|
|
|
epic_start(ifp);
|
1999-08-03 21:25:51 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
if (error)
|
|
|
|
printf("%s: interface not running\n", sc->sc_dev.dv_xname);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drain the receive queue.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_rxdrain(sc)
|
|
|
|
struct epic_softc *sc;
|
|
|
|
{
|
|
|
|
struct epic_descsoft *ds;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < EPIC_NRXDESC; i++) {
|
|
|
|
ds = EPIC_DSRX(sc, i);
|
|
|
|
if (ds->ds_mbuf != NULL) {
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
|
|
|
|
m_freem(ds->ds_mbuf);
|
|
|
|
ds->ds_mbuf = NULL;
|
|
|
|
}
|
|
|
|
}
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop transmission on the interface.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-11 20:57:45 +04:00
|
|
|
epic_stop(ifp, disable)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int disable;
|
1998-06-02 05:29:41 +04:00
|
|
|
{
|
2000-10-11 20:57:45 +04:00
|
|
|
struct epic_softc *sc = ifp->if_softc;
|
1998-06-02 05:29:41 +04:00
|
|
|
bus_space_tag_t st = sc->sc_st;
|
|
|
|
bus_space_handle_t sh = sc->sc_sh;
|
|
|
|
struct epic_descsoft *ds;
|
|
|
|
u_int32_t reg;
|
|
|
|
int i;
|
|
|
|
|
1998-08-11 04:12:52 +04:00
|
|
|
/*
|
|
|
|
* Stop the one second clock.
|
|
|
|
*/
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_stop(&sc->sc_mii_callout);
|
1998-08-11 04:12:52 +04:00
|
|
|
|
1999-11-12 21:14:17 +03:00
|
|
|
/* Down the MII. */
|
|
|
|
mii_down(&sc->sc_mii);
|
|
|
|
|
1998-07-23 21:37:38 +04:00
|
|
|
/* Paranoia... */
|
|
|
|
epic_fixup_clock_source(sc);
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
|
|
|
* Disable interrupts.
|
|
|
|
*/
|
|
|
|
reg = bus_space_read_4(st, sh, EPIC_GENCTL);
|
|
|
|
bus_space_write_4(st, sh, EPIC_GENCTL, reg & ~GENCTL_INTENA);
|
|
|
|
bus_space_write_4(st, sh, EPIC_INTMASK, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the DMA engine and take the receiver off-line.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, EPIC_COMMAND, COMMAND_STOP_RDMA |
|
|
|
|
COMMAND_STOP_TDMA | COMMAND_STOP_RX);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release any queued transmit buffers.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < EPIC_NTXDESC; i++) {
|
1999-02-12 08:55:27 +03:00
|
|
|
ds = EPIC_DSTX(sc, i);
|
1998-06-02 05:29:41 +04:00
|
|
|
if (ds->ds_mbuf != NULL) {
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
|
|
|
|
m_freem(ds->ds_mbuf);
|
|
|
|
ds->ds_mbuf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-11 20:57:45 +04:00
|
|
|
if (disable)
|
1999-08-03 21:25:51 +04:00
|
|
|
epic_rxdrain(sc);
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
|
|
|
* Mark the interface down and cancel the watchdog timer.
|
|
|
|
*/
|
|
|
|
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the EPIC Serial EEPROM.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_read_eeprom(sc, word, wordcnt, data)
|
|
|
|
struct epic_softc *sc;
|
|
|
|
int word, wordcnt;
|
|
|
|
u_int16_t *data;
|
|
|
|
{
|
|
|
|
bus_space_tag_t st = sc->sc_st;
|
|
|
|
bus_space_handle_t sh = sc->sc_sh;
|
|
|
|
u_int16_t reg;
|
|
|
|
int i, x;
|
|
|
|
|
|
|
|
#define EEPROM_WAIT_READY(st, sh) \
|
|
|
|
while ((bus_space_read_4((st), (sh), EPIC_EECTL) & EECTL_EERDY) == 0) \
|
|
|
|
/* nothing */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable the EEPROM.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, EECTL_ENABLE);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
|
|
|
|
for (i = 0; i < wordcnt; i++) {
|
|
|
|
/* Send CHIP SELECT for one clock tick. */
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, EECTL_ENABLE|EECTL_EECS);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
|
|
|
|
/* Shift in the READ opcode. */
|
|
|
|
for (x = 3; x > 0; x--) {
|
|
|
|
reg = EECTL_ENABLE|EECTL_EECS;
|
|
|
|
if (EPIC_EEPROM_OPC_READ & (1 << (x - 1)))
|
|
|
|
reg |= EECTL_EEDI;
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, reg);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, reg|EECTL_EESK);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, reg);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shift in address. */
|
|
|
|
for (x = 6; x > 0; x--) {
|
|
|
|
reg = EECTL_ENABLE|EECTL_EECS;
|
|
|
|
if ((word + i) & (1 << (x - 1)))
|
|
|
|
reg |= EECTL_EEDI;
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, reg);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, reg|EECTL_EESK);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, reg);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Shift out data. */
|
|
|
|
reg = EECTL_ENABLE|EECTL_EECS;
|
|
|
|
data[i] = 0;
|
|
|
|
for (x = 16; x > 0; x--) {
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, reg|EECTL_EESK);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
if (bus_space_read_4(st, sh, EPIC_EECTL) & EECTL_EEDO)
|
|
|
|
data[i] |= (1 << (x - 1));
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, reg);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear CHIP SELECT. */
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, EECTL_ENABLE);
|
|
|
|
EEPROM_WAIT_READY(st, sh);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable the EEPROM.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, EPIC_EECTL, 0);
|
|
|
|
|
|
|
|
#undef EEPROM_WAIT_READY
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a receive buffer to the indicated descriptor.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
epic_add_rxbuf(sc, idx)
|
|
|
|
struct epic_softc *sc;
|
|
|
|
int idx;
|
|
|
|
{
|
1999-02-12 08:55:27 +03:00
|
|
|
struct epic_descsoft *ds = EPIC_DSRX(sc, idx);
|
|
|
|
struct mbuf *m;
|
|
|
|
int error;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
1999-02-12 08:55:27 +03:00
|
|
|
if (m == NULL)
|
|
|
|
return (ENOBUFS);
|
|
|
|
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return (ENOBUFS);
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
if (ds->ds_mbuf != NULL)
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
|
|
|
|
|
1998-06-02 05:29:41 +04:00
|
|
|
ds->ds_mbuf = m;
|
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
error = bus_dmamap_load(sc->sc_dmat, ds->ds_dmamap,
|
2001-07-19 20:25:23 +04:00
|
|
|
m->m_ext.ext_buf, m->m_ext.ext_size, NULL,
|
|
|
|
BUS_DMA_READ|BUS_DMA_NOWAIT);
|
1999-02-12 08:55:27 +03:00
|
|
|
if (error) {
|
|
|
|
printf("%s: can't load rx DMA map %d, error = %d\n",
|
|
|
|
sc->sc_dev.dv_xname, idx, error);
|
|
|
|
panic("epic_add_rxbuf"); /* XXX */
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
|
|
|
|
ds->ds_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
|
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
EPIC_INIT_RXDESC(sc, idx);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
1999-02-12 08:55:27 +03:00
|
|
|
return (0);
|
1998-06-02 05:29:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the EPIC multicast hash table.
|
1999-02-18 05:12:09 +03:00
|
|
|
*
|
|
|
|
* NOTE: We rely on a recently-updated mii_media_active here!
|
1998-06-02 05:29:41 +04:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_set_mchash(sc)
|
|
|
|
struct epic_softc *sc;
|
|
|
|
{
|
|
|
|
struct ethercom *ec = &sc->sc_ethercom;
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
2000-05-12 20:57:30 +04:00
|
|
|
u_int32_t hash, mchash[4];
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the multicast address filter by passing all multicast
|
2000-05-12 20:57:30 +04:00
|
|
|
* addresses through a CRC generator, and then using the low-order
|
1998-06-02 05:29:41 +04:00
|
|
|
* 6 bits as an index into the 64 bit multicast hash table (only
|
|
|
|
* the lower 16 bits of each 32 bit multicast hash register are
|
2000-05-12 20:57:30 +04:00
|
|
|
* valid). The high order bits select the register, while the
|
1998-06-02 05:29:41 +04:00
|
|
|
* rest of the bits select the bit within the register.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
goto allmulti;
|
|
|
|
|
1999-02-18 05:12:09 +03:00
|
|
|
if (IFM_SUBTYPE(sc->sc_mii.mii_media_active) == IFM_10_T) {
|
|
|
|
/* XXX hardware bug in 10Mbps mode. */
|
|
|
|
goto allmulti;
|
|
|
|
}
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
mchash[0] = mchash[1] = mchash[2] = mchash[3] = 0;
|
|
|
|
|
|
|
|
ETHER_FIRST_MULTI(step, ec, enm);
|
|
|
|
while (enm != NULL) {
|
2001-07-07 09:35:39 +04:00
|
|
|
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
|
1998-06-02 05:29:41 +04:00
|
|
|
/*
|
|
|
|
* We must listen to a range of multicast addresses.
|
|
|
|
* For now, just accept all multicasts, rather than
|
|
|
|
* trying to set only those filter bits needed to match
|
|
|
|
* the range. (At this time, the only use of address
|
|
|
|
* ranges is for IP multicast routing, for which the
|
|
|
|
* range is big enough to require all bits set.)
|
|
|
|
*/
|
|
|
|
goto allmulti;
|
|
|
|
}
|
|
|
|
|
2000-11-08 18:20:29 +03:00
|
|
|
hash = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN);
|
|
|
|
hash >>= 26;
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
/* Set the corresponding bit in the hash table. */
|
2000-05-12 20:57:30 +04:00
|
|
|
mchash[hash >> 4] |= 1 << (hash & 0xf);
|
1998-06-02 05:29:41 +04:00
|
|
|
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
goto sethash;
|
|
|
|
|
|
|
|
allmulti:
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
mchash[0] = mchash[1] = mchash[2] = mchash[3] = 0xffff;
|
|
|
|
|
|
|
|
sethash:
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MC0, mchash[0]);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MC1, mchash[1]);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MC2, mchash[2]);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MC3, mchash[3]);
|
|
|
|
}
|
1998-08-11 04:12:52 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for the MII to become ready.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
epic_mii_wait(sc, rw)
|
|
|
|
struct epic_softc *sc;
|
|
|
|
u_int32_t rw;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 50; i++) {
|
|
|
|
if ((bus_space_read_4(sc->sc_st, sc->sc_sh, EPIC_MMCTL) & rw)
|
|
|
|
== 0)
|
|
|
|
break;
|
|
|
|
delay(2);
|
|
|
|
}
|
|
|
|
if (i == 50) {
|
|
|
|
printf("%s: MII timed out\n", sc->sc_dev.dv_xname);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read from the MII.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
epic_mii_read(self, phy, reg)
|
|
|
|
struct device *self;
|
|
|
|
int phy, reg;
|
|
|
|
{
|
|
|
|
struct epic_softc *sc = (struct epic_softc *)self;
|
|
|
|
|
|
|
|
if (epic_mii_wait(sc, MMCTL_WRITE))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MMCTL,
|
|
|
|
MMCTL_ARG(phy, reg, MMCTL_READ));
|
|
|
|
|
|
|
|
if (epic_mii_wait(sc, MMCTL_READ))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (bus_space_read_4(sc->sc_st, sc->sc_sh, EPIC_MMDATA) &
|
|
|
|
MMDATA_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write to the MII.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_mii_write(self, phy, reg, val)
|
|
|
|
struct device *self;
|
|
|
|
int phy, reg, val;
|
|
|
|
{
|
|
|
|
struct epic_softc *sc = (struct epic_softc *)self;
|
|
|
|
|
|
|
|
if (epic_mii_wait(sc, MMCTL_WRITE))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MMDATA, val);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MMCTL,
|
|
|
|
MMCTL_ARG(phy, reg, MMCTL_WRITE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback from PHY when media changes.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_statchg(self)
|
|
|
|
struct device *self;
|
|
|
|
{
|
1999-02-14 00:08:08 +03:00
|
|
|
struct epic_softc *sc = (struct epic_softc *)self;
|
2001-05-17 21:32:47 +04:00
|
|
|
u_int32_t txcon, miicfg;
|
1999-02-14 00:08:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Update loopback bits in TXCON to reflect duplex mode.
|
|
|
|
*/
|
|
|
|
txcon = bus_space_read_4(sc->sc_st, sc->sc_sh, EPIC_TXCON);
|
|
|
|
if (sc->sc_mii.mii_media_active & IFM_FDX)
|
|
|
|
txcon |= (TXCON_LOOPBACK_D1|TXCON_LOOPBACK_D2);
|
|
|
|
else
|
|
|
|
txcon &= ~(TXCON_LOOPBACK_D1|TXCON_LOOPBACK_D2);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_TXCON, txcon);
|
1998-08-11 04:12:52 +04:00
|
|
|
|
2001-05-17 21:32:47 +04:00
|
|
|
/* On some cards we need manualy set fullduplex led */
|
|
|
|
if (sc->sc_hwflags & EPIC_DUPLEXLED_ON_694) {
|
|
|
|
miicfg = bus_space_read_4(sc->sc_st, sc->sc_sh, EPIC_MIICFG);
|
|
|
|
if (IFM_OPTIONS(sc->sc_mii.mii_media_active) & IFM_FDX)
|
|
|
|
miicfg |= MIICFG_ENABLE;
|
|
|
|
else
|
|
|
|
miicfg &= ~MIICFG_ENABLE;
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MIICFG, miicfg);
|
|
|
|
}
|
|
|
|
|
1999-02-18 05:12:09 +03:00
|
|
|
/*
|
|
|
|
* There is a multicast filter bug in 10Mbps mode. Kick the
|
|
|
|
* multicast filter in case the speed changed.
|
|
|
|
*/
|
|
|
|
epic_set_mchash(sc);
|
1998-08-11 04:12:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback from ifmedia to request current media status.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
epic_mediastatus(ifp, ifmr)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmediareq *ifmr;
|
|
|
|
{
|
|
|
|
struct epic_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
mii_pollstat(&sc->sc_mii);
|
|
|
|
ifmr->ifm_status = sc->sc_mii.mii_media_status;
|
|
|
|
ifmr->ifm_active = sc->sc_mii.mii_media_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callback from ifmedia to request new media setting.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
epic_mediachange(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
1999-02-14 00:08:08 +03:00
|
|
|
struct epic_softc *sc = ifp->if_softc;
|
2001-05-17 21:32:47 +04:00
|
|
|
struct mii_data *mii = &sc->sc_mii;
|
|
|
|
struct ifmedia *ifm = &mii->mii_media;
|
|
|
|
int media = ifm->ifm_cur->ifm_media;
|
|
|
|
u_int32_t miicfg;
|
|
|
|
struct mii_softc *miisc;
|
|
|
|
int cfg;
|
|
|
|
|
|
|
|
if (!(ifp->if_flags & IFF_UP))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
if (IFM_INST(media) != sc->sc_serinst) {
|
|
|
|
/* If we're not selecting serial interface, select MII mode */
|
|
|
|
#ifdef EPICMEDIADEBUG
|
|
|
|
printf("%s: parallel mode\n", ifp->if_xname);
|
|
|
|
#endif
|
|
|
|
miicfg = bus_space_read_4(sc->sc_st, sc->sc_sh, EPIC_MIICFG);
|
|
|
|
miicfg &= ~MIICFG_SERMODEENA;
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MIICFG, miicfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
mii_mediachg(mii);
|
|
|
|
|
|
|
|
if (IFM_INST(media) == sc->sc_serinst) {
|
|
|
|
/* select serial interface */
|
|
|
|
#ifdef EPICMEDIADEBUG
|
|
|
|
printf("%s: serial mode\n", ifp->if_xname);
|
|
|
|
#endif
|
|
|
|
miicfg = bus_space_read_4(sc->sc_st, sc->sc_sh, EPIC_MIICFG);
|
|
|
|
miicfg |= (MIICFG_SERMODEENA | MIICFG_ENABLE);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, EPIC_MIICFG, miicfg);
|
|
|
|
|
|
|
|
/* There is no driver to fill this */
|
|
|
|
mii->mii_media_active = media;
|
|
|
|
mii->mii_media_status = 0;
|
|
|
|
|
|
|
|
epic_statchg(&sc->sc_dev);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!miisc) {
|
|
|
|
printf("epic_mediachange: can't happen\n"); /* ??? panic */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#ifdef EPICMEDIADEBUG
|
|
|
|
printf("%s: using phy %s\n", ifp->if_xname,
|
|
|
|
miisc->mii_dev.dv_xname);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (miisc->mii_flags & MIIF_HAVEFIBER) {
|
|
|
|
/* XXX XXX assume it's a Level1 - should check */
|
|
|
|
|
2003-11-02 14:07:44 +03:00
|
|
|
/* We have to powerup fiber transceivers */
|
2001-05-17 21:32:47 +04:00
|
|
|
cfg = PHY_READ(miisc, MII_LXTPHY_CONFIG);
|
|
|
|
if (IFM_SUBTYPE(media) == IFM_100_FX) {
|
|
|
|
#ifdef EPICMEDIADEBUG
|
|
|
|
printf("%s: power up fiber\n", ifp->if_xname);
|
|
|
|
#endif
|
|
|
|
cfg |= (CONFIG_LEDC1 | CONFIG_LEDC0);
|
|
|
|
} else {
|
|
|
|
#ifdef EPICMEDIADEBUG
|
|
|
|
printf("%s: power down fiber\n", ifp->if_xname);
|
|
|
|
#endif
|
|
|
|
cfg &= ~(CONFIG_LEDC1 | CONFIG_LEDC0);
|
|
|
|
}
|
|
|
|
PHY_WRITE(miisc, MII_LXTPHY_CONFIG, cfg);
|
|
|
|
}
|
1998-08-11 04:12:52 +04:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|