#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_aumac.c,v 1.54 2025/10/15 01:32:44 thorpej Exp $");
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/callout.h>
#include <sys/device.h>
#include <sys/endian.h>
#include <sys/errno.h>
#include <sys/intr.h>
#include <sys/ioctl.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <uvm/uvm.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_ether.h>
#include <net/bpf.h>
#include <sys/rndsource.h>
#include <dev/mii/mii.h>
#include <dev/mii/miivar.h>
#include <mips/alchemy/include/aureg.h>
#include <mips/alchemy/include/auvar.h>
#include <mips/alchemy/include/aubusvar.h>
#include <mips/alchemy/dev/if_aumacreg.h>
#define AUMAC_NTXDESC 4
#define AUMAC_NTXDESC_MASK (AUMAC_NTXDESC - 1)
#define AUMAC_NRXDESC 4
#define AUMAC_NRXDESC_MASK (AUMAC_NRXDESC - 1)
#define AUMAC_NEXTTX(x) (((x) + 1) & AUMAC_NTXDESC_MASK)
#define AUMAC_NEXTRX(x) (((x) + 1) & AUMAC_NRXDESC_MASK)
#define AUMAC_TXBUF_OFFSET 0
#define AUMAC_RXBUF_OFFSET (MAC_BUFLEN * AUMAC_NTXDESC)
#define AUMAC_BUFSIZE (MAC_BUFLEN * (AUMAC_NTXDESC + AUMAC_NRXDESC))
struct aumac_buf {
vaddr_t buf_vaddr;
bus_addr_t buf_paddr;
};
struct aumac_softc {
device_t sc_dev;
bus_space_tag_t sc_st;
bus_space_handle_t sc_mac_sh;
bus_space_handle_t sc_macen_sh;
bus_space_handle_t sc_dma_sh;
struct ethercom sc_ethercom;
void *sc_sdhook;
int sc_irq;
void *sc_ih;
struct mii_data sc_mii;
struct callout sc_tick_ch;
struct aumac_buf sc_txbufs[AUMAC_NTXDESC];
struct aumac_buf sc_rxbufs[AUMAC_NRXDESC];
void *sc_bufaddr;
int sc_txfree;
int sc_txnext;
int sc_txdirty;
int sc_rxptr;
krndsource_t rnd_source;
#ifdef AUMAC_EVENT_COUNTERS
struct evcnt sc_ev_txstall;
struct evcnt sc_ev_rxstall;
struct evcnt sc_ev_txintr;
struct evcnt sc_ev_rxintr;
#endif
uint32_t sc_control;
uint32_t sc_flowctrl;
};
#ifdef AUMAC_EVENT_COUNTERS
#define AUMAC_EVCNT_INCR(ev) (ev)->ev_count++
#else
#define AUMAC_EVCNT_INCR(ev)
#endif
#define AUMAC_INIT_RXDESC(sc, x) \
do { \
bus_space_write_4((sc)->sc_st, (sc)->sc_dma_sh, \
MACDMA_RX_STAT((x)), 0); \
bus_space_write_4((sc)->sc_st, (sc)->sc_dma_sh, \
MACDMA_RX_ADDR((x)), \
(sc)->sc_rxbufs[(x)].buf_paddr | RX_ADDR_EN); \
} while (0)
static void aumac_start(struct ifnet *);
static void aumac_watchdog(struct ifnet *);
static int aumac_ioctl(struct ifnet *, u_long, void *);
static int aumac_init(struct ifnet *);
static void aumac_stop(struct ifnet *, int);
static void aumac_shutdown(void *);
static void aumac_tick(void *);
static void aumac_set_filter(struct aumac_softc *);
static void aumac_powerup(struct aumac_softc *);
static void aumac_powerdown(struct aumac_softc *);
static int aumac_intr(void *);
static int aumac_txintr(struct aumac_softc *);
static int aumac_rxintr(struct aumac_softc *);
static int aumac_mii_readreg(device_t, int, int, uint16_t *);
static int aumac_mii_writereg(device_t, int, int, uint16_t);
static void aumac_mii_statchg(struct ifnet *);
static int aumac_mii_wait(struct aumac_softc *, const char *);
static int aumac_match(device_t, struct cfdata *, void *);
static void aumac_attach(device_t, device_t, void *);
int aumac_copy_small = 0;
CFATTACH_DECL_NEW(aumac, sizeof(struct aumac_softc),
aumac_match, aumac_attach, NULL, NULL);
static int
aumac_match(device_t parent, struct cfdata *cf, void *aux)
{
struct aubus_attach_args *aa = aux;
if (strcmp(aa->aa_name, cf->cf_name) == 0)
return 1;
return 0;
}
static void
aumac_attach(device_t parent, device_t self, void *aux)
{
struct aumac_softc *sc = device_private(self);
struct aubus_attach_args *aa = aux;
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
struct mii_data * const mii = &sc->sc_mii;
struct pglist pglist;
paddr_t bufaddr;
vaddr_t vbufaddr;
int i;
uint8_t enaddr[ETHER_ADDR_LEN];
callout_init(&sc->sc_tick_ch, 0);
aprint_normal(": Au1X00 10/100 Ethernet\n");
aprint_naive("\n");
sc->sc_dev = self;
sc->sc_st = aa->aa_st;
if (! ether_getaddr(self, enaddr)) {
aprint_error_dev(self, "unable to get MAC address\n");
return;
}
aprint_normal_dev(self, "Ethernet address %s\n", ether_sprintf(enaddr));
if (bus_space_map(sc->sc_st, aa->aa_addrs[AA_MAC_BASE],
MACx_SIZE, 0, &sc->sc_mac_sh) != 0) {
aprint_error_dev(self, "unable to map MAC registers\n");
return;
}
if (bus_space_map(sc->sc_st, aa->aa_addrs[AA_MAC_ENABLE],
MACENx_SIZE, 0, &sc->sc_macen_sh) != 0) {
aprint_error_dev(self, "unable to map MACEN registers\n");
return;
}
if (bus_space_map(sc->sc_st, aa->aa_addrs[AA_MAC_DMA_BASE],
MACx_DMA_SIZE, 0, &sc->sc_dma_sh) != 0) {
aprint_error_dev(self, "unable to map MACDMA registers\n");
return;
}
aumac_powerdown(sc);
sc->sc_ih = au_intr_establish(aa->aa_irq[0], 1, IPL_NET, IST_LEVEL,
aumac_intr, sc);
if (sc->sc_ih == NULL) {
aprint_error_dev(self,
"unable to register interrupt handler\n");
return;
}
sc->sc_irq = aa->aa_irq[0];
au_intr_disable(sc->sc_irq);
if (uvm_pglistalloc(AUMAC_BUFSIZE, 0, ctob(physmem), PAGE_SIZE, 0,
&pglist, 1, 0))
return;
bufaddr = VM_PAGE_TO_PHYS(TAILQ_FIRST(&pglist));
vbufaddr = MIPS_PHYS_TO_KSEG0(bufaddr);
for (i = 0; i < AUMAC_NTXDESC; i++) {
int offset = AUMAC_TXBUF_OFFSET + (i * MAC_BUFLEN);
sc->sc_txbufs[i].buf_vaddr = vbufaddr + offset;
sc->sc_txbufs[i].buf_paddr = bufaddr + offset;
}
for (i = 0; i < AUMAC_NRXDESC; i++) {
int offset = AUMAC_RXBUF_OFFSET + (i * MAC_BUFLEN);
sc->sc_rxbufs[i].buf_vaddr = vbufaddr + offset;
sc->sc_rxbufs[i].buf_paddr = bufaddr + offset;
}
aumac_powerup(sc);
mii->mii_ifp = ifp;
mii->mii_readreg = aumac_mii_readreg;
mii->mii_writereg = aumac_mii_writereg;
mii->mii_statchg = aumac_mii_statchg;
sc->sc_ethercom.ec_mii = mii;
ifmedia_init(&mii->mii_media, 0, ether_mediachange, ether_mediastatus);
mii_attach(self, mii, 0xffffffff, MII_PHY_ANY,
MII_OFFSET_ANY, 0);
if (LIST_FIRST(&mii->mii_phys) == NULL) {
ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE,
0, NULL);
ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE);
} else
ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
strcpy(ifp->if_xname, device_xname(self));
ifp->if_softc = sc;
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_ioctl = aumac_ioctl;
ifp->if_start = aumac_start;
ifp->if_watchdog = aumac_watchdog;
ifp->if_init = aumac_init;
ifp->if_stop = aumac_stop;
IFQ_SET_READY(&ifp->if_snd);
if_attach(ifp);
if_deferred_start_init(ifp, NULL);
ether_ifattach(ifp, enaddr);
rnd_attach_source(&sc->rnd_source, device_xname(self),
RND_TYPE_NET, RND_FLAG_DEFAULT);
#ifdef AUMAC_EVENT_COUNTERS
evcnt_attach_dynamic(&sc->sc_ev_txstall, EVCNT_TYPE_MISC,
NULL, device_xname(self), "txstall");
evcnt_attach_dynamic(&sc->sc_ev_rxstall, EVCNT_TYPE_MISC,
NULL, device_xname(self), "rxstall");
evcnt_attach_dynamic(&sc->sc_ev_txintr, EVCNT_TYPE_MISC,
NULL, device_xname(self), "txintr");
evcnt_attach_dynamic(&sc->sc_ev_rxintr, EVCNT_TYPE_MISC,
NULL, device_xname(self), "rxintr");
#endif
sc->sc_sdhook = shutdownhook_establish(aumac_shutdown, sc);
if (sc->sc_sdhook == NULL)
aprint_error_dev(self,
"WARNING: unable to establish shutdown hook\n");
return;
}
static void
aumac_shutdown(void *arg)
{
struct aumac_softc *sc = arg;
aumac_stop(&sc->sc_ethercom.ec_if, 1);
bus_space_write_4(sc->sc_st, sc->sc_macen_sh, 0, 0);
}
static void
aumac_start(struct ifnet *ifp)
{
struct aumac_softc *sc = ifp->if_softc;
struct mbuf *m;
int nexttx;
if ((ifp->if_flags & IFF_RUNNING) == 0)
return;
for (;;) {
IFQ_POLL(&ifp->if_snd, m);
if (m == NULL)
return;
if (sc->sc_txfree == 0) {
AUMAC_EVCNT_INCR(&sc->sc_ev_txstall);
return;
}
nexttx = sc->sc_txnext;
IFQ_DEQUEUE(&ifp->if_snd, m);
m_copydata(m, 0, m->m_pkthdr.len,
(void *)sc->sc_txbufs[nexttx].buf_vaddr);
if (m->m_pkthdr.len < (ETHER_MIN_LEN - ETHER_CRC_LEN))
memset((char *)sc->sc_txbufs[nexttx].buf_vaddr +
m->m_pkthdr.len, 0,
ETHER_MIN_LEN - ETHER_CRC_LEN - m->m_pkthdr.len);
bus_space_write_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_STAT(nexttx), 0);
bus_space_write_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_LEN(nexttx),
m->m_pkthdr.len < (ETHER_MIN_LEN - ETHER_CRC_LEN) ?
ETHER_MIN_LEN - ETHER_CRC_LEN : m->m_pkthdr.len);
bus_space_write_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_ADDR(nexttx),
sc->sc_txbufs[nexttx].buf_paddr | TX_ADDR_EN);
bus_space_barrier(sc->sc_st, sc->sc_dma_sh, 0 ,
0 , BUS_SPACE_BARRIER_WRITE);
sc->sc_txfree--;
sc->sc_txnext = AUMAC_NEXTTX(nexttx);
bpf_mtap(ifp, m, BPF_D_OUT);
m_freem(m);
ifp->if_timer = 5;
}
}
static void
aumac_watchdog(struct ifnet *ifp)
{
struct aumac_softc *sc = ifp->if_softc;
printf("%s: device timeout\n", device_xname(sc->sc_dev));
(void) aumac_init(ifp);
aumac_start(ifp);
}
static int
aumac_ioctl(struct ifnet *ifp, u_long cmd, void *data)
{
struct aumac_softc *sc = ifp->if_softc;
int s, error;
s = splnet();
error = ether_ioctl(ifp, cmd, data);
if (error == ENETRESET) {
if (ifp->if_flags & IFF_RUNNING)
aumac_set_filter(sc);
error = 0;
}
aumac_start(ifp);
splx(s);
return error;
}
static int
aumac_intr(void *arg)
{
struct aumac_softc *sc = arg;
int status;
if ((sc->sc_ethercom.ec_if.if_flags & IFF_RUNNING) == 0)
return 0;
status = aumac_rxintr(sc);
status += aumac_txintr(sc);
rnd_add_uint32(&sc->rnd_source, status);
return status;
}
static int
aumac_txintr(struct aumac_softc *sc)
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
uint32_t stat;
int i;
int pkts = 0;
for (i = sc->sc_txdirty; sc->sc_txfree != AUMAC_NTXDESC;
i = AUMAC_NEXTTX(i)) {
if ((bus_space_read_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_ADDR(i)) & TX_ADDR_DN) == 0)
break;
pkts++;
bus_space_write_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_ADDR(i), 0);
stat = bus_space_read_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_STAT(i));
net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
if (stat & TX_STAT_FA) {
if_statinc_ref(ifp, nsr, if_oerrors);
} else {
if_statinc_ref(ifp, nsr, if_opackets);
}
if (stat & TX_STAT_EC) {
if_statadd_ref(ifp, nsr, if_collisions, 16);
} else if (TX_STAT_CC(stat)) {
if_statadd_ref(ifp, nsr, if_collisions,
TX_STAT_CC(stat));
}
IF_STAT_PUTREF(ifp);
sc->sc_txfree++;
if_schedule_deferred_start(ifp);
}
if (pkts)
AUMAC_EVCNT_INCR(&sc->sc_ev_txintr);
sc->sc_txdirty = i;
if (sc->sc_txfree == AUMAC_NTXDESC)
ifp->if_timer = 0;
return pkts;
}
static int
aumac_rxintr(struct aumac_softc *sc)
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
struct mbuf *m;
uint32_t stat;
int i, len;
int pkts = 0;
for (i = sc->sc_rxptr;; i = AUMAC_NEXTRX(i)) {
if ((bus_space_read_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_RX_ADDR(i)) & RX_ADDR_DN) == 0)
break;
pkts++;
stat = bus_space_read_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_RX_STAT(i));
#define PRINTERR(str) \
do { \
error++; \
printf("%s: %s\n", device_xname(sc->sc_dev), str); \
} while (0)
if (stat & RX_STAT_ERRS) {
int error = 0;
#if 0
if (stat & RX_STAT_MI)
PRINTERR("missed frame");
#endif
if (stat & RX_STAT_UC)
PRINTERR("unknown control frame");
if (stat & RX_STAT_LE)
PRINTERR("short frame");
if (stat & RX_STAT_CR)
PRINTERR("CRC error");
if (stat & RX_STAT_ME)
PRINTERR("medium error");
if (stat & RX_STAT_CS)
PRINTERR("late collision");
if (stat & RX_STAT_FL)
PRINTERR("frame too big");
if (stat & RX_STAT_RF)
PRINTERR("runt frame (collision)");
if (stat & RX_STAT_WT)
PRINTERR("watch dog");
if (stat & RX_STAT_DB) {
if (stat & (RX_STAT_CS | RX_STAT_RF |
RX_STAT_CR)) {
if (!error)
goto pktok;
} else
PRINTERR("dribbling bit");
}
#undef PRINTERR
if_statinc(ifp, if_ierrors);
dropit:
AUMAC_INIT_RXDESC(sc, i);
continue;
}
pktok:
len = RX_STAT_L(stat);
len -= ETHER_CRC_LEN;
if (len > MCLBYTES - 2)
len = MCLBYTES - 2;
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
printf("%s: unable to allocate Rx mbuf\n",
device_xname(sc->sc_dev));
goto dropit;
}
if (len > MHLEN - 2) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
printf("%s: unable to allocate Rx cluster\n",
device_xname(sc->sc_dev));
m_freem(m);
goto dropit;
}
}
m->m_data += 2;
memcpy(mtod(m, void *),
(void *)sc->sc_rxbufs[i].buf_vaddr, len);
AUMAC_INIT_RXDESC(sc, i);
m_set_rcvif(m, ifp);
m->m_pkthdr.len = m->m_len = len;
if_percpuq_enqueue(ifp->if_percpuq, m);
}
if (pkts)
AUMAC_EVCNT_INCR(&sc->sc_ev_rxintr);
if (pkts == AUMAC_NRXDESC)
AUMAC_EVCNT_INCR(&sc->sc_ev_rxstall);
sc->sc_rxptr = i;
return pkts;
}
static void
aumac_tick(void *arg)
{
struct aumac_softc *sc = arg;
int s;
s = splnet();
mii_tick(&sc->sc_mii);
splx(s);
callout_reset(&sc->sc_tick_ch, hz, aumac_tick, sc);
}
static int
aumac_init(struct ifnet *ifp)
{
struct aumac_softc *sc = ifp->if_softc;
int i, error = 0;
aumac_stop(ifp, 0);
for (i = 0; i < AUMAC_NTXDESC; i++) {
bus_space_write_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_STAT(i), 0);
bus_space_write_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_LEN(i), 0);
bus_space_write_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_ADDR(i), sc->sc_txbufs[i].buf_paddr);
}
sc->sc_txfree = AUMAC_NTXDESC;
sc->sc_txnext = TX_ADDR_CB(bus_space_read_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_TX_ADDR(0)));
sc->sc_txdirty = sc->sc_txnext;
for (i = 0; i < AUMAC_NRXDESC; i++)
AUMAC_INIT_RXDESC(sc, i);
sc->sc_rxptr = RX_ADDR_CB(bus_space_read_4(sc->sc_st, sc->sc_dma_sh,
MACDMA_RX_ADDR(0)));
aumac_powerup(sc);
sc->sc_control |= CONTROL_DO | CONTROL_TE | CONTROL_RE;
#if _BYTE_ORDER == _BIG_ENDIAN
sc->sc_control |= CONTROL_EM;
#endif
if ((error = ether_mediachange(ifp)) != 0)
goto out;
aumac_set_filter(sc);
callout_reset(&sc->sc_tick_ch, hz, aumac_tick, sc);
ifp->if_flags |= IFF_RUNNING;
au_intr_enable(sc->sc_irq);
out:
if (error)
printf("%s: interface not running\n", device_xname(sc->sc_dev));
return error;
}
static void
aumac_stop(struct ifnet *ifp, int disable)
{
struct aumac_softc *sc = ifp->if_softc;
callout_stop(&sc->sc_tick_ch);
mii_down(&sc->sc_mii);
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_CONTROL, 0);
aumac_powerdown(sc);
au_intr_disable(sc->sc_irq);
ifp->if_flags &= ~IFF_RUNNING;
ifp->if_timer = 0;
}
static void
aumac_powerdown(struct aumac_softc *sc)
{
}
static void
aumac_powerup(struct aumac_softc *sc)
{
bus_space_write_4(sc->sc_st, sc->sc_macen_sh, 0, MACEN_JP | MACEN_CE);
bus_space_write_4(sc->sc_st, sc->sc_macen_sh, 0,
MACEN_E2 | MACEN_E1 | MACEN_E0 | MACEN_CE);
delay(20000);
}
static void
aumac_set_filter(struct aumac_softc *sc)
{
struct ethercom *ec = &sc->sc_ethercom;
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
struct ether_multi *enm;
struct ether_multistep step;
const uint8_t *enaddr = CLLADDR(ifp->if_sadl);
uint32_t mchash[2], crc;
sc->sc_control &= ~(CONTROL_PM | CONTROL_PR);
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_CONTROL,
sc->sc_control & ~CONTROL_RE);
if (ifp->if_flags & IFF_PROMISC) {
sc->sc_control |= CONTROL_PR;
goto allmulti;
}
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_ADDRHIGH,
enaddr[4] | (enaddr[5] << 8));
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_ADDRLOW,
enaddr[0] | (enaddr[1] << 8) | (enaddr[2] << 16) |
(enaddr[3] << 24));
sc->sc_control |= CONTROL_HP;
mchash[0] = mchash[1] = 0;
ETHER_LOCK(ec);
ETHER_FIRST_MULTI(step, ec, enm);
while (enm != NULL) {
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
ETHER_UNLOCK(ec);
goto allmulti;
}
crc = ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN);
crc >>= 26;
mchash[crc >> 5] |= 1U << (crc & 0x1f);
ETHER_NEXT_MULTI(step, enm);
}
ETHER_UNLOCK(ec);
ifp->if_flags &= ~IFF_ALLMULTI;
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_HASHHIGH,
mchash[1]);
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_HASHLOW,
mchash[0]);
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_CONTROL,
sc->sc_control);
return;
allmulti:
sc->sc_control |= CONTROL_PM;
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_CONTROL,
sc->sc_control);
}
static int
aumac_mii_wait(struct aumac_softc *sc, const char *msg)
{
int i;
for (i = 0; i < 10000; i++) {
if ((bus_space_read_4(sc->sc_st, sc->sc_mac_sh,
MAC_MIICTRL) & MIICTRL_MB) == 0)
return 0;
delay(10);
}
printf("%s: MII failed to %s\n", device_xname(sc->sc_dev), msg);
return ETIMEDOUT;
}
static int
aumac_mii_readreg(device_t self, int phy, int reg, uint16_t *val)
{
struct aumac_softc *sc = device_private(self);
int rv;
if ((rv = aumac_mii_wait(sc, "become ready")) != 0)
return rv;
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_MIICTRL,
MIICTRL_PHYADDR(phy) | MIICTRL_MIIREG(reg));
if ((rv = aumac_mii_wait(sc, "complete")) != 0)
return rv;
*val = bus_space_read_4(sc->sc_st, sc->sc_mac_sh, MAC_MIIDATA)
& MIIDATA_MASK;
return 0;
}
static int
aumac_mii_writereg(device_t self, int phy, int reg, uint16_t val)
{
struct aumac_softc *sc = device_private(self);
int rv;
if ((rv = aumac_mii_wait(sc, "become ready")) != 0)
return rv;
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_MIIDATA, val);
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_MIICTRL,
MIICTRL_PHYADDR(phy) | MIICTRL_MIIREG(reg) | MIICTRL_MW);
return aumac_mii_wait(sc, "complete");
}
static void
aumac_mii_statchg(struct ifnet *ifp)
{
struct aumac_softc *sc = ifp->if_softc;
if ((sc->sc_mii.mii_media_active & IFM_FDX) != 0)
sc->sc_control |= CONTROL_F;
else
sc->sc_control &= ~CONTROL_F;
bus_space_write_4(sc->sc_st, sc->sc_mac_sh, MAC_CONTROL,
sc->sc_control);
}