1 /* $NetBSD: if_de.c,v 1.86 1999/06/01 19:17:59 thorpej Exp $ */
3 /* $FreeBSD: src/sys/pci/if_de.c,v 1.123.2.4 2000/08/04 23:25:09 peter Exp $ */
4 /* $DragonFly: src/sys/dev/netif/de/if_de.c,v 1.16 2004/09/14 22:54:16 joerg Exp $ */
7 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software withough specific prior written permission
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp
34 * DEC 21040 PCI Ethernet Controller
36 * Written by Matt Thomas
37 * BPF support code stolen directly from if_ec.c
39 * This driver supports the DEC DE435 or any other PCI
40 * board which support 21040, 21041, or 21140 (mostly).
42 #define TULIP_HDR_DATA
44 #include <sys/param.h>
45 #include <sys/systm.h>
47 #include <sys/socket.h>
48 #include <sys/sockio.h>
49 #include <sys/malloc.h>
50 #include <sys/kernel.h>
51 #include <sys/eventhandler.h>
52 #include <machine/clock.h>
53 #include <machine/bus.h>
54 #include <machine/resource.h>
62 #include <net/if_media.h>
63 #include <net/if_dl.h>
64 #ifdef TULIP_USE_SOFTINTR
65 #include <net/netisr.h>
71 #include <netinet/in.h>
72 #include <netinet/if_ether.h>
76 #include <netproto/ipx/ipx.h>
77 #include <netproto/ipx/ipx_if.h>
81 #include <netproto/ns/ns.h>
82 #include <netproto/ns/ns_if.h>
87 #include <net/if_var.h>
89 #include <bus/pci/pcivar.h>
90 #include <bus/pci/pcireg.h>
91 #include <bus/pci/dc21040reg.h>
94 * Intel CPUs should use I/O mapped access.
97 #define TULIP_IOMAPPED
102 * This turns on all sort of debugging stuff and make the
103 * driver much larger.
109 #define TULIP_PERFSTATS
113 #define TULIP_USE_SOFTINTR
118 #include "if_devar.h"
121 * This module supports
122 * the DEC 21040 PCI Ethernet Controller.
123 * the DEC 21041 PCI Ethernet Controller.
124 * the DEC 21140 PCI Fast Ethernet Controller.
126 static void tulip_mii_autonegotiate(tulip_softc_t * const sc, const unsigned phyaddr);
127 static void tulip_intr_shared(void *arg);
128 static void tulip_intr_normal(void *arg);
129 static void tulip_init(tulip_softc_t * const sc);
130 static void tulip_reset(tulip_softc_t * const sc);
131 static void tulip_ifstart_one(struct ifnet *ifp);
132 static void tulip_ifstart(struct ifnet *ifp);
133 static struct mbuf *tulip_txput(tulip_softc_t * const sc, struct mbuf *m);
134 static void tulip_txput_setup(tulip_softc_t * const sc);
135 static void tulip_rx_intr(tulip_softc_t * const sc);
136 static void tulip_addr_filter(tulip_softc_t * const sc);
137 static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno);
138 static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data);
139 static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
140 static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t * const sc);
141 static int tulip_srom_decode(tulip_softc_t * const sc);
142 static int tulip_ifmedia_change(struct ifnet * const ifp);
143 static void tulip_ifmedia_status(struct ifnet * const ifp, struct ifmediareq *req);
144 /* static void tulip_21140_map_media(tulip_softc_t *sc); */
147 tulip_timeout_callback(
150 tulip_softc_t * const sc = arg;
153 TULIP_PERFSTART(timeout)
155 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
156 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
157 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
159 TULIP_PERFEND(timeout);
165 tulip_softc_t * const sc)
167 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
169 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
170 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
171 tulip_timeout_callback, sc);
174 #if defined(TULIP_NEED_FASTTIMEOUT)
176 tulip_fasttimeout_callback(
179 tulip_softc_t * const sc = arg;
182 sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING;
183 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER);
189 tulip_softc_t * const sc)
191 if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING)
193 sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING;
194 callout_reset(&sc->tulip_fast_timer, 1, tulip_fasttimeout_callback, sc);
200 tulip_softc_t * const sc)
204 * Before we are sure this is the right media we need
205 * to send a small packet to make sure there's carrier.
206 * Strangely, BNC and AUI will "see" receive data if
207 * either is connected so the transmit is the only way
208 * to verify the connectivity.
210 MGETHDR(m, MB_DONTWAIT, MT_DATA);
214 * Construct a LLC TEST message which will point to ourselves.
216 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
217 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
218 mtod(m, struct ether_header *)->ether_type = htons(3);
219 mtod(m, unsigned char *)[14] = 0;
220 mtod(m, unsigned char *)[15] = 0;
221 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
222 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
226 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
227 sc->tulip_intrmask |= TULIP_STS_TXINTR;
228 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
229 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
230 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
231 if ((m = tulip_txput(sc, m)) != NULL)
233 sc->tulip_probe.probe_txprobes++;
238 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
240 #define TULIP_SIAGEN_WATCHDOG 0
245 tulip_softc_t * const sc,
248 const tulip_media_info_t *mi = sc->tulip_mediums[media];
254 * If we are switching media, make sure we don't think there's
255 * any stale RX activity
257 sc->tulip_flags &= ~TULIP_RXACT;
258 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
259 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
260 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
261 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
262 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
264 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
266 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
268 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
269 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
270 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
272 * If the cmdmode bits don't match the currently operating mode,
273 * set the cmdmode appropriately and reset the chip.
275 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
276 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
277 sc->tulip_cmdmode |= mi->mi_cmdmode;
280 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
282 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
283 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
285 * If the cmdmode bits don't match the currently operating mode,
286 * set the cmdmode appropriately and reset the chip.
288 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
289 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
290 sc->tulip_cmdmode |= mi->mi_cmdmode;
293 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
294 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
295 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
296 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
298 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
300 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
301 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
303 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
305 sc->tulip_phyaddr = mi->mi_phyaddr;
306 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
307 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
309 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
312 for (idx = 0; idx < mi->mi_reset_length; idx++) {
314 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
316 sc->tulip_phyaddr = mi->mi_phyaddr;
317 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
319 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
322 if (sc->tulip_flags & TULIP_TRYNWAY) {
323 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
324 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
325 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
326 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
327 sc->tulip_flags &= ~TULIP_DIDNWAY;
328 if (TULIP_IS_MEDIA_FD(media))
329 data |= PHYCTL_FULL_DUPLEX;
330 if (TULIP_IS_MEDIA_100MB(media))
331 data |= PHYCTL_SELECT_100MB;
332 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
339 tulip_softc_t * const sc,
342 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
343 sc->tulip_flags |= TULIP_PRINTLINKUP;
344 sc->tulip_flags |= TULIP_LINKUP;
345 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
346 #if 0 /* XXX how does with work with ifmedia? */
347 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
348 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
349 if (TULIP_CAN_MEDIA_FD(media)
350 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
351 media = TULIP_FD_MEDIA_OF(media);
353 if (TULIP_IS_MEDIA_FD(media)
354 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
355 media = TULIP_HD_MEDIA_OF(media);
359 if (sc->tulip_media != media) {
361 sc->tulip_dbg.dbg_last_media = sc->tulip_media;
363 sc->tulip_media = media;
364 sc->tulip_flags |= TULIP_PRINTMEDIA;
365 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
366 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
367 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
368 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
372 * We could set probe_timeout to 0 but setting to 3000 puts this
373 * in one central place and the only matters is tulip_link is
374 * followed by a tulip_timeout. Therefore setting it should not
375 * result in aberrant behavour.
377 sc->tulip_probe_timeout = 3000;
378 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
379 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
380 if (sc->tulip_flags & TULIP_INRESET) {
381 tulip_media_set(sc, sc->tulip_media);
382 } else if (sc->tulip_probe_media != sc->tulip_media) {
384 * No reason to change media if we have the right media.
393 tulip_softc_t * const sc)
395 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
397 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
398 printf("%s%d: enabling %s port\n",
399 sc->tulip_name, sc->tulip_unit,
400 tulip_mediums[sc->tulip_media]);
401 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
402 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
403 printf("%s%d: link up\n", sc->tulip_name, sc->tulip_unit);
404 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
408 #if defined(TULIP_DO_GPR_SENSE)
410 tulip_21140_gpr_media_sense(
411 tulip_softc_t * const sc)
413 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
414 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
418 * If one of the media blocks contained a default media flag,
421 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
422 const tulip_media_info_t *mi;
424 * Media is not supported (or is full-duplex).
426 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
428 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
432 * Remember the media is this is the "default" media.
434 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
438 * No activity mask? Can't see if it is active if there's no mask.
440 if (mi->mi_actmask == 0)
444 * Does the activity data match?
446 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
449 #if defined(TULIP_DEBUG)
450 printf("%s%d: gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
451 sc->tulip_name, sc->tulip_unit, tulip_mediums[media],
452 TULIP_CSR_READ(sc, csr_gp) & 0xFF,
453 mi->mi_actmask, mi->mi_actdata);
456 * It does! If this is the first media we detected, then
457 * remember this media. If isn't the first, then there were
458 * multiple matches which we equate to no match (since we don't
459 * which to select (if any).
461 if (last_media == TULIP_MEDIA_UNKNOWN) {
463 } else if (last_media != media) {
464 last_media = TULIP_MEDIA_UNKNOWN;
467 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
469 #endif /* TULIP_DO_GPR_SENSE */
471 static tulip_link_status_t
472 tulip_media_link_monitor(
473 tulip_softc_t * const sc)
475 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
476 tulip_link_status_t linkup = TULIP_LINK_DOWN;
479 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
480 panic("tulip_media_link_monitor: %s: botch at line %d\n",
481 tulip_mediums[sc->tulip_media],__LINE__);
483 return TULIP_LINK_UNKNOWN;
488 * Have we seen some packets? If so, the link must be good.
490 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
491 sc->tulip_flags &= ~TULIP_RXACT;
492 sc->tulip_probe_timeout = 3000;
493 return TULIP_LINK_UP;
496 sc->tulip_flags &= ~TULIP_RXACT;
497 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
500 * Read the PHY status register.
502 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
503 if (status & PHYSTS_AUTONEG_DONE) {
505 * If the PHY has completed autonegotiation, see the if the
506 * remote systems abilities have changed. If so, upgrade or
507 * downgrade as appropriate.
509 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
510 abilities = (abilities << 6) & status;
511 if (abilities != sc->tulip_abilities) {
512 #if defined(TULIP_DEBUG)
513 loudprintf("%s%d(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
514 sc->tulip_name, sc->tulip_unit, sc->tulip_phyaddr,
515 sc->tulip_abilities, abilities);
517 if (tulip_mii_map_abilities(sc, abilities)) {
518 tulip_linkup(sc, sc->tulip_probe_media);
519 return TULIP_LINK_UP;
522 * if we had selected media because of autonegotiation,
523 * we need to probe for the new media.
525 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
526 if (sc->tulip_flags & TULIP_DIDNWAY)
527 return TULIP_LINK_DOWN;
531 * The link is now up. If was down, say its back up.
533 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
534 linkup = TULIP_LINK_UP;
535 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
537 * No activity sensor? Assume all's well.
539 if (mi->mi_actmask == 0)
540 return TULIP_LINK_UNKNOWN;
542 * Does the activity data match?
544 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
545 linkup = TULIP_LINK_UP;
546 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
548 * Assume non TP ok for now.
550 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
551 return TULIP_LINK_UNKNOWN;
552 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
553 linkup = TULIP_LINK_UP;
554 #if defined(TULIP_DEBUG)
555 if (sc->tulip_probe_timeout <= 0)
556 printf("%s%d: sia status = 0x%08x\n", sc->tulip_name,
557 sc->tulip_unit, TULIP_CSR_READ(sc, csr_sia_status));
559 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
560 return TULIP_LINK_UNKNOWN;
563 * We will wait for 3 seconds until the link goes into suspect mode.
565 if (sc->tulip_flags & TULIP_LINKUP) {
566 if (linkup == TULIP_LINK_UP)
567 sc->tulip_probe_timeout = 3000;
568 if (sc->tulip_probe_timeout > 0)
569 return TULIP_LINK_UP;
571 sc->tulip_flags &= ~TULIP_LINKUP;
572 printf("%s%d: link down: cable problem?\n", sc->tulip_name, sc->tulip_unit);
574 #if defined(TULIP_DEBUG)
575 sc->tulip_dbg.dbg_link_downed++;
577 return TULIP_LINK_DOWN;
582 tulip_softc_t * const sc,
583 tulip_mediapoll_event_t event)
585 #if defined(TULIP_DEBUG)
586 sc->tulip_dbg.dbg_events[event]++;
588 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
589 && event == TULIP_MEDIAPOLL_TIMER) {
590 switch (tulip_media_link_monitor(sc)) {
591 case TULIP_LINK_DOWN: {
593 * Link Monitor failed. Probe for new media.
595 event = TULIP_MEDIAPOLL_LINKFAIL;
598 case TULIP_LINK_UP: {
605 case TULIP_LINK_UNKNOWN: {
607 * We can't tell so don't bother.
614 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
615 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
616 if (TULIP_DO_AUTOSENSE(sc)) {
617 #if defined(TULIP_DEBUG)
618 sc->tulip_dbg.dbg_link_failures++;
620 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
621 if (sc->tulip_if.if_flags & IFF_UP)
622 tulip_reset(sc); /* restart probe */
626 #if defined(TULIP_DEBUG)
627 sc->tulip_dbg.dbg_link_pollintrs++;
631 if (event == TULIP_MEDIAPOLL_START) {
632 sc->tulip_if.if_flags |= IFF_OACTIVE;
633 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
635 sc->tulip_probe_mediamask = 0;
636 sc->tulip_probe_passes = 0;
637 #if defined(TULIP_DEBUG)
638 sc->tulip_dbg.dbg_media_probes++;
641 * If the SROM contained an explicit media to use, use it.
643 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
644 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
645 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
647 * connidx is defaulted to a media_unknown type.
649 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
650 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
651 tulip_linkup(sc, sc->tulip_probe_media);
656 if (sc->tulip_features & TULIP_HAVE_GPR) {
657 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
658 sc->tulip_probe_timeout = 2000;
660 sc->tulip_probe_media = TULIP_MEDIA_MAX;
661 sc->tulip_probe_timeout = 0;
662 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
667 * Ignore txprobe failures or spurious callbacks.
669 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
670 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
671 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
676 * If we really transmitted a packet, then that's the media we'll use.
678 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
679 if (event == TULIP_MEDIAPOLL_LINKPASS) {
680 /* XXX Check media status just to be sure */
681 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
682 #if defined(TULIP_DEBUG)
684 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
687 tulip_linkup(sc, sc->tulip_probe_media);
692 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
693 #if defined(TULIP_DO_GPR_SENSE)
695 * Check for media via the general purpose register.
697 * Try to sense the media via the GPR. If the same value
698 * occurs 3 times in a row then just use that.
700 if (sc->tulip_probe_timeout > 0) {
701 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
702 #if defined(TULIP_DEBUG)
703 printf("%s%d: media_poll: gpr sensing = %s\n",
704 sc->tulip_name, sc->tulip_unit, tulip_mediums[new_probe_media]);
706 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
707 if (new_probe_media == sc->tulip_probe_media) {
708 if (--sc->tulip_probe_count == 0)
709 tulip_linkup(sc, sc->tulip_probe_media);
711 sc->tulip_probe_count = 10;
714 sc->tulip_probe_media = new_probe_media;
718 #endif /* TULIP_DO_GPR_SENSE */
720 * Brute force. We cycle through each of the media types
721 * and try to transmit a packet.
723 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
724 sc->tulip_probe_media = TULIP_MEDIA_MAX;
725 sc->tulip_probe_timeout = 0;
730 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
731 && (sc->tulip_features & TULIP_HAVE_MII)) {
732 tulip_media_t old_media = sc->tulip_probe_media;
733 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
734 switch (sc->tulip_probe_state) {
735 case TULIP_PROBE_FAILED:
736 case TULIP_PROBE_MEDIATEST: {
738 * Try the next media.
740 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
741 sc->tulip_probe_timeout = 0;
743 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
745 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
747 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
751 case TULIP_PROBE_PHYAUTONEG: {
754 case TULIP_PROBE_INACTIVE: {
756 * Only probe if we autonegotiated a media that hasn't failed.
758 sc->tulip_probe_timeout = 0;
759 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
760 sc->tulip_probe_media = old_media;
763 tulip_linkup(sc, sc->tulip_probe_media);
768 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
769 panic("tulip_media_poll: botch at line %d\n", __LINE__);
776 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
777 #if defined(TULIP_DEBUG)
778 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
780 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
785 * switch to another media if we tried this one enough.
787 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
788 #if defined(TULIP_DEBUG)
789 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
790 printf("%s%d: poll media unknown!\n",
791 sc->tulip_name, sc->tulip_unit);
792 sc->tulip_probe_media = TULIP_MEDIA_MAX;
796 * Find the next media type to check for. Full Duplex
797 * types are not allowed.
800 sc->tulip_probe_media -= 1;
801 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
802 if (++sc->tulip_probe_passes == 3) {
803 printf("%s%d: autosense failed: cable problem?\n",
804 sc->tulip_name, sc->tulip_unit);
805 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
806 sc->tulip_if.if_flags &= ~IFF_RUNNING;
807 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
811 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
812 sc->tulip_probe_mediamask = 0;
813 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
815 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
816 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
817 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
819 #if defined(TULIP_DEBUG)
820 printf("%s%d: %s: probing %s\n", sc->tulip_name, sc->tulip_unit,
821 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
822 tulip_mediums[sc->tulip_probe_media]);
824 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
825 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
826 sc->tulip_probe.probe_txprobes = 0;
828 tulip_media_set(sc, sc->tulip_probe_media);
829 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
834 * If this is hanging off a phy, we know are doing NWAY and we have
835 * forced the phy to a specific speed. Wait for link up before
836 * before sending a packet.
838 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
839 case TULIP_MEDIAINFO_MII: {
840 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
844 case TULIP_MEDIAINFO_SIA: {
845 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
846 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
848 tulip_linkup(sc, sc->tulip_probe_media);
850 if (sc->tulip_features & TULIP_HAVE_MII)
857 case TULIP_MEDIAINFO_RESET:
858 case TULIP_MEDIAINFO_SYM:
859 case TULIP_MEDIAINFO_NONE:
860 case TULIP_MEDIAINFO_GPR: {
865 * Try to send a packet.
872 tulip_softc_t * const sc)
874 if (sc->tulip_features & TULIP_HAVE_GPR) {
875 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
877 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
880 * If this board has no media, just return
882 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
885 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
886 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
887 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
889 tulip_media_set(sc, sc->tulip_media);
894 tulip_21040_mediainfo_init(
895 tulip_softc_t * const sc,
898 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
899 |TULIP_CMD_BACKOFFCTR;
900 sc->tulip_if.if_baudrate = 10000000;
902 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
903 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
904 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
905 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
908 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
909 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
912 if (media == TULIP_MEDIA_UNKNOWN) {
913 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
918 tulip_21040_media_probe(
919 tulip_softc_t * const sc)
921 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
926 tulip_21040_10baset_only_media_probe(
927 tulip_softc_t * const sc)
929 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
930 tulip_media_set(sc, TULIP_MEDIA_10BASET);
931 sc->tulip_media = TULIP_MEDIA_10BASET;
935 tulip_21040_10baset_only_media_select(
936 tulip_softc_t * const sc)
938 sc->tulip_flags |= TULIP_LINKUP;
939 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
940 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
941 sc->tulip_flags &= ~TULIP_SQETEST;
943 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
944 sc->tulip_flags |= TULIP_SQETEST;
946 tulip_media_set(sc, sc->tulip_media);
950 tulip_21040_auibnc_only_media_probe(
951 tulip_softc_t * const sc)
953 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
954 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
955 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
956 sc->tulip_media = TULIP_MEDIA_AUIBNC;
960 tulip_21040_auibnc_only_media_select(
961 tulip_softc_t * const sc)
963 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
964 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
967 static const tulip_boardsw_t tulip_21040_boardsw = {
969 tulip_21040_media_probe,
974 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
976 tulip_21040_10baset_only_media_probe,
977 tulip_21040_10baset_only_media_select,
981 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
983 tulip_21040_auibnc_only_media_probe,
984 tulip_21040_auibnc_only_media_select,
989 tulip_21041_mediainfo_init(
990 tulip_softc_t * const sc)
992 tulip_media_info_t * const mi = sc->tulip_mediainfo;
995 if (sc->tulip_revinfo >= 0x20) {
996 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
997 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
998 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
999 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
1003 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
1004 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
1005 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
1006 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
1010 tulip_21041_media_probe(
1011 tulip_softc_t * const sc)
1013 sc->tulip_if.if_baudrate = 10000000;
1014 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
1015 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
1016 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
1017 tulip_21041_mediainfo_init(sc);
1021 tulip_21041_media_poll(
1022 tulip_softc_t * const sc,
1023 const tulip_mediapoll_event_t event)
1025 u_int32_t sia_status;
1027 #if defined(TULIP_DEBUG)
1028 sc->tulip_dbg.dbg_events[event]++;
1031 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
1032 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
1033 || !TULIP_DO_AUTOSENSE(sc))
1035 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
1036 tulip_reset(sc); /* start probe */
1041 * If we've been been asked to start a poll or link change interrupt
1042 * restart the probe (and reset the tulip to a known state).
1044 if (event == TULIP_MEDIAPOLL_START) {
1045 sc->tulip_if.if_flags |= IFF_OACTIVE;
1046 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
1048 if (sc->tulip_revinfo >= 0x20) {
1049 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
1050 sc->tulip_flags |= TULIP_DIDNWAY;
1053 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1054 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1055 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1056 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
1057 tulip_media_set(sc, TULIP_MEDIA_10BASET);
1062 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1065 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
1066 #if defined(TULIP_DEBUG)
1067 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
1069 tulip_linkup(sc, sc->tulip_probe_media);
1073 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
1074 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
1075 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
1076 if (sc->tulip_revinfo >= 0x20) {
1077 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
1078 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1081 * If the link has passed LinkPass, 10baseT is the
1082 * proper media to use.
1084 tulip_linkup(sc, sc->tulip_probe_media);
1089 * wait for up to 2.4 seconds for the link to reach pass state.
1090 * Only then start scanning the other media for activity.
1091 * choose media with receive activity over those without.
1093 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
1094 if (event != TULIP_MEDIAPOLL_TIMER)
1096 if (sc->tulip_probe_timeout > 0
1097 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
1101 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1102 sc->tulip_flags |= TULIP_WANTRXACT;
1103 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
1104 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1106 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1108 tulip_media_set(sc, sc->tulip_probe_media);
1114 * If we failed, clear the txprobe active flag.
1116 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
1117 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1120 if (event == TULIP_MEDIAPOLL_TIMER) {
1122 * If we've received something, then that's our link!
1124 if (sc->tulip_flags & TULIP_RXACT) {
1125 tulip_linkup(sc, sc->tulip_probe_media);
1129 * if no txprobe active
1131 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
1132 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
1133 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
1134 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1140 * Take 2 passes through before deciding to not
1141 * wait for receive activity. Then take another
1142 * two passes before spitting out a warning.
1144 if (sc->tulip_probe_timeout <= 0) {
1145 if (sc->tulip_flags & TULIP_WANTRXACT) {
1146 sc->tulip_flags &= ~TULIP_WANTRXACT;
1147 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1149 printf("%s%d: autosense failed: cable problem?\n",
1150 sc->tulip_name, sc->tulip_unit);
1151 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1152 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1153 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1161 * Since this media failed to probe, try the other one.
1163 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1164 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1165 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1167 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1169 tulip_media_set(sc, sc->tulip_probe_media);
1170 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1174 static const tulip_boardsw_t tulip_21041_boardsw = {
1175 TULIP_21041_GENERIC,
1176 tulip_21041_media_probe,
1178 tulip_21041_media_poll
1181 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1182 { 0x20005c00, 0, /* 08-00-17 */
1184 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1185 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1187 #if defined(TULIP_DEBUG)
1191 { 0x0281F400, 0, /* 00-A0-7D */
1193 { 0x12, 0x0010, 0x0000 }, /* 10T */
1195 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1196 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1198 #if defined(TULIP_DEBUG)
1203 { 0x0015F420, 0, /* 00-A0-7D */
1205 { 0x12, 0x0010, 0x0000 }, /* 10T */
1207 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1208 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1210 #if defined(TULIP_DEBUG)
1215 { 0x0281F400, 0, /* 00-A0-BE */
1217 { 0x11, 0x8000, 0x0000 }, /* 10T */
1218 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1220 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1222 #if defined(TULIP_DEBUG)
1229 static tulip_media_t
1230 tulip_mii_phy_readspecific(
1231 tulip_softc_t * const sc)
1233 const tulip_phy_attr_t *attr;
1237 static const tulip_media_t table[] = {
1238 TULIP_MEDIA_UNKNOWN,
1239 TULIP_MEDIA_10BASET,
1240 TULIP_MEDIA_100BASETX,
1241 TULIP_MEDIA_100BASET4,
1242 TULIP_MEDIA_UNKNOWN,
1243 TULIP_MEDIA_10BASET_FD,
1244 TULIP_MEDIA_100BASETX_FD,
1249 * Don't read phy specific registers if link is not up.
1251 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1252 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1253 return TULIP_MEDIA_UNKNOWN;
1255 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1256 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1257 for (attr = tulip_mii_phy_attrlist;; attr++) {
1258 if (attr->attr_id == 0)
1259 return TULIP_MEDIA_UNKNOWN;
1260 if ((id & ~0x0F) == attr->attr_id)
1264 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1265 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
1266 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1267 if ((data & pm->pm_mask) == pm->pm_value)
1270 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1271 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
1272 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1273 if ((data & pm->pm_mask) == pm->pm_value)
1276 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1277 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
1278 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1279 if ((data & pm->pm_mask) == pm->pm_value)
1282 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1283 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1284 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1285 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1291 tulip_mii_get_phyaddr(
1292 tulip_softc_t * const sc,
1297 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1298 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1299 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1306 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1307 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1308 return TULIP_MII_NOPHY;
1311 return TULIP_MII_NOPHY;
1315 tulip_mii_map_abilities(
1316 tulip_softc_t * const sc,
1319 sc->tulip_abilities = abilities;
1320 if (abilities & PHYSTS_100BASETX_FD) {
1321 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1322 } else if (abilities & PHYSTS_100BASET4) {
1323 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1324 } else if (abilities & PHYSTS_100BASETX) {
1325 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1326 } else if (abilities & PHYSTS_10BASET_FD) {
1327 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1328 } else if (abilities & PHYSTS_10BASET) {
1329 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1331 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1334 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1339 tulip_mii_autonegotiate(
1340 tulip_softc_t * const sc,
1341 const unsigned phyaddr)
1343 switch (sc->tulip_probe_state) {
1344 case TULIP_PROBE_MEDIATEST:
1345 case TULIP_PROBE_INACTIVE: {
1346 sc->tulip_flags |= TULIP_DIDNWAY;
1347 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1348 sc->tulip_probe_timeout = 3000;
1349 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1350 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1353 case TULIP_PROBE_PHYRESET: {
1355 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1356 if (data & PHYCTL_RESET) {
1357 if (sc->tulip_probe_timeout > 0) {
1361 printf("%s%d(phy%d): error: reset of PHY never completed!\n",
1362 sc->tulip_name, sc->tulip_unit, phyaddr);
1363 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1364 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1365 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1368 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1369 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1370 #if defined(TULIP_DEBUG)
1371 loudprintf("%s%d(phy%d): autonegotiation disabled\n",
1372 sc->tulip_name, sc->tulip_unit, phyaddr);
1374 sc->tulip_flags &= ~TULIP_DIDNWAY;
1375 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1378 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1379 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1380 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1381 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1382 #if defined(TULIP_DEBUG)
1383 if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
1384 loudprintf("%s%d(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
1385 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1387 loudprintf("%s%d(phy%d): autonegotiation restarted: 0x%04x\n",
1388 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1389 sc->tulip_dbg.dbg_nway_starts++;
1391 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1392 sc->tulip_probe_timeout = 3000;
1395 case TULIP_PROBE_PHYAUTONEG: {
1396 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1398 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1399 if (sc->tulip_probe_timeout > 0) {
1403 #if defined(TULIP_DEBUG)
1404 loudprintf("%s%d(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
1405 sc->tulip_name, sc->tulip_unit, phyaddr, status,
1406 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
1408 sc->tulip_flags &= ~TULIP_DIDNWAY;
1409 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1412 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1413 #if defined(TULIP_DEBUG)
1414 loudprintf("%s%d(phy%d): autonegotiation complete: 0x%04x\n",
1415 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1417 data = (data << 6) & status;
1418 if (!tulip_mii_map_abilities(sc, data))
1419 sc->tulip_flags &= ~TULIP_DIDNWAY;
1423 #if defined(DIAGNOSTIC)
1424 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1429 #if defined(TULIP_DEBUG)
1430 loudprintf("%s%d(phy%d): autonegotiation failure: state = %d\n",
1431 sc->tulip_name, sc->tulip_unit, phyaddr, sc->tulip_probe_state);
1432 sc->tulip_dbg.dbg_nway_failures++;
1437 tulip_2114x_media_preset(
1438 tulip_softc_t * const sc)
1440 const tulip_media_info_t *mi = NULL;
1441 tulip_media_t media = sc->tulip_media;
1443 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1444 media = sc->tulip_media;
1446 media = sc->tulip_probe_media;
1448 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1449 sc->tulip_flags &= ~TULIP_SQETEST;
1450 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1451 #if defined(TULIP_DEBUG)
1452 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
1454 mi = sc->tulip_mediums[media];
1455 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1456 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1457 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1458 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1459 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1460 sc->tulip_cmdmode |= mi->mi_cmdmode;
1461 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1462 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1464 #if defined(TULIP_DEBUG)
1466 printf("%s%d: preset: bad media %d!\n",
1467 sc->tulip_name, sc->tulip_unit, media);
1472 case TULIP_MEDIA_BNC:
1473 case TULIP_MEDIA_AUI:
1474 case TULIP_MEDIA_10BASET: {
1475 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1476 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1477 sc->tulip_if.if_baudrate = 10000000;
1478 sc->tulip_flags |= TULIP_SQETEST;
1481 case TULIP_MEDIA_10BASET_FD: {
1482 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1483 sc->tulip_if.if_baudrate = 10000000;
1486 case TULIP_MEDIA_100BASEFX:
1487 case TULIP_MEDIA_100BASET4:
1488 case TULIP_MEDIA_100BASETX: {
1489 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1490 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1491 sc->tulip_if.if_baudrate = 100000000;
1494 case TULIP_MEDIA_100BASEFX_FD:
1495 case TULIP_MEDIA_100BASETX_FD: {
1496 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1497 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1498 sc->tulip_if.if_baudrate = 100000000;
1505 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1509 ********************************************************************
1510 * Start of 21140/21140A support which does not use the MII interface
1514 tulip_null_media_poll(
1515 tulip_softc_t * const sc,
1516 tulip_mediapoll_event_t event)
1518 #if defined(TULIP_DEBUG)
1519 sc->tulip_dbg.dbg_events[event]++;
1521 #if defined(DIAGNOSTIC)
1522 printf("%s%d: botch(media_poll) at line %d\n",
1523 sc->tulip_name, sc->tulip_unit, __LINE__);
1527 __inline__ static void
1528 tulip_21140_mediainit(
1529 tulip_softc_t * const sc,
1530 tulip_media_info_t * const mip,
1531 tulip_media_t const media,
1535 sc->tulip_mediums[media] = mip;
1536 mip->mi_type = TULIP_MEDIAINFO_GPR;
1537 mip->mi_cmdmode = cmdmode;
1538 mip->mi_gpdata = gpdata;
1542 tulip_21140_evalboard_media_probe(
1543 tulip_softc_t * const sc)
1545 tulip_media_info_t *mip = sc->tulip_mediainfo;
1547 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1548 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1549 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1550 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1551 TULIP_CSR_WRITE(sc, csr_command,
1552 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1553 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1554 TULIP_CSR_WRITE(sc, csr_command,
1555 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1557 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1558 sc->tulip_media = TULIP_MEDIA_10BASET;
1560 sc->tulip_media = TULIP_MEDIA_100BASETX;
1562 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1564 TULIP_CMD_TXTHRSHLDCTL);
1565 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1567 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1568 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1570 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1571 |TULIP_CMD_SCRAMBLER);
1572 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1574 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1575 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1578 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1580 tulip_21140_evalboard_media_probe,
1582 tulip_null_media_poll,
1583 tulip_2114x_media_preset,
1587 tulip_21140_accton_media_probe(
1588 tulip_softc_t * const sc)
1590 tulip_media_info_t *mip = sc->tulip_mediainfo;
1593 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1594 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1595 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1596 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1597 TULIP_CSR_WRITE(sc, csr_command,
1598 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1599 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1600 TULIP_CSR_WRITE(sc, csr_command,
1601 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1603 gpdata = TULIP_CSR_READ(sc, csr_gp);
1604 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1605 sc->tulip_media = TULIP_MEDIA_10BASET;
1607 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1608 sc->tulip_media = TULIP_MEDIA_BNC;
1610 sc->tulip_media = TULIP_MEDIA_100BASETX;
1613 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1614 TULIP_GP_EN1207_BNC_INIT,
1615 TULIP_CMD_TXTHRSHLDCTL);
1616 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1617 TULIP_GP_EN1207_UTP_INIT,
1618 TULIP_CMD_TXTHRSHLDCTL);
1619 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1620 TULIP_GP_EN1207_UTP_INIT,
1621 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1622 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1623 TULIP_GP_EN1207_100_INIT,
1624 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1625 |TULIP_CMD_SCRAMBLER);
1626 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1627 TULIP_GP_EN1207_100_INIT,
1628 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1629 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1632 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1634 tulip_21140_accton_media_probe,
1636 tulip_null_media_poll,
1637 tulip_2114x_media_preset,
1641 tulip_21140_smc9332_media_probe(
1642 tulip_softc_t * const sc)
1644 tulip_media_info_t *mip = sc->tulip_mediainfo;
1647 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1648 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1649 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1650 33MHz that comes to two microseconds but wait a
1651 bit longer anyways) */
1652 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1653 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1654 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1655 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1656 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1657 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1659 for (idx = 1000; idx > 0; idx--) {
1660 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1661 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1664 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1671 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1672 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1673 TULIP_GP_SMC_9332_INIT,
1674 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1675 |TULIP_CMD_SCRAMBLER);
1676 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1677 TULIP_GP_SMC_9332_INIT,
1678 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1679 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1680 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1681 TULIP_GP_SMC_9332_INIT,
1682 TULIP_CMD_TXTHRSHLDCTL);
1683 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1684 TULIP_GP_SMC_9332_INIT,
1685 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1688 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1689 TULIP_21140_SMC_9332,
1690 tulip_21140_smc9332_media_probe,
1692 tulip_null_media_poll,
1693 tulip_2114x_media_preset,
1697 tulip_21140_cogent_em100_media_probe(
1698 tulip_softc_t * const sc)
1700 tulip_media_info_t *mip = sc->tulip_mediainfo;
1701 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1703 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1704 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1705 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1706 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1708 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1709 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1710 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1711 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1712 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1714 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1715 TULIP_GP_EM100_INIT,
1716 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1717 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1718 TULIP_GP_EM100_INIT,
1719 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1720 |TULIP_CMD_FULLDUPLEX);
1722 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1723 sc->tulip_media = TULIP_MEDIA_100BASETX;
1724 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1725 TULIP_GP_EM100_INIT,
1726 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1727 |TULIP_CMD_SCRAMBLER);
1728 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1729 TULIP_GP_EM100_INIT,
1730 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1731 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1735 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1736 TULIP_21140_COGENT_EM100,
1737 tulip_21140_cogent_em100_media_probe,
1739 tulip_null_media_poll,
1740 tulip_2114x_media_preset
1744 tulip_21140_znyx_zx34x_media_probe(
1745 tulip_softc_t * const sc)
1747 tulip_media_info_t *mip = sc->tulip_mediainfo;
1748 int cnt10 = 0, cnt100 = 0, idx;
1750 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1751 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1752 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1753 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1754 TULIP_CSR_WRITE(sc, csr_command,
1755 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1756 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1757 TULIP_CSR_WRITE(sc, csr_command,
1758 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1761 for (idx = 1000; idx > 0; idx--) {
1762 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1763 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)) {
1766 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1775 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1776 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1777 TULIP_GP_ZX34X_INIT,
1778 TULIP_CMD_TXTHRSHLDCTL);
1779 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1780 TULIP_GP_ZX34X_INIT,
1781 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1782 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1783 TULIP_GP_ZX34X_INIT,
1784 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1785 |TULIP_CMD_SCRAMBLER);
1786 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1787 TULIP_GP_ZX34X_INIT,
1788 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1789 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1792 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1793 TULIP_21140_ZNYX_ZX34X,
1794 tulip_21140_znyx_zx34x_media_probe,
1796 tulip_null_media_poll,
1797 tulip_2114x_media_preset,
1801 tulip_2114x_media_probe(
1802 tulip_softc_t * const sc)
1804 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
1805 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
1808 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1810 tulip_2114x_media_probe,
1813 tulip_2114x_media_preset,
1817 * ******** END of chip-specific handlers. ***********
1821 * Code the read the SROM and MII bit streams (I2C)
1823 #define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1827 tulip_softc_t * const sc)
1831 csr = SROMSEL ; EMIT;
1832 csr = SROMSEL | SROMRD; EMIT;
1833 csr ^= SROMCS; EMIT;
1834 csr ^= SROMCLKON; EMIT;
1837 * Write 25 cycles of 0 which will force the SROM to be idle.
1839 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1840 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1841 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1843 csr ^= SROMCLKOFF; EMIT;
1844 csr ^= SROMCS; EMIT;
1851 tulip_softc_t * const sc)
1854 const unsigned bitwidth = SROM_BITWIDTH;
1855 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1856 const unsigned msb = 1 << (bitwidth + 3 - 1);
1857 unsigned lastidx = (1 << bitwidth) - 1;
1859 tulip_srom_idle(sc);
1861 for (idx = 0; idx <= lastidx; idx++) {
1862 unsigned lastbit, data, bits, bit, csr;
1863 csr = SROMSEL ; EMIT;
1864 csr = SROMSEL | SROMRD; EMIT;
1865 csr ^= SROMCSON; EMIT;
1866 csr ^= SROMCLKON; EMIT;
1869 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1870 const unsigned thisbit = bits & msb;
1871 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1872 if (thisbit != lastbit) {
1873 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1877 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1880 csr ^= SROMCLKOFF; EMIT;
1882 for (data = 0, bits = 0; bits < 16; bits++) {
1884 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1885 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1886 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1888 sc->tulip_rombuf[idx*2] = data & 0xFF;
1889 sc->tulip_rombuf[idx*2+1] = data >> 8;
1890 csr = SROMSEL | SROMRD; EMIT;
1893 tulip_srom_idle(sc);
1896 #define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1899 tulip_mii_writebits(
1900 tulip_softc_t * const sc,
1904 unsigned msb = 1 << (bits - 1);
1905 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1906 unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
1908 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1910 for (; bits > 0; bits--, data <<= 1) {
1911 const unsigned thisbit = data & msb;
1912 if (thisbit != lastbit) {
1913 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1915 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1917 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1922 tulip_mii_turnaround(
1923 tulip_softc_t * const sc,
1926 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1928 if (cmd == MII_WRCMD) {
1929 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1930 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1931 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1932 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1934 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1936 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1937 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1942 tulip_softc_t * const sc)
1945 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1948 for (idx = 0, data = 0; idx < 16; idx++) {
1949 data <<= 1; /* this is NOOP on the first pass through */
1950 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1951 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1953 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1955 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1962 tulip_softc_t * const sc,
1966 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1969 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1970 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1971 tulip_mii_writebits(sc, MII_RDCMD, 8);
1972 tulip_mii_writebits(sc, devaddr, 5);
1973 tulip_mii_writebits(sc, regno, 5);
1974 tulip_mii_turnaround(sc, MII_RDCMD);
1976 data = tulip_mii_readbits(sc);
1977 #if defined(TULIP_DEBUG)
1978 sc->tulip_dbg.dbg_phyregs[regno][0] = data;
1979 sc->tulip_dbg.dbg_phyregs[regno][1]++;
1986 tulip_softc_t * const sc,
1991 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1992 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1993 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1994 tulip_mii_writebits(sc, MII_WRCMD, 8);
1995 tulip_mii_writebits(sc, devaddr, 5);
1996 tulip_mii_writebits(sc, regno, 5);
1997 tulip_mii_turnaround(sc, MII_WRCMD);
1998 tulip_mii_writebits(sc, data, 16);
1999 #if defined(TULIP_DEBUG)
2000 sc->tulip_dbg.dbg_phyregs[regno][2] = data;
2001 sc->tulip_dbg.dbg_phyregs[regno][3]++;
2005 #define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF)
2006 #define tulip_srom_crcok(databuf) ( \
2007 ((tulip_crc32(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
2008 ((databuf)[126] | ((databuf)[127] << 8)))
2012 const unsigned char *databuf,
2015 u_int idx, crc = 0xFFFFFFFFUL;
2016 static const u_int crctab[] = {
2017 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
2018 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
2019 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
2020 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
2023 for (idx = 0; idx < datalen; idx++) {
2025 crc = (crc >> 4) ^ crctab[crc & 0xf];
2026 crc = (crc >> 4) ^ crctab[crc & 0xf];
2032 tulip_identify_dec_nic(
2033 tulip_softc_t * const sc)
2035 strcpy(sc->tulip_boardid, "DEC ");
2037 if (sc->tulip_chipid <= TULIP_21040)
2039 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
2040 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
2041 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
2042 sc->tulip_boardid[D0+8] = ' ';
2048 tulip_identify_znyx_nic(
2049 tulip_softc_t * const sc)
2052 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
2053 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2055 sc->tulip_boardid[8] = '4';
2056 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
2057 if (znyx_ptr < 26 || znyx_ptr > 116) {
2058 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2061 /* ZX344 = 0010 .. 0013FF
2063 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
2064 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
2065 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
2066 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
2067 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
2068 sc->tulip_boardid[9] = '2';
2069 if (id == TULIP_ZNYX_ID_ZX342B) {
2070 sc->tulip_boardid[10] = 'B';
2071 sc->tulip_boardid[11] = ' ';
2073 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2074 } else if (id == TULIP_ZNYX_ID_ZX344) {
2075 sc->tulip_boardid[10] = '4';
2076 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2077 } else if (id == TULIP_ZNYX_ID_ZX345) {
2078 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
2079 } else if (id == TULIP_ZNYX_ID_ZX346) {
2080 sc->tulip_boardid[9] = '6';
2081 } else if (id == TULIP_ZNYX_ID_ZX351) {
2082 sc->tulip_boardid[8] = '5';
2083 sc->tulip_boardid[9] = '1';
2088 * Assume it's a ZX342...
2090 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2094 sc->tulip_boardid[8] = '1';
2095 if (sc->tulip_chipid == TULIP_21041) {
2096 sc->tulip_boardid[10] = '1';
2099 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
2100 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
2101 if (id == TULIP_ZNYX_ID_ZX312T) {
2102 sc->tulip_boardid[9] = '2';
2103 sc->tulip_boardid[10] = 'T';
2104 sc->tulip_boardid[11] = ' ';
2105 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2106 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
2107 sc->tulip_boardid[9] = '4';
2108 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2109 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2110 } else if (id == TULIP_ZNYX_ID_ZX314) {
2111 sc->tulip_boardid[9] = '4';
2112 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2113 sc->tulip_features |= TULIP_HAVE_BASEROM;
2114 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
2115 sc->tulip_boardid[9] = '5';
2116 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2117 } else if (id == TULIP_ZNYX_ID_ZX315) {
2118 sc->tulip_boardid[9] = '5';
2119 sc->tulip_features |= TULIP_HAVE_BASEROM;
2125 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
2126 sc->tulip_boardid[9] = '4';
2127 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2128 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2129 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
2130 sc->tulip_boardid[9] = '5';
2131 sc->tulip_boardsw = &tulip_21040_boardsw;
2132 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2133 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
2134 sc->tulip_boardid[9] = '2';
2135 sc->tulip_boardsw = &tulip_21040_boardsw;
2141 tulip_identify_smc_nic(
2142 tulip_softc_t * const sc)
2144 u_int32_t id1, id2, ei;
2145 int auibnc = 0, utp = 0;
2148 strcpy(sc->tulip_boardid, "SMC ");
2149 if (sc->tulip_chipid == TULIP_21041)
2151 if (sc->tulip_chipid != TULIP_21040) {
2152 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2153 strcpy(&sc->tulip_boardid[4], "9332DST ");
2154 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
2155 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
2156 strcpy(&sc->tulip_boardid[4], "9334BDT ");
2158 strcpy(&sc->tulip_boardid[4], "9332BDT ");
2162 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
2163 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
2164 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
2166 strcpy(&sc->tulip_boardid[4], "8432");
2167 cp = &sc->tulip_boardid[8];
2169 *cp++ = 'B', auibnc = 1;
2170 if ((id1 & 0xFF) > 0x32)
2171 *cp++ = 'T', utp = 1;
2172 if ((id1 & 0x4000) == 0)
2173 *cp++ = 'A', auibnc = 1;
2175 sc->tulip_boardid[7] = '4';
2179 *cp++ = (ei ? '2' : '1');
2184 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2185 else if (!utp && auibnc)
2186 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
2190 tulip_identify_cogent_nic(
2191 tulip_softc_t * const sc)
2193 strcpy(sc->tulip_boardid, "Cogent ");
2194 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2195 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
2196 strcat(sc->tulip_boardid, "EM100TX ");
2197 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2198 #if defined(TULIP_COGENT_EM110TX_ID)
2199 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
2200 strcat(sc->tulip_boardid, "EM110TX ");
2201 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2203 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
2204 strcat(sc->tulip_boardid, "EM100FX ");
2205 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2208 * Magic number (0x24001109U) is the SubVendor (0x2400) and
2209 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
2211 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
2212 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
2214 * Cogent (Adaptec) is still mapping all INTs to INTA of
2215 * first 21140. Dumb! Dumb!
2217 strcat(sc->tulip_boardid, "EM440TX ");
2218 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2220 } else if (sc->tulip_chipid == TULIP_21040) {
2221 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2226 tulip_identify_accton_nic(
2227 tulip_softc_t * const sc)
2229 strcpy(sc->tulip_boardid, "ACCTON ");
2230 switch (sc->tulip_chipid) {
2232 strcat(sc->tulip_boardid, "EN1207 ");
2233 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2234 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
2237 strcat(sc->tulip_boardid, "EN1207TX ");
2238 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2239 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2242 strcat(sc->tulip_boardid, "EN1203 ");
2243 sc->tulip_boardsw = &tulip_21040_boardsw;
2246 strcat(sc->tulip_boardid, "EN1203 ");
2247 sc->tulip_boardsw = &tulip_21041_boardsw;
2250 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2256 tulip_identify_asante_nic(
2257 tulip_softc_t * const sc)
2259 strcpy(sc->tulip_boardid, "Asante ");
2260 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2261 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2262 tulip_media_info_t *mi = sc->tulip_mediainfo;
2265 * The Asante Fast Ethernet doesn't always ship with a valid
2266 * new format SROM. So if isn't in the new format, we cheat
2267 * set it up as if we had.
2270 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2271 sc->tulip_gpdata = 0;
2273 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2274 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2276 TULIP_CSR_WRITE(sc, csr_gp, 0);
2278 mi->mi_type = TULIP_MEDIAINFO_MII;
2279 mi->mi_gpr_length = 0;
2280 mi->mi_gpr_offset = 0;
2281 mi->mi_reset_length = 0;
2282 mi->mi_reset_offset = 0;;
2284 mi->mi_phyaddr = TULIP_MII_NOPHY;
2285 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2287 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2289 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2290 printf("%s%d: can't find phy 0\n", sc->tulip_name, sc->tulip_unit);
2294 sc->tulip_features |= TULIP_HAVE_MII;
2295 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2296 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2297 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2298 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2299 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2300 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2301 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2302 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2303 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2304 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2305 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2307 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2312 tulip_identify_compex_nic(
2313 tulip_softc_t * const sc)
2315 strcpy(sc->tulip_boardid, "COMPEX ");
2316 if (sc->tulip_chipid == TULIP_21140A) {
2318 tulip_softc_t *root_sc = NULL;
2320 strcat(sc->tulip_boardid, "400TX/PCI ");
2322 * All 4 chips on these boards share an interrupt. This code
2323 * copied from tulip_read_macaddr.
2325 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2326 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2327 root_sc = tulips[root_unit];
2329 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2334 && root_sc->tulip_chipid == sc->tulip_chipid
2335 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2336 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2337 sc->tulip_slaves = root_sc->tulip_slaves;
2338 root_sc->tulip_slaves = sc;
2339 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2340 printf("\nCannot find master device for de%d interrupts",
2344 strcat(sc->tulip_boardid, "unknown ");
2346 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2352 tulip_softc_t * const sc)
2354 unsigned idx1, idx2, idx3;
2356 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2357 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2358 tulip_srom_media_t srom_media;
2359 tulip_media_info_t *mi = sc->tulip_mediainfo;
2361 u_int32_t leaf_offset, blocks, data;
2363 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2364 if (shp->sh_adapter_count == 1)
2366 if (saip->sai_device == sc->tulip_pci_devno)
2370 * Didn't find the right media block for this card.
2372 if (idx1 == shp->sh_adapter_count)
2376 * Save the hardware address.
2378 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2380 * If this is a multiple port card, add the adapter index to the last
2381 * byte of the hardware address. (if it isn't multiport, adding 0
2384 sc->tulip_enaddr[5] += idx1;
2386 leaf_offset = saip->sai_leaf_offset_lowbyte
2387 + saip->sai_leaf_offset_highbyte * 256;
2388 dp = sc->tulip_rombuf + leaf_offset;
2390 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2392 for (idx2 = 0;; idx2++) {
2393 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2394 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2397 sc->tulip_connidx = idx2;
2399 if (sc->tulip_chipid == TULIP_21041) {
2401 for (idx2 = 0; idx2 < blocks; idx2++) {
2402 tulip_media_t media;
2404 srom_media = (tulip_srom_media_t) (data & 0x3F);
2405 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2406 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2409 media = tulip_srom_mediums[idx3].sm_type;
2410 if (media != TULIP_MEDIA_UNKNOWN) {
2411 if (data & TULIP_SROM_21041_EXTENDED) {
2412 mi->mi_type = TULIP_MEDIAINFO_SIA;
2413 sc->tulip_mediums[media] = mi;
2414 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2415 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2416 mi->mi_sia_general = dp[4] + dp[5] * 256;
2420 case TULIP_MEDIA_BNC: {
2421 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2425 case TULIP_MEDIA_AUI: {
2426 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2430 case TULIP_MEDIA_10BASET: {
2431 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2435 case TULIP_MEDIA_10BASET_FD: {
2436 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2446 if (data & TULIP_SROM_21041_EXTENDED)
2451 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2452 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2453 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2454 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2458 unsigned length, type;
2459 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2460 if (sc->tulip_features & TULIP_HAVE_GPR)
2461 sc->tulip_gpinit = *dp++;
2463 for (idx2 = 0; idx2 < blocks; idx2++) {
2465 if ((*dp & 0x80) == 0) {
2469 length = (*dp++ & 0x7f) - 1;
2470 type = *dp++ & 0x3f;
2473 switch (type & 0x3f) {
2474 case 0: { /* 21140[A] GPR block */
2475 tulip_media_t media;
2476 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2477 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2478 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2481 media = tulip_srom_mediums[idx3].sm_type;
2482 if (media == TULIP_MEDIA_UNKNOWN)
2484 mi->mi_type = TULIP_MEDIAINFO_GPR;
2485 sc->tulip_mediums[media] = mi;
2486 mi->mi_gpdata = dp[1];
2487 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2488 sc->tulip_gpdata = mi->mi_gpdata;
2491 data = dp[2] + dp[3] * 256;
2492 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2493 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2497 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2499 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2500 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2505 case 1: { /* 21140[A] MII block */
2506 const unsigned phyno = *dp++;
2507 mi->mi_type = TULIP_MEDIAINFO_MII;
2508 mi->mi_gpr_length = *dp++;
2509 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2510 dp += mi->mi_gpr_length;
2511 mi->mi_reset_length = *dp++;
2512 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2513 dp += mi->mi_reset_length;
2516 * Before we probe for a PHY, use the GPR information
2517 * to select it. If we don't, it may be inaccessible.
2519 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2520 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2522 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2524 sc->tulip_phyaddr = mi->mi_phyaddr;
2525 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2527 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2531 * At least write something!
2533 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2534 TULIP_CSR_WRITE(sc, csr_gp, 0);
2536 mi->mi_phyaddr = TULIP_MII_NOPHY;
2537 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2539 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2541 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2542 #if defined(TULIP_DEBUG)
2543 printf("%s%d: can't find phy %d\n",
2544 sc->tulip_name, sc->tulip_unit, phyno);
2548 sc->tulip_features |= TULIP_HAVE_MII;
2549 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2550 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2551 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2552 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2553 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2554 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2555 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2556 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2557 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2558 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2559 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2563 case 2: { /* 2114[23] SIA block */
2564 tulip_media_t media;
2565 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2566 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2567 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2570 media = tulip_srom_mediums[idx3].sm_type;
2571 if (media == TULIP_MEDIA_UNKNOWN)
2573 mi->mi_type = TULIP_MEDIAINFO_SIA;
2574 sc->tulip_mediums[media] = mi;
2576 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2577 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2578 mi->mi_sia_general = dp[5] + dp[6] * 256;
2582 case TULIP_MEDIA_BNC: {
2583 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2586 case TULIP_MEDIA_AUI: {
2587 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2590 case TULIP_MEDIA_10BASET: {
2591 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2592 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2595 case TULIP_MEDIA_10BASET_FD: {
2596 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2597 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2605 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2606 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2611 case 3: { /* 2114[23] MII PHY block */
2612 const unsigned phyno = *dp++;
2613 const u_int8_t *dp0;
2614 mi->mi_type = TULIP_MEDIAINFO_MII;
2615 mi->mi_gpr_length = *dp++;
2616 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2617 dp += 2 * mi->mi_gpr_length;
2618 mi->mi_reset_length = *dp++;
2619 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2620 dp += 2 * mi->mi_reset_length;
2622 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2623 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2625 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2627 sc->tulip_phyaddr = mi->mi_phyaddr;
2628 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2629 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2631 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2634 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2635 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2637 mi->mi_phyaddr = TULIP_MII_NOPHY;
2638 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2640 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2642 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2643 #if defined(TULIP_DEBUG)
2644 printf("%s%d: can't find phy %d\n",
2645 sc->tulip_name, sc->tulip_unit, phyno);
2649 sc->tulip_features |= TULIP_HAVE_MII;
2650 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2651 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2652 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2653 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2654 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2655 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2656 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2657 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2658 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2659 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2660 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2661 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2665 case 4: { /* 21143 SYM block */
2666 tulip_media_t media;
2667 srom_media = (tulip_srom_media_t) dp[0];
2668 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2669 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2672 media = tulip_srom_mediums[idx3].sm_type;
2673 if (media == TULIP_MEDIA_UNKNOWN)
2675 mi->mi_type = TULIP_MEDIAINFO_SYM;
2676 sc->tulip_mediums[media] = mi;
2677 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2678 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2679 data = dp[5] + dp[6] * 256;
2680 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2681 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2684 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2685 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2686 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2688 if (TULIP_IS_MEDIA_TP(media))
2689 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2694 case 5: { /* 21143 Reset block */
2695 mi->mi_type = TULIP_MEDIAINFO_RESET;
2696 mi->mi_reset_length = *dp++;
2697 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2698 dp += 2 * mi->mi_reset_length;
2709 return mi - sc->tulip_mediainfo;
2712 static const struct {
2713 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2714 unsigned char vendor_oui[3];
2715 } tulip_vendors[] = {
2716 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2717 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2718 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2719 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2720 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2721 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2722 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2723 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2724 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2725 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2730 * This deals with the vagaries of the address roms and the
2731 * brain-deadness that various vendors commit in using them.
2735 tulip_softc_t * const sc)
2737 unsigned cksum, rom_cksum, idx;
2739 unsigned char tmpbuf[8];
2740 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2742 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2744 if (sc->tulip_chipid == TULIP_21040) {
2745 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2746 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2748 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2750 sc->tulip_rombuf[idx] = csr & 0xFF;
2752 sc->tulip_boardsw = &tulip_21040_boardsw;
2754 if (sc->tulip_chipid == TULIP_21041) {
2756 * Thankfully all 21041's act the same.
2758 sc->tulip_boardsw = &tulip_21041_boardsw;
2761 * Assume all 21140 board are compatible with the
2762 * DEC 10/100 evaluation board. Not really valid but
2763 * it's the best we can do until every one switches to
2764 * the new SROM format.
2767 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2769 tulip_srom_read(sc);
2770 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2772 * SROM CRC is valid therefore it must be in the
2775 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2776 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2778 * No checksum is present. See if the SROM id checks out;
2779 * the first 18 bytes should be 0 followed by a 1 followed
2780 * by the number of adapters (which we don't deal with yet).
2782 for (idx = 0; idx < 18; idx++) {
2783 if (sc->tulip_rombuf[idx] != 0)
2786 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2787 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2788 } else if (sc->tulip_chipid >= TULIP_21142) {
2789 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2790 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2792 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2793 if (sc->tulip_chipid != TULIP_21041)
2794 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2797 * If the SROM specifies more than one adapter, tag this as a
2800 if (sc->tulip_rombuf[19] > 1)
2801 sc->tulip_features |= TULIP_HAVE_BASEROM;
2802 if (sc->tulip_boardsw == NULL)
2809 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2811 * Some folks don't use the standard ethernet rom format
2812 * but instead just put the address in the first 6 bytes
2813 * of the rom and let the rest be all 0xffs. (Can we say
2814 * ZNYX?) (well sometimes they put in a checksum so we'll
2817 for (idx = 8; idx < 32; idx++) {
2818 if (sc->tulip_rombuf[idx] != 0xFF)
2822 * Make sure the address is not multicast or locally assigned
2823 * that the OUI is not 00-00-00.
2825 if ((sc->tulip_rombuf[0] & 3) != 0)
2827 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2828 && sc->tulip_rombuf[2] == 0)
2830 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2831 sc->tulip_features |= TULIP_HAVE_OKROM;
2835 * A number of makers of multiport boards (ZNYX and Cogent)
2836 * only put on one address ROM on their 21040 boards. So
2837 * if the ROM is all zeros (or all 0xFFs), look at the
2838 * previous configured boards (as long as they are on the same
2839 * PCI bus and the bus number is non-zero) until we find the
2840 * master board with address ROM. We then use its address ROM
2841 * as the base for this board. (we add our relative board
2842 * to the last byte of its address).
2844 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2845 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2848 if (idx == sizeof(sc->tulip_rombuf)) {
2850 tulip_softc_t *root_sc = NULL;
2851 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2852 root_sc = tulips[root_unit];
2853 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2857 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2858 && root_sc->tulip_chipid == sc->tulip_chipid
2859 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2860 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2861 sc->tulip_boardsw = root_sc->tulip_boardsw;
2862 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2863 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2864 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2865 sizeof(sc->tulip_rombuf));
2866 if (!tulip_srom_decode(sc))
2869 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2870 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2873 * Now for a truly disgusting kludge: all 4 21040s on
2874 * the ZX314 share the same INTA line so the mapping
2875 * setup by the BIOS on the PCI bridge is worthless.
2876 * Rather than reprogramming the value in the config
2877 * register, we will handle this internally.
2879 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2880 sc->tulip_slaves = root_sc->tulip_slaves;
2881 root_sc->tulip_slaves = sc;
2882 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2890 * This is the standard DEC address ROM test.
2893 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2896 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2897 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2898 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2899 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2900 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2903 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2905 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2907 if (cksum > 65535) cksum -= 65535;
2908 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2909 if (cksum > 65535) cksum -= 65535;
2911 if (cksum > 65535) cksum -= 65535;
2912 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2913 if (cksum >= 65535) cksum -= 65535;
2915 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2917 if (cksum != rom_cksum)
2922 * Check for various boards based on OUI. Did I say braindead?
2924 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2925 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2926 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2931 sc->tulip_features |= TULIP_HAVE_OKROM;
2937 tulip_softc_t * const sc)
2939 tulip_media_t media;
2942 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2943 if (sc->tulip_mediums[media] != NULL) {
2944 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2950 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2951 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2952 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2953 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2954 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2955 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2957 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2958 sc->tulip_flags |= TULIP_PRINTMEDIA;
2959 tulip_linkup(sc, sc->tulip_media);
2964 tulip_ifmedia_change(
2965 struct ifnet * const ifp)
2967 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
2969 sc->tulip_flags |= TULIP_NEEDRESET;
2970 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2971 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2972 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2973 tulip_media_t media;
2974 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2975 if (sc->tulip_mediums[media] != NULL
2976 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2977 sc->tulip_flags |= TULIP_PRINTMEDIA;
2978 sc->tulip_flags &= ~TULIP_DIDNWAY;
2979 tulip_linkup(sc, media);
2984 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2991 * Media status callback
2994 tulip_ifmedia_status(
2995 struct ifnet * const ifp,
2996 struct ifmediareq *req)
2998 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
3000 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
3003 req->ifm_status = IFM_AVALID;
3004 if (sc->tulip_flags & TULIP_LINKUP)
3005 req->ifm_status |= IFM_ACTIVE;
3007 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
3012 tulip_softc_t * const sc)
3014 struct ifmultiaddr *ifma;
3018 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
3019 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
3020 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3021 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3022 #if defined(IFF_ALLMULTI)
3023 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
3024 sc->tulip_flags |= TULIP_ALLMULTI ;
3028 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3029 ifma = ifma->ifma_link.le_next) {
3031 if (ifma->ifma_addr->sa_family == AF_LINK)
3035 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
3036 if (multicnt > 14) {
3037 u_int32_t *sp = sc->tulip_setupdata;
3040 * Some early passes of the 21140 have broken implementations of
3041 * hash-perfect mode. When we get too many multicasts for perfect
3042 * filtering with these chips, we need to switch into hash-only
3043 * mode (this is better than all-multicast on network with lots
3044 * of multicast traffic).
3046 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
3047 sc->tulip_flags |= TULIP_WANTHASHONLY;
3049 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
3051 * If we have more than 14 multicasts, we have
3052 * go into hash perfect mode (512 bit multicast
3053 * hash and one perfect hardware).
3055 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
3057 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3058 ifma = ifma->ifma_link.le_next) {
3060 if (ifma->ifma_addr->sa_family != AF_LINK)
3063 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
3064 #if BYTE_ORDER == BIG_ENDIAN
3065 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3067 sp[hash >> 4] |= 1 << (hash & 0xF);
3071 * No reason to use a hash if we are going to be
3072 * receiving every multicast.
3074 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3075 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
3076 #if BYTE_ORDER == BIG_ENDIAN
3077 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3079 sp[hash >> 4] |= 1 << (hash & 0xF);
3081 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
3082 hash = tulip_mchash(sc->tulip_enaddr);
3083 #if BYTE_ORDER == BIG_ENDIAN
3084 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3086 sp[hash >> 4] |= 1 << (hash & 0xF);
3089 #if BYTE_ORDER == BIG_ENDIAN
3090 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3091 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3092 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3094 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
3095 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
3096 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
3101 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
3102 u_int32_t *sp = sc->tulip_setupdata;
3104 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3106 * Else can get perfect filtering for 16 addresses.
3108 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3109 ifma = ifma->ifma_link.le_next) {
3110 if (ifma->ifma_addr->sa_family != AF_LINK)
3112 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3113 #if BYTE_ORDER == BIG_ENDIAN
3114 *sp++ = ((u_int16_t *) addrp)[0] << 16;
3115 *sp++ = ((u_int16_t *) addrp)[1] << 16;
3116 *sp++ = ((u_int16_t *) addrp)[2] << 16;
3118 *sp++ = ((u_int16_t *) addrp)[0];
3119 *sp++ = ((u_int16_t *) addrp)[1];
3120 *sp++ = ((u_int16_t *) addrp)[2];
3125 * Add the broadcast address.
3128 #if BYTE_ORDER == BIG_ENDIAN
3129 *sp++ = 0xFFFF << 16;
3130 *sp++ = 0xFFFF << 16;
3131 *sp++ = 0xFFFF << 16;
3139 * Pad the rest with our hardware address
3141 for (; idx < 16; idx++) {
3142 #if BYTE_ORDER == BIG_ENDIAN
3143 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3144 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3145 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3147 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
3148 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
3149 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
3153 #if defined(IFF_ALLMULTI)
3154 if (sc->tulip_flags & TULIP_ALLMULTI)
3155 sc->tulip_if.if_flags |= IFF_ALLMULTI;
3161 tulip_softc_t * const sc)
3163 tulip_ringinfo_t *ri;
3165 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
3168 * Brilliant. Simply brilliant. When switching modes/speeds
3169 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
3170 * bits in CSR6 and then do a software reset to get the 21140
3171 * to properly reset its internal pathways to the right places.
3174 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
3175 && sc->tulip_boardsw->bd_media_preset != NULL)
3176 (*sc->tulip_boardsw->bd_media_preset)(sc);
3178 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3179 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3180 33MHz that comes to two microseconds but wait a
3181 bit longer anyways) */
3184 sc->tulip_flags |= TULIP_INRESET;
3185 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
3186 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3187 sc->tulip_if.if_start = tulip_ifstart;
3190 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3191 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr);
3193 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
3195 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3196 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr);
3198 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
3200 TULIP_CSR_WRITE(sc, csr_busmode,
3201 (1 << (3 /*pci_max_burst_len*/ + 8))
3202 |TULIP_BUSMODE_CACHE_ALIGN8
3203 |TULIP_BUSMODE_READMULTIPLE
3204 |(BYTE_ORDER != LITTLE_ENDIAN ?
3205 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
3207 sc->tulip_txtimer = 0;
3208 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
3210 * Free all the mbufs that were on the transmit ring.
3213 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3217 IF_DEQUEUE(&sc->tulip_txq, m);
3220 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3221 map = M_GETCTX(m, bus_dmamap_t);
3222 bus_dmamap_unload(sc->tulip_dmatag, map);
3223 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3228 ri = &sc->tulip_txinfo;
3229 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3230 ri->ri_free = ri->ri_max;
3231 for (di = ri->ri_first; di < ri->ri_last; di++)
3233 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3234 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap,
3235 0, sc->tulip_txdescmap->dm_mapsize,
3236 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3240 * We need to collect all the mbufs were on the
3241 * receive ring before we reinit it either to put
3242 * them back on or to know if we have to allocate
3245 ri = &sc->tulip_rxinfo;
3246 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3247 ri->ri_free = ri->ri_max;
3248 for (di = ri->ri_first; di < ri->ri_last; di++) {
3250 di->d_length1 = 0; di->d_addr1 = 0;
3251 di->d_length2 = 0; di->d_addr2 = 0;
3253 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3254 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap,
3255 0, sc->tulip_rxdescmap->dm_mapsize,
3256 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3259 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3263 IF_DEQUEUE(&sc->tulip_rxq, m);
3266 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3267 map = M_GETCTX(m, bus_dmamap_t);
3268 bus_dmamap_unload(sc->tulip_dmatag, map);
3269 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3275 * If tulip_reset is being called recurisvely, exit quickly knowing
3276 * that when the outer tulip_reset returns all the right stuff will
3282 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
3283 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
3284 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
3285 |TULIP_STS_RXSTOPPED;
3287 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
3288 (*sc->tulip_boardsw->bd_media_select)(sc);
3289 #if defined(TULIP_DEBUG)
3290 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
3291 printf("%s%d: tulip_reset: additional reset needed?!?\n",
3292 sc->tulip_name, sc->tulip_unit);
3294 tulip_media_print(sc);
3295 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
3296 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
3298 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
3300 tulip_addr_filter(sc);
3305 tulip_softc_t * const sc)
3307 if (sc->tulip_if.if_flags & IFF_UP) {
3308 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
3309 /* initialize the media */
3312 sc->tulip_if.if_flags |= IFF_RUNNING;
3313 if (sc->tulip_if.if_flags & IFF_PROMISC) {
3314 sc->tulip_flags |= TULIP_PROMISC;
3315 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3316 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3318 sc->tulip_flags &= ~TULIP_PROMISC;
3319 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3320 if (sc->tulip_flags & TULIP_ALLMULTI) {
3321 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3323 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3326 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3327 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3329 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3330 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3332 sc->tulip_if.if_flags |= IFF_OACTIVE;
3333 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3334 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3336 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3337 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3338 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3339 tulip_txput_setup(sc);
3341 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3348 tulip_softc_t * const sc)
3350 TULIP_PERFSTART(rxintr)
3351 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
3352 struct ifnet * const ifp = &sc->tulip_if;
3354 #if defined(TULIP_DEBUG)
3359 TULIP_PERFSTART(rxget)
3360 struct ether_header eh;
3361 tulip_desc_t *eop = ri->ri_nextin;
3362 int total_len = 0, last_offset = 0;
3363 struct mbuf *ms = NULL, *me = NULL;
3365 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3370 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3373 #if defined(TULIP_DEBUG)
3374 if (cnt == ri->ri_max)
3378 * If the TULIP has no descriptors, there can't be any receive
3379 * descriptors to process.
3381 if (eop == ri->ri_nextout)
3385 * 90% of the packets will fit in one descriptor. So we optimize
3388 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3389 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3390 IF_DEQUEUE(&sc->tulip_rxq, ms);
3394 * If still owned by the TULIP, don't touch it.
3396 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3400 * It is possible (though improbable unless the BIG_PACKET support
3401 * is enabled or MCLBYTES < 1518) for a received packet to cross
3402 * more than one receive descriptor.
3404 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3405 if (++eop == ri->ri_last)
3407 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3408 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3409 #if defined(TULIP_DEBUG)
3410 sc->tulip_dbg.dbg_rxintrs++;
3411 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3413 TULIP_PERFEND(rxget);
3414 TULIP_PERFEND(rxintr);
3421 * Dequeue the first buffer for the start of the packet. Hopefully
3422 * this will be the only one we need to dequeue. However, if the
3423 * packet consumed multiple descriptors, then we need to dequeue
3424 * those buffers and chain to the starting mbuf. All buffers but
3425 * the last buffer have the same length so we can set that now.
3426 * (we add to last_offset instead of multiplying since we normally
3427 * won't go into the loop and thereby saving a ourselves from
3428 * doing a multiplication by 0 in the normal case).
3430 IF_DEQUEUE(&sc->tulip_rxq, ms);
3431 for (me = ms; total_len > 0; total_len--) {
3432 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3433 map = M_GETCTX(me, bus_dmamap_t);
3434 TULIP_RXMAP_POSTSYNC(sc, map);
3435 bus_dmamap_unload(sc->tulip_dmatag, map);
3436 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3437 #if defined(DIAGNOSTIC)
3440 #endif /* TULIP_BUS_DMA */
3441 me->m_len = TULIP_RX_BUFLEN;
3442 last_offset += TULIP_RX_BUFLEN;
3443 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3449 * Now get the size of received packet (minus the CRC).
3451 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3452 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3453 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3455 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3456 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3457 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3458 TULIP_DSTS_RxOVERFLOW)) == 0)
3461 me->m_len = total_len - last_offset;
3463 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3464 map = M_GETCTX(me, bus_dmamap_t);
3465 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len,
3466 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
3467 bus_dmamap_unload(sc->tulip_dmatag, map);
3468 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3469 #if defined(DIAGNOSTIC)
3472 #endif /* TULIP_BUS_DMA */
3474 eh = *mtod(ms, struct ether_header *);
3475 #if !defined(__DragonFly__) && !defined(__FreeBSD__)
3476 if (sc->tulip_if.if_bpf != NULL) {
3478 bpf_tap(&sc->tulip_if, mtod(ms, caddr_t), total_len);
3480 bpf_mtap(&sc->tulip_if, ms);
3483 sc->tulip_flags |= TULIP_RXACT;
3487 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3488 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3490 #if defined(TULIP_VERBOSE)
3491 const char *error = NULL;
3493 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3494 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3495 #if defined(TULIP_VERBOSE)
3496 error = "frame too long";
3499 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3500 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3501 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3502 #if defined(TULIP_VERBOSE)
3503 error = "alignment error";
3506 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3507 #if defined(TULIP_VERBOSE)
3512 #if defined(TULIP_VERBOSE)
3513 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
3514 printf("%s%d: receive: %6D: %s\n",
3515 sc->tulip_name, sc->tulip_unit,
3516 mtod(ms, u_char *) + 6, ":",
3518 sc->tulip_flags |= TULIP_NOMESSAGES;
3523 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3524 map = M_GETCTX(me, bus_dmamap_t);
3525 bus_dmamap_unload(sc->tulip_dmatag, map);
3526 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3527 #if defined(DIAGNOSTIC)
3530 #endif /* TULIP_BUS_DMA */
3532 #if defined(TULIP_DEBUG)
3536 if (++eop == ri->ri_last)
3538 ri->ri_nextin = eop;
3541 * Either we are priming the TULIP with mbufs (m == NULL)
3542 * or we are about to accept an mbuf for the upper layers
3543 * so we need to allocate an mbuf to replace it. If we
3544 * can't replace it, send up it anyways. This may cause
3545 * us to drop packets in the future but that's better than
3546 * being caught in livelock.
3548 * Note that if this packet crossed multiple descriptors
3549 * we don't even try to reallocate all the mbufs here.
3550 * Instead we rely on the test of the beginning of
3551 * the loop to refill for the extra consumed mbufs.
3553 if (accept || ms == NULL) {
3555 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
3557 #if defined(TULIP_COPY_RXDATA)
3558 if (!accept || total_len >= (MHLEN - 2)) {
3560 MCLGET(m0, MB_DONTWAIT);
3561 if ((m0->m_flags & M_EXT) == 0) {
3565 #if defined(TULIP_COPY_RXDATA)
3570 #if defined(TULIP_COPY_RXDATA)
3574 #if !defined(TULIP_COPY_RXDATA)
3575 ms->m_pkthdr.len = total_len;
3576 ms->m_pkthdr.rcvif = ifp;
3577 m_adj(ms, sizeof(struct ether_header));
3578 ether_input(ifp, &eh, ms);
3581 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3583 m0->m_data += 2; /* align data after header */
3584 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3585 m0->m_len = m0->m_pkthdr.len = total_len;
3586 m0->m_pkthdr.rcvif = ifp;
3587 m_adj(m0, sizeof(struct ether_header));
3588 ether_input(ifp, &eh, m0);
3590 #endif /* ! TULIP_COPY_RXDATA */
3596 * Couldn't allocate a new buffer. Don't bother
3597 * trying to replenish the receive queue.
3600 sc->tulip_flags |= TULIP_RXBUFSLOW;
3601 #if defined(TULIP_DEBUG)
3602 sc->tulip_dbg.dbg_rxlowbufs++;
3604 TULIP_PERFEND(rxget);
3608 * Now give the buffer(s) to the TULIP and save in our
3612 tulip_desc_t * const nextout = ri->ri_nextout;
3613 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3614 if (sc->tulip_rxmaps_free > 0) {
3615 map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free];
3618 sc->tulip_flags |= TULIP_RXBUFSLOW;
3619 #if defined(TULIP_DEBUG)
3620 sc->tulip_dbg.dbg_rxlowbufs++;
3625 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *),
3626 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT);
3628 printf("%s%d: unable to load rx map, "
3629 "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
3630 panic("tulip_rx_intr"); /* XXX */
3632 nextout->d_addr1 = map->dm_segs[0].ds_addr;
3633 nextout->d_length1 = map->dm_segs[0].ds_len;
3634 if (map->dm_nsegs == 2) {
3635 nextout->d_addr2 = map->dm_segs[1].ds_addr;
3636 nextout->d_length2 = map->dm_segs[1].ds_len;
3638 nextout->d_addr2 = 0;
3639 nextout->d_length2 = 0;
3641 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout));
3642 #else /* TULIP_BUS_DMA */
3643 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3644 nextout->d_length1 = TULIP_RX_BUFLEN;
3645 #endif /* TULIP_BUS_DMA */
3646 nextout->d_status = TULIP_DSTS_OWNER;
3647 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3648 if (++ri->ri_nextout == ri->ri_last)
3649 ri->ri_nextout = ri->ri_first;
3652 IF_ENQUEUE(&sc->tulip_rxq, ms);
3653 } while ((ms = me) != NULL);
3655 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3656 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3657 TULIP_PERFEND(rxget);
3660 #if defined(TULIP_DEBUG)
3661 sc->tulip_dbg.dbg_rxintrs++;
3662 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3664 TULIP_PERFEND(rxintr);
3669 tulip_softc_t * const sc)
3671 TULIP_PERFSTART(txintr)
3672 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3677 while (ri->ri_free < ri->ri_max) {
3680 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3681 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3686 d_flag = ri->ri_nextin->d_flag;
3687 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3688 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3690 * We've just finished processing a setup packet.
3691 * Mark that we finished it. If there's not
3692 * another pending, startup the TULIP receiver.
3693 * Make sure we ack the RXSTOPPED so we won't get
3694 * an abormal interrupt indication.
3696 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3697 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3698 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3699 sc->tulip_flags |= TULIP_HASHONLY;
3700 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3702 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3703 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3704 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3705 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3706 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3709 const u_int32_t d_status = ri->ri_nextin->d_status;
3710 IF_DEQUEUE(&sc->tulip_txq, m);
3712 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3713 bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t);
3714 TULIP_TXMAP_POSTSYNC(sc, map);
3715 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3716 #endif /* TULIP_BUS_DMA */
3718 #if defined(TULIP_DEBUG)
3720 printf("%s%d: tx_intr: failed to dequeue mbuf?!?\n",
3721 sc->tulip_name, sc->tulip_unit);
3724 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3725 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3726 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3727 #if defined(TULIP_DEBUG)
3728 if (d_status & TULIP_DSTS_TxNOCARR)
3729 sc->tulip_dbg.dbg_txprobe_nocarr++;
3730 if (d_status & TULIP_DSTS_TxEXCCOLL)
3731 sc->tulip_dbg.dbg_txprobe_exccoll++;
3733 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3735 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3737 * Escape from the loop before media poll has reset the TULIP!
3742 if (d_status & TULIP_DSTS_ERRSUM) {
3743 sc->tulip_if.if_oerrors++;
3744 if (d_status & TULIP_DSTS_TxEXCCOLL)
3745 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3746 if (d_status & TULIP_DSTS_TxLATECOLL)
3747 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3748 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3749 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3750 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3751 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3752 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3753 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3754 if (d_status & TULIP_DSTS_TxBABBLE)
3755 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3757 u_int32_t collisions =
3758 (d_status & TULIP_DSTS_TxCOLLMASK)
3759 >> TULIP_DSTS_V_TxCOLLCNT;
3760 sc->tulip_if.if_collisions += collisions;
3761 if (collisions == 1)
3762 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3763 else if (collisions > 1)
3764 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3765 else if (d_status & TULIP_DSTS_TxDEFERRED)
3766 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3768 * SQE is only valid for 10baseT/BNC/AUI when not
3769 * running in full-duplex. In order to speed up the
3770 * test, the corresponding bit in tulip_flags needs to
3771 * set as well to get us to count SQE Test Errors.
3773 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3774 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3780 if (++ri->ri_nextin == ri->ri_last)
3781 ri->ri_nextin = ri->ri_first;
3783 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3784 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3787 * If nothing left to transmit, disable the timer.
3788 * Else if progress, reset the timer back to 2 ticks.
3790 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3791 sc->tulip_txtimer = 0;
3793 sc->tulip_txtimer = TULIP_TXTIMER;
3794 sc->tulip_if.if_opackets += xmits;
3795 TULIP_PERFEND(txintr);
3800 tulip_print_abnormal_interrupt(
3801 tulip_softc_t * const sc,
3804 const char * const *msgp = tulip_status_bits;
3807 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3809 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3810 printf("%s%d: abnormal interrupt:", sc->tulip_name, sc->tulip_unit);
3811 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3812 if ((csr & mask) && *msgp != NULL) {
3813 printf("%s%s", sep, *msgp);
3814 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3815 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3816 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3817 printf(" (switching to store-and-forward mode)");
3819 printf(" (raising TX threshold to %s)",
3820 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3831 tulip_softc_t * const sc,
3834 TULIP_PERFSTART(intr)
3837 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3839 TULIP_CSR_WRITE(sc, csr_status, csr);
3841 if (csr & TULIP_STS_SYSERROR) {
3842 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3843 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3844 sc->tulip_flags |= TULIP_SYSTEMERROR;
3846 printf("%s%d: system error: %s\n",
3847 sc->tulip_name, sc->tulip_unit,
3848 tulip_system_errors[sc->tulip_last_system_error]);
3850 sc->tulip_flags |= TULIP_NEEDRESET;
3851 sc->tulip_system_errors++;
3854 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3855 #if defined(TULIP_DEBUG)
3856 sc->tulip_dbg.dbg_link_intrs++;
3858 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3859 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3860 ? TULIP_MEDIAPOLL_LINKFAIL
3861 : TULIP_MEDIAPOLL_LINKPASS);
3862 csr &= ~TULIP_STS_ABNRMLINTR;
3864 tulip_media_print(sc);
3866 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3867 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3868 if (csr & TULIP_STS_RXNOBUF)
3869 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3871 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3872 * on receive overflows.
3874 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3875 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3877 * Stop the receiver process and spin until it's stopped.
3878 * Tell rx_intr to drop the packets it dequeues.
3880 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3881 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3883 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3884 sc->tulip_flags |= TULIP_RXIGNORE;
3887 if (sc->tulip_flags & TULIP_RXIGNORE) {
3889 * Restart the receiver.
3891 sc->tulip_flags &= ~TULIP_RXIGNORE;
3892 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3895 if (csr & TULIP_STS_ABNRMLINTR) {
3896 u_int32_t tmp = csr & sc->tulip_intrmask
3897 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3898 if (csr & TULIP_STS_TXUNDERFLOW) {
3899 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3900 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3901 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3902 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3903 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3904 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3907 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3908 sc->tulip_statusbits |= tmp;
3910 tulip_print_abnormal_interrupt(sc, tmp);
3911 sc->tulip_flags |= TULIP_NOMESSAGES;
3913 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3915 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3917 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3918 tulip_ifstart(&sc->tulip_if);
3921 if (sc->tulip_flags & TULIP_NEEDRESET) {
3925 TULIP_PERFEND(intr);
3928 #if defined(TULIP_USE_SOFTINTR)
3930 * This is a experimental idea to alleviate problems due to interrupt
3931 * livelock. What is interrupt livelock? It's when you spend all your
3932 * time servicing device interrupts and never drop below device ipl
3933 * to do "useful" work.
3935 * So what we do here is see if the device needs service and if so,
3936 * disable interrupts (dismiss the interrupt), place it in a list of devices
3937 * needing service, and issue a network software interrupt.
3939 * When our network software interrupt routine gets called, we simply
3940 * walk done the list of devices that we have created and deal with them
3941 * at splnet/splsoftnet.
3945 tulip_hardintr_handler(
3946 tulip_softc_t * const sc,
3949 if (TULIP_CSR_READ(sc, csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR) == 0)
3953 * disable interrupts
3955 TULIP_CSR_WRITE(sc, csr_intr, 0);
3957 * mark it as needing a software interrupt
3959 tulip_softintr_mask |= (1U << sc->tulip_unit);
3966 u_int32_t softintr_mask, mask;
3972 * Copy mask to local copy and reset global one to 0.
3975 softintr_mask = tulip_softintr_mask;
3976 tulip_softintr_mask = 0;
3980 * Optimize for the single unit case.
3982 if (tulip_softintr_max_unit == 0) {
3983 if (softintr_mask & 1) {
3984 tulip_softc_t * const sc = tulips[0];
3986 * Handle the "interrupt" and then reenable interrupts
3989 tulip_intr_handler(sc, &progress);
3990 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3996 * Handle all "queued" interrupts in a round robin fashion.
3997 * This is done so as not to favor a particular interface.
3999 unit = tulip_softintr_last_unit;
4000 mask = (1U << unit);
4001 while (softintr_mask != 0) {
4002 if (tulip_softintr_max_unit == unit) {
4005 unit += 1; mask <<= 1;
4007 if (softintr_mask & mask) {
4008 tulip_softc_t * const sc = tulips[unit];
4010 * Handle the "interrupt" and then reenable interrupts
4012 softintr_mask ^= mask;
4013 tulip_intr_handler(sc, &progress);
4014 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4019 * Save where we ending up.
4021 tulip_softintr_last_unit = unit;
4023 #endif /* TULIP_USE_SOFTINTR */
4029 tulip_softc_t * sc = arg;
4032 for (; sc != NULL; sc = sc->tulip_slaves) {
4033 #if defined(TULIP_DEBUG)
4034 sc->tulip_dbg.dbg_intrs++;
4036 #if defined(TULIP_USE_SOFTINTR)
4037 tulip_hardintr_handler(sc, &progress);
4039 tulip_intr_handler(sc, &progress);
4042 #if defined(TULIP_USE_SOFTINTR)
4044 schednetisr(NETISR_DE);
4052 tulip_softc_t * sc = (tulip_softc_t *) arg;
4055 #if defined(TULIP_DEBUG)
4056 sc->tulip_dbg.dbg_intrs++;
4058 #if defined(TULIP_USE_SOFTINTR)
4059 tulip_hardintr_handler(sc, &progress);
4061 schednetisr(NETISR_DE);
4063 tulip_intr_handler(sc, &progress);
4067 static struct mbuf *
4068 tulip_mbuf_compress(
4072 #if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET)
4073 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
4075 if (m->m_pkthdr.len > MHLEN) {
4076 MCLGET(m0, MB_DONTWAIT);
4077 if ((m0->m_flags & M_EXT) == 0) {
4083 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
4084 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
4088 int len = m->m_pkthdr.len;
4089 struct mbuf **mp = &m0;
4092 if (mlen == MHLEN) {
4093 MGETHDR(*mp, MB_DONTWAIT, MT_DATA);
4095 MGET(*mp, MB_DONTWAIT, MT_DATA);
4103 MCLGET(*mp, MB_DONTWAIT);
4104 if (((*mp)->m_flags & M_EXT) == 0) {
4109 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
4111 (*mp)->m_len = len <= mlen ? len : mlen;
4113 m_copydata(m, m->m_pkthdr.len - len,
4114 (*mp)->m_len, mtod((*mp), caddr_t));
4115 len -= (*mp)->m_len;
4116 mp = &(*mp)->m_next;
4124 static struct mbuf *
4126 tulip_softc_t * const sc,
4129 TULIP_PERFSTART(txput)
4130 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4131 tulip_desc_t *eop, *nextout;
4134 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4141 #if defined(TULIP_DEBUG)
4142 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4143 printf("%s%d: txput%s: tx not running\n",
4144 sc->tulip_name, sc->tulip_unit,
4145 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
4146 sc->tulip_flags |= TULIP_WANTTXSTART;
4147 sc->tulip_dbg.dbg_txput_finishes[0]++;
4153 * Now we try to fill in our transmit descriptors. This is
4154 * a bit reminiscent of going on the Ark two by two
4155 * since each descriptor for the TULIP can describe
4156 * two buffers. So we advance through packet filling
4157 * each of the two entries at a time to to fill each
4158 * descriptor. Clear the first and last segment bits
4159 * in each descriptor (actually just clear everything
4160 * but the end-of-ring or chain bits) to make sure
4161 * we don't get messed up by previously sent packets.
4163 * We may fail to put the entire packet on the ring if
4164 * there is either not enough ring entries free or if the
4165 * packet has more than MAX_TXSEG segments. In the former
4166 * case we will just wait for the ring to empty. In the
4167 * latter case we have to recopy.
4169 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4174 eop = nextout = ri->ri_nextout;
4178 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4180 * Reclaim some dma maps from if we are out.
4182 if (sc->tulip_txmaps_free == 0) {
4183 #if defined(TULIP_DEBUG)
4184 sc->tulip_dbg.dbg_no_txmaps++;
4186 free += tulip_tx_intr(sc);
4188 if (sc->tulip_txmaps_free > 0) {
4189 map = sc->tulip_txmaps[sc->tulip_txmaps_free-1];
4191 sc->tulip_flags |= TULIP_WANTTXSTART;
4192 #if defined(TULIP_DEBUG)
4193 sc->tulip_dbg.dbg_txput_finishes[1]++;
4197 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4199 if (error == EFBIG) {
4201 * The packet exceeds the number of transmit buffer
4202 * entries that we can use for one packet, so we have
4203 * to recopy it into one mbuf and then try again.
4205 m = tulip_mbuf_compress(m);
4207 #if defined(TULIP_DEBUG)
4208 sc->tulip_dbg.dbg_txput_finishes[2]++;
4212 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4215 printf("%s%d: unable to load tx map, "
4216 "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
4217 #if defined(TULIP_DEBUG)
4218 sc->tulip_dbg.dbg_txput_finishes[3]++;
4223 if ((free -= (map->dm_nsegs + 1) / 2) <= 0
4225 * See if there's any unclaimed space in the transmit ring.
4227 && (free += tulip_tx_intr(sc)) <= 0) {
4229 * There's no more room but since nothing
4230 * has been committed at this point, just
4231 * show output is active, put back the
4234 sc->tulip_flags |= TULIP_WANTTXSTART;
4235 #if defined(TULIP_DEBUG)
4236 sc->tulip_dbg.dbg_txput_finishes[4]++;
4238 bus_dmamap_unload(sc->tulip_dmatag, map);
4241 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) {
4243 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4244 eop->d_status = d_status;
4245 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4246 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4247 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr;
4248 eop->d_length2 = map->dm_segs[segcnt+1].ds_len;
4249 d_status = TULIP_DSTS_OWNER;
4250 if (++nextout == ri->ri_last)
4251 nextout = ri->ri_first;
4253 if (segcnt < map->dm_nsegs) {
4255 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4256 eop->d_status = d_status;
4257 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4258 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4261 if (++nextout == ri->ri_last)
4262 nextout = ri->ri_first;
4264 TULIP_TXMAP_PRESYNC(sc, map);
4267 --sc->tulip_txmaps_free; /* commit to using the dmamap */
4269 #else /* !TULIP_BUS_DMA */
4272 int len = m0->m_len;
4273 caddr_t addr = mtod(m0, caddr_t);
4274 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
4277 unsigned slen = min(len, clsize);
4281 slen = 2040, partial = 1;
4284 if (segcnt > TULIP_MAX_TXSEG) {
4286 * The packet exceeds the number of transmit buffer
4287 * entries that we can use for one packet, so we have
4288 * recopy it into one mbuf and then try again.
4290 m = tulip_mbuf_compress(m);
4298 * See if there's any unclaimed space in the
4301 if ((free += tulip_tx_intr(sc)) == 0) {
4303 * There's no more room but since nothing
4304 * has been committed at this point, just
4305 * show output is active, put back the
4308 sc->tulip_flags |= TULIP_WANTTXSTART;
4309 #if defined(TULIP_DEBUG)
4310 sc->tulip_dbg.dbg_txput_finishes[1]++;
4316 if (++nextout == ri->ri_last)
4317 nextout = ri->ri_first;
4318 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4319 eop->d_status = d_status;
4320 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
4321 eop->d_length1 = slen;
4324 * Fill in second half of descriptor
4326 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
4327 eop->d_length2 = slen;
4329 d_status = TULIP_DSTS_OWNER;
4338 } while ((m0 = m0->m_next) != NULL);
4339 #endif /* TULIP_BUS_DMA */
4342 * bounce a copy to the bpf listener, if any.
4344 if (sc->tulip_if.if_bpf != NULL)
4345 bpf_mtap(&sc->tulip_if, m);
4348 * The descriptors have been filled in. Now get ready
4351 IF_ENQUEUE(&sc->tulip_txq, m);
4355 * Make sure the next descriptor after this packet is owned
4356 * by us since it may have been set up above if we ran out
4357 * of room in the ring.
4359 nextout->d_status = 0;
4360 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4362 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4364 * If we only used the first segment of the last descriptor,
4365 * make sure the second segment will not be used.
4371 #endif /* TULIP_BUS_DMA */
4374 * Mark the last and first segments, indicate we want a transmit
4375 * complete interrupt, and tell it to transmit!
4377 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
4380 * Note that ri->ri_nextout is still the start of the packet
4381 * and until we set the OWNER bit, we can still back out of
4382 * everything we have done.
4384 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
4385 #if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX)
4386 if (eop < ri->ri_nextout) {
4387 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4388 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout);
4389 TULIP_TXDESC_PRESYNC(sc, ri->ri_first,
4390 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first);
4392 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4393 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout);
4396 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
4397 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4400 * This advances the ring for us.
4402 ri->ri_nextout = nextout;
4405 TULIP_PERFEND(txput);
4407 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
4408 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4409 sc->tulip_if.if_flags |= IFF_OACTIVE;
4410 sc->tulip_if.if_start = tulip_ifstart;
4411 TULIP_PERFEND(txput);
4416 * switch back to the single queueing ifstart.
4418 sc->tulip_flags &= ~TULIP_WANTTXSTART;
4419 if (sc->tulip_txtimer == 0)
4420 sc->tulip_txtimer = TULIP_TXTIMER;
4421 #if defined(TULIP_DEBUG)
4422 sc->tulip_dbg.dbg_txput_finishes[5]++;
4426 * If we want a txstart, there must be not enough space in the
4427 * transmit ring. So we want to enable transmit done interrupts
4428 * so we can immediately reclaim some space. When the transmit
4429 * interrupt is posted, the interrupt handler will call tx_intr
4430 * to reclaim space and then txstart (since WANTTXSTART is set).
4431 * txstart will move the packet into the transmit ring and clear
4432 * WANTTXSTART thereby causing TXINTR to be cleared.
4435 #if defined(TULIP_DEBUG)
4436 sc->tulip_dbg.dbg_txput_finishes[6]++;
4438 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
4439 sc->tulip_if.if_flags |= IFF_OACTIVE;
4440 sc->tulip_if.if_start = tulip_ifstart;
4441 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4442 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4443 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4445 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
4446 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
4447 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
4448 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4451 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4452 TULIP_PERFEND(txput);
4458 tulip_softc_t * const sc)
4460 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4461 tulip_desc_t *nextout;
4464 * We will transmit, at most, one setup packet per call to ifstart.
4467 #if defined(TULIP_DEBUG)
4468 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4469 printf("%s%d: txput_setup: tx not running\n",
4470 sc->tulip_name, sc->tulip_unit);
4471 sc->tulip_flags |= TULIP_WANTTXSTART;
4472 sc->tulip_if.if_start = tulip_ifstart;
4477 * Try to reclaim some free descriptors..
4479 if (ri->ri_free < 2)
4481 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
4482 sc->tulip_flags |= TULIP_WANTTXSTART;
4483 sc->tulip_if.if_start = tulip_ifstart;
4486 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
4487 sizeof(sc->tulip_setupbuf));
4489 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
4490 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
4492 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
4494 nextout = ri->ri_nextout;
4495 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4496 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
4497 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
4498 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
4499 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
4500 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
4501 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
4503 nextout->d_length2 = 0;
4504 nextout->d_addr2 = 0;
4505 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4506 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len;
4507 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr;
4508 if (sc->tulip_setupmap->dm_nsegs == 2) {
4509 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len;
4510 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr;
4512 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap);
4513 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout));
4515 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
4516 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
4520 * Advance the ring for the next transmit packet.
4522 if (++ri->ri_nextout == ri->ri_last)
4523 ri->ri_nextout = ri->ri_first;
4526 * Make sure the next descriptor is owned by us since it
4527 * may have been set up above if we ran out of room in the
4530 ri->ri_nextout->d_status = 0;
4531 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4532 nextout->d_status = TULIP_DSTS_OWNER;
4534 * Flush the ownwership of the current descriptor
4536 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4537 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4538 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4539 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4540 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4546 * This routine is entered at splnet() (splsoftnet() on NetBSD)
4547 * and thereby imposes no problems when TULIP_USE_SOFTINTR is
4557 TULIP_PERFSTART(ifioctl)
4558 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4559 struct ifaddr *ifa = (struct ifaddr *)data;
4560 struct ifreq *ifr = (struct ifreq *) data;
4564 #if defined(TULIP_USE_SOFTINTR)
4571 ifp->if_flags |= IFF_UP;
4572 switch(ifa->ifa_addr->sa_family) {
4576 arp_ifinit(&(sc)->tulip_ac.ac_if, ifa);
4583 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
4584 if (ipx_nullhost(*ina)) {
4585 ina->x_host = *(union ipx_host *)(sc->tulip_enaddr);
4587 ifp->if_flags &= ~IFF_RUNNING;
4588 bcopy((caddr_t)ina->x_host.c_host,
4589 (caddr_t)sc->tulip_enaddr,
4590 sizeof(sc->tulip_enaddr));
4599 * This magic copied from if_is.c; I don't use XNS,
4600 * so I have no way of telling if this actually
4604 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
4605 if (ns_nullhost(*ina)) {
4606 ina->x_host = *(union ns_host *)(sc->tulip_enaddr);
4608 ifp->if_flags &= ~IFF_RUNNING;
4609 bcopy((caddr_t)ina->x_host.c_host,
4610 (caddr_t)sc->tulip_enaddr,
4611 sizeof(sc->tulip_enaddr));
4626 bcopy((caddr_t) sc->tulip_enaddr,
4627 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
4632 case SIOCSIFFLAGS: {
4633 tulip_addr_filter(sc); /* reinit multicast filter */
4639 case SIOCGIFMEDIA: {
4640 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
4645 case SIOCDELMULTI: {
4647 * Update multicast listeners
4649 tulip_addr_filter(sc); /* reset multicast filtering */
4657 * Set the interface MTU.
4659 if (ifr->ifr_mtu > ETHERMTU
4661 && sc->tulip_chipid != TULIP_21140
4662 && sc->tulip_chipid != TULIP_21140A
4663 && sc->tulip_chipid != TULIP_21041
4669 ifp->if_mtu = ifr->ifr_mtu;
4677 case SIOCGADDRROM: {
4678 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
4684 ifr->ifr_metric = (int) sc->tulip_chipid;
4695 TULIP_PERFEND(ifioctl);
4700 * These routines gets called at device spl (from ether_output). This might
4701 * pose a problem for TULIP_USE_SOFTINTR if ether_output is called at
4702 * device spl from another driver.
4707 struct ifnet * const ifp)
4709 TULIP_PERFSTART(ifstart)
4710 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4712 if (sc->tulip_if.if_flags & IFF_RUNNING) {
4714 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
4715 tulip_txput_setup(sc);
4717 while (sc->tulip_if.if_snd.ifq_head != NULL) {
4719 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
4720 if ((m = tulip_txput(sc, m)) != NULL) {
4721 IF_PREPEND(&sc->tulip_if.if_snd, m);
4725 if (sc->tulip_if.if_snd.ifq_head == NULL)
4726 sc->tulip_if.if_start = tulip_ifstart_one;
4729 TULIP_PERFEND(ifstart);
4734 struct ifnet * const ifp)
4736 TULIP_PERFSTART(ifstart_one)
4737 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4739 if ((sc->tulip_if.if_flags & IFF_RUNNING)
4740 && sc->tulip_if.if_snd.ifq_head != NULL) {
4742 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
4743 if ((m = tulip_txput(sc, m)) != NULL)
4744 IF_PREPEND(&sc->tulip_if.if_snd, m);
4746 TULIP_PERFEND(ifstart_one);
4750 * Even though this routine runs at device spl, it does not break
4751 * our use of splnet (splsoftnet under NetBSD) for the majority
4752 * of this driver (if TULIP_USE_SOFTINTR defined) since
4753 * if_watcbog is called from if_watchdog which is called from
4754 * splsoftclock which is below spl[soft]net.
4760 TULIP_PERFSTART(ifwatchdog)
4761 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4763 #if defined(TULIP_DEBUG)
4764 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
4765 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
4766 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
4767 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
4768 #endif /* TULIP_DEBUG */
4770 sc->tulip_if.if_timer = 1;
4772 * These should be rare so do a bulk test up front so we can just skip
4775 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
4777 * If the number of receive buffer is low, try to refill
4779 if (sc->tulip_flags & TULIP_RXBUFSLOW)
4782 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
4783 printf("%s%d: %d system errors: last was %s\n",
4784 sc->tulip_name, sc->tulip_unit, sc->tulip_system_errors,
4785 tulip_system_errors[sc->tulip_last_system_error]);
4787 if (sc->tulip_statusbits) {
4788 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
4789 sc->tulip_statusbits = 0;
4792 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
4795 if (sc->tulip_txtimer)
4797 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
4798 printf("%s%d: transmission timeout\n", sc->tulip_name, sc->tulip_unit);
4799 if (TULIP_DO_AUTOSENSE(sc)) {
4800 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4801 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
4802 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
4808 TULIP_PERFEND(ifwatchdog);
4809 TULIP_PERFMERGE(sc, perf_intr_cycles);
4810 TULIP_PERFMERGE(sc, perf_ifstart_cycles);
4811 TULIP_PERFMERGE(sc, perf_ifioctl_cycles);
4812 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles);
4813 TULIP_PERFMERGE(sc, perf_timeout_cycles);
4814 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles);
4815 TULIP_PERFMERGE(sc, perf_txput_cycles);
4816 TULIP_PERFMERGE(sc, perf_txintr_cycles);
4817 TULIP_PERFMERGE(sc, perf_rxintr_cycles);
4818 TULIP_PERFMERGE(sc, perf_rxget_cycles);
4819 TULIP_PERFMERGE(sc, perf_intr);
4820 TULIP_PERFMERGE(sc, perf_ifstart);
4821 TULIP_PERFMERGE(sc, perf_ifioctl);
4822 TULIP_PERFMERGE(sc, perf_ifwatchdog);
4823 TULIP_PERFMERGE(sc, perf_timeout);
4824 TULIP_PERFMERGE(sc, perf_ifstart_one);
4825 TULIP_PERFMERGE(sc, perf_txput);
4826 TULIP_PERFMERGE(sc, perf_txintr);
4827 TULIP_PERFMERGE(sc, perf_rxintr);
4828 TULIP_PERFMERGE(sc, perf_rxget);
4832 * All printf's are real as of now!
4840 tulip_softc_t * const sc)
4842 struct ifnet * const ifp = &sc->tulip_if;
4844 callout_init(&sc->tulip_timer);
4845 callout_init(&sc->tulip_fast_timer);
4847 if_initname(ifp, sc->tulip_name, sc->tulip_unit);
4848 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
4849 ifp->if_ioctl = tulip_ifioctl;
4850 ifp->if_start = tulip_ifstart;
4851 ifp->if_watchdog = tulip_ifwatchdog;
4854 printf("%s%d: %s%s pass %d.%d%s\n",
4855 sc->tulip_name, sc->tulip_unit,
4857 tulip_chipdescs[sc->tulip_chipid],
4858 (sc->tulip_revinfo & 0xF0) >> 4,
4859 sc->tulip_revinfo & 0x0F,
4860 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
4861 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
4863 #if defined(__alpha__)
4865 * In case the SRM console told us about a bogus media,
4866 * we need to check to be safe.
4868 if (sc->tulip_mediums[sc->tulip_media] == NULL)
4869 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4872 (*sc->tulip_boardsw->bd_media_probe)(sc);
4873 ifmedia_init(&sc->tulip_ifmedia, 0,
4874 tulip_ifmedia_change,
4875 tulip_ifmedia_status);
4876 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
4877 tulip_ifmedia_add(sc);
4881 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr);
4882 ifp->if_snd.ifq_maxlen = ifqmaxlen;
4885 #if defined(TULIP_BUS_DMA)
4886 #if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX)
4888 tulip_busdma_allocmem(
4889 tulip_softc_t * const sc,
4891 bus_dmamap_t *map_p,
4892 tulip_desc_t **desc_p)
4894 bus_dma_segment_t segs[1];
4896 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE,
4897 segs, sizeof(segs)/sizeof(segs[0]),
4898 &nsegs, BUS_DMA_NOWAIT);
4901 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size,
4902 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
4905 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0,
4906 BUS_DMA_NOWAIT, &map);
4908 error = bus_dmamap_load(sc->tulip_dmatag, map, desc,
4909 size, NULL, BUS_DMA_NOWAIT);
4911 bus_dmamap_destroy(sc->tulip_dmatag, map);
4916 bus_dmamem_unmap(sc->tulip_dmatag, desc, size);
4919 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs);
4929 tulip_softc_t * const sc)
4933 #if !defined(TULIP_BUS_DMA_NOTX)
4935 * Allocate dmamap for setup descriptor
4937 error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2,
4938 sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT,
4939 &sc->tulip_setupmap);
4941 error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap,
4942 sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf),
4943 NULL, BUS_DMA_NOWAIT);
4945 bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap);
4948 * Allocate space and dmamap for transmit ring
4951 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS,
4952 &sc->tulip_txdescmap,
4953 &sc->tulip_txdescs);
4957 * Allocate dmamaps for each transmit descriptors
4960 while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) {
4962 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0)
4963 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
4966 while (sc->tulip_txmaps_free > 0)
4967 bus_dmamap_destroy(sc->tulip_dmatag,
4968 sc->tulip_txmaps[--sc->tulip_txmaps_free]);
4973 sc->tulip_txdescs = malloc(TULIP_TXDESCS * sizeof(tulip_desc_t),
4974 M_DEVBUF, M_INTWAIT);
4977 #if !defined(TULIP_BUS_DMA_NORX)
4979 * Allocate space and dmamap for receive ring
4982 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS,
4983 &sc->tulip_rxdescmap,
4984 &sc->tulip_rxdescs);
4988 * Allocate dmamaps for each receive descriptors
4991 while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) {
4993 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0)
4994 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
4997 while (sc->tulip_rxmaps_free > 0)
4998 bus_dmamap_destroy(sc->tulip_dmatag,
4999 sc->tulip_rxmaps[--sc->tulip_rxmaps_free]);
5004 sc->tulip_rxdescs = malloc(TULIP_RXDESCS * sizeof(tulip_desc_t),
5005 M_DEVBUF, M_INTWAIT);
5010 #endif /* TULIP_BUS_DMA */
5014 tulip_softc_t * const sc,
5015 tulip_csrptr_t csr_base,
5018 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
5019 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
5020 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
5021 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
5022 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
5023 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
5024 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
5025 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
5026 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
5027 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
5028 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
5029 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
5030 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
5031 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
5032 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
5033 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
5038 tulip_softc_t * const sc,
5039 tulip_ringinfo_t * const ri,
5040 tulip_desc_t *descs,
5043 ri->ri_max = ndescs;
5044 ri->ri_first = descs;
5045 ri->ri_last = ri->ri_first + ri->ri_max;
5046 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
5047 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
5051 * This is the PCI configuration support.
5054 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
5055 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
5056 #define PCI_CFDA 0x40 /* Configuration Driver Area */
5059 tulip_pci_probe(device_t dev)
5061 const char *name = NULL;
5063 if (pci_get_vendor(dev) != DEC_VENDORID)
5067 * Some LanMedia WAN cards use the Tulip chip, but they have
5068 * their own driver, and we should not recognize them
5070 if (pci_get_subvendor(dev) == 0x1376)
5073 switch (pci_get_device(dev)) {
5075 name = "Digital 21040 Ethernet";
5078 name = "Digital 21041 Ethernet";
5081 if (pci_get_revid(dev) >= 0x20)
5082 name = "Digital 21140A Fast Ethernet";
5084 name = "Digital 21140 Fast Ethernet";
5087 if (pci_get_revid(dev) >= 0x20)
5088 name = "Digital 21143 Fast Ethernet";
5090 name = "Digital 21142 Fast Ethernet";
5094 device_set_desc(dev, name);
5101 tulip_shutdown(device_t dev)
5103 tulip_softc_t * const sc = device_get_softc(dev);
5104 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
5105 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
5106 33MHz that comes to two microseconds but wait a
5107 bit longer anyways) */
5112 tulip_pci_attach(device_t dev)
5115 #if defined(__alpha__)
5116 tulip_media_t media = TULIP_MEDIA_UNKNOWN;
5119 u_int32_t revinfo, cfdainfo, cfcsinfo;
5120 unsigned csroffset = TULIP_PCI_CSROFFSET;
5121 unsigned csrsize = TULIP_PCI_CSRSIZE;
5122 tulip_csrptr_t csr_base;
5123 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
5124 struct resource *res;
5127 unit = device_get_unit(dev);
5129 if (unit >= TULIP_MAX_DEVICES) {
5130 printf("de%d", unit);
5131 printf(": not configured; limit of %d reached or exceeded\n",
5136 revinfo = pci_get_revid(dev);
5137 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
5138 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
5140 /* turn busmaster on in case BIOS doesn't set it */
5141 if(!(cfcsinfo & PCIM_CMD_BUSMASTEREN)) {
5142 cfcsinfo |= PCIM_CMD_BUSMASTEREN;
5143 pci_write_config(dev, PCIR_COMMAND, cfcsinfo, 4);
5146 if (pci_get_vendor(dev) == DEC_VENDORID) {
5147 if (pci_get_device(dev) == CHIPID_21040)
5148 chipid = TULIP_21040;
5149 else if (pci_get_device(dev) == CHIPID_21041)
5150 chipid = TULIP_21041;
5151 else if (pci_get_device(dev) == CHIPID_21140)
5152 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
5153 else if (pci_get_device(dev) == CHIPID_21142)
5154 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
5156 if (chipid == TULIP_CHIPID_UNKNOWN)
5159 if (chipid == TULIP_21040 && revinfo < 0x20) {
5160 printf("de%d", unit);
5161 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
5162 revinfo >> 4, revinfo & 0x0f);
5164 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
5165 printf("de%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
5166 unit, revinfo >> 4, revinfo & 0x0f);
5170 sc = device_get_softc(dev);
5171 sc->tulip_pci_busno = pci_get_bus(dev);
5172 sc->tulip_pci_devno = pci_get_slot(dev);
5173 sc->tulip_chipid = chipid;
5174 sc->tulip_flags |= TULIP_DEVICEPROBE;
5175 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
5176 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
5177 if (chipid == TULIP_21140A && revinfo <= 0x22)
5178 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
5179 if (chipid == TULIP_21140)
5180 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
5181 if (chipid != TULIP_21040 && chipid != TULIP_21140)
5182 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
5183 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
5184 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
5185 if (chipid != TULIP_21041 || revinfo >= 0x20)
5186 sc->tulip_features |= TULIP_HAVE_SIANWAY;
5187 if (chipid != TULIP_21041)
5188 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
5189 if (chipid != TULIP_21041 && revinfo >= 0x20)
5190 sc->tulip_features |= TULIP_HAVE_SIA100;
5193 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
5194 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
5195 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
5196 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
5199 #if defined(__alpha__)
5201 * The Alpha SRM console encodes a console set media in the driver
5202 * part of the CFDA register. Note that the Multia presents a
5203 * problem in that its BNC mode is really EXTSIA. So in that case
5206 switch ((cfdainfo >> 8) & 0xff) {
5207 case 1: media = chipid > TULIP_21040 ? TULIP_MEDIA_AUI : TULIP_MEDIA_AUIBNC; break;
5208 case 2: media = chipid > TULIP_21040 ? TULIP_MEDIA_BNC : TULIP_MEDIA_UNKNOWN; break;
5209 case 3: media = TULIP_MEDIA_10BASET; break;
5210 case 4: media = TULIP_MEDIA_10BASET_FD; break;
5211 case 5: media = TULIP_MEDIA_100BASETX; break;
5212 case 6: media = TULIP_MEDIA_100BASETX_FD; break;
5213 default: media = TULIP_MEDIA_UNKNOWN; break;
5217 sc->tulip_unit = unit;
5218 sc->tulip_name = "de";
5219 sc->tulip_revinfo = revinfo;
5220 sc->tulip_if.if_softc = sc;
5221 #if defined(TULIP_IOMAPPED)
5223 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
5224 0, ~0, 1, RF_ACTIVE);
5227 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
5228 0, ~0, 1, RF_ACTIVE);
5232 sc->tulip_csrs_bst = rman_get_bustag(res);
5233 sc->tulip_csrs_bsh = rman_get_bushandle(res);
5238 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
5240 #if defined(TULIP_BUS_DMA)
5241 if ((retval = tulip_busdma_init(sc)) != 0) {
5242 printf("error initing bus_dma: %d\n", retval);
5246 sc->tulip_rxdescs = malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
5247 M_DEVBUF, M_INTWAIT);
5248 sc->tulip_txdescs = malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
5249 M_DEVBUF, M_INTWAIT);
5252 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
5253 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
5256 * Make sure there won't be any interrupts or such...
5258 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
5259 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
5260 33MHz that comes to two microseconds but wait a
5261 bit longer anyways) */
5263 if ((retval = tulip_read_macaddr(sc)) < 0) {
5264 printf("%s%d", sc->tulip_name, sc->tulip_unit);
5265 printf(": can't read ENET ROM (why=%d) (", retval);
5266 for (idx = 0; idx < 32; idx++)
5267 printf("%02x", sc->tulip_rombuf[idx]);
5269 printf("%s%d: %s%s pass %d.%d\n",
5270 sc->tulip_name, sc->tulip_unit,
5271 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
5272 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
5273 printf("%s%d: address unknown\n", sc->tulip_name, sc->tulip_unit);
5276 void (*intr_rtn)(void *) = tulip_intr_normal;
5278 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
5279 intr_rtn = tulip_intr_shared;
5281 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
5285 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
5286 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
5287 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
5288 intr_rtn, sc, &ih)) {
5289 printf("%s%d: couldn't map interrupt\n",
5290 sc->tulip_name, sc->tulip_unit);
5291 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
5292 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
5296 #if defined(TULIP_USE_SOFTINTR)
5297 if (sc->tulip_unit > tulip_softintr_max_unit)
5298 tulip_softintr_max_unit = sc->tulip_unit;
5302 #if defined(__alpha__)
5303 sc->tulip_media = media;
5306 #if defined(__alpha__)
5307 if (sc->tulip_media != TULIP_MEDIA_UNKNOWN)
5308 tulip_linkup(sc, media);
5315 static device_method_t tulip_pci_methods[] = {
5316 /* Device interface */
5317 DEVMETHOD(device_probe, tulip_pci_probe),
5318 DEVMETHOD(device_attach, tulip_pci_attach),
5319 DEVMETHOD(device_shutdown, tulip_shutdown),
5322 static driver_t tulip_pci_driver = {
5325 sizeof(tulip_softc_t),
5327 static devclass_t tulip_devclass;
5329 DECLARE_DUMMY_MODULE(if_de);
5330 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);