Change MII PHY read/write API from:
int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:
int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);
Now we can test if a read/write operation failed or not by the return value.
In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.
Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:
arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c
Tested with the following device:
axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)
Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url
Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
2019-01-22 06:42:24 +03:00
|
|
|
/* $NetBSD: if_stge.c,v 1.67 2019/01/22 03:42:27 msaitoh Exp $ */
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
*
|
|
|
|
* 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 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 Sundance Tech. TC9021 10/100/1000
|
|
|
|
* Ethernet controller.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 10:48:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
Change MII PHY read/write API from:
int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:
int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);
Now we can test if a read/write operation failed or not by the return value.
In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.
Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:
arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c
Tested with the following device:
axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)
Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url
Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
2019-01-22 06:42:24 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_stge.c,v 1.67 2019/01/22 03:42:27 msaitoh Exp $");
|
2001-11-13 10:48:40 +03:00
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/callout.h>
|
|
|
|
#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>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
|
|
|
#include <net/bpf.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/intr.h>
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
#include <dev/mii/mii.h>
|
|
|
|
#include <dev/mii/miivar.h>
|
|
|
|
#include <dev/mii/mii_bitbang.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
|
|
|
#include <dev/pci/if_stgereg.h>
|
|
|
|
|
2011-03-08 22:06:58 +03:00
|
|
|
#include <prop/proplib.h>
|
|
|
|
|
2003-03-01 22:49:45 +03:00
|
|
|
/* #define STGE_CU_BUG 1 */
|
2003-02-10 12:00:38 +03:00
|
|
|
#define STGE_VLAN_UNTAG 1
|
|
|
|
/* #define STGE_VLAN_CFI 1 */
|
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
/*
|
|
|
|
* Transmit descriptor list size.
|
|
|
|
*/
|
|
|
|
#define STGE_NTXDESC 256
|
|
|
|
#define STGE_NTXDESC_MASK (STGE_NTXDESC - 1)
|
|
|
|
#define STGE_NEXTTX(x) (((x) + 1) & STGE_NTXDESC_MASK)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive descriptor list size.
|
|
|
|
*/
|
|
|
|
#define STGE_NRXDESC 256
|
|
|
|
#define STGE_NRXDESC_MASK (STGE_NRXDESC - 1)
|
|
|
|
#define STGE_NEXTRX(x) (((x) + 1) & STGE_NRXDESC_MASK)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only interrupt every N frames. Must be a power-of-two.
|
|
|
|
*/
|
|
|
|
#define STGE_TXINTR_SPACING 16
|
|
|
|
#define STGE_TXINTR_SPACING_MASK (STGE_TXINTR_SPACING - 1)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Control structures are DMA'd to the TC9021 chip. We allocate them in
|
|
|
|
* a single clump that maps to a single DMA segment to make several things
|
|
|
|
* easier.
|
|
|
|
*/
|
|
|
|
struct stge_control_data {
|
|
|
|
/*
|
|
|
|
* The transmit descriptors.
|
|
|
|
*/
|
|
|
|
struct stge_tfd scd_txdescs[STGE_NTXDESC];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The receive descriptors.
|
|
|
|
*/
|
|
|
|
struct stge_rfd scd_rxdescs[STGE_NRXDESC];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define STGE_CDOFF(x) offsetof(struct stge_control_data, x)
|
|
|
|
#define STGE_CDTXOFF(x) STGE_CDOFF(scd_txdescs[(x)])
|
|
|
|
#define STGE_CDRXOFF(x) STGE_CDOFF(scd_rxdescs[(x)])
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Software state for transmit and receive jobs.
|
|
|
|
*/
|
|
|
|
struct stge_descsoft {
|
|
|
|
struct mbuf *ds_mbuf; /* head of our mbuf chain */
|
|
|
|
bus_dmamap_t ds_dmamap; /* our DMA map */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Software state per device.
|
|
|
|
*/
|
|
|
|
struct stge_softc {
|
2009-05-17 06:08:35 +04:00
|
|
|
device_t sc_dev; /* generic device information */
|
2001-07-25 04:11:51 +04:00
|
|
|
bus_space_tag_t sc_st; /* bus space tag */
|
|
|
|
bus_space_handle_t sc_sh; /* bus space handle */
|
|
|
|
bus_dma_tag_t sc_dmat; /* bus DMA tag */
|
|
|
|
struct ethercom sc_ethercom; /* ethernet common data */
|
|
|
|
int sc_rev; /* silicon revision */
|
|
|
|
|
|
|
|
void *sc_ih; /* interrupt cookie */
|
|
|
|
|
|
|
|
struct mii_data sc_mii; /* MII/media information */
|
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_t sc_tick_ch; /* tick callout */
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
bus_dmamap_t sc_cddmamap; /* control data DMA map */
|
|
|
|
#define sc_cddma sc_cddmamap->dm_segs[0].ds_addr
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Software state for transmit and receive descriptors.
|
|
|
|
*/
|
|
|
|
struct stge_descsoft sc_txsoft[STGE_NTXDESC];
|
|
|
|
struct stge_descsoft sc_rxsoft[STGE_NRXDESC];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Control data structures.
|
|
|
|
*/
|
|
|
|
struct stge_control_data *sc_control_data;
|
|
|
|
#define sc_txdescs sc_control_data->scd_txdescs
|
|
|
|
#define sc_rxdescs sc_control_data->scd_rxdescs
|
|
|
|
|
|
|
|
#ifdef STGE_EVENT_COUNTERS
|
|
|
|
/*
|
|
|
|
* Event counters.
|
|
|
|
*/
|
|
|
|
struct evcnt sc_ev_txstall; /* Tx stalled */
|
|
|
|
struct evcnt sc_ev_txdmaintr; /* Tx DMA interrupts */
|
|
|
|
struct evcnt sc_ev_txindintr; /* Tx Indicate interrupts */
|
|
|
|
struct evcnt sc_ev_rxintr; /* Rx interrupts */
|
|
|
|
|
|
|
|
struct evcnt sc_ev_txseg1; /* Tx packets w/ 1 segment */
|
|
|
|
struct evcnt sc_ev_txseg2; /* Tx packets w/ 2 segments */
|
|
|
|
struct evcnt sc_ev_txseg3; /* Tx packets w/ 3 segments */
|
|
|
|
struct evcnt sc_ev_txseg4; /* Tx packets w/ 4 segments */
|
|
|
|
struct evcnt sc_ev_txseg5; /* Tx packets w/ 5 segments */
|
|
|
|
struct evcnt sc_ev_txsegmore; /* Tx packets w/ more than 5 segments */
|
|
|
|
struct evcnt sc_ev_txcopy; /* Tx packets that we had to copy */
|
|
|
|
|
|
|
|
struct evcnt sc_ev_rxipsum; /* IP checksums checked in-bound */
|
|
|
|
struct evcnt sc_ev_rxtcpsum; /* TCP checksums checked in-bound */
|
|
|
|
struct evcnt sc_ev_rxudpsum; /* UDP checksums checked in-bound */
|
|
|
|
|
|
|
|
struct evcnt sc_ev_txipsum; /* IP checksums comp. out-bound */
|
|
|
|
struct evcnt sc_ev_txtcpsum; /* TCP checksums comp. out-bound */
|
|
|
|
struct evcnt sc_ev_txudpsum; /* UDP checksums comp. out-bound */
|
|
|
|
#endif /* STGE_EVENT_COUNTERS */
|
|
|
|
|
|
|
|
int sc_txpending; /* number of Tx requests pending */
|
|
|
|
int sc_txdirty; /* first dirty Tx descriptor */
|
|
|
|
int sc_txlast; /* last used Tx descriptor */
|
|
|
|
|
|
|
|
int sc_rxptr; /* next ready Rx descriptor/descsoft */
|
|
|
|
int sc_rxdiscard;
|
|
|
|
int sc_rxlen;
|
|
|
|
struct mbuf *sc_rxhead;
|
|
|
|
struct mbuf *sc_rxtail;
|
|
|
|
struct mbuf **sc_rxtailp;
|
|
|
|
|
|
|
|
int sc_txthresh; /* Tx threshold */
|
2005-07-28 20:04:24 +04:00
|
|
|
uint32_t sc_usefiber:1; /* if we're fiber */
|
|
|
|
uint32_t sc_stge1023:1; /* are we a 1023 */
|
2001-07-25 04:11:51 +04:00
|
|
|
uint32_t sc_DMACtrl; /* prototype DMACtrl register */
|
|
|
|
uint32_t sc_MACCtrl; /* prototype MacCtrl register */
|
|
|
|
uint16_t sc_IntEnable; /* prototype IntEnable register */
|
|
|
|
uint16_t sc_ReceiveMode; /* prototype ReceiveMode register */
|
|
|
|
uint8_t sc_PhyCtrl; /* prototype PhyCtrl register */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define STGE_RXCHAIN_RESET(sc) \
|
|
|
|
do { \
|
|
|
|
(sc)->sc_rxtailp = &(sc)->sc_rxhead; \
|
|
|
|
*(sc)->sc_rxtailp = NULL; \
|
|
|
|
(sc)->sc_rxlen = 0; \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
|
|
|
|
#define STGE_RXCHAIN_LINK(sc, m) \
|
|
|
|
do { \
|
|
|
|
*(sc)->sc_rxtailp = (sc)->sc_rxtail = (m); \
|
|
|
|
(sc)->sc_rxtailp = &(m)->m_next; \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
|
|
|
|
#ifdef STGE_EVENT_COUNTERS
|
|
|
|
#define STGE_EVCNT_INCR(ev) (ev)->ev_count++
|
|
|
|
#else
|
|
|
|
#define STGE_EVCNT_INCR(ev) /* nothing */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STGE_CDTXADDR(sc, x) ((sc)->sc_cddma + STGE_CDTXOFF((x)))
|
|
|
|
#define STGE_CDRXADDR(sc, x) ((sc)->sc_cddma + STGE_CDRXOFF((x)))
|
|
|
|
|
|
|
|
#define STGE_CDTXSYNC(sc, x, ops) \
|
|
|
|
bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
|
|
|
|
STGE_CDTXOFF((x)), sizeof(struct stge_tfd), (ops))
|
|
|
|
|
|
|
|
#define STGE_CDRXSYNC(sc, x, ops) \
|
|
|
|
bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_cddmamap, \
|
|
|
|
STGE_CDRXOFF((x)), sizeof(struct stge_rfd), (ops))
|
|
|
|
|
|
|
|
#define STGE_INIT_RXDESC(sc, x) \
|
|
|
|
do { \
|
|
|
|
struct stge_descsoft *__ds = &(sc)->sc_rxsoft[(x)]; \
|
|
|
|
struct stge_rfd *__rfd = &(sc)->sc_rxdescs[(x)]; \
|
|
|
|
\
|
|
|
|
/* \
|
|
|
|
* Note: We scoot the packet forward 2 bytes in the buffer \
|
|
|
|
* so that the payload after the Ethernet header is aligned \
|
|
|
|
* to a 4-byte boundary. \
|
|
|
|
*/ \
|
|
|
|
__rfd->rfd_frag.frag_word0 = \
|
|
|
|
htole64(FRAG_ADDR(__ds->ds_dmamap->dm_segs[0].ds_addr + 2) |\
|
|
|
|
FRAG_LEN(MCLBYTES - 2)); \
|
|
|
|
__rfd->rfd_next = \
|
|
|
|
htole64((uint64_t)STGE_CDRXADDR((sc), STGE_NEXTRX((x)))); \
|
|
|
|
__rfd->rfd_status = 0; \
|
|
|
|
STGE_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
|
|
|
|
} while (/*CONSTCOND*/0)
|
|
|
|
|
|
|
|
#define STGE_TIMEOUT 1000
|
|
|
|
|
2004-08-22 02:48:18 +04:00
|
|
|
static void stge_start(struct ifnet *);
|
|
|
|
static void stge_watchdog(struct ifnet *);
|
2007-03-04 08:59:00 +03:00
|
|
|
static int stge_ioctl(struct ifnet *, u_long, void *);
|
2004-08-22 02:48:18 +04:00
|
|
|
static int stge_init(struct ifnet *);
|
|
|
|
static void stge_stop(struct ifnet *, int);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2009-09-14 16:02:48 +04:00
|
|
|
static bool stge_shutdown(device_t, int);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2004-08-22 02:48:18 +04:00
|
|
|
static void stge_reset(struct stge_softc *);
|
|
|
|
static void stge_rxdrain(struct stge_softc *);
|
|
|
|
static int stge_add_rxbuf(struct stge_softc *, int);
|
|
|
|
static void stge_read_eeprom(struct stge_softc *, int, uint16_t *);
|
|
|
|
static void stge_tick(void *);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2004-08-22 02:48:18 +04:00
|
|
|
static void stge_stats_update(struct stge_softc *);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2004-08-22 02:48:18 +04:00
|
|
|
static void stge_set_filter(struct stge_softc *);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2004-08-22 02:48:18 +04:00
|
|
|
static int stge_intr(void *);
|
|
|
|
static void stge_txintr(struct stge_softc *);
|
|
|
|
static void stge_rxintr(struct stge_softc *);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
Change MII PHY read/write API from:
int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:
int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);
Now we can test if a read/write operation failed or not by the return value.
In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.
Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:
arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c
Tested with the following device:
axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)
Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url
Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
2019-01-22 06:42:24 +03:00
|
|
|
static int stge_mii_readreg(device_t, int, int, uint16_t *);
|
|
|
|
static int stge_mii_writereg(device_t, int, int, uint16_t);
|
2012-07-22 18:32:49 +04:00
|
|
|
static void stge_mii_statchg(struct ifnet *);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2009-05-06 13:25:14 +04:00
|
|
|
static int stge_match(device_t, cfdata_t, void *);
|
2008-03-21 10:47:43 +03:00
|
|
|
static void stge_attach(device_t, device_t, void *);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
int stge_copy_small = 0;
|
|
|
|
|
2009-05-17 06:08:35 +04:00
|
|
|
CFATTACH_DECL_NEW(stge, sizeof(struct stge_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
stge_match, stge_attach, NULL, NULL);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2008-03-21 10:47:43 +03:00
|
|
|
static uint32_t stge_mii_bitbang_read(device_t);
|
|
|
|
static void stge_mii_bitbang_write(device_t, uint32_t);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2004-08-22 02:48:18 +04:00
|
|
|
static const struct mii_bitbang_ops stge_mii_bitbang_ops = {
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_mii_bitbang_read,
|
|
|
|
stge_mii_bitbang_write,
|
|
|
|
{
|
|
|
|
PC_MgmtData, /* MII_BIT_MDO */
|
|
|
|
PC_MgmtData, /* MII_BIT_MDI */
|
|
|
|
PC_MgmtClk, /* MII_BIT_MDC */
|
|
|
|
PC_MgmtDir, /* MII_BIT_DIR_HOST_PHY */
|
|
|
|
0, /* MII_BIT_DIR_PHY_HOST */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Devices supported by this driver.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static const struct stge_product {
|
2001-07-25 04:11:51 +04:00
|
|
|
pci_vendor_id_t stge_vendor;
|
|
|
|
pci_product_id_t stge_product;
|
|
|
|
const char *stge_name;
|
|
|
|
} stge_products[] = {
|
2005-07-25 04:41:12 +04:00
|
|
|
{ PCI_VENDOR_SUNDANCETI, PCI_PRODUCT_SUNDANCETI_ST1023,
|
|
|
|
"Sundance ST-1023 Gigabit Ethernet" },
|
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
{ PCI_VENDOR_SUNDANCETI, PCI_PRODUCT_SUNDANCETI_ST2021,
|
|
|
|
"Sundance ST-2021 Gigabit Ethernet" },
|
|
|
|
|
|
|
|
{ PCI_VENDOR_TAMARACK, PCI_PRODUCT_TAMARACK_TC9021,
|
|
|
|
"Tamarack TC9021 Gigabit Ethernet" },
|
|
|
|
|
|
|
|
{ PCI_VENDOR_TAMARACK, PCI_PRODUCT_TAMARACK_TC9021_ALT,
|
|
|
|
"Tamarack TC9021 Gigabit Ethernet" },
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The Sundance sample boards use the Sundance vendor ID,
|
|
|
|
* but the Tamarack product ID.
|
|
|
|
*/
|
|
|
|
{ PCI_VENDOR_SUNDANCETI, PCI_PRODUCT_TAMARACK_TC9021,
|
|
|
|
"Sundance TC9021 Gigabit Ethernet" },
|
|
|
|
|
|
|
|
{ PCI_VENDOR_SUNDANCETI, PCI_PRODUCT_TAMARACK_TC9021_ALT,
|
|
|
|
"Sundance TC9021 Gigabit Ethernet" },
|
|
|
|
|
|
|
|
{ PCI_VENDOR_DLINK, PCI_PRODUCT_DLINK_DL4000,
|
|
|
|
"D-Link DL-4000 Gigabit Ethernet" },
|
|
|
|
|
2001-07-25 05:48:14 +04:00
|
|
|
{ PCI_VENDOR_ANTARES, PCI_PRODUCT_ANTARES_TC9021,
|
|
|
|
"Antares Gigabit Ethernet" },
|
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
{ 0, 0,
|
|
|
|
NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct stge_product *
|
|
|
|
stge_lookup(const struct pci_attach_args *pa)
|
|
|
|
{
|
|
|
|
const struct stge_product *sp;
|
|
|
|
|
|
|
|
for (sp = stge_products; sp->stge_name != NULL; sp++) {
|
|
|
|
if (PCI_VENDOR(pa->pa_id) == sp->stge_vendor &&
|
|
|
|
PCI_PRODUCT(pa->pa_id) == sp->stge_product)
|
|
|
|
return (sp);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2004-08-22 02:48:18 +04:00
|
|
|
static int
|
2009-05-06 13:25:14 +04:00
|
|
|
stge_match(device_t parent, cfdata_t cf, void *aux)
|
2001-07-25 04:11:51 +04:00
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
|
|
|
|
if (stge_lookup(pa) != NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2008-03-21 10:47:43 +03:00
|
|
|
stge_attach(device_t parent, device_t self, void *aux)
|
2001-07-25 04:11:51 +04:00
|
|
|
{
|
2008-03-21 10:47:43 +03:00
|
|
|
struct stge_softc *sc = device_private(self);
|
2001-07-25 04:11:51 +04:00
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
pci_chipset_tag_t pc = pa->pa_pc;
|
|
|
|
pci_intr_handle_t ih;
|
|
|
|
const char *intrstr = NULL;
|
|
|
|
bus_space_tag_t iot, memt;
|
|
|
|
bus_space_handle_t ioh, memh;
|
|
|
|
bus_dma_segment_t seg;
|
2011-03-08 22:06:58 +03:00
|
|
|
prop_data_t data;
|
2001-07-25 04:11:51 +04:00
|
|
|
int ioh_valid, memh_valid;
|
|
|
|
int i, rseg, error;
|
|
|
|
const struct stge_product *sp;
|
|
|
|
uint8_t enaddr[ETHER_ADDR_LEN];
|
2014-03-29 23:28:24 +04:00
|
|
|
char intrbuf[PCI_INTRSTR_LEN];
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2007-07-10 00:51:58 +04:00
|
|
|
callout_init(&sc->sc_tick_ch, 0);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
sp = stge_lookup(pa);
|
|
|
|
if (sp == NULL) {
|
|
|
|
printf("\n");
|
|
|
|
panic("ste_attach: impossible");
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_rev = PCI_REVISION(pa->pa_class);
|
|
|
|
|
2012-01-30 23:41:18 +04:00
|
|
|
pci_aprint_devinfo_fancy(pa, NULL, sp->stge_name, 1);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Map the device.
|
|
|
|
*/
|
|
|
|
ioh_valid = (pci_mapreg_map(pa, STGE_PCI_IOBA,
|
|
|
|
PCI_MAPREG_TYPE_IO, 0,
|
|
|
|
&iot, &ioh, NULL, NULL) == 0);
|
|
|
|
memh_valid = (pci_mapreg_map(pa, STGE_PCI_MMBA,
|
|
|
|
PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
|
|
|
|
&memt, &memh, NULL, NULL) == 0);
|
|
|
|
|
|
|
|
if (memh_valid) {
|
|
|
|
sc->sc_st = memt;
|
|
|
|
sc->sc_sh = memh;
|
|
|
|
} else if (ioh_valid) {
|
|
|
|
sc->sc_st = iot;
|
|
|
|
sc->sc_sh = ioh;
|
|
|
|
} else {
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error_dev(self, "unable to map device registers\n");
|
2001-07-25 04:11:51 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_dmat = pa->pa_dmat;
|
|
|
|
|
|
|
|
/* Enable bus mastering. */
|
|
|
|
pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
|
|
|
|
pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
|
|
|
|
PCI_COMMAND_MASTER_ENABLE);
|
|
|
|
|
2006-06-18 03:34:26 +04:00
|
|
|
/* power up chip */
|
2008-03-21 10:47:43 +03:00
|
|
|
if ((error = pci_activate(pa->pa_pc, pa->pa_tag, self, NULL)) &&
|
|
|
|
error != EOPNOTSUPP) {
|
2016-07-07 09:55:38 +03:00
|
|
|
aprint_error_dev(self, "cannot activate %d\n", error);
|
2006-06-18 03:34:26 +04:00
|
|
|
return;
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Map and establish our interrupt.
|
|
|
|
*/
|
|
|
|
if (pci_intr_map(pa, &ih)) {
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error_dev(self, "unable to map interrupt\n");
|
2001-07-25 04:11:51 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-03-29 23:28:24 +04:00
|
|
|
intrstr = pci_intr_string(pc, ih, intrbuf, sizeof(intrbuf));
|
2018-12-09 14:14:01 +03:00
|
|
|
sc->sc_ih = pci_intr_establish_xname(pc, ih, IPL_NET, stge_intr, sc,
|
|
|
|
device_xname(self));
|
2001-07-25 04:11:51 +04:00
|
|
|
if (sc->sc_ih == NULL) {
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error_dev(self, "unable to establish interrupt");
|
2001-07-25 04:11:51 +04:00
|
|
|
if (intrstr != NULL)
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error(" at %s", intrstr);
|
|
|
|
aprint_error("\n");
|
2001-07-25 04:11:51 +04:00
|
|
|
return;
|
|
|
|
}
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_normal_dev(self, "interrupting at %s\n", intrstr);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the control data structures, and create and load the
|
|
|
|
* DMA map for it.
|
|
|
|
*/
|
|
|
|
if ((error = bus_dmamem_alloc(sc->sc_dmat,
|
|
|
|
sizeof(struct stge_control_data), PAGE_SIZE, 0, &seg, 1, &rseg,
|
|
|
|
0)) != 0) {
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error_dev(self,
|
2016-07-07 09:55:38 +03:00
|
|
|
"unable to allocate control data, error = %d\n", error);
|
2001-07-25 04:11:51 +04:00
|
|
|
goto fail_0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,
|
2007-03-04 08:59:00 +03:00
|
|
|
sizeof(struct stge_control_data), (void **)&sc->sc_control_data,
|
2001-07-25 04:11:51 +04:00
|
|
|
BUS_DMA_COHERENT)) != 0) {
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error_dev(self,
|
2016-07-07 09:55:38 +03:00
|
|
|
"unable to map control data, error = %d\n", error);
|
2001-07-25 04:11:51 +04:00
|
|
|
goto fail_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat,
|
|
|
|
sizeof(struct stge_control_data), 1,
|
|
|
|
sizeof(struct stge_control_data), 0, 0, &sc->sc_cddmamap)) != 0) {
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"unable to create control data DMA map, error = %d\n",
|
|
|
|
error);
|
2001-07-25 04:11:51 +04:00
|
|
|
goto fail_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cddmamap,
|
|
|
|
sc->sc_control_data, sizeof(struct stge_control_data), NULL,
|
|
|
|
0)) != 0) {
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"unable to load control data DMA map, error = %d\n",
|
2008-04-10 23:13:36 +04:00
|
|
|
error);
|
2001-07-25 04:11:51 +04:00
|
|
|
goto fail_3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the transmit buffer DMA maps. Note that rev B.3
|
|
|
|
* and earlier seem to have a bug regarding multi-fragment
|
|
|
|
* packets. We need to limit the number of Tx segments on
|
|
|
|
* such chips to 1.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < STGE_NTXDESC; i++) {
|
2001-10-06 04:14:59 +04:00
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat,
|
|
|
|
ETHER_MAX_LEN_JUMBO, STGE_NTXFRAGS, MCLBYTES, 0, 0,
|
2001-07-25 04:11:51 +04:00
|
|
|
&sc->sc_txsoft[i].ds_dmamap)) != 0) {
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"unable to create tx DMA map %d, error = %d\n",
|
|
|
|
i, error);
|
2001-07-25 04:11:51 +04:00
|
|
|
goto fail_4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the receive buffer DMA maps.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < STGE_NRXDESC; i++) {
|
|
|
|
if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
|
|
|
|
MCLBYTES, 0, 0, &sc->sc_rxsoft[i].ds_dmamap)) != 0) {
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_error_dev(self,
|
|
|
|
"unable to create rx DMA map %d, error = %d\n",
|
|
|
|
i, error);
|
2001-07-25 04:11:51 +04:00
|
|
|
goto fail_5;
|
|
|
|
}
|
|
|
|
sc->sc_rxsoft[i].ds_mbuf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine if we're copper or fiber. It affects how we
|
|
|
|
* reset the card.
|
|
|
|
*/
|
|
|
|
if (bus_space_read_4(sc->sc_st, sc->sc_sh, STGE_AsicCtrl) &
|
|
|
|
AC_PhyMedia)
|
|
|
|
sc->sc_usefiber = 1;
|
|
|
|
else
|
|
|
|
sc->sc_usefiber = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the chip to a known state.
|
|
|
|
*/
|
|
|
|
stge_reset(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reading the station address from the EEPROM doesn't seem
|
2005-05-13 10:36:22 +04:00
|
|
|
* to work, at least on my sample boards. Instead, since
|
2001-07-25 04:11:51 +04:00
|
|
|
* the reset sequence does AutoInit, read it from the station
|
2005-07-25 04:41:12 +04:00
|
|
|
* address registers. For Sundance 1023 you can only read it
|
|
|
|
* from EEPROM.
|
2001-07-25 04:11:51 +04:00
|
|
|
*/
|
2005-07-25 04:41:12 +04:00
|
|
|
if (sp->stge_product != PCI_PRODUCT_SUNDANCETI_ST1023) {
|
|
|
|
enaddr[0] = bus_space_read_2(sc->sc_st, sc->sc_sh,
|
|
|
|
STGE_StationAddress0) & 0xff;
|
|
|
|
enaddr[1] = bus_space_read_2(sc->sc_st, sc->sc_sh,
|
|
|
|
STGE_StationAddress0) >> 8;
|
|
|
|
enaddr[2] = bus_space_read_2(sc->sc_st, sc->sc_sh,
|
|
|
|
STGE_StationAddress1) & 0xff;
|
|
|
|
enaddr[3] = bus_space_read_2(sc->sc_st, sc->sc_sh,
|
|
|
|
STGE_StationAddress1) >> 8;
|
|
|
|
enaddr[4] = bus_space_read_2(sc->sc_st, sc->sc_sh,
|
|
|
|
STGE_StationAddress2) & 0xff;
|
|
|
|
enaddr[5] = bus_space_read_2(sc->sc_st, sc->sc_sh,
|
|
|
|
STGE_StationAddress2) >> 8;
|
2005-07-28 20:04:24 +04:00
|
|
|
sc->sc_stge1023 = 0;
|
2005-07-25 09:44:36 +04:00
|
|
|
} else {
|
2011-03-08 22:06:58 +03:00
|
|
|
data = prop_dictionary_get(device_properties(self),
|
|
|
|
"mac-address");
|
|
|
|
if (data != NULL) {
|
|
|
|
/*
|
|
|
|
* Try to get the station address from device
|
|
|
|
* properties first, in case the EEPROM is missing.
|
|
|
|
*/
|
|
|
|
KASSERT(prop_object_type(data) == PROP_TYPE_DATA);
|
|
|
|
KASSERT(prop_data_size(data) == ETHER_ADDR_LEN);
|
|
|
|
(void)memcpy(enaddr, prop_data_data_nocopy(data),
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
} else {
|
|
|
|
uint16_t myaddr[ETHER_ADDR_LEN / 2];
|
|
|
|
for (i = 0; i <ETHER_ADDR_LEN / 2; i++) {
|
2013-03-30 07:21:02 +04:00
|
|
|
stge_read_eeprom(sc,
|
2011-03-08 22:06:58 +03:00
|
|
|
STGE_EEPROM_StationAddress0 + i,
|
|
|
|
&myaddr[i]);
|
|
|
|
myaddr[i] = le16toh(myaddr[i]);
|
|
|
|
}
|
|
|
|
(void)memcpy(enaddr, myaddr, sizeof(enaddr));
|
2005-07-25 04:41:12 +04:00
|
|
|
}
|
2005-07-28 20:04:24 +04:00
|
|
|
sc->sc_stge1023 = 1;
|
2005-07-25 04:41:12 +04:00
|
|
|
}
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2009-05-17 06:08:35 +04:00
|
|
|
aprint_normal_dev(self, "Ethernet address %s\n",
|
2001-07-25 04:11:51 +04:00
|
|
|
ether_sprintf(enaddr));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read some important bits from the PhyCtrl register.
|
|
|
|
*/
|
|
|
|
sc->sc_PhyCtrl = bus_space_read_1(sc->sc_st, sc->sc_sh,
|
|
|
|
STGE_PhyCtrl) & (PC_PhyDuplexPolarity | PC_PhyLnkPolarity);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize our media structures and probe the MII.
|
|
|
|
*/
|
|
|
|
sc->sc_mii.mii_ifp = ifp;
|
|
|
|
sc->sc_mii.mii_readreg = stge_mii_readreg;
|
|
|
|
sc->sc_mii.mii_writereg = stge_mii_writereg;
|
|
|
|
sc->sc_mii.mii_statchg = stge_mii_statchg;
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
sc->sc_ethercom.ec_mii = &sc->sc_mii;
|
|
|
|
ifmedia_init(&sc->sc_mii.mii_media, IFM_IMASK, ether_mediachange,
|
|
|
|
ether_mediastatus);
|
2009-05-17 06:08:35 +04:00
|
|
|
mii_attach(self, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
|
2001-07-28 02:46:20 +04:00
|
|
|
MII_OFFSET_ANY, MIIF_DOPAUSE);
|
2001-07-25 04:11:51 +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);
|
|
|
|
|
|
|
|
ifp = &sc->sc_ethercom.ec_if;
|
2009-05-17 06:08:35 +04:00
|
|
|
strlcpy(ifp->if_xname, device_xname(self), IFNAMSIZ);
|
2001-07-25 04:11:51 +04:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
|
|
|
|
ifp->if_ioctl = stge_ioctl;
|
|
|
|
ifp->if_start = stge_start;
|
|
|
|
ifp->if_watchdog = stge_watchdog;
|
|
|
|
ifp->if_init = stge_init;
|
|
|
|
ifp->if_stop = stge_stop;
|
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The manual recommends disabling early transmit, so we
|
|
|
|
* do. It's disabled anyway, if using IP checksumming,
|
|
|
|
* since the entire packet must be in the FIFO in order
|
|
|
|
* for the chip to perform the checksum.
|
|
|
|
*/
|
|
|
|
sc->sc_txthresh = 0x0fff;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable MWI if the PCI layer tells us to.
|
|
|
|
*/
|
|
|
|
sc->sc_DMACtrl = 0;
|
|
|
|
if ((pa->pa_flags & PCI_FLAGS_MWI_OKAY) == 0)
|
|
|
|
sc->sc_DMACtrl |= DMAC_MWIDisable;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can support 802.1Q VLAN-sized frames and jumbo
|
|
|
|
* Ethernet frames.
|
|
|
|
*
|
|
|
|
* XXX Figure out how to do hw-assisted VLAN tagging in
|
|
|
|
* XXX a reasonable way on this chip.
|
|
|
|
*/
|
|
|
|
sc->sc_ethercom.ec_capabilities |=
|
2003-02-10 12:00:38 +03:00
|
|
|
ETHERCAP_VLAN_MTU | /* XXX ETHERCAP_JUMBO_MTU | */
|
|
|
|
ETHERCAP_VLAN_HWTAGGING;
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We can do IPv4/TCPv4/UDPv4 checksums in hardware.
|
|
|
|
*/
|
2005-05-02 19:34:31 +04:00
|
|
|
sc->sc_ethercom.ec_if.if_capabilities |=
|
|
|
|
IFCAP_CSUM_IPv4_Tx | IFCAP_CSUM_IPv4_Rx |
|
|
|
|
IFCAP_CSUM_TCPv4_Tx | IFCAP_CSUM_TCPv4_Rx |
|
|
|
|
IFCAP_CSUM_UDPv4_Tx | IFCAP_CSUM_UDPv4_Rx;
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the interface.
|
|
|
|
*/
|
|
|
|
if_attach(ifp);
|
2016-12-08 04:12:00 +03:00
|
|
|
if_deferred_start_init(ifp, NULL);
|
2001-07-25 04:11:51 +04:00
|
|
|
ether_ifattach(ifp, enaddr);
|
|
|
|
|
|
|
|
#ifdef STGE_EVENT_COUNTERS
|
|
|
|
/*
|
|
|
|
* Attach event counters.
|
|
|
|
*/
|
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txstall, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txstall");
|
2001-07-25 04:11:51 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txdmaintr, EVCNT_TYPE_INTR,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txdmaintr");
|
2001-07-25 04:11:51 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txindintr, EVCNT_TYPE_INTR,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txindintr");
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_rxintr, EVCNT_TYPE_INTR,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "rxintr");
|
2001-07-25 04:11:51 +04:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txseg1, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txseg1");
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txseg2, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txseg2");
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txseg3, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txseg3");
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txseg4, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txseg4");
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txseg5, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txseg5");
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txsegmore, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txsegmore");
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txcopy, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txcopy");
|
2005-02-27 03:26:58 +03:00
|
|
|
|
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_rxipsum, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "rxipsum");
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_rxtcpsum, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "rxtcpsum");
|
2005-02-27 03:26:58 +03:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_rxudpsum, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "rxudpsum");
|
2001-07-25 04:11:51 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txipsum, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txipsum");
|
2001-07-25 04:11:51 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txtcpsum, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txtcpsum");
|
2001-07-25 04:11:51 +04:00
|
|
|
evcnt_attach_dynamic(&sc->sc_ev_txudpsum, EVCNT_TYPE_MISC,
|
2009-05-17 06:08:35 +04:00
|
|
|
NULL, device_xname(self), "txudpsum");
|
2001-07-25 04:11:51 +04:00
|
|
|
#endif /* STGE_EVENT_COUNTERS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the interface is shutdown during reboot.
|
|
|
|
*/
|
2009-09-14 16:02:48 +04:00
|
|
|
if (pmf_device_register1(self, NULL, NULL, stge_shutdown))
|
|
|
|
pmf_class_network_register(self, ifp);
|
|
|
|
else
|
|
|
|
aprint_error_dev(self, "couldn't establish power handler\n");
|
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free any resources we've allocated during the failed attach
|
|
|
|
* attempt. Do this in reverse order and fall through.
|
|
|
|
*/
|
|
|
|
fail_5:
|
|
|
|
for (i = 0; i < STGE_NRXDESC; i++) {
|
|
|
|
if (sc->sc_rxsoft[i].ds_dmamap != NULL)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat,
|
|
|
|
sc->sc_rxsoft[i].ds_dmamap);
|
|
|
|
}
|
|
|
|
fail_4:
|
|
|
|
for (i = 0; i < STGE_NTXDESC; i++) {
|
|
|
|
if (sc->sc_txsoft[i].ds_dmamap != NULL)
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat,
|
|
|
|
sc->sc_txsoft[i].ds_dmamap);
|
|
|
|
}
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, sc->sc_cddmamap);
|
|
|
|
fail_3:
|
|
|
|
bus_dmamap_destroy(sc->sc_dmat, sc->sc_cddmamap);
|
|
|
|
fail_2:
|
2007-03-04 08:59:00 +03:00
|
|
|
bus_dmamem_unmap(sc->sc_dmat, (void *)sc->sc_control_data,
|
2001-07-25 04:11:51 +04:00
|
|
|
sizeof(struct stge_control_data));
|
|
|
|
fail_1:
|
|
|
|
bus_dmamem_free(sc->sc_dmat, &seg, rseg);
|
|
|
|
fail_0:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_shutdown:
|
|
|
|
*
|
|
|
|
* Make sure the interface is stopped at reboot time.
|
|
|
|
*/
|
2009-09-14 16:02:48 +04:00
|
|
|
static bool
|
|
|
|
stge_shutdown(device_t self, int howto)
|
2001-07-25 04:11:51 +04:00
|
|
|
{
|
2009-09-14 16:02:48 +04:00
|
|
|
struct stge_softc *sc = device_private(self);
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
|
|
|
|
stge_stop(ifp, 1);
|
2011-03-12 19:52:05 +03:00
|
|
|
stge_reset(sc);
|
2009-09-14 16:02:48 +04:00
|
|
|
return true;
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stge_dma_wait(struct stge_softc *sc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < STGE_TIMEOUT; i++) {
|
|
|
|
delay(2);
|
|
|
|
if ((bus_space_read_4(sc->sc_st, sc->sc_sh, STGE_DMACtrl) &
|
|
|
|
DMAC_TxDMAInProg) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == STGE_TIMEOUT)
|
2009-05-17 06:08:35 +04:00
|
|
|
printf("%s: DMA wait timed out\n", device_xname(sc->sc_dev));
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_start: [ifnet interface function]
|
|
|
|
*
|
|
|
|
* Start packet transmission on the interface.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_start(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct stge_softc *sc = ifp->if_softc;
|
|
|
|
struct mbuf *m0;
|
|
|
|
struct stge_descsoft *ds;
|
|
|
|
struct stge_tfd *tfd;
|
|
|
|
bus_dmamap_t dmamap;
|
|
|
|
int error, firsttx, nexttx, opending, seg, totlen;
|
|
|
|
uint64_t csum_flags;
|
|
|
|
|
|
|
|
if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember the previous number of pending transmissions
|
|
|
|
* and the first descriptor we will use.
|
|
|
|
*/
|
|
|
|
opending = sc->sc_txpending;
|
|
|
|
firsttx = STGE_NEXTTX(sc->sc_txlast);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop through the send queue, setting up transmit descriptors
|
|
|
|
* until we drain the queue, or use up all available transmit
|
|
|
|
* descriptors.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
2003-02-10 12:00:38 +03:00
|
|
|
uint64_t tfc;
|
2017-09-26 10:42:05 +03:00
|
|
|
bool have_vtag;
|
|
|
|
uint16_t vtag;
|
2003-02-10 12:00:38 +03:00
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
/*
|
|
|
|
* Grab a packet off the queue.
|
|
|
|
*/
|
|
|
|
IFQ_POLL(&ifp->if_snd, m0);
|
|
|
|
if (m0 == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Leave one unused descriptor at the end of the
|
|
|
|
* list to prevent wrapping completely around.
|
|
|
|
*/
|
|
|
|
if (sc->sc_txpending == (STGE_NTXDESC - 1)) {
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txstall);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-02-10 12:00:38 +03:00
|
|
|
/*
|
|
|
|
* See if we have any VLAN stuff.
|
|
|
|
*/
|
2017-09-26 10:42:05 +03:00
|
|
|
have_vtag = vlan_has_tag(m0);
|
2017-09-28 19:23:57 +03:00
|
|
|
if (have_vtag)
|
|
|
|
vtag = vlan_get_tag(m0);
|
2003-02-10 12:00:38 +03:00
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
/*
|
|
|
|
* Get the last and next available transmit descriptor.
|
|
|
|
*/
|
|
|
|
nexttx = STGE_NEXTTX(sc->sc_txlast);
|
|
|
|
tfd = &sc->sc_txdescs[nexttx];
|
|
|
|
ds = &sc->sc_txsoft[nexttx];
|
|
|
|
|
|
|
|
dmamap = ds->ds_dmamap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Load the DMA map. If this fails, the packet either
|
|
|
|
* didn't fit in the alloted number of segments, or we
|
2004-10-03 01:20:12 +04:00
|
|
|
* were short on resources. For the too-many-segments
|
2001-07-25 04:11:51 +04:00
|
|
|
* case, we simply report an error and drop the packet,
|
|
|
|
* since we can't sanely copy a jumbo packet to a single
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, m0,
|
|
|
|
BUS_DMA_NOWAIT);
|
|
|
|
if (error) {
|
|
|
|
if (error == EFBIG) {
|
|
|
|
printf("%s: Tx packet consumes too many "
|
|
|
|
"DMA segments, dropping...\n",
|
2009-05-17 06:08:35 +04:00
|
|
|
device_xname(sc->sc_dev));
|
2001-07-25 04:11:51 +04:00
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m0);
|
|
|
|
m_freem(m0);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Short on resources, just stop for now.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
IFQ_DEQUEUE(&ifp->if_snd, m0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WE ARE NOW COMMITTED TO TRANSMITTING THE PACKET.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Sync the DMA map. */
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, dmamap, 0, dmamap->dm_mapsize,
|
|
|
|
BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
/* Initialize the fragment list. */
|
|
|
|
for (totlen = 0, seg = 0; seg < dmamap->dm_nsegs; seg++) {
|
|
|
|
tfd->tfd_frags[seg].frag_word0 =
|
|
|
|
htole64(FRAG_ADDR(dmamap->dm_segs[seg].ds_addr) |
|
|
|
|
FRAG_LEN(dmamap->dm_segs[seg].ds_len));
|
|
|
|
totlen += dmamap->dm_segs[seg].ds_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef STGE_EVENT_COUNTERS
|
|
|
|
switch (dmamap->dm_nsegs) {
|
|
|
|
case 1:
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txseg1);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txseg2);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txseg3);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txseg4);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txseg5);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txsegmore);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* STGE_EVENT_COUNTERS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize checksumming flags in the descriptor.
|
|
|
|
* Byte-swap constants so the compiler can optimize.
|
|
|
|
*/
|
|
|
|
csum_flags = 0;
|
|
|
|
if (m0->m_pkthdr.csum_flags & M_CSUM_IPv4) {
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txipsum);
|
2005-05-17 01:35:32 +04:00
|
|
|
csum_flags |= TFD_IPChecksumEnable;
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m0->m_pkthdr.csum_flags & M_CSUM_TCPv4) {
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txtcpsum);
|
2005-05-17 01:35:32 +04:00
|
|
|
csum_flags |= TFD_TCPChecksumEnable;
|
2003-02-10 12:00:38 +03:00
|
|
|
} else if (m0->m_pkthdr.csum_flags & M_CSUM_UDPv4) {
|
2001-07-25 04:11:51 +04:00
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txudpsum);
|
2005-05-17 01:35:32 +04:00
|
|
|
csum_flags |= TFD_UDPChecksumEnable;
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the descriptor and give it to the chip.
|
2003-02-10 12:00:38 +03:00
|
|
|
* Check to see if we have a VLAN tag to insert.
|
2001-07-25 04:11:51 +04:00
|
|
|
*/
|
2003-02-10 12:00:38 +03:00
|
|
|
|
|
|
|
tfc = TFD_FrameId(nexttx) | TFD_WordAlign(/*totlen & */3) |
|
2001-07-25 04:11:51 +04:00
|
|
|
TFD_FragCount(seg) | csum_flags |
|
|
|
|
(((nexttx & STGE_TXINTR_SPACING_MASK) == 0) ?
|
2003-02-10 12:00:38 +03:00
|
|
|
TFD_TxDMAIndicate : 0);
|
2017-09-26 10:42:05 +03:00
|
|
|
if (have_vtag) {
|
2003-02-10 12:00:38 +03:00
|
|
|
#if 0
|
|
|
|
struct ether_header *eh =
|
|
|
|
mtod(m0, struct ether_header *);
|
|
|
|
u_int16_t etype = ntohs(eh->ether_type);
|
|
|
|
printf("%s: xmit (tag %d) etype %x\n",
|
|
|
|
ifp->if_xname, *mtod(n, int *), etype);
|
|
|
|
#endif
|
|
|
|
tfc |= TFD_VLANTagInsert |
|
|
|
|
#ifdef STGE_VLAN_CFI
|
|
|
|
TFD_CFI |
|
|
|
|
#endif
|
2017-09-26 10:42:05 +03:00
|
|
|
TFD_VID(vtag);
|
2003-02-10 12:00:38 +03:00
|
|
|
}
|
|
|
|
tfd->tfd_control = htole64(tfc);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/* Sync the descriptor. */
|
|
|
|
STGE_CDTXSYNC(sc, nexttx,
|
|
|
|
BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Kick the transmit DMA logic.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_DMACtrl,
|
|
|
|
sc->sc_DMACtrl | DMAC_TxDMAPollNow);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store a pointer to the packet so we can free it later.
|
|
|
|
*/
|
|
|
|
ds->ds_mbuf = m0;
|
|
|
|
|
|
|
|
/* Advance the tx pointer. */
|
|
|
|
sc->sc_txpending++;
|
|
|
|
sc->sc_txlast = nexttx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass the packet to any BPF listeners.
|
|
|
|
*/
|
2018-06-26 09:47:57 +03:00
|
|
|
bpf_mtap(ifp, m0, BPF_D_OUT);
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sc_txpending == (STGE_NTXDESC - 1)) {
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* Set a watchdog timer in case the chip flakes out. */
|
|
|
|
ifp->if_timer = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_watchdog: [ifnet interface function]
|
|
|
|
*
|
|
|
|
* Watchdog timer handler.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_watchdog(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct stge_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sweep up first, since we don't interrupt every frame.
|
|
|
|
*/
|
|
|
|
stge_txintr(sc);
|
|
|
|
if (sc->sc_txpending != 0) {
|
2009-05-17 06:08:35 +04:00
|
|
|
printf("%s: device timeout\n", device_xname(sc->sc_dev));
|
2001-07-25 04:11:51 +04:00
|
|
|
ifp->if_oerrors++;
|
|
|
|
|
|
|
|
(void) stge_init(ifp);
|
|
|
|
|
|
|
|
/* Try to get more packets going. */
|
|
|
|
stge_start(ifp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_ioctl: [ifnet interface function]
|
|
|
|
*
|
|
|
|
* Handle control requests from the operator.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static int
|
2007-03-04 08:59:00 +03:00
|
|
|
stge_ioctl(struct ifnet *ifp, u_long cmd, void *data)
|
2001-07-25 04:11:51 +04:00
|
|
|
{
|
|
|
|
struct stge_softc *sc = ifp->if_softc;
|
|
|
|
int s, error;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
error = 0;
|
2008-02-07 04:21:52 +03:00
|
|
|
|
|
|
|
if (cmd != SIOCADDMULTI && cmd != SIOCDELMULTI)
|
|
|
|
;
|
|
|
|
else if (ifp->if_flags & IFF_RUNNING) {
|
|
|
|
/*
|
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
|
|
|
*/
|
|
|
|
stge_set_filter(sc);
|
|
|
|
}
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to get more packets going. */
|
|
|
|
stge_start(ifp);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_intr:
|
|
|
|
*
|
|
|
|
* Interrupt service routine.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static int
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_intr(void *arg)
|
|
|
|
{
|
|
|
|
struct stge_softc *sc = arg;
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
uint32_t txstat;
|
|
|
|
int wantinit;
|
|
|
|
uint16_t isr;
|
|
|
|
|
|
|
|
if ((bus_space_read_2(sc->sc_st, sc->sc_sh, STGE_IntStatus) &
|
|
|
|
IS_InterruptStatus) == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
for (wantinit = 0; wantinit == 0;) {
|
|
|
|
isr = bus_space_read_2(sc->sc_st, sc->sc_sh, STGE_IntStatusAck);
|
|
|
|
if ((isr & sc->sc_IntEnable) == 0)
|
|
|
|
break;
|
2003-02-10 12:00:38 +03:00
|
|
|
|
|
|
|
/* Host interface errors. */
|
2003-02-11 00:10:06 +03:00
|
|
|
if (isr & IS_HostError) {
|
2003-02-10 12:00:38 +03:00
|
|
|
printf("%s: Host interface error\n",
|
2009-05-17 06:08:35 +04:00
|
|
|
device_xname(sc->sc_dev));
|
2003-02-10 12:00:38 +03:00
|
|
|
wantinit = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
/* Receive interrupts. */
|
2003-02-11 00:10:06 +03:00
|
|
|
if (isr & (IS_RxDMAComplete|IS_RFDListEnd)) {
|
2001-07-25 04:11:51 +04:00
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_rxintr);
|
|
|
|
stge_rxintr(sc);
|
2003-02-11 00:10:06 +03:00
|
|
|
if (isr & IS_RFDListEnd) {
|
2001-07-25 04:11:51 +04:00
|
|
|
printf("%s: receive ring overflow\n",
|
2009-05-17 06:08:35 +04:00
|
|
|
device_xname(sc->sc_dev));
|
2001-07-25 04:11:51 +04:00
|
|
|
/*
|
|
|
|
* XXX Should try to recover from this
|
|
|
|
* XXX more gracefully.
|
|
|
|
*/
|
|
|
|
wantinit = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Transmit interrupts. */
|
2003-02-11 00:10:06 +03:00
|
|
|
if (isr & (IS_TxDMAComplete|IS_TxComplete)) {
|
2001-07-25 04:11:51 +04:00
|
|
|
#ifdef STGE_EVENT_COUNTERS
|
2003-02-11 00:10:06 +03:00
|
|
|
if (isr & IS_TxDMAComplete)
|
2001-07-25 04:11:51 +04:00
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txdmaintr);
|
|
|
|
#endif
|
|
|
|
stge_txintr(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Statistics overflow. */
|
2003-02-11 00:10:06 +03:00
|
|
|
if (isr & IS_UpdateStats)
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_stats_update(sc);
|
|
|
|
|
|
|
|
/* Transmission errors. */
|
2003-02-11 00:10:06 +03:00
|
|
|
if (isr & IS_TxComplete) {
|
2001-07-25 04:11:51 +04:00
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_txindintr);
|
|
|
|
for (;;) {
|
|
|
|
txstat = bus_space_read_4(sc->sc_st, sc->sc_sh,
|
|
|
|
STGE_TxStatus);
|
|
|
|
if ((txstat & TS_TxComplete) == 0)
|
|
|
|
break;
|
|
|
|
if (txstat & TS_TxUnderrun) {
|
|
|
|
sc->sc_txthresh++;
|
|
|
|
if (sc->sc_txthresh > 0x0fff)
|
|
|
|
sc->sc_txthresh = 0x0fff;
|
|
|
|
printf("%s: transmit underrun, new "
|
|
|
|
"threshold: %d bytes\n",
|
2009-05-17 06:08:35 +04:00
|
|
|
device_xname(sc->sc_dev),
|
2001-07-25 04:11:51 +04:00
|
|
|
sc->sc_txthresh << 5);
|
|
|
|
}
|
|
|
|
if (txstat & TS_MaxCollisions)
|
|
|
|
printf("%s: excessive collisions\n",
|
2009-05-17 06:08:35 +04:00
|
|
|
device_xname(sc->sc_dev));
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
wantinit = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wantinit)
|
|
|
|
stge_init(ifp);
|
|
|
|
|
|
|
|
bus_space_write_2(sc->sc_st, sc->sc_sh, STGE_IntEnable,
|
|
|
|
sc->sc_IntEnable);
|
|
|
|
|
|
|
|
/* Try to get more packets going. */
|
2016-12-08 04:12:00 +03:00
|
|
|
if_schedule_deferred_start(ifp);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_txintr:
|
|
|
|
*
|
|
|
|
* Helper; handle transmit interrupts.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_txintr(struct stge_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct stge_descsoft *ds;
|
|
|
|
uint64_t control;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through our Tx list and free mbufs for those
|
|
|
|
* frames which have been transmitted.
|
|
|
|
*/
|
|
|
|
for (i = sc->sc_txdirty; sc->sc_txpending != 0;
|
|
|
|
i = STGE_NEXTTX(i), sc->sc_txpending--) {
|
|
|
|
ds = &sc->sc_txsoft[i];
|
|
|
|
|
|
|
|
STGE_CDTXSYNC(sc, i,
|
|
|
|
BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
|
|
|
|
|
|
|
|
control = le64toh(sc->sc_txdescs[i].tfd_control);
|
|
|
|
if ((control & TFD_TFDDone) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the dirty transmit buffer pointer. */
|
|
|
|
sc->sc_txdirty = i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are no more pending transmissions, cancel the watchdog
|
|
|
|
* timer.
|
|
|
|
*/
|
|
|
|
if (sc->sc_txpending == 0)
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_rxintr:
|
|
|
|
*
|
|
|
|
* Helper; handle receive interrupts.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_rxintr(struct stge_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct stge_descsoft *ds;
|
|
|
|
struct mbuf *m, *tailm;
|
|
|
|
uint64_t status;
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
for (i = sc->sc_rxptr;; i = STGE_NEXTRX(i)) {
|
|
|
|
ds = &sc->sc_rxsoft[i];
|
|
|
|
|
|
|
|
STGE_CDRXSYNC(sc, i,
|
|
|
|
BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
|
|
|
|
|
|
|
|
status = le64toh(sc->sc_rxdescs[i].rfd_status);
|
|
|
|
|
|
|
|
if ((status & RFD_RFDDone) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (__predict_false(sc->sc_rxdiscard)) {
|
|
|
|
STGE_INIT_RXDESC(sc, i);
|
|
|
|
if (status & RFD_FrameEnd) {
|
|
|
|
/* Reset our state. */
|
|
|
|
sc->sc_rxdiscard = 0;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
|
|
|
|
ds->ds_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
|
|
|
|
|
|
|
|
m = ds->ds_mbuf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new receive buffer to the ring.
|
|
|
|
*/
|
|
|
|
if (stge_add_rxbuf(sc, i) != 0) {
|
|
|
|
/*
|
|
|
|
* Failed, throw away what we've done so
|
|
|
|
* far, and discard the rest of the packet.
|
|
|
|
*/
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
|
|
|
|
ds->ds_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
|
|
|
|
STGE_INIT_RXDESC(sc, i);
|
|
|
|
if ((status & RFD_FrameEnd) == 0)
|
|
|
|
sc->sc_rxdiscard = 1;
|
|
|
|
if (sc->sc_rxhead != NULL)
|
|
|
|
m_freem(sc->sc_rxhead);
|
|
|
|
STGE_RXCHAIN_RESET(sc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (status & RFD_FrameStart) {
|
|
|
|
KASSERT(sc->sc_rxhead == NULL);
|
|
|
|
KASSERT(sc->sc_rxtailp == &sc->sc_rxhead);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
STGE_RXCHAIN_LINK(sc, m);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is not the end of the packet, keep
|
|
|
|
* looking.
|
|
|
|
*/
|
|
|
|
if ((status & RFD_FrameEnd) == 0) {
|
|
|
|
sc->sc_rxlen += m->m_len;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Okay, we have the entire packet now...
|
|
|
|
*/
|
|
|
|
*sc->sc_rxtailp = NULL;
|
|
|
|
m = sc->sc_rxhead;
|
|
|
|
tailm = sc->sc_rxtail;
|
|
|
|
|
|
|
|
STGE_RXCHAIN_RESET(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the packet had an error, drop it. Note we
|
|
|
|
* count the error later in the periodic stats update.
|
|
|
|
*/
|
|
|
|
if (status & (RFD_RxFIFOOverrun | RFD_RxRuntFrame |
|
|
|
|
RFD_RxAlignmentError | RFD_RxFCSError |
|
|
|
|
RFD_RxLengthError)) {
|
|
|
|
m_freem(m);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No errors.
|
|
|
|
*
|
|
|
|
* Note we have configured the chip to not include
|
|
|
|
* the CRC at the end of the packet.
|
|
|
|
*/
|
|
|
|
len = RFD_RxDMAFrameLen(status);
|
|
|
|
tailm->m_len = len - sc->sc_rxlen;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if (stge_copy_small != 0 && len <= (MHLEN - 2)) {
|
|
|
|
struct mbuf *nm;
|
|
|
|
MGETHDR(nm, M_DONTWAIT, MT_DATA);
|
|
|
|
if (nm == NULL) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
m_freem(m);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nm->m_data += 2;
|
|
|
|
nm->m_pkthdr.len = nm->m_len = len;
|
2007-03-04 08:59:00 +03:00
|
|
|
m_copydata(m, 0, len, mtod(nm, void *));
|
2001-07-25 04:11:51 +04:00
|
|
|
m_freem(m);
|
|
|
|
m = nm;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the incoming checksum information for the packet.
|
|
|
|
*/
|
|
|
|
if (status & RFD_IPDetected) {
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_rxipsum);
|
|
|
|
m->m_pkthdr.csum_flags |= M_CSUM_IPv4;
|
|
|
|
if (status & RFD_IPError)
|
|
|
|
m->m_pkthdr.csum_flags |= M_CSUM_IPv4_BAD;
|
|
|
|
if (status & RFD_TCPDetected) {
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_rxtcpsum);
|
|
|
|
m->m_pkthdr.csum_flags |= M_CSUM_TCPv4;
|
|
|
|
if (status & RFD_TCPError)
|
|
|
|
m->m_pkthdr.csum_flags |=
|
|
|
|
M_CSUM_TCP_UDP_BAD;
|
|
|
|
} else if (status & RFD_UDPDetected) {
|
|
|
|
STGE_EVCNT_INCR(&sc->sc_ev_rxudpsum);
|
|
|
|
m->m_pkthdr.csum_flags |= M_CSUM_UDPv4;
|
|
|
|
if (status & RFD_UDPError)
|
|
|
|
m->m_pkthdr.csum_flags |=
|
|
|
|
M_CSUM_TCP_UDP_BAD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-10 16:27:10 +03:00
|
|
|
m_set_rcvif(m, ifp);
|
2001-07-25 04:11:51 +04:00
|
|
|
m->m_pkthdr.len = len;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass this up to any BPF listeners, but only
|
|
|
|
* pass if up the stack if it's for us.
|
|
|
|
*/
|
2003-02-10 12:00:38 +03:00
|
|
|
#ifdef STGE_VLAN_UNTAG
|
|
|
|
/*
|
|
|
|
* Check for VLAN tagged packets
|
|
|
|
*/
|
2005-02-20 18:56:03 +03:00
|
|
|
if (status & RFD_VLANDetected)
|
2017-09-26 10:42:05 +03:00
|
|
|
vlan_set_tag(m, RFD_TCI(status));
|
2005-02-20 18:56:03 +03:00
|
|
|
|
2003-02-10 12:00:38 +03:00
|
|
|
#endif
|
|
|
|
#if 0
|
|
|
|
if (status & RFD_VLANDetected) {
|
|
|
|
struct ether_header *eh;
|
|
|
|
u_int16_t etype;
|
|
|
|
|
|
|
|
eh = mtod(m, struct ether_header *);
|
|
|
|
etype = ntohs(eh->ether_type);
|
|
|
|
printf("%s: VLANtag detected (TCI %d) etype %x\n",
|
|
|
|
ifp->if_xname, (u_int16_t) RFD_TCI(status),
|
|
|
|
etype);
|
|
|
|
}
|
|
|
|
#endif
|
2001-07-25 04:11:51 +04:00
|
|
|
/* Pass it on. */
|
2016-02-09 11:32:07 +03:00
|
|
|
if_percpuq_enqueue(ifp->if_percpuq, m);
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the receive pointer. */
|
|
|
|
sc->sc_rxptr = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_tick:
|
|
|
|
*
|
|
|
|
* One second timer, used to tick the MII.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_tick(void *arg)
|
|
|
|
{
|
|
|
|
struct stge_softc *sc = arg;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splnet();
|
|
|
|
mii_tick(&sc->sc_mii);
|
|
|
|
stge_stats_update(sc);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
callout_reset(&sc->sc_tick_ch, hz, stge_tick, sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_stats_update:
|
|
|
|
*
|
|
|
|
* Read the TC9021 statistics counters.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_stats_update(struct stge_softc *sc)
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
bus_space_tag_t st = sc->sc_st;
|
|
|
|
bus_space_handle_t sh = sc->sc_sh;
|
|
|
|
|
|
|
|
(void) bus_space_read_4(st, sh, STGE_OctetRcvOk);
|
|
|
|
|
|
|
|
ifp->if_ipackets +=
|
|
|
|
bus_space_read_4(st, sh, STGE_FramesRcvdOk);
|
|
|
|
|
|
|
|
ifp->if_ierrors +=
|
|
|
|
(u_int) bus_space_read_2(st, sh, STGE_FramesLostRxErrors);
|
|
|
|
|
|
|
|
(void) bus_space_read_4(st, sh, STGE_OctetXmtdOk);
|
|
|
|
|
|
|
|
ifp->if_opackets +=
|
|
|
|
bus_space_read_4(st, sh, STGE_FramesXmtdOk);
|
|
|
|
|
|
|
|
ifp->if_collisions +=
|
|
|
|
bus_space_read_4(st, sh, STGE_LateCollisions) +
|
|
|
|
bus_space_read_4(st, sh, STGE_MultiColFrames) +
|
|
|
|
bus_space_read_4(st, sh, STGE_SingleColFrames);
|
|
|
|
|
|
|
|
ifp->if_oerrors +=
|
|
|
|
(u_int) bus_space_read_2(st, sh, STGE_FramesAbortXSColls) +
|
|
|
|
(u_int) bus_space_read_2(st, sh, STGE_FramesWEXDeferal);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_reset:
|
|
|
|
*
|
|
|
|
* Perform a soft reset on the TC9021.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_reset(struct stge_softc *sc)
|
|
|
|
{
|
|
|
|
uint32_t ac;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ac = bus_space_read_4(sc->sc_st, sc->sc_sh, STGE_AsicCtrl);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only assert RstOut if we're fiber. We need GMII clocks
|
|
|
|
* to be present in order for the reset to complete on fiber
|
|
|
|
* cards.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_AsicCtrl,
|
|
|
|
ac | AC_GlobalReset | AC_RxReset | AC_TxReset |
|
|
|
|
AC_DMA | AC_FIFO | AC_Network | AC_Host | AC_AutoInit |
|
|
|
|
(sc->sc_usefiber ? AC_RstOut : 0));
|
|
|
|
|
|
|
|
delay(50000);
|
|
|
|
|
|
|
|
for (i = 0; i < STGE_TIMEOUT; i++) {
|
|
|
|
delay(5000);
|
|
|
|
if ((bus_space_read_4(sc->sc_st, sc->sc_sh, STGE_AsicCtrl) &
|
|
|
|
AC_ResetBusy) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == STGE_TIMEOUT)
|
2009-05-17 06:08:35 +04:00
|
|
|
printf("%s: reset failed to complete\n",
|
|
|
|
device_xname(sc->sc_dev));
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
delay(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_init: [ ifnet interface function ]
|
|
|
|
*
|
|
|
|
* Initialize the interface. Must be called at splnet().
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static int
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_init(struct ifnet *ifp)
|
|
|
|
{
|
|
|
|
struct stge_softc *sc = ifp->if_softc;
|
|
|
|
bus_space_tag_t st = sc->sc_st;
|
|
|
|
bus_space_handle_t sh = sc->sc_sh;
|
|
|
|
struct stge_descsoft *ds;
|
|
|
|
int i, error = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel any pending I/O.
|
|
|
|
*/
|
|
|
|
stge_stop(ifp, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the chip to a known state.
|
|
|
|
*/
|
|
|
|
stge_reset(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the transmit descriptor ring.
|
|
|
|
*/
|
|
|
|
memset(sc->sc_txdescs, 0, sizeof(sc->sc_txdescs));
|
|
|
|
for (i = 0; i < STGE_NTXDESC; i++) {
|
2005-05-17 01:35:32 +04:00
|
|
|
sc->sc_txdescs[i].tfd_next = htole64(
|
|
|
|
STGE_CDTXADDR(sc, STGE_NEXTTX(i)));
|
2001-07-25 04:11:51 +04:00
|
|
|
sc->sc_txdescs[i].tfd_control = htole64(TFD_TFDDone);
|
|
|
|
}
|
|
|
|
sc->sc_txpending = 0;
|
|
|
|
sc->sc_txdirty = 0;
|
|
|
|
sc->sc_txlast = STGE_NTXDESC - 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the receive descriptor and receive job
|
|
|
|
* descriptor rings.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < STGE_NRXDESC; i++) {
|
|
|
|
ds = &sc->sc_rxsoft[i];
|
|
|
|
if (ds->ds_mbuf == NULL) {
|
|
|
|
if ((error = stge_add_rxbuf(sc, i)) != 0) {
|
|
|
|
printf("%s: unable to allocate or map rx "
|
|
|
|
"buffer %d, error = %d\n",
|
2009-05-17 06:08:35 +04:00
|
|
|
device_xname(sc->sc_dev), i, error);
|
2001-07-25 04:11:51 +04:00
|
|
|
/*
|
|
|
|
* XXX Should attempt to run with fewer receive
|
|
|
|
* XXX buffers instead of just failing.
|
|
|
|
*/
|
|
|
|
stge_rxdrain(sc);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
STGE_INIT_RXDESC(sc, i);
|
|
|
|
}
|
|
|
|
sc->sc_rxptr = 0;
|
|
|
|
sc->sc_rxdiscard = 0;
|
|
|
|
STGE_RXCHAIN_RESET(sc);
|
|
|
|
|
|
|
|
/* Set the station address. */
|
2005-06-26 01:43:38 +04:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
bus_space_write_1(st, sh, STGE_StationAddress0 + i,
|
2007-08-27 02:45:55 +04:00
|
|
|
CLLADDR(ifp->if_sadl)[i]);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the statistics masks. Disable all the RMON stats,
|
|
|
|
* and disable selected stats in the non-RMON stats registers.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, STGE_RMONStatisticsMask, 0xffffffff);
|
|
|
|
bus_space_write_4(st, sh, STGE_StatisticsMask,
|
|
|
|
(1U << 1) | (1U << 2) | (1U << 3) | (1U << 4) | (1U << 5) |
|
|
|
|
(1U << 6) | (1U << 7) | (1U << 8) | (1U << 9) | (1U << 10) |
|
|
|
|
(1U << 13) | (1U << 14) | (1U << 15) | (1U << 19) | (1U << 20) |
|
|
|
|
(1U << 21));
|
|
|
|
|
|
|
|
/* Set up the receive filter. */
|
|
|
|
stge_set_filter(sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Give the transmit and receive ring to the chip.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, STGE_TFDListPtrHi, 0); /* NOTE: 32-bit DMA */
|
|
|
|
bus_space_write_4(st, sh, STGE_TFDListPtrLo,
|
|
|
|
STGE_CDTXADDR(sc, sc->sc_txdirty));
|
|
|
|
|
|
|
|
bus_space_write_4(st, sh, STGE_RFDListPtrHi, 0); /* NOTE: 32-bit DMA */
|
|
|
|
bus_space_write_4(st, sh, STGE_RFDListPtrLo,
|
|
|
|
STGE_CDRXADDR(sc, sc->sc_rxptr));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the Tx auto-poll period. It's OK to make this number
|
|
|
|
* large (255 is the max, but we use 127) -- we explicitly kick the
|
|
|
|
* transmit engine when there's actually a packet.
|
|
|
|
*/
|
|
|
|
bus_space_write_1(st, sh, STGE_TxDMAPollPeriod, 127);
|
|
|
|
|
|
|
|
/* ..and the Rx auto-poll period. */
|
|
|
|
bus_space_write_1(st, sh, STGE_RxDMAPollPeriod, 64);
|
|
|
|
|
|
|
|
/* Initialize the Tx start threshold. */
|
|
|
|
bus_space_write_2(st, sh, STGE_TxStartThresh, sc->sc_txthresh);
|
|
|
|
|
2005-06-26 01:43:38 +04:00
|
|
|
/* RX DMA thresholds, from linux */
|
|
|
|
bus_space_write_1(st, sh, STGE_RxDMABurstThresh, 0x30);
|
|
|
|
bus_space_write_1(st, sh, STGE_RxDMAUrgentThresh, 0x30);
|
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
/*
|
|
|
|
* Initialize the Rx DMA interrupt control register. We
|
|
|
|
* request an interrupt after every incoming packet, but
|
2001-07-31 00:12:10 +04:00
|
|
|
* defer it for 32us (64 * 512 ns). When the number of
|
|
|
|
* interrupts pending reaches 8, we stop deferring the
|
|
|
|
* interrupt, and signal it immediately.
|
2001-07-25 04:11:51 +04:00
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, STGE_RxDMAIntCtrl,
|
2001-07-31 00:12:10 +04:00
|
|
|
RDIC_RxFrameCount(8) | RDIC_RxDMAWaitTime(512));
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the interrupt mask.
|
|
|
|
*/
|
2003-02-11 00:10:06 +03:00
|
|
|
sc->sc_IntEnable = IS_HostError | IS_TxComplete | IS_UpdateStats |
|
|
|
|
IS_TxDMAComplete | IS_RxDMAComplete | IS_RFDListEnd;
|
2001-07-25 04:11:51 +04:00
|
|
|
bus_space_write_2(st, sh, STGE_IntStatus, 0xffff);
|
|
|
|
bus_space_write_2(st, sh, STGE_IntEnable, sc->sc_IntEnable);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure the DMA engine.
|
|
|
|
* XXX Should auto-tune TxBurstLimit.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(st, sh, STGE_DMACtrl, sc->sc_DMACtrl |
|
|
|
|
DMAC_TxBurstLimit(3));
|
|
|
|
|
|
|
|
/*
|
2001-07-28 02:46:20 +04:00
|
|
|
* Send a PAUSE frame when we reach 29,696 bytes in the Rx
|
|
|
|
* FIFO, and send an un-PAUSE frame when the FIFO is totally
|
|
|
|
* empty again.
|
2001-07-25 04:11:51 +04:00
|
|
|
*/
|
2001-10-10 07:41:24 +04:00
|
|
|
bus_space_write_2(st, sh, STGE_FlowOnTresh, 29696 / 16);
|
|
|
|
bus_space_write_2(st, sh, STGE_FlowOffThresh, 0);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the maximum frame size.
|
|
|
|
*/
|
|
|
|
bus_space_write_2(st, sh, STGE_MaxFrameSize,
|
|
|
|
ifp->if_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN +
|
|
|
|
((sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
|
|
|
|
ETHER_VLAN_ENCAP_LEN : 0));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize MacCtrl -- do it before setting the media,
|
|
|
|
* as setting the media will actually program the register.
|
|
|
|
*
|
|
|
|
* Note: We have to poke the IFS value before poking
|
|
|
|
* anything else.
|
|
|
|
*/
|
|
|
|
sc->sc_MACCtrl = MC_IFSSelect(0);
|
|
|
|
bus_space_write_4(st, sh, STGE_MACCtrl, sc->sc_MACCtrl);
|
|
|
|
sc->sc_MACCtrl |= MC_StatisticsEnable | MC_TxEnable | MC_RxEnable;
|
2003-02-10 12:00:38 +03:00
|
|
|
#ifdef STGE_VLAN_UNTAG
|
|
|
|
sc->sc_MACCtrl |= MC_AutoVLANuntagging;
|
|
|
|
#endif
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
if (sc->sc_rev >= 6) { /* >= B.2 */
|
|
|
|
/* Multi-frag frame bug work-around. */
|
|
|
|
bus_space_write_2(st, sh, STGE_DebugCtrl,
|
|
|
|
bus_space_read_2(st, sh, STGE_DebugCtrl) | 0x0200);
|
|
|
|
|
|
|
|
/* Tx Poll Now bug work-around. */
|
|
|
|
bus_space_write_2(st, sh, STGE_DebugCtrl,
|
|
|
|
bus_space_read_2(st, sh, STGE_DebugCtrl) | 0x0010);
|
2005-06-26 01:43:38 +04:00
|
|
|
/* XXX ? from linux */
|
|
|
|
bus_space_write_2(st, sh, STGE_DebugCtrl,
|
|
|
|
bus_space_read_2(st, sh, STGE_DebugCtrl) | 0x0020);
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the current media.
|
|
|
|
*/
|
Make many ethernet drivers share the common code for MII media
handling, ether_mediastatus() and ether_mediachange(). Check for
a non-ENXIO error return from mii_mediachg(). (ENXIO indicates
that a PHY is suspended.)
This patch shrinks the source code size by 979 lines. There was
a 5100-byte savings on the NetBSD/i386 kernel configuration, ALL.
I have made a few miscellaneous changes, too:
gem(4): use LIST_EMPTY(), LIST_FOREACH().
mtd(4): handle media ioctls, for a change!
axe(4): do not track link status in sc->axe_link any longer
nfe(4), aue(4), axe(4), udav(4), url(4): do not reset all PHYs
on a change of media
Except for the change to mtd(4), no functional changes are intended.
XXX This patch affects more architectures than I can feasibly
XXX compile and run. I have compiled macppc, sparc64, i386. I
XXX have run the patches on i386 boxen with bnx(4) and sip(4).
XXX Compiling and running on evbmips (MERAKI, ADM5120) is in
XXX progress.
2008-01-20 01:10:14 +03:00
|
|
|
if ((error = ether_mediachange(ifp)) != 0)
|
|
|
|
goto out;
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the one second MII clock.
|
|
|
|
*/
|
|
|
|
callout_reset(&sc->sc_tick_ch, hz, stge_tick, sc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ...all done!
|
|
|
|
*/
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (error)
|
2009-05-17 06:08:35 +04:00
|
|
|
printf("%s: interface not running\n", device_xname(sc->sc_dev));
|
2001-07-25 04:11:51 +04:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_drain:
|
|
|
|
*
|
|
|
|
* Drain the receive queue.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_rxdrain(struct stge_softc *sc)
|
|
|
|
{
|
|
|
|
struct stge_descsoft *ds;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < STGE_NRXDESC; i++) {
|
|
|
|
ds = &sc->sc_rxsoft[i];
|
|
|
|
if (ds->ds_mbuf != NULL) {
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
|
|
|
|
ds->ds_mbuf->m_next = NULL;
|
|
|
|
m_freem(ds->ds_mbuf);
|
|
|
|
ds->ds_mbuf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_stop: [ ifnet interface function ]
|
|
|
|
*
|
|
|
|
* Stop transmission on the interface.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_stop(struct ifnet *ifp, int disable)
|
|
|
|
{
|
|
|
|
struct stge_softc *sc = ifp->if_softc;
|
|
|
|
struct stge_descsoft *ds;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the one second clock.
|
|
|
|
*/
|
|
|
|
callout_stop(&sc->sc_tick_ch);
|
|
|
|
|
|
|
|
/* Down the MII. */
|
|
|
|
mii_down(&sc->sc_mii);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable interrupts.
|
|
|
|
*/
|
|
|
|
bus_space_write_2(sc->sc_st, sc->sc_sh, STGE_IntEnable, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop receiver, transmitter, and stats update.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_MACCtrl,
|
|
|
|
MC_StatisticsDisable | MC_TxDisable | MC_RxDisable);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the transmit and receive DMA.
|
|
|
|
*/
|
|
|
|
stge_dma_wait(sc);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_TFDListPtrHi, 0);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_TFDListPtrLo, 0);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_RFDListPtrHi, 0);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_RFDListPtrLo, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release any queued transmit buffers.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < STGE_NTXDESC; i++) {
|
|
|
|
ds = &sc->sc_txsoft[i];
|
|
|
|
if (ds->ds_mbuf != NULL) {
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
|
|
|
|
m_freem(ds->ds_mbuf);
|
|
|
|
ds->ds_mbuf = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the interface down and cancel the watchdog timer.
|
|
|
|
*/
|
|
|
|
ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
|
|
|
|
ifp->if_timer = 0;
|
2008-03-12 02:58:06 +03:00
|
|
|
|
|
|
|
if (disable)
|
|
|
|
stge_rxdrain(sc);
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
stge_eeprom_wait(struct stge_softc *sc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < STGE_TIMEOUT; i++) {
|
|
|
|
delay(1000);
|
|
|
|
if ((bus_space_read_2(sc->sc_st, sc->sc_sh, STGE_EepromCtrl) &
|
|
|
|
EC_EepromBusy) == 0)
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_read_eeprom:
|
|
|
|
*
|
|
|
|
* Read data from the serial EEPROM.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_read_eeprom(struct stge_softc *sc, int offset, uint16_t *data)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (stge_eeprom_wait(sc))
|
|
|
|
printf("%s: EEPROM failed to come ready\n",
|
2009-05-17 06:08:35 +04:00
|
|
|
device_xname(sc->sc_dev));
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
bus_space_write_2(sc->sc_st, sc->sc_sh, STGE_EepromCtrl,
|
|
|
|
EC_EepromAddress(offset) | EC_EepromOpcode(EC_OP_RR));
|
|
|
|
if (stge_eeprom_wait(sc))
|
|
|
|
printf("%s: EEPROM read timed out\n",
|
2009-05-17 06:08:35 +04:00
|
|
|
device_xname(sc->sc_dev));
|
2001-07-25 04:11:51 +04:00
|
|
|
*data = bus_space_read_2(sc->sc_st, sc->sc_sh, STGE_EepromData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_add_rxbuf:
|
|
|
|
*
|
|
|
|
* Add a receive buffer to the indicated descriptor.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static int
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_add_rxbuf(struct stge_softc *sc, int idx)
|
|
|
|
{
|
|
|
|
struct stge_descsoft *ds = &sc->sc_rxsoft[idx];
|
|
|
|
struct mbuf *m;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
2005-02-27 03:26:58 +03:00
|
|
|
if (m == NULL)
|
2001-07-25 04:11:51 +04:00
|
|
|
return (ENOBUFS);
|
|
|
|
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if ((m->m_flags & M_EXT) == 0) {
|
|
|
|
m_freem(m);
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
|
|
|
|
m->m_data = m->m_ext.ext_buf + 2;
|
|
|
|
m->m_len = MCLBYTES - 2;
|
|
|
|
|
|
|
|
if (ds->ds_mbuf != NULL)
|
|
|
|
bus_dmamap_unload(sc->sc_dmat, ds->ds_dmamap);
|
|
|
|
|
|
|
|
ds->ds_mbuf = m;
|
|
|
|
|
|
|
|
error = bus_dmamap_load(sc->sc_dmat, ds->ds_dmamap,
|
|
|
|
m->m_ext.ext_buf, m->m_ext.ext_size, NULL, BUS_DMA_NOWAIT);
|
|
|
|
if (error) {
|
|
|
|
printf("%s: can't load rx DMA map %d, error = %d\n",
|
2009-05-17 06:08:35 +04:00
|
|
|
device_xname(sc->sc_dev), idx, error);
|
2001-07-25 04:11:51 +04:00
|
|
|
panic("stge_add_rxbuf"); /* XXX */
|
|
|
|
}
|
|
|
|
|
|
|
|
bus_dmamap_sync(sc->sc_dmat, ds->ds_dmamap, 0,
|
|
|
|
ds->ds_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
|
|
|
|
|
|
|
|
STGE_INIT_RXDESC(sc, idx);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_set_filter:
|
|
|
|
*
|
|
|
|
* Set up the receive filter.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2001-07-25 04:11:51 +04:00
|
|
|
stge_set_filter(struct stge_softc *sc)
|
|
|
|
{
|
|
|
|
struct ethercom *ec = &sc->sc_ethercom;
|
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
|
|
|
uint32_t crc;
|
|
|
|
uint32_t mchash[2];
|
|
|
|
|
|
|
|
sc->sc_ReceiveMode = RM_ReceiveUnicast;
|
|
|
|
if (ifp->if_flags & IFF_BROADCAST)
|
|
|
|
sc->sc_ReceiveMode |= RM_ReceiveBroadcast;
|
|
|
|
|
2005-07-25 04:41:12 +04:00
|
|
|
/* XXX: ST1023 only works in promiscuous mode */
|
2005-07-28 20:04:24 +04:00
|
|
|
if (sc->sc_stge1023)
|
2005-07-25 04:41:12 +04:00
|
|
|
ifp->if_flags |= IFF_PROMISC;
|
|
|
|
|
2001-07-25 04:11:51 +04:00
|
|
|
if (ifp->if_flags & IFF_PROMISC) {
|
|
|
|
sc->sc_ReceiveMode |= RM_ReceiveAllFrames;
|
|
|
|
goto allmulti;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the multicast address filter by passing all multicast
|
|
|
|
* addresses through a CRC generator, and then using the low-order
|
|
|
|
* 6 bits as an index into the 64 bit multicast hash table. The
|
|
|
|
* high order bits select the register, while the rest of the bits
|
|
|
|
* select the bit within the register.
|
|
|
|
*/
|
|
|
|
|
|
|
|
memset(mchash, 0, sizeof(mchash));
|
|
|
|
|
|
|
|
ETHER_FIRST_MULTI(step, ec, enm);
|
|
|
|
if (enm == NULL)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
while (enm != NULL) {
|
|
|
|
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
crc = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN);
|
|
|
|
|
|
|
|
/* Just want the 6 least significant bits. */
|
|
|
|
crc &= 0x3f;
|
|
|
|
|
|
|
|
/* Set the corresponding bit in the hash table. */
|
|
|
|
mchash[crc >> 5] |= 1 << (crc & 0x1f);
|
|
|
|
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sc_ReceiveMode |= RM_ReceiveMulticastHash;
|
|
|
|
|
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
allmulti:
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
sc->sc_ReceiveMode |= RM_ReceiveMulticast;
|
|
|
|
|
|
|
|
done:
|
|
|
|
if ((ifp->if_flags & IFF_ALLMULTI) == 0) {
|
|
|
|
/*
|
|
|
|
* Program the multicast hash table.
|
|
|
|
*/
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_HashTable0,
|
|
|
|
mchash[0]);
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_HashTable1,
|
|
|
|
mchash[1]);
|
|
|
|
}
|
|
|
|
|
2003-02-10 12:00:38 +03:00
|
|
|
bus_space_write_2(sc->sc_st, sc->sc_sh, STGE_ReceiveMode,
|
2001-07-25 04:11:51 +04:00
|
|
|
sc->sc_ReceiveMode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_mii_readreg: [mii interface function]
|
|
|
|
*
|
|
|
|
* Read a PHY register on the MII of the TC9021.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static int
|
Change MII PHY read/write API from:
int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:
int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);
Now we can test if a read/write operation failed or not by the return value.
In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.
Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:
arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c
Tested with the following device:
axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)
Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url
Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
2019-01-22 06:42:24 +03:00
|
|
|
stge_mii_readreg(device_t self, int phy, int reg, uint16_t *val)
|
2001-07-25 04:11:51 +04:00
|
|
|
{
|
|
|
|
|
Change MII PHY read/write API from:
int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:
int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);
Now we can test if a read/write operation failed or not by the return value.
In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.
Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:
arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c
Tested with the following device:
axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)
Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url
Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
2019-01-22 06:42:24 +03:00
|
|
|
return mii_bitbang_readreg(self, &stge_mii_bitbang_ops, phy, reg, val);
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_mii_writereg: [mii interface function]
|
|
|
|
*
|
|
|
|
* Write a PHY register on the MII of the TC9021.
|
|
|
|
*/
|
Change MII PHY read/write API from:
int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:
int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);
Now we can test if a read/write operation failed or not by the return value.
In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.
Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:
arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c
Tested with the following device:
axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)
Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url
Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
2019-01-22 06:42:24 +03:00
|
|
|
static int
|
|
|
|
stge_mii_writereg(device_t self, int phy, int reg, uint16_t val)
|
2001-07-25 04:11:51 +04:00
|
|
|
{
|
|
|
|
|
Change MII PHY read/write API from:
int (*mii_readreg_t)(device_t, int, int);
void (*mii_writereg_t)(device_t, int, int, int);
to:
int (*mii_readreg_t)(device_t, int, int, uint16_t *);
int (*mii_writereg_t)(device_t, int, int, uint16_t);
Now we can test if a read/write operation failed or not by the return value.
In 802.3 spec says that the PHY shall not respond to read/write transaction
to the unimplemented register(22.2.4.3). Detecting timeout can be used to
check whether a register is implemented or not (if the register conforms to
the spec). ukphy(4) can be used this for MII_MMDACR and MII_MMDAADR.
Note that I noticed that the following code do infinite loop in the
read/wirte function. If it accesses unimplemented PHY register, it will hang.
It should be fixed:
arm/at91/at91emac.c
arm/ep93xx/epe.c
arm/omap/omapl1x_emac.c
mips/ralink/ralink_eth.c
arch/powerpc/booke/dev/pq3etsec.c(read)
dev/cadence/if_cemac.c <- hkenken
dev/ic/lan9118.c
Tested with the following device:
axe+ukphy
axe+rgephy
axen+rgephy (tested by Andrius V)
wm+atphy
wm+ukphy
wm+igphy
wm+ihphy
wm+makphy
sk+makphy
sk+brgphy
sk+gentbi
msk+makphy
sip+icsphy
sip+ukphy
re+rgephy
bge+brgphy
bnx+brgphy
gsip+gphyter
rtk+rlphy
fxp+inphy (tested by Andrius V)
tlp+acphy
ex+exphy
epic+qsphy
vge+ciphy (tested by Andrius V)
vr+ukphy (tested by Andrius V)
vte+ukphy (tested by Andrius V)
Not tested (MAC):
arm:at91emac
arm:cemac
arm:epe
arm:geminigmac
arm:enet
arm:cpsw
arm:emac(omac)
arm:emac(sunxi)
arm:npe
evbppc:temac
macppc:bm
macppc:gm
mips:aumac
mips:ae
mips:cnmac
mips:reth
mips:sbmac
playstation2:smap
powerpc:tsec
powerpc:emac(ibm4xx)
sgimips:mec
sparc:be
sf
ne(ax88190, dl10019)
awge
ep
gem
hme
smsh
mtd
sm
age
alc
ale
bce
cas
et
jme
lii
nfe
pcn
ste
stge
tl
xi
aue
mue
smsc
udav
url
Not tested (PHY):
amhphy
bmtphy
dmphy
etphy
glxtphy
ikphy
iophy
lxtphy
nsphyter
pnaphy
rdcphy
sqphy
tlphy
tqphy
urlphy
2019-01-22 06:42:24 +03:00
|
|
|
return mii_bitbang_writereg(self, &stge_mii_bitbang_ops, phy, reg,
|
|
|
|
val);
|
2001-07-25 04:11:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_mii_statchg: [mii interface function]
|
|
|
|
*
|
|
|
|
* Callback from MII layer when media changes.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2012-07-22 18:32:49 +04:00
|
|
|
stge_mii_statchg(struct ifnet *ifp)
|
2001-07-25 04:11:51 +04:00
|
|
|
{
|
2012-07-22 18:32:49 +04:00
|
|
|
struct stge_softc *sc = ifp->if_softc;
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
if (sc->sc_mii.mii_media_active & IFM_FDX)
|
|
|
|
sc->sc_MACCtrl |= MC_DuplexSelect;
|
|
|
|
else
|
|
|
|
sc->sc_MACCtrl &= ~MC_DuplexSelect;
|
|
|
|
|
|
|
|
/* XXX 802.1x flow-control? */
|
|
|
|
|
|
|
|
bus_space_write_4(sc->sc_st, sc->sc_sh, STGE_MACCtrl, sc->sc_MACCtrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sste_mii_bitbang_read: [mii bit-bang interface function]
|
|
|
|
*
|
|
|
|
* Read the MII serial port for the MII bit-bang module.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static uint32_t
|
2008-03-21 10:47:43 +03:00
|
|
|
stge_mii_bitbang_read(device_t self)
|
2001-07-25 04:11:51 +04:00
|
|
|
{
|
2008-03-21 10:47:43 +03:00
|
|
|
struct stge_softc *sc = device_private(self);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
return (bus_space_read_1(sc->sc_st, sc->sc_sh, STGE_PhyCtrl));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stge_mii_bitbang_write: [mii big-bang interface function]
|
|
|
|
*
|
|
|
|
* Write the MII serial port for the MII bit-bang module.
|
|
|
|
*/
|
2004-08-22 02:48:18 +04:00
|
|
|
static void
|
2008-03-21 10:47:43 +03:00
|
|
|
stge_mii_bitbang_write(device_t self, uint32_t val)
|
2001-07-25 04:11:51 +04:00
|
|
|
{
|
2008-03-21 10:47:43 +03:00
|
|
|
struct stge_softc *sc = device_private(self);
|
2001-07-25 04:11:51 +04:00
|
|
|
|
|
|
|
bus_space_write_1(sc->sc_st, sc->sc_sh, STGE_PhyCtrl,
|
|
|
|
val | sc->sc_PhyCtrl);
|
|
|
|
}
|