Module Name: src
Committed By: kre
Date: Mon Aug 1 10:30:29 UTC 2022
Modified Files:
src/sys/dev/ic: tulip.c
Log Message:
Revert this to 1.205, undoing changes apparently mistakenly
committed in 1.206, and the total disaster that the attempt to
revert those in 1.207 created.
To generate a diff of this commit:
cvs rdiff -u -r1.207 -r1.208 src/sys/dev/ic/tulip.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/ic/tulip.c
diff -u src/sys/dev/ic/tulip.c:1.207 src/sys/dev/ic/tulip.c:1.208
--- src/sys/dev/ic/tulip.c:1.207 Mon Aug 1 07:37:18 2022
+++ src/sys/dev/ic/tulip.c Mon Aug 1 10:30:28 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tulip.c,v 1.207 2022/08/01 07:37:18 mlelstv Exp $ */
+/* $NetBSD: tulip.c,v 1.208 2022/08/01 10:30:28 kre Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000, 2002 The NetBSD Foundation, Inc.
@@ -36,9 +36,8 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tulip.c,v 1.207 2022/08/01 07:37:18 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tulip.c,v 1.208 2022/08/01 10:30:28 kre Exp $");
-#include "bpfilter.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -53,16 +52,12 @@ __KERNEL_RCSID(0, "$NetBSD: tulip.c,v 1.
#include <machine/endian.h>
-#include <uvm/uvm_extern.h>
-
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_ether.h>
-#if NBPFILTER > 0
#include <net/bpf.h>
-#endif
#include <sys/bus.h>
#include <sys/intr.h>
@@ -74,7 +69,7 @@ __KERNEL_RCSID(0, "$NetBSD: tulip.c,v 1.
#include <dev/ic/tulipreg.h>
#include <dev/ic/tulipvar.h>
-const char * const tlp_chip_names[] = TULIP_CHIP_NAMES;
+static const char * const tlp_chip_names[] = TULIP_CHIP_NAMES;
static const struct tulip_txthresh_tab tlp_10_txthresh_tab[] =
TLP_TXTHRESH_TAB_10;
@@ -82,9 +77,6 @@ static const struct tulip_txthresh_tab t
static const struct tulip_txthresh_tab tlp_10_100_txthresh_tab[] =
TLP_TXTHRESH_TAB_10_100;
-static const struct tulip_txthresh_tab tlp_winb_txthresh_tab[] =
- TLP_TXTHRESH_TAB_WINB;
-
static const struct tulip_txthresh_tab tlp_dm9102_txthresh_tab[] =
TLP_TXTHRESH_TAB_DM9102;
@@ -112,21 +104,21 @@ static void tlp_rxintr(struct tulip_soft
static void tlp_txintr(struct tulip_softc *);
static void tlp_mii_tick(void *);
-static void tlp_mii_statchg(device_t);
-static void tlp_winb_mii_statchg(device_t);
-static void tlp_dm9102_mii_statchg(device_t);
+static void tlp_mii_statchg(struct ifnet *);
+static void tlp_winb_mii_statchg(struct ifnet *);
+static void tlp_dm9102_mii_statchg(struct ifnet *);
static void tlp_mii_getmedia(struct tulip_softc *, struct ifmediareq *);
static int tlp_mii_setmedia(struct tulip_softc *);
-static int tlp_bitbang_mii_readreg(device_t, int, int);
-static void tlp_bitbang_mii_writereg(device_t, int, int, int);
+static int tlp_bitbang_mii_readreg(device_t, int, int, uint16_t *);
+static int tlp_bitbang_mii_writereg(device_t, int, int, uint16_t);
-static int tlp_pnic_mii_readreg(device_t, int, int);
-static void tlp_pnic_mii_writereg(device_t, int, int, int);
+static int tlp_pnic_mii_readreg(device_t, int, int, uint16_t *);
+static int tlp_pnic_mii_writereg(device_t, int, int, uint16_t);
-static int tlp_al981_mii_readreg(device_t, int, int);
-static void tlp_al981_mii_writereg(device_t, int, int, int);
+static int tlp_al981_mii_readreg(device_t, int, int, uint16_t *);
+static int tlp_al981_mii_writereg(device_t, int, int, uint16_t);
static void tlp_2114x_preinit(struct tulip_softc *);
static void tlp_2114x_mii_preinit(struct tulip_softc *);
@@ -276,7 +268,7 @@ tlp_attach(struct tulip_softc *sc, const
*/
switch (sc->sc_chip) {
case TULIP_CHIP_X3201_3:
- sc->sc_setup_fsls = TDCTL_Tx_FS|TDCTL_Tx_LS;
+ sc->sc_setup_fsls = TDCTL_Tx_FS | TDCTL_Tx_LS;
break;
default:
@@ -399,16 +391,16 @@ tlp_attach(struct tulip_softc *sc, const
if ((error = bus_dmamem_alloc(sc->sc_dmat,
sizeof(struct tulip_control_data), PAGE_SIZE, 0, &sc->sc_cdseg,
1, &sc->sc_cdnseg, 0)) != 0) {
- aprint_error_dev(self, "unable to allocate control data, error = %d\n",
- error);
+ aprint_error_dev(self,
+ "unable to allocate control data, error = %d\n", error);
goto fail_0;
}
if ((error = bus_dmamem_map(sc->sc_dmat, &sc->sc_cdseg, sc->sc_cdnseg,
sizeof(struct tulip_control_data), (void **)&sc->sc_control_data,
BUS_DMA_COHERENT)) != 0) {
- aprint_error_dev(self, "unable to map control data, error = %d\n",
- error);
+ aprint_error_dev(self,
+ "unable to map control data, error = %d\n", error);
goto fail_1;
}
@@ -416,15 +408,17 @@ tlp_attach(struct tulip_softc *sc, const
sizeof(struct tulip_control_data), 1,
sizeof(struct tulip_control_data), 0, 0, &sc->sc_cddmamap)) != 0) {
sc->sc_cddmamap = NULL;
- aprint_error_dev(self, "unable to create control data DMA map, "
- "error = %d\n", error);
+ aprint_error_dev(self,
+ "unable to create control data DMA map, error = %d\n",
+ error);
goto fail_2;
}
if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cddmamap,
sc->sc_control_data, sizeof(struct tulip_control_data), NULL,
0)) != 0) {
- aprint_error_dev(self, "unable to load control data DMA map, error = %d\n",
+ aprint_error_dev(self,
+ "unable to load control data DMA map, error = %d\n",
error);
goto fail_3;
}
@@ -457,8 +451,9 @@ tlp_attach(struct tulip_softc *sc, const
sc->sc_ntxsegs, MCLBYTES, 0, 0,
&sc->sc_txsoft[i].txs_dmamap)) != 0) {
sc->sc_txsoft[i].txs_dmamap = NULL;
- aprint_error_dev(self, "unable to create tx DMA map %d, "
- "error = %d\n", i, error);
+ aprint_error_dev(self,
+ "unable to create tx DMA map %d, error = %d\n", i,
+ error);
goto fail_4;
}
}
@@ -469,9 +464,10 @@ tlp_attach(struct tulip_softc *sc, const
for (i = 0; i < TULIP_NRXDESC; i++) {
if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
MCLBYTES, 0, 0, &sc->sc_rxsoft[i].rxs_dmamap)) != 0) {
- sc->sc_rxsoft[i].rxs_dmamap = NULL;
- aprint_error_dev(self, "unable to create rx DMA map %d, "
- "error = %d\n", i, error);
+ sc->sc_rxsoft[i].rxs_dmamap = NULL;
+ aprint_error_dev(self,
+ "unable to create rx DMA map %d, error = %d\n", i,
+ error);
goto fail_5;
}
sc->sc_rxsoft[i].rxs_mbuf = NULL;
@@ -528,12 +524,12 @@ tlp_attach(struct tulip_softc *sc, const
* Attach the interface.
*/
if_attach(ifp);
+ if_deferred_start_init(ifp, NULL);
ether_ifattach(ifp, enaddr);
ether_set_ifflags_cb(&sc->sc_ethercom, tlp_ifflags_cb);
-#if NRND > 0
+
rnd_attach_source(&sc->sc_rnd_source, device_xname(self),
- RND_TYPE_NET, 0);
-#endif
+ RND_TYPE_NET, RND_FLAG_DEFAULT);
if (pmf_device_register(self, NULL, NULL))
pmf_class_network_register(self, ifp);
@@ -579,24 +575,14 @@ int
tlp_activate(device_t self, enum devact act)
{
struct tulip_softc *sc = device_private(self);
- int s, error = 0;
- s = splnet();
switch (act) {
- case DVACT_ACTIVATE:
- error = EOPNOTSUPP;
- break;
-
case DVACT_DEACTIVATE:
- if (sc->sc_flags & TULIPF_HAS_MII)
- mii_activate(&sc->sc_mii, act, MII_PHY_ANY,
- MII_OFFSET_ANY);
if_deactivate(&sc->sc_ethercom.ec_if);
- break;
+ return 0;
+ default:
+ return EOPNOTSUPP;
}
- splx(s);
-
- return (error);
}
/*
@@ -611,32 +597,36 @@ tlp_detach(struct tulip_softc *sc)
struct tulip_rxsoft *rxs;
struct tulip_txsoft *txs;
device_t self = sc->sc_dev;
- int i;
+ int i, s;
/*
* Succeed now if there isn't any work to do.
*/
if ((sc->sc_flags & TULIPF_ATTACHED) == 0)
- return (0);
+ return 0;
- /* Unhook our tick handler. */
- if (sc->sc_tick)
- callout_stop(&sc->sc_tick_callout);
+ s = splnet();
+ /* Stop the interface. Callouts are stopped in it. */
+ tlp_stop(ifp, 1);
+ splx(s);
+
+ /* Destroy our callouts. */
+ callout_destroy(&sc->sc_nway_callout);
+ callout_destroy(&sc->sc_tick_callout);
if (sc->sc_flags & TULIPF_HAS_MII) {
/* Detach all PHYs */
mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
}
- /* Delete all remaining media. */
- ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY);
-
-#if NRND > 0
rnd_detach_source(&sc->sc_rnd_source);
-#endif
+
ether_ifdetach(ifp);
if_detach(ifp);
+ /* Delete all remaining media. */
+ ifmedia_fini(&sc->sc_mii.mii_media);
+
for (i = 0; i < TULIP_NRXDESC; i++) {
rxs = &sc->sc_rxsoft[i];
if (rxs->rxs_mbuf != NULL) {
@@ -666,7 +656,7 @@ tlp_detach(struct tulip_softc *sc)
if (sc->sc_srom)
free(sc->sc_srom, M_DEVBUF);
- return (0);
+ return 0;
}
/*
@@ -682,6 +672,7 @@ tlp_start(struct ifnet *ifp)
struct tulip_txsoft *txs, *last_txs = NULL;
bus_dmamap_t dmamap;
int error, firsttx, nexttx, lasttx = 1, ofree, seg;
+ struct tulip_desc *txd;
DPRINTF(sc, ("%s: tlp_start: sc_flags 0x%08x, if_flags 0x%08x\n",
device_xname(sc->sc_dev), sc->sc_flags, ifp->if_flags));
@@ -692,9 +683,9 @@ tlp_start(struct ifnet *ifp)
* itself into the ring.
*/
if (sc->sc_flags & TULIPF_WANT_SETUP)
- ifp->if_flags |= IFF_OACTIVE;
+ return;
- if ((ifp->if_flags & (IFF_RUNNING|IFF_OACTIVE)) != IFF_RUNNING)
+ if ((ifp->if_flags & IFF_RUNNING) != IFF_RUNNING)
return;
if (sc->sc_tick == tlp_2114x_nway_tick &&
@@ -742,7 +733,7 @@ tlp_start(struct ifnet *ifp)
*/
if ((sc->sc_ntxsegs == 1 && (mtod(m0, uintptr_t) & 3) != 0) ||
bus_dmamap_load_mbuf(sc->sc_dmat, dmamap, m0,
- BUS_DMA_WRITE|BUS_DMA_NOWAIT) != 0) {
+ BUS_DMA_WRITE | BUS_DMA_NOWAIT) != 0) {
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
aprint_error_dev(sc->sc_dev, "unable to allocate Tx mbuf\n");
@@ -761,7 +752,7 @@ tlp_start(struct ifnet *ifp)
m_copydata(m0, 0, m0->m_pkthdr.len, mtod(m, void *));
m->m_pkthdr.len = m->m_len = m0->m_pkthdr.len;
error = bus_dmamap_load_mbuf(sc->sc_dmat, dmamap,
- m, BUS_DMA_WRITE|BUS_DMA_NOWAIT);
+ m, BUS_DMA_WRITE | BUS_DMA_NOWAIT);
if (error) {
aprint_error_dev(sc->sc_dev,
"unable to load Tx buffer, error = %d",
@@ -777,15 +768,8 @@ tlp_start(struct ifnet *ifp)
if (dmamap->dm_nsegs > sc->sc_txfree) {
/*
* Not enough free descriptors to transmit this
- * packet. We haven't committed to anything yet,
- * so just unload the DMA map, put the packet
- * back on the queue, and punt. Notify the upper
- * layer that there are no more slots left.
- *
- * XXX We could allocate an mbuf and copy, but
- * XXX it is worth it?
+ * packet.
*/
- ifp->if_flags |= IFF_OACTIVE;
bus_dmamap_unload(sc->sc_dmat, dmamap);
if (m != NULL)
m_freem(m);
@@ -818,13 +802,14 @@ tlp_start(struct ifnet *ifp)
* yet. That could cause a race condition.
* We'll do it below.
*/
- sc->sc_txdescs[nexttx].td_status =
+ txd = &sc->sc_txdescs[nexttx];
+ txd->td_status =
(nexttx == firsttx) ? 0 : htole32(TDSTAT_OWN);
- sc->sc_txdescs[nexttx].td_bufaddr1 =
+ txd->td_bufaddr1 =
htole32(dmamap->dm_segs[seg].ds_addr);
- sc->sc_txdescs[nexttx].td_ctl =
+ txd->td_ctl =
htole32((dmamap->dm_segs[seg].ds_len <<
- TDCTL_SIZE1_SHIFT) | sc->sc_tdctl_ch |
+ TDCTL_SIZE1_SHIFT) | sc->sc_tdctl_ch |
(nexttx == (TULIP_NTXDESC - 1) ?
sc->sc_tdctl_er : 0));
lasttx = nexttx;
@@ -840,15 +825,16 @@ tlp_start(struct ifnet *ifp)
if (ifp->if_flags & IFF_DEBUG) {
printf(" txsoft %p transmit chain:\n", txs);
for (seg = sc->sc_txnext;; seg = TULIP_NEXTTX(seg)) {
+ txd = &sc->sc_txdescs[seg];
printf(" descriptor %d:\n", seg);
printf(" td_status: 0x%08x\n",
- le32toh(sc->sc_txdescs[seg].td_status));
+ le32toh(txd->td_status));
printf(" td_ctl: 0x%08x\n",
- le32toh(sc->sc_txdescs[seg].td_ctl));
+ le32toh(txd->td_ctl));
printf(" td_bufaddr1: 0x%08x\n",
- le32toh(sc->sc_txdescs[seg].td_bufaddr1));
+ le32toh(txd->td_bufaddr1));
printf(" td_bufaddr2: 0x%08x\n",
- le32toh(sc->sc_txdescs[seg].td_bufaddr2));
+ le32toh(txd->td_bufaddr2));
if (seg == lasttx)
break;
}
@@ -857,7 +843,7 @@ tlp_start(struct ifnet *ifp)
/* Sync the descriptors we're using. */
TULIP_CDTXSYNC(sc, sc->sc_txnext, dmamap->dm_nsegs,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+ BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
/*
* Store a pointer to the packet so we can free it later,
@@ -878,18 +864,10 @@ tlp_start(struct ifnet *ifp)
last_txs = txs;
-#if NBPFILTER > 0
/*
* Pass the packet to any BPF listeners.
*/
- if (ifp->if_bpf)
- bpf_mtap(ifp->if_bpf, m0);
-#endif /* NBPFILTER > 0 */
- }
-
- if (txs == NULL || sc->sc_txfree == 0) {
- /* No more slots left; notify upper layer. */
- ifp->if_flags |= IFF_OACTIVE;
+ bpf_mtap(ifp, m0, BPF_D_OUT);
}
if (sc->sc_txfree != ofree) {
@@ -901,7 +879,7 @@ tlp_start(struct ifnet *ifp)
*/
sc->sc_txdescs[lasttx].td_ctl |= htole32(TDCTL_Tx_IC);
TULIP_CDTXSYNC(sc, lasttx, 1,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+ BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
/*
* Some clone chips want IC on the *first* segment in
@@ -913,7 +891,7 @@ tlp_start(struct ifnet *ifp)
sc->sc_txdescs[last_txs->txs_firstdesc].td_ctl |=
htole32(TDCTL_Tx_IC);
TULIP_CDTXSYNC(sc, last_txs->txs_firstdesc, 1,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+ BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
}
/*
@@ -922,7 +900,7 @@ tlp_start(struct ifnet *ifp)
*/
sc->sc_txdescs[firsttx].td_status |= htole32(TDSTAT_OWN);
TULIP_CDTXSYNC(sc, firsttx, 1,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+ BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
/* Wake up the transmitter. */
/* XXX USE AUTOPOLLING? */
@@ -948,15 +926,17 @@ tlp_watchdog(struct ifnet *ifp)
doing_transmit = (! SIMPLEQ_EMPTY(&sc->sc_txdirtyq));
if (doing_setup && doing_transmit) {
- printf("%s: filter setup and transmit timeout\n", device_xname(sc->sc_dev));
- ifp->if_oerrors++;
+ printf("%s: filter setup and transmit timeout\n",
+ device_xname(sc->sc_dev));
+ if_statinc(ifp, if_oerrors);
} else if (doing_transmit) {
printf("%s: transmit timeout\n", device_xname(sc->sc_dev));
- ifp->if_oerrors++;
+ if_statinc(ifp, if_oerrors);
} else if (doing_setup)
printf("%s: filter setup timeout\n", device_xname(sc->sc_dev));
else
- printf("%s: spurious watchdog timeout\n", device_xname(sc->sc_dev));
+ printf("%s: spurious watchdog timeout\n",
+ device_xname(sc->sc_dev));
(void) tlp_init(ifp);
@@ -973,9 +953,9 @@ tlp_ifflags_cb(struct ethercom *ec)
{
struct ifnet *ifp = &ec->ec_if;
struct tulip_softc *sc = ifp->if_softc;
- int change = ifp->if_flags ^ sc->sc_if_flags;
+ u_short change = ifp->if_flags ^ sc->sc_if_flags;
- if ((change & ~(IFF_CANTCHANGE|IFF_DEBUG)) != 0)
+ if ((change & ~(IFF_CANTCHANGE | IFF_DEBUG)) != 0)
return ENETRESET;
if ((change & IFF_PROMISC) != 0)
(*sc->sc_filter_setup)(sc);
@@ -991,16 +971,11 @@ static int
tlp_ioctl(struct ifnet *ifp, u_long cmd, void *data)
{
struct tulip_softc *sc = ifp->if_softc;
- struct ifreq *ifr = (struct ifreq *)data;
int s, error;
s = splnet();
switch (cmd) {
- case SIOCSIFMEDIA:
- case SIOCGIFMEDIA:
- error = ifmedia_ioctl(ifp, ifr, &sc->sc_mii.mii_media, cmd);
- break;
default:
error = ether_ioctl(ifp, cmd, data);
if (error == ENETRESET) {
@@ -1022,7 +997,7 @@ tlp_ioctl(struct ifnet *ifp, u_long cmd,
sc->sc_if_flags = ifp->if_flags;
splx(s);
- return (error);
+ return error;
}
/*
@@ -1035,7 +1010,7 @@ tlp_intr(void *arg)
{
struct tulip_softc *sc = arg;
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
- uint32_t status, rxstatus, txstatus;
+ uint32_t status, rxstatus, txstatus, rndstatus = 0;
int handled = 0, txthresh;
DPRINTF(sc, ("%s: tlp_intr\n", device_xname(sc->sc_dev)));
@@ -1051,7 +1026,7 @@ tlp_intr(void *arg)
*/
if ((ifp->if_flags & IFF_RUNNING) == 0 ||
!device_is_active(sc->sc_dev))
- return (0);
+ return 0;
/* Disable interrupts on the DM9102 (interrupt edge bug). */
switch (sc->sc_chip) {
@@ -1067,8 +1042,10 @@ tlp_intr(void *arg)
for (;;) {
status = TULIP_READ(sc, CSR_STATUS);
- if (status)
+ if (status) {
TULIP_WRITE(sc, CSR_STATUS, status);
+ rndstatus = status;
+ }
if ((status & sc->sc_inten) == 0)
break;
@@ -1143,7 +1120,7 @@ tlp_intr(void *arg)
}
}
- if (status & (STATUS_TPS|STATUS_RPS)) {
+ if (status & (STATUS_TPS | STATUS_RPS)) {
if (status & STATUS_TPS)
printf("%s: transmit process stopped\n",
device_xname(sc->sc_dev));
@@ -1173,8 +1150,8 @@ tlp_intr(void *arg)
str = "unknown error";
break;
}
- aprint_error_dev(sc->sc_dev, "fatal system error: %s\n",
- str);
+ aprint_error_dev(sc->sc_dev,
+ "fatal system error: %s\n", str);
(void) tlp_init(ifp);
break;
}
@@ -1208,13 +1185,12 @@ tlp_intr(void *arg)
}
/* Try to get more packets going. */
- tlp_start(ifp);
+ if_schedule_deferred_start(ifp);
-#if NRND > 0
if (handled)
- rnd_add_uint32(&sc->sc_rnd_source, status);
-#endif
- return (handled);
+ rnd_add_uint32(&sc->sc_rnd_source, rndstatus);
+
+ return handled;
}
/*
@@ -1236,7 +1212,7 @@ tlp_rxintr(struct tulip_softc *sc)
rxs = &sc->sc_rxsoft[i];
TULIP_CDRXSYNC(sc, i,
- BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
+ BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
rxstat = le32toh(sc->sc_rxdescs[i].td_status);
@@ -1253,8 +1229,8 @@ tlp_rxintr(struct tulip_softc *sc)
* has an awful receive engine bug, which may require
* a very icky work-around.
*/
- if ((rxstat & (TDSTAT_Rx_FS|TDSTAT_Rx_LS)) !=
- (TDSTAT_Rx_FS|TDSTAT_Rx_LS)) {
+ if ((rxstat & (TDSTAT_Rx_FS | TDSTAT_Rx_LS)) !=
+ (TDSTAT_Rx_FS | TDSTAT_Rx_LS)) {
printf("%s: incoming packet spilled, resetting\n",
device_xname(sc->sc_dev));
(void) tlp_init(ifp);
@@ -1265,7 +1241,7 @@ tlp_rxintr(struct tulip_softc *sc)
* If any collisions were seen on the wire, count one.
*/
if (rxstat & TDSTAT_Rx_CS)
- ifp->if_collisions++;
+ if_statinc(ifp, if_collisions);
/*
* If an error occurred, update stats, clear the status
@@ -1291,9 +1267,9 @@ tlp_rxintr(struct tulip_softc *sc)
rxstat &= errors;
#define PRINTERR(bit, str) \
if (rxstat & (bit)) \
- aprint_error_dev(sc->sc_dev, "receive error: %s\n", \
- str)
- ifp->if_ierrors++;
+ aprint_error_dev(sc->sc_dev, \
+ "receive error: %s\n", str)
+ if_statinc(ifp, if_ierrors);
PRINTERR(TDSTAT_Rx_DE, "descriptor error");
PRINTERR(TDSTAT_Rx_RF, "runt frame");
PRINTERR(TDSTAT_Rx_TL, "frame too long");
@@ -1322,7 +1298,7 @@ tlp_rxintr(struct tulip_softc *sc)
*/
m = rxs->rxs_mbuf;
if (tlp_add_rxbuf(sc, i) != 0) {
- ifp->if_ierrors++;
+ if_statinc(ifp, if_ierrors);
TULIP_INIT_RXDESC(sc, i);
bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0,
rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
@@ -1338,7 +1314,7 @@ tlp_rxintr(struct tulip_softc *sc)
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
dropit:
- ifp->if_ierrors++;
+ if_statinc(ifp, if_ierrors);
TULIP_INIT_RXDESC(sc, i);
bus_dmamap_sync(sc->sc_dmat, rxs->rxs_dmamap, 0,
rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
@@ -1366,9 +1342,8 @@ tlp_rxintr(struct tulip_softc *sc)
rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
#endif /* __NO_STRICT_ALIGNMENT */
- ifp->if_ipackets++;
eh = mtod(m, struct ether_header *);
- m->m_pkthdr.rcvif = ifp;
+ m_set_rcvif(m, ifp);
m->m_pkthdr.len = m->m_len = len;
/*
@@ -1391,15 +1366,6 @@ tlp_rxintr(struct tulip_softc *sc)
ETHER_MAX_FRAME(ifp, etype, 0);
}
-#if NBPFILTER > 0
- /*
- * Pass this up to any BPF listeners, but only
- * pass it up the stack if it's for us.
- */
- if (ifp->if_bpf)
- bpf_mtap(ifp->if_bpf, m);
-#endif /* NBPFILTER > 0 */
-
/*
* We sometimes have to run the 21140 in Hash-Only
* mode. If we're in that mode, and not in promiscuous
@@ -1416,7 +1382,7 @@ tlp_rxintr(struct tulip_softc *sc)
}
/* Pass it on. */
- (*ifp->if_input)(ifp, m);
+ if_percpuq_enqueue(ifp->if_percpuq, m);
}
/* Update the receive pointer. */
@@ -1438,29 +1404,28 @@ tlp_txintr(struct tulip_softc *sc)
DPRINTF(sc, ("%s: tlp_txintr: sc_flags 0x%08x\n",
device_xname(sc->sc_dev), sc->sc_flags));
- ifp->if_flags &= ~IFF_OACTIVE;
-
/*
* Go through our Tx list and free mbufs for those
* frames that have been transmitted.
*/
while ((txs = SIMPLEQ_FIRST(&sc->sc_txdirtyq)) != NULL) {
- TULIP_CDTXSYNC(sc, txs->txs_lastdesc,
- txs->txs_ndescs,
- BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
+ TULIP_CDTXSYNC(sc, txs->txs_lastdesc, txs->txs_ndescs,
+ BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
#ifdef TLP_DEBUG
if (ifp->if_flags & IFF_DEBUG) {
int i;
+ struct tulip_desc *txd;
printf(" txsoft %p transmit chain:\n", txs);
for (i = txs->txs_firstdesc;; i = TULIP_NEXTTX(i)) {
+ txd = &sc->sc_txdescs[i];
printf(" descriptor %d:\n", i);
printf(" td_status: 0x%08x\n",
- le32toh(sc->sc_txdescs[i].td_status));
+ le32toh(txd->td_status));
printf(" td_ctl: 0x%08x\n",
- le32toh(sc->sc_txdescs[i].td_ctl));
+ le32toh(txd->td_ctl));
printf(" td_bufaddr1: 0x%08x\n",
- le32toh(sc->sc_txdescs[i].td_bufaddr1));
+ le32toh(txd->td_bufaddr1));
printf(" td_bufaddr2: 0x%08x\n",
le32toh(sc->sc_txdescs[i].td_bufaddr2));
if (i == txs->txs_lastdesc)
@@ -1514,18 +1479,20 @@ tlp_txintr(struct tulip_softc *sc)
if (txstat & TDSTAT_Tx_LC)
sc->sc_stats.ts_tx_lc++;
#endif
-
- if (txstat & (TDSTAT_Tx_UF|TDSTAT_Tx_TO))
- ifp->if_oerrors++;
+ net_stat_ref_t nsr = IF_STAT_GETREF(ifp);
+ if (txstat & (TDSTAT_Tx_UF | TDSTAT_Tx_TO))
+ if_statinc_ref(nsr, if_oerrors);
if (txstat & TDSTAT_Tx_EC)
- ifp->if_collisions += 16;
+ if_statadd_ref(nsr, if_collisions, 16);
else
- ifp->if_collisions += TDSTAT_Tx_COLLISIONS(txstat);
+ if_statadd_ref(nsr, if_collisions,
+ TDSTAT_Tx_COLLISIONS(txstat));
if (txstat & TDSTAT_Tx_LC)
- ifp->if_collisions++;
+ if_statinc_ref(nsr, if_collisions);
- ifp->if_opackets++;
+ if_statinc_ref(nsr, if_opackets);
+ IF_STAT_PUTREF(ifp);
}
/*
@@ -1801,13 +1768,13 @@ tlp_init(struct ifnet *ifp)
*/
memset(sc->sc_txdescs, 0, sizeof(sc->sc_txdescs));
for (i = 0; i < TULIP_NTXDESC; i++) {
- sc->sc_txdescs[i].td_ctl = htole32(sc->sc_tdctl_ch);
- sc->sc_txdescs[i].td_bufaddr2 =
- htole32(TULIP_CDTXADDR(sc, TULIP_NEXTTX(i)));
+ struct tulip_desc *txd = &sc->sc_txdescs[i];
+ txd->td_ctl = htole32(sc->sc_tdctl_ch);
+ txd->td_bufaddr2 = htole32(TULIP_CDTXADDR(sc, TULIP_NEXTTX(i)));
}
sc->sc_txdescs[TULIP_NTXDESC - 1].td_ctl |= htole32(sc->sc_tdctl_er);
TULIP_CDTXSYNC(sc, 0, TULIP_NTXDESC,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+ BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
sc->sc_txfree = TULIP_NTXDESC;
sc->sc_txnext = 0;
@@ -1830,9 +1797,9 @@ tlp_init(struct ifnet *ifp)
rxs = &sc->sc_rxsoft[i];
if (rxs->rxs_mbuf == NULL) {
if ((error = tlp_add_rxbuf(sc, i)) != 0) {
- aprint_error_dev(sc->sc_dev, "unable to allocate or map rx "
- "buffer %d, error = %d\n",
- i, error);
+ aprint_error_dev(sc->sc_dev,
+ "unable to allocate or map rx "
+ "buffer %d, error = %d\n", i, error);
/*
* XXX Should attempt to run with fewer receive
* XXX buffers instead of just failing.
@@ -1849,14 +1816,14 @@ tlp_init(struct ifnet *ifp)
* Initialize the interrupt mask and enable interrupts.
*/
/* normal interrupts */
- sc->sc_inten = STATUS_TI | STATUS_TU | STATUS_RI | STATUS_NIS;
+ sc->sc_inten = STATUS_TI | STATUS_TU | STATUS_RI | STATUS_NIS;
/* abnormal interrupts */
sc->sc_inten |= STATUS_TPS | STATUS_TJT | STATUS_UNF |
STATUS_RU | STATUS_RPS | STATUS_RWT | STATUS_SE | STATUS_AIS;
- sc->sc_rxint_mask = STATUS_RI|STATUS_RU|STATUS_RWT;
- sc->sc_txint_mask = STATUS_TI|STATUS_UNF|STATUS_TJT;
+ sc->sc_rxint_mask = STATUS_RI | STATUS_RU | STATUS_RWT;
+ sc->sc_txint_mask = STATUS_TI | STATUS_UNF | STATUS_TJT;
switch (sc->sc_chip) {
case TULIP_CHIP_WB89C840F:
@@ -1864,7 +1831,7 @@ tlp_init(struct ifnet *ifp)
* Clear bits that we don't want that happen to
* overlap or don't exist.
*/
- sc->sc_inten &= ~(STATUS_WINB_REI|STATUS_RWT);
+ sc->sc_inten &= ~(STATUS_WINB_REI | STATUS_RWT);
break;
default:
@@ -1908,9 +1875,9 @@ tlp_init(struct ifnet *ifp)
const uint8_t *enaddr = CLLADDR(ifp->if_sadl);
reg = enaddr[0] |
- (enaddr[1] << 8) |
- (enaddr[2] << 16) |
- (enaddr[3] << 24);
+ (enaddr[1] << 8) |
+ (enaddr[2] << 16) |
+ ((uint32_t)enaddr[3] << 24);
bus_space_write_4(sc->sc_st, sc->sc_sh, CSR_ADM_PAR0, reg);
reg = enaddr[4] |
@@ -1926,9 +1893,9 @@ tlp_init(struct ifnet *ifp)
const uint8_t *enaddr = CLLADDR(ifp->if_sadl);
reg = enaddr[0] |
- (enaddr[1] << 8) |
- (enaddr[2] << 16) |
- (enaddr[3] << 24);
+ (enaddr[1] << 8) |
+ (enaddr[2] << 16) |
+ ((uint32_t)enaddr[3] << 24);
TULIP_WRITE(sc, CSR_AX_FILTIDX, AX_FILTIDX_PAR0);
TULIP_WRITE(sc, CSR_AX_FILTDATA, reg);
@@ -1952,7 +1919,7 @@ tlp_init(struct ifnet *ifp)
/*
* Set the current media.
*/
- (void) (*sc->sc_mediasw->tmsw_set)(sc);
+ (void)(*sc->sc_mediasw->tmsw_set)(sc);
/*
* Start the receive process.
@@ -1968,16 +1935,15 @@ tlp_init(struct ifnet *ifp)
* Note that the interface is now running.
*/
ifp->if_flags |= IFF_RUNNING;
- ifp->if_flags &= ~IFF_OACTIVE;
sc->sc_if_flags = ifp->if_flags;
out:
if (error) {
- ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
+ ifp->if_flags &= ~IFF_RUNNING;
ifp->if_timer = 0;
printf("%s: interface not running\n", device_xname(sc->sc_dev));
}
- return (error);
+ return error;
}
/*
@@ -1992,11 +1958,11 @@ tlp_enable(struct tulip_softc *sc)
if (TULIP_IS_ENABLED(sc) == 0 && sc->sc_enable != NULL) {
if ((*sc->sc_enable)(sc) != 0) {
aprint_error_dev(sc->sc_dev, "device enable failed\n");
- return (EIO);
+ return EIO;
}
sc->sc_flags |= TULIPF_ENABLED;
}
- return (0);
+ return 0;
}
/*
@@ -2078,12 +2044,12 @@ tlp_stop(struct ifnet *ifp, int disable)
SIMPLEQ_INSERT_TAIL(&sc->sc_txfreeq, txs, txs_q);
}
- sc->sc_flags &= ~(TULIPF_WANT_SETUP|TULIPF_DOING_SETUP);
+ sc->sc_flags &= ~(TULIPF_WANT_SETUP | TULIPF_DOING_SETUP);
/*
* Mark the interface down and cancel the watchdog timer.
*/
- ifp->if_flags &= ~(IFF_RUNNING | IFF_OACTIVE);
+ ifp->if_flags &= ~IFF_RUNNING;
sc->sc_if_flags = ifp->if_flags;
ifp->if_timer = 0;
@@ -2124,12 +2090,12 @@ tlp_srom_idle(struct tulip_softc *sc)
miirom |= MIIROM_SROMCS;
SROM_EMIT(sc, miirom);
- SROM_EMIT(sc, miirom|MIIROM_SROMSK);
+ SROM_EMIT(sc, miirom | MIIROM_SROMSK);
/* Strobe the clock 32 times. */
for (i = 0; i < 32; i++) {
SROM_EMIT(sc, miirom);
- SROM_EMIT(sc, miirom|MIIROM_SROMSK);
+ SROM_EMIT(sc, miirom | MIIROM_SROMSK);
}
SROM_EMIT(sc, miirom);
@@ -2169,7 +2135,7 @@ tlp_srom_size(struct tulip_softc *sc)
else
miirom &= ~MIIROM_SROMDI;
SROM_EMIT(sc, miirom);
- SROM_EMIT(sc, miirom|MIIROM_SROMSK);
+ SROM_EMIT(sc, miirom | MIIROM_SROMSK);
SROM_EMIT(sc, miirom);
}
@@ -2177,7 +2143,7 @@ tlp_srom_size(struct tulip_softc *sc)
for (x = 1; x <= 12; x++) {
miirom &= ~MIIROM_SROMDI;
SROM_EMIT(sc, miirom);
- SROM_EMIT(sc, miirom|MIIROM_SROMSK);
+ SROM_EMIT(sc, miirom | MIIROM_SROMSK);
if (!TULIP_ISSET(sc, CSR_MIIROM, MIIROM_SROMDO))
break;
SROM_EMIT(sc, miirom);
@@ -2191,14 +2157,14 @@ tlp_srom_size(struct tulip_softc *sc)
SROM_EMIT(sc, 0);
if (x < 4 || x > 12) {
- aprint_debug_dev(sc->sc_dev, "broken MicroWire interface detected; "
- "setting SROM size to 1Kb\n");
- return (6);
+ aprint_debug_dev(sc->sc_dev, "broken MicroWire interface "
+ "detected; setting SROM size to 1Kb\n");
+ return 6;
} else {
if (tlp_srom_debug)
printf("%s: SROM size is 2^%d*16 bits (%d bytes)\n",
device_xname(sc->sc_dev), x, (1 << (x + 4)) >> 3);
- return (x);
+ return x;
}
}
@@ -2219,9 +2185,9 @@ tlp_read_srom(struct tulip_softc *sc)
sc->sc_srom_addrbits = tlp_srom_size(sc);
if (sc->sc_srom_addrbits == 0)
- return (0);
+ return 0;
size = TULIP_ROM_SIZE(sc->sc_srom_addrbits);
- sc->sc_srom = malloc(size, M_DEVBUF, M_NOWAIT);
+ sc->sc_srom = malloc(size, M_DEVBUF, M_WAITOK);
/* Select the SROM. */
miirom = MIIROM_SR;
@@ -2242,7 +2208,7 @@ tlp_read_srom(struct tulip_softc *sc)
else
miirom &= ~MIIROM_SROMDI;
SROM_EMIT(sc, miirom);
- SROM_EMIT(sc, miirom|MIIROM_SROMSK);
+ SROM_EMIT(sc, miirom | MIIROM_SROMSK);
SROM_EMIT(sc, miirom);
}
@@ -2253,7 +2219,7 @@ tlp_read_srom(struct tulip_softc *sc)
else
miirom &= ~MIIROM_SROMDI;
SROM_EMIT(sc, miirom);
- SROM_EMIT(sc, miirom|MIIROM_SROMSK);
+ SROM_EMIT(sc, miirom | MIIROM_SROMSK);
SROM_EMIT(sc, miirom);
}
@@ -2261,7 +2227,7 @@ tlp_read_srom(struct tulip_softc *sc)
miirom &= ~MIIROM_SROMDI;
datain = 0;
for (x = 16; x > 0; x--) {
- SROM_EMIT(sc, miirom|MIIROM_SROMSK);
+ SROM_EMIT(sc, miirom | MIIROM_SROMSK);
if (TULIP_ISSET(sc, CSR_MIIROM, MIIROM_SROMDO))
datain |= (1 << (x - 1));
SROM_EMIT(sc, miirom);
@@ -2290,7 +2256,7 @@ tlp_read_srom(struct tulip_softc *sc)
printf("\n");
}
- return (1);
+ return 1;
}
#undef SROM_EMIT
@@ -2309,13 +2275,13 @@ tlp_add_rxbuf(struct tulip_softc *sc, in
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL)
- return (ENOBUFS);
+ return ENOBUFS;
MCLAIM(m, &sc->sc_ethercom.ec_rx_mowner);
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
m_freem(m);
- return (ENOBUFS);
+ return ENOBUFS;
}
if (rxs->rxs_mbuf != NULL)
@@ -2325,10 +2291,10 @@ tlp_add_rxbuf(struct tulip_softc *sc, in
error = bus_dmamap_load(sc->sc_dmat, rxs->rxs_dmamap,
m->m_ext.ext_buf, m->m_ext.ext_size, NULL,
- BUS_DMA_READ|BUS_DMA_NOWAIT);
+ BUS_DMA_READ | BUS_DMA_NOWAIT);
if (error) {
- aprint_error_dev(sc->sc_dev, "can't load rx DMA map %d, error = %d\n",
- idx, error);
+ aprint_error_dev(sc->sc_dev,
+ "can't load rx DMA map %d, error = %d\n", idx, error);
panic("tlp_add_rxbuf"); /* XXX */
}
@@ -2337,7 +2303,7 @@ tlp_add_rxbuf(struct tulip_softc *sc, in
TULIP_INIT_RXDESC(sc, idx);
- return (0);
+ return 0;
}
/*
@@ -2353,7 +2319,7 @@ tlp_srom_crcok(const uint8_t *romdata)
crc = ether_crc32_le(romdata, TULIP_ROM_CRC32_CHECKSUM);
crc = (crc & 0xffff) ^ 0xffff;
if (crc == TULIP_ROM_GETW(romdata, TULIP_ROM_CRC32_CHECKSUM))
- return (1);
+ return 1;
/*
* Try an alternate checksum.
@@ -2361,9 +2327,9 @@ tlp_srom_crcok(const uint8_t *romdata)
crc = ether_crc32_le(romdata, TULIP_ROM_CRC32_CHECKSUM1);
crc = (crc & 0xffff) ^ 0xffff;
if (crc == TULIP_ROM_GETW(romdata, TULIP_ROM_CRC32_CHECKSUM1))
- return (1);
+ return 1;
- return (0);
+ return 0;
}
/*
@@ -2381,7 +2347,7 @@ tlp_isv_srom(const uint8_t *romdata)
/*
* SROM CRC checks out; must be in the new format.
*/
- return (1);
+ return 1;
}
cksum = TULIP_ROM_GETW(romdata, TULIP_ROM_CRC32_CHECKSUM);
@@ -2393,16 +2359,16 @@ tlp_isv_srom(const uint8_t *romdata)
*/
for (i = 0; i < TULIP_ROM_SROM_FORMAT_VERION; i++) {
if (romdata[i] != 0)
- return (0);
+ return 0;
}
if (romdata[TULIP_ROM_SROM_FORMAT_VERION] != 1)
- return (0);
+ return 0;
if (romdata[TULIP_ROM_CHIP_COUNT] == 0)
- return (0);
- return (1);
+ return 0;
+ return 1;
}
- return (0);
+ return 0;
}
/*
@@ -2416,7 +2382,7 @@ tlp_isv_srom_enaddr(struct tulip_softc *
int i, devcnt;
if (tlp_isv_srom(sc->sc_srom) == 0)
- return (0);
+ return 0;
devcnt = sc->sc_srom[TULIP_ROM_CHIP_COUNT];
for (i = 0; i < devcnt; i++) {
@@ -2428,13 +2394,13 @@ tlp_isv_srom_enaddr(struct tulip_softc *
}
if (i == devcnt)
- return (0);
+ return 0;
memcpy(enaddr, &sc->sc_srom[TULIP_ROM_IEEE_NETWORK_ADDRESS],
ETHER_ADDR_LEN);
enaddr[5] += i;
- return (1);
+ return 1;
}
/*
@@ -2467,7 +2433,7 @@ tlp_parse_old_srom(struct tulip_softc *s
enaddr[i] = sc->sc_srom[i + 1];
enaddr[i + 1] = sc->sc_srom[i];
}
- return (1);
+ return 1;
}
/*
@@ -2484,7 +2450,7 @@ tlp_parse_old_srom(struct tulip_softc *s
enaddr[i] = sc->sc_srom[20 + i + 1];
enaddr[i + 1] = sc->sc_srom[20 + i];
}
- return (1);
+ return 1;
}
/*
@@ -2496,7 +2462,7 @@ tlp_parse_old_srom(struct tulip_softc *s
sc->sc_srom[1] == 0x10 &&
sc->sc_srom[2] == 0xe0) {
memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
- return (1);
+ return 1;
}
/*
@@ -2508,7 +2474,7 @@ tlp_parse_old_srom(struct tulip_softc *s
for (i = 8; i < 32; i++) {
if (sc->sc_srom[i] != 0xff &&
sc->sc_srom[i] != 0)
- return (0);
+ return 0;
}
/*
@@ -2519,13 +2485,13 @@ tlp_parse_old_srom(struct tulip_softc *s
* - Make sure it has a non-0 OUI
*/
if (sc->sc_srom[0] & 3)
- return (0);
+ return 0;
if (sc->sc_srom[0] == 0 && sc->sc_srom[1] == 0 &&
sc->sc_srom[2] == 0)
- return (0);
+ return 0;
memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
- return (1);
+ return 1;
}
/*
@@ -2533,11 +2499,11 @@ tlp_parse_old_srom(struct tulip_softc *s
*/
if (memcmp(&sc->sc_srom[24], testpat, 8) != 0)
- return (0);
+ return 0;
for (i = 0; i < 8; i++) {
if (sc->sc_srom[i] != sc->sc_srom[15 - i])
- return (0);
+ return 0;
}
memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
@@ -2561,9 +2527,9 @@ tlp_parse_old_srom(struct tulip_softc *s
cksum -= 0xffff;
if (cksum != *(uint16_t *) &sc->sc_srom[6])
- return (0);
+ return 0;
- return (1);
+ return 1;
}
/*
@@ -2580,6 +2546,7 @@ tlp_filter_setup(struct tulip_softc *sc)
struct ether_multistep step;
volatile uint32_t *sp;
struct tulip_txsoft *txs;
+ struct tulip_desc *txd;
uint8_t enaddr[ETHER_ADDR_LEN];
uint32_t hash, hashsize;
int cnt, nexttx;
@@ -2618,9 +2585,9 @@ tlp_filter_setup(struct tulip_softc *sc)
* in motion.
*/
if (ifp->if_flags & IFF_RUNNING)
- tlp_idle(sc, OPMODE_ST|OPMODE_SR);
+ tlp_idle(sc, OPMODE_ST | OPMODE_SR);
- sc->sc_opmode &= ~(OPMODE_PR|OPMODE_PM);
+ sc->sc_opmode &= ~(OPMODE_PR | OPMODE_PM);
if (ifp->if_flags & IFF_PROMISC) {
sc->sc_opmode |= OPMODE_PR;
@@ -2635,6 +2602,7 @@ tlp_filter_setup(struct tulip_softc *sc)
sp = TULIP_CDSP(sc);
memset(TULIP_CDSP(sc), 0, TULIP_SETUP_PACKET_LEN);
cnt = 0;
+ ETHER_LOCK(ec);
ETHER_FIRST_MULTI(step, ec, enm);
while (enm != NULL) {
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
@@ -2646,6 +2614,7 @@ tlp_filter_setup(struct tulip_softc *sc)
* ranges is for IP multicast routing, for which the
* range is big enough to require all bits set.)
*/
+ ETHER_UNLOCK(ec);
goto allmulti;
}
if (cnt == (TULIP_MAXADDRS - 2)) {
@@ -2654,6 +2623,7 @@ tlp_filter_setup(struct tulip_softc *sc)
* our station address and broadcast). Go to
* Hash-Perfect mode.
*/
+ ETHER_UNLOCK(ec);
goto hashperfect;
}
cnt++;
@@ -2662,6 +2632,7 @@ tlp_filter_setup(struct tulip_softc *sc)
*sp++ = htole32(TULIP_SP_FIELD(enm->enm_addrlo, 2));
ETHER_NEXT_MULTI(step, enm);
}
+ ETHER_UNLOCK(ec);
if (ifp->if_flags & IFF_BROADCAST) {
/* ...and the broadcast address. */
@@ -2696,6 +2667,7 @@ tlp_filter_setup(struct tulip_softc *sc)
sc->sc_filtmode = TDCTL_Tx_FT_HASH;
sp = TULIP_CDSP(sc);
memset(TULIP_CDSP(sc), 0, TULIP_SETUP_PACKET_LEN);
+ ETHER_LOCK(ec);
ETHER_FIRST_MULTI(step, ec, enm);
while (enm != NULL) {
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, ETHER_ADDR_LEN)) {
@@ -2707,12 +2679,14 @@ tlp_filter_setup(struct tulip_softc *sc)
* ranges is for IP multicast routing, for which the
* range is big enough to require all bits set.)
*/
+ ETHER_UNLOCK(ec);
goto allmulti;
}
hash = tlp_mchash(enm->enm_addrlo, hashsize);
sp[hash >> 4] |= htole32(1 << (hash & 0xf));
ETHER_NEXT_MULTI(step, enm);
}
+ ETHER_UNLOCK(ec);
if (ifp->if_flags & IFF_BROADCAST) {
/* ...and the broadcast address. */
@@ -2777,34 +2751,32 @@ tlp_filter_setup(struct tulip_softc *sc)
txs->txs_mbuf = NULL;
nexttx = sc->sc_txnext;
- sc->sc_txdescs[nexttx].td_status = 0;
- sc->sc_txdescs[nexttx].td_bufaddr1 = htole32(TULIP_CDSPADDR(sc));
- sc->sc_txdescs[nexttx].td_ctl =
- htole32((TULIP_SETUP_PACKET_LEN << TDCTL_SIZE1_SHIFT) |
+ txd = &sc->sc_txdescs[nexttx];
+ txd->td_status = 0;
+ txd->td_bufaddr1 = htole32(TULIP_CDSPADDR(sc));
+ txd->td_ctl = htole32((TULIP_SETUP_PACKET_LEN << TDCTL_SIZE1_SHIFT) |
sc->sc_filtmode | TDCTL_Tx_SET | sc->sc_setup_fsls |
TDCTL_Tx_IC | sc->sc_tdctl_ch |
(nexttx == (TULIP_NTXDESC - 1) ? sc->sc_tdctl_er : 0));
TULIP_CDTXSYNC(sc, nexttx, 1,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+ BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
#ifdef TLP_DEBUG
if (ifp->if_flags & IFF_DEBUG) {
printf(" filter_setup %p transmit chain:\n", txs);
printf(" descriptor %d:\n", nexttx);
- printf(" td_status: 0x%08x\n",
- le32toh(sc->sc_txdescs[nexttx].td_status));
- printf(" td_ctl: 0x%08x\n",
- le32toh(sc->sc_txdescs[nexttx].td_ctl));
+ printf(" td_status: 0x%08x\n", le32toh(txd->td_status));
+ printf(" td_ctl: 0x%08x\n", le32toh(txd->td_ctl));
printf(" td_bufaddr1: 0x%08x\n",
- le32toh(sc->sc_txdescs[nexttx].td_bufaddr1));
+ le32toh(txd->td_bufaddr1));
printf(" td_bufaddr2: 0x%08x\n",
- le32toh(sc->sc_txdescs[nexttx].td_bufaddr2));
+ le32toh(txd->td_bufaddr2));
}
#endif
- sc->sc_txdescs[nexttx].td_status = htole32(TDSTAT_OWN);
+ txd->td_status = htole32(TDSTAT_OWN);
TULIP_CDTXSYNC(sc, nexttx, 1,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
+ BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
/* Advance the tx pointer. */
sc->sc_txfree -= 1;
@@ -2831,7 +2803,8 @@ tlp_filter_setup(struct tulip_softc *sc)
/* Set up a watchdog timer in case the chip flakes out. */
ifp->if_timer = 5;
- DPRINTF(sc, ("%s: tlp_filter_setup: returning\n", device_xname(sc->sc_dev)));
+ DPRINTF(sc, ("%s: tlp_filter_setup: returning\n",
+ device_xname(sc->sc_dev)));
}
/*
@@ -2851,7 +2824,7 @@ tlp_winb_filter_setup(struct tulip_softc
DPRINTF(sc, ("%s: tlp_winb_filter_setup: sc_flags 0x%08x\n",
device_xname(sc->sc_dev), sc->sc_flags));
- sc->sc_opmode &= ~(OPMODE_WINB_APP|OPMODE_WINB_AMP|OPMODE_WINB_ABP);
+ sc->sc_opmode &= ~(OPMODE_WINB_APP | OPMODE_WINB_AMP |OPMODE_WINB_ABP);
if (ifp->if_flags & IFF_MULTICAST)
sc->sc_opmode |= OPMODE_WINB_AMP;
@@ -2933,7 +2906,7 @@ tlp_al981_filter_setup(struct tulip_soft
DPRINTF(sc, ("%s: tlp_al981_filter_setup: sc_flags 0x%08x\n",
device_xname(sc->sc_dev), sc->sc_flags));
- sc->sc_opmode &= ~(OPMODE_PR|OPMODE_PM);
+ sc->sc_opmode &= ~(OPMODE_PR | OPMODE_PM);
if (ifp->if_flags & IFF_PROMISC) {
sc->sc_opmode |= OPMODE_PR;
@@ -2942,6 +2915,7 @@ tlp_al981_filter_setup(struct tulip_soft
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)) {
@@ -2953,13 +2927,15 @@ tlp_al981_filter_setup(struct tulip_soft
* ranges is for IP multicast routing, for which the
* range is big enough to require all bits set.)
*/
+ ETHER_UNLOCK(ec);
goto allmulti;
}
hash = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN) & 0x3f;
- mchash[hash >> 5] |= 1 << (hash & 0x1f);
+ mchash[hash >> 5] |= __BIT(hash & 0x1f);
ETHER_NEXT_MULTI(step, enm);
}
+ ETHER_UNLOCK(ec);
ifp->if_flags &= ~IFF_ALLMULTI;
goto setit;
@@ -2978,7 +2954,7 @@ tlp_al981_filter_setup(struct tulip_soft
/*
* tlp_asix_filter_setup:
*
- * Set the ASIX AX8814x recieve filter.
+ * Set the ASIX AX8814x receive filter.
*/
static void
tlp_asix_filter_setup(struct tulip_softc *sc)
@@ -2992,7 +2968,7 @@ tlp_asix_filter_setup(struct tulip_softc
DPRINTF(sc, ("%s: tlp_asix_filter_setup: sc_flags 0x%08x\n",
device_xname(sc->sc_dev), sc->sc_flags));
- sc->sc_opmode &= ~(OPMODE_PM|OPMODE_AX_RB|OPMODE_PR);
+ sc->sc_opmode &= ~(OPMODE_PM | OPMODE_AX_RB | OPMODE_PR);
if (ifp->if_flags & IFF_MULTICAST)
sc->sc_opmode |= OPMODE_PM;
@@ -3007,6 +2983,7 @@ tlp_asix_filter_setup(struct tulip_softc
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)) {
@@ -3018,6 +2995,7 @@ tlp_asix_filter_setup(struct tulip_softc
* ranges is for IP multicast routing, for which the
* range is big enough to require all bits set.)
*/
+ ETHER_UNLOCK(ec);
goto allmulti;
}
hash = (ether_crc32_be(enm->enm_addrlo, ETHER_ADDR_LEN) >> 26)
@@ -3028,6 +3006,7 @@ tlp_asix_filter_setup(struct tulip_softc
mchash[1] |= (1 << (hash - 32));
ETHER_NEXT_MULTI(step, enm);
}
+ ETHER_UNLOCK(ec);
ifp->if_flags &= ~IFF_ALLMULTI;
goto setit;
@@ -3198,8 +3177,8 @@ tlp_mediachange(struct ifnet *ifp)
struct tulip_softc *sc = ifp->if_softc;
if ((ifp->if_flags & IFF_UP) == 0)
- return (0);
- return ((*sc->sc_mediasw->tmsw_set)(sc));
+ return 0;
+ return (*sc->sc_mediasw->tmsw_set)(sc);
}
/*****************************************************************************
@@ -3233,14 +3212,14 @@ tlp_mii_tick(void *arg)
* Callback from PHY when media changes.
*/
static void
-tlp_mii_statchg(device_t self)
+tlp_mii_statchg(struct ifnet *ifp)
{
- struct tulip_softc *sc = device_private(self);
+ struct tulip_softc *sc = ifp->if_softc;
/* Idle the transmit and receive processes. */
- tlp_idle(sc, OPMODE_ST|OPMODE_SR);
+ tlp_idle(sc, OPMODE_ST | OPMODE_SR);
- sc->sc_opmode &= ~(OPMODE_TTM|OPMODE_FD|OPMODE_HBD);
+ sc->sc_opmode &= ~(OPMODE_TTM | OPMODE_FD | OPMODE_HBD);
if (IFM_SUBTYPE(sc->sc_mii.mii_media_active) == IFM_10_T)
sc->sc_opmode |= OPMODE_TTM;
@@ -3248,7 +3227,7 @@ tlp_mii_statchg(device_t self)
sc->sc_opmode |= OPMODE_HBD;
if (sc->sc_mii.mii_media_active & IFM_FDX)
- sc->sc_opmode |= OPMODE_FD|OPMODE_HBD;
+ sc->sc_opmode |= OPMODE_FD | OPMODE_HBD;
/*
* Write new OPMODE bits. This also restarts the transmit
@@ -3264,14 +3243,14 @@ tlp_mii_statchg(device_t self)
* for the Winbond 89C840F, which has different OPMODE bits.
*/
static void
-tlp_winb_mii_statchg(device_t self)
+tlp_winb_mii_statchg(struct ifnet *ifp)
{
- struct tulip_softc *sc = device_private(self);
+ struct tulip_softc *sc = ifp->if_softc;
/* Idle the transmit and receive processes. */
- tlp_idle(sc, OPMODE_ST|OPMODE_SR);
+ tlp_idle(sc, OPMODE_ST | OPMODE_SR);
- sc->sc_opmode &= ~(OPMODE_WINB_FES|OPMODE_FD);
+ sc->sc_opmode &= ~(OPMODE_WINB_FES | OPMODE_FD);
if (IFM_SUBTYPE(sc->sc_mii.mii_media_active) == IFM_100_TX)
sc->sc_opmode |= OPMODE_WINB_FES;
@@ -3293,15 +3272,15 @@ tlp_winb_mii_statchg(device_t self)
* for the DM9102.
*/
static void
-tlp_dm9102_mii_statchg(device_t self)
+tlp_dm9102_mii_statchg(struct ifnet *ifp)
{
- struct tulip_softc *sc = device_private(self);
+ struct tulip_softc *sc = ifp->if_softc;
/*
* Don't idle the transmit and receive processes, here. It
* seems to fail, and just causes excess noise.
*/
- sc->sc_opmode &= ~(OPMODE_TTM|OPMODE_FD);
+ sc->sc_opmode &= ~(OPMODE_TTM | OPMODE_FD);
if (IFM_SUBTYPE(sc->sc_mii.mii_media_active) != IFM_100_TX)
sc->sc_opmode |= OPMODE_TTM;
@@ -3323,10 +3302,11 @@ tlp_dm9102_mii_statchg(device_t self)
static void
tlp_mii_getmedia(struct tulip_softc *sc, struct ifmediareq *ifmr)
{
+ struct mii_data * const mii = &sc->sc_mii;
- mii_pollstat(&sc->sc_mii);
- ifmr->ifm_status = sc->sc_mii.mii_media_status;
- ifmr->ifm_active = sc->sc_mii.mii_media_active;
+ mii_pollstat(mii);
+ ifmr->ifm_status = mii->mii_media_status;
+ ifmr->ifm_active = mii->mii_media_active;
}
/*
@@ -3364,11 +3344,11 @@ tlp_mii_setmedia(struct tulip_softc *sc)
* Read a PHY register via bit-bang'ing the MII.
*/
static int
-tlp_bitbang_mii_readreg(device_t self, int phy, int reg)
+tlp_bitbang_mii_readreg(device_t self, int phy, int reg, uint16_t *val)
{
struct tulip_softc *sc = device_private(self);
- return (mii_bitbang_readreg(self, sc->sc_bitbang_ops, phy, reg));
+ return mii_bitbang_readreg(self, sc->sc_bitbang_ops, phy, reg, val);
}
/*
@@ -3376,12 +3356,12 @@ tlp_bitbang_mii_readreg(device_t self, i
*
* Write a PHY register via bit-bang'ing the MII.
*/
-static void
-tlp_bitbang_mii_writereg(device_t self, int phy, int reg, int val)
+static int
+tlp_bitbang_mii_writereg(device_t self, int phy, int reg, uint16_t val)
{
struct tulip_softc *sc = device_private(self);
- mii_bitbang_writereg(self, sc->sc_bitbang_ops, phy, reg, val);
+ return mii_bitbang_writereg(self, sc->sc_bitbang_ops, phy, reg, val);
}
/*
@@ -3394,7 +3374,7 @@ tlp_sio_mii_bitbang_read(device_t self)
{
struct tulip_softc *sc = device_private(self);
- return (TULIP_READ(sc, CSR_MIIROM));
+ return TULIP_READ(sc, CSR_MIIROM);
}
/*
@@ -3416,10 +3396,10 @@ tlp_sio_mii_bitbang_write(device_t self,
* Read a PHY register on the Lite-On PNIC.
*/
static int
-tlp_pnic_mii_readreg(device_t self, int phy, int reg)
+tlp_pnic_mii_readreg(device_t self, int phy, int reg, uint16_t *val)
{
struct tulip_softc *sc = device_private(self);
- uint32_t val;
+ uint32_t data;
int i;
TULIP_WRITE(sc, CSR_PNIC_MII,
@@ -3429,16 +3409,18 @@ tlp_pnic_mii_readreg(device_t self, int
for (i = 0; i < 1000; i++) {
delay(10);
- val = TULIP_READ(sc, CSR_PNIC_MII);
- if ((val & PNIC_MII_BUSY) == 0) {
- if ((val & PNIC_MII_DATA) == PNIC_MII_DATA)
- return (0);
- else
- return (val & PNIC_MII_DATA);
+ data = TULIP_READ(sc, CSR_PNIC_MII);
+ if ((data & PNIC_MII_BUSY) == 0) {
+ if ((data & PNIC_MII_DATA) == PNIC_MII_DATA)
+ return -1;
+ else {
+ *val = data & PNIC_MII_DATA;
+ return 0;
+ }
}
}
printf("%s: MII read timed out\n", device_xname(sc->sc_dev));
- return (0);
+ return ETIMEDOUT;
}
/*
@@ -3446,8 +3428,8 @@ tlp_pnic_mii_readreg(device_t self, int
*
* Write a PHY register on the Lite-On PNIC.
*/
-static void
-tlp_pnic_mii_writereg(device_t self, int phy, int reg, int val)
+static int
+tlp_pnic_mii_writereg(device_t self, int phy, int reg, uint16_t val)
{
struct tulip_softc *sc = device_private(self);
int i;
@@ -3460,9 +3442,10 @@ tlp_pnic_mii_writereg(device_t self, int
for (i = 0; i < 1000; i++) {
delay(10);
if (TULIP_ISSET(sc, CSR_PNIC_MII, PNIC_MII_BUSY) == 0)
- return;
+ return 0;
}
printf("%s: MII write timed out\n", device_xname(sc->sc_dev));
+ return ETIMEDOUT;
}
static const bus_addr_t tlp_al981_phy_regmap[] = {
@@ -3488,19 +3471,20 @@ static const int tlp_al981_phy_regmap_si
* Read a PHY register on the ADMtek AL981.
*/
static int
-tlp_al981_mii_readreg(device_t self, int phy, int reg)
+tlp_al981_mii_readreg(device_t self, int phy, int reg, uint16_t *val)
{
struct tulip_softc *sc = device_private(self);
/* AL981 only has an internal PHY. */
if (phy != 0)
- return (0);
+ return -1;
if (reg >= tlp_al981_phy_regmap_size)
- return (0);
+ return -1;
- return (bus_space_read_4(sc->sc_st, sc->sc_sh,
- tlp_al981_phy_regmap[reg]) & 0xffff);
+ *val = bus_space_read_4(sc->sc_st, sc->sc_sh,
+ tlp_al981_phy_regmap[reg]) & 0xffff;
+ return 0;
}
/*
@@ -3508,20 +3492,22 @@ tlp_al981_mii_readreg(device_t self, int
*
* Write a PHY register on the ADMtek AL981.
*/
-static void
-tlp_al981_mii_writereg(device_t self, int phy, int reg, int val)
+static int
+tlp_al981_mii_writereg(device_t self, int phy, int reg, uint16_t val)
{
struct tulip_softc *sc = device_private(self);
/* AL981 only has an internal PHY. */
if (phy != 0)
- return;
+ return -1;
if (reg >= tlp_al981_phy_regmap_size)
- return;
+ return -1;
bus_space_write_4(sc->sc_st, sc->sc_sh,
tlp_al981_phy_regmap[reg], val);
+
+ return 0;
}
/*****************************************************************************
@@ -3565,7 +3551,7 @@ tlp_2114x_mii_preinit(struct tulip_softc
* Always set the Must-Be-One bit, and Port Select (to select MII).
* We'll never be called during a media change.
*/
- sc->sc_opmode |= OPMODE_MBO|OPMODE_PS;
+ sc->sc_opmode |= OPMODE_MBO | OPMODE_PS;
TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
}
@@ -3605,7 +3591,7 @@ tlp_asix_preinit(struct tulip_softc *sc)
case TULIP_CHIP_AX88140:
case TULIP_CHIP_AX88141:
/* XXX Handle PHY. */
- sc->sc_opmode |= OPMODE_HBD|OPMODE_PS;
+ sc->sc_opmode |= OPMODE_HBD | OPMODE_PS;
break;
default:
/* Nothing */
@@ -3626,7 +3612,7 @@ tlp_dm9102_preinit(struct tulip_softc *s
switch (sc->sc_chip) {
case TULIP_CHIP_DM9102:
- sc->sc_opmode |= OPMODE_MBO|OPMODE_HBD|OPMODE_PS;
+ sc->sc_opmode |= OPMODE_MBO | OPMODE_HBD | OPMODE_PS;
break;
case TULIP_CHIP_DM9102A:
@@ -3634,7 +3620,7 @@ tlp_dm9102_preinit(struct tulip_softc *s
* XXX Figure out how to actually deal with the HomePNA
* XXX portion of the DM9102A.
*/
- sc->sc_opmode |= OPMODE_MBO|OPMODE_HBD;
+ sc->sc_opmode |= OPMODE_MBO | OPMODE_HBD;
break;
default:
@@ -3658,7 +3644,7 @@ tlp_21140_reset(struct tulip_softc *sc)
int i;
/* First, set the direction on the GPIO pins. */
- TULIP_WRITE(sc, CSR_GPP, GPP_GPC|sc->sc_gp_dir);
+ TULIP_WRITE(sc, CSR_GPP, GPP_GPC | sc->sc_gp_dir);
/* Now, issue the reset sequence. */
for (i = 0; i < tm->tm_reset_length; i++) {
@@ -3758,7 +3744,7 @@ static void
tlp_dm9102_reset(struct tulip_softc *sc)
{
- TULIP_WRITE(sc, CSR_DM_PHYSTAT, DM_PHYSTAT_GEPC|DM_PHYSTAT_GPED);
+ TULIP_WRITE(sc, CSR_DM_PHYSTAT, DM_PHYSTAT_GEPC | DM_PHYSTAT_GPED);
delay(100);
TULIP_WRITE(sc, CSR_DM_PHYSTAT, 0);
}
@@ -3828,7 +3814,7 @@ static const struct tulip_srom_to_ifmedi
{ TULIP_ROM_MB_MEDIA_100TX, IFM_100_TX, 0,
"100baseTX",
- OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_HBD,
+ OPMODE_PS | OPMODE_PCS | OPMODE_SCR | OPMODE_HBD,
BMSR_100TXHDX,
{ 0,
0,
@@ -3844,7 +3830,7 @@ static const struct tulip_srom_to_ifmedi
{ TULIP_ROM_MB_MEDIA_TP_FDX, IFM_10_T, IFM_FDX,
"10baseT-FDX",
- OPMODE_TTM|OPMODE_FD|OPMODE_HBD,
+ OPMODE_TTM | OPMODE_FD | OPMODE_HBD,
BMSR_10TFDX,
{ SIACONN_21040_10BASET_FDX,
SIATXRX_21040_10BASET_FDX,
@@ -3860,7 +3846,7 @@ static const struct tulip_srom_to_ifmedi
{ TULIP_ROM_MB_MEDIA_100TX_FDX, IFM_100_TX, IFM_FDX,
"100baseTX-FDX",
- OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_FD|OPMODE_HBD,
+ OPMODE_PS | OPMODE_PCS | OPMODE_SCR | OPMODE_FD | OPMODE_HBD,
BMSR_100TXFDX,
{ 0,
0,
@@ -3876,7 +3862,7 @@ static const struct tulip_srom_to_ifmedi
{ TULIP_ROM_MB_MEDIA_100T4, IFM_100_T4, 0,
"100baseT4",
- OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_HBD,
+ OPMODE_PS | OPMODE_PCS | OPMODE_SCR | OPMODE_HBD,
BMSR_100T4,
{ 0,
0,
@@ -3892,7 +3878,7 @@ static const struct tulip_srom_to_ifmedi
{ TULIP_ROM_MB_MEDIA_100FX, IFM_100_FX, 0,
"100baseFX",
- OPMODE_PS|OPMODE_PCS|OPMODE_HBD,
+ OPMODE_PS | OPMODE_PCS | OPMODE_HBD,
0,
{ 0,
0,
@@ -3908,7 +3894,7 @@ static const struct tulip_srom_to_ifmedi
{ TULIP_ROM_MB_MEDIA_100FX_FDX, IFM_100_FX, IFM_FDX,
"100baseFX-FDX",
- OPMODE_PS|OPMODE_PCS|OPMODE_FD|OPMODE_HBD,
+ OPMODE_PS | OPMODE_PCS | OPMODE_FD | OPMODE_HBD,
0,
{ 0,
0,
@@ -3958,10 +3944,10 @@ tlp_srom_to_ifmedia(uint8_t sm)
for (tsti = tulip_srom_to_ifmedia_table;
tsti->tsti_name != NULL; tsti++) {
if (tsti->tsti_srom == sm)
- return (tsti);
+ return tsti;
}
- return (NULL);
+ return NULL;
}
static void
@@ -4012,7 +3998,7 @@ tlp_add_srom_media(struct tulip_softc *s
for (i = 0; i < cnt; i++) {
tsti = tlp_srom_to_ifmedia(list[i]);
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
tlp_srom_media_info(sc, tsti, tm);
tm->tm_type = type;
tm->tm_get = get;
@@ -4102,7 +4088,7 @@ tlp_sia_update_link(struct tulip_softc *
ife = TULIP_CURRENT_MEDIA(sc);
tm = ife->ifm_aux;
- sc->sc_flags &= ~(TULIPF_LINK_UP|TULIPF_LINK_VALID);
+ sc->sc_flags &= ~(TULIPF_LINK_UP | TULIPF_LINK_VALID);
siastat = TULIP_READ(sc, CSR_SIASTAT);
@@ -4226,7 +4212,7 @@ static int
tlp_sia_set(struct tulip_softc *sc)
{
- return (tlp_sia_media(sc, TULIP_CURRENT_MEDIA(sc)));
+ return tlp_sia_media(sc, TULIP_CURRENT_MEDIA(sc));
}
static int
@@ -4244,7 +4230,7 @@ tlp_sia_media(struct tulip_softc *sc, st
/*
* Idle the chip.
*/
- tlp_idle(sc, OPMODE_ST|OPMODE_SR);
+ tlp_idle(sc, OPMODE_ST | OPMODE_SR);
/*
* Program the SIA. It's important to write in this order,
@@ -4274,7 +4260,7 @@ tlp_sia_media(struct tulip_softc *sc, st
sc->sc_opmode = (sc->sc_opmode & ~OPMODE_MEDIA_BITS) | tm->tm_opmode;
TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
- return (0);
+ return 0;
}
/*
@@ -4291,7 +4277,7 @@ tlp_21140_gpio_update_link(struct tulip_
ife = TULIP_CURRENT_MEDIA(sc);
tm = ife->ifm_aux;
- sc->sc_flags &= ~(TULIPF_LINK_UP|TULIPF_LINK_VALID);
+ sc->sc_flags &= ~(TULIPF_LINK_UP | TULIPF_LINK_VALID);
if (tm->tm_actmask != 0) {
sc->sc_flags |= TULIPF_LINK_VALID;
@@ -4331,13 +4317,13 @@ tlp_21140_gpio_set(struct tulip_softc *s
/*
* Idle the chip.
*/
- tlp_idle(sc, OPMODE_ST|OPMODE_SR);
+ tlp_idle(sc, OPMODE_ST | OPMODE_SR);
/*
* Set the GPIO pins for this media, to flip any
* relays, etc.
*/
- TULIP_WRITE(sc, CSR_GPP, GPP_GPC|sc->sc_gp_dir);
+ TULIP_WRITE(sc, CSR_GPP, GPP_GPC | sc->sc_gp_dir);
delay(10);
TULIP_WRITE(sc, CSR_GPP, tm->tm_gpdata);
@@ -4348,7 +4334,7 @@ tlp_21140_gpio_set(struct tulip_softc *s
sc->sc_opmode = (sc->sc_opmode & ~OPMODE_MEDIA_BITS) | tm->tm_opmode;
TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
- return (0);
+ return 0;
}
/*
@@ -4378,6 +4364,7 @@ const struct tulip_mediasw tlp_21041_med
static void
tlp_21040_tmsw_init(struct tulip_softc *sc)
{
+ struct mii_data * const mii = &sc->sc_mii;
static const uint8_t media[] = {
TULIP_ROM_MB_MEDIA_TP,
TULIP_ROM_MB_MEDIA_TP_FDX,
@@ -4385,21 +4372,21 @@ tlp_21040_tmsw_init(struct tulip_softc *
};
struct tulip_21x4x_media *tm;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
tlp_add_srom_media(sc, 0, NULL, NULL, media, 3);
/*
* No SROM type for External SIA.
*/
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
tm->tm_name = "manual";
tm->tm_opmode = 0;
tm->tm_siaconn = SIACONN_21040_EXTSIA;
tm->tm_siatxrx = SIATXRX_21040_EXTSIA;
tm->tm_siagen = SIAGEN_21040_EXTSIA;
- ifmedia_add(&sc->sc_mii.mii_media,
+ ifmedia_add(&mii->mii_media,
IFM_MAKEWORD(IFM_ETHER, IFM_MANUAL, 0, sc->sc_tlp_minst), 0, tm);
/*
@@ -4407,7 +4394,7 @@ tlp_21040_tmsw_init(struct tulip_softc *
*/
/* XXX This should be auto-sense. */
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_10_T);
tlp_print_media(sc);
}
@@ -4415,17 +4402,18 @@ tlp_21040_tmsw_init(struct tulip_softc *
static void
tlp_21040_tp_tmsw_init(struct tulip_softc *sc)
{
+ struct mii_data * const mii = &sc->sc_mii;
static const uint8_t media[] = {
TULIP_ROM_MB_MEDIA_TP,
TULIP_ROM_MB_MEDIA_TP_FDX,
};
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
tlp_add_srom_media(sc, 0, NULL, NULL, media, 2);
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_10_T);
tlp_print_media(sc);
}
@@ -4433,16 +4421,17 @@ tlp_21040_tp_tmsw_init(struct tulip_soft
static void
tlp_21040_auibnc_tmsw_init(struct tulip_softc *sc)
{
+ struct mii_data * const mii = &sc->sc_mii;
static const uint8_t media[] = {
TULIP_ROM_MB_MEDIA_AUI,
};
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
tlp_add_srom_media(sc, 0, NULL, NULL, media, 1);
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_5);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_10_5);
tlp_print_media(sc);
}
@@ -4450,6 +4439,7 @@ tlp_21040_auibnc_tmsw_init(struct tulip_
static void
tlp_21041_tmsw_init(struct tulip_softc *sc)
{
+ struct mii_data * const mii = &sc->sc_mii;
static const uint8_t media[] = {
TULIP_ROM_MB_MEDIA_TP,
TULIP_ROM_MB_MEDIA_TP_FDX,
@@ -4462,8 +4452,8 @@ tlp_21041_tmsw_init(struct tulip_softc *
uint16_t romdef;
uint8_t mb;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
if (tlp_isv_srom(sc->sc_srom) == 0) {
not_isv_srom:
@@ -4479,7 +4469,7 @@ tlp_21041_tmsw_init(struct tulip_softc *
*/
/* XXX This should be auto-sense. */
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_10_T);
tlp_print_media(sc);
return;
@@ -4505,7 +4495,7 @@ tlp_21041_tmsw_init(struct tulip_softc *
for (; m_cnt != 0;
m_cnt--, mb_offset += TULIP_ROM_MB_SIZE(mb)) {
mb = sc->sc_srom[mb_offset];
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
switch (mb & TULIP_ROM_MB_MEDIA_CODE) {
case TULIP_ROM_MB_MEDIA_TP_FDX:
case TULIP_ROM_MB_MEDIA_TP:
@@ -4529,7 +4519,7 @@ tlp_21041_tmsw_init(struct tulip_softc *
mb_offset + TULIP_ROM_MB_CSR15);
}
- ifmedia_add(&sc->sc_mii.mii_media,
+ ifmedia_add(&mii->mii_media,
IFM_MAKEWORD(IFM_ETHER, tsti->tsti_subtype,
tsti->tsti_options, sc->sc_tlp_minst), 0, tm);
break;
@@ -4552,24 +4542,24 @@ tlp_21041_tmsw_init(struct tulip_softc *
case SELECT_CONN_TYPE_TP:
case SELECT_CONN_TYPE_TP_AUTONEG:
case SELECT_CONN_TYPE_TP_NOLINKPASS:
- defmedia = IFM_ETHER|IFM_10_T;
+ defmedia = IFM_ETHER | IFM_10_T;
break;
case SELECT_CONN_TYPE_TP_FDX:
- defmedia = IFM_ETHER|IFM_10_T|IFM_FDX;
+ defmedia = IFM_ETHER | IFM_10_T | IFM_FDX;
break;
case SELECT_CONN_TYPE_BNC:
- defmedia = IFM_ETHER|IFM_10_2;
+ defmedia = IFM_ETHER | IFM_10_2;
break;
case SELECT_CONN_TYPE_AUI:
- defmedia = IFM_ETHER|IFM_10_5;
+ defmedia = IFM_ETHER | IFM_10_5;
break;
#if 0 /* XXX */
case SELECT_CONN_TYPE_ASENSE:
case SELECT_CONN_TYPE_ASENSE_AUTONEG:
- defmedia = IFM_ETHER|IFM_AUTO;
+ defmedia = IFM_ETHER | IFM_AUTO;
break;
#endif
default:
@@ -4580,10 +4570,10 @@ tlp_21041_tmsw_init(struct tulip_softc *
/*
* XXX We should default to auto-sense.
*/
- defmedia = IFM_ETHER|IFM_10_T;
+ defmedia = IFM_ETHER | IFM_10_T;
}
- ifmedia_set(&sc->sc_mii.mii_media, defmedia);
+ ifmedia_set(&mii->mii_media, defmedia);
tlp_print_media(sc);
}
@@ -4603,7 +4593,7 @@ const struct tulip_mediasw tlp_2114x_isv
static void tlp_2114x_nway_get(struct tulip_softc *, struct ifmediareq *);
static int tlp_2114x_nway_set(struct tulip_softc *);
-static void tlp_2114x_nway_statchg(device_t);
+static void tlp_2114x_nway_statchg(struct ifnet *);
static int tlp_2114x_nway_service(struct tulip_softc *, int);
static void tlp_2114x_nway_auto(struct tulip_softc *);
static void tlp_2114x_nway_status(struct tulip_softc *);
@@ -4612,6 +4602,7 @@ static void
tlp_2114x_isv_tmsw_init(struct tulip_softc *sc)
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+ struct mii_data * const mii = &sc->sc_mii;
struct ifmedia_entry *ife;
struct mii_softc *phy;
struct tulip_21x4x_media *tm;
@@ -4623,10 +4614,11 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
defmedia = miidef = 0;
- sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
- sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
- sc->sc_mii.mii_statchg = sc->sc_statchg;
+ mii->mii_ifp = ifp;
+ mii->mii_readreg = tlp_bitbang_mii_readreg;
+ mii->mii_writereg = tlp_bitbang_mii_writereg;
+ mii->mii_statchg = sc->sc_statchg;
+ sc->sc_ethercom.ec_mii = mii;
/*
* Ignore `instance'; we may get a mixture of SIA and MII
@@ -4634,7 +4626,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
* PHY on the MII as appropriate. Note that duplicate media
* are disallowed, so ignoring `instance' is safe.
*/
- ifmedia_init(&sc->sc_mii.mii_media, IFM_IMASK, tlp_mediachange,
+ ifmedia_init(&mii->mii_media, IFM_IMASK, tlp_mediachange,
tlp_mediastatus);
devcnt = sc->sc_srom[TULIP_ROM_CHIP_COUNT];
@@ -4647,7 +4639,8 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
}
if (i == devcnt) {
- aprint_error_dev(sc->sc_dev, "unable to locate info leaf in SROM\n");
+ aprint_error_dev(sc->sc_dev,
+ "unable to locate info leaf in SROM\n");
return;
}
@@ -4710,7 +4703,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
tlp_get_minst(sc);
sc->sc_media_seen |= 1 << TULIP_ROM_MB_21140_GPR;
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
tm->tm_type = TULIP_ROM_MB_21140_GPR;
tm->tm_get = tlp_21140_gpio_get;
@@ -4747,7 +4740,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
0 : tm->tm_actmask;
}
- ifmedia_add(&sc->sc_mii.mii_media,
+ ifmedia_add(&mii->mii_media,
IFM_MAKEWORD(IFM_ETHER, tsti->tsti_subtype,
tsti->tsti_options, sc->sc_tlp_minst), 0, tm);
break;
@@ -4755,7 +4748,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
case TULIP_ROM_MB_21140_MII:
sc->sc_media_seen |= 1 << TULIP_ROM_MB_21140_MII;
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
tm->tm_type = TULIP_ROM_MB_21140_MII;
tm->tm_get = tlp_mii_getmedia;
@@ -4797,7 +4790,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
*/
/* Set the direction of the pins... */
- TULIP_WRITE(sc, CSR_GPP, GPP_GPC|sc->sc_gp_dir);
+ TULIP_WRITE(sc, CSR_GPP, GPP_GPC | sc->sc_gp_dir);
for (i = 0; i < tm->tm_reset_length; i++) {
delay(10);
@@ -4823,7 +4816,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
* particularly care; the MII code just likes to
* search the whole thing anyhow.
*/
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff,
+ mii_attach(sc->sc_dev, mii, 0xffffffff,
MII_PHY_ANY, tm->tm_phyno, 0);
/*
@@ -4832,12 +4825,13 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
* kernel, we lose. The PHY's default media always
* takes priority.
*/
- LIST_FOREACH(phy, &sc->sc_mii.mii_phys, mii_list) {
+ LIST_FOREACH(phy, &mii->mii_phys, mii_list) {
if (phy->mii_offset == tm->tm_phyno)
break;
}
if (phy == NULL) {
- aprint_error_dev(sc->sc_dev, "unable to configure MII\n");
+ aprint_error_dev(sc->sc_dev,
+ "unable to configure MII\n");
break;
}
@@ -4856,7 +4850,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
* We do this by looking for media with our
* PHY's `instance'.
*/
- TAILQ_FOREACH(ife, &sc->sc_mii.mii_media.ifm_list,
+ TAILQ_FOREACH(ife, &mii->mii_media.ifm_list,
ifm_list) {
if (IFM_INST(ife->ifm_media) != phy->mii_inst)
continue;
@@ -4868,7 +4862,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
tlp_get_minst(sc);
sc->sc_media_seen |= 1 << TULIP_ROM_MB_21142_SIA;
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
tm->tm_type = TULIP_ROM_MB_21142_SIA;
tm->tm_get = tlp_sia_get;
@@ -4902,7 +4896,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
tm->tm_gpctl = TULIP_ROM_GETW(cp, 0) << 16;
tm->tm_gpdata = TULIP_ROM_GETW(cp, 2) << 16;
- ifmedia_add(&sc->sc_mii.mii_media,
+ ifmedia_add(&mii->mii_media,
IFM_MAKEWORD(IFM_ETHER, tsti->tsti_subtype,
tsti->tsti_options, sc->sc_tlp_minst), 0, tm);
break;
@@ -4910,7 +4904,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
case TULIP_ROM_MB_21142_MII:
sc->sc_media_seen |= 1 << TULIP_ROM_MB_21142_MII;
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
tm->tm_type = TULIP_ROM_MB_21142_MII;
tm->tm_get = tlp_mii_getmedia;
@@ -4978,7 +4972,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
* particularly care; the MII code just likes to
* search the whole thing anyhow.
*/
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff,
+ mii_attach(sc->sc_dev, mii, 0xffffffff,
MII_PHY_ANY, tm->tm_phyno, 0);
/*
@@ -4987,12 +4981,13 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
* kernel, we lose. The PHY's default media always
* takes priority.
*/
- LIST_FOREACH(phy, &sc->sc_mii.mii_phys, mii_list) {
+ LIST_FOREACH(phy, &mii->mii_phys, mii_list) {
if (phy->mii_offset == tm->tm_phyno)
break;
}
if (phy == NULL) {
- aprint_error_dev(sc->sc_dev, "unable to configure MII\n");
+ aprint_error_dev(sc->sc_dev,
+ "unable to configure MII\n");
break;
}
@@ -5011,7 +5006,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
* We do this by looking for media with our
* PHY's `instance'.
*/
- TAILQ_FOREACH(ife, &sc->sc_mii.mii_media.ifm_list,
+ TAILQ_FOREACH(ife, &mii->mii_media.ifm_list,
ifm_list) {
if (IFM_INST(ife->ifm_media) != phy->mii_inst)
continue;
@@ -5023,7 +5018,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
tlp_get_minst(sc);
sc->sc_media_seen |= 1 << TULIP_ROM_MB_21143_SYM;
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
tm->tm_type = TULIP_ROM_MB_21143_SYM;
tm->tm_get = tlp_sia_get;
@@ -5061,7 +5056,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
0 : tm->tm_actmask;
}
- ifmedia_add(&sc->sc_mii.mii_media,
+ ifmedia_add(&mii->mii_media,
IFM_MAKEWORD(IFM_ETHER, tsti->tsti_subtype,
tsti->tsti_options, sc->sc_tlp_minst), 0, tm);
break;
@@ -5079,10 +5074,10 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
/*
* Deal with the case where no media is configured.
*/
- if (TAILQ_FIRST(&sc->sc_mii.mii_media.ifm_list) == NULL) {
+ if (TAILQ_FIRST(&mii->mii_media.ifm_list) == NULL) {
aprint_error_dev(sc->sc_dev, "no media found!\n");
- ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
+ ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE);
return;
}
@@ -5097,13 +5092,13 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
case TULIP_CHIP_21140A:
/* XXX should come from SROM */
defmedia = IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, 0);
- if (ifmedia_match(&sc->sc_mii.mii_media, defmedia,
- sc->sc_mii.mii_media.ifm_mask) == NULL) {
+ if (ifmedia_match(&mii->mii_media, defmedia,
+ mii->mii_media.ifm_mask) == NULL) {
/*
* There is not a 10baseT media.
* Fall back to the first found one.
*/
- ife = TAILQ_FIRST(&sc->sc_mii.mii_media.ifm_list);
+ ife = TAILQ_FIRST(&mii->mii_media.ifm_list);
defmedia = ife->ifm_media;
}
break;
@@ -5115,13 +5110,13 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
case TULIP_CHIP_MX98715A:
case TULIP_CHIP_MX98715AEC_X:
case TULIP_CHIP_MX98725:
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
tm->tm_name = "auto";
tm->tm_get = tlp_2114x_nway_get;
tm->tm_set = tlp_2114x_nway_set;
defmedia = IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0);
- ifmedia_add(&sc->sc_mii.mii_media, defmedia, 0, tm);
+ ifmedia_add(&mii->mii_media, defmedia, 0, tm);
sc->sc_statchg = tlp_2114x_nway_statchg;
sc->sc_tick = tlp_2114x_nway_tick;
@@ -5133,7 +5128,7 @@ tlp_2114x_isv_tmsw_init(struct tulip_sof
}
}
- ifmedia_set(&sc->sc_mii.mii_media, defmedia);
+ ifmedia_set(&mii->mii_media, defmedia);
/*
* Display any non-MII media we've located.
@@ -5158,13 +5153,13 @@ static int
tlp_2114x_nway_set(struct tulip_softc *sc)
{
- return (tlp_2114x_nway_service(sc, MII_MEDIACHG));
+ return tlp_2114x_nway_service(sc, MII_MEDIACHG);
}
static void
-tlp_2114x_nway_statchg(device_t self)
+tlp_2114x_nway_statchg(struct ifnet *ifp)
{
- struct tulip_softc *sc = device_private(self);
+ struct tulip_softc *sc = ifp->if_softc;
struct mii_data *mii = &sc->sc_mii;
struct ifmedia_entry *ife;
@@ -5223,7 +5218,7 @@ tlp_2114x_nway_service(struct tulip_soft
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
- return (0);
+ return 0;
switch (cmd) {
case MII_POLLSTAT:
@@ -5237,7 +5232,7 @@ tlp_2114x_nway_service(struct tulip_soft
default:
/* Manual setting doesn't go through here. */
printf("tlp_2114x_nway_service: oops!\n");
- return (EINVAL);
+ return EINVAL;
}
break;
@@ -5281,10 +5276,10 @@ tlp_2114x_nway_service(struct tulip_soft
*/
if (IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO &&
ife->ifm_data != mii->mii_media_active) {
- (*sc->sc_statchg)(sc->sc_dev);
+ (*sc->sc_statchg)(mii->mii_ifp);
ife->ifm_data = mii->mii_media_active;
}
- return (0);
+ return 0;
}
static void
@@ -5292,10 +5287,10 @@ tlp_2114x_nway_auto(struct tulip_softc *
{
uint32_t siastat, siatxrx;
- tlp_idle(sc, OPMODE_ST|OPMODE_SR);
+ tlp_idle(sc, OPMODE_ST | OPMODE_SR);
- sc->sc_opmode &= ~(OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_FD);
- sc->sc_opmode |= OPMODE_TTM|OPMODE_HBD;
+ sc->sc_opmode &= ~(OPMODE_PS | OPMODE_PCS | OPMODE_SCR | OPMODE_FD);
+ sc->sc_opmode |= OPMODE_TTM | OPMODE_HBD;
siatxrx = 0xffbf; /* XXX magic number */
/* Compute the link code word to advertise. */
@@ -5318,8 +5313,8 @@ tlp_2114x_nway_auto(struct tulip_softc *
TULIP_WRITE(sc, CSR_SIACONN, SIACONN_SRL);
siastat = TULIP_READ(sc, CSR_SIASTAT);
- siastat &= ~(SIASTAT_ANS|SIASTAT_LPC|SIASTAT_TRA|SIASTAT_ARA|
- SIASTAT_LS100|SIASTAT_LS10|SIASTAT_MRA);
+ siastat &= ~(SIASTAT_ANS | SIASTAT_LPC | SIASTAT_TRA | SIASTAT_ARA |
+ SIASTAT_LS100 | SIASTAT_LS10 | SIASTAT_MRA);
siastat |= SIASTAT_ANS_TXDIS;
TULIP_WRITE(sc, CSR_SIASTAT, siastat);
}
@@ -5356,13 +5351,13 @@ tlp_2114x_nway_status(struct tulip_softc
mii->mii_media_active |= IFM_100_T4;
else if (anlpar & ANLPAR_TX_FD &&
sc->sc_sia_cap & BMSR_100TXFDX)
- mii->mii_media_active |= IFM_100_TX|IFM_FDX;
+ mii->mii_media_active |= IFM_100_TX | IFM_FDX;
else if (anlpar & ANLPAR_TX &&
sc->sc_sia_cap & BMSR_100TXHDX)
mii->mii_media_active |= IFM_100_TX;
else if (anlpar & ANLPAR_10_FD &&
sc->sc_sia_cap & BMSR_10TFDX)
- mii->mii_media_active |= IFM_10_T|IFM_FDX;
+ mii->mii_media_active |= IFM_10_T | IFM_FDX;
else if (anlpar & ANLPAR_10 &&
sc->sc_sia_cap & BMSR_10THDX)
mii->mii_media_active |= IFM_10_T;
@@ -5418,9 +5413,9 @@ tlp_2114x_isv_tmsw_set(struct tulip_soft
* time through.
*/
if (TULIP_MEDIA_NEEDSRESET(sc, tm->tm_opmode))
- return (tlp_init(&sc->sc_ethercom.ec_if));
+ return tlp_init(&sc->sc_ethercom.ec_if);
- return ((*tm->tm_set)(sc));
+ return (*tm->tm_set)(sc);
}
/*
@@ -5436,6 +5431,7 @@ static void
tlp_sio_mii_tmsw_init(struct tulip_softc *sc)
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+ struct mii_data * const mii = &sc->sc_mii;
/*
* We don't attach any media info structures to the ifmedia
@@ -5445,21 +5441,21 @@ tlp_sio_mii_tmsw_init(struct tulip_softc
if (sc->sc_preinit == tlp_2114x_preinit)
sc->sc_preinit = tlp_2114x_mii_preinit;
- sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
- sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
- sc->sc_mii.mii_statchg = sc->sc_statchg;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
+ mii->mii_ifp = ifp;
+ mii->mii_readreg = tlp_bitbang_mii_readreg;
+ mii->mii_writereg = tlp_bitbang_mii_writereg;
+ mii->mii_statchg = sc->sc_statchg;
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
+ mii_attach(sc->sc_dev, mii, 0xffffffff, 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);
+ 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 {
sc->sc_flags |= TULIPF_HAS_MII;
sc->sc_tick = tlp_mii_tick;
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
}
}
@@ -5474,7 +5470,7 @@ const struct tulip_mediasw tlp_pnic_medi
tlp_pnic_tmsw_init, tlp_pnic_tmsw_get, tlp_pnic_tmsw_set
};
-static void tlp_pnic_nway_statchg(device_t);
+static void tlp_pnic_nway_statchg(struct ifnet *);
static void tlp_pnic_nway_tick(void *);
static int tlp_pnic_nway_service(struct tulip_softc *, int);
static void tlp_pnic_nway_reset(struct tulip_softc *);
@@ -5486,58 +5482,59 @@ static void tlp_pnic_nway_acomp(struct t
static void
tlp_pnic_tmsw_init(struct tulip_softc *sc)
{
+ struct mii_data * const mii = &sc->sc_mii;
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
const char *sep = "";
-#define ADD(m, c) ifmedia_add(&sc->sc_mii.mii_media, (m), (c), NULL)
+#define ADD(m, c) ifmedia_add(&mii->mii_media, (m), (c), NULL)
#define PRINT(str) aprint_normal("%s%s", sep, str); sep = ", "
- sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = tlp_pnic_mii_readreg;
- sc->sc_mii.mii_writereg = tlp_pnic_mii_writereg;
- sc->sc_mii.mii_statchg = sc->sc_statchg;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
+ mii->mii_ifp = ifp;
+ mii->mii_readreg = tlp_pnic_mii_readreg;
+ mii->mii_writereg = tlp_pnic_mii_writereg;
+ mii->mii_statchg = sc->sc_statchg;
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
+ mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY,
MII_OFFSET_ANY, 0);
- if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
+ if (LIST_FIRST(&mii->mii_phys) == NULL) {
/* XXX What about AUI/BNC support? */
aprint_normal_dev(sc->sc_dev, "");
tlp_pnic_nway_reset(sc);
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, 0),
- PNIC_NWAY_TW|PNIC_NWAY_CAP10T);
+ PNIC_NWAY_TW | PNIC_NWAY_CAP10T);
PRINT("10baseT");
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, IFM_FDX, 0),
- PNIC_NWAY_TW|PNIC_NWAY_FD|PNIC_NWAY_CAP10TFDX);
+ PNIC_NWAY_TW | PNIC_NWAY_FD | PNIC_NWAY_CAP10TFDX);
PRINT("10baseT-FDX");
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, 0, 0),
- PNIC_NWAY_TW|PNIC_NWAY_100|PNIC_NWAY_CAP100TX);
+ PNIC_NWAY_TW | PNIC_NWAY_100 | PNIC_NWAY_CAP100TX);
PRINT("100baseTX");
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_FDX, 0),
- PNIC_NWAY_TW|PNIC_NWAY_100|PNIC_NWAY_FD|
+ PNIC_NWAY_TW | PNIC_NWAY_100 | PNIC_NWAY_FD |
PNIC_NWAY_CAP100TXFDX);
PRINT("100baseTX-FDX");
ADD(IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0),
- PNIC_NWAY_TW|PNIC_NWAY_RN|PNIC_NWAY_NW|
- PNIC_NWAY_CAP10T|PNIC_NWAY_CAP10TFDX|
- PNIC_NWAY_CAP100TXFDX|PNIC_NWAY_CAP100TX);
+ PNIC_NWAY_TW | PNIC_NWAY_RN | PNIC_NWAY_NW |
+ PNIC_NWAY_CAP10T | PNIC_NWAY_CAP10TFDX |
+ PNIC_NWAY_CAP100TXFDX | PNIC_NWAY_CAP100TX);
PRINT("auto");
aprint_normal("\n");
sc->sc_statchg = tlp_pnic_nway_statchg;
sc->sc_tick = tlp_pnic_nway_tick;
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
} else {
sc->sc_flags |= TULIPF_HAS_MII;
sc->sc_tick = tlp_mii_tick;
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
}
#undef ADD
@@ -5555,8 +5552,8 @@ tlp_pnic_tmsw_get(struct tulip_softc *sc
mii->mii_media_status = 0;
mii->mii_media_active = IFM_NONE;
tlp_pnic_nway_service(sc, MII_POLLSTAT);
- ifmr->ifm_status = sc->sc_mii.mii_media_status;
- ifmr->ifm_active = sc->sc_mii.mii_media_active;
+ ifmr->ifm_status = mii->mii_media_status;
+ ifmr->ifm_active = mii->mii_media_active;
}
}
@@ -5572,28 +5569,28 @@ tlp_pnic_tmsw_set(struct tulip_softc *sc
*/
TULIP_WRITE(sc, CSR_PNIC_ENDEC, PNIC_ENDEC_JDIS);
- return (tlp_mii_setmedia(sc));
+ return tlp_mii_setmedia(sc);
}
if (ifp->if_flags & IFF_UP) {
mii->mii_media_status = 0;
mii->mii_media_active = IFM_NONE;
- return (tlp_pnic_nway_service(sc, MII_MEDIACHG));
+ return tlp_pnic_nway_service(sc, MII_MEDIACHG);
}
- return (0);
+ return 0;
}
static void
-tlp_pnic_nway_statchg(device_t self)
+tlp_pnic_nway_statchg(struct ifnet *ifp)
{
- struct tulip_softc *sc = device_private(self);
+ struct tulip_softc *sc = ifp->if_softc;
/* Idle the transmit and receive processes. */
- tlp_idle(sc, OPMODE_ST|OPMODE_SR);
+ tlp_idle(sc, OPMODE_ST | OPMODE_SR);
- sc->sc_opmode &= ~(OPMODE_TTM|OPMODE_FD|OPMODE_PS|OPMODE_PCS|
- OPMODE_SCR|OPMODE_HBD);
+ sc->sc_opmode &= ~(OPMODE_TTM | OPMODE_FD | OPMODE_PS | OPMODE_PCS |
+ OPMODE_SCR | OPMODE_HBD);
if (IFM_SUBTYPE(sc->sc_mii.mii_media_active) == IFM_10_T) {
sc->sc_opmode |= OPMODE_TTM;
@@ -5601,14 +5598,14 @@ tlp_pnic_nway_statchg(device_t self)
GPP_PNIC_OUT(GPP_PNIC_PIN_SPEED_RLY, 0) |
GPP_PNIC_OUT(GPP_PNIC_PIN_100M_LPKB, 1));
} else {
- sc->sc_opmode |= OPMODE_PS|OPMODE_PCS|OPMODE_SCR|OPMODE_HBD;
+ sc->sc_opmode |= OPMODE_PS |OPMODE_PCS |OPMODE_SCR |OPMODE_HBD;
TULIP_WRITE(sc, CSR_GPP,
GPP_PNIC_OUT(GPP_PNIC_PIN_SPEED_RLY, 1) |
GPP_PNIC_OUT(GPP_PNIC_PIN_100M_LPKB, 1));
}
if (sc->sc_mii.mii_media_active & IFM_FDX)
- sc->sc_opmode |= OPMODE_FD|OPMODE_HBD;
+ sc->sc_opmode |= OPMODE_FD | OPMODE_HBD;
/*
* Write new OPMODE bits. This also restarts the transmit
@@ -5645,7 +5642,7 @@ tlp_pnic_nway_service(struct tulip_softc
struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
- return (0);
+ return 0;
switch (cmd) {
case MII_POLLSTAT:
@@ -5661,7 +5658,7 @@ tlp_pnic_nway_service(struct tulip_softc
/*
* XXX Not supported as a manual setting right now.
*/
- return (EINVAL);
+ return EINVAL;
default:
/*
* NWAY register data is stored in the ifmedia entry.
@@ -5675,25 +5672,25 @@ tlp_pnic_nway_service(struct tulip_softc
* Only used for autonegotiation.
*/
if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
- return (0);
+ return 0;
/*
* Check to see if we have link. If we do, we don't
* need to restart the autonegotiation process.
*/
if (sc->sc_flags & TULIPF_LINK_UP)
- return (0);
+ return 0;
/*
* Only retry autonegotiation every 5 seconds.
*/
if (++sc->sc_nway_ticks != 5)
- return (0);
+ return 0;
sc->sc_nway_ticks = 0;
tlp_pnic_nway_reset(sc);
if (tlp_pnic_nway_auto(sc, 0) == EJUSTRETURN)
- return (0);
+ return 0;
break;
}
@@ -5704,10 +5701,10 @@ tlp_pnic_nway_service(struct tulip_softc
if ((sc->sc_nway_active == NULL ||
sc->sc_nway_active->ifm_media != mii->mii_media_active) ||
cmd == MII_MEDIACHG) {
- (*sc->sc_statchg)(sc->sc_dev);
+ (*sc->sc_statchg)(mii->mii_ifp);
tlp_nway_activate(sc, mii->mii_media_active);
}
- return (0);
+ return 0;
}
static void
@@ -5736,13 +5733,14 @@ tlp_pnic_nway_auto(struct tulip_softc *s
reg = TULIP_READ(sc, CSR_PNIC_NWAY);
if (reg & PNIC_NWAY_LPAR_MASK) {
tlp_pnic_nway_acomp(sc);
- return (0);
+ return 0;
}
delay(1000);
}
#if 0
if ((reg & PNIC_NWAY_LPAR_MASK) == 0)
- aprint_error_dev(sc->sc_dev, "autonegotiation failed to complete\n");
+ aprint_error_dev(sc->sc_dev,
+ "autonegotiation failed to complete\n");
#endif
/*
@@ -5750,7 +5748,7 @@ tlp_pnic_nway_auto(struct tulip_softc *s
* If that's set, a timeout is pending, and it will
* clear the flag.
*/
- return (EIO);
+ return EIO;
}
/*
@@ -5763,28 +5761,30 @@ tlp_pnic_nway_auto(struct tulip_softc *s
callout_reset(&sc->sc_nway_callout, hz >> 1,
tlp_pnic_nway_auto_timeout, sc);
}
- return (EJUSTRETURN);
+ return EJUSTRETURN;
}
static void
tlp_pnic_nway_auto_timeout(void *arg)
{
struct tulip_softc *sc = arg;
- uint32_t reg;
+ /* uint32_t reg; */
int s;
s = splnet();
sc->sc_flags &= ~TULIPF_DOINGAUTO;
- reg = TULIP_READ(sc, CSR_PNIC_NWAY);
+ /* reg = */
+ TULIP_READ(sc, CSR_PNIC_NWAY);
#if 0
if ((reg & PNIC_NWAY_LPAR_MASK) == 0)
- aprint_error_dev(sc->sc_dev, "autonegotiation failed to complete\n");
+ aprint_error_dev(sc->sc_dev,
+ "autonegotiation failed to complete\n");
#endif
tlp_pnic_nway_acomp(sc);
/* Update the media status. */
- (void) tlp_pnic_nway_service(sc, MII_POLLSTAT);
+ (void)tlp_pnic_nway_service(sc, MII_POLLSTAT);
splx(s);
}
@@ -5815,11 +5815,11 @@ tlp_pnic_nway_status(struct tulip_softc
else
#endif
if (reg & PNIC_NWAY_LPAR100TXFDX)
- mii->mii_media_active |= IFM_100_TX|IFM_FDX;
+ mii->mii_media_active |= IFM_100_TX | IFM_FDX;
else if (reg & PNIC_NWAY_LPAR100TX)
mii->mii_media_active |= IFM_100_TX;
else if (reg & PNIC_NWAY_LPAR10TFDX)
- mii->mii_media_active |= IFM_10_T|IFM_FDX;
+ mii->mii_media_active |= IFM_10_T | IFM_FDX;
else if (reg & PNIC_NWAY_LPAR10T)
mii->mii_media_active |= IFM_10_T;
else
@@ -5840,11 +5840,11 @@ tlp_pnic_nway_acomp(struct tulip_softc *
uint32_t reg;
reg = TULIP_READ(sc, CSR_PNIC_NWAY);
- reg &= ~(PNIC_NWAY_FD|PNIC_NWAY_100|PNIC_NWAY_RN);
+ reg &= ~(PNIC_NWAY_FD | PNIC_NWAY_100 | PNIC_NWAY_RN);
- if (reg & (PNIC_NWAY_LPAR100TXFDX|PNIC_NWAY_LPAR100TX))
+ if (reg & (PNIC_NWAY_LPAR100TXFDX | PNIC_NWAY_LPAR100TX))
reg |= PNIC_NWAY_100;
- if (reg & (PNIC_NWAY_LPAR10TFDX|PNIC_NWAY_LPAR100TXFDX))
+ if (reg & (PNIC_NWAY_LPAR10TFDX | PNIC_NWAY_LPAR100TXFDX))
reg |= PNIC_NWAY_FD;
TULIP_WRITE(sc, CSR_PNIC_NWAY, reg);
@@ -5877,6 +5877,7 @@ const struct tulip_mediasw tlp_pmac_mii_
static void
tlp_pmac_tmsw_init(struct tulip_softc *sc)
{
+ struct mii_data * const mii = &sc->sc_mii;
static const uint8_t media[] = {
TULIP_ROM_MB_MEDIA_TP,
TULIP_ROM_MB_MEDIA_TP_FDX,
@@ -5886,23 +5887,22 @@ tlp_pmac_tmsw_init(struct tulip_softc *s
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
struct tulip_21x4x_media *tm;
- sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
- sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
- sc->sc_mii.mii_statchg = sc->sc_statchg;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
+ mii->mii_ifp = ifp;
+ mii->mii_readreg = tlp_bitbang_mii_readreg;
+ mii->mii_writereg = tlp_bitbang_mii_writereg;
+ mii->mii_statchg = sc->sc_statchg;
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
if (sc->sc_chip == TULIP_CHIP_MX98713 ||
sc->sc_chip == TULIP_CHIP_MX98713A) {
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff,
+ mii_attach(sc->sc_dev, mii, 0xffffffff,
MII_PHY_ANY, MII_OFFSET_ANY, 0);
- if (LIST_FIRST(&sc->sc_mii.mii_phys) != NULL) {
+ if (LIST_FIRST(&mii->mii_phys) != NULL) {
sc->sc_flags |= TULIPF_HAS_MII;
sc->sc_tick = tlp_mii_tick;
sc->sc_preinit = tlp_2114x_mii_preinit;
sc->sc_mediasw = &tlp_pmac_mii_mediasw;
- ifmedia_set(&sc->sc_mii.mii_media,
- IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
return;
}
}
@@ -5916,7 +5916,7 @@ tlp_pmac_tmsw_init(struct tulip_softc *s
* XXX Should implement auto-sense for this someday,
* XXX when we do the same for the 21140.
*/
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_10_T);
break;
default:
@@ -5925,14 +5925,14 @@ tlp_pmac_tmsw_init(struct tulip_softc *s
tlp_add_srom_media(sc, TULIP_ROM_MB_21143_SYM,
tlp_sia_get, tlp_sia_set, media + 2, 2);
- tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO);
+ tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK | M_ZERO);
tm->tm_name = "auto";
tm->tm_get = tlp_2114x_nway_get;
tm->tm_set = tlp_2114x_nway_set;
- ifmedia_add(&sc->sc_mii.mii_media,
+ ifmedia_add(&mii->mii_media,
IFM_MAKEWORD(IFM_ETHER, IFM_AUTO, 0, 0), 0, tm);
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
sc->sc_statchg = tlp_2114x_nway_statchg;
sc->sc_tick = tlp_2114x_nway_tick;
break;
@@ -5960,22 +5960,23 @@ static void
tlp_al981_tmsw_init(struct tulip_softc *sc)
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+ struct mii_data * const mii = &sc->sc_mii;
- sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = tlp_al981_mii_readreg;
- sc->sc_mii.mii_writereg = tlp_al981_mii_writereg;
- sc->sc_mii.mii_statchg = sc->sc_statchg;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
+ mii->mii_ifp = ifp;
+ mii->mii_readreg = tlp_al981_mii_readreg;
+ mii->mii_writereg = tlp_al981_mii_writereg;
+ mii->mii_statchg = sc->sc_statchg;
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
+ mii_attach(sc->sc_dev, mii, 0xffffffff, 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);
+ 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 {
sc->sc_flags |= TULIPF_HAS_MII;
sc->sc_tick = tlp_mii_tick;
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
}
}
@@ -5995,22 +5996,22 @@ static void
tlp_an985_tmsw_init(struct tulip_softc *sc)
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+ struct mii_data * const mii = &sc->sc_mii;
- sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
- sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
- sc->sc_mii.mii_statchg = sc->sc_statchg;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff, 1,
- 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);
+ mii->mii_ifp = ifp;
+ mii->mii_readreg = tlp_bitbang_mii_readreg;
+ mii->mii_writereg = tlp_bitbang_mii_writereg;
+ mii->mii_statchg = sc->sc_statchg;
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
+ mii_attach(sc->sc_dev, mii, 0xffffffff, 1, 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 {
sc->sc_flags |= TULIPF_HAS_MII;
sc->sc_tick = tlp_mii_tick;
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
}
}
@@ -6031,14 +6032,15 @@ static void
tlp_dm9102_tmsw_init(struct tulip_softc *sc)
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+ struct mii_data * const mii = &sc->sc_mii;
uint32_t opmode;
- sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
- sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
- sc->sc_mii.mii_statchg = sc->sc_statchg;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
+ mii->mii_ifp = ifp;
+ mii->mii_readreg = tlp_bitbang_mii_readreg;
+ mii->mii_writereg = tlp_bitbang_mii_writereg;
+ mii->mii_statchg = sc->sc_statchg;
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
/* PHY block already reset via tlp_reset(). */
@@ -6047,11 +6049,11 @@ tlp_dm9102_tmsw_init(struct tulip_softc
*/
switch (sc->sc_chip) {
case TULIP_CHIP_DM9102:
- opmode = OPMODE_MBO|OPMODE_HBD|OPMODE_PS;
+ opmode = OPMODE_MBO | OPMODE_HBD | OPMODE_PS;
break;
case TULIP_CHIP_DM9102A:
- opmode = OPMODE_MBO|OPMODE_HBD;
+ opmode = OPMODE_MBO | OPMODE_HBD;
break;
default:
@@ -6062,7 +6064,7 @@ tlp_dm9102_tmsw_init(struct tulip_softc
TULIP_WRITE(sc, CSR_OPMODE, opmode);
/* Now, probe the internal MII for the internal PHY. */
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
+ mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY,
MII_OFFSET_ANY, 0);
/*
@@ -6071,12 +6073,12 @@ tlp_dm9102_tmsw_init(struct tulip_softc
*/
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);
+ ifmedia_add(&mii->mii_media, IFM_ETHER | IFM_NONE, 0, NULL);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_NONE);
} else {
sc->sc_flags |= TULIPF_HAS_MII;
sc->sc_tick = tlp_mii_tick;
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
}
}
@@ -6093,7 +6095,7 @@ tlp_dm9102_tmsw_setmedia(struct tulip_so
{
/* XXX HomePNA on DM9102A. */
- return (tlp_mii_setmedia(sc));
+ return tlp_mii_setmedia(sc);
}
/*
@@ -6114,14 +6116,15 @@ static void
tlp_asix_tmsw_init(struct tulip_softc *sc)
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+ struct mii_data * const mii = &sc->sc_mii;
uint32_t opmode;
- sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
- sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
- sc->sc_mii.mii_statchg = sc->sc_statchg;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
+ mii->mii_ifp = ifp;
+ mii->mii_readreg = tlp_bitbang_mii_readreg;
+ mii->mii_writereg = tlp_bitbang_mii_writereg;
+ mii->mii_statchg = sc->sc_statchg;
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
/*
* Configure OPMODE properly for the internal MII interface.
@@ -6129,28 +6132,28 @@ tlp_asix_tmsw_init(struct tulip_softc *s
switch (sc->sc_chip) {
case TULIP_CHIP_AX88140:
case TULIP_CHIP_AX88141:
- opmode = OPMODE_HBD|OPMODE_PS;
+ opmode = OPMODE_HBD | OPMODE_PS;
break;
- default:
- opmode = 0;
- break;
- }
+ default:
+ opmode = 0;
+ break;
+ }
TULIP_WRITE(sc, CSR_OPMODE, opmode);
/* Now, probe the internal MII for the internal PHY. */
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
+ mii_attach(sc->sc_dev, mii, 0xffffffff, MII_PHY_ANY,
MII_OFFSET_ANY, 0);
/* XXX Figure how to handle the PHY. */
- 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);
+ 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 {
sc->sc_flags |= TULIPF_HAS_MII;
sc->sc_tick = tlp_mii_tick;
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
}
@@ -6169,7 +6172,7 @@ tlp_asix_tmsw_setmedia(struct tulip_soft
{
/* XXX PHY handling. */
- return (tlp_mii_setmedia(sc));
+ return tlp_mii_setmedia(sc);
}
/*
@@ -6186,6 +6189,7 @@ void
tlp_rs7112_tmsw_init(struct tulip_softc *sc)
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+ struct mii_data * const mii = &sc->sc_mii;
/*
* We don't attach any media info structures to the ifmedia
@@ -6195,26 +6199,35 @@ tlp_rs7112_tmsw_init(struct tulip_softc
if (sc->sc_preinit == tlp_2114x_preinit)
sc->sc_preinit = tlp_2114x_mii_preinit;
- sc->sc_mii.mii_ifp = ifp;
- sc->sc_mii.mii_readreg = tlp_bitbang_mii_readreg;
- sc->sc_mii.mii_writereg = tlp_bitbang_mii_writereg;
- sc->sc_mii.mii_statchg = sc->sc_statchg;
- ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
- tlp_mediastatus);
+ mii->mii_ifp = ifp;
+ mii->mii_readreg = tlp_bitbang_mii_readreg;
+ mii->mii_writereg = tlp_bitbang_mii_writereg;
+ mii->mii_statchg = sc->sc_statchg;
+ sc->sc_ethercom.ec_mii = mii;
+ ifmedia_init(&mii->mii_media, 0, tlp_mediachange, tlp_mediastatus);
/*
* The RS7112 reports a PHY at 0 (possibly HomePNA?)
* and 1 (ethernet). We attach ethernet only.
*/
- mii_attach(sc->sc_dev, &sc->sc_mii, 0xffffffff, 1,
- MII_OFFSET_ANY, 0);
+ mii_attach(sc->sc_dev, mii, 0xffffffff, 1, 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);
+ 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 {
sc->sc_flags |= TULIPF_HAS_MII;
sc->sc_tick = tlp_mii_tick;
- ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
+ ifmedia_set(&mii->mii_media, IFM_ETHER | IFM_AUTO);
+ }
+}
+
+const char *
+tlp_chip_name(tulip_chip_t t) {
+ if ((int)t < 0 || (int)t >= __arraycount(tlp_chip_names)) {
+ static char buf[256];
+ (void)snprintf(buf, sizeof(buf), "[unknown 0x%x]", t);
+ return buf;
}
+ return tlp_chip_names[t];
}