/* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
/* $FreeBSD: src/sys/pci/if_de.c,v 1.123.2.4 2000/08/04 23:25:09 peter Exp $ */
-/* $DragonFly: src/sys/dev/netif/de/if_de.c,v 1.22 2005/02/21 04:48:57 joerg Exp $ */
+/* $DragonFly: src/sys/dev/netif/de/if_de.c,v 1.39 2005/06/20 15:10:40 joerg Exp $ */
/*-
* Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/eventhandler.h>
-#include <machine/clock.h>
+#include <sys/thread2.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/bus.h>
#define TULIP_IOMAPPED
#endif
-#if 0
-/*
- * This turns on all sort of debugging stuff and make the
- * driver much larger.
- */
-#define TULIP_DEBUG
-#endif
-
-#if 0
-#define TULIP_PERFSTATS
-#endif
-
#define TULIP_HZ 10
#include "if_devar.h"
+static tulip_softc_t *tulips[TULIP_MAX_DEVICES];
+
/*
* This module supports
* the DEC 21040 PCI Ethernet Controller.
* the DEC 21041 PCI Ethernet Controller.
* the DEC 21140 PCI Fast Ethernet Controller.
*/
-static void tulip_mii_autonegotiate(tulip_softc_t * const sc, const unsigned phyaddr);
-static void tulip_intr_shared(void *arg);
-static void tulip_intr_normal(void *arg);
-static void tulip_init(tulip_softc_t * const sc);
-static void tulip_reset(tulip_softc_t * const sc);
-static void tulip_ifstart(struct ifnet *ifp);
-static struct mbuf *tulip_txput(tulip_softc_t * const sc, struct mbuf *m);
-static void tulip_txput_setup(tulip_softc_t * const sc);
-static void tulip_rx_intr(tulip_softc_t * const sc);
-static void tulip_addr_filter(tulip_softc_t * const sc);
-static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno);
-static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data);
-static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
-static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t * const sc);
-static int tulip_srom_decode(tulip_softc_t * const sc);
-static int tulip_ifmedia_change(struct ifnet * const ifp);
-static void tulip_ifmedia_status(struct ifnet * const ifp, struct ifmediareq *req);
+static void tulip_mii_autonegotiate(tulip_softc_t *, u_int);
+static void tulip_intr_shared(void *);
+static void tulip_intr_normal(void *);
+static void tulip_init(tulip_softc_t *);
+static void tulip_reset(tulip_softc_t *);
+static void tulip_ifstart(struct ifnet *);
+static struct mbuf *tulip_txput(tulip_softc_t *, struct mbuf *);
+static void tulip_txput_setup(tulip_softc_t *);
+static void tulip_rx_intr(tulip_softc_t *);
+static void tulip_addr_filter(tulip_softc_t *);
+static u_int tulip_mii_readreg(tulip_softc_t *, u_int, u_int);
+static void tulip_mii_writereg(tulip_softc_t *, u_int, u_int, u_int);
+static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
+static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t *);
+static int tulip_srom_decode(tulip_softc_t *);
+static int tulip_ifmedia_change(struct ifnet *);
+static void tulip_ifmedia_status(struct ifnet *, struct ifmediareq *);
/* static void tulip_21140_map_media(tulip_softc_t *sc); */
-\f
+
static void
-tulip_timeout_callback(
- void *arg)
+tulip_timeout_callback(void *arg)
{
- tulip_softc_t * const sc = arg;
- int s = splimp();
+ tulip_softc_t *sc = arg;
+
+ crit_enter();
sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
(sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
- splx(s);
+
+ crit_exit();
}
static void
-tulip_timeout(
- tulip_softc_t * const sc)
+tulip_timeout(tulip_softc_t *sc)
{
if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
return;
tulip_timeout_callback, sc);
}
-#if defined(TULIP_NEED_FASTTIMEOUT)
-static void
-tulip_fasttimeout_callback(
- void *arg)
-{
- tulip_softc_t * const sc = arg;
- int s = splimp();
-
- sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING;
- (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER);
- splx(s);
-}
-
-static void
-tulip_fasttimeout(
- tulip_softc_t * const sc)
-{
- if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING)
- return;
- sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING;
- callout_reset(&sc->tulip_fast_timer, 1, tulip_fasttimeout_callback, sc);
-}
-#endif
-\f
static int
-tulip_txprobe(
- tulip_softc_t * const sc)
+tulip_txprobe(tulip_softc_t *sc)
{
struct mbuf *m;
/*
sc->tulip_probe.probe_txprobes++;
return 1;
}
-\f
+
#ifdef BIG_PACKET
#define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
#else
#endif
static void
-tulip_media_set(
- tulip_softc_t * const sc,
- tulip_media_t media)
+tulip_media_set(tulip_softc_t *sc, tulip_media_t media)
{
const tulip_media_info_t *mi = sc->tulip_mediums[media];
}
}
}
-\f
+
static void
-tulip_linkup(
- tulip_softc_t * const sc,
- tulip_media_t media)
+tulip_linkup(tulip_softc_t *sc, tulip_media_t media)
{
if ((sc->tulip_flags & TULIP_LINKUP) == 0)
sc->tulip_flags |= TULIP_PRINTLINKUP;
}
#endif
if (sc->tulip_media != media) {
-#ifdef TULIP_DEBUG
- sc->tulip_dbg.dbg_last_media = sc->tulip_media;
-#endif
sc->tulip_media = media;
sc->tulip_flags |= TULIP_PRINTMEDIA;
if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
}
tulip_init(sc);
}
-\f
+
static void
-tulip_media_print(
- tulip_softc_t * const sc)
+tulip_media_print(tulip_softc_t *sc)
{
if ((sc->tulip_flags & TULIP_LINKUP) == 0)
return;
if (sc->tulip_flags & TULIP_PRINTMEDIA) {
- printf("%s%d: enabling %s port\n",
- sc->tulip_name, sc->tulip_unit,
- tulip_mediums[sc->tulip_media]);
+ if_printf(&sc->tulip_if, "enabling %s port\n",
+ tulip_mediums[sc->tulip_media]);
sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
} else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
- printf("%s%d: link up\n", sc->tulip_name, sc->tulip_unit);
+ if_printf(&sc->tulip_if, "link up\n");
sc->tulip_flags &= ~TULIP_PRINTLINKUP;
}
}
-\f
+
#if defined(TULIP_DO_GPR_SENSE)
static tulip_media_t
-tulip_21140_gpr_media_sense(
- tulip_softc_t * const sc)
+tulip_21140_gpr_media_sense(tulip_softc_t *sc)
{
tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
continue;
-#if defined(TULIP_DEBUG)
- printf("%s%d: gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
- sc->tulip_name, sc->tulip_unit, tulip_mediums[media],
- TULIP_CSR_READ(sc, csr_gp) & 0xFF,
- mi->mi_actmask, mi->mi_actdata);
-#endif
/*
* It does! If this is the first media we detected, then
* remember this media. If isn't the first, then there were
return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
}
#endif /* TULIP_DO_GPR_SENSE */
-\f
+
static tulip_link_status_t
-tulip_media_link_monitor(
- tulip_softc_t * const sc)
+tulip_media_link_monitor(tulip_softc_t *sc)
{
- const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
+ const tulip_media_info_t *mi = sc->tulip_mediums[sc->tulip_media];
tulip_link_status_t linkup = TULIP_LINK_DOWN;
if (mi == NULL) {
-#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
+#if defined(DIAGNOSTIC)
panic("tulip_media_link_monitor: %s: botch at line %d\n",
tulip_mediums[sc->tulip_media],__LINE__);
#endif
u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
abilities = (abilities << 6) & status;
if (abilities != sc->tulip_abilities) {
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
- sc->tulip_name, sc->tulip_unit, sc->tulip_phyaddr,
- sc->tulip_abilities, abilities);
-#endif
if (tulip_mii_map_abilities(sc, abilities)) {
tulip_linkup(sc, sc->tulip_probe_media);
return TULIP_LINK_UP;
return TULIP_LINK_UNKNOWN;
if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
linkup = TULIP_LINK_UP;
-#if defined(TULIP_DEBUG)
- if (sc->tulip_probe_timeout <= 0)
- printf("%s%d: sia status = 0x%08x\n", sc->tulip_name,
- sc->tulip_unit, TULIP_CSR_READ(sc, csr_sia_status));
-#endif
} else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
return TULIP_LINK_UNKNOWN;
}
return TULIP_LINK_UP;
sc->tulip_flags &= ~TULIP_LINKUP;
- printf("%s%d: link down: cable problem?\n", sc->tulip_name, sc->tulip_unit);
+ if_printf(&sc->tulip_if, "link down: cable problem?\n");
}
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_link_downed++;
-#endif
return TULIP_LINK_DOWN;
}
-\f
+
static void
-tulip_media_poll(
- tulip_softc_t * const sc,
- tulip_mediapoll_event_t event)
+tulip_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
{
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_events[event]++;
-#endif
if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
&& event == TULIP_MEDIAPOLL_TIMER) {
switch (tulip_media_link_monitor(sc)) {
if (event == TULIP_MEDIAPOLL_LINKFAIL) {
if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
if (TULIP_DO_AUTOSENSE(sc)) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_link_failures++;
-#endif
sc->tulip_media = TULIP_MEDIA_UNKNOWN;
if (sc->tulip_if.if_flags & IFF_UP)
tulip_reset(sc); /* restart probe */
}
return;
}
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_link_pollintrs++;
-#endif
}
if (event == TULIP_MEDIAPOLL_START) {
return;
sc->tulip_probe_mediamask = 0;
sc->tulip_probe_passes = 0;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_media_probes++;
-#endif
/*
* If the SROM contained an explicit media to use, use it.
*/
if (event == TULIP_MEDIAPOLL_LINKPASS) {
/* XXX Check media status just to be sure */
sc->tulip_probe_media = TULIP_MEDIA_10BASET;
-#if defined(TULIP_DEBUG)
- } else {
- sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
-#endif
}
tulip_linkup(sc, sc->tulip_probe_media);
tulip_timeout(sc);
*/
if (sc->tulip_probe_timeout > 0) {
tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
-#if defined(TULIP_DEBUG)
- printf("%s%d: media_poll: gpr sensing = %s\n",
- sc->tulip_name, sc->tulip_unit, tulip_mediums[new_probe_media]);
-#endif
if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
if (new_probe_media == sc->tulip_probe_media) {
if (--sc->tulip_probe_count == 0)
return;
}
default: {
-#if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
+#if defined(DIAGNOSTIC)
panic("tulip_media_poll: botch at line %d\n", __LINE__);
#endif
break;
}
if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
-#endif
sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
return;
}
* switch to another media if we tried this one enough.
*/
if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
-#if defined(TULIP_DEBUG)
- if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
- printf("%s%d: poll media unknown!\n",
- sc->tulip_name, sc->tulip_unit);
- sc->tulip_probe_media = TULIP_MEDIA_MAX;
- }
-#endif
/*
* Find the next media type to check for. Full Duplex
* types are not allowed.
sc->tulip_probe_media -= 1;
if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
if (++sc->tulip_probe_passes == 3) {
- printf("%s%d: autosense failed: cable problem?\n",
- sc->tulip_name, sc->tulip_unit);
+ if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
sc->tulip_if.if_flags &= ~IFF_RUNNING;
sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
|| (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
|| TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
-#if defined(TULIP_DEBUG)
- printf("%s%d: %s: probing %s\n", sc->tulip_name, sc->tulip_unit,
- event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
- tulip_mediums[sc->tulip_probe_media]);
-#endif
sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
sc->tulip_probe.probe_txprobes = 0;
*/
tulip_txprobe(sc);
}
-\f
+
static void
-tulip_media_select(
- tulip_softc_t * const sc)
+tulip_media_select(tulip_softc_t *sc)
{
if (sc->tulip_features & TULIP_HAVE_GPR) {
TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
tulip_media_set(sc, sc->tulip_media);
}
}
-\f
+
static void
-tulip_21040_mediainfo_init(
- tulip_softc_t * const sc,
- tulip_media_t media)
+tulip_21040_mediainfo_init(tulip_softc_t *sc, tulip_media_t media)
{
sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
|TULIP_CMD_BACKOFFCTR;
}
static void
-tulip_21040_media_probe(
- tulip_softc_t * const sc)
+tulip_21040_media_probe(tulip_softc_t *sc)
{
tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
- return;
}
static void
-tulip_21040_10baset_only_media_probe(
- tulip_softc_t * const sc)
+tulip_21040_10baset_only_media_probe(tulip_softc_t *sc)
{
tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
tulip_media_set(sc, TULIP_MEDIA_10BASET);
}
static void
-tulip_21040_10baset_only_media_select(
- tulip_softc_t * const sc)
+tulip_21040_10baset_only_media_select(tulip_softc_t *sc)
{
sc->tulip_flags |= TULIP_LINKUP;
if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
}
static void
-tulip_21040_auibnc_only_media_probe(
- tulip_softc_t * const sc)
+tulip_21040_auibnc_only_media_probe(tulip_softc_t *sc)
{
tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
}
static void
-tulip_21040_auibnc_only_media_select(
- tulip_softc_t * const sc)
+tulip_21040_auibnc_only_media_select(tulip_softc_t *sc)
{
tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
tulip_21040_auibnc_only_media_select,
NULL,
};
-\f
+
static void
-tulip_21041_mediainfo_init(
- tulip_softc_t * const sc)
+tulip_21041_mediainfo_init(tulip_softc_t *sc)
{
- tulip_media_info_t * const mi = sc->tulip_mediainfo;
+ tulip_media_info_t *mi = sc->tulip_mediainfo;
#ifdef notyet
if (sc->tulip_revinfo >= 0x20) {
TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
}
-\f
+
static void
-tulip_21041_media_probe(
- tulip_softc_t * const sc)
+tulip_21041_media_probe(tulip_softc_t *sc)
{
sc->tulip_if.if_baudrate = 10000000;
sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
}
static void
-tulip_21041_media_poll(
- tulip_softc_t * const sc,
- const tulip_mediapoll_event_t event)
+tulip_21041_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
{
- u_int32_t sia_status;
-
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_events[event]++;
-#endif
+ uint32_t sia_status;
if (event == TULIP_MEDIAPOLL_LINKFAIL) {
if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
return;
if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
-#endif
tulip_linkup(sc, sc->tulip_probe_media);
return;
}
sc->tulip_flags &= ~TULIP_WANTRXACT;
sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
} else {
- printf("%s%d: autosense failed: cable problem?\n",
- sc->tulip_name, sc->tulip_unit);
+ if_printf(&sc->tulip_if, "autosense failed: cable problem?\n");
if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
sc->tulip_if.if_flags &= ~IFF_RUNNING;
sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
tulip_media_select,
tulip_21041_media_poll
};
-\f
+
static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
{ 0x20005c00, 0, /* 08-00-17 */
{
{ 0x19, 0x0040, 0x0040 }, /* 10TX */
{ 0x19, 0x0040, 0x0000 }, /* 100TX */
},
-#if defined(TULIP_DEBUG)
- "NS DP83840",
-#endif
},
{ 0x0281F400, 0, /* 00-A0-7D */
{
{ 0x12, 0x0010, 0x0010 }, /* 100T4 */
{ 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
},
-#if defined(TULIP_DEBUG)
- "Seeq 80C240"
-#endif
},
#if 0
{ 0x0015F420, 0, /* 00-A0-7D */
{ 0x12, 0x0010, 0x0010 }, /* 100T4 */
{ 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
},
-#if defined(TULIP_DEBUG)
- "Broadcom BCM5000"
-#endif
},
#endif
{ 0x0281F400, 0, /* 00-A0-BE */
{ }, /* 100T4 */
{ 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
},
-#if defined(TULIP_DEBUG)
- "ICS 1890"
-#endif
},
{ 0 }
};
-\f
+
static tulip_media_t
-tulip_mii_phy_readspecific(
- tulip_softc_t * const sc)
+tulip_mii_phy_readspecific(tulip_softc_t *sc)
{
const tulip_phy_attr_t *attr;
u_int16_t data;
}
if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
- const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
+ const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100TX];
data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
if ((data & pm->pm_mask) == pm->pm_value)
idx = 2;
}
if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
- const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
+ const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_100T4];
data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
if ((data & pm->pm_mask) == pm->pm_value)
idx = 3;
}
if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
- const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
+ const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_10T];
data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
if ((data & pm->pm_mask) == pm->pm_value)
idx = 1;
}
if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
- const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
+ const tulip_phy_modedata_t *pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
}
return table[idx];
}
-\f
-static unsigned
-tulip_mii_get_phyaddr(
- tulip_softc_t * const sc,
- unsigned offset)
+
+static u_int
+tulip_mii_get_phyaddr(tulip_softc_t *sc, u_int offset)
{
- unsigned phyaddr;
+ u_int phyaddr;
for (phyaddr = 1; phyaddr < 32; phyaddr++) {
- unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
+ u_int status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
continue;
if (offset == 0)
offset--;
}
if (offset == 0) {
- unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
+ u_int status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
return TULIP_MII_NOPHY;
return 0;
}
return TULIP_MII_NOPHY;
}
-\f
+
static int
-tulip_mii_map_abilities(
- tulip_softc_t * const sc,
- unsigned abilities)
+tulip_mii_map_abilities(tulip_softc_t *sc, u_int abilities)
{
sc->tulip_abilities = abilities;
if (abilities & PHYSTS_100BASETX_FD) {
}
static void
-tulip_mii_autonegotiate(
- tulip_softc_t * const sc,
- const unsigned phyaddr)
+tulip_mii_autonegotiate(tulip_softc_t *sc, u_int phyaddr)
{
switch (sc->tulip_probe_state) {
case TULIP_PROBE_MEDIATEST:
/* FALL THROUGH */
}
case TULIP_PROBE_PHYRESET: {
- u_int32_t status;
- u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
+ uint32_t status;
+ uint32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
if (data & PHYCTL_RESET) {
if (sc->tulip_probe_timeout > 0) {
tulip_timeout(sc);
return;
}
- printf("%s%d(phy%d): error: reset of PHY never completed!\n",
- sc->tulip_name, sc->tulip_unit, phyaddr);
+ if_printf(&sc->tulip_if,
+ "(phy%d): error: reset of PHY never completed!\n", phyaddr);
sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
sc->tulip_probe_state = TULIP_PROBE_FAILED;
sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
}
status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
if ((status & PHYSTS_CAN_AUTONEG) == 0) {
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation disabled\n",
- sc->tulip_name, sc->tulip_unit, phyaddr);
-#endif
sc->tulip_flags &= ~TULIP_DIDNWAY;
sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
return;
tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
-#if defined(TULIP_DEBUG)
- if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
- loudprintf("%s%d(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, data);
- else
- loudprintf("%s%d(phy%d): autonegotiation restarted: 0x%04x\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, data);
- sc->tulip_dbg.dbg_nway_starts++;
-#endif
sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
sc->tulip_probe_timeout = 3000;
/* FALL THROUGH */
tulip_timeout(sc);
return;
}
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, status,
- tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
-#endif
sc->tulip_flags &= ~TULIP_DIDNWAY;
sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
return;
}
data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation complete: 0x%04x\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, data);
-#endif
data = (data << 6) & status;
if (!tulip_mii_map_abilities(sc, data))
sc->tulip_flags &= ~TULIP_DIDNWAY;
break;
}
}
-#if defined(TULIP_DEBUG)
- loudprintf("%s%d(phy%d): autonegotiation failure: state = %d\n",
- sc->tulip_name, sc->tulip_unit, phyaddr, sc->tulip_probe_state);
- sc->tulip_dbg.dbg_nway_failures++;
-#endif
}
-\f
+
static void
-tulip_2114x_media_preset(
- tulip_softc_t * const sc)
+tulip_2114x_media_preset(tulip_softc_t *sc)
{
const tulip_media_info_t *mi = NULL;
tulip_media_t media = sc->tulip_media;
sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
sc->tulip_flags &= ~TULIP_SQETEST;
if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
-#if defined(TULIP_DEBUG)
- if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
-#endif
mi = sc->tulip_mediums[media];
if (mi->mi_type == TULIP_MEDIAINFO_MII) {
sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
} else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
}
-#if defined(TULIP_DEBUG)
- } else {
- printf("%s%d: preset: bad media %d!\n",
- sc->tulip_name, sc->tulip_unit, media);
- }
-#endif
}
switch (media) {
case TULIP_MEDIA_BNC:
}
TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
}
-\f
+
/*
********************************************************************
* Start of 21140/21140A support which does not use the MII interface
*/
-\f
+
static void
-tulip_null_media_poll(
- tulip_softc_t * const sc,
- tulip_mediapoll_event_t event)
+tulip_null_media_poll(tulip_softc_t *sc, tulip_mediapoll_event_t event)
{
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_events[event]++;
-#endif
#if defined(DIAGNOSTIC)
- printf("%s%d: botch(media_poll) at line %d\n",
- sc->tulip_name, sc->tulip_unit, __LINE__);
+ if_printf(&sc->tulip_if, "botch(media_poll) at line %d\n", __LINE__);
#endif
}
-__inline__ static void
-tulip_21140_mediainit(
- tulip_softc_t * const sc,
- tulip_media_info_t * const mip,
- tulip_media_t const media,
- unsigned gpdata,
- unsigned cmdmode)
+static void
+tulip_21140_mediainit(tulip_softc_t *sc, tulip_media_info_t *mip,
+ tulip_media_t media, u_int gpdata, u_int cmdmode)
{
sc->tulip_mediums[media] = mip;
mip->mi_type = TULIP_MEDIAINFO_GPR;
mip->mi_cmdmode = cmdmode;
mip->mi_gpdata = gpdata;
}
-\f
+
static void
-tulip_21140_evalboard_media_probe(
- tulip_softc_t * const sc)
+tulip_21140_evalboard_media_probe(tulip_softc_t *sc)
{
tulip_media_info_t *mip = sc->tulip_mediainfo;
tulip_null_media_poll,
tulip_2114x_media_preset,
};
-\f
+
static void
-tulip_21140_accton_media_probe(
- tulip_softc_t * const sc)
+tulip_21140_accton_media_probe(tulip_softc_t *sc)
{
tulip_media_info_t *mip = sc->tulip_mediainfo;
- unsigned gpdata;
+ u_int gpdata;
sc->tulip_gpinit = TULIP_GP_EB_PINS;
sc->tulip_gpdata = TULIP_GP_EB_INIT;
tulip_null_media_poll,
tulip_2114x_media_preset,
};
-\f
+
static void
-tulip_21140_smc9332_media_probe(
- tulip_softc_t * const sc)
+tulip_21140_smc9332_media_probe(tulip_softc_t *sc)
{
tulip_media_info_t *mip = sc->tulip_mediainfo;
int idx, cnt = 0;
tulip_null_media_poll,
tulip_2114x_media_preset,
};
-\f
+
static void
-tulip_21140_cogent_em100_media_probe(
- tulip_softc_t * const sc)
+tulip_21140_cogent_em100_media_probe(tulip_softc_t *sc)
{
tulip_media_info_t *mip = sc->tulip_mediainfo;
- u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
+ uint32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
sc->tulip_gpinit = TULIP_GP_EM100_PINS;
sc->tulip_gpdata = TULIP_GP_EM100_INIT;
tulip_null_media_poll,
tulip_2114x_media_preset
};
-\f
+
static void
-tulip_21140_znyx_zx34x_media_probe(
- tulip_softc_t * const sc)
+tulip_21140_znyx_zx34x_media_probe(tulip_softc_t *sc)
{
tulip_media_info_t *mip = sc->tulip_mediainfo;
int cnt10 = 0, cnt100 = 0, idx;
DELAY(200000);
for (idx = 1000; idx > 0; idx--) {
- u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
+ uint32_t csr = TULIP_CSR_READ(sc, csr_gp);
if ((csr & (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) == (TULIP_GP_ZX34X_LNKFAIL|TULIP_GP_ZX34X_SYMDET|TULIP_GP_ZX34X_SIGDET)) {
if (++cnt100 > 100)
break;
tulip_null_media_poll,
tulip_2114x_media_preset,
};
-\f
+
static void
-tulip_2114x_media_probe(
- tulip_softc_t * const sc)
+tulip_2114x_media_probe(tulip_softc_t *sc)
{
- sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
- |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
+ sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE | TULIP_CMD_BACKOFFCTR |
+ TULIP_CMD_THRSHLD72;
}
static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
tulip_media_poll,
tulip_2114x_media_preset,
};
-\f
+
/*
* ******** END of chip-specific handlers. ***********
*/
-\f
+
/*
* Code the read the SROM and MII bit streams (I2C)
*/
-#define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
+#define EMIT do { \
+ TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
+ DELAY(1); \
+} while (0)
static void
-tulip_srom_idle(
- tulip_softc_t * const sc)
+tulip_srom_idle(tulip_softc_t *sc)
{
- unsigned bit, csr;
+ u_int bit, csr;
csr = SROMSEL ; EMIT;
csr = SROMSEL | SROMRD; EMIT;
static void
-tulip_srom_read(
- tulip_softc_t * const sc)
+tulip_srom_read(tulip_softc_t *sc)
{
- unsigned idx;
- const unsigned bitwidth = SROM_BITWIDTH;
- const unsigned cmdmask = (SROMCMD_RD << bitwidth);
- const unsigned msb = 1 << (bitwidth + 3 - 1);
- unsigned lastidx = (1 << bitwidth) - 1;
+ const u_int bitwidth = SROM_BITWIDTH;
+ const u_int cmdmask = (SROMCMD_RD << bitwidth);
+ const u_int msb = 1 << (bitwidth + 3 - 1);
+ u_int idx, lastidx = (1 << bitwidth) - 1;
tulip_srom_idle(sc);
for (idx = 0; idx <= lastidx; idx++) {
- unsigned lastbit, data, bits, bit, csr;
+ u_int lastbit, data, bits, bit, csr;
csr = SROMSEL ; EMIT;
csr = SROMSEL | SROMRD; EMIT;
csr ^= SROMCSON; EMIT;
lastbit = 0;
for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
- const unsigned thisbit = bits & msb;
+ u_int thisbit = bits & msb;
csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
if (thisbit != lastbit) {
csr ^= SROMDOUT; EMIT; /* clock low; invert data */
}
tulip_srom_idle(sc);
}
-\f
-#define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
+
+#define MII_EMIT do { \
+ TULIP_CSR_WRITE(sc, csr_srom_mii, csr); \
+ DELAY(1); \
+} while (0)
static void
-tulip_mii_writebits(
- tulip_softc_t * const sc,
- unsigned data,
- unsigned bits)
+tulip_mii_writebits(tulip_softc_t *sc, u_int data, u_int bits)
{
- unsigned msb = 1 << (bits - 1);
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
- unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
+ u_int csr, msb, lastbit;
+ msb = 1 << (bits - 1);
+ csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
+ lastbit = (csr & MII_DOUT) ? msb : 0;
csr |= MII_WR; MII_EMIT; /* clock low; assert write */
for (; bits > 0; bits--, data <<= 1) {
}
static void
-tulip_mii_turnaround(
- tulip_softc_t * const sc,
- unsigned cmd)
+tulip_mii_turnaround(tulip_softc_t *sc, u_int cmd)
{
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
+ u_int csr;
+
+ csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
if (cmd == MII_WRCMD) {
csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
}
-static unsigned
-tulip_mii_readbits(
- tulip_softc_t * const sc)
+static u_int
+tulip_mii_readbits(tulip_softc_t *sc)
{
- unsigned data;
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
- int idx;
+ u_int csr, data, idx;
+
+ csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
for (idx = 0, data = 0; idx < 16; idx++) {
data <<= 1; /* this is NOOP on the first pass through */
return data;
}
-static unsigned
-tulip_mii_readreg(
- tulip_softc_t * const sc,
- unsigned devaddr,
- unsigned regno)
+static u_int
+tulip_mii_readreg(tulip_softc_t *sc, u_int devaddr, u_int regno)
{
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
- unsigned data;
+ u_int csr;
+ u_int data;
+ csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
csr &= ~(MII_RD|MII_CLK); MII_EMIT;
tulip_mii_writebits(sc, MII_PREAMBLE, 32);
tulip_mii_writebits(sc, MII_RDCMD, 8);
tulip_mii_turnaround(sc, MII_RDCMD);
data = tulip_mii_readbits(sc);
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_phyregs[regno][0] = data;
- sc->tulip_dbg.dbg_phyregs[regno][1]++;
-#endif
return data;
}
static void
-tulip_mii_writereg(
- tulip_softc_t * const sc,
- unsigned devaddr,
- unsigned regno,
- unsigned data)
+tulip_mii_writereg(tulip_softc_t *sc, u_int devaddr, u_int regno, u_int data)
{
- unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
+ u_int csr;
+
+ csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
csr &= ~(MII_RD|MII_CLK); MII_EMIT;
tulip_mii_writebits(sc, MII_PREAMBLE, 32);
tulip_mii_writebits(sc, MII_WRCMD, 8);
tulip_mii_writebits(sc, regno, 5);
tulip_mii_turnaround(sc, MII_WRCMD);
tulip_mii_writebits(sc, data, 16);
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_phyregs[regno][2] = data;
- sc->tulip_dbg.dbg_phyregs[regno][3]++;
-#endif
}
-\f
+
#define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
#define tulip_srom_crcok(databuf) ( \
((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
((databuf)[126] | ((databuf)[127] << 8)))
\f
static void
-tulip_identify_dec_nic(
- tulip_softc_t * const sc)
+tulip_identify_dec_nic(tulip_softc_t *sc)
{
strcpy(sc->tulip_boardid, "DEC ");
#define D0 4
}
#undef D0
}
-\f
+
static void
-tulip_identify_znyx_nic(
- tulip_softc_t * const sc)
+tulip_identify_znyx_nic(tulip_softc_t * const sc)
{
- unsigned id = 0;
+ u_int id = 0;
strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
- unsigned znyx_ptr;
+ u_int znyx_ptr;
sc->tulip_boardid[8] = '4';
znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
if (znyx_ptr < 26 || znyx_ptr > 116) {
}
}
}
-\f
+
static void
-tulip_identify_smc_nic(
- tulip_softc_t * const sc)
+tulip_identify_smc_nic(tulip_softc_t * const sc)
{
- u_int32_t id1, id2, ei;
+ uint32_t id1, id2, ei;
int auibnc = 0, utp = 0;
char *cp;
else if (!utp && auibnc)
sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
}
-\f
+
static void
-tulip_identify_cogent_nic(
- tulip_softc_t * const sc)
+tulip_identify_cogent_nic(tulip_softc_t * const sc)
{
strcpy(sc->tulip_boardid, "Cogent ");
if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
* Magic number (0x24001109U) is the SubVendor (0x2400) and
* SubDevId (0x1109) for the ANA6944TX (EM440TX).
*/
- if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
+ if (*(uint32_t *) sc->tulip_rombuf == 0x24001109U
&& (sc->tulip_features & TULIP_HAVE_BASEROM)) {
/*
* Cogent (Adaptec) is still mapping all INTs to INTA of
sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
}
}
-\f
+
static void
-tulip_identify_accton_nic(
- tulip_softc_t * const sc)
+tulip_identify_accton_nic(tulip_softc_t * const sc)
{
strcpy(sc->tulip_boardid, "ACCTON ");
switch (sc->tulip_chipid) {
break;
}
}
-\f
+
static void
-tulip_identify_asante_nic(
- tulip_softc_t * const sc)
+tulip_identify_asante_nic(tulip_softc_t * const sc)
{
strcpy(sc->tulip_boardid, "Asante ");
if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
}
if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
- printf("%s%d: can't find phy 0\n", sc->tulip_name, sc->tulip_unit);
+ if_printf(&sc->tulip_if, "can't find phy 0\n");
return;
}
sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
}
}
-\f
+
static void
-tulip_identify_compex_nic(
- tulip_softc_t * const sc)
+tulip_identify_compex_nic(tulip_softc_t *sc)
{
strcpy(sc->tulip_boardid, "COMPEX ");
if (sc->tulip_chipid == TULIP_21140A) {
* copied from tulip_read_macaddr.
*/
sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
- for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
+ for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
root_sc = tulips[root_unit];
if (root_sc == NULL
|| !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
sc->tulip_slaves = root_sc->tulip_slaves;
root_sc->tulip_slaves = sc;
} else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
- printf("\nCannot find master device for de%d interrupts",
- sc->tulip_unit);
+ if_printf(&sc->tulip_if, "can't find master device for interrupts");
}
} else {
strcat(sc->tulip_boardid, "unknown ");
}
\f
static int
-tulip_srom_decode(
- tulip_softc_t * const sc)
+tulip_srom_decode(tulip_softc_t *sc)
{
- unsigned idx1, idx2, idx3;
+ u_int idx1, idx2, idx3;
const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
tulip_srom_media_t srom_media;
tulip_media_info_t *mi = sc->tulip_mediainfo;
- const u_int8_t *dp;
- u_int32_t leaf_offset, blocks, data;
+ const uint8_t *dp;
+ uint32_t leaf_offset, blocks, data;
for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
if (shp->sh_adapter_count == 1)
sc->tulip_gpinit = *dp++;
blocks = *dp++;
for (idx2 = 0; idx2 < blocks; idx2++) {
- const u_int8_t *ep;
+ const uint8_t *ep;
if ((*dp & 0x80) == 0) {
length = 4;
type = 0;
break;
}
case 1: { /* 21140[A] MII block */
- const unsigned phyno = *dp++;
+ const u_int phyno = *dp++;
mi->mi_type = TULIP_MEDIAINFO_MII;
mi->mi_gpr_length = *dp++;
mi->mi_gpr_offset = dp - sc->tulip_rombuf;
DELAY(10000);
mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
}
- if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
-#if defined(TULIP_DEBUG)
- printf("%s%d: can't find phy %d\n",
- sc->tulip_name, sc->tulip_unit, phyno);
-#endif
+ if (mi->mi_phyaddr == TULIP_MII_NOPHY)
break;
- }
sc->tulip_features |= TULIP_HAVE_MII;
mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
break;
}
case 3: { /* 2114[23] MII PHY block */
- const unsigned phyno = *dp++;
- const u_int8_t *dp0;
+ const u_int phyno = *dp++;
+ const uint8_t *dp0;
mi->mi_type = TULIP_MEDIAINFO_MII;
mi->mi_gpr_length = *dp++;
mi->mi_gpr_offset = dp - sc->tulip_rombuf;
DELAY(10000);
mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
}
- if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
-#if defined(TULIP_DEBUG)
- printf("%s%d: can't find phy %d\n",
- sc->tulip_name, sc->tulip_unit, phyno);
-#endif
+ if (mi->mi_phyaddr == TULIP_MII_NOPHY)
break;
- }
sc->tulip_features |= TULIP_HAVE_MII;
mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
* brain-deadness that various vendors commit in using them.
*/
static int
-tulip_read_macaddr(
- tulip_softc_t * const sc)
+tulip_read_macaddr(tulip_softc_t *sc)
{
- unsigned cksum, rom_cksum, idx;
- u_int32_t csr;
+ u_int cksum, rom_cksum, idx;
+ uint32_t csr;
unsigned char tmpbuf[8];
static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
if (idx == sizeof(sc->tulip_rombuf)) {
int root_unit;
tulip_softc_t *root_sc = NULL;
- for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
+ for (root_unit = device_get_unit(sc->tulip_dev) - 1; root_unit >= 0; root_unit--) {
root_sc = tulips[root_unit];
if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
break;
return -5;
} else {
bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
- sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
+ sc->tulip_enaddr[5] += device_get_unit(sc->tulip_dev) - device_get_unit(root_sc->tulip_dev);
}
/*
* Now for a truly disgusting kludge: all 4 21040s on
sc->tulip_features |= TULIP_HAVE_OKROM;
return 0;
}
-\f
+
static void
-tulip_ifmedia_add(
- tulip_softc_t * const sc)
+tulip_ifmedia_add(tulip_softc_t * const sc)
{
tulip_media_t media;
int medias = 0;
}
static int
-tulip_ifmedia_change(
- struct ifnet * const ifp)
+tulip_ifmedia_change(struct ifnet *ifp)
{
- tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
+ tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
sc->tulip_flags |= TULIP_NEEDRESET;
sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
tulip_init(sc);
return 0;
}
-\f
+
/*
* Media status callback
*/
static void
-tulip_ifmedia_status(
- struct ifnet * const ifp,
- struct ifmediareq *req)
+tulip_ifmedia_status(struct ifnet *ifp, struct ifmediareq *req)
{
tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
}
-\f
+
static void
-tulip_addr_filter(
- tulip_softc_t * const sc)
+tulip_addr_filter(tulip_softc_t *sc)
{
struct ifmultiaddr *ifma;
u_char *addrp;
#endif
multicnt = 0;
- for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
- ifma = ifma->ifma_link.le_next) {
-
+ LIST_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family == AF_LINK)
multicnt++;
}
sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
if (multicnt > 14) {
- u_int32_t *sp = sc->tulip_setupdata;
- unsigned hash;
+ uint32_t *sp = sc->tulip_setupdata;
+ u_int hash;
/*
* Some early passes of the 21140 have broken implementations of
* hash-perfect mode. When we get too many multicasts for perfect
*/
bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
- for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
- ifma = ifma->ifma_link.le_next) {
-
+ LIST_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
}
}
if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
- u_int32_t *sp = sc->tulip_setupdata;
+ uint32_t *sp = sc->tulip_setupdata;
int idx = 0;
if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
/*
* Else can get perfect filtering for 16 addresses.
*/
- for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
- ifma = ifma->ifma_link.le_next) {
+ LIST_FOREACH(ifma, &sc->tulip_if.if_multiaddrs, ifma_link) {
if (ifma->ifma_addr->sa_family != AF_LINK)
continue;
addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
}
\f
static void
-tulip_reset(
- tulip_softc_t * const sc)
+tulip_reset(tulip_softc_t *sc)
{
tulip_ringinfo_t *ri;
tulip_desc_t *di;
- u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
+ uint32_t inreset = (sc->tulip_flags & TULIP_INRESET);
/*
* Brilliant. Simply brilliant. When switching modes/speeds
sc->tulip_if.if_start = tulip_ifstart;
}
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr);
-#else
TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
-#endif
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr);
-#else
TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
-#endif
TULIP_CSR_WRITE(sc, csr_busmode,
(1 << (3 /*pci_max_burst_len*/ + 8))
|TULIP_BUSMODE_CACHE_ALIGN8
/*
* Free all the mbufs that were on the transmit ring.
*/
- for (;;) {
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- bus_dmamap_t map;
-#endif
- struct mbuf *m;
- IF_DEQUEUE(&sc->tulip_txq, m);
- if (m == NULL)
- break;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- map = M_GETCTX(m, bus_dmamap_t);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
-#endif
- m_freem(m);
- }
+ IF_DRAIN(&sc->tulip_txq);
ri = &sc->tulip_txinfo;
ri->ri_nextin = ri->ri_nextout = ri->ri_first;
ri->ri_free = ri->ri_max;
for (di = ri->ri_first; di < ri->ri_last; di++)
di->d_status = 0;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap,
- 0, sc->tulip_txdescmap->dm_mapsize,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
-#endif
/*
* We need to collect all the mbufs were on the
di->d_length1 = 0; di->d_addr1 = 0;
di->d_length2 = 0; di->d_addr2 = 0;
}
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap,
- 0, sc->tulip_rxdescmap->dm_mapsize,
- BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
-#endif
- for (;;) {
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- bus_dmamap_t map;
-#endif
- struct mbuf *m;
- IF_DEQUEUE(&sc->tulip_rxq, m);
- if (m == NULL)
- break;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- map = M_GETCTX(m, bus_dmamap_t);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
-#endif
- m_freem(m);
- }
+ IF_DRAIN(&sc->tulip_rxq);
/*
* If tulip_reset is being called recurisvely, exit quickly knowing
if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
(*sc->tulip_boardsw->bd_media_select)(sc);
-#if defined(TULIP_DEBUG)
- if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
- printf("%s%d: tulip_reset: additional reset needed?!?\n",
- sc->tulip_name, sc->tulip_unit);
-#endif
tulip_media_print(sc);
if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
|TULIP_RXACT);
tulip_addr_filter(sc);
}
-\f
+
static void
-tulip_init(
- tulip_softc_t * const sc)
+tulip_init(tulip_softc_t * const sc)
{
if (sc->tulip_if.if_flags & IFF_UP) {
if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
tulip_reset(sc);
}
}
-\f
+
static void
-tulip_rx_intr(
- tulip_softc_t * const sc)
+tulip_rx_intr(tulip_softc_t *sc)
{
- tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
- struct ifnet * const ifp = &sc->tulip_if;
+ tulip_ringinfo_t *ri = &sc->tulip_rxinfo;
+ struct ifnet *ifp = &sc->tulip_if;
int fillok = 1;
-#if defined(TULIP_DEBUG)
- int cnt = 0;
-#endif
for (;;) {
struct ether_header eh;
int total_len = 0, last_offset = 0;
struct mbuf *ms = NULL, *me = NULL;
int accept = 0;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- bus_dmamap_t map;
- int error;
-#endif
if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
goto queue_mbuf;
-#if defined(TULIP_DEBUG)
- if (cnt == ri->ri_max)
- break;
-#endif
/*
* If the TULIP has no descriptors, there can't be any receive
* descriptors to process.
eop = ri->ri_first;
TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_rxintrs++;
- sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
-#endif
return;
}
total_len++;
*/
IF_DEQUEUE(&sc->tulip_rxq, ms);
for (me = ms; total_len > 0; total_len--) {
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- map = M_GETCTX(me, bus_dmamap_t);
- TULIP_RXMAP_POSTSYNC(sc, map);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
-#if defined(DIAGNOSTIC)
- M_SETCTX(me, NULL);
-#endif
-#endif /* TULIP_BUS_DMA */
me->m_len = TULIP_RX_BUFLEN;
last_offset += TULIP_RX_BUFLEN;
IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
)) {
me->m_len = total_len - last_offset;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- map = M_GETCTX(me, bus_dmamap_t);
- bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len,
- BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
-#if defined(DIAGNOSTIC)
- M_SETCTX(me, NULL);
-#endif
-#endif /* TULIP_BUS_DMA */
-
eh = *mtod(ms, struct ether_header *);
-#if !defined(__DragonFly__) && !defined(__FreeBSD__)
- if (sc->tulip_if.if_bpf != NULL) {
- if (me == ms)
- bpf_tap(&sc->tulip_if, mtod(ms, caddr_t), total_len);
- else
- bpf_mtap(&sc->tulip_if, ms);
- }
-#endif
sc->tulip_flags |= TULIP_RXACT;
accept = 1;
} else {
if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
} else {
-#if defined(TULIP_VERBOSE)
- const char *error = NULL;
-#endif
if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
-#if defined(TULIP_VERBOSE)
- error = "frame too long";
-#endif
}
if (eop->d_status & TULIP_DSTS_RxBADCRC) {
if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
-#if defined(TULIP_VERBOSE)
- error = "alignment error";
-#endif
} else {
sc->tulip_dot3stats.dot3StatsFCSErrors++;
-#if defined(TULIP_VERBOSE)
- error = "bad crc";
-#endif
}
}
-#if defined(TULIP_VERBOSE)
- if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
- printf("%s%d: receive: %6D: %s\n",
- sc->tulip_name, sc->tulip_unit,
- mtod(ms, u_char *) + 6, ":",
- error);
- sc->tulip_flags |= TULIP_NOMESSAGES;
- }
-#endif
}
-
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- map = M_GETCTX(me, bus_dmamap_t);
- bus_dmamap_unload(sc->tulip_dmatag, map);
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
-#if defined(DIAGNOSTIC)
- M_SETCTX(me, NULL);
-#endif
-#endif /* TULIP_BUS_DMA */
}
-#if defined(TULIP_DEBUG)
- cnt++;
-#endif
ifp->if_ipackets++;
if (++eop == ri->ri_last)
eop = ri->ri_first;
*/
if (accept || ms == NULL) {
struct mbuf *m0;
- MGETHDR(m0, MB_DONTWAIT, MT_DATA);
- if (m0 != NULL) {
-#if defined(TULIP_COPY_RXDATA)
- if (!accept || total_len >= (MHLEN - 2)) {
-#endif
- MCLGET(m0, MB_DONTWAIT);
- if ((m0->m_flags & M_EXT) == 0) {
- m_freem(m0);
- m0 = NULL;
- }
+
#if defined(TULIP_COPY_RXDATA)
- }
+ if (!accept || total_len >= (MHLEN - 2))
+ m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
+ else
+ m0 = m_gethdr(MB_DONTWAIT, MT_DATA);
+#else
+ m0 = m_getcl(MB_DONTWAIT, MT_DATA, M_PKTHDR);
#endif
- }
+
if (accept
#if defined(TULIP_COPY_RXDATA)
&& m0 != NULL
*/
fillok = 0;
sc->tulip_flags |= TULIP_RXBUFSLOW;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_rxlowbufs++;
-#endif
continue;
}
/*
*/
do {
tulip_desc_t * const nextout = ri->ri_nextout;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
- if (sc->tulip_rxmaps_free > 0) {
- map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free];
- } else {
- m_freem(ms);
- sc->tulip_flags |= TULIP_RXBUFSLOW;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_rxlowbufs++;
-#endif
- break;
- }
- M_SETCTX(ms, map);
- error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *),
- TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT);
- if (error) {
- printf("%s%d: unable to load rx map, "
- "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
- panic("tulip_rx_intr"); /* XXX */
- }
- nextout->d_addr1 = map->dm_segs[0].ds_addr;
- nextout->d_length1 = map->dm_segs[0].ds_len;
- if (map->dm_nsegs == 2) {
- nextout->d_addr2 = map->dm_segs[1].ds_addr;
- nextout->d_length2 = map->dm_segs[1].ds_len;
- } else {
- nextout->d_addr2 = 0;
- nextout->d_length2 = 0;
- }
- TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout));
-#else /* TULIP_BUS_DMA */
nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
nextout->d_length1 = TULIP_RX_BUFLEN;
-#endif /* TULIP_BUS_DMA */
nextout->d_status = TULIP_DSTS_OWNER;
TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
if (++ri->ri_nextout == ri->ri_last)
if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
sc->tulip_flags &= ~TULIP_RXBUFSLOW;
}
-
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_rxintrs++;
- sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
-#endif
}
-\f
+
static int
-tulip_tx_intr(
- tulip_softc_t * const sc)
+tulip_tx_intr(tulip_softc_t *sc)
{
- tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
+ tulip_ringinfo_t *ri = &sc->tulip_txinfo;
struct mbuf *m;
int xmits = 0;
int descs = 0;
while (ri->ri_free < ri->ri_max) {
- u_int32_t d_flag;
+ uint32_t d_flag;
TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
}
} else {
- const u_int32_t d_status = ri->ri_nextin->d_status;
+ const uint32_t d_status = ri->ri_nextin->d_status;
IF_DEQUEUE(&sc->tulip_txq, m);
if (m != NULL) {
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t);
- TULIP_TXMAP_POSTSYNC(sc, map);
- sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
-#endif /* TULIP_BUS_DMA */
m_freem(m);
-#if defined(TULIP_DEBUG)
- } else {
- printf("%s%d: tx_intr: failed to dequeue mbuf?!?\n",
- sc->tulip_name, sc->tulip_unit);
-#endif
}
if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
-#if defined(TULIP_DEBUG)
- if (d_status & TULIP_DSTS_TxNOCARR)
- sc->tulip_dbg.dbg_txprobe_nocarr++;
- if (d_status & TULIP_DSTS_TxEXCCOLL)
- sc->tulip_dbg.dbg_txprobe_exccoll++;
-#endif
event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
}
(*sc->tulip_boardsw->bd_media_poll)(sc, event);
sc->tulip_if.if_opackets += xmits;
return descs;
}
-\f
+
static void
-tulip_print_abnormal_interrupt(
- tulip_softc_t * const sc,
- u_int32_t csr)
+tulip_print_abnormal_interrupt(tulip_softc_t *sc, uint32_t csr)
{
const char * const *msgp = tulip_status_bits;
const char *sep;
- u_int32_t mask;
+ uint32_t mask;
const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
- printf("%s%d: abnormal interrupt:", sc->tulip_name, sc->tulip_unit);
+ if_printf(&sc->tulip_if, "abnormal interrupt:");
for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
if ((csr & mask) && *msgp != NULL) {
printf("%s%s", sep, *msgp);
}
static void
-tulip_intr_handler(
- tulip_softc_t * const sc,
- int *progress_p)
+tulip_intr_handler(tulip_softc_t *sc)
{
- u_int32_t csr;
+ uint32_t csr;
while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
- *progress_p = 1;
TULIP_CSR_WRITE(sc, csr_status, csr);
if (csr & TULIP_STS_SYSERROR) {
if (sc->tulip_flags & TULIP_NOMESSAGES) {
sc->tulip_flags |= TULIP_SYSTEMERROR;
} else {
- printf("%s%d: system error: %s\n",
- sc->tulip_name, sc->tulip_unit,
+ if_printf(&sc->tulip_if, "system error: %s\n",
tulip_system_errors[sc->tulip_last_system_error]);
}
sc->tulip_flags |= TULIP_NEEDRESET;
break;
}
if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_link_intrs++;
-#endif
if (sc->tulip_boardsw->bd_media_poll != NULL) {
(*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
? TULIP_MEDIAPOLL_LINKFAIL
}
static void
-tulip_intr_shared(
- void *arg)
+tulip_intr_shared(void *arg)
{
- tulip_softc_t * sc = arg;
- int progress = 0;
+ tulip_softc_t *sc;
- for (; sc != NULL; sc = sc->tulip_slaves) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_intrs++;
-#endif
- tulip_intr_handler(sc, &progress);
- }
+ for (sc = arg; sc != NULL; sc = sc->tulip_slaves)
+ tulip_intr_handler(sc);
}
static void
-tulip_intr_normal(
- void *arg)
+tulip_intr_normal(void *arg)
{
- tulip_softc_t * sc = (tulip_softc_t *) arg;
- int progress = 0;
+ tulip_softc_t *sc = (tulip_softc_t *)arg;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_intrs++;
-#endif
- tulip_intr_handler(sc, &progress);
+ tulip_intr_handler(sc);
}
-\f
-static struct mbuf *
-tulip_mbuf_compress(
- struct mbuf *m)
-{
- struct mbuf *m0;
-#if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET)
- MGETHDR(m0, MB_DONTWAIT, MT_DATA);
- if (m0 != NULL) {
- if (m->m_pkthdr.len > MHLEN) {
- MCLGET(m0, MB_DONTWAIT);
- if ((m0->m_flags & M_EXT) == 0) {
- m_freem(m);
- m_freem(m0);
- return NULL;
- }
- }
- m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
- m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
- }
-#else
- int mlen = MHLEN;
- int len = m->m_pkthdr.len;
- struct mbuf **mp = &m0;
- while (len > 0) {
- if (mlen == MHLEN) {
- MGETHDR(*mp, MB_DONTWAIT, MT_DATA);
- } else {
- MGET(*mp, MB_DONTWAIT, MT_DATA);
- }
- if (*mp == NULL) {
- m_freem(m0);
- m0 = NULL;
- break;
- }
- if (len > MLEN) {
- MCLGET(*mp, MB_DONTWAIT);
- if (((*mp)->m_flags & M_EXT) == 0) {
- m_freem(m0);
- m0 = NULL;
- break;
- }
- (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
- } else {
- (*mp)->m_len = len <= mlen ? len : mlen;
- }
- m_copydata(m, m->m_pkthdr.len - len,
- (*mp)->m_len, mtod((*mp), caddr_t));
- len -= (*mp)->m_len;
- mp = &(*mp)->m_next;
- mlen = MLEN;
- }
-#endif
- m_freem(m);
- return m0;
-}
-\f
static struct mbuf *
-tulip_txput(
- tulip_softc_t * const sc,
- struct mbuf *m)
+tulip_txput(tulip_softc_t *sc, struct mbuf *m)
{
- tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
+ tulip_ringinfo_t *ri = &sc->tulip_txinfo;
tulip_desc_t *eop, *nextout;
int segcnt, free;
- u_int32_t d_status;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- bus_dmamap_t map;
- int error;
-#else
+ uint32_t d_status;
struct mbuf *m0;
-#endif
-
-#if defined(TULIP_DEBUG)
- if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
- printf("%s%d: txput%s: tx not running\n",
- sc->tulip_name, sc->tulip_unit,
- (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
- sc->tulip_flags |= TULIP_WANTTXSTART;
- sc->tulip_dbg.dbg_txput_finishes[0]++;
- goto finish;
- }
-#endif
/*
* Now we try to fill in our transmit descriptors. This is
* case we will just wait for the ring to empty. In the
* latter case we have to recopy.
*/
-#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
again:
m0 = m;
-#endif
d_status = 0;
eop = nextout = ri->ri_nextout;
segcnt = 0;
free = ri->ri_free;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- /*
- * Reclaim some dma maps from if we are out.
- */
- if (sc->tulip_txmaps_free == 0) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_no_txmaps++;
-#endif
- free += tulip_tx_intr(sc);
- }
- if (sc->tulip_txmaps_free > 0) {
- map = sc->tulip_txmaps[sc->tulip_txmaps_free-1];
- } else {
- sc->tulip_flags |= TULIP_WANTTXSTART;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[1]++;
-#endif
- goto finish;
- }
- error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
- if (error != 0) {
- if (error == EFBIG) {
- /*
- * The packet exceeds the number of transmit buffer
- * entries that we can use for one packet, so we have
- * to recopy it into one mbuf and then try again.
- */
- m = tulip_mbuf_compress(m);
- if (m == NULL) {
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[2]++;
-#endif
- goto finish;
- }
- error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
- }
- if (error != 0) {
- printf("%s%d: unable to load tx map, "
- "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[3]++;
-#endif
- goto finish;
- }
- }
- if ((free -= (map->dm_nsegs + 1) / 2) <= 0
- /*
- * See if there's any unclaimed space in the transmit ring.
- */
- && (free += tulip_tx_intr(sc)) <= 0) {
- /*
- * There's no more room but since nothing
- * has been committed at this point, just
- * show output is active, put back the
- * mbuf and return.
- */
- sc->tulip_flags |= TULIP_WANTTXSTART;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[4]++;
-#endif
- bus_dmamap_unload(sc->tulip_dmatag, map);
- goto finish;
- }
- for (; map->dm_nsegs - segcnt > 1; segcnt += 2) {
- eop = nextout;
- eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
- eop->d_status = d_status;
- eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
- eop->d_length1 = map->dm_segs[segcnt].ds_len;
- eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr;
- eop->d_length2 = map->dm_segs[segcnt+1].ds_len;
- d_status = TULIP_DSTS_OWNER;
- if (++nextout == ri->ri_last)
- nextout = ri->ri_first;
- }
- if (segcnt < map->dm_nsegs) {
- eop = nextout;
- eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
- eop->d_status = d_status;
- eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
- eop->d_length1 = map->dm_segs[segcnt].ds_len;
- eop->d_addr2 = 0;
- eop->d_length2 = 0;
- if (++nextout == ri->ri_last)
- nextout = ri->ri_first;
- }
- TULIP_TXMAP_PRESYNC(sc, map);
- M_SETCTX(m, map);
- map = NULL;
- --sc->tulip_txmaps_free; /* commit to using the dmamap */
-
-#else /* !TULIP_BUS_DMA */
-
do {
int len = m0->m_len;
caddr_t addr = mtod(m0, caddr_t);
* entries that we can use for one packet, so we have
* recopy it into one mbuf and then try again.
*/
- m = tulip_mbuf_compress(m);
- if (m == NULL)
+ m0 = m_defrag(m, MB_DONTWAIT);
+ if (m0 == NULL)
goto finish;
+ m = m0;
goto again;
}
if (segcnt & 1) {
* mbuf and return.
*/
sc->tulip_flags |= TULIP_WANTTXSTART;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[1]++;
-#endif
goto finish;
}
}
clsize = PAGE_SIZE;
}
} while ((m0 = m0->m_next) != NULL);
-#endif /* TULIP_BUS_DMA */
BPF_MTAP(&sc->tulip_if, m);
nextout->d_status = 0;
TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
-#if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
/*
* If we only used the first segment of the last descriptor,
* make sure the second segment will not be used.
eop->d_addr2 = 0;
eop->d_length2 = 0;
}
-#endif /* TULIP_BUS_DMA */
/*
* Mark the last and first segments, indicate we want a transmit
* everything we have done.
*/
ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
-#if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX)
- if (eop < ri->ri_nextout) {
- TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
- (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout);
- TULIP_TXDESC_PRESYNC(sc, ri->ri_first,
- (caddr_t) (eop + 1) - (caddr_t) ri->ri_first);
- } else {
- TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
- (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout);
- }
-#endif
ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
sc->tulip_flags &= ~TULIP_WANTTXSTART;
if (sc->tulip_txtimer == 0)
sc->tulip_txtimer = TULIP_TXTIMER;
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[5]++;
-#endif
/*
* If we want a txstart, there must be not enough space in the
* WANTTXSTART thereby causing TXINTR to be cleared.
*/
finish:
-#if defined(TULIP_DEBUG)
- sc->tulip_dbg.dbg_txput_finishes[6]++;
-#endif
if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
sc->tulip_if.if_flags |= IFF_OACTIVE;
sc->tulip_if.if_start = tulip_ifstart;
TULIP_CSR_WRITE(sc, csr_txpoll, 1);
return m;
}
-\f
+
static void
-tulip_txput_setup(
- tulip_softc_t * const sc)
+tulip_txput_setup(tulip_softc_t *sc)
{
- tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
+ tulip_ringinfo_t *ri = &sc->tulip_txinfo;
tulip_desc_t *nextout;
/*
* We will transmit, at most, one setup packet per call to ifstart.
*/
-#if defined(TULIP_DEBUG)
- if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
- printf("%s%d: txput_setup: tx not running\n",
- sc->tulip_name, sc->tulip_unit);
- sc->tulip_flags |= TULIP_WANTTXSTART;
- sc->tulip_if.if_start = tulip_ifstart;
- return;
- }
-#endif
/*
* Try to reclaim some free descriptors..
*/
nextout->d_length2 = 0;
nextout->d_addr2 = 0;
-#if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
- nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len;
- nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr;
- if (sc->tulip_setupmap->dm_nsegs == 2) {
- nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len;
- nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr;
- }
- TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap);
- TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout));
-#else
nextout->d_length1 = sizeof(sc->tulip_setupbuf);
nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
-#endif
/*
* Advance the ring for the next transmit packet.
}
}
-\f
static int
-tulip_ifioctl(
- struct ifnet * ifp,
- u_long cmd,
- caddr_t data,
- struct ucred * cr)
+tulip_ifioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred * cr)
{
- tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
+ tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
struct ifaddr *ifa = (struct ifaddr *)data;
- struct ifreq *ifr = (struct ifreq *) data;
- int s;
+ struct ifreq *ifr = (struct ifreq *)data;
int error = 0;
- s = splimp();
+ crit_enter();
+
switch (cmd) {
case SIOCSIFADDR: {
ifp->if_flags |= IFF_UP;
}
}
- splx(s);
+ crit_exit();
+
return error;
}
-\f
+
static void
-tulip_ifstart(
- struct ifnet * const ifp)
+tulip_ifstart(struct ifnet *ifp)
{
- tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
+ tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
if (sc->tulip_if.if_flags & IFF_RUNNING) {
}
}
}
-\f
+
static void
-tulip_ifwatchdog(
- struct ifnet *ifp)
+tulip_ifwatchdog(struct ifnet *ifp)
{
tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
-#if defined(TULIP_DEBUG)
- u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
- if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
- sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
- sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
-#endif /* TULIP_DEBUG */
-
sc->tulip_if.if_timer = 1;
/*
* These should be rare so do a bulk test up front so we can just skip
tulip_rx_intr(sc);
if (sc->tulip_flags & TULIP_SYSTEMERROR) {
- printf("%s%d: %d system errors: last was %s\n",
- sc->tulip_name, sc->tulip_unit, sc->tulip_system_errors,
- tulip_system_errors[sc->tulip_last_system_error]);
+ if_printf(ifp, "%d system errors: last was %s\n",
+ sc->tulip_system_errors,
+ tulip_system_errors[sc->tulip_last_system_error]);
}
if (sc->tulip_statusbits) {
tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
if (sc->tulip_txtimer)
tulip_tx_intr(sc);
if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
- printf("%s%d: transmission timeout\n", sc->tulip_name, sc->tulip_unit);
+ if_printf(ifp, "transmission timeout\n");
if (TULIP_DO_AUTOSENSE(sc)) {
sc->tulip_media = TULIP_MEDIA_UNKNOWN;
sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
tulip_init(sc);
}
}
-\f
-/*
- * All printf's are real as of now!
- */
-#ifdef printf
-#undef printf
-#endif
static void
-tulip_attach(
- tulip_softc_t * const sc)
+tulip_attach(tulip_softc_t *sc)
{
- struct ifnet * const ifp = &sc->tulip_if;
+ struct ifnet *ifp = &sc->tulip_if;
callout_init(&sc->tulip_timer);
callout_init(&sc->tulip_fast_timer);
- if_initname(ifp, sc->tulip_name, sc->tulip_unit);
ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
ifp->if_ioctl = tulip_ifioctl;
ifp->if_start = tulip_ifstart;
ifp->if_watchdog = tulip_ifwatchdog;
ifp->if_timer = 1;
- printf("%s%d: %s%s pass %d.%d%s\n",
- sc->tulip_name, sc->tulip_unit,
+ if_printf(ifp, "%s%s pass %d.%d%s\n",
sc->tulip_boardid,
tulip_chipdescs[sc->tulip_chipid],
(sc->tulip_revinfo & 0xF0) >> 4,
ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr);
ifp->if_snd.ifq_maxlen = ifqmaxlen;
}
-\f
-#if defined(TULIP_BUS_DMA)
-#if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX)
-static int
-tulip_busdma_allocmem(
- tulip_softc_t * const sc,
- size_t size,
- bus_dmamap_t *map_p,
- tulip_desc_t **desc_p)
-{
- bus_dma_segment_t segs[1];
- int nsegs, error;
- error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE,
- segs, sizeof(segs)/sizeof(segs[0]),
- &nsegs, BUS_DMA_NOWAIT);
- if (error == 0) {
- void *desc;
- error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size,
- (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
- if (error == 0) {
- bus_dmamap_t map;
- error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0,
- BUS_DMA_NOWAIT, &map);
- if (error == 0) {
- error = bus_dmamap_load(sc->tulip_dmatag, map, desc,
- size, NULL, BUS_DMA_NOWAIT);
- if (error)
- bus_dmamap_destroy(sc->tulip_dmatag, map);
- else
- *map_p = map;
- }
- if (error)
- bus_dmamem_unmap(sc->tulip_dmatag, desc, size);
- }
- if (error)
- bus_dmamem_free(sc->tulip_dmatag, segs, nsegs);
- else
- *desc_p = desc;
- }
- return error;
-}
-#endif
-\f
-static int
-tulip_busdma_init(
- tulip_softc_t * const sc)
-{
- int error = 0;
-
-#if !defined(TULIP_BUS_DMA_NOTX)
- /*
- * Allocate dmamap for setup descriptor
- */
- error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2,
- sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT,
- &sc->tulip_setupmap);
- if (error == 0) {
- error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap,
- sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf),
- NULL, BUS_DMA_NOWAIT);
- if (error)
- bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap);
- }
- /*
- * Allocate space and dmamap for transmit ring
- */
- if (error == 0) {
- error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS,
- &sc->tulip_txdescmap,
- &sc->tulip_txdescs);
- }
-
- /*
- * Allocate dmamaps for each transmit descriptors
- */
- if (error == 0) {
- while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) {
- bus_dmamap_t map;
- if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0)
- sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
- }
- if (error) {
- while (sc->tulip_txmaps_free > 0)
- bus_dmamap_destroy(sc->tulip_dmatag,
- sc->tulip_txmaps[--sc->tulip_txmaps_free]);
- }
- }
-#else
- if (error == 0) {
- sc->tulip_txdescs = malloc(TULIP_TXDESCS * sizeof(tulip_desc_t),
- M_DEVBUF, M_INTWAIT);
- }
-#endif
-#if !defined(TULIP_BUS_DMA_NORX)
- /*
- * Allocate space and dmamap for receive ring
- */
- if (error == 0) {
- error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS,
- &sc->tulip_rxdescmap,
- &sc->tulip_rxdescs);
- }
- /*
- * Allocate dmamaps for each receive descriptors
- */
- if (error == 0) {
- while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) {
- bus_dmamap_t map;
- if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0)
- sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
- }
- if (error) {
- while (sc->tulip_rxmaps_free > 0)
- bus_dmamap_destroy(sc->tulip_dmatag,
- sc->tulip_rxmaps[--sc->tulip_rxmaps_free]);
- }
- }
-#else
- if (error == 0) {
- sc->tulip_rxdescs = malloc(TULIP_RXDESCS * sizeof(tulip_desc_t),
- M_DEVBUF, M_INTWAIT);
- }
-#endif
- return error;
-}
-#endif /* TULIP_BUS_DMA */
-\f
static void
-tulip_initcsrs(
- tulip_softc_t * const sc,
- tulip_csrptr_t csr_base,
- size_t csr_size)
+tulip_initcsrs(tulip_softc_t *sc, tulip_csrptr_t csr_base, size_t csr_size)
{
sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
}
-\f
+
static void
-tulip_initring(
- tulip_softc_t * const sc,
- tulip_ringinfo_t * const ri,
- tulip_desc_t *descs,
- int ndescs)
+tulip_initring(tulip_softc_t *sc, tulip_ringinfo_t *ri, tulip_desc_t *descs,
+ int ndescs)
{
ri->ri_max = ndescs;
ri->ri_first = descs;
bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
}
-\f
+
/*
* This is the PCI configuration support.
*/
static int
tulip_shutdown(device_t dev)
{
- tulip_softc_t * const sc = device_get_softc(dev);
+ tulip_softc_t *sc = device_get_softc(dev);
TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
33MHz that comes to two microseconds but wait a
{
tulip_softc_t *sc;
int retval, idx;
- u_int32_t revinfo, cfdainfo, cfcsinfo;
- unsigned csroffset = TULIP_PCI_CSROFFSET;
- unsigned csrsize = TULIP_PCI_CSRSIZE;
+ uint32_t revinfo, cfdainfo, cfcsinfo;
+ u_int csroffset = TULIP_PCI_CSROFFSET;
+ u_int csrsize = TULIP_PCI_CSRSIZE;
tulip_csrptr_t csr_base;
tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
struct resource *res;
- int rid, unit;
-
- unit = device_get_unit(dev);
+ int rid;
- if (unit >= TULIP_MAX_DEVICES) {
- printf("de%d", unit);
- printf(": not configured; limit of %d reached or exceeded\n",
+ if (device_get_unit(dev) >= TULIP_MAX_DEVICES) {
+ device_printf(dev, "not configured; limit of %d reached or exceeded\n",
TULIP_MAX_DEVICES);
return ENXIO;
}
cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
/* turn busmaster on in case BIOS doesn't set it */
- if(!(cfcsinfo & PCIM_CMD_BUSMASTEREN)) {
- cfcsinfo |= PCIM_CMD_BUSMASTEREN;
- pci_write_config(dev, PCIR_COMMAND, cfcsinfo, 4);
- }
+ pci_enable_busmaster(dev);
if (pci_get_vendor(dev) == DEC_VENDORID) {
if (pci_get_device(dev) == CHIPID_21040)
return ENXIO;
if (chipid == TULIP_21040 && revinfo < 0x20) {
- printf("de%d", unit);
- printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
+ device_printf(dev, "not configured; 21040 pass 2.0 required (%d.%d found)\n",
revinfo >> 4, revinfo & 0x0f);
return ENXIO;
} else if (chipid == TULIP_21140 && revinfo < 0x11) {
- printf("de%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
- unit, revinfo >> 4, revinfo & 0x0f);
+ device_printf(dev, "not configured; 21140 pass 1.1 required (%d.%d found)\n",
+ revinfo >> 4, revinfo & 0x0f);
return ENXIO;
}
sc = device_get_softc(dev);
+ sc->tulip_dev = dev;
sc->tulip_pci_busno = pci_get_bus(dev);
sc->tulip_pci_devno = pci_get_slot(dev);
sc->tulip_chipid = chipid;
pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
DELAY(11*1000);
}
- sc->tulip_unit = unit;
- sc->tulip_name = "de";
+ if_initname(&sc->tulip_if, device_get_name(dev), device_get_unit(dev));
sc->tulip_revinfo = revinfo;
sc->tulip_if.if_softc = sc;
#if defined(TULIP_IOMAPPED)
rid = PCI_CBIO;
- res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
- 0, ~0, 1, RF_ACTIVE);
+ res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
#else
rid = PCI_CBMA;
- res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
- 0, ~0, 1, RF_ACTIVE);
+ res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
#endif
if (!res)
return ENXIO;
sc->tulip_csrs_bsh = rman_get_bushandle(res);
csr_base = 0;
- tulips[unit] = sc;
+ tulips[device_get_unit(dev)] = sc;
tulip_initcsrs(sc, csr_base + csroffset, csrsize);
-#if defined(TULIP_BUS_DMA)
- if ((retval = tulip_busdma_init(sc)) != 0) {
- printf("error initing bus_dma: %d\n", retval);
- return ENXIO;
- }
-#else
sc->tulip_rxdescs = malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
M_DEVBUF, M_INTWAIT);
sc->tulip_txdescs = malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
M_DEVBUF, M_INTWAIT);
-#endif
tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
bit longer anyways) */
if ((retval = tulip_read_macaddr(sc)) < 0) {
- printf("%s%d", sc->tulip_name, sc->tulip_unit);
- printf(": can't read ENET ROM (why=%d) (", retval);
+ device_printf(dev, "can't read ENET ROM (why=%d) (", retval);
for (idx = 0; idx < 32; idx++)
printf("%02x", sc->tulip_rombuf[idx]);
printf("\n");
- printf("%s%d: %s%s pass %d.%d\n",
- sc->tulip_name, sc->tulip_unit,
+ device_printf(dev, "%s%s pass %d.%d\n",
sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
(sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
- printf("%s%d: address unknown\n", sc->tulip_name, sc->tulip_unit);
+ device_printf(dev, "address unknown\n");
} else {
- int s;
void (*intr_rtn)(void *) = tulip_intr_normal;
if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
void *ih;
rid = 0;
- res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
- 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
+ res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
+ RF_SHAREABLE | RF_ACTIVE);
if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
- intr_rtn, sc, &ih)) {
- printf("%s%d: couldn't map interrupt\n",
- sc->tulip_name, sc->tulip_unit);
+ intr_rtn, sc, &ih, NULL)) {
+ device_printf(dev, "couldn't map interrupt\n");
free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
return ENXIO;
}
}
- s = splimp();
+ crit_enter();
tulip_attach(sc);
- splx(s);
+ crit_exit();
}
return 0;
}