#include "bpfilter.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
#include <sys/syslog.h>
#include <sys/socket.h>
#include <sys/device.h>
#include <sys/timeout.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <machine/bus.h>
#include <machine/intr.h>
#include <net/if.h>
#include <net/if_media.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#if NBPFILTER > 0
#include <net/bpf.h>
#endif
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
#include <dev/mii/mii_bitbang.h>
#include <dev/ic/smc91cxxreg.h>
#include <dev/ic/smc91cxxvar.h>
#ifndef __BUS_SPACE_HAS_STREAM_METHODS
#define bus_space_write_multi_stream_2 bus_space_write_multi_2
#define bus_space_write_multi_stream_4 bus_space_write_multi_4
#define bus_space_read_multi_stream_2 bus_space_read_multi_2
#define bus_space_read_multi_stream_4 bus_space_read_multi_4
#endif
#define SMC91CXX_SW_PAD
const char *smc91cxx_idstrs[] = {
NULL,
NULL,
NULL,
"SMC91C90/91C92",
"SMC91C94/91C96",
"SMC91C95",
NULL,
"SMC91C100",
"SMC91C100FD",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
};
const uint64_t smc91cxx_media[] = {
IFM_ETHER|IFM_10_T,
IFM_ETHER|IFM_10_5,
};
#define NSMC91CxxMEDIA (sizeof(smc91cxx_media) / sizeof(smc91cxx_media[0]))
u_int32_t smc91cxx_mii_bitbang_read(struct device *);
void smc91cxx_mii_bitbang_write(struct device *, u_int32_t);
const struct mii_bitbang_ops smc91cxx_mii_bitbang_ops = {
smc91cxx_mii_bitbang_read,
smc91cxx_mii_bitbang_write,
{
MR_MDO,
MR_MDI,
MR_MCLK,
MR_MDOE,
0,
}
};
struct cfdriver sm_cd = {
NULL, "sm", DV_IFNET
};
int smc91cxx_mii_readreg(struct device *, int, int);
void smc91cxx_mii_writereg(struct device *, int, int, int);
void smc91cxx_statchg(struct device *);
void smc91cxx_tick(void *);
int smc91cxx_mediachange(struct ifnet *);
void smc91cxx_mediastatus(struct ifnet *, struct ifmediareq *);
int smc91cxx_set_media(struct smc91cxx_softc *, uint64_t);
void smc91cxx_read(struct smc91cxx_softc *);
void smc91cxx_reset(struct smc91cxx_softc *);
void smc91cxx_start(struct ifnet *);
void smc91cxx_watchdog(struct ifnet *);
int smc91cxx_ioctl(struct ifnet *, u_long, caddr_t);
void
smc91cxx_attach(struct smc91cxx_softc *sc, u_int8_t *myea)
{
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
bus_space_tag_t bst = sc->sc_bst;
bus_space_handle_t bsh = sc->sc_bsh;
struct ifmedia *ifm = &sc->sc_mii.mii_media;
u_int32_t miicapabilities;
u_int16_t tmp;
int i, aui;
const char *idstr;
smc91cxx_stop(sc);
SMC_SELECT_BANK(sc, 3);
tmp = bus_space_read_2(bst, bsh, REVISION_REG_W);
sc->sc_chipid = RR_ID(tmp);
if ((tmp & BSR_DETECT_MASK) != BSR_DETECT_VALUE) {
idstr = NULL;
printf("%s: invalid BSR 0x%04x\n", sc->sc_dev.dv_xname, tmp);
} else
idstr = smc91cxx_idstrs[RR_ID(tmp)];
#ifdef SMC_DEBUG
printf("\n%s: ", sc->sc_dev.dv_xname);
if (idstr != NULL)
printf("%s, ", idstr);
else
printf("unknown chip id %d, ", sc->sc_chipid);
printf("revision %d", RR_REV(tmp));
#endif
SMC_SELECT_BANK(sc, 1);
if (myea == NULL) {
for (i = 0; i < ETHER_ADDR_LEN; i += 2) {
tmp = bus_space_read_2(bst, bsh, IAR_ADDR0_REG_W + i);
sc->sc_arpcom.ac_enaddr[i + 1] = (tmp >>8) & 0xff;
sc->sc_arpcom.ac_enaddr[i] = tmp & 0xff;
}
} else {
bcopy(myea, sc->sc_arpcom.ac_enaddr, ETHER_ADDR_LEN);
}
printf(": address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr));
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
ifp->if_softc = sc;
ifp->if_start = smc91cxx_start;
ifp->if_ioctl = smc91cxx_ioctl;
ifp->if_watchdog = smc91cxx_watchdog;
ifp->if_flags =
IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
if_attach(ifp);
ether_ifattach(ifp);
sc->sc_mii.mii_ifp = ifp;
sc->sc_mii.mii_readreg = smc91cxx_mii_readreg;
sc->sc_mii.mii_writereg = smc91cxx_mii_writereg;
sc->sc_mii.mii_statchg = smc91cxx_statchg;
ifmedia_init(ifm, 0, smc91cxx_mediachange, smc91cxx_mediastatus);
SMC_SELECT_BANK(sc, 1);
tmp = bus_space_read_2(bst, bsh, CONFIG_REG_W);
miicapabilities = BMSR_MEDIAMASK|BMSR_ANEG;
switch (sc->sc_chipid) {
case CHIP_91100:
miicapabilities &= ~(BMSR_100TXFDX | BMSR_10TFDX);
case CHIP_91100FD:
if (tmp & CR_MII_SELECT) {
#ifdef SMC_DEBUG
printf("%s: default media MII\n",
sc->sc_dev.dv_xname);
#endif
mii_attach(&sc->sc_dev, &sc->sc_mii, miicapabilities,
MII_PHY_ANY, MII_OFFSET_ANY, 0);
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);
}
sc->sc_flags |= SMC_FLAGS_HAS_MII;
break;
}
default:
aui = tmp & CR_AUI_SELECT;
#ifdef SMC_DEBUG
printf("%s: default media %s\n", sc->sc_dev.dv_xname,
aui ? "AUI" : "UTP");
#endif
for (i = 0; i < NSMC91CxxMEDIA; i++)
ifmedia_add(ifm, smc91cxx_media[i], 0, NULL);
ifmedia_set(ifm, IFM_ETHER | (aui ? IFM_10_5 : IFM_10_T));
break;
}
sc->sc_flags |= SMC_FLAGS_ATTACHED;
}
int
smc91cxx_mediachange(struct ifnet *ifp)
{
struct smc91cxx_softc *sc = ifp->if_softc;
return (smc91cxx_set_media(sc, sc->sc_mii.mii_media.ifm_media));
}
int
smc91cxx_set_media(struct smc91cxx_softc *sc, uint64_t media)
{
bus_space_tag_t bst = sc->sc_bst;
bus_space_handle_t bsh = sc->sc_bsh;
u_int16_t tmp;
if ((sc->sc_flags & SMC_FLAGS_ENABLED) == 0)
return (0);
if (IFM_TYPE(media) != IFM_ETHER)
return (EINVAL);
if (sc->sc_flags & SMC_FLAGS_HAS_MII)
return (mii_mediachg(&sc->sc_mii));
switch (IFM_SUBTYPE(media)) {
case IFM_10_T:
case IFM_10_5:
SMC_SELECT_BANK(sc, 1);
tmp = bus_space_read_2(bst, bsh, CONFIG_REG_W);
if (IFM_SUBTYPE(media) == IFM_10_5)
tmp |= CR_AUI_SELECT;
else
tmp &= ~CR_AUI_SELECT;
bus_space_write_2(bst, bsh, CONFIG_REG_W, tmp);
delay(20000);
break;
default:
return (EINVAL);
}
return (0);
}
void
smc91cxx_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
{
struct smc91cxx_softc *sc = ifp->if_softc;
bus_space_tag_t bst = sc->sc_bst;
bus_space_handle_t bsh = sc->sc_bsh;
u_int16_t tmp;
if ((sc->sc_flags & SMC_FLAGS_ENABLED) == 0) {
ifmr->ifm_active = IFM_ETHER | IFM_NONE;
ifmr->ifm_status = 0;
return;
}
if (sc->sc_flags & SMC_FLAGS_HAS_MII) {
mii_pollstat(&sc->sc_mii);
ifmr->ifm_active = sc->sc_mii.mii_media_active;
ifmr->ifm_status = sc->sc_mii.mii_media_status;
return;
}
SMC_SELECT_BANK(sc, 1);
tmp = bus_space_read_2(bst, bsh, CONFIG_REG_W);
ifmr->ifm_active =
IFM_ETHER | ((tmp & CR_AUI_SELECT) ? IFM_10_5 : IFM_10_T);
}
void
smc91cxx_init(struct smc91cxx_softc *sc)
{
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
bus_space_tag_t bst = sc->sc_bst;
bus_space_handle_t bsh = sc->sc_bsh;
u_int16_t tmp;
int s, i;
s = splnet();
SMC_SELECT_BANK(sc, 0);
bus_space_write_2(bst, bsh, RECV_CONTROL_REG_W, RCR_SOFTRESET);
delay(100);
bus_space_write_2(bst, bsh, RECV_CONTROL_REG_W, 0);
delay(200);
bus_space_write_2(bst, bsh, TXMIT_CONTROL_REG_W, 0);
SMC_SELECT_BANK(sc, 1);
for (i = 0; i < ETHER_ADDR_LEN; i++ )
bus_space_write_1(bst, bsh, IAR_ADDR0_REG_W + i,
sc->sc_arpcom.ac_enaddr[i]);
bus_space_write_2(bst, bsh, CONTROL_REG_W, (CTR_AUTO_RELEASE |
CTR_TE_ENABLE | CTR_CR_ENABLE | CTR_LE_ENABLE));
SMC_SELECT_BANK(sc, 2);
bus_space_write_2(bst, bsh, MMU_CMD_REG_W, MMUCR_RESET);
while (bus_space_read_2(bst, bsh, MMU_CMD_REG_W) & MMUCR_BUSY)
;
bus_space_write_1(bst, bsh, INTR_MASK_REG_B, 0);
smc91cxx_set_media(sc, sc->sc_mii.mii_media.ifm_cur->ifm_media);
SMC_SELECT_BANK(sc, 0);
tmp = RCR_ENABLE | RCR_STRIP_CRC | RCR_ALMUL;
if (ifp->if_flags & IFF_PROMISC)
tmp |= RCR_PROMISC;
bus_space_write_2(bst, bsh, RECV_CONTROL_REG_W, tmp);
tmp = TCR_ENABLE;
#ifndef SMC91CXX_SW_PAD
tmp |= TCR_PAD_ENABLE;
#endif
bus_space_write_2(bst, bsh, TXMIT_CONTROL_REG_W, tmp);
SMC_SELECT_BANK(sc, 2);
bus_space_write_1(bst, bsh, INTR_MASK_REG_B,
IM_EPH_INT | IM_RX_OVRN_INT | IM_RCV_INT | IM_TX_INT);
ifp->if_flags |= IFF_RUNNING;
ifq_clr_oactive(&ifp->if_snd);
if (sc->sc_flags & SMC_FLAGS_HAS_MII) {
timeout_set(&sc->sc_mii_timeout, smc91cxx_tick, sc);
timeout_add_sec(&sc->sc_mii_timeout, 1);
}
smc91cxx_start(ifp);
splx(s);
}
void
smc91cxx_start(struct ifnet *ifp)
{
struct smc91cxx_softc *sc = ifp->if_softc;
bus_space_tag_t bst = sc->sc_bst;
bus_space_handle_t bsh = sc->sc_bsh;
u_int len;
struct mbuf *m, *top;
u_int16_t length, npages;
u_int8_t packetno;
int timo, pad;
if (!(ifp->if_flags & IFF_RUNNING) || ifq_is_oactive(&ifp->if_snd))
return;
again:
m = ifq_deq_begin(&ifp->if_snd);
if (m == NULL)
return;
for (len = 0, top = m; m != NULL; m = m->m_next)
len += m->m_len;
pad = (len & 1);
if ((len + pad) > (ETHER_MAX_LEN - ETHER_CRC_LEN)) {
printf("%s: large packet discarded\n", sc->sc_dev.dv_xname);
ifp->if_oerrors++;
ifq_deq_commit(&ifp->if_snd, m);
m_freem(m);
goto readcheck;
}
#ifdef SMC91CXX_SW_PAD
if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN))
pad = ETHER_MIN_LEN - ETHER_CRC_LEN - len;
#endif
length = pad + len;
npages = (length + 6) >> 8;
SMC_SELECT_BANK(sc, 2);
bus_space_write_2(bst, bsh, MMU_CMD_REG_W, MMUCR_ALLOC | npages);
timo = MEMORY_WAIT_TIME;
do {
if (bus_space_read_1(bst, bsh, INTR_STAT_REG_B) & IM_ALLOC_INT)
break;
delay(1);
} while (--timo);
packetno = bus_space_read_1(bst, bsh, ALLOC_RESULT_REG_B);
if (packetno & ARR_FAILED || timo == 0) {
bus_space_write_1(bst, bsh, INTR_MASK_REG_B,
bus_space_read_1(bst, bsh, INTR_MASK_REG_B) | IM_ALLOC_INT);
ifp->if_timer = 5;
ifq_deq_rollback(&ifp->if_snd, m);
ifq_set_oactive(&ifp->if_snd);
return;
}
bus_space_write_1(bst, bsh, PACKET_NUM_REG_B, packetno);
bus_space_write_2(bst, bsh, POINTER_REG_W, PTR_AUTOINC );
bus_space_write_2(bst, bsh, DATA_REG_W, 0);
bus_space_write_1(bst, bsh, DATA_REG_B, (length + 6) & 0xff);
bus_space_write_1(bst, bsh, DATA_REG_B, ((length + 6) >> 8) & 0xff);
ifq_deq_commit(&ifp->if_snd, m);
for (top = m; m != NULL; m = m->m_next) {
if (m->m_len > 1)
bus_space_write_multi_stream_2(bst, bsh, DATA_REG_W,
mtod(m, u_int16_t *), m->m_len >> 1);
if (m->m_len & 1)
bus_space_write_1(bst, bsh, DATA_REG_B,
*(u_int8_t *)(mtod(m, u_int8_t *) + (m->m_len - 1)));
}
#ifdef SMC91CXX_SW_PAD
while (pad > 1) {
bus_space_write_2(bst, bsh, DATA_REG_W, 0);
pad -= 2;
}
if (pad)
bus_space_write_1(bst, bsh, DATA_REG_B, 0);
#endif
bus_space_write_2(bst, bsh, DATA_REG_W, 0);
bus_space_write_1(bst, bsh, INTR_MASK_REG_B,
bus_space_read_1(bst, bsh, INTR_MASK_REG_B) |
IM_TX_INT | IM_TX_EMPTY_INT);
bus_space_write_2(bst, bsh, MMU_CMD_REG_W, MMUCR_ENQUEUE);
ifp->if_timer = 5;
#if NBPFILTER > 0
if (ifp->if_bpf)
bpf_mtap(ifp->if_bpf, top, BPF_DIRECTION_OUT);
#endif
m_freem(top);
readcheck:
if (bus_space_read_2(bst, bsh, FIFO_PORTS_REG_W) & FIFO_REMPTY)
goto again;
}
int
smc91cxx_intr(void *arg)
{
struct smc91cxx_softc *sc = arg;
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
bus_space_tag_t bst = sc->sc_bst;
bus_space_handle_t bsh = sc->sc_bsh;
u_int8_t mask, interrupts, status;
u_int16_t packetno, tx_status, card_stats;
if ((sc->sc_flags & SMC_FLAGS_ENABLED) == 0 ||
(sc->sc_dev.dv_flags & DVF_ACTIVE) == 0)
return (0);
SMC_SELECT_BANK(sc, 2);
mask = bus_space_read_1(bst, bsh, INTR_MASK_REG_B);
interrupts = bus_space_read_1(bst, bsh, INTR_STAT_REG_B);
status = interrupts & mask;
if (status == 0)
return (0);
bus_space_write_1(bst, bsh, INTR_MASK_REG_B, 0);
if (status & IM_RX_OVRN_INT) {
bus_space_write_1(bst, bsh, INTR_ACK_REG_B, IM_RX_OVRN_INT);
ifp->if_ierrors++;
}
if (status & IM_RCV_INT) {
#if 1
packetno = bus_space_read_2(bst, bsh, FIFO_PORTS_REG_W);
if (packetno & FIFO_REMPTY) {
printf("%s: receive interrupt on empty fifo\n",
sc->sc_dev.dv_xname);
goto out;
} else
#endif
smc91cxx_read(sc);
}
if (status & IM_ALLOC_INT) {
mask &= ~IM_ALLOC_INT;
while (bus_space_read_2(bst, bsh, MMU_CMD_REG_W) & MMUCR_BUSY)
;
bus_space_write_2(bst, bsh, MMU_CMD_REG_W, MMUCR_FREEPKT);
ifq_clr_oactive(&ifp->if_snd);
ifp->if_timer = 0;
}
if (status & IM_TX_INT) {
bus_space_write_1(bst, bsh, INTR_ACK_REG_B, IM_TX_INT);
packetno = bus_space_read_2(bst, bsh, FIFO_PORTS_REG_W) &
FIFO_TX_MASK;
bus_space_write_1(bst, bsh, PACKET_NUM_REG_B, packetno);
bus_space_write_2(bst, bsh, POINTER_REG_W,
PTR_AUTOINC | PTR_READ );
tx_status = bus_space_read_2(bst, bsh, DATA_REG_W);
if (tx_status & EPHSR_TX_SUC)
printf("%s: successful packet caused TX interrupt?!\n",
sc->sc_dev.dv_xname);
else
ifp->if_oerrors++;
if (tx_status & EPHSR_LATCOL)
ifp->if_collisions++;
SMC_SELECT_BANK(sc, 0);
#ifdef SMC91CXX_SW_PAD
bus_space_write_2(bst, bsh, TXMIT_CONTROL_REG_W, TCR_ENABLE);
#else
bus_space_write_2(bst, bsh, TXMIT_CONTROL_REG_W,
TCR_ENABLE | TCR_PAD_ENABLE);
#endif
SMC_SELECT_BANK(sc, 2);
while (bus_space_read_2(bst, bsh, MMU_CMD_REG_W) & MMUCR_BUSY)
;
bus_space_write_2(bst, bsh, MMU_CMD_REG_W, MMUCR_FREEPKT);
ifp->if_timer = 0;
}
if (status & IM_TX_EMPTY_INT) {
bus_space_write_1(bst, bsh, INTR_ACK_REG_B, IM_TX_EMPTY_INT);
mask &= ~IM_TX_EMPTY_INT;
SMC_SELECT_BANK(sc, 0);
card_stats = bus_space_read_2(bst, bsh, COUNTER_REG_W);
ifp->if_collisions += card_stats & ECR_COLN_MASK;
ifp->if_collisions += (card_stats & ECR_MCOLN_MASK) >> 4;
SMC_SELECT_BANK(sc, 2);
ifp->if_timer = 0;
}
if (status & IM_EPH_INT) {
smc91cxx_stop(sc);
smc91cxx_init(sc);
}
smc91cxx_start(ifp);
out:
mask |= bus_space_read_1(bst, bsh, INTR_MASK_REG_B);
bus_space_write_1(bst, bsh, INTR_MASK_REG_B, mask);
return (1);
}
void
smc91cxx_read(struct smc91cxx_softc *sc)
{
struct ifnet *ifp = &sc->sc_arpcom.ac_if;
bus_space_tag_t bst = sc->sc_bst;
bus_space_handle_t bsh = sc->sc_bsh;
struct mbuf_list ml = MBUF_LIST_INITIALIZER();
struct mbuf *m;
u_int16_t status, packetno, packetlen;
u_int8_t *data;
again:
bus_space_write_2(bst, bsh, POINTER_REG_W,
PTR_READ | PTR_RCV | PTR_AUTOINC );
status = bus_space_read_2(bst, bsh, DATA_REG_W);
packetlen = bus_space_read_2(bst, bsh, DATA_REG_W);
packetlen -= 6;
if (status & RS_ERRORS) {
ifp->if_ierrors++;
goto out;
}
if (status & RS_ODDFRAME)
packetlen++;
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL)
goto out;
m->m_pkthdr.len = packetlen;
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
m_freem(m);
ifp->if_ierrors++;
printf("%s: can't allocate cluster for incoming packet\n",
sc->sc_dev.dv_xname);
goto out;
}
m->m_data = (caddr_t) ALIGN(mtod(m, caddr_t) +
sizeof(struct ether_header)) - sizeof(struct ether_header);
data = mtod(m, u_int8_t *);
if (packetlen > 1)
bus_space_read_multi_stream_2(bst, bsh, DATA_REG_W,
(u_int16_t *)data, packetlen >> 1);
if (packetlen & 1) {
data += packetlen & ~1;
*data = bus_space_read_1(bst, bsh, DATA_REG_B);
}
m->m_pkthdr.len = m->m_len = packetlen;
ml_enqueue(&ml, m);
out:
while (bus_space_read_2(bst, bsh, MMU_CMD_REG_W) & MMUCR_BUSY)
;
bus_space_write_2(bst, bsh, MMU_CMD_REG_W, MMUCR_RELEASE);
packetno = bus_space_read_2(bst, bsh, FIFO_PORTS_REG_W);
if (packetno & FIFO_REMPTY) {
if_input(ifp, &ml);
return;
}
goto again;
}
int
smc91cxx_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
struct smc91cxx_softc *sc = ifp->if_softc;
struct ifreq *ifr = (struct ifreq *)data;
int s, error = 0;
s = splnet();
switch (cmd) {
case SIOCSIFADDR:
if ((error = smc91cxx_enable(sc)) != 0)
break;
ifp->if_flags |= IFF_UP;
smc91cxx_init(sc);
break;
case SIOCSIFFLAGS:
if ((ifp->if_flags & IFF_UP) == 0 &&
(ifp->if_flags & IFF_RUNNING) != 0) {
smc91cxx_stop(sc);
ifp->if_flags &= ~IFF_RUNNING;
smc91cxx_disable(sc);
} else if ((ifp->if_flags & IFF_UP) != 0 &&
(ifp->if_flags & IFF_RUNNING) == 0) {
if ((error = smc91cxx_enable(sc)) != 0)
break;
smc91cxx_init(sc);
} else if ((ifp->if_flags & IFF_UP) != 0) {
smc91cxx_reset(sc);
}
break;
case SIOCGIFMEDIA:
case SIOCSIFMEDIA:
error = ifmedia_ioctl(ifp, ifr, &sc->sc_mii.mii_media, cmd);
break;
default:
error = ether_ioctl(ifp, &sc->sc_arpcom, cmd, data);
}
if (error == ENETRESET) {
if (ifp->if_flags & IFF_RUNNING)
smc91cxx_reset(sc);
error = 0;
}
splx(s);
return (error);
}
void
smc91cxx_reset(struct smc91cxx_softc *sc)
{
int s;
s = splnet();
smc91cxx_stop(sc);
smc91cxx_init(sc);
splx(s);
}
void
smc91cxx_watchdog(struct ifnet *ifp)
{
struct smc91cxx_softc *sc = ifp->if_softc;
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
++sc->sc_arpcom.ac_if.if_oerrors;
smc91cxx_reset(sc);
}
void
smc91cxx_stop(struct smc91cxx_softc *sc)
{
bus_space_tag_t bst = sc->sc_bst;
bus_space_handle_t bsh = sc->sc_bsh;
SMC_SELECT_BANK(sc, 2);
bus_space_write_1(bst, bsh, INTR_MASK_REG_B, 0);
SMC_SELECT_BANK(sc, 0);
bus_space_write_2(bst, bsh, RECV_CONTROL_REG_W, 0);
bus_space_write_2(bst, bsh, TXMIT_CONTROL_REG_W, 0);
sc->sc_arpcom.ac_if.if_timer = 0;
}
int
smc91cxx_enable(struct smc91cxx_softc *sc)
{
if ((sc->sc_flags & SMC_FLAGS_ENABLED) == 0 && sc->sc_enable != NULL) {
if ((*sc->sc_enable)(sc) != 0) {
printf("%s: device enable failed\n",
sc->sc_dev.dv_xname);
return (EIO);
}
}
sc->sc_flags |= SMC_FLAGS_ENABLED;
return (0);
}
void
smc91cxx_disable(struct smc91cxx_softc *sc)
{
if ((sc->sc_flags & SMC_FLAGS_ENABLED) != 0 && sc->sc_disable != NULL) {
(*sc->sc_disable)(sc);
sc->sc_flags &= ~SMC_FLAGS_ENABLED;
}
}
u_int32_t
smc91cxx_mii_bitbang_read(struct device *self)
{
struct smc91cxx_softc *sc = (void *) self;
return (bus_space_read_2(sc->sc_bst, sc->sc_bsh, MGMT_REG_W));
}
void
smc91cxx_mii_bitbang_write(struct device *self, u_int32_t val)
{
struct smc91cxx_softc *sc = (void *) self;
bus_space_write_2(sc->sc_bst, sc->sc_bsh, MGMT_REG_W, val);
}
int
smc91cxx_mii_readreg(struct device *self, int phy, int reg)
{
struct smc91cxx_softc *sc = (void *) self;
int val;
SMC_SELECT_BANK(sc, 3);
val = mii_bitbang_readreg(self, &smc91cxx_mii_bitbang_ops, phy, reg);
SMC_SELECT_BANK(sc, 2);
return (val);
}
void
smc91cxx_mii_writereg(struct device *self, int phy, int reg, int val)
{
struct smc91cxx_softc *sc = (void *) self;
SMC_SELECT_BANK(sc, 3);
mii_bitbang_writereg(self, &smc91cxx_mii_bitbang_ops, phy, reg, val);
SMC_SELECT_BANK(sc, 2);
}
void
smc91cxx_statchg(struct device *self)
{
struct smc91cxx_softc *sc = (struct smc91cxx_softc *)self;
bus_space_tag_t bst = sc->sc_bst;
bus_space_handle_t bsh = sc->sc_bsh;
int mctl;
SMC_SELECT_BANK(sc, 0);
mctl = bus_space_read_2(bst, bsh, TXMIT_CONTROL_REG_W);
if (sc->sc_mii.mii_media_active & IFM_FDX)
mctl |= TCR_SWFDUP;
else
mctl &= ~TCR_SWFDUP;
bus_space_write_2(bst, bsh, TXMIT_CONTROL_REG_W, mctl);
SMC_SELECT_BANK(sc, 2);
}
void
smc91cxx_tick(void *arg)
{
struct smc91cxx_softc *sc = arg;
int s;
#ifdef DIAGNOSTIC
if ((sc->sc_flags & SMC_FLAGS_HAS_MII) == 0)
panic("smc91cxx_tick");
#endif
if ((sc->sc_dev.dv_flags & DVF_ACTIVE) == 0)
return;
s = splnet();
mii_tick(&sc->sc_mii);
splx(s);
timeout_add_sec(&sc->sc_mii_timeout, 1);
}