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.25 2005/02/21 05:03:51 joerg Exp $ */
7 * Copyright (c) 1994-1997 Matt Thomas (matt@3am-software.com)
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software withough specific prior written permission
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * Id: if_de.c,v 1.94 1997/07/03 16:55:07 thomas Exp
34 * DEC 21040 PCI Ethernet Controller
36 * Written by Matt Thomas
37 * BPF support code stolen directly from if_ec.c
39 * This driver supports the DEC DE435 or any other PCI
40 * board which support 21040, 21041, or 21140 (mostly).
43 #include <sys/param.h>
44 #include <sys/systm.h>
46 #include <sys/socket.h>
47 #include <sys/sockio.h>
48 #include <sys/malloc.h>
49 #include <sys/kernel.h>
50 #include <sys/eventhandler.h>
51 #include <machine/clock.h>
52 #include <machine/bus.h>
53 #include <machine/resource.h>
61 #include <net/if_media.h>
62 #include <net/if_dl.h>
67 #include <netinet/in.h>
68 #include <netinet/if_ether.h>
72 #include <netproto/ipx/ipx.h>
73 #include <netproto/ipx/ipx_if.h>
77 #include <netproto/ns/ns.h>
78 #include <netproto/ns/ns_if.h>
83 #include <net/if_var.h>
85 #include <bus/pci/pcivar.h>
86 #include <bus/pci/pcireg.h>
87 #include <bus/pci/dc21040reg.h>
90 * Intel CPUs should use I/O mapped access.
93 #define TULIP_IOMAPPED
98 * This turns on all sort of debugging stuff and make the
105 #define TULIP_PERFSTATS
110 #include "if_devar.h"
113 * This module supports
114 * the DEC 21040 PCI Ethernet Controller.
115 * the DEC 21041 PCI Ethernet Controller.
116 * the DEC 21140 PCI Fast Ethernet Controller.
118 static void tulip_mii_autonegotiate(tulip_softc_t * const sc, const unsigned phyaddr);
119 static void tulip_intr_shared(void *arg);
120 static void tulip_intr_normal(void *arg);
121 static void tulip_init(tulip_softc_t * const sc);
122 static void tulip_reset(tulip_softc_t * const sc);
123 static void tulip_ifstart(struct ifnet *ifp);
124 static struct mbuf *tulip_txput(tulip_softc_t * const sc, struct mbuf *m);
125 static void tulip_txput_setup(tulip_softc_t * const sc);
126 static void tulip_rx_intr(tulip_softc_t * const sc);
127 static void tulip_addr_filter(tulip_softc_t * const sc);
128 static unsigned tulip_mii_readreg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno);
129 static void tulip_mii_writereg(tulip_softc_t * const sc, unsigned devaddr, unsigned regno, unsigned data);
130 static int tulip_mii_map_abilities(tulip_softc_t * const sc, unsigned abilities);
131 static tulip_media_t tulip_mii_phy_readspecific(tulip_softc_t * const sc);
132 static int tulip_srom_decode(tulip_softc_t * const sc);
133 static int tulip_ifmedia_change(struct ifnet * const ifp);
134 static void tulip_ifmedia_status(struct ifnet * const ifp, struct ifmediareq *req);
135 /* static void tulip_21140_map_media(tulip_softc_t *sc); */
138 tulip_timeout_callback(
141 tulip_softc_t * const sc = arg;
144 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
145 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
146 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
152 tulip_softc_t * const sc)
154 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
156 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
157 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
158 tulip_timeout_callback, sc);
161 #if defined(TULIP_NEED_FASTTIMEOUT)
163 tulip_fasttimeout_callback(
166 tulip_softc_t * const sc = arg;
169 sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING;
170 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER);
176 tulip_softc_t * const sc)
178 if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING)
180 sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING;
181 callout_reset(&sc->tulip_fast_timer, 1, tulip_fasttimeout_callback, sc);
187 tulip_softc_t * const sc)
191 * Before we are sure this is the right media we need
192 * to send a small packet to make sure there's carrier.
193 * Strangely, BNC and AUI will "see" receive data if
194 * either is connected so the transmit is the only way
195 * to verify the connectivity.
197 MGETHDR(m, MB_DONTWAIT, MT_DATA);
201 * Construct a LLC TEST message which will point to ourselves.
203 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
204 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
205 mtod(m, struct ether_header *)->ether_type = htons(3);
206 mtod(m, unsigned char *)[14] = 0;
207 mtod(m, unsigned char *)[15] = 0;
208 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
209 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
213 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
214 sc->tulip_intrmask |= TULIP_STS_TXINTR;
215 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
216 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
217 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
218 if ((m = tulip_txput(sc, m)) != NULL)
220 sc->tulip_probe.probe_txprobes++;
225 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
227 #define TULIP_SIAGEN_WATCHDOG 0
232 tulip_softc_t * const sc,
235 const tulip_media_info_t *mi = sc->tulip_mediums[media];
241 * If we are switching media, make sure we don't think there's
242 * any stale RX activity
244 sc->tulip_flags &= ~TULIP_RXACT;
245 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
246 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
247 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
248 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
249 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
251 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
253 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
255 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
256 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
257 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
259 * If the cmdmode bits don't match the currently operating mode,
260 * set the cmdmode appropriately and reset the chip.
262 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
263 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
264 sc->tulip_cmdmode |= mi->mi_cmdmode;
267 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
269 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
270 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
272 * If the cmdmode bits don't match the currently operating mode,
273 * set the cmdmode appropriately and reset the chip.
275 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
276 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
277 sc->tulip_cmdmode |= mi->mi_cmdmode;
280 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
281 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
282 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
283 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
285 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
287 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
288 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
290 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
292 sc->tulip_phyaddr = mi->mi_phyaddr;
293 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
294 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
296 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
299 for (idx = 0; idx < mi->mi_reset_length; idx++) {
301 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
303 sc->tulip_phyaddr = mi->mi_phyaddr;
304 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
306 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
309 if (sc->tulip_flags & TULIP_TRYNWAY) {
310 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
311 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
312 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
313 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
314 sc->tulip_flags &= ~TULIP_DIDNWAY;
315 if (TULIP_IS_MEDIA_FD(media))
316 data |= PHYCTL_FULL_DUPLEX;
317 if (TULIP_IS_MEDIA_100MB(media))
318 data |= PHYCTL_SELECT_100MB;
319 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
326 tulip_softc_t * const sc,
329 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
330 sc->tulip_flags |= TULIP_PRINTLINKUP;
331 sc->tulip_flags |= TULIP_LINKUP;
332 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
333 #if 0 /* XXX how does with work with ifmedia? */
334 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
335 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
336 if (TULIP_CAN_MEDIA_FD(media)
337 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
338 media = TULIP_FD_MEDIA_OF(media);
340 if (TULIP_IS_MEDIA_FD(media)
341 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
342 media = TULIP_HD_MEDIA_OF(media);
346 if (sc->tulip_media != media) {
348 sc->tulip_dbg.dbg_last_media = sc->tulip_media;
350 sc->tulip_media = media;
351 sc->tulip_flags |= TULIP_PRINTMEDIA;
352 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
353 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
354 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
355 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
359 * We could set probe_timeout to 0 but setting to 3000 puts this
360 * in one central place and the only matters is tulip_link is
361 * followed by a tulip_timeout. Therefore setting it should not
362 * result in aberrant behavour.
364 sc->tulip_probe_timeout = 3000;
365 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
366 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
367 if (sc->tulip_flags & TULIP_INRESET) {
368 tulip_media_set(sc, sc->tulip_media);
369 } else if (sc->tulip_probe_media != sc->tulip_media) {
371 * No reason to change media if we have the right media.
380 tulip_softc_t * const sc)
382 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
384 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
385 printf("%s%d: enabling %s port\n",
386 sc->tulip_name, sc->tulip_unit,
387 tulip_mediums[sc->tulip_media]);
388 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
389 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
390 printf("%s%d: link up\n", sc->tulip_name, sc->tulip_unit);
391 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
395 #if defined(TULIP_DO_GPR_SENSE)
397 tulip_21140_gpr_media_sense(
398 tulip_softc_t * const sc)
400 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
401 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
405 * If one of the media blocks contained a default media flag,
408 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
409 const tulip_media_info_t *mi;
411 * Media is not supported (or is full-duplex).
413 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
415 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
419 * Remember the media is this is the "default" media.
421 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
425 * No activity mask? Can't see if it is active if there's no mask.
427 if (mi->mi_actmask == 0)
431 * Does the activity data match?
433 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
436 #if defined(TULIP_DEBUG)
437 printf("%s%d: gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
438 sc->tulip_name, sc->tulip_unit, tulip_mediums[media],
439 TULIP_CSR_READ(sc, csr_gp) & 0xFF,
440 mi->mi_actmask, mi->mi_actdata);
443 * It does! If this is the first media we detected, then
444 * remember this media. If isn't the first, then there were
445 * multiple matches which we equate to no match (since we don't
446 * which to select (if any).
448 if (last_media == TULIP_MEDIA_UNKNOWN) {
450 } else if (last_media != media) {
451 last_media = TULIP_MEDIA_UNKNOWN;
454 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
456 #endif /* TULIP_DO_GPR_SENSE */
458 static tulip_link_status_t
459 tulip_media_link_monitor(
460 tulip_softc_t * const sc)
462 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
463 tulip_link_status_t linkup = TULIP_LINK_DOWN;
466 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
467 panic("tulip_media_link_monitor: %s: botch at line %d\n",
468 tulip_mediums[sc->tulip_media],__LINE__);
470 return TULIP_LINK_UNKNOWN;
475 * Have we seen some packets? If so, the link must be good.
477 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
478 sc->tulip_flags &= ~TULIP_RXACT;
479 sc->tulip_probe_timeout = 3000;
480 return TULIP_LINK_UP;
483 sc->tulip_flags &= ~TULIP_RXACT;
484 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
487 * Read the PHY status register.
489 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
490 if (status & PHYSTS_AUTONEG_DONE) {
492 * If the PHY has completed autonegotiation, see the if the
493 * remote systems abilities have changed. If so, upgrade or
494 * downgrade as appropriate.
496 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
497 abilities = (abilities << 6) & status;
498 if (abilities != sc->tulip_abilities) {
499 #if defined(TULIP_DEBUG)
500 loudprintf("%s%d(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
501 sc->tulip_name, sc->tulip_unit, sc->tulip_phyaddr,
502 sc->tulip_abilities, abilities);
504 if (tulip_mii_map_abilities(sc, abilities)) {
505 tulip_linkup(sc, sc->tulip_probe_media);
506 return TULIP_LINK_UP;
509 * if we had selected media because of autonegotiation,
510 * we need to probe for the new media.
512 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
513 if (sc->tulip_flags & TULIP_DIDNWAY)
514 return TULIP_LINK_DOWN;
518 * The link is now up. If was down, say its back up.
520 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
521 linkup = TULIP_LINK_UP;
522 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
524 * No activity sensor? Assume all's well.
526 if (mi->mi_actmask == 0)
527 return TULIP_LINK_UNKNOWN;
529 * Does the activity data match?
531 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
532 linkup = TULIP_LINK_UP;
533 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
535 * Assume non TP ok for now.
537 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
538 return TULIP_LINK_UNKNOWN;
539 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
540 linkup = TULIP_LINK_UP;
541 #if defined(TULIP_DEBUG)
542 if (sc->tulip_probe_timeout <= 0)
543 printf("%s%d: sia status = 0x%08x\n", sc->tulip_name,
544 sc->tulip_unit, TULIP_CSR_READ(sc, csr_sia_status));
546 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
547 return TULIP_LINK_UNKNOWN;
550 * We will wait for 3 seconds until the link goes into suspect mode.
552 if (sc->tulip_flags & TULIP_LINKUP) {
553 if (linkup == TULIP_LINK_UP)
554 sc->tulip_probe_timeout = 3000;
555 if (sc->tulip_probe_timeout > 0)
556 return TULIP_LINK_UP;
558 sc->tulip_flags &= ~TULIP_LINKUP;
559 printf("%s%d: link down: cable problem?\n", sc->tulip_name, sc->tulip_unit);
561 #if defined(TULIP_DEBUG)
562 sc->tulip_dbg.dbg_link_downed++;
564 return TULIP_LINK_DOWN;
569 tulip_softc_t * const sc,
570 tulip_mediapoll_event_t event)
572 #if defined(TULIP_DEBUG)
573 sc->tulip_dbg.dbg_events[event]++;
575 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
576 && event == TULIP_MEDIAPOLL_TIMER) {
577 switch (tulip_media_link_monitor(sc)) {
578 case TULIP_LINK_DOWN: {
580 * Link Monitor failed. Probe for new media.
582 event = TULIP_MEDIAPOLL_LINKFAIL;
585 case TULIP_LINK_UP: {
592 case TULIP_LINK_UNKNOWN: {
594 * We can't tell so don't bother.
601 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
602 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
603 if (TULIP_DO_AUTOSENSE(sc)) {
604 #if defined(TULIP_DEBUG)
605 sc->tulip_dbg.dbg_link_failures++;
607 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
608 if (sc->tulip_if.if_flags & IFF_UP)
609 tulip_reset(sc); /* restart probe */
613 #if defined(TULIP_DEBUG)
614 sc->tulip_dbg.dbg_link_pollintrs++;
618 if (event == TULIP_MEDIAPOLL_START) {
619 sc->tulip_if.if_flags |= IFF_OACTIVE;
620 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
622 sc->tulip_probe_mediamask = 0;
623 sc->tulip_probe_passes = 0;
624 #if defined(TULIP_DEBUG)
625 sc->tulip_dbg.dbg_media_probes++;
628 * If the SROM contained an explicit media to use, use it.
630 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
631 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
632 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
634 * connidx is defaulted to a media_unknown type.
636 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
637 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
638 tulip_linkup(sc, sc->tulip_probe_media);
643 if (sc->tulip_features & TULIP_HAVE_GPR) {
644 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
645 sc->tulip_probe_timeout = 2000;
647 sc->tulip_probe_media = TULIP_MEDIA_MAX;
648 sc->tulip_probe_timeout = 0;
649 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
654 * Ignore txprobe failures or spurious callbacks.
656 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
657 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
658 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
663 * If we really transmitted a packet, then that's the media we'll use.
665 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
666 if (event == TULIP_MEDIAPOLL_LINKPASS) {
667 /* XXX Check media status just to be sure */
668 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
669 #if defined(TULIP_DEBUG)
671 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
674 tulip_linkup(sc, sc->tulip_probe_media);
679 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
680 #if defined(TULIP_DO_GPR_SENSE)
682 * Check for media via the general purpose register.
684 * Try to sense the media via the GPR. If the same value
685 * occurs 3 times in a row then just use that.
687 if (sc->tulip_probe_timeout > 0) {
688 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
689 #if defined(TULIP_DEBUG)
690 printf("%s%d: media_poll: gpr sensing = %s\n",
691 sc->tulip_name, sc->tulip_unit, tulip_mediums[new_probe_media]);
693 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
694 if (new_probe_media == sc->tulip_probe_media) {
695 if (--sc->tulip_probe_count == 0)
696 tulip_linkup(sc, sc->tulip_probe_media);
698 sc->tulip_probe_count = 10;
701 sc->tulip_probe_media = new_probe_media;
705 #endif /* TULIP_DO_GPR_SENSE */
707 * Brute force. We cycle through each of the media types
708 * and try to transmit a packet.
710 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
711 sc->tulip_probe_media = TULIP_MEDIA_MAX;
712 sc->tulip_probe_timeout = 0;
717 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
718 && (sc->tulip_features & TULIP_HAVE_MII)) {
719 tulip_media_t old_media = sc->tulip_probe_media;
720 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
721 switch (sc->tulip_probe_state) {
722 case TULIP_PROBE_FAILED:
723 case TULIP_PROBE_MEDIATEST: {
725 * Try the next media.
727 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
728 sc->tulip_probe_timeout = 0;
730 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
732 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
734 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
738 case TULIP_PROBE_PHYAUTONEG: {
741 case TULIP_PROBE_INACTIVE: {
743 * Only probe if we autonegotiated a media that hasn't failed.
745 sc->tulip_probe_timeout = 0;
746 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
747 sc->tulip_probe_media = old_media;
750 tulip_linkup(sc, sc->tulip_probe_media);
755 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
756 panic("tulip_media_poll: botch at line %d\n", __LINE__);
763 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
764 #if defined(TULIP_DEBUG)
765 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
767 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
772 * switch to another media if we tried this one enough.
774 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
775 #if defined(TULIP_DEBUG)
776 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
777 printf("%s%d: poll media unknown!\n",
778 sc->tulip_name, sc->tulip_unit);
779 sc->tulip_probe_media = TULIP_MEDIA_MAX;
783 * Find the next media type to check for. Full Duplex
784 * types are not allowed.
787 sc->tulip_probe_media -= 1;
788 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
789 if (++sc->tulip_probe_passes == 3) {
790 printf("%s%d: autosense failed: cable problem?\n",
791 sc->tulip_name, sc->tulip_unit);
792 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
793 sc->tulip_if.if_flags &= ~IFF_RUNNING;
794 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
798 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
799 sc->tulip_probe_mediamask = 0;
800 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
802 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
803 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
804 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
806 #if defined(TULIP_DEBUG)
807 printf("%s%d: %s: probing %s\n", sc->tulip_name, sc->tulip_unit,
808 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
809 tulip_mediums[sc->tulip_probe_media]);
811 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
812 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
813 sc->tulip_probe.probe_txprobes = 0;
815 tulip_media_set(sc, sc->tulip_probe_media);
816 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
821 * If this is hanging off a phy, we know are doing NWAY and we have
822 * forced the phy to a specific speed. Wait for link up before
823 * before sending a packet.
825 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
826 case TULIP_MEDIAINFO_MII: {
827 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
831 case TULIP_MEDIAINFO_SIA: {
832 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
833 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
835 tulip_linkup(sc, sc->tulip_probe_media);
837 if (sc->tulip_features & TULIP_HAVE_MII)
844 case TULIP_MEDIAINFO_RESET:
845 case TULIP_MEDIAINFO_SYM:
846 case TULIP_MEDIAINFO_NONE:
847 case TULIP_MEDIAINFO_GPR: {
852 * Try to send a packet.
859 tulip_softc_t * const sc)
861 if (sc->tulip_features & TULIP_HAVE_GPR) {
862 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
864 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
867 * If this board has no media, just return
869 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
872 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
873 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
874 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
876 tulip_media_set(sc, sc->tulip_media);
881 tulip_21040_mediainfo_init(
882 tulip_softc_t * const sc,
885 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
886 |TULIP_CMD_BACKOFFCTR;
887 sc->tulip_if.if_baudrate = 10000000;
889 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
890 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
891 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
892 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
895 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
896 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
899 if (media == TULIP_MEDIA_UNKNOWN) {
900 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
905 tulip_21040_media_probe(
906 tulip_softc_t * const sc)
908 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
913 tulip_21040_10baset_only_media_probe(
914 tulip_softc_t * const sc)
916 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
917 tulip_media_set(sc, TULIP_MEDIA_10BASET);
918 sc->tulip_media = TULIP_MEDIA_10BASET;
922 tulip_21040_10baset_only_media_select(
923 tulip_softc_t * const sc)
925 sc->tulip_flags |= TULIP_LINKUP;
926 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
927 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
928 sc->tulip_flags &= ~TULIP_SQETEST;
930 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
931 sc->tulip_flags |= TULIP_SQETEST;
933 tulip_media_set(sc, sc->tulip_media);
937 tulip_21040_auibnc_only_media_probe(
938 tulip_softc_t * const sc)
940 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
941 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
942 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
943 sc->tulip_media = TULIP_MEDIA_AUIBNC;
947 tulip_21040_auibnc_only_media_select(
948 tulip_softc_t * const sc)
950 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
951 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
954 static const tulip_boardsw_t tulip_21040_boardsw = {
956 tulip_21040_media_probe,
961 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
963 tulip_21040_10baset_only_media_probe,
964 tulip_21040_10baset_only_media_select,
968 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
970 tulip_21040_auibnc_only_media_probe,
971 tulip_21040_auibnc_only_media_select,
976 tulip_21041_mediainfo_init(
977 tulip_softc_t * const sc)
979 tulip_media_info_t * const mi = sc->tulip_mediainfo;
982 if (sc->tulip_revinfo >= 0x20) {
983 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
984 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
985 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
986 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
990 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
991 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
992 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
993 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
997 tulip_21041_media_probe(
998 tulip_softc_t * const sc)
1000 sc->tulip_if.if_baudrate = 10000000;
1001 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
1002 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
1003 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
1004 tulip_21041_mediainfo_init(sc);
1008 tulip_21041_media_poll(
1009 tulip_softc_t * const sc,
1010 const tulip_mediapoll_event_t event)
1012 u_int32_t sia_status;
1014 #if defined(TULIP_DEBUG)
1015 sc->tulip_dbg.dbg_events[event]++;
1018 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
1019 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
1020 || !TULIP_DO_AUTOSENSE(sc))
1022 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
1023 tulip_reset(sc); /* start probe */
1028 * If we've been been asked to start a poll or link change interrupt
1029 * restart the probe (and reset the tulip to a known state).
1031 if (event == TULIP_MEDIAPOLL_START) {
1032 sc->tulip_if.if_flags |= IFF_OACTIVE;
1033 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
1035 if (sc->tulip_revinfo >= 0x20) {
1036 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
1037 sc->tulip_flags |= TULIP_DIDNWAY;
1040 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1041 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1042 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1043 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
1044 tulip_media_set(sc, TULIP_MEDIA_10BASET);
1049 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1052 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
1053 #if defined(TULIP_DEBUG)
1054 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
1056 tulip_linkup(sc, sc->tulip_probe_media);
1060 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
1061 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
1062 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
1063 if (sc->tulip_revinfo >= 0x20) {
1064 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
1065 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1068 * If the link has passed LinkPass, 10baseT is the
1069 * proper media to use.
1071 tulip_linkup(sc, sc->tulip_probe_media);
1076 * wait for up to 2.4 seconds for the link to reach pass state.
1077 * Only then start scanning the other media for activity.
1078 * choose media with receive activity over those without.
1080 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
1081 if (event != TULIP_MEDIAPOLL_TIMER)
1083 if (sc->tulip_probe_timeout > 0
1084 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
1088 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1089 sc->tulip_flags |= TULIP_WANTRXACT;
1090 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
1091 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1093 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1095 tulip_media_set(sc, sc->tulip_probe_media);
1101 * If we failed, clear the txprobe active flag.
1103 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
1104 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1107 if (event == TULIP_MEDIAPOLL_TIMER) {
1109 * If we've received something, then that's our link!
1111 if (sc->tulip_flags & TULIP_RXACT) {
1112 tulip_linkup(sc, sc->tulip_probe_media);
1116 * if no txprobe active
1118 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
1119 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
1120 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
1121 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1127 * Take 2 passes through before deciding to not
1128 * wait for receive activity. Then take another
1129 * two passes before spitting out a warning.
1131 if (sc->tulip_probe_timeout <= 0) {
1132 if (sc->tulip_flags & TULIP_WANTRXACT) {
1133 sc->tulip_flags &= ~TULIP_WANTRXACT;
1134 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1136 printf("%s%d: autosense failed: cable problem?\n",
1137 sc->tulip_name, sc->tulip_unit);
1138 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1139 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1140 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1148 * Since this media failed to probe, try the other one.
1150 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1151 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1152 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1154 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1156 tulip_media_set(sc, sc->tulip_probe_media);
1157 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1161 static const tulip_boardsw_t tulip_21041_boardsw = {
1162 TULIP_21041_GENERIC,
1163 tulip_21041_media_probe,
1165 tulip_21041_media_poll
1168 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1169 { 0x20005c00, 0, /* 08-00-17 */
1171 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1172 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1174 #if defined(TULIP_DEBUG)
1178 { 0x0281F400, 0, /* 00-A0-7D */
1180 { 0x12, 0x0010, 0x0000 }, /* 10T */
1182 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1183 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1185 #if defined(TULIP_DEBUG)
1190 { 0x0015F420, 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 { 0x0281F400, 0, /* 00-A0-BE */
1204 { 0x11, 0x8000, 0x0000 }, /* 10T */
1205 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1207 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1209 #if defined(TULIP_DEBUG)
1216 static tulip_media_t
1217 tulip_mii_phy_readspecific(
1218 tulip_softc_t * const sc)
1220 const tulip_phy_attr_t *attr;
1224 static const tulip_media_t table[] = {
1225 TULIP_MEDIA_UNKNOWN,
1226 TULIP_MEDIA_10BASET,
1227 TULIP_MEDIA_100BASETX,
1228 TULIP_MEDIA_100BASET4,
1229 TULIP_MEDIA_UNKNOWN,
1230 TULIP_MEDIA_10BASET_FD,
1231 TULIP_MEDIA_100BASETX_FD,
1236 * Don't read phy specific registers if link is not up.
1238 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1239 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1240 return TULIP_MEDIA_UNKNOWN;
1242 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1243 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1244 for (attr = tulip_mii_phy_attrlist;; attr++) {
1245 if (attr->attr_id == 0)
1246 return TULIP_MEDIA_UNKNOWN;
1247 if ((id & ~0x0F) == attr->attr_id)
1251 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1252 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
1253 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1254 if ((data & pm->pm_mask) == pm->pm_value)
1257 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1258 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
1259 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1260 if ((data & pm->pm_mask) == pm->pm_value)
1263 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1264 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
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_FULLDUPLEX].pm_regno) {
1270 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1271 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1272 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1278 tulip_mii_get_phyaddr(
1279 tulip_softc_t * const sc,
1284 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1285 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1286 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1293 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1294 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1295 return TULIP_MII_NOPHY;
1298 return TULIP_MII_NOPHY;
1302 tulip_mii_map_abilities(
1303 tulip_softc_t * const sc,
1306 sc->tulip_abilities = abilities;
1307 if (abilities & PHYSTS_100BASETX_FD) {
1308 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1309 } else if (abilities & PHYSTS_100BASET4) {
1310 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1311 } else if (abilities & PHYSTS_100BASETX) {
1312 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1313 } else if (abilities & PHYSTS_10BASET_FD) {
1314 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1315 } else if (abilities & PHYSTS_10BASET) {
1316 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1318 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1321 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1326 tulip_mii_autonegotiate(
1327 tulip_softc_t * const sc,
1328 const unsigned phyaddr)
1330 switch (sc->tulip_probe_state) {
1331 case TULIP_PROBE_MEDIATEST:
1332 case TULIP_PROBE_INACTIVE: {
1333 sc->tulip_flags |= TULIP_DIDNWAY;
1334 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1335 sc->tulip_probe_timeout = 3000;
1336 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1337 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1340 case TULIP_PROBE_PHYRESET: {
1342 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1343 if (data & PHYCTL_RESET) {
1344 if (sc->tulip_probe_timeout > 0) {
1348 printf("%s%d(phy%d): error: reset of PHY never completed!\n",
1349 sc->tulip_name, sc->tulip_unit, phyaddr);
1350 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1351 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1352 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1355 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1356 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1357 #if defined(TULIP_DEBUG)
1358 loudprintf("%s%d(phy%d): autonegotiation disabled\n",
1359 sc->tulip_name, sc->tulip_unit, phyaddr);
1361 sc->tulip_flags &= ~TULIP_DIDNWAY;
1362 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1365 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1366 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1367 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1368 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1369 #if defined(TULIP_DEBUG)
1370 if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
1371 loudprintf("%s%d(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
1372 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1374 loudprintf("%s%d(phy%d): autonegotiation restarted: 0x%04x\n",
1375 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1376 sc->tulip_dbg.dbg_nway_starts++;
1378 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1379 sc->tulip_probe_timeout = 3000;
1382 case TULIP_PROBE_PHYAUTONEG: {
1383 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1385 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1386 if (sc->tulip_probe_timeout > 0) {
1390 #if defined(TULIP_DEBUG)
1391 loudprintf("%s%d(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
1392 sc->tulip_name, sc->tulip_unit, phyaddr, status,
1393 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
1395 sc->tulip_flags &= ~TULIP_DIDNWAY;
1396 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1399 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1400 #if defined(TULIP_DEBUG)
1401 loudprintf("%s%d(phy%d): autonegotiation complete: 0x%04x\n",
1402 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1404 data = (data << 6) & status;
1405 if (!tulip_mii_map_abilities(sc, data))
1406 sc->tulip_flags &= ~TULIP_DIDNWAY;
1410 #if defined(DIAGNOSTIC)
1411 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1416 #if defined(TULIP_DEBUG)
1417 loudprintf("%s%d(phy%d): autonegotiation failure: state = %d\n",
1418 sc->tulip_name, sc->tulip_unit, phyaddr, sc->tulip_probe_state);
1419 sc->tulip_dbg.dbg_nway_failures++;
1424 tulip_2114x_media_preset(
1425 tulip_softc_t * const sc)
1427 const tulip_media_info_t *mi = NULL;
1428 tulip_media_t media = sc->tulip_media;
1430 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1431 media = sc->tulip_media;
1433 media = sc->tulip_probe_media;
1435 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1436 sc->tulip_flags &= ~TULIP_SQETEST;
1437 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1438 #if defined(TULIP_DEBUG)
1439 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
1441 mi = sc->tulip_mediums[media];
1442 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1443 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1444 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1445 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1446 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1447 sc->tulip_cmdmode |= mi->mi_cmdmode;
1448 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1449 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1451 #if defined(TULIP_DEBUG)
1453 printf("%s%d: preset: bad media %d!\n",
1454 sc->tulip_name, sc->tulip_unit, media);
1459 case TULIP_MEDIA_BNC:
1460 case TULIP_MEDIA_AUI:
1461 case TULIP_MEDIA_10BASET: {
1462 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1463 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1464 sc->tulip_if.if_baudrate = 10000000;
1465 sc->tulip_flags |= TULIP_SQETEST;
1468 case TULIP_MEDIA_10BASET_FD: {
1469 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1470 sc->tulip_if.if_baudrate = 10000000;
1473 case TULIP_MEDIA_100BASEFX:
1474 case TULIP_MEDIA_100BASET4:
1475 case TULIP_MEDIA_100BASETX: {
1476 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1477 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1478 sc->tulip_if.if_baudrate = 100000000;
1481 case TULIP_MEDIA_100BASEFX_FD:
1482 case TULIP_MEDIA_100BASETX_FD: {
1483 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1484 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1485 sc->tulip_if.if_baudrate = 100000000;
1492 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1496 ********************************************************************
1497 * Start of 21140/21140A support which does not use the MII interface
1501 tulip_null_media_poll(
1502 tulip_softc_t * const sc,
1503 tulip_mediapoll_event_t event)
1505 #if defined(TULIP_DEBUG)
1506 sc->tulip_dbg.dbg_events[event]++;
1508 #if defined(DIAGNOSTIC)
1509 printf("%s%d: botch(media_poll) at line %d\n",
1510 sc->tulip_name, sc->tulip_unit, __LINE__);
1514 __inline__ static void
1515 tulip_21140_mediainit(
1516 tulip_softc_t * const sc,
1517 tulip_media_info_t * const mip,
1518 tulip_media_t const media,
1522 sc->tulip_mediums[media] = mip;
1523 mip->mi_type = TULIP_MEDIAINFO_GPR;
1524 mip->mi_cmdmode = cmdmode;
1525 mip->mi_gpdata = gpdata;
1529 tulip_21140_evalboard_media_probe(
1530 tulip_softc_t * const sc)
1532 tulip_media_info_t *mip = sc->tulip_mediainfo;
1534 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1535 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1536 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1537 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1538 TULIP_CSR_WRITE(sc, csr_command,
1539 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1540 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1541 TULIP_CSR_WRITE(sc, csr_command,
1542 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1544 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1545 sc->tulip_media = TULIP_MEDIA_10BASET;
1547 sc->tulip_media = TULIP_MEDIA_100BASETX;
1549 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1551 TULIP_CMD_TXTHRSHLDCTL);
1552 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1554 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1555 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1557 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1558 |TULIP_CMD_SCRAMBLER);
1559 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1561 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1562 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1565 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1567 tulip_21140_evalboard_media_probe,
1569 tulip_null_media_poll,
1570 tulip_2114x_media_preset,
1574 tulip_21140_accton_media_probe(
1575 tulip_softc_t * const sc)
1577 tulip_media_info_t *mip = sc->tulip_mediainfo;
1580 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1581 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1582 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1583 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1584 TULIP_CSR_WRITE(sc, csr_command,
1585 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1586 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1587 TULIP_CSR_WRITE(sc, csr_command,
1588 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1590 gpdata = TULIP_CSR_READ(sc, csr_gp);
1591 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1592 sc->tulip_media = TULIP_MEDIA_10BASET;
1594 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1595 sc->tulip_media = TULIP_MEDIA_BNC;
1597 sc->tulip_media = TULIP_MEDIA_100BASETX;
1600 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1601 TULIP_GP_EN1207_BNC_INIT,
1602 TULIP_CMD_TXTHRSHLDCTL);
1603 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1604 TULIP_GP_EN1207_UTP_INIT,
1605 TULIP_CMD_TXTHRSHLDCTL);
1606 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1607 TULIP_GP_EN1207_UTP_INIT,
1608 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1609 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1610 TULIP_GP_EN1207_100_INIT,
1611 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1612 |TULIP_CMD_SCRAMBLER);
1613 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1614 TULIP_GP_EN1207_100_INIT,
1615 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1616 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1619 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1621 tulip_21140_accton_media_probe,
1623 tulip_null_media_poll,
1624 tulip_2114x_media_preset,
1628 tulip_21140_smc9332_media_probe(
1629 tulip_softc_t * const sc)
1631 tulip_media_info_t *mip = sc->tulip_mediainfo;
1634 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1635 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1636 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1637 33MHz that comes to two microseconds but wait a
1638 bit longer anyways) */
1639 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1640 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1641 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1642 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1643 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1644 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1646 for (idx = 1000; idx > 0; idx--) {
1647 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1648 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1651 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1658 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1659 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1660 TULIP_GP_SMC_9332_INIT,
1661 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1662 |TULIP_CMD_SCRAMBLER);
1663 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1664 TULIP_GP_SMC_9332_INIT,
1665 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1666 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1667 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1668 TULIP_GP_SMC_9332_INIT,
1669 TULIP_CMD_TXTHRSHLDCTL);
1670 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1671 TULIP_GP_SMC_9332_INIT,
1672 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1675 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1676 TULIP_21140_SMC_9332,
1677 tulip_21140_smc9332_media_probe,
1679 tulip_null_media_poll,
1680 tulip_2114x_media_preset,
1684 tulip_21140_cogent_em100_media_probe(
1685 tulip_softc_t * const sc)
1687 tulip_media_info_t *mip = sc->tulip_mediainfo;
1688 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1690 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1691 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1692 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1693 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1695 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1696 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1697 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1698 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1699 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1701 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1702 TULIP_GP_EM100_INIT,
1703 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1704 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1705 TULIP_GP_EM100_INIT,
1706 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1707 |TULIP_CMD_FULLDUPLEX);
1709 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1710 sc->tulip_media = TULIP_MEDIA_100BASETX;
1711 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1712 TULIP_GP_EM100_INIT,
1713 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1714 |TULIP_CMD_SCRAMBLER);
1715 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1716 TULIP_GP_EM100_INIT,
1717 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1718 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1722 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1723 TULIP_21140_COGENT_EM100,
1724 tulip_21140_cogent_em100_media_probe,
1726 tulip_null_media_poll,
1727 tulip_2114x_media_preset
1731 tulip_21140_znyx_zx34x_media_probe(
1732 tulip_softc_t * const sc)
1734 tulip_media_info_t *mip = sc->tulip_mediainfo;
1735 int cnt10 = 0, cnt100 = 0, idx;
1737 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1738 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1739 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1740 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1741 TULIP_CSR_WRITE(sc, csr_command,
1742 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1743 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1744 TULIP_CSR_WRITE(sc, csr_command,
1745 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1748 for (idx = 1000; idx > 0; idx--) {
1749 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1750 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)) {
1753 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1762 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1763 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1764 TULIP_GP_ZX34X_INIT,
1765 TULIP_CMD_TXTHRSHLDCTL);
1766 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1767 TULIP_GP_ZX34X_INIT,
1768 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1769 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1770 TULIP_GP_ZX34X_INIT,
1771 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1772 |TULIP_CMD_SCRAMBLER);
1773 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1774 TULIP_GP_ZX34X_INIT,
1775 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1776 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1779 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1780 TULIP_21140_ZNYX_ZX34X,
1781 tulip_21140_znyx_zx34x_media_probe,
1783 tulip_null_media_poll,
1784 tulip_2114x_media_preset,
1788 tulip_2114x_media_probe(
1789 tulip_softc_t * const sc)
1791 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
1792 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
1795 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1797 tulip_2114x_media_probe,
1800 tulip_2114x_media_preset,
1804 * ******** END of chip-specific handlers. ***********
1808 * Code the read the SROM and MII bit streams (I2C)
1810 #define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1814 tulip_softc_t * const sc)
1818 csr = SROMSEL ; EMIT;
1819 csr = SROMSEL | SROMRD; EMIT;
1820 csr ^= SROMCS; EMIT;
1821 csr ^= SROMCLKON; EMIT;
1824 * Write 25 cycles of 0 which will force the SROM to be idle.
1826 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1827 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1828 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1830 csr ^= SROMCLKOFF; EMIT;
1831 csr ^= SROMCS; EMIT;
1838 tulip_softc_t * const sc)
1841 const unsigned bitwidth = SROM_BITWIDTH;
1842 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1843 const unsigned msb = 1 << (bitwidth + 3 - 1);
1844 unsigned lastidx = (1 << bitwidth) - 1;
1846 tulip_srom_idle(sc);
1848 for (idx = 0; idx <= lastidx; idx++) {
1849 unsigned lastbit, data, bits, bit, csr;
1850 csr = SROMSEL ; EMIT;
1851 csr = SROMSEL | SROMRD; EMIT;
1852 csr ^= SROMCSON; EMIT;
1853 csr ^= SROMCLKON; EMIT;
1856 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1857 const unsigned thisbit = bits & msb;
1858 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1859 if (thisbit != lastbit) {
1860 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1864 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1867 csr ^= SROMCLKOFF; EMIT;
1869 for (data = 0, bits = 0; bits < 16; bits++) {
1871 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1872 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1873 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1875 sc->tulip_rombuf[idx*2] = data & 0xFF;
1876 sc->tulip_rombuf[idx*2+1] = data >> 8;
1877 csr = SROMSEL | SROMRD; EMIT;
1880 tulip_srom_idle(sc);
1883 #define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1886 tulip_mii_writebits(
1887 tulip_softc_t * const sc,
1891 unsigned msb = 1 << (bits - 1);
1892 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1893 unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
1895 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1897 for (; bits > 0; bits--, data <<= 1) {
1898 const unsigned thisbit = data & msb;
1899 if (thisbit != lastbit) {
1900 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1902 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1904 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1909 tulip_mii_turnaround(
1910 tulip_softc_t * const sc,
1913 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1915 if (cmd == MII_WRCMD) {
1916 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1917 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1918 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1919 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1921 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1923 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1924 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1929 tulip_softc_t * const sc)
1932 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1935 for (idx = 0, data = 0; idx < 16; idx++) {
1936 data <<= 1; /* this is NOOP on the first pass through */
1937 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1938 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1940 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1942 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1949 tulip_softc_t * const sc,
1953 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1956 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1957 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1958 tulip_mii_writebits(sc, MII_RDCMD, 8);
1959 tulip_mii_writebits(sc, devaddr, 5);
1960 tulip_mii_writebits(sc, regno, 5);
1961 tulip_mii_turnaround(sc, MII_RDCMD);
1963 data = tulip_mii_readbits(sc);
1964 #if defined(TULIP_DEBUG)
1965 sc->tulip_dbg.dbg_phyregs[regno][0] = data;
1966 sc->tulip_dbg.dbg_phyregs[regno][1]++;
1973 tulip_softc_t * const sc,
1978 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1979 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1980 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1981 tulip_mii_writebits(sc, MII_WRCMD, 8);
1982 tulip_mii_writebits(sc, devaddr, 5);
1983 tulip_mii_writebits(sc, regno, 5);
1984 tulip_mii_turnaround(sc, MII_WRCMD);
1985 tulip_mii_writebits(sc, data, 16);
1986 #if defined(TULIP_DEBUG)
1987 sc->tulip_dbg.dbg_phyregs[regno][2] = data;
1988 sc->tulip_dbg.dbg_phyregs[regno][3]++;
1992 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
1993 #define tulip_srom_crcok(databuf) ( \
1994 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1995 ((databuf)[126] | ((databuf)[127] << 8)))
1998 tulip_identify_dec_nic(
1999 tulip_softc_t * const sc)
2001 strcpy(sc->tulip_boardid, "DEC ");
2003 if (sc->tulip_chipid <= TULIP_21040)
2005 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
2006 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
2007 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
2008 sc->tulip_boardid[D0+8] = ' ';
2014 tulip_identify_znyx_nic(
2015 tulip_softc_t * const sc)
2018 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
2019 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2021 sc->tulip_boardid[8] = '4';
2022 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
2023 if (znyx_ptr < 26 || znyx_ptr > 116) {
2024 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2027 /* ZX344 = 0010 .. 0013FF
2029 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
2030 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
2031 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
2032 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
2033 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
2034 sc->tulip_boardid[9] = '2';
2035 if (id == TULIP_ZNYX_ID_ZX342B) {
2036 sc->tulip_boardid[10] = 'B';
2037 sc->tulip_boardid[11] = ' ';
2039 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2040 } else if (id == TULIP_ZNYX_ID_ZX344) {
2041 sc->tulip_boardid[10] = '4';
2042 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2043 } else if (id == TULIP_ZNYX_ID_ZX345) {
2044 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
2045 } else if (id == TULIP_ZNYX_ID_ZX346) {
2046 sc->tulip_boardid[9] = '6';
2047 } else if (id == TULIP_ZNYX_ID_ZX351) {
2048 sc->tulip_boardid[8] = '5';
2049 sc->tulip_boardid[9] = '1';
2054 * Assume it's a ZX342...
2056 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2060 sc->tulip_boardid[8] = '1';
2061 if (sc->tulip_chipid == TULIP_21041) {
2062 sc->tulip_boardid[10] = '1';
2065 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
2066 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
2067 if (id == TULIP_ZNYX_ID_ZX312T) {
2068 sc->tulip_boardid[9] = '2';
2069 sc->tulip_boardid[10] = 'T';
2070 sc->tulip_boardid[11] = ' ';
2071 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2072 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
2073 sc->tulip_boardid[9] = '4';
2074 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2075 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2076 } else if (id == TULIP_ZNYX_ID_ZX314) {
2077 sc->tulip_boardid[9] = '4';
2078 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2079 sc->tulip_features |= TULIP_HAVE_BASEROM;
2080 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
2081 sc->tulip_boardid[9] = '5';
2082 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2083 } else if (id == TULIP_ZNYX_ID_ZX315) {
2084 sc->tulip_boardid[9] = '5';
2085 sc->tulip_features |= TULIP_HAVE_BASEROM;
2091 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
2092 sc->tulip_boardid[9] = '4';
2093 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2094 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2095 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
2096 sc->tulip_boardid[9] = '5';
2097 sc->tulip_boardsw = &tulip_21040_boardsw;
2098 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2099 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
2100 sc->tulip_boardid[9] = '2';
2101 sc->tulip_boardsw = &tulip_21040_boardsw;
2107 tulip_identify_smc_nic(
2108 tulip_softc_t * const sc)
2110 u_int32_t id1, id2, ei;
2111 int auibnc = 0, utp = 0;
2114 strcpy(sc->tulip_boardid, "SMC ");
2115 if (sc->tulip_chipid == TULIP_21041)
2117 if (sc->tulip_chipid != TULIP_21040) {
2118 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2119 strcpy(&sc->tulip_boardid[4], "9332DST ");
2120 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
2121 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
2122 strcpy(&sc->tulip_boardid[4], "9334BDT ");
2124 strcpy(&sc->tulip_boardid[4], "9332BDT ");
2128 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
2129 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
2130 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
2132 strcpy(&sc->tulip_boardid[4], "8432");
2133 cp = &sc->tulip_boardid[8];
2135 *cp++ = 'B', auibnc = 1;
2136 if ((id1 & 0xFF) > 0x32)
2137 *cp++ = 'T', utp = 1;
2138 if ((id1 & 0x4000) == 0)
2139 *cp++ = 'A', auibnc = 1;
2141 sc->tulip_boardid[7] = '4';
2145 *cp++ = (ei ? '2' : '1');
2150 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2151 else if (!utp && auibnc)
2152 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
2156 tulip_identify_cogent_nic(
2157 tulip_softc_t * const sc)
2159 strcpy(sc->tulip_boardid, "Cogent ");
2160 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2161 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
2162 strcat(sc->tulip_boardid, "EM100TX ");
2163 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2164 #if defined(TULIP_COGENT_EM110TX_ID)
2165 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
2166 strcat(sc->tulip_boardid, "EM110TX ");
2167 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2169 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
2170 strcat(sc->tulip_boardid, "EM100FX ");
2171 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2174 * Magic number (0x24001109U) is the SubVendor (0x2400) and
2175 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
2177 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
2178 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
2180 * Cogent (Adaptec) is still mapping all INTs to INTA of
2181 * first 21140. Dumb! Dumb!
2183 strcat(sc->tulip_boardid, "EM440TX ");
2184 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2186 } else if (sc->tulip_chipid == TULIP_21040) {
2187 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2192 tulip_identify_accton_nic(
2193 tulip_softc_t * const sc)
2195 strcpy(sc->tulip_boardid, "ACCTON ");
2196 switch (sc->tulip_chipid) {
2198 strcat(sc->tulip_boardid, "EN1207 ");
2199 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2200 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
2203 strcat(sc->tulip_boardid, "EN1207TX ");
2204 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2205 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2208 strcat(sc->tulip_boardid, "EN1203 ");
2209 sc->tulip_boardsw = &tulip_21040_boardsw;
2212 strcat(sc->tulip_boardid, "EN1203 ");
2213 sc->tulip_boardsw = &tulip_21041_boardsw;
2216 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2222 tulip_identify_asante_nic(
2223 tulip_softc_t * const sc)
2225 strcpy(sc->tulip_boardid, "Asante ");
2226 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2227 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2228 tulip_media_info_t *mi = sc->tulip_mediainfo;
2231 * The Asante Fast Ethernet doesn't always ship with a valid
2232 * new format SROM. So if isn't in the new format, we cheat
2233 * set it up as if we had.
2236 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2237 sc->tulip_gpdata = 0;
2239 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2240 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2242 TULIP_CSR_WRITE(sc, csr_gp, 0);
2244 mi->mi_type = TULIP_MEDIAINFO_MII;
2245 mi->mi_gpr_length = 0;
2246 mi->mi_gpr_offset = 0;
2247 mi->mi_reset_length = 0;
2248 mi->mi_reset_offset = 0;;
2250 mi->mi_phyaddr = TULIP_MII_NOPHY;
2251 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2253 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2255 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2256 printf("%s%d: can't find phy 0\n", sc->tulip_name, sc->tulip_unit);
2260 sc->tulip_features |= TULIP_HAVE_MII;
2261 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2262 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2263 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2264 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2265 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2266 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2267 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2268 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2269 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2270 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2271 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2273 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2278 tulip_identify_compex_nic(
2279 tulip_softc_t * const sc)
2281 strcpy(sc->tulip_boardid, "COMPEX ");
2282 if (sc->tulip_chipid == TULIP_21140A) {
2284 tulip_softc_t *root_sc = NULL;
2286 strcat(sc->tulip_boardid, "400TX/PCI ");
2288 * All 4 chips on these boards share an interrupt. This code
2289 * copied from tulip_read_macaddr.
2291 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2292 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2293 root_sc = tulips[root_unit];
2295 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2300 && root_sc->tulip_chipid == sc->tulip_chipid
2301 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2302 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2303 sc->tulip_slaves = root_sc->tulip_slaves;
2304 root_sc->tulip_slaves = sc;
2305 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2306 printf("\nCannot find master device for de%d interrupts",
2310 strcat(sc->tulip_boardid, "unknown ");
2312 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2318 tulip_softc_t * const sc)
2320 unsigned idx1, idx2, idx3;
2322 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2323 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2324 tulip_srom_media_t srom_media;
2325 tulip_media_info_t *mi = sc->tulip_mediainfo;
2327 u_int32_t leaf_offset, blocks, data;
2329 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2330 if (shp->sh_adapter_count == 1)
2332 if (saip->sai_device == sc->tulip_pci_devno)
2336 * Didn't find the right media block for this card.
2338 if (idx1 == shp->sh_adapter_count)
2342 * Save the hardware address.
2344 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2346 * If this is a multiple port card, add the adapter index to the last
2347 * byte of the hardware address. (if it isn't multiport, adding 0
2350 sc->tulip_enaddr[5] += idx1;
2352 leaf_offset = saip->sai_leaf_offset_lowbyte
2353 + saip->sai_leaf_offset_highbyte * 256;
2354 dp = sc->tulip_rombuf + leaf_offset;
2356 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2358 for (idx2 = 0;; idx2++) {
2359 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2360 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2363 sc->tulip_connidx = idx2;
2365 if (sc->tulip_chipid == TULIP_21041) {
2367 for (idx2 = 0; idx2 < blocks; idx2++) {
2368 tulip_media_t media;
2370 srom_media = (tulip_srom_media_t) (data & 0x3F);
2371 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2372 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2375 media = tulip_srom_mediums[idx3].sm_type;
2376 if (media != TULIP_MEDIA_UNKNOWN) {
2377 if (data & TULIP_SROM_21041_EXTENDED) {
2378 mi->mi_type = TULIP_MEDIAINFO_SIA;
2379 sc->tulip_mediums[media] = mi;
2380 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2381 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2382 mi->mi_sia_general = dp[4] + dp[5] * 256;
2386 case TULIP_MEDIA_BNC: {
2387 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2391 case TULIP_MEDIA_AUI: {
2392 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2396 case TULIP_MEDIA_10BASET: {
2397 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2401 case TULIP_MEDIA_10BASET_FD: {
2402 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2412 if (data & TULIP_SROM_21041_EXTENDED)
2417 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2418 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2419 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2420 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2424 unsigned length, type;
2425 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2426 if (sc->tulip_features & TULIP_HAVE_GPR)
2427 sc->tulip_gpinit = *dp++;
2429 for (idx2 = 0; idx2 < blocks; idx2++) {
2431 if ((*dp & 0x80) == 0) {
2435 length = (*dp++ & 0x7f) - 1;
2436 type = *dp++ & 0x3f;
2439 switch (type & 0x3f) {
2440 case 0: { /* 21140[A] GPR block */
2441 tulip_media_t media;
2442 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2443 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2444 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2447 media = tulip_srom_mediums[idx3].sm_type;
2448 if (media == TULIP_MEDIA_UNKNOWN)
2450 mi->mi_type = TULIP_MEDIAINFO_GPR;
2451 sc->tulip_mediums[media] = mi;
2452 mi->mi_gpdata = dp[1];
2453 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2454 sc->tulip_gpdata = mi->mi_gpdata;
2457 data = dp[2] + dp[3] * 256;
2458 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2459 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2463 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2465 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2466 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2471 case 1: { /* 21140[A] MII block */
2472 const unsigned phyno = *dp++;
2473 mi->mi_type = TULIP_MEDIAINFO_MII;
2474 mi->mi_gpr_length = *dp++;
2475 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2476 dp += mi->mi_gpr_length;
2477 mi->mi_reset_length = *dp++;
2478 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2479 dp += mi->mi_reset_length;
2482 * Before we probe for a PHY, use the GPR information
2483 * to select it. If we don't, it may be inaccessible.
2485 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2486 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2488 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2490 sc->tulip_phyaddr = mi->mi_phyaddr;
2491 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2493 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2497 * At least write something!
2499 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2500 TULIP_CSR_WRITE(sc, csr_gp, 0);
2502 mi->mi_phyaddr = TULIP_MII_NOPHY;
2503 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2505 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2507 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2508 #if defined(TULIP_DEBUG)
2509 printf("%s%d: can't find phy %d\n",
2510 sc->tulip_name, sc->tulip_unit, phyno);
2514 sc->tulip_features |= TULIP_HAVE_MII;
2515 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2516 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2517 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2518 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2519 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2520 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2521 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2522 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2523 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2524 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2525 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2529 case 2: { /* 2114[23] SIA block */
2530 tulip_media_t media;
2531 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2532 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2533 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2536 media = tulip_srom_mediums[idx3].sm_type;
2537 if (media == TULIP_MEDIA_UNKNOWN)
2539 mi->mi_type = TULIP_MEDIAINFO_SIA;
2540 sc->tulip_mediums[media] = mi;
2542 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2543 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2544 mi->mi_sia_general = dp[5] + dp[6] * 256;
2548 case TULIP_MEDIA_BNC: {
2549 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2552 case TULIP_MEDIA_AUI: {
2553 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2556 case TULIP_MEDIA_10BASET: {
2557 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2558 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2561 case TULIP_MEDIA_10BASET_FD: {
2562 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2563 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2571 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2572 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2577 case 3: { /* 2114[23] MII PHY block */
2578 const unsigned phyno = *dp++;
2579 const u_int8_t *dp0;
2580 mi->mi_type = TULIP_MEDIAINFO_MII;
2581 mi->mi_gpr_length = *dp++;
2582 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2583 dp += 2 * mi->mi_gpr_length;
2584 mi->mi_reset_length = *dp++;
2585 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2586 dp += 2 * mi->mi_reset_length;
2588 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2589 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2591 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2593 sc->tulip_phyaddr = mi->mi_phyaddr;
2594 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2595 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2597 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2600 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2601 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2603 mi->mi_phyaddr = TULIP_MII_NOPHY;
2604 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2606 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2608 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2609 #if defined(TULIP_DEBUG)
2610 printf("%s%d: can't find phy %d\n",
2611 sc->tulip_name, sc->tulip_unit, phyno);
2615 sc->tulip_features |= TULIP_HAVE_MII;
2616 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2617 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2618 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2619 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2620 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2621 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2622 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2623 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2624 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2625 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2626 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2627 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2631 case 4: { /* 21143 SYM block */
2632 tulip_media_t media;
2633 srom_media = (tulip_srom_media_t) dp[0];
2634 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2635 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2638 media = tulip_srom_mediums[idx3].sm_type;
2639 if (media == TULIP_MEDIA_UNKNOWN)
2641 mi->mi_type = TULIP_MEDIAINFO_SYM;
2642 sc->tulip_mediums[media] = mi;
2643 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2644 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2645 data = dp[5] + dp[6] * 256;
2646 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2647 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2650 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2651 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2652 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2654 if (TULIP_IS_MEDIA_TP(media))
2655 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2660 case 5: { /* 21143 Reset block */
2661 mi->mi_type = TULIP_MEDIAINFO_RESET;
2662 mi->mi_reset_length = *dp++;
2663 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2664 dp += 2 * mi->mi_reset_length;
2675 return mi - sc->tulip_mediainfo;
2678 static const struct {
2679 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2680 unsigned char vendor_oui[3];
2681 } tulip_vendors[] = {
2682 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2683 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2684 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2685 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2686 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2687 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2688 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2689 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2690 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2691 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2696 * This deals with the vagaries of the address roms and the
2697 * brain-deadness that various vendors commit in using them.
2701 tulip_softc_t * const sc)
2703 unsigned cksum, rom_cksum, idx;
2705 unsigned char tmpbuf[8];
2706 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2708 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2710 if (sc->tulip_chipid == TULIP_21040) {
2711 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2712 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2714 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2716 sc->tulip_rombuf[idx] = csr & 0xFF;
2718 sc->tulip_boardsw = &tulip_21040_boardsw;
2720 if (sc->tulip_chipid == TULIP_21041) {
2722 * Thankfully all 21041's act the same.
2724 sc->tulip_boardsw = &tulip_21041_boardsw;
2727 * Assume all 21140 board are compatible with the
2728 * DEC 10/100 evaluation board. Not really valid but
2729 * it's the best we can do until every one switches to
2730 * the new SROM format.
2733 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2735 tulip_srom_read(sc);
2736 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2738 * SROM CRC is valid therefore it must be in the
2741 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2742 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2744 * No checksum is present. See if the SROM id checks out;
2745 * the first 18 bytes should be 0 followed by a 1 followed
2746 * by the number of adapters (which we don't deal with yet).
2748 for (idx = 0; idx < 18; idx++) {
2749 if (sc->tulip_rombuf[idx] != 0)
2752 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2753 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2754 } else if (sc->tulip_chipid >= TULIP_21142) {
2755 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2756 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2758 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2759 if (sc->tulip_chipid != TULIP_21041)
2760 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2763 * If the SROM specifies more than one adapter, tag this as a
2766 if (sc->tulip_rombuf[19] > 1)
2767 sc->tulip_features |= TULIP_HAVE_BASEROM;
2768 if (sc->tulip_boardsw == NULL)
2775 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2777 * Some folks don't use the standard ethernet rom format
2778 * but instead just put the address in the first 6 bytes
2779 * of the rom and let the rest be all 0xffs. (Can we say
2780 * ZNYX?) (well sometimes they put in a checksum so we'll
2783 for (idx = 8; idx < 32; idx++) {
2784 if (sc->tulip_rombuf[idx] != 0xFF)
2788 * Make sure the address is not multicast or locally assigned
2789 * that the OUI is not 00-00-00.
2791 if ((sc->tulip_rombuf[0] & 3) != 0)
2793 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2794 && sc->tulip_rombuf[2] == 0)
2796 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2797 sc->tulip_features |= TULIP_HAVE_OKROM;
2801 * A number of makers of multiport boards (ZNYX and Cogent)
2802 * only put on one address ROM on their 21040 boards. So
2803 * if the ROM is all zeros (or all 0xFFs), look at the
2804 * previous configured boards (as long as they are on the same
2805 * PCI bus and the bus number is non-zero) until we find the
2806 * master board with address ROM. We then use its address ROM
2807 * as the base for this board. (we add our relative board
2808 * to the last byte of its address).
2810 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2811 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2814 if (idx == sizeof(sc->tulip_rombuf)) {
2816 tulip_softc_t *root_sc = NULL;
2817 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2818 root_sc = tulips[root_unit];
2819 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2823 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2824 && root_sc->tulip_chipid == sc->tulip_chipid
2825 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2826 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2827 sc->tulip_boardsw = root_sc->tulip_boardsw;
2828 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2829 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2830 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2831 sizeof(sc->tulip_rombuf));
2832 if (!tulip_srom_decode(sc))
2835 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2836 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2839 * Now for a truly disgusting kludge: all 4 21040s on
2840 * the ZX314 share the same INTA line so the mapping
2841 * setup by the BIOS on the PCI bridge is worthless.
2842 * Rather than reprogramming the value in the config
2843 * register, we will handle this internally.
2845 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2846 sc->tulip_slaves = root_sc->tulip_slaves;
2847 root_sc->tulip_slaves = sc;
2848 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2856 * This is the standard DEC address ROM test.
2859 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2862 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2863 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2864 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2865 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2866 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2869 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2871 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2873 if (cksum > 65535) cksum -= 65535;
2874 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2875 if (cksum > 65535) cksum -= 65535;
2877 if (cksum > 65535) cksum -= 65535;
2878 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2879 if (cksum >= 65535) cksum -= 65535;
2881 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2883 if (cksum != rom_cksum)
2888 * Check for various boards based on OUI. Did I say braindead?
2890 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2891 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2892 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2897 sc->tulip_features |= TULIP_HAVE_OKROM;
2903 tulip_softc_t * const sc)
2905 tulip_media_t media;
2908 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2909 if (sc->tulip_mediums[media] != NULL) {
2910 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2916 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2917 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2918 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2919 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2920 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2921 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2923 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2924 sc->tulip_flags |= TULIP_PRINTMEDIA;
2925 tulip_linkup(sc, sc->tulip_media);
2930 tulip_ifmedia_change(
2931 struct ifnet * const ifp)
2933 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
2935 sc->tulip_flags |= TULIP_NEEDRESET;
2936 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2937 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2938 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2939 tulip_media_t media;
2940 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2941 if (sc->tulip_mediums[media] != NULL
2942 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2943 sc->tulip_flags |= TULIP_PRINTMEDIA;
2944 sc->tulip_flags &= ~TULIP_DIDNWAY;
2945 tulip_linkup(sc, media);
2950 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2957 * Media status callback
2960 tulip_ifmedia_status(
2961 struct ifnet * const ifp,
2962 struct ifmediareq *req)
2964 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2966 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2969 req->ifm_status = IFM_AVALID;
2970 if (sc->tulip_flags & TULIP_LINKUP)
2971 req->ifm_status |= IFM_ACTIVE;
2973 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2978 tulip_softc_t * const sc)
2980 struct ifmultiaddr *ifma;
2984 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2985 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2986 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2987 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2988 #if defined(IFF_ALLMULTI)
2989 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
2990 sc->tulip_flags |= TULIP_ALLMULTI ;
2994 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2995 ifma = ifma->ifma_link.le_next) {
2997 if (ifma->ifma_addr->sa_family == AF_LINK)
3001 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
3002 if (multicnt > 14) {
3003 u_int32_t *sp = sc->tulip_setupdata;
3006 * Some early passes of the 21140 have broken implementations of
3007 * hash-perfect mode. When we get too many multicasts for perfect
3008 * filtering with these chips, we need to switch into hash-only
3009 * mode (this is better than all-multicast on network with lots
3010 * of multicast traffic).
3012 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
3013 sc->tulip_flags |= TULIP_WANTHASHONLY;
3015 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
3017 * If we have more than 14 multicasts, we have
3018 * go into hash perfect mode (512 bit multicast
3019 * hash and one perfect hardware).
3021 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
3023 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3024 ifma = ifma->ifma_link.le_next) {
3026 if (ifma->ifma_addr->sa_family != AF_LINK)
3029 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
3030 #if BYTE_ORDER == BIG_ENDIAN
3031 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3033 sp[hash >> 4] |= 1 << (hash & 0xF);
3037 * No reason to use a hash if we are going to be
3038 * receiving every multicast.
3040 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3041 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
3042 #if BYTE_ORDER == BIG_ENDIAN
3043 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3045 sp[hash >> 4] |= 1 << (hash & 0xF);
3047 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
3048 hash = tulip_mchash(sc->tulip_enaddr);
3049 #if BYTE_ORDER == BIG_ENDIAN
3050 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3052 sp[hash >> 4] |= 1 << (hash & 0xF);
3055 #if BYTE_ORDER == BIG_ENDIAN
3056 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3057 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3058 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3060 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
3061 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
3062 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
3067 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
3068 u_int32_t *sp = sc->tulip_setupdata;
3070 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3072 * Else can get perfect filtering for 16 addresses.
3074 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3075 ifma = ifma->ifma_link.le_next) {
3076 if (ifma->ifma_addr->sa_family != AF_LINK)
3078 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3079 #if BYTE_ORDER == BIG_ENDIAN
3080 *sp++ = ((u_int16_t *) addrp)[0] << 16;
3081 *sp++ = ((u_int16_t *) addrp)[1] << 16;
3082 *sp++ = ((u_int16_t *) addrp)[2] << 16;
3084 *sp++ = ((u_int16_t *) addrp)[0];
3085 *sp++ = ((u_int16_t *) addrp)[1];
3086 *sp++ = ((u_int16_t *) addrp)[2];
3091 * Add the broadcast address.
3094 #if BYTE_ORDER == BIG_ENDIAN
3095 *sp++ = 0xFFFF << 16;
3096 *sp++ = 0xFFFF << 16;
3097 *sp++ = 0xFFFF << 16;
3105 * Pad the rest with our hardware address
3107 for (; idx < 16; idx++) {
3108 #if BYTE_ORDER == BIG_ENDIAN
3109 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3110 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3111 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3113 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
3114 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
3115 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
3119 #if defined(IFF_ALLMULTI)
3120 if (sc->tulip_flags & TULIP_ALLMULTI)
3121 sc->tulip_if.if_flags |= IFF_ALLMULTI;
3127 tulip_softc_t * const sc)
3129 tulip_ringinfo_t *ri;
3131 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
3134 * Brilliant. Simply brilliant. When switching modes/speeds
3135 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
3136 * bits in CSR6 and then do a software reset to get the 21140
3137 * to properly reset its internal pathways to the right places.
3140 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
3141 && sc->tulip_boardsw->bd_media_preset != NULL)
3142 (*sc->tulip_boardsw->bd_media_preset)(sc);
3144 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3145 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3146 33MHz that comes to two microseconds but wait a
3147 bit longer anyways) */
3150 sc->tulip_flags |= TULIP_INRESET;
3151 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
3152 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3153 sc->tulip_if.if_start = tulip_ifstart;
3156 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
3157 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
3158 TULIP_CSR_WRITE(sc, csr_busmode,
3159 (1 << (3 /*pci_max_burst_len*/ + 8))
3160 |TULIP_BUSMODE_CACHE_ALIGN8
3161 |TULIP_BUSMODE_READMULTIPLE
3162 |(BYTE_ORDER != LITTLE_ENDIAN ?
3163 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
3165 sc->tulip_txtimer = 0;
3166 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
3168 * Free all the mbufs that were on the transmit ring.
3172 IF_DEQUEUE(&sc->tulip_txq, m);
3178 ri = &sc->tulip_txinfo;
3179 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3180 ri->ri_free = ri->ri_max;
3181 for (di = ri->ri_first; di < ri->ri_last; di++)
3185 * We need to collect all the mbufs were on the
3186 * receive ring before we reinit it either to put
3187 * them back on or to know if we have to allocate
3190 ri = &sc->tulip_rxinfo;
3191 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3192 ri->ri_free = ri->ri_max;
3193 for (di = ri->ri_first; di < ri->ri_last; di++) {
3195 di->d_length1 = 0; di->d_addr1 = 0;
3196 di->d_length2 = 0; di->d_addr2 = 0;
3200 IF_DEQUEUE(&sc->tulip_rxq, m);
3207 * If tulip_reset is being called recurisvely, exit quickly knowing
3208 * that when the outer tulip_reset returns all the right stuff will
3214 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
3215 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
3216 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
3217 |TULIP_STS_RXSTOPPED;
3219 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
3220 (*sc->tulip_boardsw->bd_media_select)(sc);
3221 #if defined(TULIP_DEBUG)
3222 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
3223 printf("%s%d: tulip_reset: additional reset needed?!?\n",
3224 sc->tulip_name, sc->tulip_unit);
3226 tulip_media_print(sc);
3227 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
3228 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
3230 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
3232 tulip_addr_filter(sc);
3237 tulip_softc_t * const sc)
3239 if (sc->tulip_if.if_flags & IFF_UP) {
3240 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
3241 /* initialize the media */
3244 sc->tulip_if.if_flags |= IFF_RUNNING;
3245 if (sc->tulip_if.if_flags & IFF_PROMISC) {
3246 sc->tulip_flags |= TULIP_PROMISC;
3247 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3248 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3250 sc->tulip_flags &= ~TULIP_PROMISC;
3251 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3252 if (sc->tulip_flags & TULIP_ALLMULTI) {
3253 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3255 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3258 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3259 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3261 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3262 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3264 sc->tulip_if.if_flags |= IFF_OACTIVE;
3265 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3266 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3268 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3269 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3270 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3271 tulip_txput_setup(sc);
3273 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3280 tulip_softc_t * const sc)
3282 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
3283 struct ifnet * const ifp = &sc->tulip_if;
3285 #if defined(TULIP_DEBUG)
3290 struct ether_header eh;
3291 tulip_desc_t *eop = ri->ri_nextin;
3292 int total_len = 0, last_offset = 0;
3293 struct mbuf *ms = NULL, *me = NULL;
3296 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3299 #if defined(TULIP_DEBUG)
3300 if (cnt == ri->ri_max)
3304 * If the TULIP has no descriptors, there can't be any receive
3305 * descriptors to process.
3307 if (eop == ri->ri_nextout)
3311 * 90% of the packets will fit in one descriptor. So we optimize
3314 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3315 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3316 IF_DEQUEUE(&sc->tulip_rxq, ms);
3320 * If still owned by the TULIP, don't touch it.
3322 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3326 * It is possible (though improbable unless the BIG_PACKET support
3327 * is enabled or MCLBYTES < 1518) for a received packet to cross
3328 * more than one receive descriptor.
3330 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3331 if (++eop == ri->ri_last)
3333 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3334 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3335 #if defined(TULIP_DEBUG)
3336 sc->tulip_dbg.dbg_rxintrs++;
3337 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3345 * Dequeue the first buffer for the start of the packet. Hopefully
3346 * this will be the only one we need to dequeue. However, if the
3347 * packet consumed multiple descriptors, then we need to dequeue
3348 * those buffers and chain to the starting mbuf. All buffers but
3349 * the last buffer have the same length so we can set that now.
3350 * (we add to last_offset instead of multiplying since we normally
3351 * won't go into the loop and thereby saving a ourselves from
3352 * doing a multiplication by 0 in the normal case).
3354 IF_DEQUEUE(&sc->tulip_rxq, ms);
3355 for (me = ms; total_len > 0; total_len--) {
3356 me->m_len = TULIP_RX_BUFLEN;
3357 last_offset += TULIP_RX_BUFLEN;
3358 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3364 * Now get the size of received packet (minus the CRC).
3366 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3367 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3368 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3370 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3371 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3372 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3373 TULIP_DSTS_RxOVERFLOW)) == 0)
3376 me->m_len = total_len - last_offset;
3378 eh = *mtod(ms, struct ether_header *);
3379 sc->tulip_flags |= TULIP_RXACT;
3383 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3384 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3386 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3387 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3389 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3390 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3391 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3393 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3398 #if defined(TULIP_DEBUG)
3402 if (++eop == ri->ri_last)
3404 ri->ri_nextin = eop;
3407 * Either we are priming the TULIP with mbufs (m == NULL)
3408 * or we are about to accept an mbuf for the upper layers
3409 * so we need to allocate an mbuf to replace it. If we
3410 * can't replace it, send up it anyways. This may cause
3411 * us to drop packets in the future but that's better than
3412 * being caught in livelock.
3414 * Note that if this packet crossed multiple descriptors
3415 * we don't even try to reallocate all the mbufs here.
3416 * Instead we rely on the test of the beginning of
3417 * the loop to refill for the extra consumed mbufs.
3419 if (accept || ms == NULL) {
3421 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
3423 #if defined(TULIP_COPY_RXDATA)
3424 if (!accept || total_len >= (MHLEN - 2)) {
3426 MCLGET(m0, MB_DONTWAIT);
3427 if ((m0->m_flags & M_EXT) == 0) {
3431 #if defined(TULIP_COPY_RXDATA)
3436 #if defined(TULIP_COPY_RXDATA)
3440 #if !defined(TULIP_COPY_RXDATA)
3441 ms->m_pkthdr.len = total_len;
3442 ms->m_pkthdr.rcvif = ifp;
3443 m_adj(ms, sizeof(struct ether_header));
3444 ether_input(ifp, &eh, ms);
3447 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3449 m0->m_data += 2; /* align data after header */
3450 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3451 m0->m_len = m0->m_pkthdr.len = total_len;
3452 m0->m_pkthdr.rcvif = ifp;
3453 m_adj(m0, sizeof(struct ether_header));
3454 ether_input(ifp, &eh, m0);
3456 #endif /* ! TULIP_COPY_RXDATA */
3462 * Couldn't allocate a new buffer. Don't bother
3463 * trying to replenish the receive queue.
3466 sc->tulip_flags |= TULIP_RXBUFSLOW;
3467 #if defined(TULIP_DEBUG)
3468 sc->tulip_dbg.dbg_rxlowbufs++;
3473 * Now give the buffer(s) to the TULIP and save in our
3477 tulip_desc_t * const nextout = ri->ri_nextout;
3478 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3479 nextout->d_length1 = TULIP_RX_BUFLEN;
3480 nextout->d_status = TULIP_DSTS_OWNER;
3481 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3482 if (++ri->ri_nextout == ri->ri_last)
3483 ri->ri_nextout = ri->ri_first;
3486 IF_ENQUEUE(&sc->tulip_rxq, ms);
3487 } while ((ms = me) != NULL);
3489 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3490 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3493 #if defined(TULIP_DEBUG)
3494 sc->tulip_dbg.dbg_rxintrs++;
3495 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3501 tulip_softc_t * const sc)
3503 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3508 while (ri->ri_free < ri->ri_max) {
3511 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3512 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3517 d_flag = ri->ri_nextin->d_flag;
3518 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3519 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3521 * We've just finished processing a setup packet.
3522 * Mark that we finished it. If there's not
3523 * another pending, startup the TULIP receiver.
3524 * Make sure we ack the RXSTOPPED so we won't get
3525 * an abormal interrupt indication.
3527 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3528 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3529 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3530 sc->tulip_flags |= TULIP_HASHONLY;
3531 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3533 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3534 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3535 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3536 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3537 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3540 const u_int32_t d_status = ri->ri_nextin->d_status;
3541 IF_DEQUEUE(&sc->tulip_txq, m);
3544 #if defined(TULIP_DEBUG)
3546 printf("%s%d: tx_intr: failed to dequeue mbuf?!?\n",
3547 sc->tulip_name, sc->tulip_unit);
3550 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3551 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3552 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3553 #if defined(TULIP_DEBUG)
3554 if (d_status & TULIP_DSTS_TxNOCARR)
3555 sc->tulip_dbg.dbg_txprobe_nocarr++;
3556 if (d_status & TULIP_DSTS_TxEXCCOLL)
3557 sc->tulip_dbg.dbg_txprobe_exccoll++;
3559 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3561 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3563 * Escape from the loop before media poll has reset the TULIP!
3568 if (d_status & TULIP_DSTS_ERRSUM) {
3569 sc->tulip_if.if_oerrors++;
3570 if (d_status & TULIP_DSTS_TxEXCCOLL)
3571 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3572 if (d_status & TULIP_DSTS_TxLATECOLL)
3573 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3574 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3575 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3576 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3577 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3578 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3579 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3580 if (d_status & TULIP_DSTS_TxBABBLE)
3581 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3583 u_int32_t collisions =
3584 (d_status & TULIP_DSTS_TxCOLLMASK)
3585 >> TULIP_DSTS_V_TxCOLLCNT;
3586 sc->tulip_if.if_collisions += collisions;
3587 if (collisions == 1)
3588 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3589 else if (collisions > 1)
3590 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3591 else if (d_status & TULIP_DSTS_TxDEFERRED)
3592 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3594 * SQE is only valid for 10baseT/BNC/AUI when not
3595 * running in full-duplex. In order to speed up the
3596 * test, the corresponding bit in tulip_flags needs to
3597 * set as well to get us to count SQE Test Errors.
3599 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3600 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3606 if (++ri->ri_nextin == ri->ri_last)
3607 ri->ri_nextin = ri->ri_first;
3609 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3610 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3613 * If nothing left to transmit, disable the timer.
3614 * Else if progress, reset the timer back to 2 ticks.
3616 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3617 sc->tulip_txtimer = 0;
3619 sc->tulip_txtimer = TULIP_TXTIMER;
3620 sc->tulip_if.if_opackets += xmits;
3625 tulip_print_abnormal_interrupt(
3626 tulip_softc_t * const sc,
3629 const char * const *msgp = tulip_status_bits;
3632 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3634 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3635 printf("%s%d: abnormal interrupt:", sc->tulip_name, sc->tulip_unit);
3636 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3637 if ((csr & mask) && *msgp != NULL) {
3638 printf("%s%s", sep, *msgp);
3639 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3640 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3641 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3642 printf(" (switching to store-and-forward mode)");
3644 printf(" (raising TX threshold to %s)",
3645 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3656 tulip_softc_t * const sc,
3661 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3663 TULIP_CSR_WRITE(sc, csr_status, csr);
3665 if (csr & TULIP_STS_SYSERROR) {
3666 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3667 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3668 sc->tulip_flags |= TULIP_SYSTEMERROR;
3670 printf("%s%d: system error: %s\n",
3671 sc->tulip_name, sc->tulip_unit,
3672 tulip_system_errors[sc->tulip_last_system_error]);
3674 sc->tulip_flags |= TULIP_NEEDRESET;
3675 sc->tulip_system_errors++;
3678 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3679 #if defined(TULIP_DEBUG)
3680 sc->tulip_dbg.dbg_link_intrs++;
3682 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3683 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3684 ? TULIP_MEDIAPOLL_LINKFAIL
3685 : TULIP_MEDIAPOLL_LINKPASS);
3686 csr &= ~TULIP_STS_ABNRMLINTR;
3688 tulip_media_print(sc);
3690 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3691 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3692 if (csr & TULIP_STS_RXNOBUF)
3693 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3695 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3696 * on receive overflows.
3698 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3699 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3701 * Stop the receiver process and spin until it's stopped.
3702 * Tell rx_intr to drop the packets it dequeues.
3704 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3705 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3707 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3708 sc->tulip_flags |= TULIP_RXIGNORE;
3711 if (sc->tulip_flags & TULIP_RXIGNORE) {
3713 * Restart the receiver.
3715 sc->tulip_flags &= ~TULIP_RXIGNORE;
3716 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3719 if (csr & TULIP_STS_ABNRMLINTR) {
3720 u_int32_t tmp = csr & sc->tulip_intrmask
3721 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3722 if (csr & TULIP_STS_TXUNDERFLOW) {
3723 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3724 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3725 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3726 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3727 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3728 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3731 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3732 sc->tulip_statusbits |= tmp;
3734 tulip_print_abnormal_interrupt(sc, tmp);
3735 sc->tulip_flags |= TULIP_NOMESSAGES;
3737 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3739 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3741 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3742 tulip_ifstart(&sc->tulip_if);
3745 if (sc->tulip_flags & TULIP_NEEDRESET) {
3755 tulip_softc_t * sc = arg;
3758 for (; sc != NULL; sc = sc->tulip_slaves) {
3759 #if defined(TULIP_DEBUG)
3760 sc->tulip_dbg.dbg_intrs++;
3762 tulip_intr_handler(sc, &progress);
3770 tulip_softc_t * sc = (tulip_softc_t *) arg;
3773 #if defined(TULIP_DEBUG)
3774 sc->tulip_dbg.dbg_intrs++;
3776 tulip_intr_handler(sc, &progress);
3779 static struct mbuf *
3780 tulip_mbuf_compress(
3784 #if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET)
3785 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
3787 if (m->m_pkthdr.len > MHLEN) {
3788 MCLGET(m0, MB_DONTWAIT);
3789 if ((m0->m_flags & M_EXT) == 0) {
3795 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
3796 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
3800 int len = m->m_pkthdr.len;
3801 struct mbuf **mp = &m0;
3804 if (mlen == MHLEN) {
3805 MGETHDR(*mp, MB_DONTWAIT, MT_DATA);
3807 MGET(*mp, MB_DONTWAIT, MT_DATA);
3815 MCLGET(*mp, MB_DONTWAIT);
3816 if (((*mp)->m_flags & M_EXT) == 0) {
3821 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
3823 (*mp)->m_len = len <= mlen ? len : mlen;
3825 m_copydata(m, m->m_pkthdr.len - len,
3826 (*mp)->m_len, mtod((*mp), caddr_t));
3827 len -= (*mp)->m_len;
3828 mp = &(*mp)->m_next;
3836 static struct mbuf *
3838 tulip_softc_t * const sc,
3841 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3842 tulip_desc_t *eop, *nextout;
3847 #if defined(TULIP_DEBUG)
3848 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
3849 printf("%s%d: txput%s: tx not running\n",
3850 sc->tulip_name, sc->tulip_unit,
3851 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
3852 sc->tulip_flags |= TULIP_WANTTXSTART;
3853 sc->tulip_dbg.dbg_txput_finishes[0]++;
3859 * Now we try to fill in our transmit descriptors. This is
3860 * a bit reminiscent of going on the Ark two by two
3861 * since each descriptor for the TULIP can describe
3862 * two buffers. So we advance through packet filling
3863 * each of the two entries at a time to to fill each
3864 * descriptor. Clear the first and last segment bits
3865 * in each descriptor (actually just clear everything
3866 * but the end-of-ring or chain bits) to make sure
3867 * we don't get messed up by previously sent packets.
3869 * We may fail to put the entire packet on the ring if
3870 * there is either not enough ring entries free or if the
3871 * packet has more than MAX_TXSEG segments. In the former
3872 * case we will just wait for the ring to empty. In the
3873 * latter case we have to recopy.
3878 eop = nextout = ri->ri_nextout;
3883 int len = m0->m_len;
3884 caddr_t addr = mtod(m0, caddr_t);
3885 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
3888 unsigned slen = min(len, clsize);
3892 slen = 2040, partial = 1;
3895 if (segcnt > TULIP_MAX_TXSEG) {
3897 * The packet exceeds the number of transmit buffer
3898 * entries that we can use for one packet, so we have
3899 * recopy it into one mbuf and then try again.
3901 m = tulip_mbuf_compress(m);
3909 * See if there's any unclaimed space in the
3912 if ((free += tulip_tx_intr(sc)) == 0) {
3914 * There's no more room but since nothing
3915 * has been committed at this point, just
3916 * show output is active, put back the
3919 sc->tulip_flags |= TULIP_WANTTXSTART;
3920 #if defined(TULIP_DEBUG)
3921 sc->tulip_dbg.dbg_txput_finishes[1]++;
3927 if (++nextout == ri->ri_last)
3928 nextout = ri->ri_first;
3929 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
3930 eop->d_status = d_status;
3931 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
3932 eop->d_length1 = slen;
3935 * Fill in second half of descriptor
3937 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
3938 eop->d_length2 = slen;
3940 d_status = TULIP_DSTS_OWNER;
3949 } while ((m0 = m0->m_next) != NULL);
3951 BPF_MTAP(&sc->tulip_if, m);
3954 * The descriptors have been filled in. Now get ready
3957 IF_ENQUEUE(&sc->tulip_txq, m);
3961 * Make sure the next descriptor after this packet is owned
3962 * by us since it may have been set up above if we ran out
3963 * of room in the ring.
3965 nextout->d_status = 0;
3966 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
3969 * If we only used the first segment of the last descriptor,
3970 * make sure the second segment will not be used.
3978 * Mark the last and first segments, indicate we want a transmit
3979 * complete interrupt, and tell it to transmit!
3981 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
3984 * Note that ri->ri_nextout is still the start of the packet
3985 * and until we set the OWNER bit, we can still back out of
3986 * everything we have done.
3988 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
3989 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
3990 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
3993 * This advances the ring for us.
3995 ri->ri_nextout = nextout;
3998 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3999 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4000 sc->tulip_if.if_flags |= IFF_OACTIVE;
4001 sc->tulip_if.if_start = tulip_ifstart;
4006 * switch back to the single queueing ifstart.
4008 sc->tulip_flags &= ~TULIP_WANTTXSTART;
4009 if (sc->tulip_txtimer == 0)
4010 sc->tulip_txtimer = TULIP_TXTIMER;
4011 #if defined(TULIP_DEBUG)
4012 sc->tulip_dbg.dbg_txput_finishes[5]++;
4016 * If we want a txstart, there must be not enough space in the
4017 * transmit ring. So we want to enable transmit done interrupts
4018 * so we can immediately reclaim some space. When the transmit
4019 * interrupt is posted, the interrupt handler will call tx_intr
4020 * to reclaim space and then txstart (since WANTTXSTART is set).
4021 * txstart will move the packet into the transmit ring and clear
4022 * WANTTXSTART thereby causing TXINTR to be cleared.
4025 #if defined(TULIP_DEBUG)
4026 sc->tulip_dbg.dbg_txput_finishes[6]++;
4028 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
4029 sc->tulip_if.if_flags |= IFF_OACTIVE;
4030 sc->tulip_if.if_start = tulip_ifstart;
4031 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4032 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4033 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4035 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
4036 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
4037 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
4038 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4041 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4047 tulip_softc_t * const sc)
4049 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4050 tulip_desc_t *nextout;
4053 * We will transmit, at most, one setup packet per call to ifstart.
4056 #if defined(TULIP_DEBUG)
4057 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4058 printf("%s%d: txput_setup: tx not running\n",
4059 sc->tulip_name, sc->tulip_unit);
4060 sc->tulip_flags |= TULIP_WANTTXSTART;
4061 sc->tulip_if.if_start = tulip_ifstart;
4066 * Try to reclaim some free descriptors..
4068 if (ri->ri_free < 2)
4070 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
4071 sc->tulip_flags |= TULIP_WANTTXSTART;
4072 sc->tulip_if.if_start = tulip_ifstart;
4075 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
4076 sizeof(sc->tulip_setupbuf));
4078 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
4079 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
4081 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
4083 nextout = ri->ri_nextout;
4084 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4085 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
4086 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
4087 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
4088 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
4089 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
4090 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
4092 nextout->d_length2 = 0;
4093 nextout->d_addr2 = 0;
4094 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
4095 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
4098 * Advance the ring for the next transmit packet.
4100 if (++ri->ri_nextout == ri->ri_last)
4101 ri->ri_nextout = ri->ri_first;
4104 * Make sure the next descriptor is owned by us since it
4105 * may have been set up above if we ran out of room in the
4108 ri->ri_nextout->d_status = 0;
4109 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4110 nextout->d_status = TULIP_DSTS_OWNER;
4112 * Flush the ownwership of the current descriptor
4114 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4115 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4116 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4117 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4118 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4130 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4131 struct ifaddr *ifa = (struct ifaddr *)data;
4132 struct ifreq *ifr = (struct ifreq *) data;
4139 ifp->if_flags |= IFF_UP;
4140 switch(ifa->ifa_addr->sa_family) {
4144 arp_ifinit(&(sc)->tulip_ac.ac_if, ifa);
4151 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
4152 if (ipx_nullhost(*ina)) {
4153 ina->x_host = *(union ipx_host *)(sc->tulip_enaddr);
4155 ifp->if_flags &= ~IFF_RUNNING;
4156 bcopy((caddr_t)ina->x_host.c_host,
4157 (caddr_t)sc->tulip_enaddr,
4158 sizeof(sc->tulip_enaddr));
4167 * This magic copied from if_is.c; I don't use XNS,
4168 * so I have no way of telling if this actually
4172 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
4173 if (ns_nullhost(*ina)) {
4174 ina->x_host = *(union ns_host *)(sc->tulip_enaddr);
4176 ifp->if_flags &= ~IFF_RUNNING;
4177 bcopy((caddr_t)ina->x_host.c_host,
4178 (caddr_t)sc->tulip_enaddr,
4179 sizeof(sc->tulip_enaddr));
4194 bcopy((caddr_t) sc->tulip_enaddr,
4195 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
4200 case SIOCSIFFLAGS: {
4201 tulip_addr_filter(sc); /* reinit multicast filter */
4207 case SIOCGIFMEDIA: {
4208 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
4213 case SIOCDELMULTI: {
4215 * Update multicast listeners
4217 tulip_addr_filter(sc); /* reset multicast filtering */
4225 * Set the interface MTU.
4227 if (ifr->ifr_mtu > ETHERMTU
4229 && sc->tulip_chipid != TULIP_21140
4230 && sc->tulip_chipid != TULIP_21140A
4231 && sc->tulip_chipid != TULIP_21041
4237 ifp->if_mtu = ifr->ifr_mtu;
4245 case SIOCGADDRROM: {
4246 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
4252 ifr->ifr_metric = (int) sc->tulip_chipid;
4268 struct ifnet * const ifp)
4270 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4272 if (sc->tulip_if.if_flags & IFF_RUNNING) {
4274 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
4275 tulip_txput_setup(sc);
4277 while (sc->tulip_if.if_snd.ifq_head != NULL) {
4279 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
4280 if ((m = tulip_txput(sc, m)) != NULL) {
4281 IF_PREPEND(&sc->tulip_if.if_snd, m);
4292 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4294 #if defined(TULIP_DEBUG)
4295 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
4296 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
4297 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
4298 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
4299 #endif /* TULIP_DEBUG */
4301 sc->tulip_if.if_timer = 1;
4303 * These should be rare so do a bulk test up front so we can just skip
4306 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
4308 * If the number of receive buffer is low, try to refill
4310 if (sc->tulip_flags & TULIP_RXBUFSLOW)
4313 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
4314 printf("%s%d: %d system errors: last was %s\n",
4315 sc->tulip_name, sc->tulip_unit, sc->tulip_system_errors,
4316 tulip_system_errors[sc->tulip_last_system_error]);
4318 if (sc->tulip_statusbits) {
4319 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
4320 sc->tulip_statusbits = 0;
4323 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
4326 if (sc->tulip_txtimer)
4328 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
4329 printf("%s%d: transmission timeout\n", sc->tulip_name, sc->tulip_unit);
4330 if (TULIP_DO_AUTOSENSE(sc)) {
4331 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4332 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
4333 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
4341 * All printf's are real as of now!
4349 tulip_softc_t * const sc)
4351 struct ifnet * const ifp = &sc->tulip_if;
4353 callout_init(&sc->tulip_timer);
4354 callout_init(&sc->tulip_fast_timer);
4356 if_initname(ifp, sc->tulip_name, sc->tulip_unit);
4357 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
4358 ifp->if_ioctl = tulip_ifioctl;
4359 ifp->if_start = tulip_ifstart;
4360 ifp->if_watchdog = tulip_ifwatchdog;
4363 printf("%s%d: %s%s pass %d.%d%s\n",
4364 sc->tulip_name, sc->tulip_unit,
4366 tulip_chipdescs[sc->tulip_chipid],
4367 (sc->tulip_revinfo & 0xF0) >> 4,
4368 sc->tulip_revinfo & 0x0F,
4369 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
4370 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
4372 (*sc->tulip_boardsw->bd_media_probe)(sc);
4373 ifmedia_init(&sc->tulip_ifmedia, 0,
4374 tulip_ifmedia_change,
4375 tulip_ifmedia_status);
4376 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
4377 tulip_ifmedia_add(sc);
4381 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr);
4382 ifp->if_snd.ifq_maxlen = ifqmaxlen;
4387 tulip_softc_t * const sc,
4388 tulip_csrptr_t csr_base,
4391 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
4392 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
4393 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
4394 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
4395 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
4396 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
4397 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
4398 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
4399 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
4400 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
4401 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
4402 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
4403 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
4404 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
4405 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
4406 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
4411 tulip_softc_t * const sc,
4412 tulip_ringinfo_t * const ri,
4413 tulip_desc_t *descs,
4416 ri->ri_max = ndescs;
4417 ri->ri_first = descs;
4418 ri->ri_last = ri->ri_first + ri->ri_max;
4419 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
4420 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
4424 * This is the PCI configuration support.
4427 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
4428 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
4429 #define PCI_CFDA 0x40 /* Configuration Driver Area */
4432 tulip_pci_probe(device_t dev)
4434 const char *name = NULL;
4436 if (pci_get_vendor(dev) != DEC_VENDORID)
4440 * Some LanMedia WAN cards use the Tulip chip, but they have
4441 * their own driver, and we should not recognize them
4443 if (pci_get_subvendor(dev) == 0x1376)
4446 switch (pci_get_device(dev)) {
4448 name = "Digital 21040 Ethernet";
4451 name = "Digital 21041 Ethernet";
4454 if (pci_get_revid(dev) >= 0x20)
4455 name = "Digital 21140A Fast Ethernet";
4457 name = "Digital 21140 Fast Ethernet";
4460 if (pci_get_revid(dev) >= 0x20)
4461 name = "Digital 21143 Fast Ethernet";
4463 name = "Digital 21142 Fast Ethernet";
4467 device_set_desc(dev, name);
4474 tulip_shutdown(device_t dev)
4476 tulip_softc_t * const sc = device_get_softc(dev);
4477 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4478 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4479 33MHz that comes to two microseconds but wait a
4480 bit longer anyways) */
4485 tulip_pci_attach(device_t dev)
4489 u_int32_t revinfo, cfdainfo, cfcsinfo;
4490 unsigned csroffset = TULIP_PCI_CSROFFSET;
4491 unsigned csrsize = TULIP_PCI_CSRSIZE;
4492 tulip_csrptr_t csr_base;
4493 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4494 struct resource *res;
4497 unit = device_get_unit(dev);
4499 if (unit >= TULIP_MAX_DEVICES) {
4500 printf("de%d", unit);
4501 printf(": not configured; limit of %d reached or exceeded\n",
4506 revinfo = pci_get_revid(dev);
4507 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4508 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
4510 /* turn busmaster on in case BIOS doesn't set it */
4511 if(!(cfcsinfo & PCIM_CMD_BUSMASTEREN)) {
4512 cfcsinfo |= PCIM_CMD_BUSMASTEREN;
4513 pci_write_config(dev, PCIR_COMMAND, cfcsinfo, 4);
4516 if (pci_get_vendor(dev) == DEC_VENDORID) {
4517 if (pci_get_device(dev) == CHIPID_21040)
4518 chipid = TULIP_21040;
4519 else if (pci_get_device(dev) == CHIPID_21041)
4520 chipid = TULIP_21041;
4521 else if (pci_get_device(dev) == CHIPID_21140)
4522 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4523 else if (pci_get_device(dev) == CHIPID_21142)
4524 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4526 if (chipid == TULIP_CHIPID_UNKNOWN)
4529 if (chipid == TULIP_21040 && revinfo < 0x20) {
4530 printf("de%d", unit);
4531 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
4532 revinfo >> 4, revinfo & 0x0f);
4534 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4535 printf("de%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
4536 unit, revinfo >> 4, revinfo & 0x0f);
4540 sc = device_get_softc(dev);
4541 sc->tulip_pci_busno = pci_get_bus(dev);
4542 sc->tulip_pci_devno = pci_get_slot(dev);
4543 sc->tulip_chipid = chipid;
4544 sc->tulip_flags |= TULIP_DEVICEPROBE;
4545 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4546 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4547 if (chipid == TULIP_21140A && revinfo <= 0x22)
4548 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4549 if (chipid == TULIP_21140)
4550 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4551 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4552 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4553 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4554 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4555 if (chipid != TULIP_21041 || revinfo >= 0x20)
4556 sc->tulip_features |= TULIP_HAVE_SIANWAY;
4557 if (chipid != TULIP_21041)
4558 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
4559 if (chipid != TULIP_21041 && revinfo >= 0x20)
4560 sc->tulip_features |= TULIP_HAVE_SIA100;
4563 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
4564 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
4565 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
4566 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
4569 sc->tulip_unit = unit;
4570 sc->tulip_name = "de";
4571 sc->tulip_revinfo = revinfo;
4572 sc->tulip_if.if_softc = sc;
4573 #if defined(TULIP_IOMAPPED)
4575 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
4576 0, ~0, 1, RF_ACTIVE);
4579 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
4580 0, ~0, 1, RF_ACTIVE);
4584 sc->tulip_csrs_bst = rman_get_bustag(res);
4585 sc->tulip_csrs_bsh = rman_get_bushandle(res);
4590 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
4592 sc->tulip_rxdescs = malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
4593 M_DEVBUF, M_INTWAIT);
4594 sc->tulip_txdescs = malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
4595 M_DEVBUF, M_INTWAIT);
4597 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
4598 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
4601 * Make sure there won't be any interrupts or such...
4603 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4604 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
4605 33MHz that comes to two microseconds but wait a
4606 bit longer anyways) */
4608 if ((retval = tulip_read_macaddr(sc)) < 0) {
4609 printf("%s%d", sc->tulip_name, sc->tulip_unit);
4610 printf(": can't read ENET ROM (why=%d) (", retval);
4611 for (idx = 0; idx < 32; idx++)
4612 printf("%02x", sc->tulip_rombuf[idx]);
4614 printf("%s%d: %s%s pass %d.%d\n",
4615 sc->tulip_name, sc->tulip_unit,
4616 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
4617 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
4618 printf("%s%d: address unknown\n", sc->tulip_name, sc->tulip_unit);
4621 void (*intr_rtn)(void *) = tulip_intr_normal;
4623 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
4624 intr_rtn = tulip_intr_shared;
4626 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
4630 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
4631 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
4632 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
4633 intr_rtn, sc, &ih)) {
4634 printf("%s%d: couldn't map interrupt\n",
4635 sc->tulip_name, sc->tulip_unit);
4636 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
4637 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
4649 static device_method_t tulip_pci_methods[] = {
4650 /* Device interface */
4651 DEVMETHOD(device_probe, tulip_pci_probe),
4652 DEVMETHOD(device_attach, tulip_pci_attach),
4653 DEVMETHOD(device_shutdown, tulip_shutdown),
4656 static driver_t tulip_pci_driver = {
4659 sizeof(tulip_softc_t),
4661 static devclass_t tulip_devclass;
4663 DECLARE_DUMMY_MODULE(if_de);
4664 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);