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.11 2004/04/07 05:45:27 dillon 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 timeout(tulip_timeout_callback, sc, (hz + TULIP_HZ / 2) / TULIP_HZ);
173 #if defined(TULIP_NEED_FASTTIMEOUT)
175 tulip_fasttimeout_callback(
178 tulip_softc_t * const sc = arg;
181 sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING;
182 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER);
188 tulip_softc_t * const sc)
190 if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING)
192 sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING;
193 timeout(tulip_fasttimeout_callback, sc, 1);
199 tulip_softc_t * const sc)
203 * Before we are sure this is the right media we need
204 * to send a small packet to make sure there's carrier.
205 * Strangely, BNC and AUI will "see" receive data if
206 * either is connected so the transmit is the only way
207 * to verify the connectivity.
209 MGETHDR(m, M_DONTWAIT, MT_DATA);
213 * Construct a LLC TEST message which will point to ourselves.
215 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
216 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
217 mtod(m, struct ether_header *)->ether_type = htons(3);
218 mtod(m, unsigned char *)[14] = 0;
219 mtod(m, unsigned char *)[15] = 0;
220 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
221 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
225 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
226 sc->tulip_intrmask |= TULIP_STS_TXINTR;
227 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
228 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
229 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
230 if ((m = tulip_txput(sc, m)) != NULL)
232 sc->tulip_probe.probe_txprobes++;
237 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
239 #define TULIP_SIAGEN_WATCHDOG 0
244 tulip_softc_t * const sc,
247 const tulip_media_info_t *mi = sc->tulip_mediums[media];
253 * If we are switching media, make sure we don't think there's
254 * any stale RX activity
256 sc->tulip_flags &= ~TULIP_RXACT;
257 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
258 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
259 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
260 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
261 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
263 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
265 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
267 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
268 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
269 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
271 * If the cmdmode bits don't match the currently operating mode,
272 * set the cmdmode appropriately and reset the chip.
274 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
275 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
276 sc->tulip_cmdmode |= mi->mi_cmdmode;
279 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
281 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
282 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
284 * If the cmdmode bits don't match the currently operating mode,
285 * set the cmdmode appropriately and reset the chip.
287 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
288 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
289 sc->tulip_cmdmode |= mi->mi_cmdmode;
292 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
293 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
294 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
295 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
297 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
299 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
300 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
302 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
304 sc->tulip_phyaddr = mi->mi_phyaddr;
305 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
306 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
308 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
311 for (idx = 0; idx < mi->mi_reset_length; idx++) {
313 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
315 sc->tulip_phyaddr = mi->mi_phyaddr;
316 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
318 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
321 if (sc->tulip_flags & TULIP_TRYNWAY) {
322 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
323 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
324 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
325 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
326 sc->tulip_flags &= ~TULIP_DIDNWAY;
327 if (TULIP_IS_MEDIA_FD(media))
328 data |= PHYCTL_FULL_DUPLEX;
329 if (TULIP_IS_MEDIA_100MB(media))
330 data |= PHYCTL_SELECT_100MB;
331 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
338 tulip_softc_t * const sc,
341 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
342 sc->tulip_flags |= TULIP_PRINTLINKUP;
343 sc->tulip_flags |= TULIP_LINKUP;
344 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
345 #if 0 /* XXX how does with work with ifmedia? */
346 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
347 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
348 if (TULIP_CAN_MEDIA_FD(media)
349 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
350 media = TULIP_FD_MEDIA_OF(media);
352 if (TULIP_IS_MEDIA_FD(media)
353 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
354 media = TULIP_HD_MEDIA_OF(media);
358 if (sc->tulip_media != media) {
360 sc->tulip_dbg.dbg_last_media = sc->tulip_media;
362 sc->tulip_media = media;
363 sc->tulip_flags |= TULIP_PRINTMEDIA;
364 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
365 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
366 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
367 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
371 * We could set probe_timeout to 0 but setting to 3000 puts this
372 * in one central place and the only matters is tulip_link is
373 * followed by a tulip_timeout. Therefore setting it should not
374 * result in aberrant behavour.
376 sc->tulip_probe_timeout = 3000;
377 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
378 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
379 if (sc->tulip_flags & TULIP_INRESET) {
380 tulip_media_set(sc, sc->tulip_media);
381 } else if (sc->tulip_probe_media != sc->tulip_media) {
383 * No reason to change media if we have the right media.
392 tulip_softc_t * const sc)
394 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
396 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
397 printf("%s%d: enabling %s port\n",
398 sc->tulip_name, sc->tulip_unit,
399 tulip_mediums[sc->tulip_media]);
400 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
401 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
402 printf("%s%d: link up\n", sc->tulip_name, sc->tulip_unit);
403 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
407 #if defined(TULIP_DO_GPR_SENSE)
409 tulip_21140_gpr_media_sense(
410 tulip_softc_t * const sc)
412 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
413 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
417 * If one of the media blocks contained a default media flag,
420 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
421 const tulip_media_info_t *mi;
423 * Media is not supported (or is full-duplex).
425 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
427 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
431 * Remember the media is this is the "default" media.
433 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
437 * No activity mask? Can't see if it is active if there's no mask.
439 if (mi->mi_actmask == 0)
443 * Does the activity data match?
445 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
448 #if defined(TULIP_DEBUG)
449 printf("%s%d: gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
450 sc->tulip_name, sc->tulip_unit, tulip_mediums[media],
451 TULIP_CSR_READ(sc, csr_gp) & 0xFF,
452 mi->mi_actmask, mi->mi_actdata);
455 * It does! If this is the first media we detected, then
456 * remember this media. If isn't the first, then there were
457 * multiple matches which we equate to no match (since we don't
458 * which to select (if any).
460 if (last_media == TULIP_MEDIA_UNKNOWN) {
462 } else if (last_media != media) {
463 last_media = TULIP_MEDIA_UNKNOWN;
466 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
468 #endif /* TULIP_DO_GPR_SENSE */
470 static tulip_link_status_t
471 tulip_media_link_monitor(
472 tulip_softc_t * const sc)
474 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
475 tulip_link_status_t linkup = TULIP_LINK_DOWN;
478 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
479 panic("tulip_media_link_monitor: %s: botch at line %d\n",
480 tulip_mediums[sc->tulip_media],__LINE__);
482 return TULIP_LINK_UNKNOWN;
487 * Have we seen some packets? If so, the link must be good.
489 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
490 sc->tulip_flags &= ~TULIP_RXACT;
491 sc->tulip_probe_timeout = 3000;
492 return TULIP_LINK_UP;
495 sc->tulip_flags &= ~TULIP_RXACT;
496 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
499 * Read the PHY status register.
501 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
502 if (status & PHYSTS_AUTONEG_DONE) {
504 * If the PHY has completed autonegotiation, see the if the
505 * remote systems abilities have changed. If so, upgrade or
506 * downgrade as appropriate.
508 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
509 abilities = (abilities << 6) & status;
510 if (abilities != sc->tulip_abilities) {
511 #if defined(TULIP_DEBUG)
512 loudprintf("%s%d(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
513 sc->tulip_name, sc->tulip_unit, sc->tulip_phyaddr,
514 sc->tulip_abilities, abilities);
516 if (tulip_mii_map_abilities(sc, abilities)) {
517 tulip_linkup(sc, sc->tulip_probe_media);
518 return TULIP_LINK_UP;
521 * if we had selected media because of autonegotiation,
522 * we need to probe for the new media.
524 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
525 if (sc->tulip_flags & TULIP_DIDNWAY)
526 return TULIP_LINK_DOWN;
530 * The link is now up. If was down, say its back up.
532 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
533 linkup = TULIP_LINK_UP;
534 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
536 * No activity sensor? Assume all's well.
538 if (mi->mi_actmask == 0)
539 return TULIP_LINK_UNKNOWN;
541 * Does the activity data match?
543 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
544 linkup = TULIP_LINK_UP;
545 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
547 * Assume non TP ok for now.
549 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
550 return TULIP_LINK_UNKNOWN;
551 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
552 linkup = TULIP_LINK_UP;
553 #if defined(TULIP_DEBUG)
554 if (sc->tulip_probe_timeout <= 0)
555 printf("%s%d: sia status = 0x%08x\n", sc->tulip_name,
556 sc->tulip_unit, TULIP_CSR_READ(sc, csr_sia_status));
558 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
559 return TULIP_LINK_UNKNOWN;
562 * We will wait for 3 seconds until the link goes into suspect mode.
564 if (sc->tulip_flags & TULIP_LINKUP) {
565 if (linkup == TULIP_LINK_UP)
566 sc->tulip_probe_timeout = 3000;
567 if (sc->tulip_probe_timeout > 0)
568 return TULIP_LINK_UP;
570 sc->tulip_flags &= ~TULIP_LINKUP;
571 printf("%s%d: link down: cable problem?\n", sc->tulip_name, sc->tulip_unit);
573 #if defined(TULIP_DEBUG)
574 sc->tulip_dbg.dbg_link_downed++;
576 return TULIP_LINK_DOWN;
581 tulip_softc_t * const sc,
582 tulip_mediapoll_event_t event)
584 #if defined(TULIP_DEBUG)
585 sc->tulip_dbg.dbg_events[event]++;
587 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
588 && event == TULIP_MEDIAPOLL_TIMER) {
589 switch (tulip_media_link_monitor(sc)) {
590 case TULIP_LINK_DOWN: {
592 * Link Monitor failed. Probe for new media.
594 event = TULIP_MEDIAPOLL_LINKFAIL;
597 case TULIP_LINK_UP: {
604 case TULIP_LINK_UNKNOWN: {
606 * We can't tell so don't bother.
613 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
614 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
615 if (TULIP_DO_AUTOSENSE(sc)) {
616 #if defined(TULIP_DEBUG)
617 sc->tulip_dbg.dbg_link_failures++;
619 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
620 if (sc->tulip_if.if_flags & IFF_UP)
621 tulip_reset(sc); /* restart probe */
625 #if defined(TULIP_DEBUG)
626 sc->tulip_dbg.dbg_link_pollintrs++;
630 if (event == TULIP_MEDIAPOLL_START) {
631 sc->tulip_if.if_flags |= IFF_OACTIVE;
632 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
634 sc->tulip_probe_mediamask = 0;
635 sc->tulip_probe_passes = 0;
636 #if defined(TULIP_DEBUG)
637 sc->tulip_dbg.dbg_media_probes++;
640 * If the SROM contained an explicit media to use, use it.
642 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
643 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
644 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
646 * connidx is defaulted to a media_unknown type.
648 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
649 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
650 tulip_linkup(sc, sc->tulip_probe_media);
655 if (sc->tulip_features & TULIP_HAVE_GPR) {
656 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
657 sc->tulip_probe_timeout = 2000;
659 sc->tulip_probe_media = TULIP_MEDIA_MAX;
660 sc->tulip_probe_timeout = 0;
661 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
666 * Ignore txprobe failures or spurious callbacks.
668 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
669 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
670 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
675 * If we really transmitted a packet, then that's the media we'll use.
677 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
678 if (event == TULIP_MEDIAPOLL_LINKPASS) {
679 /* XXX Check media status just to be sure */
680 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
681 #if defined(TULIP_DEBUG)
683 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
686 tulip_linkup(sc, sc->tulip_probe_media);
691 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
692 #if defined(TULIP_DO_GPR_SENSE)
694 * Check for media via the general purpose register.
696 * Try to sense the media via the GPR. If the same value
697 * occurs 3 times in a row then just use that.
699 if (sc->tulip_probe_timeout > 0) {
700 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
701 #if defined(TULIP_DEBUG)
702 printf("%s%d: media_poll: gpr sensing = %s\n",
703 sc->tulip_name, sc->tulip_unit, tulip_mediums[new_probe_media]);
705 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
706 if (new_probe_media == sc->tulip_probe_media) {
707 if (--sc->tulip_probe_count == 0)
708 tulip_linkup(sc, sc->tulip_probe_media);
710 sc->tulip_probe_count = 10;
713 sc->tulip_probe_media = new_probe_media;
717 #endif /* TULIP_DO_GPR_SENSE */
719 * Brute force. We cycle through each of the media types
720 * and try to transmit a packet.
722 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
723 sc->tulip_probe_media = TULIP_MEDIA_MAX;
724 sc->tulip_probe_timeout = 0;
729 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
730 && (sc->tulip_features & TULIP_HAVE_MII)) {
731 tulip_media_t old_media = sc->tulip_probe_media;
732 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
733 switch (sc->tulip_probe_state) {
734 case TULIP_PROBE_FAILED:
735 case TULIP_PROBE_MEDIATEST: {
737 * Try the next media.
739 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
740 sc->tulip_probe_timeout = 0;
742 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
744 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
746 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
750 case TULIP_PROBE_PHYAUTONEG: {
753 case TULIP_PROBE_INACTIVE: {
755 * Only probe if we autonegotiated a media that hasn't failed.
757 sc->tulip_probe_timeout = 0;
758 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
759 sc->tulip_probe_media = old_media;
762 tulip_linkup(sc, sc->tulip_probe_media);
767 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
768 panic("tulip_media_poll: botch at line %d\n", __LINE__);
775 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
776 #if defined(TULIP_DEBUG)
777 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
779 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
784 * switch to another media if we tried this one enough.
786 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
787 #if defined(TULIP_DEBUG)
788 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
789 printf("%s%d: poll media unknown!\n",
790 sc->tulip_name, sc->tulip_unit);
791 sc->tulip_probe_media = TULIP_MEDIA_MAX;
795 * Find the next media type to check for. Full Duplex
796 * types are not allowed.
799 sc->tulip_probe_media -= 1;
800 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
801 if (++sc->tulip_probe_passes == 3) {
802 printf("%s%d: autosense failed: cable problem?\n",
803 sc->tulip_name, sc->tulip_unit);
804 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
805 sc->tulip_if.if_flags &= ~IFF_RUNNING;
806 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
810 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
811 sc->tulip_probe_mediamask = 0;
812 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
814 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
815 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
816 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
818 #if defined(TULIP_DEBUG)
819 printf("%s%d: %s: probing %s\n", sc->tulip_name, sc->tulip_unit,
820 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
821 tulip_mediums[sc->tulip_probe_media]);
823 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
824 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
825 sc->tulip_probe.probe_txprobes = 0;
827 tulip_media_set(sc, sc->tulip_probe_media);
828 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
833 * If this is hanging off a phy, we know are doing NWAY and we have
834 * forced the phy to a specific speed. Wait for link up before
835 * before sending a packet.
837 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
838 case TULIP_MEDIAINFO_MII: {
839 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
843 case TULIP_MEDIAINFO_SIA: {
844 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
845 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
847 tulip_linkup(sc, sc->tulip_probe_media);
849 if (sc->tulip_features & TULIP_HAVE_MII)
856 case TULIP_MEDIAINFO_RESET:
857 case TULIP_MEDIAINFO_SYM:
858 case TULIP_MEDIAINFO_NONE:
859 case TULIP_MEDIAINFO_GPR: {
864 * Try to send a packet.
871 tulip_softc_t * const sc)
873 if (sc->tulip_features & TULIP_HAVE_GPR) {
874 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
876 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
879 * If this board has no media, just return
881 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
884 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
885 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
886 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
888 tulip_media_set(sc, sc->tulip_media);
893 tulip_21040_mediainfo_init(
894 tulip_softc_t * const sc,
897 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
898 |TULIP_CMD_BACKOFFCTR;
899 sc->tulip_if.if_baudrate = 10000000;
901 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
902 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
903 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
904 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
907 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
908 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
911 if (media == TULIP_MEDIA_UNKNOWN) {
912 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
917 tulip_21040_media_probe(
918 tulip_softc_t * const sc)
920 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
925 tulip_21040_10baset_only_media_probe(
926 tulip_softc_t * const sc)
928 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
929 tulip_media_set(sc, TULIP_MEDIA_10BASET);
930 sc->tulip_media = TULIP_MEDIA_10BASET;
934 tulip_21040_10baset_only_media_select(
935 tulip_softc_t * const sc)
937 sc->tulip_flags |= TULIP_LINKUP;
938 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
939 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
940 sc->tulip_flags &= ~TULIP_SQETEST;
942 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
943 sc->tulip_flags |= TULIP_SQETEST;
945 tulip_media_set(sc, sc->tulip_media);
949 tulip_21040_auibnc_only_media_probe(
950 tulip_softc_t * const sc)
952 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
953 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
954 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
955 sc->tulip_media = TULIP_MEDIA_AUIBNC;
959 tulip_21040_auibnc_only_media_select(
960 tulip_softc_t * const sc)
962 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
963 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
966 static const tulip_boardsw_t tulip_21040_boardsw = {
968 tulip_21040_media_probe,
973 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
975 tulip_21040_10baset_only_media_probe,
976 tulip_21040_10baset_only_media_select,
980 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
982 tulip_21040_auibnc_only_media_probe,
983 tulip_21040_auibnc_only_media_select,
988 tulip_21041_mediainfo_init(
989 tulip_softc_t * const sc)
991 tulip_media_info_t * const mi = sc->tulip_mediainfo;
994 if (sc->tulip_revinfo >= 0x20) {
995 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
996 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
997 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
998 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
1002 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
1003 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
1004 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
1005 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
1009 tulip_21041_media_probe(
1010 tulip_softc_t * const sc)
1012 sc->tulip_if.if_baudrate = 10000000;
1013 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
1014 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
1015 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
1016 tulip_21041_mediainfo_init(sc);
1020 tulip_21041_media_poll(
1021 tulip_softc_t * const sc,
1022 const tulip_mediapoll_event_t event)
1024 u_int32_t sia_status;
1026 #if defined(TULIP_DEBUG)
1027 sc->tulip_dbg.dbg_events[event]++;
1030 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
1031 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
1032 || !TULIP_DO_AUTOSENSE(sc))
1034 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
1035 tulip_reset(sc); /* start probe */
1040 * If we've been been asked to start a poll or link change interrupt
1041 * restart the probe (and reset the tulip to a known state).
1043 if (event == TULIP_MEDIAPOLL_START) {
1044 sc->tulip_if.if_flags |= IFF_OACTIVE;
1045 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
1047 if (sc->tulip_revinfo >= 0x20) {
1048 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
1049 sc->tulip_flags |= TULIP_DIDNWAY;
1052 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1053 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1054 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1055 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
1056 tulip_media_set(sc, TULIP_MEDIA_10BASET);
1061 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1064 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
1065 #if defined(TULIP_DEBUG)
1066 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
1068 tulip_linkup(sc, sc->tulip_probe_media);
1072 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
1073 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
1074 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
1075 if (sc->tulip_revinfo >= 0x20) {
1076 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
1077 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1080 * If the link has passed LinkPass, 10baseT is the
1081 * proper media to use.
1083 tulip_linkup(sc, sc->tulip_probe_media);
1088 * wait for up to 2.4 seconds for the link to reach pass state.
1089 * Only then start scanning the other media for activity.
1090 * choose media with receive activity over those without.
1092 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
1093 if (event != TULIP_MEDIAPOLL_TIMER)
1095 if (sc->tulip_probe_timeout > 0
1096 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
1100 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1101 sc->tulip_flags |= TULIP_WANTRXACT;
1102 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
1103 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1105 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1107 tulip_media_set(sc, sc->tulip_probe_media);
1113 * If we failed, clear the txprobe active flag.
1115 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
1116 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1119 if (event == TULIP_MEDIAPOLL_TIMER) {
1121 * If we've received something, then that's our link!
1123 if (sc->tulip_flags & TULIP_RXACT) {
1124 tulip_linkup(sc, sc->tulip_probe_media);
1128 * if no txprobe active
1130 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
1131 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
1132 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
1133 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1139 * Take 2 passes through before deciding to not
1140 * wait for receive activity. Then take another
1141 * two passes before spitting out a warning.
1143 if (sc->tulip_probe_timeout <= 0) {
1144 if (sc->tulip_flags & TULIP_WANTRXACT) {
1145 sc->tulip_flags &= ~TULIP_WANTRXACT;
1146 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1148 printf("%s%d: autosense failed: cable problem?\n",
1149 sc->tulip_name, sc->tulip_unit);
1150 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1151 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1152 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1160 * Since this media failed to probe, try the other one.
1162 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1163 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1164 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1166 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1168 tulip_media_set(sc, sc->tulip_probe_media);
1169 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1173 static const tulip_boardsw_t tulip_21041_boardsw = {
1174 TULIP_21041_GENERIC,
1175 tulip_21041_media_probe,
1177 tulip_21041_media_poll
1180 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1181 { 0x20005c00, 0, /* 08-00-17 */
1183 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1184 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1186 #if defined(TULIP_DEBUG)
1190 { 0x0281F400, 0, /* 00-A0-7D */
1192 { 0x12, 0x0010, 0x0000 }, /* 10T */
1194 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1195 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1197 #if defined(TULIP_DEBUG)
1202 { 0x0015F420, 0, /* 00-A0-7D */
1204 { 0x12, 0x0010, 0x0000 }, /* 10T */
1206 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1207 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1209 #if defined(TULIP_DEBUG)
1214 { 0x0281F400, 0, /* 00-A0-BE */
1216 { 0x11, 0x8000, 0x0000 }, /* 10T */
1217 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1219 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1221 #if defined(TULIP_DEBUG)
1228 static tulip_media_t
1229 tulip_mii_phy_readspecific(
1230 tulip_softc_t * const sc)
1232 const tulip_phy_attr_t *attr;
1236 static const tulip_media_t table[] = {
1237 TULIP_MEDIA_UNKNOWN,
1238 TULIP_MEDIA_10BASET,
1239 TULIP_MEDIA_100BASETX,
1240 TULIP_MEDIA_100BASET4,
1241 TULIP_MEDIA_UNKNOWN,
1242 TULIP_MEDIA_10BASET_FD,
1243 TULIP_MEDIA_100BASETX_FD,
1248 * Don't read phy specific registers if link is not up.
1250 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1251 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1252 return TULIP_MEDIA_UNKNOWN;
1254 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1255 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1256 for (attr = tulip_mii_phy_attrlist;; attr++) {
1257 if (attr->attr_id == 0)
1258 return TULIP_MEDIA_UNKNOWN;
1259 if ((id & ~0x0F) == attr->attr_id)
1263 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1264 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
1265 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1266 if ((data & pm->pm_mask) == pm->pm_value)
1269 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1270 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
1271 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1272 if ((data & pm->pm_mask) == pm->pm_value)
1275 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1276 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
1277 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1278 if ((data & pm->pm_mask) == pm->pm_value)
1281 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1282 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1283 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1284 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1290 tulip_mii_get_phyaddr(
1291 tulip_softc_t * const sc,
1296 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1297 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1298 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1305 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1306 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1307 return TULIP_MII_NOPHY;
1310 return TULIP_MII_NOPHY;
1314 tulip_mii_map_abilities(
1315 tulip_softc_t * const sc,
1318 sc->tulip_abilities = abilities;
1319 if (abilities & PHYSTS_100BASETX_FD) {
1320 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1321 } else if (abilities & PHYSTS_100BASET4) {
1322 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1323 } else if (abilities & PHYSTS_100BASETX) {
1324 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1325 } else if (abilities & PHYSTS_10BASET_FD) {
1326 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1327 } else if (abilities & PHYSTS_10BASET) {
1328 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1330 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1333 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1338 tulip_mii_autonegotiate(
1339 tulip_softc_t * const sc,
1340 const unsigned phyaddr)
1342 switch (sc->tulip_probe_state) {
1343 case TULIP_PROBE_MEDIATEST:
1344 case TULIP_PROBE_INACTIVE: {
1345 sc->tulip_flags |= TULIP_DIDNWAY;
1346 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1347 sc->tulip_probe_timeout = 3000;
1348 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1349 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1352 case TULIP_PROBE_PHYRESET: {
1354 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1355 if (data & PHYCTL_RESET) {
1356 if (sc->tulip_probe_timeout > 0) {
1360 printf("%s%d(phy%d): error: reset of PHY never completed!\n",
1361 sc->tulip_name, sc->tulip_unit, phyaddr);
1362 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1363 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1364 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1367 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1368 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1369 #if defined(TULIP_DEBUG)
1370 loudprintf("%s%d(phy%d): autonegotiation disabled\n",
1371 sc->tulip_name, sc->tulip_unit, phyaddr);
1373 sc->tulip_flags &= ~TULIP_DIDNWAY;
1374 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1377 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1378 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1379 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1380 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1381 #if defined(TULIP_DEBUG)
1382 if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
1383 loudprintf("%s%d(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
1384 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1386 loudprintf("%s%d(phy%d): autonegotiation restarted: 0x%04x\n",
1387 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1388 sc->tulip_dbg.dbg_nway_starts++;
1390 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1391 sc->tulip_probe_timeout = 3000;
1394 case TULIP_PROBE_PHYAUTONEG: {
1395 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1397 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1398 if (sc->tulip_probe_timeout > 0) {
1402 #if defined(TULIP_DEBUG)
1403 loudprintf("%s%d(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
1404 sc->tulip_name, sc->tulip_unit, phyaddr, status,
1405 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
1407 sc->tulip_flags &= ~TULIP_DIDNWAY;
1408 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1411 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1412 #if defined(TULIP_DEBUG)
1413 loudprintf("%s%d(phy%d): autonegotiation complete: 0x%04x\n",
1414 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1416 data = (data << 6) & status;
1417 if (!tulip_mii_map_abilities(sc, data))
1418 sc->tulip_flags &= ~TULIP_DIDNWAY;
1422 #if defined(DIAGNOSTIC)
1423 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1428 #if defined(TULIP_DEBUG)
1429 loudprintf("%s%d(phy%d): autonegotiation failure: state = %d\n",
1430 sc->tulip_name, sc->tulip_unit, phyaddr, sc->tulip_probe_state);
1431 sc->tulip_dbg.dbg_nway_failures++;
1436 tulip_2114x_media_preset(
1437 tulip_softc_t * const sc)
1439 const tulip_media_info_t *mi = NULL;
1440 tulip_media_t media = sc->tulip_media;
1442 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1443 media = sc->tulip_media;
1445 media = sc->tulip_probe_media;
1447 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1448 sc->tulip_flags &= ~TULIP_SQETEST;
1449 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1450 #if defined(TULIP_DEBUG)
1451 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
1453 mi = sc->tulip_mediums[media];
1454 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1455 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1456 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1457 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1458 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1459 sc->tulip_cmdmode |= mi->mi_cmdmode;
1460 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1461 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1463 #if defined(TULIP_DEBUG)
1465 printf("%s%d: preset: bad media %d!\n",
1466 sc->tulip_name, sc->tulip_unit, media);
1471 case TULIP_MEDIA_BNC:
1472 case TULIP_MEDIA_AUI:
1473 case TULIP_MEDIA_10BASET: {
1474 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1475 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1476 sc->tulip_if.if_baudrate = 10000000;
1477 sc->tulip_flags |= TULIP_SQETEST;
1480 case TULIP_MEDIA_10BASET_FD: {
1481 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1482 sc->tulip_if.if_baudrate = 10000000;
1485 case TULIP_MEDIA_100BASEFX:
1486 case TULIP_MEDIA_100BASET4:
1487 case TULIP_MEDIA_100BASETX: {
1488 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1489 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1490 sc->tulip_if.if_baudrate = 100000000;
1493 case TULIP_MEDIA_100BASEFX_FD:
1494 case TULIP_MEDIA_100BASETX_FD: {
1495 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1496 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1497 sc->tulip_if.if_baudrate = 100000000;
1504 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1508 ********************************************************************
1509 * Start of 21140/21140A support which does not use the MII interface
1513 tulip_null_media_poll(
1514 tulip_softc_t * const sc,
1515 tulip_mediapoll_event_t event)
1517 #if defined(TULIP_DEBUG)
1518 sc->tulip_dbg.dbg_events[event]++;
1520 #if defined(DIAGNOSTIC)
1521 printf("%s%d: botch(media_poll) at line %d\n",
1522 sc->tulip_name, sc->tulip_unit, __LINE__);
1526 __inline__ static void
1527 tulip_21140_mediainit(
1528 tulip_softc_t * const sc,
1529 tulip_media_info_t * const mip,
1530 tulip_media_t const media,
1534 sc->tulip_mediums[media] = mip;
1535 mip->mi_type = TULIP_MEDIAINFO_GPR;
1536 mip->mi_cmdmode = cmdmode;
1537 mip->mi_gpdata = gpdata;
1541 tulip_21140_evalboard_media_probe(
1542 tulip_softc_t * const sc)
1544 tulip_media_info_t *mip = sc->tulip_mediainfo;
1546 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1547 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1548 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1549 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1550 TULIP_CSR_WRITE(sc, csr_command,
1551 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1552 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1553 TULIP_CSR_WRITE(sc, csr_command,
1554 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1556 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1557 sc->tulip_media = TULIP_MEDIA_10BASET;
1559 sc->tulip_media = TULIP_MEDIA_100BASETX;
1561 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1563 TULIP_CMD_TXTHRSHLDCTL);
1564 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1566 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1567 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1569 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1570 |TULIP_CMD_SCRAMBLER);
1571 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1573 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1574 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1577 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1579 tulip_21140_evalboard_media_probe,
1581 tulip_null_media_poll,
1582 tulip_2114x_media_preset,
1586 tulip_21140_accton_media_probe(
1587 tulip_softc_t * const sc)
1589 tulip_media_info_t *mip = sc->tulip_mediainfo;
1592 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1593 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1594 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1595 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1596 TULIP_CSR_WRITE(sc, csr_command,
1597 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1598 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1599 TULIP_CSR_WRITE(sc, csr_command,
1600 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1602 gpdata = TULIP_CSR_READ(sc, csr_gp);
1603 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1604 sc->tulip_media = TULIP_MEDIA_10BASET;
1606 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1607 sc->tulip_media = TULIP_MEDIA_BNC;
1609 sc->tulip_media = TULIP_MEDIA_100BASETX;
1612 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1613 TULIP_GP_EN1207_BNC_INIT,
1614 TULIP_CMD_TXTHRSHLDCTL);
1615 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1616 TULIP_GP_EN1207_UTP_INIT,
1617 TULIP_CMD_TXTHRSHLDCTL);
1618 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1619 TULIP_GP_EN1207_UTP_INIT,
1620 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1621 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1622 TULIP_GP_EN1207_100_INIT,
1623 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1624 |TULIP_CMD_SCRAMBLER);
1625 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1626 TULIP_GP_EN1207_100_INIT,
1627 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1628 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1631 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1633 tulip_21140_accton_media_probe,
1635 tulip_null_media_poll,
1636 tulip_2114x_media_preset,
1640 tulip_21140_smc9332_media_probe(
1641 tulip_softc_t * const sc)
1643 tulip_media_info_t *mip = sc->tulip_mediainfo;
1646 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1647 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1648 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1649 33MHz that comes to two microseconds but wait a
1650 bit longer anyways) */
1651 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1652 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1653 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1654 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1655 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1656 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1658 for (idx = 1000; idx > 0; idx--) {
1659 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1660 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1663 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1670 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1671 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1672 TULIP_GP_SMC_9332_INIT,
1673 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1674 |TULIP_CMD_SCRAMBLER);
1675 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1676 TULIP_GP_SMC_9332_INIT,
1677 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1678 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1679 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1680 TULIP_GP_SMC_9332_INIT,
1681 TULIP_CMD_TXTHRSHLDCTL);
1682 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1683 TULIP_GP_SMC_9332_INIT,
1684 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1687 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1688 TULIP_21140_SMC_9332,
1689 tulip_21140_smc9332_media_probe,
1691 tulip_null_media_poll,
1692 tulip_2114x_media_preset,
1696 tulip_21140_cogent_em100_media_probe(
1697 tulip_softc_t * const sc)
1699 tulip_media_info_t *mip = sc->tulip_mediainfo;
1700 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1702 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1703 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1704 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1705 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1707 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1708 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1709 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1710 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1711 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1713 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1714 TULIP_GP_EM100_INIT,
1715 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1716 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1717 TULIP_GP_EM100_INIT,
1718 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1719 |TULIP_CMD_FULLDUPLEX);
1721 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1722 sc->tulip_media = TULIP_MEDIA_100BASETX;
1723 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1724 TULIP_GP_EM100_INIT,
1725 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1726 |TULIP_CMD_SCRAMBLER);
1727 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1728 TULIP_GP_EM100_INIT,
1729 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1730 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1734 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1735 TULIP_21140_COGENT_EM100,
1736 tulip_21140_cogent_em100_media_probe,
1738 tulip_null_media_poll,
1739 tulip_2114x_media_preset
1743 tulip_21140_znyx_zx34x_media_probe(
1744 tulip_softc_t * const sc)
1746 tulip_media_info_t *mip = sc->tulip_mediainfo;
1747 int cnt10 = 0, cnt100 = 0, idx;
1749 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1750 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1751 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1752 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1753 TULIP_CSR_WRITE(sc, csr_command,
1754 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1755 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1756 TULIP_CSR_WRITE(sc, csr_command,
1757 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1760 for (idx = 1000; idx > 0; idx--) {
1761 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1762 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)) {
1765 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1774 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1775 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1776 TULIP_GP_ZX34X_INIT,
1777 TULIP_CMD_TXTHRSHLDCTL);
1778 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1779 TULIP_GP_ZX34X_INIT,
1780 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1781 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1782 TULIP_GP_ZX34X_INIT,
1783 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1784 |TULIP_CMD_SCRAMBLER);
1785 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1786 TULIP_GP_ZX34X_INIT,
1787 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1788 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1791 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1792 TULIP_21140_ZNYX_ZX34X,
1793 tulip_21140_znyx_zx34x_media_probe,
1795 tulip_null_media_poll,
1796 tulip_2114x_media_preset,
1800 tulip_2114x_media_probe(
1801 tulip_softc_t * const sc)
1803 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
1804 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
1807 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1809 tulip_2114x_media_probe,
1812 tulip_2114x_media_preset,
1816 * ******** END of chip-specific handlers. ***********
1820 * Code the read the SROM and MII bit streams (I2C)
1822 #define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1826 tulip_softc_t * const sc)
1830 csr = SROMSEL ; EMIT;
1831 csr = SROMSEL | SROMRD; EMIT;
1832 csr ^= SROMCS; EMIT;
1833 csr ^= SROMCLKON; EMIT;
1836 * Write 25 cycles of 0 which will force the SROM to be idle.
1838 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1839 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1840 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1842 csr ^= SROMCLKOFF; EMIT;
1843 csr ^= SROMCS; EMIT;
1850 tulip_softc_t * const sc)
1853 const unsigned bitwidth = SROM_BITWIDTH;
1854 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1855 const unsigned msb = 1 << (bitwidth + 3 - 1);
1856 unsigned lastidx = (1 << bitwidth) - 1;
1858 tulip_srom_idle(sc);
1860 for (idx = 0; idx <= lastidx; idx++) {
1861 unsigned lastbit, data, bits, bit, csr;
1862 csr = SROMSEL ; EMIT;
1863 csr = SROMSEL | SROMRD; EMIT;
1864 csr ^= SROMCSON; EMIT;
1865 csr ^= SROMCLKON; EMIT;
1868 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1869 const unsigned thisbit = bits & msb;
1870 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1871 if (thisbit != lastbit) {
1872 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1876 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1879 csr ^= SROMCLKOFF; EMIT;
1881 for (data = 0, bits = 0; bits < 16; bits++) {
1883 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1884 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1885 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1887 sc->tulip_rombuf[idx*2] = data & 0xFF;
1888 sc->tulip_rombuf[idx*2+1] = data >> 8;
1889 csr = SROMSEL | SROMRD; EMIT;
1892 tulip_srom_idle(sc);
1895 #define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1898 tulip_mii_writebits(
1899 tulip_softc_t * const sc,
1903 unsigned msb = 1 << (bits - 1);
1904 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1905 unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
1907 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1909 for (; bits > 0; bits--, data <<= 1) {
1910 const unsigned thisbit = data & msb;
1911 if (thisbit != lastbit) {
1912 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1914 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1916 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1921 tulip_mii_turnaround(
1922 tulip_softc_t * const sc,
1925 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1927 if (cmd == MII_WRCMD) {
1928 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1929 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1930 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1931 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1933 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1935 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1936 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1941 tulip_softc_t * const sc)
1944 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1947 for (idx = 0, data = 0; idx < 16; idx++) {
1948 data <<= 1; /* this is NOOP on the first pass through */
1949 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1950 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1952 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1954 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1961 tulip_softc_t * const sc,
1965 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1968 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1969 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1970 tulip_mii_writebits(sc, MII_RDCMD, 8);
1971 tulip_mii_writebits(sc, devaddr, 5);
1972 tulip_mii_writebits(sc, regno, 5);
1973 tulip_mii_turnaround(sc, MII_RDCMD);
1975 data = tulip_mii_readbits(sc);
1976 #if defined(TULIP_DEBUG)
1977 sc->tulip_dbg.dbg_phyregs[regno][0] = data;
1978 sc->tulip_dbg.dbg_phyregs[regno][1]++;
1985 tulip_softc_t * const sc,
1990 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1991 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1992 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1993 tulip_mii_writebits(sc, MII_WRCMD, 8);
1994 tulip_mii_writebits(sc, devaddr, 5);
1995 tulip_mii_writebits(sc, regno, 5);
1996 tulip_mii_turnaround(sc, MII_WRCMD);
1997 tulip_mii_writebits(sc, data, 16);
1998 #if defined(TULIP_DEBUG)
1999 sc->tulip_dbg.dbg_phyregs[regno][2] = data;
2000 sc->tulip_dbg.dbg_phyregs[regno][3]++;
2004 #define tulip_mchash(mca) (tulip_crc32(mca, 6) & 0x1FF)
2005 #define tulip_srom_crcok(databuf) ( \
2006 ((tulip_crc32(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
2007 ((databuf)[126] | ((databuf)[127] << 8)))
2011 const unsigned char *databuf,
2014 u_int idx, crc = 0xFFFFFFFFUL;
2015 static const u_int crctab[] = {
2016 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
2017 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
2018 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
2019 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
2022 for (idx = 0; idx < datalen; idx++) {
2024 crc = (crc >> 4) ^ crctab[crc & 0xf];
2025 crc = (crc >> 4) ^ crctab[crc & 0xf];
2031 tulip_identify_dec_nic(
2032 tulip_softc_t * const sc)
2034 strcpy(sc->tulip_boardid, "DEC ");
2036 if (sc->tulip_chipid <= TULIP_21040)
2038 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
2039 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
2040 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
2041 sc->tulip_boardid[D0+8] = ' ';
2047 tulip_identify_znyx_nic(
2048 tulip_softc_t * const sc)
2051 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
2052 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2054 sc->tulip_boardid[8] = '4';
2055 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
2056 if (znyx_ptr < 26 || znyx_ptr > 116) {
2057 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2060 /* ZX344 = 0010 .. 0013FF
2062 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
2063 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
2064 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
2065 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
2066 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
2067 sc->tulip_boardid[9] = '2';
2068 if (id == TULIP_ZNYX_ID_ZX342B) {
2069 sc->tulip_boardid[10] = 'B';
2070 sc->tulip_boardid[11] = ' ';
2072 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2073 } else if (id == TULIP_ZNYX_ID_ZX344) {
2074 sc->tulip_boardid[10] = '4';
2075 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2076 } else if (id == TULIP_ZNYX_ID_ZX345) {
2077 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
2078 } else if (id == TULIP_ZNYX_ID_ZX346) {
2079 sc->tulip_boardid[9] = '6';
2080 } else if (id == TULIP_ZNYX_ID_ZX351) {
2081 sc->tulip_boardid[8] = '5';
2082 sc->tulip_boardid[9] = '1';
2087 * Assume it's a ZX342...
2089 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2093 sc->tulip_boardid[8] = '1';
2094 if (sc->tulip_chipid == TULIP_21041) {
2095 sc->tulip_boardid[10] = '1';
2098 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
2099 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
2100 if (id == TULIP_ZNYX_ID_ZX312T) {
2101 sc->tulip_boardid[9] = '2';
2102 sc->tulip_boardid[10] = 'T';
2103 sc->tulip_boardid[11] = ' ';
2104 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2105 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
2106 sc->tulip_boardid[9] = '4';
2107 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2108 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2109 } else if (id == TULIP_ZNYX_ID_ZX314) {
2110 sc->tulip_boardid[9] = '4';
2111 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2112 sc->tulip_features |= TULIP_HAVE_BASEROM;
2113 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
2114 sc->tulip_boardid[9] = '5';
2115 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2116 } else if (id == TULIP_ZNYX_ID_ZX315) {
2117 sc->tulip_boardid[9] = '5';
2118 sc->tulip_features |= TULIP_HAVE_BASEROM;
2124 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
2125 sc->tulip_boardid[9] = '4';
2126 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2127 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2128 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
2129 sc->tulip_boardid[9] = '5';
2130 sc->tulip_boardsw = &tulip_21040_boardsw;
2131 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2132 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
2133 sc->tulip_boardid[9] = '2';
2134 sc->tulip_boardsw = &tulip_21040_boardsw;
2140 tulip_identify_smc_nic(
2141 tulip_softc_t * const sc)
2143 u_int32_t id1, id2, ei;
2144 int auibnc = 0, utp = 0;
2147 strcpy(sc->tulip_boardid, "SMC ");
2148 if (sc->tulip_chipid == TULIP_21041)
2150 if (sc->tulip_chipid != TULIP_21040) {
2151 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2152 strcpy(&sc->tulip_boardid[4], "9332DST ");
2153 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
2154 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
2155 strcpy(&sc->tulip_boardid[4], "9334BDT ");
2157 strcpy(&sc->tulip_boardid[4], "9332BDT ");
2161 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
2162 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
2163 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
2165 strcpy(&sc->tulip_boardid[4], "8432");
2166 cp = &sc->tulip_boardid[8];
2168 *cp++ = 'B', auibnc = 1;
2169 if ((id1 & 0xFF) > 0x32)
2170 *cp++ = 'T', utp = 1;
2171 if ((id1 & 0x4000) == 0)
2172 *cp++ = 'A', auibnc = 1;
2174 sc->tulip_boardid[7] = '4';
2178 *cp++ = (ei ? '2' : '1');
2183 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2184 else if (!utp && auibnc)
2185 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
2189 tulip_identify_cogent_nic(
2190 tulip_softc_t * const sc)
2192 strcpy(sc->tulip_boardid, "Cogent ");
2193 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2194 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
2195 strcat(sc->tulip_boardid, "EM100TX ");
2196 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2197 #if defined(TULIP_COGENT_EM110TX_ID)
2198 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
2199 strcat(sc->tulip_boardid, "EM110TX ");
2200 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2202 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
2203 strcat(sc->tulip_boardid, "EM100FX ");
2204 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2207 * Magic number (0x24001109U) is the SubVendor (0x2400) and
2208 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
2210 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
2211 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
2213 * Cogent (Adaptec) is still mapping all INTs to INTA of
2214 * first 21140. Dumb! Dumb!
2216 strcat(sc->tulip_boardid, "EM440TX ");
2217 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2219 } else if (sc->tulip_chipid == TULIP_21040) {
2220 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2225 tulip_identify_accton_nic(
2226 tulip_softc_t * const sc)
2228 strcpy(sc->tulip_boardid, "ACCTON ");
2229 switch (sc->tulip_chipid) {
2231 strcat(sc->tulip_boardid, "EN1207 ");
2232 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2233 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
2236 strcat(sc->tulip_boardid, "EN1207TX ");
2237 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2238 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2241 strcat(sc->tulip_boardid, "EN1203 ");
2242 sc->tulip_boardsw = &tulip_21040_boardsw;
2245 strcat(sc->tulip_boardid, "EN1203 ");
2246 sc->tulip_boardsw = &tulip_21041_boardsw;
2249 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2255 tulip_identify_asante_nic(
2256 tulip_softc_t * const sc)
2258 strcpy(sc->tulip_boardid, "Asante ");
2259 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2260 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2261 tulip_media_info_t *mi = sc->tulip_mediainfo;
2264 * The Asante Fast Ethernet doesn't always ship with a valid
2265 * new format SROM. So if isn't in the new format, we cheat
2266 * set it up as if we had.
2269 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2270 sc->tulip_gpdata = 0;
2272 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2273 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2275 TULIP_CSR_WRITE(sc, csr_gp, 0);
2277 mi->mi_type = TULIP_MEDIAINFO_MII;
2278 mi->mi_gpr_length = 0;
2279 mi->mi_gpr_offset = 0;
2280 mi->mi_reset_length = 0;
2281 mi->mi_reset_offset = 0;;
2283 mi->mi_phyaddr = TULIP_MII_NOPHY;
2284 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2286 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2288 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2289 printf("%s%d: can't find phy 0\n", sc->tulip_name, sc->tulip_unit);
2293 sc->tulip_features |= TULIP_HAVE_MII;
2294 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2295 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2296 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2297 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2298 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2299 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2300 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2301 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2302 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2303 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2304 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2306 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2311 tulip_identify_compex_nic(
2312 tulip_softc_t * const sc)
2314 strcpy(sc->tulip_boardid, "COMPEX ");
2315 if (sc->tulip_chipid == TULIP_21140A) {
2317 tulip_softc_t *root_sc = NULL;
2319 strcat(sc->tulip_boardid, "400TX/PCI ");
2321 * All 4 chips on these boards share an interrupt. This code
2322 * copied from tulip_read_macaddr.
2324 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2325 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2326 root_sc = tulips[root_unit];
2328 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2333 && root_sc->tulip_chipid == sc->tulip_chipid
2334 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2335 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2336 sc->tulip_slaves = root_sc->tulip_slaves;
2337 root_sc->tulip_slaves = sc;
2338 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2339 printf("\nCannot find master device for de%d interrupts",
2343 strcat(sc->tulip_boardid, "unknown ");
2345 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2351 tulip_softc_t * const sc)
2353 unsigned idx1, idx2, idx3;
2355 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2356 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2357 tulip_srom_media_t srom_media;
2358 tulip_media_info_t *mi = sc->tulip_mediainfo;
2360 u_int32_t leaf_offset, blocks, data;
2362 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2363 if (shp->sh_adapter_count == 1)
2365 if (saip->sai_device == sc->tulip_pci_devno)
2369 * Didn't find the right media block for this card.
2371 if (idx1 == shp->sh_adapter_count)
2375 * Save the hardware address.
2377 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2379 * If this is a multiple port card, add the adapter index to the last
2380 * byte of the hardware address. (if it isn't multiport, adding 0
2383 sc->tulip_enaddr[5] += idx1;
2385 leaf_offset = saip->sai_leaf_offset_lowbyte
2386 + saip->sai_leaf_offset_highbyte * 256;
2387 dp = sc->tulip_rombuf + leaf_offset;
2389 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2391 for (idx2 = 0;; idx2++) {
2392 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2393 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2396 sc->tulip_connidx = idx2;
2398 if (sc->tulip_chipid == TULIP_21041) {
2400 for (idx2 = 0; idx2 < blocks; idx2++) {
2401 tulip_media_t media;
2403 srom_media = (tulip_srom_media_t) (data & 0x3F);
2404 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2405 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2408 media = tulip_srom_mediums[idx3].sm_type;
2409 if (media != TULIP_MEDIA_UNKNOWN) {
2410 if (data & TULIP_SROM_21041_EXTENDED) {
2411 mi->mi_type = TULIP_MEDIAINFO_SIA;
2412 sc->tulip_mediums[media] = mi;
2413 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2414 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2415 mi->mi_sia_general = dp[4] + dp[5] * 256;
2419 case TULIP_MEDIA_BNC: {
2420 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2424 case TULIP_MEDIA_AUI: {
2425 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2429 case TULIP_MEDIA_10BASET: {
2430 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2434 case TULIP_MEDIA_10BASET_FD: {
2435 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2445 if (data & TULIP_SROM_21041_EXTENDED)
2450 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2451 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2452 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2453 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2457 unsigned length, type;
2458 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2459 if (sc->tulip_features & TULIP_HAVE_GPR)
2460 sc->tulip_gpinit = *dp++;
2462 for (idx2 = 0; idx2 < blocks; idx2++) {
2464 if ((*dp & 0x80) == 0) {
2468 length = (*dp++ & 0x7f) - 1;
2469 type = *dp++ & 0x3f;
2472 switch (type & 0x3f) {
2473 case 0: { /* 21140[A] GPR block */
2474 tulip_media_t media;
2475 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2476 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2477 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2480 media = tulip_srom_mediums[idx3].sm_type;
2481 if (media == TULIP_MEDIA_UNKNOWN)
2483 mi->mi_type = TULIP_MEDIAINFO_GPR;
2484 sc->tulip_mediums[media] = mi;
2485 mi->mi_gpdata = dp[1];
2486 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2487 sc->tulip_gpdata = mi->mi_gpdata;
2490 data = dp[2] + dp[3] * 256;
2491 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2492 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2496 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2498 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2499 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2504 case 1: { /* 21140[A] MII block */
2505 const unsigned phyno = *dp++;
2506 mi->mi_type = TULIP_MEDIAINFO_MII;
2507 mi->mi_gpr_length = *dp++;
2508 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2509 dp += mi->mi_gpr_length;
2510 mi->mi_reset_length = *dp++;
2511 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2512 dp += mi->mi_reset_length;
2515 * Before we probe for a PHY, use the GPR information
2516 * to select it. If we don't, it may be inaccessible.
2518 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2519 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2521 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2523 sc->tulip_phyaddr = mi->mi_phyaddr;
2524 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2526 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2530 * At least write something!
2532 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2533 TULIP_CSR_WRITE(sc, csr_gp, 0);
2535 mi->mi_phyaddr = TULIP_MII_NOPHY;
2536 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2538 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2540 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2541 #if defined(TULIP_DEBUG)
2542 printf("%s%d: can't find phy %d\n",
2543 sc->tulip_name, sc->tulip_unit, phyno);
2547 sc->tulip_features |= TULIP_HAVE_MII;
2548 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2549 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2550 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2551 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2552 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2553 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2554 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2555 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2556 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2557 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2558 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2562 case 2: { /* 2114[23] SIA block */
2563 tulip_media_t media;
2564 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2565 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2566 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2569 media = tulip_srom_mediums[idx3].sm_type;
2570 if (media == TULIP_MEDIA_UNKNOWN)
2572 mi->mi_type = TULIP_MEDIAINFO_SIA;
2573 sc->tulip_mediums[media] = mi;
2575 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2576 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2577 mi->mi_sia_general = dp[5] + dp[6] * 256;
2581 case TULIP_MEDIA_BNC: {
2582 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2585 case TULIP_MEDIA_AUI: {
2586 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2589 case TULIP_MEDIA_10BASET: {
2590 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2591 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2594 case TULIP_MEDIA_10BASET_FD: {
2595 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2596 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2604 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2605 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2610 case 3: { /* 2114[23] MII PHY block */
2611 const unsigned phyno = *dp++;
2612 const u_int8_t *dp0;
2613 mi->mi_type = TULIP_MEDIAINFO_MII;
2614 mi->mi_gpr_length = *dp++;
2615 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2616 dp += 2 * mi->mi_gpr_length;
2617 mi->mi_reset_length = *dp++;
2618 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2619 dp += 2 * mi->mi_reset_length;
2621 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2622 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2624 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2626 sc->tulip_phyaddr = mi->mi_phyaddr;
2627 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2628 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2630 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2633 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2634 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2636 mi->mi_phyaddr = TULIP_MII_NOPHY;
2637 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2639 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2641 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2642 #if defined(TULIP_DEBUG)
2643 printf("%s%d: can't find phy %d\n",
2644 sc->tulip_name, sc->tulip_unit, phyno);
2648 sc->tulip_features |= TULIP_HAVE_MII;
2649 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2650 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2651 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2652 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2653 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2654 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2655 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2656 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2657 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2658 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2659 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2660 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2664 case 4: { /* 21143 SYM block */
2665 tulip_media_t media;
2666 srom_media = (tulip_srom_media_t) dp[0];
2667 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2668 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2671 media = tulip_srom_mediums[idx3].sm_type;
2672 if (media == TULIP_MEDIA_UNKNOWN)
2674 mi->mi_type = TULIP_MEDIAINFO_SYM;
2675 sc->tulip_mediums[media] = mi;
2676 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2677 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2678 data = dp[5] + dp[6] * 256;
2679 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2680 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2683 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2684 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2685 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2687 if (TULIP_IS_MEDIA_TP(media))
2688 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2693 case 5: { /* 21143 Reset block */
2694 mi->mi_type = TULIP_MEDIAINFO_RESET;
2695 mi->mi_reset_length = *dp++;
2696 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2697 dp += 2 * mi->mi_reset_length;
2708 return mi - sc->tulip_mediainfo;
2711 static const struct {
2712 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2713 unsigned char vendor_oui[3];
2714 } tulip_vendors[] = {
2715 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2716 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2717 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2718 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2719 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2720 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2721 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2722 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2723 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2724 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2729 * This deals with the vagaries of the address roms and the
2730 * brain-deadness that various vendors commit in using them.
2734 tulip_softc_t * const sc)
2736 unsigned cksum, rom_cksum, idx;
2738 unsigned char tmpbuf[8];
2739 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2741 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2743 if (sc->tulip_chipid == TULIP_21040) {
2744 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2745 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2747 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2749 sc->tulip_rombuf[idx] = csr & 0xFF;
2751 sc->tulip_boardsw = &tulip_21040_boardsw;
2753 if (sc->tulip_chipid == TULIP_21041) {
2755 * Thankfully all 21041's act the same.
2757 sc->tulip_boardsw = &tulip_21041_boardsw;
2760 * Assume all 21140 board are compatible with the
2761 * DEC 10/100 evaluation board. Not really valid but
2762 * it's the best we can do until every one switches to
2763 * the new SROM format.
2766 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2768 tulip_srom_read(sc);
2769 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2771 * SROM CRC is valid therefore it must be in the
2774 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2775 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2777 * No checksum is present. See if the SROM id checks out;
2778 * the first 18 bytes should be 0 followed by a 1 followed
2779 * by the number of adapters (which we don't deal with yet).
2781 for (idx = 0; idx < 18; idx++) {
2782 if (sc->tulip_rombuf[idx] != 0)
2785 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2786 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2787 } else if (sc->tulip_chipid >= TULIP_21142) {
2788 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2789 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2791 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2792 if (sc->tulip_chipid != TULIP_21041)
2793 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2796 * If the SROM specifies more than one adapter, tag this as a
2799 if (sc->tulip_rombuf[19] > 1)
2800 sc->tulip_features |= TULIP_HAVE_BASEROM;
2801 if (sc->tulip_boardsw == NULL)
2808 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2810 * Some folks don't use the standard ethernet rom format
2811 * but instead just put the address in the first 6 bytes
2812 * of the rom and let the rest be all 0xffs. (Can we say
2813 * ZNYX?) (well sometimes they put in a checksum so we'll
2816 for (idx = 8; idx < 32; idx++) {
2817 if (sc->tulip_rombuf[idx] != 0xFF)
2821 * Make sure the address is not multicast or locally assigned
2822 * that the OUI is not 00-00-00.
2824 if ((sc->tulip_rombuf[0] & 3) != 0)
2826 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2827 && sc->tulip_rombuf[2] == 0)
2829 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2830 sc->tulip_features |= TULIP_HAVE_OKROM;
2834 * A number of makers of multiport boards (ZNYX and Cogent)
2835 * only put on one address ROM on their 21040 boards. So
2836 * if the ROM is all zeros (or all 0xFFs), look at the
2837 * previous configured boards (as long as they are on the same
2838 * PCI bus and the bus number is non-zero) until we find the
2839 * master board with address ROM. We then use its address ROM
2840 * as the base for this board. (we add our relative board
2841 * to the last byte of its address).
2843 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2844 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2847 if (idx == sizeof(sc->tulip_rombuf)) {
2849 tulip_softc_t *root_sc = NULL;
2850 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2851 root_sc = tulips[root_unit];
2852 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2856 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2857 && root_sc->tulip_chipid == sc->tulip_chipid
2858 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2859 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2860 sc->tulip_boardsw = root_sc->tulip_boardsw;
2861 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2862 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2863 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2864 sizeof(sc->tulip_rombuf));
2865 if (!tulip_srom_decode(sc))
2868 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2869 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2872 * Now for a truly disgusting kludge: all 4 21040s on
2873 * the ZX314 share the same INTA line so the mapping
2874 * setup by the BIOS on the PCI bridge is worthless.
2875 * Rather than reprogramming the value in the config
2876 * register, we will handle this internally.
2878 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2879 sc->tulip_slaves = root_sc->tulip_slaves;
2880 root_sc->tulip_slaves = sc;
2881 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2889 * This is the standard DEC address ROM test.
2892 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2895 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2896 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2897 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2898 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2899 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2902 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2904 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2906 if (cksum > 65535) cksum -= 65535;
2907 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2908 if (cksum > 65535) cksum -= 65535;
2910 if (cksum > 65535) cksum -= 65535;
2911 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2912 if (cksum >= 65535) cksum -= 65535;
2914 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2916 if (cksum != rom_cksum)
2921 * Check for various boards based on OUI. Did I say braindead?
2923 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2924 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2925 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2930 sc->tulip_features |= TULIP_HAVE_OKROM;
2936 tulip_softc_t * const sc)
2938 tulip_media_t media;
2941 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2942 if (sc->tulip_mediums[media] != NULL) {
2943 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2949 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2950 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2951 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2952 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2953 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2954 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2956 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2957 sc->tulip_flags |= TULIP_PRINTMEDIA;
2958 tulip_linkup(sc, sc->tulip_media);
2963 tulip_ifmedia_change(
2964 struct ifnet * const ifp)
2966 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
2968 sc->tulip_flags |= TULIP_NEEDRESET;
2969 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2970 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2971 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2972 tulip_media_t media;
2973 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2974 if (sc->tulip_mediums[media] != NULL
2975 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2976 sc->tulip_flags |= TULIP_PRINTMEDIA;
2977 sc->tulip_flags &= ~TULIP_DIDNWAY;
2978 tulip_linkup(sc, media);
2983 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2990 * Media status callback
2993 tulip_ifmedia_status(
2994 struct ifnet * const ifp,
2995 struct ifmediareq *req)
2997 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2999 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
3002 req->ifm_status = IFM_AVALID;
3003 if (sc->tulip_flags & TULIP_LINKUP)
3004 req->ifm_status |= IFM_ACTIVE;
3006 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
3011 tulip_softc_t * const sc)
3013 struct ifmultiaddr *ifma;
3017 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
3018 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
3019 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3020 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3021 #if defined(IFF_ALLMULTI)
3022 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
3023 sc->tulip_flags |= TULIP_ALLMULTI ;
3027 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3028 ifma = ifma->ifma_link.le_next) {
3030 if (ifma->ifma_addr->sa_family == AF_LINK)
3034 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
3035 if (multicnt > 14) {
3036 u_int32_t *sp = sc->tulip_setupdata;
3039 * Some early passes of the 21140 have broken implementations of
3040 * hash-perfect mode. When we get too many multicasts for perfect
3041 * filtering with these chips, we need to switch into hash-only
3042 * mode (this is better than all-multicast on network with lots
3043 * of multicast traffic).
3045 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
3046 sc->tulip_flags |= TULIP_WANTHASHONLY;
3048 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
3050 * If we have more than 14 multicasts, we have
3051 * go into hash perfect mode (512 bit multicast
3052 * hash and one perfect hardware).
3054 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
3056 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3057 ifma = ifma->ifma_link.le_next) {
3059 if (ifma->ifma_addr->sa_family != AF_LINK)
3062 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
3063 #if BYTE_ORDER == BIG_ENDIAN
3064 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3066 sp[hash >> 4] |= 1 << (hash & 0xF);
3070 * No reason to use a hash if we are going to be
3071 * receiving every multicast.
3073 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3074 hash = tulip_mchash(etherbroadcastaddr);
3075 #if BYTE_ORDER == BIG_ENDIAN
3076 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3078 sp[hash >> 4] |= 1 << (hash & 0xF);
3080 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
3081 hash = tulip_mchash(sc->tulip_enaddr);
3082 #if BYTE_ORDER == BIG_ENDIAN
3083 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3085 sp[hash >> 4] |= 1 << (hash & 0xF);
3088 #if BYTE_ORDER == BIG_ENDIAN
3089 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3090 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3091 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3093 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
3094 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
3095 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
3100 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
3101 u_int32_t *sp = sc->tulip_setupdata;
3103 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3105 * Else can get perfect filtering for 16 addresses.
3107 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3108 ifma = ifma->ifma_link.le_next) {
3109 if (ifma->ifma_addr->sa_family != AF_LINK)
3111 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3112 #if BYTE_ORDER == BIG_ENDIAN
3113 *sp++ = ((u_int16_t *) addrp)[0] << 16;
3114 *sp++ = ((u_int16_t *) addrp)[1] << 16;
3115 *sp++ = ((u_int16_t *) addrp)[2] << 16;
3117 *sp++ = ((u_int16_t *) addrp)[0];
3118 *sp++ = ((u_int16_t *) addrp)[1];
3119 *sp++ = ((u_int16_t *) addrp)[2];
3124 * Add the broadcast address.
3127 #if BYTE_ORDER == BIG_ENDIAN
3128 *sp++ = 0xFFFF << 16;
3129 *sp++ = 0xFFFF << 16;
3130 *sp++ = 0xFFFF << 16;
3138 * Pad the rest with our hardware address
3140 for (; idx < 16; idx++) {
3141 #if BYTE_ORDER == BIG_ENDIAN
3142 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3143 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3144 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3146 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
3147 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
3148 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
3152 #if defined(IFF_ALLMULTI)
3153 if (sc->tulip_flags & TULIP_ALLMULTI)
3154 sc->tulip_if.if_flags |= IFF_ALLMULTI;
3160 tulip_softc_t * const sc)
3162 tulip_ringinfo_t *ri;
3164 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
3167 * Brilliant. Simply brilliant. When switching modes/speeds
3168 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
3169 * bits in CSR6 and then do a software reset to get the 21140
3170 * to properly reset its internal pathways to the right places.
3173 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
3174 && sc->tulip_boardsw->bd_media_preset != NULL)
3175 (*sc->tulip_boardsw->bd_media_preset)(sc);
3177 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3178 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3179 33MHz that comes to two microseconds but wait a
3180 bit longer anyways) */
3183 sc->tulip_flags |= TULIP_INRESET;
3184 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
3185 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3186 sc->tulip_if.if_start = tulip_ifstart;
3189 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3190 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr);
3192 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
3194 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3195 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr);
3197 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
3199 TULIP_CSR_WRITE(sc, csr_busmode,
3200 (1 << (3 /*pci_max_burst_len*/ + 8))
3201 |TULIP_BUSMODE_CACHE_ALIGN8
3202 |TULIP_BUSMODE_READMULTIPLE
3203 |(BYTE_ORDER != LITTLE_ENDIAN ?
3204 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
3206 sc->tulip_txtimer = 0;
3207 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
3209 * Free all the mbufs that were on the transmit ring.
3212 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3216 IF_DEQUEUE(&sc->tulip_txq, m);
3219 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3220 map = M_GETCTX(m, bus_dmamap_t);
3221 bus_dmamap_unload(sc->tulip_dmatag, map);
3222 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3227 ri = &sc->tulip_txinfo;
3228 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3229 ri->ri_free = ri->ri_max;
3230 for (di = ri->ri_first; di < ri->ri_last; di++)
3232 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3233 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap,
3234 0, sc->tulip_txdescmap->dm_mapsize,
3235 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3239 * We need to collect all the mbufs were on the
3240 * receive ring before we reinit it either to put
3241 * them back on or to know if we have to allocate
3244 ri = &sc->tulip_rxinfo;
3245 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3246 ri->ri_free = ri->ri_max;
3247 for (di = ri->ri_first; di < ri->ri_last; di++) {
3249 di->d_length1 = 0; di->d_addr1 = 0;
3250 di->d_length2 = 0; di->d_addr2 = 0;
3252 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3253 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap,
3254 0, sc->tulip_rxdescmap->dm_mapsize,
3255 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3258 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3262 IF_DEQUEUE(&sc->tulip_rxq, m);
3265 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3266 map = M_GETCTX(m, bus_dmamap_t);
3267 bus_dmamap_unload(sc->tulip_dmatag, map);
3268 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3274 * If tulip_reset is being called recurisvely, exit quickly knowing
3275 * that when the outer tulip_reset returns all the right stuff will
3281 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
3282 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
3283 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
3284 |TULIP_STS_RXSTOPPED;
3286 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
3287 (*sc->tulip_boardsw->bd_media_select)(sc);
3288 #if defined(TULIP_DEBUG)
3289 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
3290 printf("%s%d: tulip_reset: additional reset needed?!?\n",
3291 sc->tulip_name, sc->tulip_unit);
3293 tulip_media_print(sc);
3294 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
3295 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
3297 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
3299 tulip_addr_filter(sc);
3304 tulip_softc_t * const sc)
3306 if (sc->tulip_if.if_flags & IFF_UP) {
3307 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
3308 /* initialize the media */
3311 sc->tulip_if.if_flags |= IFF_RUNNING;
3312 if (sc->tulip_if.if_flags & IFF_PROMISC) {
3313 sc->tulip_flags |= TULIP_PROMISC;
3314 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3315 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3317 sc->tulip_flags &= ~TULIP_PROMISC;
3318 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3319 if (sc->tulip_flags & TULIP_ALLMULTI) {
3320 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3322 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3325 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3326 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3328 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3329 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3331 sc->tulip_if.if_flags |= IFF_OACTIVE;
3332 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3333 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3335 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3336 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3337 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3338 tulip_txput_setup(sc);
3340 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3347 tulip_softc_t * const sc)
3349 TULIP_PERFSTART(rxintr)
3350 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
3351 struct ifnet * const ifp = &sc->tulip_if;
3353 #if defined(TULIP_DEBUG)
3358 TULIP_PERFSTART(rxget)
3359 struct ether_header eh;
3360 tulip_desc_t *eop = ri->ri_nextin;
3361 int total_len = 0, last_offset = 0;
3362 struct mbuf *ms = NULL, *me = NULL;
3364 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3369 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3372 #if defined(TULIP_DEBUG)
3373 if (cnt == ri->ri_max)
3377 * If the TULIP has no descriptors, there can't be any receive
3378 * descriptors to process.
3380 if (eop == ri->ri_nextout)
3384 * 90% of the packets will fit in one descriptor. So we optimize
3387 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3388 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3389 IF_DEQUEUE(&sc->tulip_rxq, ms);
3393 * If still owned by the TULIP, don't touch it.
3395 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3399 * It is possible (though improbable unless the BIG_PACKET support
3400 * is enabled or MCLBYTES < 1518) for a received packet to cross
3401 * more than one receive descriptor.
3403 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3404 if (++eop == ri->ri_last)
3406 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3407 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3408 #if defined(TULIP_DEBUG)
3409 sc->tulip_dbg.dbg_rxintrs++;
3410 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3412 TULIP_PERFEND(rxget);
3413 TULIP_PERFEND(rxintr);
3420 * Dequeue the first buffer for the start of the packet. Hopefully
3421 * this will be the only one we need to dequeue. However, if the
3422 * packet consumed multiple descriptors, then we need to dequeue
3423 * those buffers and chain to the starting mbuf. All buffers but
3424 * the last buffer have the same length so we can set that now.
3425 * (we add to last_offset instead of multiplying since we normally
3426 * won't go into the loop and thereby saving a ourselves from
3427 * doing a multiplication by 0 in the normal case).
3429 IF_DEQUEUE(&sc->tulip_rxq, ms);
3430 for (me = ms; total_len > 0; total_len--) {
3431 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3432 map = M_GETCTX(me, bus_dmamap_t);
3433 TULIP_RXMAP_POSTSYNC(sc, map);
3434 bus_dmamap_unload(sc->tulip_dmatag, map);
3435 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3436 #if defined(DIAGNOSTIC)
3439 #endif /* TULIP_BUS_DMA */
3440 me->m_len = TULIP_RX_BUFLEN;
3441 last_offset += TULIP_RX_BUFLEN;
3442 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3448 * Now get the size of received packet (minus the CRC).
3450 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3451 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3452 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3454 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3455 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3456 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3457 TULIP_DSTS_RxOVERFLOW)) == 0)
3460 me->m_len = total_len - last_offset;
3462 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3463 map = M_GETCTX(me, bus_dmamap_t);
3464 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len,
3465 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
3466 bus_dmamap_unload(sc->tulip_dmatag, map);
3467 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3468 #if defined(DIAGNOSTIC)
3471 #endif /* TULIP_BUS_DMA */
3473 eh = *mtod(ms, struct ether_header *);
3474 #if !defined(__DragonFly__) && !defined(__FreeBSD__)
3475 if (sc->tulip_if.if_bpf != NULL) {
3477 bpf_tap(&sc->tulip_if, mtod(ms, caddr_t), total_len);
3479 bpf_mtap(&sc->tulip_if, ms);
3482 sc->tulip_flags |= TULIP_RXACT;
3486 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3487 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3489 #if defined(TULIP_VERBOSE)
3490 const char *error = NULL;
3492 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3493 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3494 #if defined(TULIP_VERBOSE)
3495 error = "frame too long";
3498 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3499 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3500 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3501 #if defined(TULIP_VERBOSE)
3502 error = "alignment error";
3505 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3506 #if defined(TULIP_VERBOSE)
3511 #if defined(TULIP_VERBOSE)
3512 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
3513 printf("%s%d: receive: %6D: %s\n",
3514 sc->tulip_name, sc->tulip_unit,
3515 mtod(ms, u_char *) + 6, ":",
3517 sc->tulip_flags |= TULIP_NOMESSAGES;
3522 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3523 map = M_GETCTX(me, bus_dmamap_t);
3524 bus_dmamap_unload(sc->tulip_dmatag, map);
3525 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3526 #if defined(DIAGNOSTIC)
3529 #endif /* TULIP_BUS_DMA */
3531 #if defined(TULIP_DEBUG)
3535 if (++eop == ri->ri_last)
3537 ri->ri_nextin = eop;
3540 * Either we are priming the TULIP with mbufs (m == NULL)
3541 * or we are about to accept an mbuf for the upper layers
3542 * so we need to allocate an mbuf to replace it. If we
3543 * can't replace it, send up it anyways. This may cause
3544 * us to drop packets in the future but that's better than
3545 * being caught in livelock.
3547 * Note that if this packet crossed multiple descriptors
3548 * we don't even try to reallocate all the mbufs here.
3549 * Instead we rely on the test of the beginning of
3550 * the loop to refill for the extra consumed mbufs.
3552 if (accept || ms == NULL) {
3554 MGETHDR(m0, M_DONTWAIT, MT_DATA);
3556 #if defined(TULIP_COPY_RXDATA)
3557 if (!accept || total_len >= (MHLEN - 2)) {
3559 MCLGET(m0, M_DONTWAIT);
3560 if ((m0->m_flags & M_EXT) == 0) {
3564 #if defined(TULIP_COPY_RXDATA)
3569 #if defined(TULIP_COPY_RXDATA)
3573 #if !defined(TULIP_COPY_RXDATA)
3574 ms->m_pkthdr.len = total_len;
3575 ms->m_pkthdr.rcvif = ifp;
3576 m_adj(ms, sizeof(struct ether_header));
3577 ether_input(ifp, &eh, ms);
3580 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3582 m0->m_data += 2; /* align data after header */
3583 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3584 m0->m_len = m0->m_pkthdr.len = total_len;
3585 m0->m_pkthdr.rcvif = ifp;
3586 m_adj(m0, sizeof(struct ether_header));
3587 ether_input(ifp, &eh, m0);
3589 #endif /* ! TULIP_COPY_RXDATA */
3595 * Couldn't allocate a new buffer. Don't bother
3596 * trying to replenish the receive queue.
3599 sc->tulip_flags |= TULIP_RXBUFSLOW;
3600 #if defined(TULIP_DEBUG)
3601 sc->tulip_dbg.dbg_rxlowbufs++;
3603 TULIP_PERFEND(rxget);
3607 * Now give the buffer(s) to the TULIP and save in our
3611 tulip_desc_t * const nextout = ri->ri_nextout;
3612 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3613 if (sc->tulip_rxmaps_free > 0) {
3614 map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free];
3617 sc->tulip_flags |= TULIP_RXBUFSLOW;
3618 #if defined(TULIP_DEBUG)
3619 sc->tulip_dbg.dbg_rxlowbufs++;
3624 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *),
3625 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT);
3627 printf("%s%d: unable to load rx map, "
3628 "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
3629 panic("tulip_rx_intr"); /* XXX */
3631 nextout->d_addr1 = map->dm_segs[0].ds_addr;
3632 nextout->d_length1 = map->dm_segs[0].ds_len;
3633 if (map->dm_nsegs == 2) {
3634 nextout->d_addr2 = map->dm_segs[1].ds_addr;
3635 nextout->d_length2 = map->dm_segs[1].ds_len;
3637 nextout->d_addr2 = 0;
3638 nextout->d_length2 = 0;
3640 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout));
3641 #else /* TULIP_BUS_DMA */
3642 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3643 nextout->d_length1 = TULIP_RX_BUFLEN;
3644 #endif /* TULIP_BUS_DMA */
3645 nextout->d_status = TULIP_DSTS_OWNER;
3646 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3647 if (++ri->ri_nextout == ri->ri_last)
3648 ri->ri_nextout = ri->ri_first;
3651 IF_ENQUEUE(&sc->tulip_rxq, ms);
3652 } while ((ms = me) != NULL);
3654 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3655 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3656 TULIP_PERFEND(rxget);
3659 #if defined(TULIP_DEBUG)
3660 sc->tulip_dbg.dbg_rxintrs++;
3661 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3663 TULIP_PERFEND(rxintr);
3668 tulip_softc_t * const sc)
3670 TULIP_PERFSTART(txintr)
3671 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3676 while (ri->ri_free < ri->ri_max) {
3679 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3680 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3685 d_flag = ri->ri_nextin->d_flag;
3686 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3687 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3689 * We've just finished processing a setup packet.
3690 * Mark that we finished it. If there's not
3691 * another pending, startup the TULIP receiver.
3692 * Make sure we ack the RXSTOPPED so we won't get
3693 * an abormal interrupt indication.
3695 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3696 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3697 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3698 sc->tulip_flags |= TULIP_HASHONLY;
3699 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3701 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3702 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3703 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3704 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3705 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3708 const u_int32_t d_status = ri->ri_nextin->d_status;
3709 IF_DEQUEUE(&sc->tulip_txq, m);
3711 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3712 bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t);
3713 TULIP_TXMAP_POSTSYNC(sc, map);
3714 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3715 #endif /* TULIP_BUS_DMA */
3717 #if defined(TULIP_DEBUG)
3719 printf("%s%d: tx_intr: failed to dequeue mbuf?!?\n",
3720 sc->tulip_name, sc->tulip_unit);
3723 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3724 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3725 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3726 #if defined(TULIP_DEBUG)
3727 if (d_status & TULIP_DSTS_TxNOCARR)
3728 sc->tulip_dbg.dbg_txprobe_nocarr++;
3729 if (d_status & TULIP_DSTS_TxEXCCOLL)
3730 sc->tulip_dbg.dbg_txprobe_exccoll++;
3732 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3734 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3736 * Escape from the loop before media poll has reset the TULIP!
3741 if (d_status & TULIP_DSTS_ERRSUM) {
3742 sc->tulip_if.if_oerrors++;
3743 if (d_status & TULIP_DSTS_TxEXCCOLL)
3744 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3745 if (d_status & TULIP_DSTS_TxLATECOLL)
3746 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3747 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3748 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3749 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3750 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3751 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3752 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3753 if (d_status & TULIP_DSTS_TxBABBLE)
3754 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3756 u_int32_t collisions =
3757 (d_status & TULIP_DSTS_TxCOLLMASK)
3758 >> TULIP_DSTS_V_TxCOLLCNT;
3759 sc->tulip_if.if_collisions += collisions;
3760 if (collisions == 1)
3761 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3762 else if (collisions > 1)
3763 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3764 else if (d_status & TULIP_DSTS_TxDEFERRED)
3765 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3767 * SQE is only valid for 10baseT/BNC/AUI when not
3768 * running in full-duplex. In order to speed up the
3769 * test, the corresponding bit in tulip_flags needs to
3770 * set as well to get us to count SQE Test Errors.
3772 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3773 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3779 if (++ri->ri_nextin == ri->ri_last)
3780 ri->ri_nextin = ri->ri_first;
3782 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3783 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3786 * If nothing left to transmit, disable the timer.
3787 * Else if progress, reset the timer back to 2 ticks.
3789 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3790 sc->tulip_txtimer = 0;
3792 sc->tulip_txtimer = TULIP_TXTIMER;
3793 sc->tulip_if.if_opackets += xmits;
3794 TULIP_PERFEND(txintr);
3799 tulip_print_abnormal_interrupt(
3800 tulip_softc_t * const sc,
3803 const char * const *msgp = tulip_status_bits;
3806 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3808 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3809 printf("%s%d: abnormal interrupt:", sc->tulip_name, sc->tulip_unit);
3810 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3811 if ((csr & mask) && *msgp != NULL) {
3812 printf("%s%s", sep, *msgp);
3813 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3814 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3815 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3816 printf(" (switching to store-and-forward mode)");
3818 printf(" (raising TX threshold to %s)",
3819 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3830 tulip_softc_t * const sc,
3833 TULIP_PERFSTART(intr)
3836 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3838 TULIP_CSR_WRITE(sc, csr_status, csr);
3840 if (csr & TULIP_STS_SYSERROR) {
3841 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3842 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3843 sc->tulip_flags |= TULIP_SYSTEMERROR;
3845 printf("%s%d: system error: %s\n",
3846 sc->tulip_name, sc->tulip_unit,
3847 tulip_system_errors[sc->tulip_last_system_error]);
3849 sc->tulip_flags |= TULIP_NEEDRESET;
3850 sc->tulip_system_errors++;
3853 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3854 #if defined(TULIP_DEBUG)
3855 sc->tulip_dbg.dbg_link_intrs++;
3857 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3858 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3859 ? TULIP_MEDIAPOLL_LINKFAIL
3860 : TULIP_MEDIAPOLL_LINKPASS);
3861 csr &= ~TULIP_STS_ABNRMLINTR;
3863 tulip_media_print(sc);
3865 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3866 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3867 if (csr & TULIP_STS_RXNOBUF)
3868 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3870 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3871 * on receive overflows.
3873 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3874 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3876 * Stop the receiver process and spin until it's stopped.
3877 * Tell rx_intr to drop the packets it dequeues.
3879 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3880 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3882 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3883 sc->tulip_flags |= TULIP_RXIGNORE;
3886 if (sc->tulip_flags & TULIP_RXIGNORE) {
3888 * Restart the receiver.
3890 sc->tulip_flags &= ~TULIP_RXIGNORE;
3891 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3894 if (csr & TULIP_STS_ABNRMLINTR) {
3895 u_int32_t tmp = csr & sc->tulip_intrmask
3896 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3897 if (csr & TULIP_STS_TXUNDERFLOW) {
3898 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3899 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3900 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3901 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3902 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3903 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3906 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3907 sc->tulip_statusbits |= tmp;
3909 tulip_print_abnormal_interrupt(sc, tmp);
3910 sc->tulip_flags |= TULIP_NOMESSAGES;
3912 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3914 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3916 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3917 tulip_ifstart(&sc->tulip_if);
3920 if (sc->tulip_flags & TULIP_NEEDRESET) {
3924 TULIP_PERFEND(intr);
3927 #if defined(TULIP_USE_SOFTINTR)
3929 * This is a experimental idea to alleviate problems due to interrupt
3930 * livelock. What is interrupt livelock? It's when you spend all your
3931 * time servicing device interrupts and never drop below device ipl
3932 * to do "useful" work.
3934 * So what we do here is see if the device needs service and if so,
3935 * disable interrupts (dismiss the interrupt), place it in a list of devices
3936 * needing service, and issue a network software interrupt.
3938 * When our network software interrupt routine gets called, we simply
3939 * walk done the list of devices that we have created and deal with them
3940 * at splnet/splsoftnet.
3944 tulip_hardintr_handler(
3945 tulip_softc_t * const sc,
3948 if (TULIP_CSR_READ(sc, csr_status) & (TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR) == 0)
3952 * disable interrupts
3954 TULIP_CSR_WRITE(sc, csr_intr, 0);
3956 * mark it as needing a software interrupt
3958 tulip_softintr_mask |= (1U << sc->tulip_unit);
3965 u_int32_t softintr_mask, mask;
3971 * Copy mask to local copy and reset global one to 0.
3974 softintr_mask = tulip_softintr_mask;
3975 tulip_softintr_mask = 0;
3979 * Optimize for the single unit case.
3981 if (tulip_softintr_max_unit == 0) {
3982 if (softintr_mask & 1) {
3983 tulip_softc_t * const sc = tulips[0];
3985 * Handle the "interrupt" and then reenable interrupts
3988 tulip_intr_handler(sc, &progress);
3989 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3995 * Handle all "queued" interrupts in a round robin fashion.
3996 * This is done so as not to favor a particular interface.
3998 unit = tulip_softintr_last_unit;
3999 mask = (1U << unit);
4000 while (softintr_mask != 0) {
4001 if (tulip_softintr_max_unit == unit) {
4004 unit += 1; mask <<= 1;
4006 if (softintr_mask & mask) {
4007 tulip_softc_t * const sc = tulips[unit];
4009 * Handle the "interrupt" and then reenable interrupts
4011 softintr_mask ^= mask;
4012 tulip_intr_handler(sc, &progress);
4013 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4018 * Save where we ending up.
4020 tulip_softintr_last_unit = unit;
4022 #endif /* TULIP_USE_SOFTINTR */
4028 tulip_softc_t * sc = arg;
4031 for (; sc != NULL; sc = sc->tulip_slaves) {
4032 #if defined(TULIP_DEBUG)
4033 sc->tulip_dbg.dbg_intrs++;
4035 #if defined(TULIP_USE_SOFTINTR)
4036 tulip_hardintr_handler(sc, &progress);
4038 tulip_intr_handler(sc, &progress);
4041 #if defined(TULIP_USE_SOFTINTR)
4043 schednetisr(NETISR_DE);
4051 tulip_softc_t * sc = (tulip_softc_t *) arg;
4054 #if defined(TULIP_DEBUG)
4055 sc->tulip_dbg.dbg_intrs++;
4057 #if defined(TULIP_USE_SOFTINTR)
4058 tulip_hardintr_handler(sc, &progress);
4060 schednetisr(NETISR_DE);
4062 tulip_intr_handler(sc, &progress);
4066 static struct mbuf *
4067 tulip_mbuf_compress(
4071 #if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET)
4072 MGETHDR(m0, M_DONTWAIT, MT_DATA);
4074 if (m->m_pkthdr.len > MHLEN) {
4075 MCLGET(m0, M_DONTWAIT);
4076 if ((m0->m_flags & M_EXT) == 0) {
4082 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
4083 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
4087 int len = m->m_pkthdr.len;
4088 struct mbuf **mp = &m0;
4091 if (mlen == MHLEN) {
4092 MGETHDR(*mp, M_DONTWAIT, MT_DATA);
4094 MGET(*mp, M_DONTWAIT, MT_DATA);
4102 MCLGET(*mp, M_DONTWAIT);
4103 if (((*mp)->m_flags & M_EXT) == 0) {
4108 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
4110 (*mp)->m_len = len <= mlen ? len : mlen;
4112 m_copydata(m, m->m_pkthdr.len - len,
4113 (*mp)->m_len, mtod((*mp), caddr_t));
4114 len -= (*mp)->m_len;
4115 mp = &(*mp)->m_next;
4123 static struct mbuf *
4125 tulip_softc_t * const sc,
4128 TULIP_PERFSTART(txput)
4129 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4130 tulip_desc_t *eop, *nextout;
4133 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4140 #if defined(TULIP_DEBUG)
4141 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4142 printf("%s%d: txput%s: tx not running\n",
4143 sc->tulip_name, sc->tulip_unit,
4144 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
4145 sc->tulip_flags |= TULIP_WANTTXSTART;
4146 sc->tulip_dbg.dbg_txput_finishes[0]++;
4152 * Now we try to fill in our transmit descriptors. This is
4153 * a bit reminiscent of going on the Ark two by two
4154 * since each descriptor for the TULIP can describe
4155 * two buffers. So we advance through packet filling
4156 * each of the two entries at a time to to fill each
4157 * descriptor. Clear the first and last segment bits
4158 * in each descriptor (actually just clear everything
4159 * but the end-of-ring or chain bits) to make sure
4160 * we don't get messed up by previously sent packets.
4162 * We may fail to put the entire packet on the ring if
4163 * there is either not enough ring entries free or if the
4164 * packet has more than MAX_TXSEG segments. In the former
4165 * case we will just wait for the ring to empty. In the
4166 * latter case we have to recopy.
4168 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4173 eop = nextout = ri->ri_nextout;
4177 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4179 * Reclaim some dma maps from if we are out.
4181 if (sc->tulip_txmaps_free == 0) {
4182 #if defined(TULIP_DEBUG)
4183 sc->tulip_dbg.dbg_no_txmaps++;
4185 free += tulip_tx_intr(sc);
4187 if (sc->tulip_txmaps_free > 0) {
4188 map = sc->tulip_txmaps[sc->tulip_txmaps_free-1];
4190 sc->tulip_flags |= TULIP_WANTTXSTART;
4191 #if defined(TULIP_DEBUG)
4192 sc->tulip_dbg.dbg_txput_finishes[1]++;
4196 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4198 if (error == EFBIG) {
4200 * The packet exceeds the number of transmit buffer
4201 * entries that we can use for one packet, so we have
4202 * to recopy it into one mbuf and then try again.
4204 m = tulip_mbuf_compress(m);
4206 #if defined(TULIP_DEBUG)
4207 sc->tulip_dbg.dbg_txput_finishes[2]++;
4211 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4214 printf("%s%d: unable to load tx map, "
4215 "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
4216 #if defined(TULIP_DEBUG)
4217 sc->tulip_dbg.dbg_txput_finishes[3]++;
4222 if ((free -= (map->dm_nsegs + 1) / 2) <= 0
4224 * See if there's any unclaimed space in the transmit ring.
4226 && (free += tulip_tx_intr(sc)) <= 0) {
4228 * There's no more room but since nothing
4229 * has been committed at this point, just
4230 * show output is active, put back the
4233 sc->tulip_flags |= TULIP_WANTTXSTART;
4234 #if defined(TULIP_DEBUG)
4235 sc->tulip_dbg.dbg_txput_finishes[4]++;
4237 bus_dmamap_unload(sc->tulip_dmatag, map);
4240 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) {
4242 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4243 eop->d_status = d_status;
4244 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4245 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4246 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr;
4247 eop->d_length2 = map->dm_segs[segcnt+1].ds_len;
4248 d_status = TULIP_DSTS_OWNER;
4249 if (++nextout == ri->ri_last)
4250 nextout = ri->ri_first;
4252 if (segcnt < map->dm_nsegs) {
4254 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4255 eop->d_status = d_status;
4256 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4257 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4260 if (++nextout == ri->ri_last)
4261 nextout = ri->ri_first;
4263 TULIP_TXMAP_PRESYNC(sc, map);
4266 --sc->tulip_txmaps_free; /* commit to using the dmamap */
4268 #else /* !TULIP_BUS_DMA */
4271 int len = m0->m_len;
4272 caddr_t addr = mtod(m0, caddr_t);
4273 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
4276 unsigned slen = min(len, clsize);
4280 slen = 2040, partial = 1;
4283 if (segcnt > TULIP_MAX_TXSEG) {
4285 * The packet exceeds the number of transmit buffer
4286 * entries that we can use for one packet, so we have
4287 * recopy it into one mbuf and then try again.
4289 m = tulip_mbuf_compress(m);
4297 * See if there's any unclaimed space in the
4300 if ((free += tulip_tx_intr(sc)) == 0) {
4302 * There's no more room but since nothing
4303 * has been committed at this point, just
4304 * show output is active, put back the
4307 sc->tulip_flags |= TULIP_WANTTXSTART;
4308 #if defined(TULIP_DEBUG)
4309 sc->tulip_dbg.dbg_txput_finishes[1]++;
4315 if (++nextout == ri->ri_last)
4316 nextout = ri->ri_first;
4317 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4318 eop->d_status = d_status;
4319 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
4320 eop->d_length1 = slen;
4323 * Fill in second half of descriptor
4325 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
4326 eop->d_length2 = slen;
4328 d_status = TULIP_DSTS_OWNER;
4337 } while ((m0 = m0->m_next) != NULL);
4338 #endif /* TULIP_BUS_DMA */
4341 * bounce a copy to the bpf listener, if any.
4343 if (sc->tulip_if.if_bpf != NULL)
4344 bpf_mtap(&sc->tulip_if, m);
4347 * The descriptors have been filled in. Now get ready
4350 IF_ENQUEUE(&sc->tulip_txq, m);
4354 * Make sure the next descriptor after this packet is owned
4355 * by us since it may have been set up above if we ran out
4356 * of room in the ring.
4358 nextout->d_status = 0;
4359 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4361 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4363 * If we only used the first segment of the last descriptor,
4364 * make sure the second segment will not be used.
4370 #endif /* TULIP_BUS_DMA */
4373 * Mark the last and first segments, indicate we want a transmit
4374 * complete interrupt, and tell it to transmit!
4376 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
4379 * Note that ri->ri_nextout is still the start of the packet
4380 * and until we set the OWNER bit, we can still back out of
4381 * everything we have done.
4383 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
4384 #if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX)
4385 if (eop < ri->ri_nextout) {
4386 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4387 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout);
4388 TULIP_TXDESC_PRESYNC(sc, ri->ri_first,
4389 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first);
4391 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4392 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout);
4395 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
4396 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4399 * This advances the ring for us.
4401 ri->ri_nextout = nextout;
4404 TULIP_PERFEND(txput);
4406 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
4407 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4408 sc->tulip_if.if_flags |= IFF_OACTIVE;
4409 sc->tulip_if.if_start = tulip_ifstart;
4410 TULIP_PERFEND(txput);
4415 * switch back to the single queueing ifstart.
4417 sc->tulip_flags &= ~TULIP_WANTTXSTART;
4418 if (sc->tulip_txtimer == 0)
4419 sc->tulip_txtimer = TULIP_TXTIMER;
4420 #if defined(TULIP_DEBUG)
4421 sc->tulip_dbg.dbg_txput_finishes[5]++;
4425 * If we want a txstart, there must be not enough space in the
4426 * transmit ring. So we want to enable transmit done interrupts
4427 * so we can immediately reclaim some space. When the transmit
4428 * interrupt is posted, the interrupt handler will call tx_intr
4429 * to reclaim space and then txstart (since WANTTXSTART is set).
4430 * txstart will move the packet into the transmit ring and clear
4431 * WANTTXSTART thereby causing TXINTR to be cleared.
4434 #if defined(TULIP_DEBUG)
4435 sc->tulip_dbg.dbg_txput_finishes[6]++;
4437 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
4438 sc->tulip_if.if_flags |= IFF_OACTIVE;
4439 sc->tulip_if.if_start = tulip_ifstart;
4440 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4441 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4442 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4444 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
4445 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
4446 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
4447 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4450 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4451 TULIP_PERFEND(txput);
4457 tulip_softc_t * const sc)
4459 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4460 tulip_desc_t *nextout;
4463 * We will transmit, at most, one setup packet per call to ifstart.
4466 #if defined(TULIP_DEBUG)
4467 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4468 printf("%s%d: txput_setup: tx not running\n",
4469 sc->tulip_name, sc->tulip_unit);
4470 sc->tulip_flags |= TULIP_WANTTXSTART;
4471 sc->tulip_if.if_start = tulip_ifstart;
4476 * Try to reclaim some free descriptors..
4478 if (ri->ri_free < 2)
4480 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
4481 sc->tulip_flags |= TULIP_WANTTXSTART;
4482 sc->tulip_if.if_start = tulip_ifstart;
4485 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
4486 sizeof(sc->tulip_setupbuf));
4488 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
4489 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
4491 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
4493 nextout = ri->ri_nextout;
4494 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4495 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
4496 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
4497 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
4498 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
4499 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
4500 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
4502 nextout->d_length2 = 0;
4503 nextout->d_addr2 = 0;
4504 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4505 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len;
4506 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr;
4507 if (sc->tulip_setupmap->dm_nsegs == 2) {
4508 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len;
4509 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr;
4511 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap);
4512 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout));
4514 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
4515 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
4519 * Advance the ring for the next transmit packet.
4521 if (++ri->ri_nextout == ri->ri_last)
4522 ri->ri_nextout = ri->ri_first;
4525 * Make sure the next descriptor is owned by us since it
4526 * may have been set up above if we ran out of room in the
4529 ri->ri_nextout->d_status = 0;
4530 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4531 nextout->d_status = TULIP_DSTS_OWNER;
4533 * Flush the ownwership of the current descriptor
4535 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4536 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4537 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4538 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4539 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4545 * This routine is entered at splnet() (splsoftnet() on NetBSD)
4546 * and thereby imposes no problems when TULIP_USE_SOFTINTR is
4556 TULIP_PERFSTART(ifioctl)
4557 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4558 struct ifaddr *ifa = (struct ifaddr *)data;
4559 struct ifreq *ifr = (struct ifreq *) data;
4563 #if defined(TULIP_USE_SOFTINTR)
4570 ifp->if_flags |= IFF_UP;
4571 switch(ifa->ifa_addr->sa_family) {
4575 arp_ifinit(&(sc)->tulip_ac.ac_if, ifa);
4582 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
4583 if (ipx_nullhost(*ina)) {
4584 ina->x_host = *(union ipx_host *)(sc->tulip_enaddr);
4586 ifp->if_flags &= ~IFF_RUNNING;
4587 bcopy((caddr_t)ina->x_host.c_host,
4588 (caddr_t)sc->tulip_enaddr,
4589 sizeof(sc->tulip_enaddr));
4598 * This magic copied from if_is.c; I don't use XNS,
4599 * so I have no way of telling if this actually
4603 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
4604 if (ns_nullhost(*ina)) {
4605 ina->x_host = *(union ns_host *)(sc->tulip_enaddr);
4607 ifp->if_flags &= ~IFF_RUNNING;
4608 bcopy((caddr_t)ina->x_host.c_host,
4609 (caddr_t)sc->tulip_enaddr,
4610 sizeof(sc->tulip_enaddr));
4625 bcopy((caddr_t) sc->tulip_enaddr,
4626 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
4631 case SIOCSIFFLAGS: {
4632 tulip_addr_filter(sc); /* reinit multicast filter */
4638 case SIOCGIFMEDIA: {
4639 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
4644 case SIOCDELMULTI: {
4646 * Update multicast listeners
4648 tulip_addr_filter(sc); /* reset multicast filtering */
4656 * Set the interface MTU.
4658 if (ifr->ifr_mtu > ETHERMTU
4660 && sc->tulip_chipid != TULIP_21140
4661 && sc->tulip_chipid != TULIP_21140A
4662 && sc->tulip_chipid != TULIP_21041
4668 ifp->if_mtu = ifr->ifr_mtu;
4676 case SIOCGADDRROM: {
4677 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
4683 ifr->ifr_metric = (int) sc->tulip_chipid;
4694 TULIP_PERFEND(ifioctl);
4699 * These routines gets called at device spl (from ether_output). This might
4700 * pose a problem for TULIP_USE_SOFTINTR if ether_output is called at
4701 * device spl from another driver.
4706 struct ifnet * const ifp)
4708 TULIP_PERFSTART(ifstart)
4709 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4711 if (sc->tulip_if.if_flags & IFF_RUNNING) {
4713 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
4714 tulip_txput_setup(sc);
4716 while (sc->tulip_if.if_snd.ifq_head != NULL) {
4718 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
4719 if ((m = tulip_txput(sc, m)) != NULL) {
4720 IF_PREPEND(&sc->tulip_if.if_snd, m);
4724 if (sc->tulip_if.if_snd.ifq_head == NULL)
4725 sc->tulip_if.if_start = tulip_ifstart_one;
4728 TULIP_PERFEND(ifstart);
4733 struct ifnet * const ifp)
4735 TULIP_PERFSTART(ifstart_one)
4736 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4738 if ((sc->tulip_if.if_flags & IFF_RUNNING)
4739 && sc->tulip_if.if_snd.ifq_head != NULL) {
4741 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
4742 if ((m = tulip_txput(sc, m)) != NULL)
4743 IF_PREPEND(&sc->tulip_if.if_snd, m);
4745 TULIP_PERFEND(ifstart_one);
4749 * Even though this routine runs at device spl, it does not break
4750 * our use of splnet (splsoftnet under NetBSD) for the majority
4751 * of this driver (if TULIP_USE_SOFTINTR defined) since
4752 * if_watcbog is called from if_watchdog which is called from
4753 * splsoftclock which is below spl[soft]net.
4759 TULIP_PERFSTART(ifwatchdog)
4760 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4762 #if defined(TULIP_DEBUG)
4763 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
4764 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
4765 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
4766 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
4767 #endif /* TULIP_DEBUG */
4769 sc->tulip_if.if_timer = 1;
4771 * These should be rare so do a bulk test up front so we can just skip
4774 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
4776 * If the number of receive buffer is low, try to refill
4778 if (sc->tulip_flags & TULIP_RXBUFSLOW)
4781 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
4782 printf("%s%d: %d system errors: last was %s\n",
4783 sc->tulip_name, sc->tulip_unit, sc->tulip_system_errors,
4784 tulip_system_errors[sc->tulip_last_system_error]);
4786 if (sc->tulip_statusbits) {
4787 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
4788 sc->tulip_statusbits = 0;
4791 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
4794 if (sc->tulip_txtimer)
4796 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
4797 printf("%s%d: transmission timeout\n", sc->tulip_name, sc->tulip_unit);
4798 if (TULIP_DO_AUTOSENSE(sc)) {
4799 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4800 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
4801 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
4807 TULIP_PERFEND(ifwatchdog);
4808 TULIP_PERFMERGE(sc, perf_intr_cycles);
4809 TULIP_PERFMERGE(sc, perf_ifstart_cycles);
4810 TULIP_PERFMERGE(sc, perf_ifioctl_cycles);
4811 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles);
4812 TULIP_PERFMERGE(sc, perf_timeout_cycles);
4813 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles);
4814 TULIP_PERFMERGE(sc, perf_txput_cycles);
4815 TULIP_PERFMERGE(sc, perf_txintr_cycles);
4816 TULIP_PERFMERGE(sc, perf_rxintr_cycles);
4817 TULIP_PERFMERGE(sc, perf_rxget_cycles);
4818 TULIP_PERFMERGE(sc, perf_intr);
4819 TULIP_PERFMERGE(sc, perf_ifstart);
4820 TULIP_PERFMERGE(sc, perf_ifioctl);
4821 TULIP_PERFMERGE(sc, perf_ifwatchdog);
4822 TULIP_PERFMERGE(sc, perf_timeout);
4823 TULIP_PERFMERGE(sc, perf_ifstart_one);
4824 TULIP_PERFMERGE(sc, perf_txput);
4825 TULIP_PERFMERGE(sc, perf_txintr);
4826 TULIP_PERFMERGE(sc, perf_rxintr);
4827 TULIP_PERFMERGE(sc, perf_rxget);
4831 * All printf's are real as of now!
4839 tulip_softc_t * const sc)
4841 struct ifnet * const ifp = &sc->tulip_if;
4843 if_initname(ifp, sc->tulip_name, sc->tulip_unit);
4844 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
4845 ifp->if_ioctl = tulip_ifioctl;
4846 ifp->if_start = tulip_ifstart;
4847 ifp->if_watchdog = tulip_ifwatchdog;
4849 ifp->if_output = ether_output;
4851 printf("%s%d: %s%s pass %d.%d%s\n",
4852 sc->tulip_name, sc->tulip_unit,
4854 tulip_chipdescs[sc->tulip_chipid],
4855 (sc->tulip_revinfo & 0xF0) >> 4,
4856 sc->tulip_revinfo & 0x0F,
4857 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
4858 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
4859 printf("%s%d: address %6D\n",
4860 sc->tulip_name, sc->tulip_unit, sc->tulip_enaddr, ":");
4862 #if defined(__alpha__)
4864 * In case the SRM console told us about a bogus media,
4865 * we need to check to be safe.
4867 if (sc->tulip_mediums[sc->tulip_media] == NULL)
4868 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4871 (*sc->tulip_boardsw->bd_media_probe)(sc);
4872 ifmedia_init(&sc->tulip_ifmedia, 0,
4873 tulip_ifmedia_change,
4874 tulip_ifmedia_status);
4875 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
4876 tulip_ifmedia_add(sc);
4880 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr);
4881 ifp->if_snd.ifq_maxlen = ifqmaxlen;
4884 #if defined(TULIP_BUS_DMA)
4885 #if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX)
4887 tulip_busdma_allocmem(
4888 tulip_softc_t * const sc,
4890 bus_dmamap_t *map_p,
4891 tulip_desc_t **desc_p)
4893 bus_dma_segment_t segs[1];
4895 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE,
4896 segs, sizeof(segs)/sizeof(segs[0]),
4897 &nsegs, BUS_DMA_NOWAIT);
4900 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size,
4901 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
4904 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0,
4905 BUS_DMA_NOWAIT, &map);
4907 error = bus_dmamap_load(sc->tulip_dmatag, map, desc,
4908 size, NULL, BUS_DMA_NOWAIT);
4910 bus_dmamap_destroy(sc->tulip_dmatag, map);
4915 bus_dmamem_unmap(sc->tulip_dmatag, desc, size);
4918 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs);
4928 tulip_softc_t * const sc)
4932 #if !defined(TULIP_BUS_DMA_NOTX)
4934 * Allocate dmamap for setup descriptor
4936 error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2,
4937 sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT,
4938 &sc->tulip_setupmap);
4940 error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap,
4941 sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf),
4942 NULL, BUS_DMA_NOWAIT);
4944 bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap);
4947 * Allocate space and dmamap for transmit ring
4950 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS,
4951 &sc->tulip_txdescmap,
4952 &sc->tulip_txdescs);
4956 * Allocate dmamaps for each transmit descriptors
4959 while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) {
4961 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0)
4962 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
4965 while (sc->tulip_txmaps_free > 0)
4966 bus_dmamap_destroy(sc->tulip_dmatag,
4967 sc->tulip_txmaps[--sc->tulip_txmaps_free]);
4972 sc->tulip_txdescs = malloc(TULIP_TXDESCS * sizeof(tulip_desc_t),
4973 M_DEVBUF, M_INTWAIT);
4976 #if !defined(TULIP_BUS_DMA_NORX)
4978 * Allocate space and dmamap for receive ring
4981 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS,
4982 &sc->tulip_rxdescmap,
4983 &sc->tulip_rxdescs);
4987 * Allocate dmamaps for each receive descriptors
4990 while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) {
4992 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0)
4993 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
4996 while (sc->tulip_rxmaps_free > 0)
4997 bus_dmamap_destroy(sc->tulip_dmatag,
4998 sc->tulip_rxmaps[--sc->tulip_rxmaps_free]);
5003 sc->tulip_rxdescs = malloc(TULIP_RXDESCS * sizeof(tulip_desc_t),
5004 M_DEVBUF, M_INTWAIT);
5009 #endif /* TULIP_BUS_DMA */
5013 tulip_softc_t * const sc,
5014 tulip_csrptr_t csr_base,
5017 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
5018 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
5019 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
5020 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
5021 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
5022 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
5023 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
5024 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
5025 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
5026 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
5027 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
5028 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
5029 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
5030 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
5031 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
5032 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
5037 tulip_softc_t * const sc,
5038 tulip_ringinfo_t * const ri,
5039 tulip_desc_t *descs,
5042 ri->ri_max = ndescs;
5043 ri->ri_first = descs;
5044 ri->ri_last = ri->ri_first + ri->ri_max;
5045 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
5046 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
5050 * This is the PCI configuration support.
5053 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
5054 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
5055 #define PCI_CFDA 0x40 /* Configuration Driver Area */
5058 tulip_pci_probe(device_t dev)
5060 const char *name = NULL;
5062 if (pci_get_vendor(dev) != DEC_VENDORID)
5066 * Some LanMedia WAN cards use the Tulip chip, but they have
5067 * their own driver, and we should not recognize them
5069 if (pci_get_subvendor(dev) == 0x1376)
5072 switch (pci_get_device(dev)) {
5074 name = "Digital 21040 Ethernet";
5077 name = "Digital 21041 Ethernet";
5080 if (pci_get_revid(dev) >= 0x20)
5081 name = "Digital 21140A Fast Ethernet";
5083 name = "Digital 21140 Fast Ethernet";
5086 if (pci_get_revid(dev) >= 0x20)
5087 name = "Digital 21143 Fast Ethernet";
5089 name = "Digital 21142 Fast Ethernet";
5093 device_set_desc(dev, name);
5100 tulip_shutdown(device_t dev)
5102 tulip_softc_t * const sc = device_get_softc(dev);
5103 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
5104 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
5105 33MHz that comes to two microseconds but wait a
5106 bit longer anyways) */
5111 tulip_pci_attach(device_t dev)
5114 #if defined(__alpha__)
5115 tulip_media_t media = TULIP_MEDIA_UNKNOWN;
5118 u_int32_t revinfo, cfdainfo, cfcsinfo;
5119 unsigned csroffset = TULIP_PCI_CSROFFSET;
5120 unsigned csrsize = TULIP_PCI_CSRSIZE;
5121 tulip_csrptr_t csr_base;
5122 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
5123 struct resource *res;
5126 unit = device_get_unit(dev);
5128 if (unit >= TULIP_MAX_DEVICES) {
5129 printf("de%d", unit);
5130 printf(": not configured; limit of %d reached or exceeded\n",
5135 revinfo = pci_get_revid(dev);
5136 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
5137 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
5139 /* turn busmaster on in case BIOS doesn't set it */
5140 if(!(cfcsinfo & PCIM_CMD_BUSMASTEREN)) {
5141 cfcsinfo |= PCIM_CMD_BUSMASTEREN;
5142 pci_write_config(dev, PCIR_COMMAND, cfcsinfo, 4);
5145 if (pci_get_vendor(dev) == DEC_VENDORID) {
5146 if (pci_get_device(dev) == CHIPID_21040)
5147 chipid = TULIP_21040;
5148 else if (pci_get_device(dev) == CHIPID_21041)
5149 chipid = TULIP_21041;
5150 else if (pci_get_device(dev) == CHIPID_21140)
5151 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
5152 else if (pci_get_device(dev) == CHIPID_21142)
5153 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
5155 if (chipid == TULIP_CHIPID_UNKNOWN)
5158 if (chipid == TULIP_21040 && revinfo < 0x20) {
5159 printf("de%d", unit);
5160 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
5161 revinfo >> 4, revinfo & 0x0f);
5163 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
5164 printf("de%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
5165 unit, revinfo >> 4, revinfo & 0x0f);
5169 sc = device_get_softc(dev);
5170 sc->tulip_pci_busno = pci_get_bus(dev);
5171 sc->tulip_pci_devno = pci_get_slot(dev);
5172 sc->tulip_chipid = chipid;
5173 sc->tulip_flags |= TULIP_DEVICEPROBE;
5174 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
5175 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
5176 if (chipid == TULIP_21140A && revinfo <= 0x22)
5177 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
5178 if (chipid == TULIP_21140)
5179 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
5180 if (chipid != TULIP_21040 && chipid != TULIP_21140)
5181 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
5182 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
5183 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
5184 if (chipid != TULIP_21041 || revinfo >= 0x20)
5185 sc->tulip_features |= TULIP_HAVE_SIANWAY;
5186 if (chipid != TULIP_21041)
5187 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
5188 if (chipid != TULIP_21041 && revinfo >= 0x20)
5189 sc->tulip_features |= TULIP_HAVE_SIA100;
5192 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
5193 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
5194 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
5195 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
5198 #if defined(__alpha__)
5200 * The Alpha SRM console encodes a console set media in the driver
5201 * part of the CFDA register. Note that the Multia presents a
5202 * problem in that its BNC mode is really EXTSIA. So in that case
5205 switch ((cfdainfo >> 8) & 0xff) {
5206 case 1: media = chipid > TULIP_21040 ? TULIP_MEDIA_AUI : TULIP_MEDIA_AUIBNC; break;
5207 case 2: media = chipid > TULIP_21040 ? TULIP_MEDIA_BNC : TULIP_MEDIA_UNKNOWN; break;
5208 case 3: media = TULIP_MEDIA_10BASET; break;
5209 case 4: media = TULIP_MEDIA_10BASET_FD; break;
5210 case 5: media = TULIP_MEDIA_100BASETX; break;
5211 case 6: media = TULIP_MEDIA_100BASETX_FD; break;
5212 default: media = TULIP_MEDIA_UNKNOWN; break;
5216 sc->tulip_unit = unit;
5217 sc->tulip_name = "de";
5218 sc->tulip_revinfo = revinfo;
5219 sc->tulip_if.if_softc = sc;
5220 #if defined(TULIP_IOMAPPED)
5222 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
5223 0, ~0, 1, RF_ACTIVE);
5226 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
5227 0, ~0, 1, RF_ACTIVE);
5231 sc->tulip_csrs_bst = rman_get_bustag(res);
5232 sc->tulip_csrs_bsh = rman_get_bushandle(res);
5237 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
5239 #if defined(TULIP_BUS_DMA)
5240 if ((retval = tulip_busdma_init(sc)) != 0) {
5241 printf("error initing bus_dma: %d\n", retval);
5245 sc->tulip_rxdescs = malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
5246 M_DEVBUF, M_INTWAIT);
5247 sc->tulip_txdescs = malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
5248 M_DEVBUF, M_INTWAIT);
5251 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
5252 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
5255 * Make sure there won't be any interrupts or such...
5257 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
5258 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
5259 33MHz that comes to two microseconds but wait a
5260 bit longer anyways) */
5262 if ((retval = tulip_read_macaddr(sc)) < 0) {
5263 printf("%s%d", sc->tulip_name, sc->tulip_unit);
5264 printf(": can't read ENET ROM (why=%d) (", retval);
5265 for (idx = 0; idx < 32; idx++)
5266 printf("%02x", sc->tulip_rombuf[idx]);
5268 printf("%s%d: %s%s pass %d.%d\n",
5269 sc->tulip_name, sc->tulip_unit,
5270 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
5271 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
5272 printf("%s%d: address unknown\n", sc->tulip_name, sc->tulip_unit);
5275 void (*intr_rtn)(void *) = tulip_intr_normal;
5277 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
5278 intr_rtn = tulip_intr_shared;
5280 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
5284 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
5285 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
5286 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
5287 intr_rtn, sc, &ih)) {
5288 printf("%s%d: couldn't map interrupt\n",
5289 sc->tulip_name, sc->tulip_unit);
5290 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
5291 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
5295 #if defined(TULIP_USE_SOFTINTR)
5296 if (sc->tulip_unit > tulip_softintr_max_unit)
5297 tulip_softintr_max_unit = sc->tulip_unit;
5301 #if defined(__alpha__)
5302 sc->tulip_media = media;
5305 #if defined(__alpha__)
5306 if (sc->tulip_media != TULIP_MEDIA_UNKNOWN)
5307 tulip_linkup(sc, media);
5314 static device_method_t tulip_pci_methods[] = {
5315 /* Device interface */
5316 DEVMETHOD(device_probe, tulip_pci_probe),
5317 DEVMETHOD(device_attach, tulip_pci_attach),
5318 DEVMETHOD(device_shutdown, tulip_shutdown),
5321 static driver_t tulip_pci_driver = {
5324 sizeof(tulip_softc_t),
5326 static devclass_t tulip_devclass;
5328 DECLARE_DUMMY_MODULE(if_de);
5329 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);