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.20 2005/02/21 04:38:21 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 TULIP_PERFSTART(timeout)
146 sc->tulip_flags &= ~TULIP_TIMEOUTPENDING;
147 sc->tulip_probe_timeout -= 1000 / TULIP_HZ;
148 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_TIMER);
150 TULIP_PERFEND(timeout);
156 tulip_softc_t * const sc)
158 if (sc->tulip_flags & TULIP_TIMEOUTPENDING)
160 sc->tulip_flags |= TULIP_TIMEOUTPENDING;
161 callout_reset(&sc->tulip_timer, (hz + TULIP_HZ / 2) / TULIP_HZ,
162 tulip_timeout_callback, sc);
165 #if defined(TULIP_NEED_FASTTIMEOUT)
167 tulip_fasttimeout_callback(
170 tulip_softc_t * const sc = arg;
173 sc->tulip_flags &= ~TULIP_FASTTIMEOUTPENDING;
174 (sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_FASTTIMER);
180 tulip_softc_t * const sc)
182 if (sc->tulip_flags & TULIP_FASTTIMEOUTPENDING)
184 sc->tulip_flags |= TULIP_FASTTIMEOUTPENDING;
185 callout_reset(&sc->tulip_fast_timer, 1, tulip_fasttimeout_callback, sc);
191 tulip_softc_t * const sc)
195 * Before we are sure this is the right media we need
196 * to send a small packet to make sure there's carrier.
197 * Strangely, BNC and AUI will "see" receive data if
198 * either is connected so the transmit is the only way
199 * to verify the connectivity.
201 MGETHDR(m, MB_DONTWAIT, MT_DATA);
205 * Construct a LLC TEST message which will point to ourselves.
207 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_dhost, 6);
208 bcopy(sc->tulip_enaddr, mtod(m, struct ether_header *)->ether_shost, 6);
209 mtod(m, struct ether_header *)->ether_type = htons(3);
210 mtod(m, unsigned char *)[14] = 0;
211 mtod(m, unsigned char *)[15] = 0;
212 mtod(m, unsigned char *)[16] = 0xE3; /* LLC Class1 TEST (no poll) */
213 m->m_len = m->m_pkthdr.len = sizeof(struct ether_header) + 3;
217 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
218 sc->tulip_intrmask |= TULIP_STS_TXINTR;
219 sc->tulip_flags |= TULIP_TXPROBE_ACTIVE;
220 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
221 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
222 if ((m = tulip_txput(sc, m)) != NULL)
224 sc->tulip_probe.probe_txprobes++;
229 #define TULIP_SIAGEN_WATCHDOG (sc->tulip_if.if_mtu > ETHERMTU ? TULIP_WATCHDOG_RXDISABLE|TULIP_WATCHDOG_TXDISABLE : 0)
231 #define TULIP_SIAGEN_WATCHDOG 0
236 tulip_softc_t * const sc,
239 const tulip_media_info_t *mi = sc->tulip_mediums[media];
245 * If we are switching media, make sure we don't think there's
246 * any stale RX activity
248 sc->tulip_flags &= ~TULIP_RXACT;
249 if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
250 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
251 TULIP_CSR_WRITE(sc, csr_sia_tx_rx, mi->mi_sia_tx_rx);
252 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
253 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_control|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
255 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_gp_data|mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
257 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_sia_general|TULIP_SIAGEN_WATCHDOG);
259 TULIP_CSR_WRITE(sc, csr_sia_connectivity, mi->mi_sia_connectivity);
260 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
261 #define TULIP_GPR_CMDBITS (TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_SCRAMBLER|TULIP_CMD_TXTHRSHLDCTL)
263 * If the cmdmode bits don't match the currently operating mode,
264 * set the cmdmode appropriately and reset the chip.
266 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
267 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
268 sc->tulip_cmdmode |= mi->mi_cmdmode;
271 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
273 TULIP_CSR_WRITE(sc, csr_gp, (u_int8_t) mi->mi_gpdata);
274 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
276 * If the cmdmode bits don't match the currently operating mode,
277 * set the cmdmode appropriately and reset the chip.
279 if (((mi->mi_cmdmode ^ TULIP_CSR_READ(sc, csr_command)) & TULIP_GPR_CMDBITS) != 0) {
280 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
281 sc->tulip_cmdmode |= mi->mi_cmdmode;
284 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpcontrol);
285 TULIP_CSR_WRITE(sc, csr_sia_general, mi->mi_gpdata);
286 } else if (mi->mi_type == TULIP_MEDIAINFO_MII
287 && sc->tulip_probe_state != TULIP_PROBE_INACTIVE) {
289 if (sc->tulip_features & TULIP_HAVE_SIAGP) {
291 dp = &sc->tulip_rombuf[mi->mi_reset_offset];
292 for (idx = 0; idx < mi->mi_reset_length; idx++, dp += 2) {
294 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
296 sc->tulip_phyaddr = mi->mi_phyaddr;
297 dp = &sc->tulip_rombuf[mi->mi_gpr_offset];
298 for (idx = 0; idx < mi->mi_gpr_length; idx++, dp += 2) {
300 TULIP_CSR_WRITE(sc, csr_sia_general, (dp[0] + 256 * dp[1]) << 16);
303 for (idx = 0; idx < mi->mi_reset_length; idx++) {
305 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx]);
307 sc->tulip_phyaddr = mi->mi_phyaddr;
308 for (idx = 0; idx < mi->mi_gpr_length; idx++) {
310 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx]);
313 if (sc->tulip_flags & TULIP_TRYNWAY) {
314 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
315 } else if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
316 u_int32_t data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_CONTROL);
317 data &= ~(PHYCTL_SELECT_100MB|PHYCTL_FULL_DUPLEX|PHYCTL_AUTONEG_ENABLE);
318 sc->tulip_flags &= ~TULIP_DIDNWAY;
319 if (TULIP_IS_MEDIA_FD(media))
320 data |= PHYCTL_FULL_DUPLEX;
321 if (TULIP_IS_MEDIA_100MB(media))
322 data |= PHYCTL_SELECT_100MB;
323 tulip_mii_writereg(sc, sc->tulip_phyaddr, PHYREG_CONTROL, data);
330 tulip_softc_t * const sc,
333 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
334 sc->tulip_flags |= TULIP_PRINTLINKUP;
335 sc->tulip_flags |= TULIP_LINKUP;
336 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
337 #if 0 /* XXX how does with work with ifmedia? */
338 if ((sc->tulip_flags & TULIP_DIDNWAY) == 0) {
339 if (sc->tulip_if.if_flags & IFF_FULLDUPLEX) {
340 if (TULIP_CAN_MEDIA_FD(media)
341 && sc->tulip_mediums[TULIP_FD_MEDIA_OF(media)] != NULL)
342 media = TULIP_FD_MEDIA_OF(media);
344 if (TULIP_IS_MEDIA_FD(media)
345 && sc->tulip_mediums[TULIP_HD_MEDIA_OF(media)] != NULL)
346 media = TULIP_HD_MEDIA_OF(media);
350 if (sc->tulip_media != media) {
352 sc->tulip_dbg.dbg_last_media = sc->tulip_media;
354 sc->tulip_media = media;
355 sc->tulip_flags |= TULIP_PRINTMEDIA;
356 if (TULIP_IS_MEDIA_FD(sc->tulip_media)) {
357 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
358 } else if (sc->tulip_chipid != TULIP_21041 || (sc->tulip_flags & TULIP_DIDNWAY) == 0) {
359 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
363 * We could set probe_timeout to 0 but setting to 3000 puts this
364 * in one central place and the only matters is tulip_link is
365 * followed by a tulip_timeout. Therefore setting it should not
366 * result in aberrant behavour.
368 sc->tulip_probe_timeout = 3000;
369 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
370 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_TRYNWAY);
371 if (sc->tulip_flags & TULIP_INRESET) {
372 tulip_media_set(sc, sc->tulip_media);
373 } else if (sc->tulip_probe_media != sc->tulip_media) {
375 * No reason to change media if we have the right media.
384 tulip_softc_t * const sc)
386 if ((sc->tulip_flags & TULIP_LINKUP) == 0)
388 if (sc->tulip_flags & TULIP_PRINTMEDIA) {
389 printf("%s%d: enabling %s port\n",
390 sc->tulip_name, sc->tulip_unit,
391 tulip_mediums[sc->tulip_media]);
392 sc->tulip_flags &= ~(TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
393 } else if (sc->tulip_flags & TULIP_PRINTLINKUP) {
394 printf("%s%d: link up\n", sc->tulip_name, sc->tulip_unit);
395 sc->tulip_flags &= ~TULIP_PRINTLINKUP;
399 #if defined(TULIP_DO_GPR_SENSE)
401 tulip_21140_gpr_media_sense(
402 tulip_softc_t * const sc)
404 tulip_media_t maybe_media = TULIP_MEDIA_UNKNOWN;
405 tulip_media_t last_media = TULIP_MEDIA_UNKNOWN;
409 * If one of the media blocks contained a default media flag,
412 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
413 const tulip_media_info_t *mi;
415 * Media is not supported (or is full-duplex).
417 if ((mi = sc->tulip_mediums[media]) == NULL || TULIP_IS_MEDIA_FD(media))
419 if (mi->mi_type != TULIP_MEDIAINFO_GPR)
423 * Remember the media is this is the "default" media.
425 if (mi->mi_default && maybe_media == TULIP_MEDIA_UNKNOWN)
429 * No activity mask? Can't see if it is active if there's no mask.
431 if (mi->mi_actmask == 0)
435 * Does the activity data match?
437 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) != mi->mi_actdata)
440 #if defined(TULIP_DEBUG)
441 printf("%s%d: gpr_media_sense: %s: 0x%02x & 0x%02x == 0x%02x\n",
442 sc->tulip_name, sc->tulip_unit, tulip_mediums[media],
443 TULIP_CSR_READ(sc, csr_gp) & 0xFF,
444 mi->mi_actmask, mi->mi_actdata);
447 * It does! If this is the first media we detected, then
448 * remember this media. If isn't the first, then there were
449 * multiple matches which we equate to no match (since we don't
450 * which to select (if any).
452 if (last_media == TULIP_MEDIA_UNKNOWN) {
454 } else if (last_media != media) {
455 last_media = TULIP_MEDIA_UNKNOWN;
458 return (last_media != TULIP_MEDIA_UNKNOWN) ? last_media : maybe_media;
460 #endif /* TULIP_DO_GPR_SENSE */
462 static tulip_link_status_t
463 tulip_media_link_monitor(
464 tulip_softc_t * const sc)
466 const tulip_media_info_t * const mi = sc->tulip_mediums[sc->tulip_media];
467 tulip_link_status_t linkup = TULIP_LINK_DOWN;
470 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
471 panic("tulip_media_link_monitor: %s: botch at line %d\n",
472 tulip_mediums[sc->tulip_media],__LINE__);
474 return TULIP_LINK_UNKNOWN;
479 * Have we seen some packets? If so, the link must be good.
481 if ((sc->tulip_flags & (TULIP_RXACT|TULIP_LINKUP)) == (TULIP_RXACT|TULIP_LINKUP)) {
482 sc->tulip_flags &= ~TULIP_RXACT;
483 sc->tulip_probe_timeout = 3000;
484 return TULIP_LINK_UP;
487 sc->tulip_flags &= ~TULIP_RXACT;
488 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
491 * Read the PHY status register.
493 status = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
494 if (status & PHYSTS_AUTONEG_DONE) {
496 * If the PHY has completed autonegotiation, see the if the
497 * remote systems abilities have changed. If so, upgrade or
498 * downgrade as appropriate.
500 u_int32_t abilities = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_AUTONEG_ABILITIES);
501 abilities = (abilities << 6) & status;
502 if (abilities != sc->tulip_abilities) {
503 #if defined(TULIP_DEBUG)
504 loudprintf("%s%d(phy%d): autonegotiation changed: 0x%04x -> 0x%04x\n",
505 sc->tulip_name, sc->tulip_unit, sc->tulip_phyaddr,
506 sc->tulip_abilities, abilities);
508 if (tulip_mii_map_abilities(sc, abilities)) {
509 tulip_linkup(sc, sc->tulip_probe_media);
510 return TULIP_LINK_UP;
513 * if we had selected media because of autonegotiation,
514 * we need to probe for the new media.
516 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
517 if (sc->tulip_flags & TULIP_DIDNWAY)
518 return TULIP_LINK_DOWN;
522 * The link is now up. If was down, say its back up.
524 if ((status & (PHYSTS_LINK_UP|PHYSTS_REMOTE_FAULT)) == PHYSTS_LINK_UP)
525 linkup = TULIP_LINK_UP;
526 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR) {
528 * No activity sensor? Assume all's well.
530 if (mi->mi_actmask == 0)
531 return TULIP_LINK_UNKNOWN;
533 * Does the activity data match?
535 if ((TULIP_CSR_READ(sc, csr_gp) & mi->mi_actmask) == mi->mi_actdata)
536 linkup = TULIP_LINK_UP;
537 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
539 * Assume non TP ok for now.
541 if (!TULIP_IS_MEDIA_TP(sc->tulip_media))
542 return TULIP_LINK_UNKNOWN;
543 if ((TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL) == 0)
544 linkup = TULIP_LINK_UP;
545 #if defined(TULIP_DEBUG)
546 if (sc->tulip_probe_timeout <= 0)
547 printf("%s%d: sia status = 0x%08x\n", sc->tulip_name,
548 sc->tulip_unit, TULIP_CSR_READ(sc, csr_sia_status));
550 } else if (mi->mi_type == TULIP_MEDIAINFO_SYM) {
551 return TULIP_LINK_UNKNOWN;
554 * We will wait for 3 seconds until the link goes into suspect mode.
556 if (sc->tulip_flags & TULIP_LINKUP) {
557 if (linkup == TULIP_LINK_UP)
558 sc->tulip_probe_timeout = 3000;
559 if (sc->tulip_probe_timeout > 0)
560 return TULIP_LINK_UP;
562 sc->tulip_flags &= ~TULIP_LINKUP;
563 printf("%s%d: link down: cable problem?\n", sc->tulip_name, sc->tulip_unit);
565 #if defined(TULIP_DEBUG)
566 sc->tulip_dbg.dbg_link_downed++;
568 return TULIP_LINK_DOWN;
573 tulip_softc_t * const sc,
574 tulip_mediapoll_event_t event)
576 #if defined(TULIP_DEBUG)
577 sc->tulip_dbg.dbg_events[event]++;
579 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE
580 && event == TULIP_MEDIAPOLL_TIMER) {
581 switch (tulip_media_link_monitor(sc)) {
582 case TULIP_LINK_DOWN: {
584 * Link Monitor failed. Probe for new media.
586 event = TULIP_MEDIAPOLL_LINKFAIL;
589 case TULIP_LINK_UP: {
596 case TULIP_LINK_UNKNOWN: {
598 * We can't tell so don't bother.
605 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
606 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE) {
607 if (TULIP_DO_AUTOSENSE(sc)) {
608 #if defined(TULIP_DEBUG)
609 sc->tulip_dbg.dbg_link_failures++;
611 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
612 if (sc->tulip_if.if_flags & IFF_UP)
613 tulip_reset(sc); /* restart probe */
617 #if defined(TULIP_DEBUG)
618 sc->tulip_dbg.dbg_link_pollintrs++;
622 if (event == TULIP_MEDIAPOLL_START) {
623 sc->tulip_if.if_flags |= IFF_OACTIVE;
624 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE)
626 sc->tulip_probe_mediamask = 0;
627 sc->tulip_probe_passes = 0;
628 #if defined(TULIP_DEBUG)
629 sc->tulip_dbg.dbg_media_probes++;
632 * If the SROM contained an explicit media to use, use it.
634 sc->tulip_cmdmode &= ~(TULIP_CMD_RXRUN|TULIP_CMD_FULLDUPLEX);
635 sc->tulip_flags |= TULIP_TRYNWAY|TULIP_PROBE1STPASS;
636 sc->tulip_flags &= ~(TULIP_DIDNWAY|TULIP_PRINTMEDIA|TULIP_PRINTLINKUP);
638 * connidx is defaulted to a media_unknown type.
640 sc->tulip_probe_media = tulip_srom_conninfo[sc->tulip_connidx].sc_media;
641 if (sc->tulip_probe_media != TULIP_MEDIA_UNKNOWN) {
642 tulip_linkup(sc, sc->tulip_probe_media);
647 if (sc->tulip_features & TULIP_HAVE_GPR) {
648 sc->tulip_probe_state = TULIP_PROBE_GPRTEST;
649 sc->tulip_probe_timeout = 2000;
651 sc->tulip_probe_media = TULIP_MEDIA_MAX;
652 sc->tulip_probe_timeout = 0;
653 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
658 * Ignore txprobe failures or spurious callbacks.
660 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED
661 && sc->tulip_probe_state != TULIP_PROBE_MEDIATEST) {
662 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
667 * If we really transmitted a packet, then that's the media we'll use.
669 if (event == TULIP_MEDIAPOLL_TXPROBE_OK || event == TULIP_MEDIAPOLL_LINKPASS) {
670 if (event == TULIP_MEDIAPOLL_LINKPASS) {
671 /* XXX Check media status just to be sure */
672 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
673 #if defined(TULIP_DEBUG)
675 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
678 tulip_linkup(sc, sc->tulip_probe_media);
683 if (sc->tulip_probe_state == TULIP_PROBE_GPRTEST) {
684 #if defined(TULIP_DO_GPR_SENSE)
686 * Check for media via the general purpose register.
688 * Try to sense the media via the GPR. If the same value
689 * occurs 3 times in a row then just use that.
691 if (sc->tulip_probe_timeout > 0) {
692 tulip_media_t new_probe_media = tulip_21140_gpr_media_sense(sc);
693 #if defined(TULIP_DEBUG)
694 printf("%s%d: media_poll: gpr sensing = %s\n",
695 sc->tulip_name, sc->tulip_unit, tulip_mediums[new_probe_media]);
697 if (new_probe_media != TULIP_MEDIA_UNKNOWN) {
698 if (new_probe_media == sc->tulip_probe_media) {
699 if (--sc->tulip_probe_count == 0)
700 tulip_linkup(sc, sc->tulip_probe_media);
702 sc->tulip_probe_count = 10;
705 sc->tulip_probe_media = new_probe_media;
709 #endif /* TULIP_DO_GPR_SENSE */
711 * Brute force. We cycle through each of the media types
712 * and try to transmit a packet.
714 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
715 sc->tulip_probe_media = TULIP_MEDIA_MAX;
716 sc->tulip_probe_timeout = 0;
721 if (sc->tulip_probe_state != TULIP_PROBE_MEDIATEST
722 && (sc->tulip_features & TULIP_HAVE_MII)) {
723 tulip_media_t old_media = sc->tulip_probe_media;
724 tulip_mii_autonegotiate(sc, sc->tulip_phyaddr);
725 switch (sc->tulip_probe_state) {
726 case TULIP_PROBE_FAILED:
727 case TULIP_PROBE_MEDIATEST: {
729 * Try the next media.
731 sc->tulip_probe_mediamask |= sc->tulip_mediums[sc->tulip_probe_media]->mi_mediamask;
732 sc->tulip_probe_timeout = 0;
734 if (sc->tulip_probe_state == TULIP_PROBE_FAILED)
736 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
738 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 300;
742 case TULIP_PROBE_PHYAUTONEG: {
745 case TULIP_PROBE_INACTIVE: {
747 * Only probe if we autonegotiated a media that hasn't failed.
749 sc->tulip_probe_timeout = 0;
750 if (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media)) {
751 sc->tulip_probe_media = old_media;
754 tulip_linkup(sc, sc->tulip_probe_media);
759 #if defined(DIAGNOSTIC) || defined(TULIP_DEBUG)
760 panic("tulip_media_poll: botch at line %d\n", __LINE__);
767 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED) {
768 #if defined(TULIP_DEBUG)
769 sc->tulip_dbg.dbg_txprobes_failed[sc->tulip_probe_media]++;
771 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
776 * switch to another media if we tried this one enough.
778 if (/* event == TULIP_MEDIAPOLL_TXPROBE_FAILED || */ sc->tulip_probe_timeout <= 0) {
779 #if defined(TULIP_DEBUG)
780 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
781 printf("%s%d: poll media unknown!\n",
782 sc->tulip_name, sc->tulip_unit);
783 sc->tulip_probe_media = TULIP_MEDIA_MAX;
787 * Find the next media type to check for. Full Duplex
788 * types are not allowed.
791 sc->tulip_probe_media -= 1;
792 if (sc->tulip_probe_media == TULIP_MEDIA_UNKNOWN) {
793 if (++sc->tulip_probe_passes == 3) {
794 printf("%s%d: autosense failed: cable problem?\n",
795 sc->tulip_name, sc->tulip_unit);
796 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
797 sc->tulip_if.if_flags &= ~IFF_RUNNING;
798 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
802 sc->tulip_flags ^= TULIP_TRYNWAY; /* XXX */
803 sc->tulip_probe_mediamask = 0;
804 sc->tulip_probe_media = TULIP_MEDIA_MAX - 1;
806 } while (sc->tulip_mediums[sc->tulip_probe_media] == NULL
807 || (sc->tulip_probe_mediamask & TULIP_BIT(sc->tulip_probe_media))
808 || TULIP_IS_MEDIA_FD(sc->tulip_probe_media));
810 #if defined(TULIP_DEBUG)
811 printf("%s%d: %s: probing %s\n", sc->tulip_name, sc->tulip_unit,
812 event == TULIP_MEDIAPOLL_TXPROBE_FAILED ? "txprobe failed" : "timeout",
813 tulip_mediums[sc->tulip_probe_media]);
815 sc->tulip_probe_timeout = TULIP_IS_MEDIA_TP(sc->tulip_probe_media) ? 2500 : 1000;
816 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
817 sc->tulip_probe.probe_txprobes = 0;
819 tulip_media_set(sc, sc->tulip_probe_media);
820 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
825 * If this is hanging off a phy, we know are doing NWAY and we have
826 * forced the phy to a specific speed. Wait for link up before
827 * before sending a packet.
829 switch (sc->tulip_mediums[sc->tulip_probe_media]->mi_type) {
830 case TULIP_MEDIAINFO_MII: {
831 if (sc->tulip_probe_media != tulip_mii_phy_readspecific(sc))
835 case TULIP_MEDIAINFO_SIA: {
836 if (TULIP_IS_MEDIA_TP(sc->tulip_probe_media)) {
837 if (TULIP_CSR_READ(sc, csr_sia_status) & TULIP_SIASTS_LINKFAIL)
839 tulip_linkup(sc, sc->tulip_probe_media);
841 if (sc->tulip_features & TULIP_HAVE_MII)
848 case TULIP_MEDIAINFO_RESET:
849 case TULIP_MEDIAINFO_SYM:
850 case TULIP_MEDIAINFO_NONE:
851 case TULIP_MEDIAINFO_GPR: {
856 * Try to send a packet.
863 tulip_softc_t * const sc)
865 if (sc->tulip_features & TULIP_HAVE_GPR) {
866 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_PINSET|sc->tulip_gpinit);
868 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpdata);
871 * If this board has no media, just return
873 if (sc->tulip_features & TULIP_HAVE_NOMEDIA)
876 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
877 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
878 (*sc->tulip_boardsw->bd_media_poll)(sc, TULIP_MEDIAPOLL_START);
880 tulip_media_set(sc, sc->tulip_media);
885 tulip_21040_mediainfo_init(
886 tulip_softc_t * const sc,
889 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_THRSHLD160
890 |TULIP_CMD_BACKOFFCTR;
891 sc->tulip_if.if_baudrate = 10000000;
893 if (media == TULIP_MEDIA_10BASET || media == TULIP_MEDIA_UNKNOWN) {
894 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[0], 21040, 10BASET);
895 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[1], 21040, 10BASET_FD);
896 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
899 if (media == TULIP_MEDIA_AUIBNC || media == TULIP_MEDIA_UNKNOWN) {
900 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[2], 21040, AUIBNC);
903 if (media == TULIP_MEDIA_UNKNOWN) {
904 TULIP_MEDIAINFO_SIA_INIT(sc, &sc->tulip_mediainfo[3], 21040, EXTSIA);
909 tulip_21040_media_probe(
910 tulip_softc_t * const sc)
912 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_UNKNOWN);
917 tulip_21040_10baset_only_media_probe(
918 tulip_softc_t * const sc)
920 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_10BASET);
921 tulip_media_set(sc, TULIP_MEDIA_10BASET);
922 sc->tulip_media = TULIP_MEDIA_10BASET;
926 tulip_21040_10baset_only_media_select(
927 tulip_softc_t * const sc)
929 sc->tulip_flags |= TULIP_LINKUP;
930 if (sc->tulip_media == TULIP_MEDIA_10BASET_FD) {
931 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
932 sc->tulip_flags &= ~TULIP_SQETEST;
934 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
935 sc->tulip_flags |= TULIP_SQETEST;
937 tulip_media_set(sc, sc->tulip_media);
941 tulip_21040_auibnc_only_media_probe(
942 tulip_softc_t * const sc)
944 tulip_21040_mediainfo_init(sc, TULIP_MEDIA_AUIBNC);
945 sc->tulip_flags |= TULIP_SQETEST|TULIP_LINKUP;
946 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
947 sc->tulip_media = TULIP_MEDIA_AUIBNC;
951 tulip_21040_auibnc_only_media_select(
952 tulip_softc_t * const sc)
954 tulip_media_set(sc, TULIP_MEDIA_AUIBNC);
955 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
958 static const tulip_boardsw_t tulip_21040_boardsw = {
960 tulip_21040_media_probe,
965 static const tulip_boardsw_t tulip_21040_10baset_only_boardsw = {
967 tulip_21040_10baset_only_media_probe,
968 tulip_21040_10baset_only_media_select,
972 static const tulip_boardsw_t tulip_21040_auibnc_only_boardsw = {
974 tulip_21040_auibnc_only_media_probe,
975 tulip_21040_auibnc_only_media_select,
980 tulip_21041_mediainfo_init(
981 tulip_softc_t * const sc)
983 tulip_media_info_t * const mi = sc->tulip_mediainfo;
986 if (sc->tulip_revinfo >= 0x20) {
987 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, 10BASET);
988 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, 10BASET_FD);
989 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041P2, AUI);
990 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041P2, BNC);
994 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[0], 21041, 10BASET);
995 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[1], 21041, 10BASET_FD);
996 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[2], 21041, AUI);
997 TULIP_MEDIAINFO_SIA_INIT(sc, &mi[3], 21041, BNC);
1001 tulip_21041_media_probe(
1002 tulip_softc_t * const sc)
1004 sc->tulip_if.if_baudrate = 10000000;
1005 sc->tulip_cmdmode |= TULIP_CMD_CAPTREFFCT|TULIP_CMD_ENHCAPTEFFCT
1006 |TULIP_CMD_THRSHLD160|TULIP_CMD_BACKOFFCTR;
1007 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
1008 tulip_21041_mediainfo_init(sc);
1012 tulip_21041_media_poll(
1013 tulip_softc_t * const sc,
1014 const tulip_mediapoll_event_t event)
1016 u_int32_t sia_status;
1018 #if defined(TULIP_DEBUG)
1019 sc->tulip_dbg.dbg_events[event]++;
1022 if (event == TULIP_MEDIAPOLL_LINKFAIL) {
1023 if (sc->tulip_probe_state != TULIP_PROBE_INACTIVE
1024 || !TULIP_DO_AUTOSENSE(sc))
1026 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
1027 tulip_reset(sc); /* start probe */
1032 * If we've been been asked to start a poll or link change interrupt
1033 * restart the probe (and reset the tulip to a known state).
1035 if (event == TULIP_MEDIAPOLL_START) {
1036 sc->tulip_if.if_flags |= IFF_OACTIVE;
1037 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_RXRUN);
1039 if (sc->tulip_revinfo >= 0x20) {
1040 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX;
1041 sc->tulip_flags |= TULIP_DIDNWAY;
1044 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1045 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1046 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1047 sc->tulip_probe_timeout = TULIP_21041_PROBE_10BASET_TIMEOUT;
1048 tulip_media_set(sc, TULIP_MEDIA_10BASET);
1053 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1056 if (event == TULIP_MEDIAPOLL_TXPROBE_OK) {
1057 #if defined(TULIP_DEBUG)
1058 sc->tulip_dbg.dbg_txprobes_ok[sc->tulip_probe_media]++;
1060 tulip_linkup(sc, sc->tulip_probe_media);
1064 sia_status = TULIP_CSR_READ(sc, csr_sia_status);
1065 TULIP_CSR_WRITE(sc, csr_sia_status, sia_status);
1066 if ((sia_status & TULIP_SIASTS_LINKFAIL) == 0) {
1067 if (sc->tulip_revinfo >= 0x20) {
1068 if (sia_status & (PHYSTS_10BASET_FD << (16 - 6)))
1069 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1072 * If the link has passed LinkPass, 10baseT is the
1073 * proper media to use.
1075 tulip_linkup(sc, sc->tulip_probe_media);
1080 * wait for up to 2.4 seconds for the link to reach pass state.
1081 * Only then start scanning the other media for activity.
1082 * choose media with receive activity over those without.
1084 if (sc->tulip_probe_media == TULIP_MEDIA_10BASET) {
1085 if (event != TULIP_MEDIAPOLL_TIMER)
1087 if (sc->tulip_probe_timeout > 0
1088 && (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) == 0) {
1092 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1093 sc->tulip_flags |= TULIP_WANTRXACT;
1094 if (sia_status & TULIP_SIASTS_OTHERRXACTIVITY) {
1095 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1097 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1099 tulip_media_set(sc, sc->tulip_probe_media);
1105 * If we failed, clear the txprobe active flag.
1107 if (event == TULIP_MEDIAPOLL_TXPROBE_FAILED)
1108 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1111 if (event == TULIP_MEDIAPOLL_TIMER) {
1113 * If we've received something, then that's our link!
1115 if (sc->tulip_flags & TULIP_RXACT) {
1116 tulip_linkup(sc, sc->tulip_probe_media);
1120 * if no txprobe active
1122 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0
1123 && ((sc->tulip_flags & TULIP_WANTRXACT) == 0
1124 || (sia_status & TULIP_SIASTS_RXACTIVITY))) {
1125 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1131 * Take 2 passes through before deciding to not
1132 * wait for receive activity. Then take another
1133 * two passes before spitting out a warning.
1135 if (sc->tulip_probe_timeout <= 0) {
1136 if (sc->tulip_flags & TULIP_WANTRXACT) {
1137 sc->tulip_flags &= ~TULIP_WANTRXACT;
1138 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1140 printf("%s%d: autosense failed: cable problem?\n",
1141 sc->tulip_name, sc->tulip_unit);
1142 if ((sc->tulip_if.if_flags & IFF_UP) == 0) {
1143 sc->tulip_if.if_flags &= ~IFF_RUNNING;
1144 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1152 * Since this media failed to probe, try the other one.
1154 sc->tulip_probe_timeout = TULIP_21041_PROBE_AUIBNC_TIMEOUT;
1155 if (sc->tulip_probe_media == TULIP_MEDIA_AUI) {
1156 sc->tulip_probe_media = TULIP_MEDIA_BNC;
1158 sc->tulip_probe_media = TULIP_MEDIA_AUI;
1160 tulip_media_set(sc, sc->tulip_probe_media);
1161 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1165 static const tulip_boardsw_t tulip_21041_boardsw = {
1166 TULIP_21041_GENERIC,
1167 tulip_21041_media_probe,
1169 tulip_21041_media_poll
1172 static const tulip_phy_attr_t tulip_mii_phy_attrlist[] = {
1173 { 0x20005c00, 0, /* 08-00-17 */
1175 { 0x19, 0x0040, 0x0040 }, /* 10TX */
1176 { 0x19, 0x0040, 0x0000 }, /* 100TX */
1178 #if defined(TULIP_DEBUG)
1182 { 0x0281F400, 0, /* 00-A0-7D */
1184 { 0x12, 0x0010, 0x0000 }, /* 10T */
1186 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1187 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1189 #if defined(TULIP_DEBUG)
1194 { 0x0015F420, 0, /* 00-A0-7D */
1196 { 0x12, 0x0010, 0x0000 }, /* 10T */
1198 { 0x12, 0x0010, 0x0010 }, /* 100T4 */
1199 { 0x12, 0x0008, 0x0008 }, /* FULL_DUPLEX */
1201 #if defined(TULIP_DEBUG)
1206 { 0x0281F400, 0, /* 00-A0-BE */
1208 { 0x11, 0x8000, 0x0000 }, /* 10T */
1209 { 0x11, 0x8000, 0x8000 }, /* 100TX */
1211 { 0x11, 0x4000, 0x4000 }, /* FULL_DUPLEX */
1213 #if defined(TULIP_DEBUG)
1220 static tulip_media_t
1221 tulip_mii_phy_readspecific(
1222 tulip_softc_t * const sc)
1224 const tulip_phy_attr_t *attr;
1228 static const tulip_media_t table[] = {
1229 TULIP_MEDIA_UNKNOWN,
1230 TULIP_MEDIA_10BASET,
1231 TULIP_MEDIA_100BASETX,
1232 TULIP_MEDIA_100BASET4,
1233 TULIP_MEDIA_UNKNOWN,
1234 TULIP_MEDIA_10BASET_FD,
1235 TULIP_MEDIA_100BASETX_FD,
1240 * Don't read phy specific registers if link is not up.
1242 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_STATUS);
1243 if ((data & (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS)) != (PHYSTS_LINK_UP|PHYSTS_EXTENDED_REGS))
1244 return TULIP_MEDIA_UNKNOWN;
1246 id = (tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDLOW) << 16) |
1247 tulip_mii_readreg(sc, sc->tulip_phyaddr, PHYREG_IDHIGH);
1248 for (attr = tulip_mii_phy_attrlist;; attr++) {
1249 if (attr->attr_id == 0)
1250 return TULIP_MEDIA_UNKNOWN;
1251 if ((id & ~0x0F) == attr->attr_id)
1255 if (attr->attr_modes[PHY_MODE_100TX].pm_regno) {
1256 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100TX];
1257 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1258 if ((data & pm->pm_mask) == pm->pm_value)
1261 if (idx == 0 && attr->attr_modes[PHY_MODE_100T4].pm_regno) {
1262 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_100T4];
1263 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1264 if ((data & pm->pm_mask) == pm->pm_value)
1267 if (idx == 0 && attr->attr_modes[PHY_MODE_10T].pm_regno) {
1268 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_10T];
1269 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1270 if ((data & pm->pm_mask) == pm->pm_value)
1273 if (idx != 0 && attr->attr_modes[PHY_MODE_FULLDUPLEX].pm_regno) {
1274 const tulip_phy_modedata_t * const pm = &attr->attr_modes[PHY_MODE_FULLDUPLEX];
1275 data = tulip_mii_readreg(sc, sc->tulip_phyaddr, pm->pm_regno);
1276 idx += ((data & pm->pm_mask) == pm->pm_value ? 4 : 0);
1282 tulip_mii_get_phyaddr(
1283 tulip_softc_t * const sc,
1288 for (phyaddr = 1; phyaddr < 32; phyaddr++) {
1289 unsigned status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1290 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1297 unsigned status = tulip_mii_readreg(sc, 0, PHYREG_STATUS);
1298 if (status == 0 || status == 0xFFFF || status < PHYSTS_10BASET)
1299 return TULIP_MII_NOPHY;
1302 return TULIP_MII_NOPHY;
1306 tulip_mii_map_abilities(
1307 tulip_softc_t * const sc,
1310 sc->tulip_abilities = abilities;
1311 if (abilities & PHYSTS_100BASETX_FD) {
1312 sc->tulip_probe_media = TULIP_MEDIA_100BASETX_FD;
1313 } else if (abilities & PHYSTS_100BASET4) {
1314 sc->tulip_probe_media = TULIP_MEDIA_100BASET4;
1315 } else if (abilities & PHYSTS_100BASETX) {
1316 sc->tulip_probe_media = TULIP_MEDIA_100BASETX;
1317 } else if (abilities & PHYSTS_10BASET_FD) {
1318 sc->tulip_probe_media = TULIP_MEDIA_10BASET_FD;
1319 } else if (abilities & PHYSTS_10BASET) {
1320 sc->tulip_probe_media = TULIP_MEDIA_10BASET;
1322 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1325 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
1330 tulip_mii_autonegotiate(
1331 tulip_softc_t * const sc,
1332 const unsigned phyaddr)
1334 switch (sc->tulip_probe_state) {
1335 case TULIP_PROBE_MEDIATEST:
1336 case TULIP_PROBE_INACTIVE: {
1337 sc->tulip_flags |= TULIP_DIDNWAY;
1338 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, PHYCTL_RESET);
1339 sc->tulip_probe_timeout = 3000;
1340 sc->tulip_intrmask |= TULIP_STS_ABNRMLINTR|TULIP_STS_NORMALINTR;
1341 sc->tulip_probe_state = TULIP_PROBE_PHYRESET;
1344 case TULIP_PROBE_PHYRESET: {
1346 u_int32_t data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1347 if (data & PHYCTL_RESET) {
1348 if (sc->tulip_probe_timeout > 0) {
1352 printf("%s%d(phy%d): error: reset of PHY never completed!\n",
1353 sc->tulip_name, sc->tulip_unit, phyaddr);
1354 sc->tulip_flags &= ~TULIP_TXPROBE_ACTIVE;
1355 sc->tulip_probe_state = TULIP_PROBE_FAILED;
1356 sc->tulip_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
1359 status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1360 if ((status & PHYSTS_CAN_AUTONEG) == 0) {
1361 #if defined(TULIP_DEBUG)
1362 loudprintf("%s%d(phy%d): autonegotiation disabled\n",
1363 sc->tulip_name, sc->tulip_unit, phyaddr);
1365 sc->tulip_flags &= ~TULIP_DIDNWAY;
1366 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1369 if (tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT) != ((status >> 6) | 0x01))
1370 tulip_mii_writereg(sc, phyaddr, PHYREG_AUTONEG_ADVERTISEMENT, (status >> 6) | 0x01);
1371 tulip_mii_writereg(sc, phyaddr, PHYREG_CONTROL, data|PHYCTL_AUTONEG_RESTART|PHYCTL_AUTONEG_ENABLE);
1372 data = tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL);
1373 #if defined(TULIP_DEBUG)
1374 if ((data & PHYCTL_AUTONEG_ENABLE) == 0)
1375 loudprintf("%s%d(phy%d): oops: enable autonegotiation failed: 0x%04x\n",
1376 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1378 loudprintf("%s%d(phy%d): autonegotiation restarted: 0x%04x\n",
1379 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1380 sc->tulip_dbg.dbg_nway_starts++;
1382 sc->tulip_probe_state = TULIP_PROBE_PHYAUTONEG;
1383 sc->tulip_probe_timeout = 3000;
1386 case TULIP_PROBE_PHYAUTONEG: {
1387 u_int32_t status = tulip_mii_readreg(sc, phyaddr, PHYREG_STATUS);
1389 if ((status & PHYSTS_AUTONEG_DONE) == 0) {
1390 if (sc->tulip_probe_timeout > 0) {
1394 #if defined(TULIP_DEBUG)
1395 loudprintf("%s%d(phy%d): autonegotiation timeout: sts=0x%04x, ctl=0x%04x\n",
1396 sc->tulip_name, sc->tulip_unit, phyaddr, status,
1397 tulip_mii_readreg(sc, phyaddr, PHYREG_CONTROL));
1399 sc->tulip_flags &= ~TULIP_DIDNWAY;
1400 sc->tulip_probe_state = TULIP_PROBE_MEDIATEST;
1403 data = tulip_mii_readreg(sc, phyaddr, PHYREG_AUTONEG_ABILITIES);
1404 #if defined(TULIP_DEBUG)
1405 loudprintf("%s%d(phy%d): autonegotiation complete: 0x%04x\n",
1406 sc->tulip_name, sc->tulip_unit, phyaddr, data);
1408 data = (data << 6) & status;
1409 if (!tulip_mii_map_abilities(sc, data))
1410 sc->tulip_flags &= ~TULIP_DIDNWAY;
1414 #if defined(DIAGNOSTIC)
1415 panic("tulip_media_poll: botch at line %d\n", __LINE__);
1420 #if defined(TULIP_DEBUG)
1421 loudprintf("%s%d(phy%d): autonegotiation failure: state = %d\n",
1422 sc->tulip_name, sc->tulip_unit, phyaddr, sc->tulip_probe_state);
1423 sc->tulip_dbg.dbg_nway_failures++;
1428 tulip_2114x_media_preset(
1429 tulip_softc_t * const sc)
1431 const tulip_media_info_t *mi = NULL;
1432 tulip_media_t media = sc->tulip_media;
1434 if (sc->tulip_probe_state == TULIP_PROBE_INACTIVE)
1435 media = sc->tulip_media;
1437 media = sc->tulip_probe_media;
1439 sc->tulip_cmdmode &= ~TULIP_CMD_PORTSELECT;
1440 sc->tulip_flags &= ~TULIP_SQETEST;
1441 if (media != TULIP_MEDIA_UNKNOWN && media != TULIP_MEDIA_MAX) {
1442 #if defined(TULIP_DEBUG)
1443 if (media < TULIP_MEDIA_MAX && sc->tulip_mediums[media] != NULL) {
1445 mi = sc->tulip_mediums[media];
1446 if (mi->mi_type == TULIP_MEDIAINFO_MII) {
1447 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1448 } else if (mi->mi_type == TULIP_MEDIAINFO_GPR
1449 || mi->mi_type == TULIP_MEDIAINFO_SYM) {
1450 sc->tulip_cmdmode &= ~TULIP_GPR_CMDBITS;
1451 sc->tulip_cmdmode |= mi->mi_cmdmode;
1452 } else if (mi->mi_type == TULIP_MEDIAINFO_SIA) {
1453 TULIP_CSR_WRITE(sc, csr_sia_connectivity, TULIP_SIACONN_RESET);
1455 #if defined(TULIP_DEBUG)
1457 printf("%s%d: preset: bad media %d!\n",
1458 sc->tulip_name, sc->tulip_unit, media);
1463 case TULIP_MEDIA_BNC:
1464 case TULIP_MEDIA_AUI:
1465 case TULIP_MEDIA_10BASET: {
1466 sc->tulip_cmdmode &= ~TULIP_CMD_FULLDUPLEX;
1467 sc->tulip_cmdmode |= TULIP_CMD_TXTHRSHLDCTL;
1468 sc->tulip_if.if_baudrate = 10000000;
1469 sc->tulip_flags |= TULIP_SQETEST;
1472 case TULIP_MEDIA_10BASET_FD: {
1473 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL;
1474 sc->tulip_if.if_baudrate = 10000000;
1477 case TULIP_MEDIA_100BASEFX:
1478 case TULIP_MEDIA_100BASET4:
1479 case TULIP_MEDIA_100BASETX: {
1480 sc->tulip_cmdmode &= ~(TULIP_CMD_FULLDUPLEX|TULIP_CMD_TXTHRSHLDCTL);
1481 sc->tulip_cmdmode |= TULIP_CMD_PORTSELECT;
1482 sc->tulip_if.if_baudrate = 100000000;
1485 case TULIP_MEDIA_100BASEFX_FD:
1486 case TULIP_MEDIA_100BASETX_FD: {
1487 sc->tulip_cmdmode |= TULIP_CMD_FULLDUPLEX|TULIP_CMD_PORTSELECT;
1488 sc->tulip_cmdmode &= ~TULIP_CMD_TXTHRSHLDCTL;
1489 sc->tulip_if.if_baudrate = 100000000;
1496 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
1500 ********************************************************************
1501 * Start of 21140/21140A support which does not use the MII interface
1505 tulip_null_media_poll(
1506 tulip_softc_t * const sc,
1507 tulip_mediapoll_event_t event)
1509 #if defined(TULIP_DEBUG)
1510 sc->tulip_dbg.dbg_events[event]++;
1512 #if defined(DIAGNOSTIC)
1513 printf("%s%d: botch(media_poll) at line %d\n",
1514 sc->tulip_name, sc->tulip_unit, __LINE__);
1518 __inline__ static void
1519 tulip_21140_mediainit(
1520 tulip_softc_t * const sc,
1521 tulip_media_info_t * const mip,
1522 tulip_media_t const media,
1526 sc->tulip_mediums[media] = mip;
1527 mip->mi_type = TULIP_MEDIAINFO_GPR;
1528 mip->mi_cmdmode = cmdmode;
1529 mip->mi_gpdata = gpdata;
1533 tulip_21140_evalboard_media_probe(
1534 tulip_softc_t * const sc)
1536 tulip_media_info_t *mip = sc->tulip_mediainfo;
1538 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1539 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1540 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1541 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1542 TULIP_CSR_WRITE(sc, csr_command,
1543 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1544 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1545 TULIP_CSR_WRITE(sc, csr_command,
1546 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1548 if ((TULIP_CSR_READ(sc, csr_gp) & TULIP_GP_EB_OK100) != 0) {
1549 sc->tulip_media = TULIP_MEDIA_10BASET;
1551 sc->tulip_media = TULIP_MEDIA_100BASETX;
1553 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1555 TULIP_CMD_TXTHRSHLDCTL);
1556 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1558 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1559 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1561 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1562 |TULIP_CMD_SCRAMBLER);
1563 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1565 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1566 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1569 static const tulip_boardsw_t tulip_21140_eb_boardsw = {
1571 tulip_21140_evalboard_media_probe,
1573 tulip_null_media_poll,
1574 tulip_2114x_media_preset,
1578 tulip_21140_accton_media_probe(
1579 tulip_softc_t * const sc)
1581 tulip_media_info_t *mip = sc->tulip_mediainfo;
1584 sc->tulip_gpinit = TULIP_GP_EB_PINS;
1585 sc->tulip_gpdata = TULIP_GP_EB_INIT;
1586 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_PINS);
1587 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EB_INIT);
1588 TULIP_CSR_WRITE(sc, csr_command,
1589 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1590 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1591 TULIP_CSR_WRITE(sc, csr_command,
1592 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1594 gpdata = TULIP_CSR_READ(sc, csr_gp);
1595 if ((gpdata & TULIP_GP_EN1207_UTP_INIT) == 0) {
1596 sc->tulip_media = TULIP_MEDIA_10BASET;
1598 if ((gpdata & TULIP_GP_EN1207_BNC_INIT) == 0) {
1599 sc->tulip_media = TULIP_MEDIA_BNC;
1601 sc->tulip_media = TULIP_MEDIA_100BASETX;
1604 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_BNC,
1605 TULIP_GP_EN1207_BNC_INIT,
1606 TULIP_CMD_TXTHRSHLDCTL);
1607 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1608 TULIP_GP_EN1207_UTP_INIT,
1609 TULIP_CMD_TXTHRSHLDCTL);
1610 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1611 TULIP_GP_EN1207_UTP_INIT,
1612 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1613 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1614 TULIP_GP_EN1207_100_INIT,
1615 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1616 |TULIP_CMD_SCRAMBLER);
1617 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1618 TULIP_GP_EN1207_100_INIT,
1619 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1620 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1623 static const tulip_boardsw_t tulip_21140_accton_boardsw = {
1625 tulip_21140_accton_media_probe,
1627 tulip_null_media_poll,
1628 tulip_2114x_media_preset,
1632 tulip_21140_smc9332_media_probe(
1633 tulip_softc_t * const sc)
1635 tulip_media_info_t *mip = sc->tulip_mediainfo;
1638 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT|TULIP_CMD_MUSTBEONE);
1639 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
1640 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
1641 33MHz that comes to two microseconds but wait a
1642 bit longer anyways) */
1643 TULIP_CSR_WRITE(sc, csr_command, TULIP_CMD_PORTSELECT |
1644 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1645 sc->tulip_gpinit = TULIP_GP_SMC_9332_PINS;
1646 sc->tulip_gpdata = TULIP_GP_SMC_9332_INIT;
1647 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_PINS|TULIP_GP_PINSET);
1648 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_SMC_9332_INIT);
1650 for (idx = 1000; idx > 0; idx--) {
1651 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1652 if ((csr & (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) == (TULIP_GP_SMC_9332_OK10|TULIP_GP_SMC_9332_OK100)) {
1655 } else if ((csr & TULIP_GP_SMC_9332_OK10) == 0) {
1662 sc->tulip_media = cnt > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1663 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1664 TULIP_GP_SMC_9332_INIT,
1665 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1666 |TULIP_CMD_SCRAMBLER);
1667 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1668 TULIP_GP_SMC_9332_INIT,
1669 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1670 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1671 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1672 TULIP_GP_SMC_9332_INIT,
1673 TULIP_CMD_TXTHRSHLDCTL);
1674 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1675 TULIP_GP_SMC_9332_INIT,
1676 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1679 static const tulip_boardsw_t tulip_21140_smc9332_boardsw = {
1680 TULIP_21140_SMC_9332,
1681 tulip_21140_smc9332_media_probe,
1683 tulip_null_media_poll,
1684 tulip_2114x_media_preset,
1688 tulip_21140_cogent_em100_media_probe(
1689 tulip_softc_t * const sc)
1691 tulip_media_info_t *mip = sc->tulip_mediainfo;
1692 u_int32_t cmdmode = TULIP_CSR_READ(sc, csr_command);
1694 sc->tulip_gpinit = TULIP_GP_EM100_PINS;
1695 sc->tulip_gpdata = TULIP_GP_EM100_INIT;
1696 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_PINS);
1697 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_EM100_INIT);
1699 cmdmode = TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION|TULIP_CMD_MUSTBEONE;
1700 cmdmode &= ~(TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_SCRAMBLER);
1701 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
1702 TULIP_CSR_WRITE(sc, csr_command, cmdmode);
1703 sc->tulip_media = TULIP_MEDIA_100BASEFX;
1705 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX,
1706 TULIP_GP_EM100_INIT,
1707 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION);
1708 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASEFX_FD,
1709 TULIP_GP_EM100_INIT,
1710 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1711 |TULIP_CMD_FULLDUPLEX);
1713 TULIP_CSR_WRITE(sc, csr_command, cmdmode|TULIP_CMD_SCRAMBLER);
1714 sc->tulip_media = TULIP_MEDIA_100BASETX;
1715 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1716 TULIP_GP_EM100_INIT,
1717 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1718 |TULIP_CMD_SCRAMBLER);
1719 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1720 TULIP_GP_EM100_INIT,
1721 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1722 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1726 static const tulip_boardsw_t tulip_21140_cogent_em100_boardsw = {
1727 TULIP_21140_COGENT_EM100,
1728 tulip_21140_cogent_em100_media_probe,
1730 tulip_null_media_poll,
1731 tulip_2114x_media_preset
1735 tulip_21140_znyx_zx34x_media_probe(
1736 tulip_softc_t * const sc)
1738 tulip_media_info_t *mip = sc->tulip_mediainfo;
1739 int cnt10 = 0, cnt100 = 0, idx;
1741 sc->tulip_gpinit = TULIP_GP_ZX34X_PINS;
1742 sc->tulip_gpdata = TULIP_GP_ZX34X_INIT;
1743 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_PINS);
1744 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ZX34X_INIT);
1745 TULIP_CSR_WRITE(sc, csr_command,
1746 TULIP_CSR_READ(sc, csr_command) | TULIP_CMD_PORTSELECT |
1747 TULIP_CMD_PCSFUNCTION | TULIP_CMD_SCRAMBLER | TULIP_CMD_MUSTBEONE);
1748 TULIP_CSR_WRITE(sc, csr_command,
1749 TULIP_CSR_READ(sc, csr_command) & ~TULIP_CMD_TXTHRSHLDCTL);
1752 for (idx = 1000; idx > 0; idx--) {
1753 u_int32_t csr = TULIP_CSR_READ(sc, csr_gp);
1754 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)) {
1757 } else if ((csr & TULIP_GP_ZX34X_LNKFAIL) == 0) {
1766 sc->tulip_media = cnt100 > 100 ? TULIP_MEDIA_100BASETX : TULIP_MEDIA_10BASET;
1767 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET,
1768 TULIP_GP_ZX34X_INIT,
1769 TULIP_CMD_TXTHRSHLDCTL);
1770 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_10BASET_FD,
1771 TULIP_GP_ZX34X_INIT,
1772 TULIP_CMD_TXTHRSHLDCTL|TULIP_CMD_FULLDUPLEX);
1773 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX,
1774 TULIP_GP_ZX34X_INIT,
1775 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1776 |TULIP_CMD_SCRAMBLER);
1777 tulip_21140_mediainit(sc, mip++, TULIP_MEDIA_100BASETX_FD,
1778 TULIP_GP_ZX34X_INIT,
1779 TULIP_CMD_PORTSELECT|TULIP_CMD_PCSFUNCTION
1780 |TULIP_CMD_SCRAMBLER|TULIP_CMD_FULLDUPLEX);
1783 static const tulip_boardsw_t tulip_21140_znyx_zx34x_boardsw = {
1784 TULIP_21140_ZNYX_ZX34X,
1785 tulip_21140_znyx_zx34x_media_probe,
1787 tulip_null_media_poll,
1788 tulip_2114x_media_preset,
1792 tulip_2114x_media_probe(
1793 tulip_softc_t * const sc)
1795 sc->tulip_cmdmode |= TULIP_CMD_MUSTBEONE
1796 |TULIP_CMD_BACKOFFCTR|TULIP_CMD_THRSHLD72;
1799 static const tulip_boardsw_t tulip_2114x_isv_boardsw = {
1801 tulip_2114x_media_probe,
1804 tulip_2114x_media_preset,
1808 * ******** END of chip-specific handlers. ***********
1812 * Code the read the SROM and MII bit streams (I2C)
1814 #define EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1818 tulip_softc_t * const sc)
1822 csr = SROMSEL ; EMIT;
1823 csr = SROMSEL | SROMRD; EMIT;
1824 csr ^= SROMCS; EMIT;
1825 csr ^= SROMCLKON; EMIT;
1828 * Write 25 cycles of 0 which will force the SROM to be idle.
1830 for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
1831 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1832 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1834 csr ^= SROMCLKOFF; EMIT;
1835 csr ^= SROMCS; EMIT;
1842 tulip_softc_t * const sc)
1845 const unsigned bitwidth = SROM_BITWIDTH;
1846 const unsigned cmdmask = (SROMCMD_RD << bitwidth);
1847 const unsigned msb = 1 << (bitwidth + 3 - 1);
1848 unsigned lastidx = (1 << bitwidth) - 1;
1850 tulip_srom_idle(sc);
1852 for (idx = 0; idx <= lastidx; idx++) {
1853 unsigned lastbit, data, bits, bit, csr;
1854 csr = SROMSEL ; EMIT;
1855 csr = SROMSEL | SROMRD; EMIT;
1856 csr ^= SROMCSON; EMIT;
1857 csr ^= SROMCLKON; EMIT;
1860 for (bits = idx|cmdmask, bit = bitwidth + 3; bit > 0; bit--, bits <<= 1) {
1861 const unsigned thisbit = bits & msb;
1862 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1863 if (thisbit != lastbit) {
1864 csr ^= SROMDOUT; EMIT; /* clock low; invert data */
1868 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1871 csr ^= SROMCLKOFF; EMIT;
1873 for (data = 0, bits = 0; bits < 16; bits++) {
1875 csr ^= SROMCLKON; EMIT; /* clock high; data valid */
1876 data |= TULIP_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
1877 csr ^= SROMCLKOFF; EMIT; /* clock low; data not valid */
1879 sc->tulip_rombuf[idx*2] = data & 0xFF;
1880 sc->tulip_rombuf[idx*2+1] = data >> 8;
1881 csr = SROMSEL | SROMRD; EMIT;
1884 tulip_srom_idle(sc);
1887 #define MII_EMIT do { TULIP_CSR_WRITE(sc, csr_srom_mii, csr); DELAY(1); } while (0)
1890 tulip_mii_writebits(
1891 tulip_softc_t * const sc,
1895 unsigned msb = 1 << (bits - 1);
1896 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1897 unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
1899 csr |= MII_WR; MII_EMIT; /* clock low; assert write */
1901 for (; bits > 0; bits--, data <<= 1) {
1902 const unsigned thisbit = data & msb;
1903 if (thisbit != lastbit) {
1904 csr ^= MII_DOUT; MII_EMIT; /* clock low; invert data */
1906 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1908 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1913 tulip_mii_turnaround(
1914 tulip_softc_t * const sc,
1917 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1919 if (cmd == MII_WRCMD) {
1920 csr |= MII_DOUT; MII_EMIT; /* clock low; change data */
1921 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1922 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1923 csr ^= MII_DOUT; MII_EMIT; /* clock low; change data */
1925 csr |= MII_RD; MII_EMIT; /* clock low; switch to read */
1927 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1928 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1933 tulip_softc_t * const sc)
1936 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1939 for (idx = 0, data = 0; idx < 16; idx++) {
1940 data <<= 1; /* this is NOOP on the first pass through */
1941 csr ^= MII_CLKON; MII_EMIT; /* clock high; data valid */
1942 if (TULIP_CSR_READ(sc, csr_srom_mii) & MII_DIN)
1944 csr ^= MII_CLKOFF; MII_EMIT; /* clock low; data not valid */
1946 csr ^= MII_RD; MII_EMIT; /* clock low; turn off read */
1953 tulip_softc_t * const sc,
1957 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1960 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1961 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1962 tulip_mii_writebits(sc, MII_RDCMD, 8);
1963 tulip_mii_writebits(sc, devaddr, 5);
1964 tulip_mii_writebits(sc, regno, 5);
1965 tulip_mii_turnaround(sc, MII_RDCMD);
1967 data = tulip_mii_readbits(sc);
1968 #if defined(TULIP_DEBUG)
1969 sc->tulip_dbg.dbg_phyregs[regno][0] = data;
1970 sc->tulip_dbg.dbg_phyregs[regno][1]++;
1977 tulip_softc_t * const sc,
1982 unsigned csr = TULIP_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
1983 csr &= ~(MII_RD|MII_CLK); MII_EMIT;
1984 tulip_mii_writebits(sc, MII_PREAMBLE, 32);
1985 tulip_mii_writebits(sc, MII_WRCMD, 8);
1986 tulip_mii_writebits(sc, devaddr, 5);
1987 tulip_mii_writebits(sc, regno, 5);
1988 tulip_mii_turnaround(sc, MII_WRCMD);
1989 tulip_mii_writebits(sc, data, 16);
1990 #if defined(TULIP_DEBUG)
1991 sc->tulip_dbg.dbg_phyregs[regno][2] = data;
1992 sc->tulip_dbg.dbg_phyregs[regno][3]++;
1996 #define tulip_mchash(mca) (ether_crc32_le(mca, 6) & 0x1FF)
1997 #define tulip_srom_crcok(databuf) ( \
1998 ((ether_crc32_le(databuf, 126) & 0xFFFFU) ^ 0xFFFFU) == \
1999 ((databuf)[126] | ((databuf)[127] << 8)))
2002 tulip_identify_dec_nic(
2003 tulip_softc_t * const sc)
2005 strcpy(sc->tulip_boardid, "DEC ");
2007 if (sc->tulip_chipid <= TULIP_21040)
2009 if (bcmp(sc->tulip_rombuf + 29, "DE500", 5) == 0
2010 || bcmp(sc->tulip_rombuf + 29, "DE450", 5) == 0) {
2011 bcopy(sc->tulip_rombuf + 29, &sc->tulip_boardid[D0], 8);
2012 sc->tulip_boardid[D0+8] = ' ';
2018 tulip_identify_znyx_nic(
2019 tulip_softc_t * const sc)
2022 strcpy(sc->tulip_boardid, "ZNYX ZX3XX ");
2023 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2025 sc->tulip_boardid[8] = '4';
2026 znyx_ptr = sc->tulip_rombuf[124] + 256 * sc->tulip_rombuf[125];
2027 if (znyx_ptr < 26 || znyx_ptr > 116) {
2028 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2031 /* ZX344 = 0010 .. 0013FF
2033 if (sc->tulip_rombuf[znyx_ptr] == 0x4A
2034 && sc->tulip_rombuf[znyx_ptr + 1] == 0x52
2035 && sc->tulip_rombuf[znyx_ptr + 2] == 0x01) {
2036 id = sc->tulip_rombuf[znyx_ptr + 5] + 256 * sc->tulip_rombuf[znyx_ptr + 4];
2037 if ((id >> 8) == (TULIP_ZNYX_ID_ZX342 >> 8)) {
2038 sc->tulip_boardid[9] = '2';
2039 if (id == TULIP_ZNYX_ID_ZX342B) {
2040 sc->tulip_boardid[10] = 'B';
2041 sc->tulip_boardid[11] = ' ';
2043 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2044 } else if (id == TULIP_ZNYX_ID_ZX344) {
2045 sc->tulip_boardid[10] = '4';
2046 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2047 } else if (id == TULIP_ZNYX_ID_ZX345) {
2048 sc->tulip_boardid[9] = (sc->tulip_rombuf[19] > 1) ? '8' : '5';
2049 } else if (id == TULIP_ZNYX_ID_ZX346) {
2050 sc->tulip_boardid[9] = '6';
2051 } else if (id == TULIP_ZNYX_ID_ZX351) {
2052 sc->tulip_boardid[8] = '5';
2053 sc->tulip_boardid[9] = '1';
2058 * Assume it's a ZX342...
2060 sc->tulip_boardsw = &tulip_21140_znyx_zx34x_boardsw;
2064 sc->tulip_boardid[8] = '1';
2065 if (sc->tulip_chipid == TULIP_21041) {
2066 sc->tulip_boardid[10] = '1';
2069 if (sc->tulip_rombuf[32] == 0x4A && sc->tulip_rombuf[33] == 0x52) {
2070 id = sc->tulip_rombuf[37] + 256 * sc->tulip_rombuf[36];
2071 if (id == TULIP_ZNYX_ID_ZX312T) {
2072 sc->tulip_boardid[9] = '2';
2073 sc->tulip_boardid[10] = 'T';
2074 sc->tulip_boardid[11] = ' ';
2075 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2076 } else if (id == TULIP_ZNYX_ID_ZX314_INTA) {
2077 sc->tulip_boardid[9] = '4';
2078 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2079 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2080 } else if (id == TULIP_ZNYX_ID_ZX314) {
2081 sc->tulip_boardid[9] = '4';
2082 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2083 sc->tulip_features |= TULIP_HAVE_BASEROM;
2084 } else if (id == TULIP_ZNYX_ID_ZX315_INTA) {
2085 sc->tulip_boardid[9] = '5';
2086 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2087 } else if (id == TULIP_ZNYX_ID_ZX315) {
2088 sc->tulip_boardid[9] = '5';
2089 sc->tulip_features |= TULIP_HAVE_BASEROM;
2095 if ((sc->tulip_enaddr[3] & ~3) == 0xF0 && (sc->tulip_enaddr[5] & 2) == 0) {
2096 sc->tulip_boardid[9] = '4';
2097 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2098 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2099 } else if ((sc->tulip_enaddr[3] & ~3) == 0xF4 && (sc->tulip_enaddr[5] & 1) == 0) {
2100 sc->tulip_boardid[9] = '5';
2101 sc->tulip_boardsw = &tulip_21040_boardsw;
2102 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2103 } else if ((sc->tulip_enaddr[3] & ~3) == 0xEC) {
2104 sc->tulip_boardid[9] = '2';
2105 sc->tulip_boardsw = &tulip_21040_boardsw;
2111 tulip_identify_smc_nic(
2112 tulip_softc_t * const sc)
2114 u_int32_t id1, id2, ei;
2115 int auibnc = 0, utp = 0;
2118 strcpy(sc->tulip_boardid, "SMC ");
2119 if (sc->tulip_chipid == TULIP_21041)
2121 if (sc->tulip_chipid != TULIP_21040) {
2122 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2123 strcpy(&sc->tulip_boardid[4], "9332DST ");
2124 sc->tulip_boardsw = &tulip_21140_smc9332_boardsw;
2125 } else if (sc->tulip_features & (TULIP_HAVE_BASEROM|TULIP_HAVE_SLAVEDROM)) {
2126 strcpy(&sc->tulip_boardid[4], "9334BDT ");
2128 strcpy(&sc->tulip_boardid[4], "9332BDT ");
2132 id1 = sc->tulip_rombuf[0x60] | (sc->tulip_rombuf[0x61] << 8);
2133 id2 = sc->tulip_rombuf[0x62] | (sc->tulip_rombuf[0x63] << 8);
2134 ei = sc->tulip_rombuf[0x66] | (sc->tulip_rombuf[0x67] << 8);
2136 strcpy(&sc->tulip_boardid[4], "8432");
2137 cp = &sc->tulip_boardid[8];
2139 *cp++ = 'B', auibnc = 1;
2140 if ((id1 & 0xFF) > 0x32)
2141 *cp++ = 'T', utp = 1;
2142 if ((id1 & 0x4000) == 0)
2143 *cp++ = 'A', auibnc = 1;
2145 sc->tulip_boardid[7] = '4';
2149 *cp++ = (ei ? '2' : '1');
2154 sc->tulip_boardsw = &tulip_21040_10baset_only_boardsw;
2155 else if (!utp && auibnc)
2156 sc->tulip_boardsw = &tulip_21040_auibnc_only_boardsw;
2160 tulip_identify_cogent_nic(
2161 tulip_softc_t * const sc)
2163 strcpy(sc->tulip_boardid, "Cogent ");
2164 if (sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A) {
2165 if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100TX_ID) {
2166 strcat(sc->tulip_boardid, "EM100TX ");
2167 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2168 #if defined(TULIP_COGENT_EM110TX_ID)
2169 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM110TX_ID) {
2170 strcat(sc->tulip_boardid, "EM110TX ");
2171 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2173 } else if (sc->tulip_rombuf[32] == TULIP_COGENT_EM100FX_ID) {
2174 strcat(sc->tulip_boardid, "EM100FX ");
2175 sc->tulip_boardsw = &tulip_21140_cogent_em100_boardsw;
2178 * Magic number (0x24001109U) is the SubVendor (0x2400) and
2179 * SubDevId (0x1109) for the ANA6944TX (EM440TX).
2181 if (*(u_int32_t *) sc->tulip_rombuf == 0x24001109U
2182 && (sc->tulip_features & TULIP_HAVE_BASEROM)) {
2184 * Cogent (Adaptec) is still mapping all INTs to INTA of
2185 * first 21140. Dumb! Dumb!
2187 strcat(sc->tulip_boardid, "EM440TX ");
2188 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2190 } else if (sc->tulip_chipid == TULIP_21040) {
2191 sc->tulip_features |= TULIP_HAVE_SHAREDINTR|TULIP_HAVE_BASEROM;
2196 tulip_identify_accton_nic(
2197 tulip_softc_t * const sc)
2199 strcpy(sc->tulip_boardid, "ACCTON ");
2200 switch (sc->tulip_chipid) {
2202 strcat(sc->tulip_boardid, "EN1207 ");
2203 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2204 sc->tulip_boardsw = &tulip_21140_accton_boardsw;
2207 strcat(sc->tulip_boardid, "EN1207TX ");
2208 if (sc->tulip_boardsw != &tulip_2114x_isv_boardsw)
2209 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2212 strcat(sc->tulip_boardid, "EN1203 ");
2213 sc->tulip_boardsw = &tulip_21040_boardsw;
2216 strcat(sc->tulip_boardid, "EN1203 ");
2217 sc->tulip_boardsw = &tulip_21041_boardsw;
2220 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2226 tulip_identify_asante_nic(
2227 tulip_softc_t * const sc)
2229 strcpy(sc->tulip_boardid, "Asante ");
2230 if ((sc->tulip_chipid == TULIP_21140 || sc->tulip_chipid == TULIP_21140A)
2231 && sc->tulip_boardsw != &tulip_2114x_isv_boardsw) {
2232 tulip_media_info_t *mi = sc->tulip_mediainfo;
2235 * The Asante Fast Ethernet doesn't always ship with a valid
2236 * new format SROM. So if isn't in the new format, we cheat
2237 * set it up as if we had.
2240 sc->tulip_gpinit = TULIP_GP_ASANTE_PINS;
2241 sc->tulip_gpdata = 0;
2243 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PINS|TULIP_GP_PINSET);
2244 TULIP_CSR_WRITE(sc, csr_gp, TULIP_GP_ASANTE_PHYRESET);
2246 TULIP_CSR_WRITE(sc, csr_gp, 0);
2248 mi->mi_type = TULIP_MEDIAINFO_MII;
2249 mi->mi_gpr_length = 0;
2250 mi->mi_gpr_offset = 0;
2251 mi->mi_reset_length = 0;
2252 mi->mi_reset_offset = 0;;
2254 mi->mi_phyaddr = TULIP_MII_NOPHY;
2255 for (idx = 20; idx > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx--) {
2257 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, 0);
2259 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2260 printf("%s%d: can't find phy 0\n", sc->tulip_name, sc->tulip_unit);
2264 sc->tulip_features |= TULIP_HAVE_MII;
2265 mi->mi_capabilities = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2266 mi->mi_advertisement = PHYSTS_10BASET|PHYSTS_10BASET_FD|PHYSTS_100BASETX|PHYSTS_100BASETX_FD;
2267 mi->mi_full_duplex = PHYSTS_10BASET_FD|PHYSTS_100BASETX_FD;
2268 mi->mi_tx_threshold = PHYSTS_10BASET|PHYSTS_10BASET_FD;
2269 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2270 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2271 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2272 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2273 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2274 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2275 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2277 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2282 tulip_identify_compex_nic(
2283 tulip_softc_t * const sc)
2285 strcpy(sc->tulip_boardid, "COMPEX ");
2286 if (sc->tulip_chipid == TULIP_21140A) {
2288 tulip_softc_t *root_sc = NULL;
2290 strcat(sc->tulip_boardid, "400TX/PCI ");
2292 * All 4 chips on these boards share an interrupt. This code
2293 * copied from tulip_read_macaddr.
2295 sc->tulip_features |= TULIP_HAVE_SHAREDINTR;
2296 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2297 root_sc = tulips[root_unit];
2299 || !(root_sc->tulip_features & TULIP_HAVE_SLAVEDINTR))
2304 && root_sc->tulip_chipid == sc->tulip_chipid
2305 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2306 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2307 sc->tulip_slaves = root_sc->tulip_slaves;
2308 root_sc->tulip_slaves = sc;
2309 } else if(sc->tulip_features & TULIP_HAVE_SLAVEDINTR) {
2310 printf("\nCannot find master device for de%d interrupts",
2314 strcat(sc->tulip_boardid, "unknown ");
2316 /* sc->tulip_boardsw = &tulip_21140_eb_boardsw; */
2322 tulip_softc_t * const sc)
2324 unsigned idx1, idx2, idx3;
2326 const tulip_srom_header_t *shp = (const tulip_srom_header_t *) &sc->tulip_rombuf[0];
2327 const tulip_srom_adapter_info_t *saip = (const tulip_srom_adapter_info_t *) (shp + 1);
2328 tulip_srom_media_t srom_media;
2329 tulip_media_info_t *mi = sc->tulip_mediainfo;
2331 u_int32_t leaf_offset, blocks, data;
2333 for (idx1 = 0; idx1 < shp->sh_adapter_count; idx1++, saip++) {
2334 if (shp->sh_adapter_count == 1)
2336 if (saip->sai_device == sc->tulip_pci_devno)
2340 * Didn't find the right media block for this card.
2342 if (idx1 == shp->sh_adapter_count)
2346 * Save the hardware address.
2348 bcopy(shp->sh_ieee802_address, sc->tulip_enaddr, 6);
2350 * If this is a multiple port card, add the adapter index to the last
2351 * byte of the hardware address. (if it isn't multiport, adding 0
2354 sc->tulip_enaddr[5] += idx1;
2356 leaf_offset = saip->sai_leaf_offset_lowbyte
2357 + saip->sai_leaf_offset_highbyte * 256;
2358 dp = sc->tulip_rombuf + leaf_offset;
2360 sc->tulip_conntype = (tulip_srom_connection_t) (dp[0] + dp[1] * 256); dp += 2;
2362 for (idx2 = 0;; idx2++) {
2363 if (tulip_srom_conninfo[idx2].sc_type == sc->tulip_conntype
2364 || tulip_srom_conninfo[idx2].sc_type == TULIP_SROM_CONNTYPE_NOT_USED)
2367 sc->tulip_connidx = idx2;
2369 if (sc->tulip_chipid == TULIP_21041) {
2371 for (idx2 = 0; idx2 < blocks; idx2++) {
2372 tulip_media_t media;
2374 srom_media = (tulip_srom_media_t) (data & 0x3F);
2375 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2376 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2379 media = tulip_srom_mediums[idx3].sm_type;
2380 if (media != TULIP_MEDIA_UNKNOWN) {
2381 if (data & TULIP_SROM_21041_EXTENDED) {
2382 mi->mi_type = TULIP_MEDIAINFO_SIA;
2383 sc->tulip_mediums[media] = mi;
2384 mi->mi_sia_connectivity = dp[0] + dp[1] * 256;
2385 mi->mi_sia_tx_rx = dp[2] + dp[3] * 256;
2386 mi->mi_sia_general = dp[4] + dp[5] * 256;
2390 case TULIP_MEDIA_BNC: {
2391 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC);
2395 case TULIP_MEDIA_AUI: {
2396 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI);
2400 case TULIP_MEDIA_10BASET: {
2401 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET);
2405 case TULIP_MEDIA_10BASET_FD: {
2406 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD);
2416 if (data & TULIP_SROM_21041_EXTENDED)
2421 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, BNC); mi++;
2422 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, AUI); mi++;
2423 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET); mi++;
2424 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21041, 10BASET_FD); mi++;
2428 unsigned length, type;
2429 tulip_media_t gp_media = TULIP_MEDIA_UNKNOWN;
2430 if (sc->tulip_features & TULIP_HAVE_GPR)
2431 sc->tulip_gpinit = *dp++;
2433 for (idx2 = 0; idx2 < blocks; idx2++) {
2435 if ((*dp & 0x80) == 0) {
2439 length = (*dp++ & 0x7f) - 1;
2440 type = *dp++ & 0x3f;
2443 switch (type & 0x3f) {
2444 case 0: { /* 21140[A] GPR block */
2445 tulip_media_t media;
2446 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2447 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2448 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2451 media = tulip_srom_mediums[idx3].sm_type;
2452 if (media == TULIP_MEDIA_UNKNOWN)
2454 mi->mi_type = TULIP_MEDIAINFO_GPR;
2455 sc->tulip_mediums[media] = mi;
2456 mi->mi_gpdata = dp[1];
2457 if (media > gp_media && !TULIP_IS_MEDIA_FD(media)) {
2458 sc->tulip_gpdata = mi->mi_gpdata;
2461 data = dp[2] + dp[3] * 256;
2462 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2463 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2467 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2469 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2470 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2475 case 1: { /* 21140[A] MII block */
2476 const unsigned phyno = *dp++;
2477 mi->mi_type = TULIP_MEDIAINFO_MII;
2478 mi->mi_gpr_length = *dp++;
2479 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2480 dp += mi->mi_gpr_length;
2481 mi->mi_reset_length = *dp++;
2482 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2483 dp += mi->mi_reset_length;
2486 * Before we probe for a PHY, use the GPR information
2487 * to select it. If we don't, it may be inaccessible.
2489 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_gpinit|TULIP_GP_PINSET);
2490 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++) {
2492 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_reset_offset + idx3]);
2494 sc->tulip_phyaddr = mi->mi_phyaddr;
2495 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++) {
2497 TULIP_CSR_WRITE(sc, csr_gp, sc->tulip_rombuf[mi->mi_gpr_offset + idx3]);
2501 * At least write something!
2503 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2504 TULIP_CSR_WRITE(sc, csr_gp, 0);
2506 mi->mi_phyaddr = TULIP_MII_NOPHY;
2507 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2509 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2511 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2512 #if defined(TULIP_DEBUG)
2513 printf("%s%d: can't find phy %d\n",
2514 sc->tulip_name, sc->tulip_unit, phyno);
2518 sc->tulip_features |= TULIP_HAVE_MII;
2519 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2520 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2521 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2522 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2523 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2524 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2525 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2526 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2527 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2528 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2529 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2533 case 2: { /* 2114[23] SIA block */
2534 tulip_media_t media;
2535 srom_media = (tulip_srom_media_t)(dp[0] & 0x3f);
2536 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2537 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2540 media = tulip_srom_mediums[idx3].sm_type;
2541 if (media == TULIP_MEDIA_UNKNOWN)
2543 mi->mi_type = TULIP_MEDIAINFO_SIA;
2544 sc->tulip_mediums[media] = mi;
2546 mi->mi_sia_connectivity = dp[1] + dp[2] * 256;
2547 mi->mi_sia_tx_rx = dp[3] + dp[4] * 256;
2548 mi->mi_sia_general = dp[5] + dp[6] * 256;
2552 case TULIP_MEDIA_BNC: {
2553 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, BNC);
2556 case TULIP_MEDIA_AUI: {
2557 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, AUI);
2560 case TULIP_MEDIA_10BASET: {
2561 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET);
2562 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2565 case TULIP_MEDIA_10BASET_FD: {
2566 TULIP_MEDIAINFO_SIA_INIT(sc, mi, 21142, 10BASET_FD);
2567 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2575 mi->mi_sia_gp_control = (dp[1] + dp[2] * 256) << 16;
2576 mi->mi_sia_gp_data = (dp[3] + dp[4] * 256) << 16;
2581 case 3: { /* 2114[23] MII PHY block */
2582 const unsigned phyno = *dp++;
2583 const u_int8_t *dp0;
2584 mi->mi_type = TULIP_MEDIAINFO_MII;
2585 mi->mi_gpr_length = *dp++;
2586 mi->mi_gpr_offset = dp - sc->tulip_rombuf;
2587 dp += 2 * mi->mi_gpr_length;
2588 mi->mi_reset_length = *dp++;
2589 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2590 dp += 2 * mi->mi_reset_length;
2592 dp0 = &sc->tulip_rombuf[mi->mi_reset_offset];
2593 for (idx3 = 0; idx3 < mi->mi_reset_length; idx3++, dp0 += 2) {
2595 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2597 sc->tulip_phyaddr = mi->mi_phyaddr;
2598 dp0 = &sc->tulip_rombuf[mi->mi_gpr_offset];
2599 for (idx3 = 0; idx3 < mi->mi_gpr_length; idx3++, dp0 += 2) {
2601 TULIP_CSR_WRITE(sc, csr_sia_general, (dp0[0] + 256 * dp0[1]) << 16);
2604 if (mi->mi_reset_length == 0 && mi->mi_gpr_length == 0)
2605 TULIP_CSR_WRITE(sc, csr_sia_general, 0);
2607 mi->mi_phyaddr = TULIP_MII_NOPHY;
2608 for (idx3 = 20; idx3 > 0 && mi->mi_phyaddr == TULIP_MII_NOPHY; idx3--) {
2610 mi->mi_phyaddr = tulip_mii_get_phyaddr(sc, phyno);
2612 if (mi->mi_phyaddr == TULIP_MII_NOPHY) {
2613 #if defined(TULIP_DEBUG)
2614 printf("%s%d: can't find phy %d\n",
2615 sc->tulip_name, sc->tulip_unit, phyno);
2619 sc->tulip_features |= TULIP_HAVE_MII;
2620 mi->mi_capabilities = dp[0] + dp[1] * 256; dp += 2;
2621 mi->mi_advertisement = dp[0] + dp[1] * 256; dp += 2;
2622 mi->mi_full_duplex = dp[0] + dp[1] * 256; dp += 2;
2623 mi->mi_tx_threshold = dp[0] + dp[1] * 256; dp += 2;
2624 mi->mi_mii_interrupt = dp[0] + dp[1] * 256; dp += 2;
2625 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX_FD);
2626 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASETX);
2627 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 100BASET4);
2628 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET_FD);
2629 TULIP_MEDIAINFO_ADD_CAPABILITY(sc, mi, 10BASET);
2630 mi->mi_phyid = (tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDLOW) << 16) |
2631 tulip_mii_readreg(sc, mi->mi_phyaddr, PHYREG_IDHIGH);
2635 case 4: { /* 21143 SYM block */
2636 tulip_media_t media;
2637 srom_media = (tulip_srom_media_t) dp[0];
2638 for (idx3 = 0; tulip_srom_mediums[idx3].sm_type != TULIP_MEDIA_UNKNOWN; idx3++) {
2639 if (tulip_srom_mediums[idx3].sm_srom_type == srom_media)
2642 media = tulip_srom_mediums[idx3].sm_type;
2643 if (media == TULIP_MEDIA_UNKNOWN)
2645 mi->mi_type = TULIP_MEDIAINFO_SYM;
2646 sc->tulip_mediums[media] = mi;
2647 mi->mi_gpcontrol = (dp[1] + dp[2] * 256) << 16;
2648 mi->mi_gpdata = (dp[3] + dp[4] * 256) << 16;
2649 data = dp[5] + dp[6] * 256;
2650 mi->mi_cmdmode = TULIP_SROM_2114X_CMDBITS(data);
2651 if (data & TULIP_SROM_2114X_NOINDICATOR) {
2654 mi->mi_default = (data & TULIP_SROM_2114X_DEFAULT) != 0;
2655 mi->mi_actmask = TULIP_SROM_2114X_BITPOS(data);
2656 mi->mi_actdata = (data & TULIP_SROM_2114X_POLARITY) ? 0 : mi->mi_actmask;
2658 if (TULIP_IS_MEDIA_TP(media))
2659 sc->tulip_intrmask |= TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL;
2664 case 5: { /* 21143 Reset block */
2665 mi->mi_type = TULIP_MEDIAINFO_RESET;
2666 mi->mi_reset_length = *dp++;
2667 mi->mi_reset_offset = dp - sc->tulip_rombuf;
2668 dp += 2 * mi->mi_reset_length;
2679 return mi - sc->tulip_mediainfo;
2682 static const struct {
2683 void (*vendor_identify_nic)(tulip_softc_t * const sc);
2684 unsigned char vendor_oui[3];
2685 } tulip_vendors[] = {
2686 { tulip_identify_dec_nic, { 0x08, 0x00, 0x2B } },
2687 { tulip_identify_dec_nic, { 0x00, 0x00, 0xF8 } },
2688 { tulip_identify_smc_nic, { 0x00, 0x00, 0xC0 } },
2689 { tulip_identify_smc_nic, { 0x00, 0xE0, 0x29 } },
2690 { tulip_identify_znyx_nic, { 0x00, 0xC0, 0x95 } },
2691 { tulip_identify_cogent_nic, { 0x00, 0x00, 0x92 } },
2692 { tulip_identify_asante_nic, { 0x00, 0x00, 0x94 } },
2693 { tulip_identify_cogent_nic, { 0x00, 0x00, 0xD1 } },
2694 { tulip_identify_accton_nic, { 0x00, 0x00, 0xE8 } },
2695 { tulip_identify_compex_nic, { 0x00, 0x80, 0x48 } },
2700 * This deals with the vagaries of the address roms and the
2701 * brain-deadness that various vendors commit in using them.
2705 tulip_softc_t * const sc)
2707 unsigned cksum, rom_cksum, idx;
2709 unsigned char tmpbuf[8];
2710 static const u_char testpat[] = { 0xFF, 0, 0x55, 0xAA, 0xFF, 0, 0x55, 0xAA };
2712 sc->tulip_connidx = TULIP_SROM_LASTCONNIDX;
2714 if (sc->tulip_chipid == TULIP_21040) {
2715 TULIP_CSR_WRITE(sc, csr_enetrom, 1);
2716 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2718 while (((csr = TULIP_CSR_READ(sc, csr_enetrom)) & 0x80000000L) && cnt < 10000)
2720 sc->tulip_rombuf[idx] = csr & 0xFF;
2722 sc->tulip_boardsw = &tulip_21040_boardsw;
2724 if (sc->tulip_chipid == TULIP_21041) {
2726 * Thankfully all 21041's act the same.
2728 sc->tulip_boardsw = &tulip_21041_boardsw;
2731 * Assume all 21140 board are compatible with the
2732 * DEC 10/100 evaluation board. Not really valid but
2733 * it's the best we can do until every one switches to
2734 * the new SROM format.
2737 sc->tulip_boardsw = &tulip_21140_eb_boardsw;
2739 tulip_srom_read(sc);
2740 if (tulip_srom_crcok(sc->tulip_rombuf)) {
2742 * SROM CRC is valid therefore it must be in the
2745 sc->tulip_features |= TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM;
2746 } else if (sc->tulip_rombuf[126] == 0xff && sc->tulip_rombuf[127] == 0xFF) {
2748 * No checksum is present. See if the SROM id checks out;
2749 * the first 18 bytes should be 0 followed by a 1 followed
2750 * by the number of adapters (which we don't deal with yet).
2752 for (idx = 0; idx < 18; idx++) {
2753 if (sc->tulip_rombuf[idx] != 0)
2756 if (idx == 18 && sc->tulip_rombuf[18] == 1 && sc->tulip_rombuf[19] != 0)
2757 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2758 } else if (sc->tulip_chipid >= TULIP_21142) {
2759 sc->tulip_features |= TULIP_HAVE_ISVSROM;
2760 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2762 if ((sc->tulip_features & TULIP_HAVE_ISVSROM) && tulip_srom_decode(sc)) {
2763 if (sc->tulip_chipid != TULIP_21041)
2764 sc->tulip_boardsw = &tulip_2114x_isv_boardsw;
2767 * If the SROM specifies more than one adapter, tag this as a
2770 if (sc->tulip_rombuf[19] > 1)
2771 sc->tulip_features |= TULIP_HAVE_BASEROM;
2772 if (sc->tulip_boardsw == NULL)
2779 if (bcmp(&sc->tulip_rombuf[0], &sc->tulip_rombuf[16], 8) != 0) {
2781 * Some folks don't use the standard ethernet rom format
2782 * but instead just put the address in the first 6 bytes
2783 * of the rom and let the rest be all 0xffs. (Can we say
2784 * ZNYX?) (well sometimes they put in a checksum so we'll
2787 for (idx = 8; idx < 32; idx++) {
2788 if (sc->tulip_rombuf[idx] != 0xFF)
2792 * Make sure the address is not multicast or locally assigned
2793 * that the OUI is not 00-00-00.
2795 if ((sc->tulip_rombuf[0] & 3) != 0)
2797 if (sc->tulip_rombuf[0] == 0 && sc->tulip_rombuf[1] == 0
2798 && sc->tulip_rombuf[2] == 0)
2800 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2801 sc->tulip_features |= TULIP_HAVE_OKROM;
2805 * A number of makers of multiport boards (ZNYX and Cogent)
2806 * only put on one address ROM on their 21040 boards. So
2807 * if the ROM is all zeros (or all 0xFFs), look at the
2808 * previous configured boards (as long as they are on the same
2809 * PCI bus and the bus number is non-zero) until we find the
2810 * master board with address ROM. We then use its address ROM
2811 * as the base for this board. (we add our relative board
2812 * to the last byte of its address).
2814 for (idx = 0; idx < sizeof(sc->tulip_rombuf); idx++) {
2815 if (sc->tulip_rombuf[idx] != 0 && sc->tulip_rombuf[idx] != 0xFF)
2818 if (idx == sizeof(sc->tulip_rombuf)) {
2820 tulip_softc_t *root_sc = NULL;
2821 for (root_unit = sc->tulip_unit - 1; root_unit >= 0; root_unit--) {
2822 root_sc = tulips[root_unit];
2823 if (root_sc == NULL || (root_sc->tulip_features & (TULIP_HAVE_OKROM|TULIP_HAVE_SLAVEDROM)) == TULIP_HAVE_OKROM)
2827 if (root_sc != NULL && (root_sc->tulip_features & TULIP_HAVE_BASEROM)
2828 && root_sc->tulip_chipid == sc->tulip_chipid
2829 && root_sc->tulip_pci_busno == sc->tulip_pci_busno) {
2830 sc->tulip_features |= TULIP_HAVE_SLAVEDROM;
2831 sc->tulip_boardsw = root_sc->tulip_boardsw;
2832 strcpy(sc->tulip_boardid, root_sc->tulip_boardid);
2833 if (sc->tulip_boardsw->bd_type == TULIP_21140_ISV) {
2834 bcopy(root_sc->tulip_rombuf, sc->tulip_rombuf,
2835 sizeof(sc->tulip_rombuf));
2836 if (!tulip_srom_decode(sc))
2839 bcopy(root_sc->tulip_enaddr, sc->tulip_enaddr, 6);
2840 sc->tulip_enaddr[5] += sc->tulip_unit - root_sc->tulip_unit;
2843 * Now for a truly disgusting kludge: all 4 21040s on
2844 * the ZX314 share the same INTA line so the mapping
2845 * setup by the BIOS on the PCI bridge is worthless.
2846 * Rather than reprogramming the value in the config
2847 * register, we will handle this internally.
2849 if (root_sc->tulip_features & TULIP_HAVE_SHAREDINTR) {
2850 sc->tulip_slaves = root_sc->tulip_slaves;
2851 root_sc->tulip_slaves = sc;
2852 sc->tulip_features |= TULIP_HAVE_SLAVEDINTR;
2860 * This is the standard DEC address ROM test.
2863 if (bcmp(&sc->tulip_rombuf[24], testpat, 8) != 0)
2866 tmpbuf[0] = sc->tulip_rombuf[15]; tmpbuf[1] = sc->tulip_rombuf[14];
2867 tmpbuf[2] = sc->tulip_rombuf[13]; tmpbuf[3] = sc->tulip_rombuf[12];
2868 tmpbuf[4] = sc->tulip_rombuf[11]; tmpbuf[5] = sc->tulip_rombuf[10];
2869 tmpbuf[6] = sc->tulip_rombuf[9]; tmpbuf[7] = sc->tulip_rombuf[8];
2870 if (bcmp(&sc->tulip_rombuf[0], tmpbuf, 8) != 0)
2873 bcopy(sc->tulip_rombuf, sc->tulip_enaddr, 6);
2875 cksum = *(u_int16_t *) &sc->tulip_enaddr[0];
2877 if (cksum > 65535) cksum -= 65535;
2878 cksum += *(u_int16_t *) &sc->tulip_enaddr[2];
2879 if (cksum > 65535) cksum -= 65535;
2881 if (cksum > 65535) cksum -= 65535;
2882 cksum += *(u_int16_t *) &sc->tulip_enaddr[4];
2883 if (cksum >= 65535) cksum -= 65535;
2885 rom_cksum = *(u_int16_t *) &sc->tulip_rombuf[6];
2887 if (cksum != rom_cksum)
2892 * Check for various boards based on OUI. Did I say braindead?
2894 for (idx = 0; tulip_vendors[idx].vendor_identify_nic != NULL; idx++) {
2895 if (bcmp(sc->tulip_enaddr, tulip_vendors[idx].vendor_oui, 3) == 0) {
2896 (*tulip_vendors[idx].vendor_identify_nic)(sc);
2901 sc->tulip_features |= TULIP_HAVE_OKROM;
2907 tulip_softc_t * const sc)
2909 tulip_media_t media;
2912 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2913 if (sc->tulip_mediums[media] != NULL) {
2914 ifmedia_add(&sc->tulip_ifmedia, tulip_media_to_ifmedia[media],
2920 sc->tulip_features |= TULIP_HAVE_NOMEDIA;
2921 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE, 0, 0);
2922 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_NONE);
2923 } else if (sc->tulip_media == TULIP_MEDIA_UNKNOWN) {
2924 ifmedia_add(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO, 0, 0);
2925 ifmedia_set(&sc->tulip_ifmedia, IFM_ETHER | IFM_AUTO);
2927 ifmedia_set(&sc->tulip_ifmedia, tulip_media_to_ifmedia[sc->tulip_media]);
2928 sc->tulip_flags |= TULIP_PRINTMEDIA;
2929 tulip_linkup(sc, sc->tulip_media);
2934 tulip_ifmedia_change(
2935 struct ifnet * const ifp)
2937 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
2939 sc->tulip_flags |= TULIP_NEEDRESET;
2940 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
2941 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
2942 if (IFM_SUBTYPE(sc->tulip_ifmedia.ifm_media) != IFM_AUTO) {
2943 tulip_media_t media;
2944 for (media = TULIP_MEDIA_UNKNOWN; media < TULIP_MEDIA_MAX; media++) {
2945 if (sc->tulip_mediums[media] != NULL
2946 && sc->tulip_ifmedia.ifm_media == tulip_media_to_ifmedia[media]) {
2947 sc->tulip_flags |= TULIP_PRINTMEDIA;
2948 sc->tulip_flags &= ~TULIP_DIDNWAY;
2949 tulip_linkup(sc, media);
2954 sc->tulip_flags &= ~(TULIP_TXPROBE_ACTIVE|TULIP_WANTRXACT);
2961 * Media status callback
2964 tulip_ifmedia_status(
2965 struct ifnet * const ifp,
2966 struct ifmediareq *req)
2968 tulip_softc_t *sc = (tulip_softc_t *)ifp->if_softc;
2970 if (sc->tulip_media == TULIP_MEDIA_UNKNOWN)
2973 req->ifm_status = IFM_AVALID;
2974 if (sc->tulip_flags & TULIP_LINKUP)
2975 req->ifm_status |= IFM_ACTIVE;
2977 req->ifm_active = tulip_media_to_ifmedia[sc->tulip_media];
2982 tulip_softc_t * const sc)
2984 struct ifmultiaddr *ifma;
2988 sc->tulip_flags &= ~(TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY|TULIP_ALLMULTI);
2989 sc->tulip_flags |= TULIP_WANTSETUP|TULIP_WANTTXSTART;
2990 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
2991 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
2992 #if defined(IFF_ALLMULTI)
2993 if (sc->tulip_if.if_flags & IFF_ALLMULTI)
2994 sc->tulip_flags |= TULIP_ALLMULTI ;
2998 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
2999 ifma = ifma->ifma_link.le_next) {
3001 if (ifma->ifma_addr->sa_family == AF_LINK)
3005 sc->tulip_if.if_start = tulip_ifstart; /* so the setup packet gets queued */
3006 if (multicnt > 14) {
3007 u_int32_t *sp = sc->tulip_setupdata;
3010 * Some early passes of the 21140 have broken implementations of
3011 * hash-perfect mode. When we get too many multicasts for perfect
3012 * filtering with these chips, we need to switch into hash-only
3013 * mode (this is better than all-multicast on network with lots
3014 * of multicast traffic).
3016 if (sc->tulip_features & TULIP_HAVE_BROKEN_HASH)
3017 sc->tulip_flags |= TULIP_WANTHASHONLY;
3019 sc->tulip_flags |= TULIP_WANTHASHPERFECT;
3021 * If we have more than 14 multicasts, we have
3022 * go into hash perfect mode (512 bit multicast
3023 * hash and one perfect hardware).
3025 bzero(sc->tulip_setupdata, sizeof(sc->tulip_setupdata));
3027 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3028 ifma = ifma->ifma_link.le_next) {
3030 if (ifma->ifma_addr->sa_family != AF_LINK)
3033 hash = tulip_mchash(LLADDR((struct sockaddr_dl *)ifma->ifma_addr));
3034 #if BYTE_ORDER == BIG_ENDIAN
3035 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3037 sp[hash >> 4] |= 1 << (hash & 0xF);
3041 * No reason to use a hash if we are going to be
3042 * receiving every multicast.
3044 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3045 hash = tulip_mchash(sc->tulip_if.if_broadcastaddr);
3046 #if BYTE_ORDER == BIG_ENDIAN
3047 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3049 sp[hash >> 4] |= 1 << (hash & 0xF);
3051 if (sc->tulip_flags & TULIP_WANTHASHONLY) {
3052 hash = tulip_mchash(sc->tulip_enaddr);
3053 #if BYTE_ORDER == BIG_ENDIAN
3054 sp[hash >> 4] |= bswap32(1 << (hash & 0xF));
3056 sp[hash >> 4] |= 1 << (hash & 0xF);
3059 #if BYTE_ORDER == BIG_ENDIAN
3060 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3061 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3062 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3064 sp[39] = ((u_int16_t *) sc->tulip_enaddr)[0];
3065 sp[40] = ((u_int16_t *) sc->tulip_enaddr)[1];
3066 sp[41] = ((u_int16_t *) sc->tulip_enaddr)[2];
3071 if ((sc->tulip_flags & (TULIP_WANTHASHPERFECT|TULIP_WANTHASHONLY)) == 0) {
3072 u_int32_t *sp = sc->tulip_setupdata;
3074 if ((sc->tulip_flags & TULIP_ALLMULTI) == 0) {
3076 * Else can get perfect filtering for 16 addresses.
3078 for (ifma = sc->tulip_if.if_multiaddrs.lh_first; ifma != NULL;
3079 ifma = ifma->ifma_link.le_next) {
3080 if (ifma->ifma_addr->sa_family != AF_LINK)
3082 addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr);
3083 #if BYTE_ORDER == BIG_ENDIAN
3084 *sp++ = ((u_int16_t *) addrp)[0] << 16;
3085 *sp++ = ((u_int16_t *) addrp)[1] << 16;
3086 *sp++ = ((u_int16_t *) addrp)[2] << 16;
3088 *sp++ = ((u_int16_t *) addrp)[0];
3089 *sp++ = ((u_int16_t *) addrp)[1];
3090 *sp++ = ((u_int16_t *) addrp)[2];
3095 * Add the broadcast address.
3098 #if BYTE_ORDER == BIG_ENDIAN
3099 *sp++ = 0xFFFF << 16;
3100 *sp++ = 0xFFFF << 16;
3101 *sp++ = 0xFFFF << 16;
3109 * Pad the rest with our hardware address
3111 for (; idx < 16; idx++) {
3112 #if BYTE_ORDER == BIG_ENDIAN
3113 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0] << 16;
3114 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1] << 16;
3115 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2] << 16;
3117 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[0];
3118 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[1];
3119 *sp++ = ((u_int16_t *) sc->tulip_enaddr)[2];
3123 #if defined(IFF_ALLMULTI)
3124 if (sc->tulip_flags & TULIP_ALLMULTI)
3125 sc->tulip_if.if_flags |= IFF_ALLMULTI;
3131 tulip_softc_t * const sc)
3133 tulip_ringinfo_t *ri;
3135 u_int32_t inreset = (sc->tulip_flags & TULIP_INRESET);
3138 * Brilliant. Simply brilliant. When switching modes/speeds
3139 * on a 2114*, you need to set the appriopriate MII/PCS/SCL/PS
3140 * bits in CSR6 and then do a software reset to get the 21140
3141 * to properly reset its internal pathways to the right places.
3144 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0
3145 && sc->tulip_boardsw->bd_media_preset != NULL)
3146 (*sc->tulip_boardsw->bd_media_preset)(sc);
3148 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
3149 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
3150 33MHz that comes to two microseconds but wait a
3151 bit longer anyways) */
3154 sc->tulip_flags |= TULIP_INRESET;
3155 sc->tulip_flags &= ~(TULIP_NEEDRESET|TULIP_RXBUFSLOW);
3156 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3157 sc->tulip_if.if_start = tulip_ifstart;
3160 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3161 TULIP_CSR_WRITE(sc, csr_txlist, sc->tulip_txdescmap->dm_segs[0].ds_addr);
3163 TULIP_CSR_WRITE(sc, csr_txlist, TULIP_KVATOPHYS(sc, &sc->tulip_txinfo.ri_first[0]));
3165 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3166 TULIP_CSR_WRITE(sc, csr_rxlist, sc->tulip_rxdescmap->dm_segs[0].ds_addr);
3168 TULIP_CSR_WRITE(sc, csr_rxlist, TULIP_KVATOPHYS(sc, &sc->tulip_rxinfo.ri_first[0]));
3170 TULIP_CSR_WRITE(sc, csr_busmode,
3171 (1 << (3 /*pci_max_burst_len*/ + 8))
3172 |TULIP_BUSMODE_CACHE_ALIGN8
3173 |TULIP_BUSMODE_READMULTIPLE
3174 |(BYTE_ORDER != LITTLE_ENDIAN ?
3175 TULIP_BUSMODE_DESC_BIGENDIAN : 0));
3177 sc->tulip_txtimer = 0;
3178 sc->tulip_txq.ifq_maxlen = TULIP_TXDESCS;
3180 * Free all the mbufs that were on the transmit ring.
3183 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3187 IF_DEQUEUE(&sc->tulip_txq, m);
3190 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3191 map = M_GETCTX(m, bus_dmamap_t);
3192 bus_dmamap_unload(sc->tulip_dmatag, map);
3193 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3198 ri = &sc->tulip_txinfo;
3199 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3200 ri->ri_free = ri->ri_max;
3201 for (di = ri->ri_first; di < ri->ri_last; di++)
3203 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3204 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_txdescmap,
3205 0, sc->tulip_txdescmap->dm_mapsize,
3206 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3210 * We need to collect all the mbufs were on the
3211 * receive ring before we reinit it either to put
3212 * them back on or to know if we have to allocate
3215 ri = &sc->tulip_rxinfo;
3216 ri->ri_nextin = ri->ri_nextout = ri->ri_first;
3217 ri->ri_free = ri->ri_max;
3218 for (di = ri->ri_first; di < ri->ri_last; di++) {
3220 di->d_length1 = 0; di->d_addr1 = 0;
3221 di->d_length2 = 0; di->d_addr2 = 0;
3223 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3224 bus_dmamap_sync(sc->tulip_dmatag, sc->tulip_rxdescmap,
3225 0, sc->tulip_rxdescmap->dm_mapsize,
3226 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
3229 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3233 IF_DEQUEUE(&sc->tulip_rxq, m);
3236 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3237 map = M_GETCTX(m, bus_dmamap_t);
3238 bus_dmamap_unload(sc->tulip_dmatag, map);
3239 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3245 * If tulip_reset is being called recurisvely, exit quickly knowing
3246 * that when the outer tulip_reset returns all the right stuff will
3252 sc->tulip_intrmask |= TULIP_STS_NORMALINTR|TULIP_STS_RXINTR|TULIP_STS_TXINTR
3253 |TULIP_STS_ABNRMLINTR|TULIP_STS_SYSERROR|TULIP_STS_TXSTOPPED
3254 |TULIP_STS_TXUNDERFLOW|TULIP_STS_TXBABBLE
3255 |TULIP_STS_RXSTOPPED;
3257 if ((sc->tulip_flags & TULIP_DEVICEPROBE) == 0)
3258 (*sc->tulip_boardsw->bd_media_select)(sc);
3259 #if defined(TULIP_DEBUG)
3260 if ((sc->tulip_flags & TULIP_NEEDRESET) == TULIP_NEEDRESET)
3261 printf("%s%d: tulip_reset: additional reset needed?!?\n",
3262 sc->tulip_name, sc->tulip_unit);
3264 tulip_media_print(sc);
3265 if (sc->tulip_features & TULIP_HAVE_DUALSENSE)
3266 TULIP_CSR_WRITE(sc, csr_sia_status, TULIP_CSR_READ(sc, csr_sia_status));
3268 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_WANTSETUP|TULIP_INRESET
3270 tulip_addr_filter(sc);
3275 tulip_softc_t * const sc)
3277 if (sc->tulip_if.if_flags & IFF_UP) {
3278 if ((sc->tulip_if.if_flags & IFF_RUNNING) == 0) {
3279 /* initialize the media */
3282 sc->tulip_if.if_flags |= IFF_RUNNING;
3283 if (sc->tulip_if.if_flags & IFF_PROMISC) {
3284 sc->tulip_flags |= TULIP_PROMISC;
3285 sc->tulip_cmdmode |= TULIP_CMD_PROMISCUOUS;
3286 sc->tulip_intrmask |= TULIP_STS_TXINTR;
3288 sc->tulip_flags &= ~TULIP_PROMISC;
3289 sc->tulip_cmdmode &= ~TULIP_CMD_PROMISCUOUS;
3290 if (sc->tulip_flags & TULIP_ALLMULTI) {
3291 sc->tulip_cmdmode |= TULIP_CMD_ALLMULTI;
3293 sc->tulip_cmdmode &= ~TULIP_CMD_ALLMULTI;
3296 sc->tulip_cmdmode |= TULIP_CMD_TXRUN;
3297 if ((sc->tulip_flags & (TULIP_TXPROBE_ACTIVE|TULIP_WANTSETUP)) == 0) {
3299 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3300 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3302 sc->tulip_if.if_flags |= IFF_OACTIVE;
3303 sc->tulip_cmdmode &= ~TULIP_CMD_RXRUN;
3304 sc->tulip_intrmask &= ~TULIP_STS_RXSTOPPED;
3306 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3307 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3308 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
3309 tulip_txput_setup(sc);
3311 sc->tulip_if.if_flags &= ~IFF_RUNNING;
3318 tulip_softc_t * const sc)
3320 TULIP_PERFSTART(rxintr)
3321 tulip_ringinfo_t * const ri = &sc->tulip_rxinfo;
3322 struct ifnet * const ifp = &sc->tulip_if;
3324 #if defined(TULIP_DEBUG)
3329 TULIP_PERFSTART(rxget)
3330 struct ether_header eh;
3331 tulip_desc_t *eop = ri->ri_nextin;
3332 int total_len = 0, last_offset = 0;
3333 struct mbuf *ms = NULL, *me = NULL;
3335 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3340 if (fillok && sc->tulip_rxq.ifq_len < TULIP_RXQ_TARGET)
3343 #if defined(TULIP_DEBUG)
3344 if (cnt == ri->ri_max)
3348 * If the TULIP has no descriptors, there can't be any receive
3349 * descriptors to process.
3351 if (eop == ri->ri_nextout)
3355 * 90% of the packets will fit in one descriptor. So we optimize
3358 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3359 if ((((volatile tulip_desc_t *) eop)->d_status & (TULIP_DSTS_OWNER|TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) == (TULIP_DSTS_RxFIRSTDESC|TULIP_DSTS_RxLASTDESC)) {
3360 IF_DEQUEUE(&sc->tulip_rxq, ms);
3364 * If still owned by the TULIP, don't touch it.
3366 if (((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER)
3370 * It is possible (though improbable unless the BIG_PACKET support
3371 * is enabled or MCLBYTES < 1518) for a received packet to cross
3372 * more than one receive descriptor.
3374 while ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_RxLASTDESC) == 0) {
3375 if (++eop == ri->ri_last)
3377 TULIP_RXDESC_POSTSYNC(sc, eop, sizeof(*eop));
3378 if (eop == ri->ri_nextout || ((((volatile tulip_desc_t *) eop)->d_status & TULIP_DSTS_OWNER))) {
3379 #if defined(TULIP_DEBUG)
3380 sc->tulip_dbg.dbg_rxintrs++;
3381 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3383 TULIP_PERFEND(rxget);
3384 TULIP_PERFEND(rxintr);
3391 * Dequeue the first buffer for the start of the packet. Hopefully
3392 * this will be the only one we need to dequeue. However, if the
3393 * packet consumed multiple descriptors, then we need to dequeue
3394 * those buffers and chain to the starting mbuf. All buffers but
3395 * the last buffer have the same length so we can set that now.
3396 * (we add to last_offset instead of multiplying since we normally
3397 * won't go into the loop and thereby saving a ourselves from
3398 * doing a multiplication by 0 in the normal case).
3400 IF_DEQUEUE(&sc->tulip_rxq, ms);
3401 for (me = ms; total_len > 0; total_len--) {
3402 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3403 map = M_GETCTX(me, bus_dmamap_t);
3404 TULIP_RXMAP_POSTSYNC(sc, map);
3405 bus_dmamap_unload(sc->tulip_dmatag, map);
3406 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3407 #if defined(DIAGNOSTIC)
3410 #endif /* TULIP_BUS_DMA */
3411 me->m_len = TULIP_RX_BUFLEN;
3412 last_offset += TULIP_RX_BUFLEN;
3413 IF_DEQUEUE(&sc->tulip_rxq, me->m_next);
3419 * Now get the size of received packet (minus the CRC).
3421 total_len = ((eop->d_status >> 16) & 0x7FFF) - 4;
3422 if ((sc->tulip_flags & TULIP_RXIGNORE) == 0
3423 && ((eop->d_status & TULIP_DSTS_ERRSUM) == 0
3425 || (total_len <= sc->tulip_if.if_mtu + sizeof(struct ether_header) &&
3426 (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxRUNT|
3427 TULIP_DSTS_RxCOLLSEEN|TULIP_DSTS_RxBADCRC|
3428 TULIP_DSTS_RxOVERFLOW)) == 0)
3431 me->m_len = total_len - last_offset;
3433 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3434 map = M_GETCTX(me, bus_dmamap_t);
3435 bus_dmamap_sync(sc->tulip_dmatag, map, 0, me->m_len,
3436 BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
3437 bus_dmamap_unload(sc->tulip_dmatag, map);
3438 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3439 #if defined(DIAGNOSTIC)
3442 #endif /* TULIP_BUS_DMA */
3444 eh = *mtod(ms, struct ether_header *);
3445 #if !defined(__DragonFly__) && !defined(__FreeBSD__)
3446 if (sc->tulip_if.if_bpf != NULL) {
3448 bpf_tap(&sc->tulip_if, mtod(ms, caddr_t), total_len);
3450 bpf_mtap(&sc->tulip_if, ms);
3453 sc->tulip_flags |= TULIP_RXACT;
3457 if (eop->d_status & (TULIP_DSTS_RxBADLENGTH|TULIP_DSTS_RxOVERFLOW|TULIP_DSTS_RxWATCHDOG)) {
3458 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3460 #if defined(TULIP_VERBOSE)
3461 const char *error = NULL;
3463 if (eop->d_status & TULIP_DSTS_RxTOOLONG) {
3464 sc->tulip_dot3stats.dot3StatsFrameTooLongs++;
3465 #if defined(TULIP_VERBOSE)
3466 error = "frame too long";
3469 if (eop->d_status & TULIP_DSTS_RxBADCRC) {
3470 if (eop->d_status & TULIP_DSTS_RxDRBBLBIT) {
3471 sc->tulip_dot3stats.dot3StatsAlignmentErrors++;
3472 #if defined(TULIP_VERBOSE)
3473 error = "alignment error";
3476 sc->tulip_dot3stats.dot3StatsFCSErrors++;
3477 #if defined(TULIP_VERBOSE)
3482 #if defined(TULIP_VERBOSE)
3483 if (error != NULL && (sc->tulip_flags & TULIP_NOMESSAGES) == 0) {
3484 printf("%s%d: receive: %6D: %s\n",
3485 sc->tulip_name, sc->tulip_unit,
3486 mtod(ms, u_char *) + 6, ":",
3488 sc->tulip_flags |= TULIP_NOMESSAGES;
3493 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3494 map = M_GETCTX(me, bus_dmamap_t);
3495 bus_dmamap_unload(sc->tulip_dmatag, map);
3496 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
3497 #if defined(DIAGNOSTIC)
3500 #endif /* TULIP_BUS_DMA */
3502 #if defined(TULIP_DEBUG)
3506 if (++eop == ri->ri_last)
3508 ri->ri_nextin = eop;
3511 * Either we are priming the TULIP with mbufs (m == NULL)
3512 * or we are about to accept an mbuf for the upper layers
3513 * so we need to allocate an mbuf to replace it. If we
3514 * can't replace it, send up it anyways. This may cause
3515 * us to drop packets in the future but that's better than
3516 * being caught in livelock.
3518 * Note that if this packet crossed multiple descriptors
3519 * we don't even try to reallocate all the mbufs here.
3520 * Instead we rely on the test of the beginning of
3521 * the loop to refill for the extra consumed mbufs.
3523 if (accept || ms == NULL) {
3525 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
3527 #if defined(TULIP_COPY_RXDATA)
3528 if (!accept || total_len >= (MHLEN - 2)) {
3530 MCLGET(m0, MB_DONTWAIT);
3531 if ((m0->m_flags & M_EXT) == 0) {
3535 #if defined(TULIP_COPY_RXDATA)
3540 #if defined(TULIP_COPY_RXDATA)
3544 #if !defined(TULIP_COPY_RXDATA)
3545 ms->m_pkthdr.len = total_len;
3546 ms->m_pkthdr.rcvif = ifp;
3547 m_adj(ms, sizeof(struct ether_header));
3548 ether_input(ifp, &eh, ms);
3551 #error BIG_PACKET is incompatible with TULIP_COPY_RXDATA
3553 m0->m_data += 2; /* align data after header */
3554 m_copydata(ms, 0, total_len, mtod(m0, caddr_t));
3555 m0->m_len = m0->m_pkthdr.len = total_len;
3556 m0->m_pkthdr.rcvif = ifp;
3557 m_adj(m0, sizeof(struct ether_header));
3558 ether_input(ifp, &eh, m0);
3560 #endif /* ! TULIP_COPY_RXDATA */
3566 * Couldn't allocate a new buffer. Don't bother
3567 * trying to replenish the receive queue.
3570 sc->tulip_flags |= TULIP_RXBUFSLOW;
3571 #if defined(TULIP_DEBUG)
3572 sc->tulip_dbg.dbg_rxlowbufs++;
3574 TULIP_PERFEND(rxget);
3578 * Now give the buffer(s) to the TULIP and save in our
3582 tulip_desc_t * const nextout = ri->ri_nextout;
3583 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NORX)
3584 if (sc->tulip_rxmaps_free > 0) {
3585 map = sc->tulip_rxmaps[--sc->tulip_rxmaps_free];
3588 sc->tulip_flags |= TULIP_RXBUFSLOW;
3589 #if defined(TULIP_DEBUG)
3590 sc->tulip_dbg.dbg_rxlowbufs++;
3595 error = bus_dmamap_load(sc->tulip_dmatag, map, mtod(ms, void *),
3596 TULIP_RX_BUFLEN, NULL, BUS_DMA_NOWAIT);
3598 printf("%s%d: unable to load rx map, "
3599 "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
3600 panic("tulip_rx_intr"); /* XXX */
3602 nextout->d_addr1 = map->dm_segs[0].ds_addr;
3603 nextout->d_length1 = map->dm_segs[0].ds_len;
3604 if (map->dm_nsegs == 2) {
3605 nextout->d_addr2 = map->dm_segs[1].ds_addr;
3606 nextout->d_length2 = map->dm_segs[1].ds_len;
3608 nextout->d_addr2 = 0;
3609 nextout->d_length2 = 0;
3611 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(*nextout));
3612 #else /* TULIP_BUS_DMA */
3613 nextout->d_addr1 = TULIP_KVATOPHYS(sc, mtod(ms, caddr_t));
3614 nextout->d_length1 = TULIP_RX_BUFLEN;
3615 #endif /* TULIP_BUS_DMA */
3616 nextout->d_status = TULIP_DSTS_OWNER;
3617 TULIP_RXDESC_POSTSYNC(sc, nextout, sizeof(u_int32_t));
3618 if (++ri->ri_nextout == ri->ri_last)
3619 ri->ri_nextout = ri->ri_first;
3622 IF_ENQUEUE(&sc->tulip_rxq, ms);
3623 } while ((ms = me) != NULL);
3625 if (sc->tulip_rxq.ifq_len >= TULIP_RXQ_TARGET)
3626 sc->tulip_flags &= ~TULIP_RXBUFSLOW;
3627 TULIP_PERFEND(rxget);
3630 #if defined(TULIP_DEBUG)
3631 sc->tulip_dbg.dbg_rxintrs++;
3632 sc->tulip_dbg.dbg_rxpktsperintr[cnt]++;
3634 TULIP_PERFEND(rxintr);
3639 tulip_softc_t * const sc)
3641 TULIP_PERFSTART(txintr)
3642 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3647 while (ri->ri_free < ri->ri_max) {
3650 TULIP_TXDESC_POSTSYNC(sc, ri->ri_nextin, sizeof(*ri->ri_nextin));
3651 if (((volatile tulip_desc_t *) ri->ri_nextin)->d_status & TULIP_DSTS_OWNER)
3656 d_flag = ri->ri_nextin->d_flag;
3657 if (d_flag & TULIP_DFLAG_TxLASTSEG) {
3658 if (d_flag & TULIP_DFLAG_TxSETUPPKT) {
3660 * We've just finished processing a setup packet.
3661 * Mark that we finished it. If there's not
3662 * another pending, startup the TULIP receiver.
3663 * Make sure we ack the RXSTOPPED so we won't get
3664 * an abormal interrupt indication.
3666 TULIP_TXMAP_POSTSYNC(sc, sc->tulip_setupmap);
3667 sc->tulip_flags &= ~(TULIP_DOINGSETUP|TULIP_HASHONLY);
3668 if (ri->ri_nextin->d_flag & TULIP_DFLAG_TxINVRSFILT)
3669 sc->tulip_flags |= TULIP_HASHONLY;
3670 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == 0) {
3672 sc->tulip_cmdmode |= TULIP_CMD_RXRUN;
3673 sc->tulip_intrmask |= TULIP_STS_RXSTOPPED;
3674 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3675 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
3676 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3679 const u_int32_t d_status = ri->ri_nextin->d_status;
3680 IF_DEQUEUE(&sc->tulip_txq, m);
3682 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
3683 bus_dmamap_t map = M_GETCTX(m, bus_dmamap_t);
3684 TULIP_TXMAP_POSTSYNC(sc, map);
3685 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
3686 #endif /* TULIP_BUS_DMA */
3688 #if defined(TULIP_DEBUG)
3690 printf("%s%d: tx_intr: failed to dequeue mbuf?!?\n",
3691 sc->tulip_name, sc->tulip_unit);
3694 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
3695 tulip_mediapoll_event_t event = TULIP_MEDIAPOLL_TXPROBE_OK;
3696 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxEXCCOLL)) {
3697 #if defined(TULIP_DEBUG)
3698 if (d_status & TULIP_DSTS_TxNOCARR)
3699 sc->tulip_dbg.dbg_txprobe_nocarr++;
3700 if (d_status & TULIP_DSTS_TxEXCCOLL)
3701 sc->tulip_dbg.dbg_txprobe_exccoll++;
3703 event = TULIP_MEDIAPOLL_TXPROBE_FAILED;
3705 (*sc->tulip_boardsw->bd_media_poll)(sc, event);
3707 * Escape from the loop before media poll has reset the TULIP!
3712 if (d_status & TULIP_DSTS_ERRSUM) {
3713 sc->tulip_if.if_oerrors++;
3714 if (d_status & TULIP_DSTS_TxEXCCOLL)
3715 sc->tulip_dot3stats.dot3StatsExcessiveCollisions++;
3716 if (d_status & TULIP_DSTS_TxLATECOLL)
3717 sc->tulip_dot3stats.dot3StatsLateCollisions++;
3718 if (d_status & (TULIP_DSTS_TxNOCARR|TULIP_DSTS_TxCARRLOSS))
3719 sc->tulip_dot3stats.dot3StatsCarrierSenseErrors++;
3720 if (d_status & (TULIP_DSTS_TxUNDERFLOW|TULIP_DSTS_TxBABBLE))
3721 sc->tulip_dot3stats.dot3StatsInternalMacTransmitErrors++;
3722 if (d_status & TULIP_DSTS_TxUNDERFLOW)
3723 sc->tulip_dot3stats.dot3StatsInternalTransmitUnderflows++;
3724 if (d_status & TULIP_DSTS_TxBABBLE)
3725 sc->tulip_dot3stats.dot3StatsInternalTransmitBabbles++;
3727 u_int32_t collisions =
3728 (d_status & TULIP_DSTS_TxCOLLMASK)
3729 >> TULIP_DSTS_V_TxCOLLCNT;
3730 sc->tulip_if.if_collisions += collisions;
3731 if (collisions == 1)
3732 sc->tulip_dot3stats.dot3StatsSingleCollisionFrames++;
3733 else if (collisions > 1)
3734 sc->tulip_dot3stats.dot3StatsMultipleCollisionFrames++;
3735 else if (d_status & TULIP_DSTS_TxDEFERRED)
3736 sc->tulip_dot3stats.dot3StatsDeferredTransmissions++;
3738 * SQE is only valid for 10baseT/BNC/AUI when not
3739 * running in full-duplex. In order to speed up the
3740 * test, the corresponding bit in tulip_flags needs to
3741 * set as well to get us to count SQE Test Errors.
3743 if (d_status & TULIP_DSTS_TxNOHRTBT & sc->tulip_flags)
3744 sc->tulip_dot3stats.dot3StatsSQETestErrors++;
3750 if (++ri->ri_nextin == ri->ri_last)
3751 ri->ri_nextin = ri->ri_first;
3753 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3754 sc->tulip_if.if_flags &= ~IFF_OACTIVE;
3757 * If nothing left to transmit, disable the timer.
3758 * Else if progress, reset the timer back to 2 ticks.
3760 if (ri->ri_free == ri->ri_max || (sc->tulip_flags & TULIP_TXPROBE_ACTIVE))
3761 sc->tulip_txtimer = 0;
3763 sc->tulip_txtimer = TULIP_TXTIMER;
3764 sc->tulip_if.if_opackets += xmits;
3765 TULIP_PERFEND(txintr);
3770 tulip_print_abnormal_interrupt(
3771 tulip_softc_t * const sc,
3774 const char * const *msgp = tulip_status_bits;
3777 const char thrsh[] = "72|128\0\0\0" "96|256\0\0\0" "128|512\0\0" "160|1024";
3779 csr &= (1 << (sizeof(tulip_status_bits)/sizeof(tulip_status_bits[0]))) - 1;
3780 printf("%s%d: abnormal interrupt:", sc->tulip_name, sc->tulip_unit);
3781 for (sep = " ", mask = 1; mask <= csr; mask <<= 1, msgp++) {
3782 if ((csr & mask) && *msgp != NULL) {
3783 printf("%s%s", sep, *msgp);
3784 if (mask == TULIP_STS_TXUNDERFLOW && (sc->tulip_flags & TULIP_NEWTXTHRESH)) {
3785 sc->tulip_flags &= ~TULIP_NEWTXTHRESH;
3786 if (sc->tulip_cmdmode & TULIP_CMD_STOREFWD) {
3787 printf(" (switching to store-and-forward mode)");
3789 printf(" (raising TX threshold to %s)",
3790 &thrsh[9 * ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) >> 14)]);
3801 tulip_softc_t * const sc,
3804 TULIP_PERFSTART(intr)
3807 while ((csr = TULIP_CSR_READ(sc, csr_status)) & sc->tulip_intrmask) {
3809 TULIP_CSR_WRITE(sc, csr_status, csr);
3811 if (csr & TULIP_STS_SYSERROR) {
3812 sc->tulip_last_system_error = (csr & TULIP_STS_ERRORMASK) >> TULIP_STS_ERR_SHIFT;
3813 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3814 sc->tulip_flags |= TULIP_SYSTEMERROR;
3816 printf("%s%d: system error: %s\n",
3817 sc->tulip_name, sc->tulip_unit,
3818 tulip_system_errors[sc->tulip_last_system_error]);
3820 sc->tulip_flags |= TULIP_NEEDRESET;
3821 sc->tulip_system_errors++;
3824 if (csr & (TULIP_STS_LINKPASS|TULIP_STS_LINKFAIL) & sc->tulip_intrmask) {
3825 #if defined(TULIP_DEBUG)
3826 sc->tulip_dbg.dbg_link_intrs++;
3828 if (sc->tulip_boardsw->bd_media_poll != NULL) {
3829 (*sc->tulip_boardsw->bd_media_poll)(sc, csr & TULIP_STS_LINKFAIL
3830 ? TULIP_MEDIAPOLL_LINKFAIL
3831 : TULIP_MEDIAPOLL_LINKPASS);
3832 csr &= ~TULIP_STS_ABNRMLINTR;
3834 tulip_media_print(sc);
3836 if (csr & (TULIP_STS_RXINTR|TULIP_STS_RXNOBUF)) {
3837 u_int32_t misses = TULIP_CSR_READ(sc, csr_missed_frames);
3838 if (csr & TULIP_STS_RXNOBUF)
3839 sc->tulip_dot3stats.dot3StatsMissedFrames += misses & 0xFFFF;
3841 * Pass 2.[012] of the 21140A-A[CDE] may hang and/or corrupt data
3842 * on receive overflows.
3844 if ((misses & 0x0FFE0000) && (sc->tulip_features & TULIP_HAVE_RXBADOVRFLW)) {
3845 sc->tulip_dot3stats.dot3StatsInternalMacReceiveErrors++;
3847 * Stop the receiver process and spin until it's stopped.
3848 * Tell rx_intr to drop the packets it dequeues.
3850 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode & ~TULIP_CMD_RXRUN);
3851 while ((TULIP_CSR_READ(sc, csr_status) & TULIP_STS_RXSTOPPED) == 0)
3853 TULIP_CSR_WRITE(sc, csr_status, TULIP_STS_RXSTOPPED);
3854 sc->tulip_flags |= TULIP_RXIGNORE;
3857 if (sc->tulip_flags & TULIP_RXIGNORE) {
3859 * Restart the receiver.
3861 sc->tulip_flags &= ~TULIP_RXIGNORE;
3862 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3865 if (csr & TULIP_STS_ABNRMLINTR) {
3866 u_int32_t tmp = csr & sc->tulip_intrmask
3867 & ~(TULIP_STS_NORMALINTR|TULIP_STS_ABNRMLINTR);
3868 if (csr & TULIP_STS_TXUNDERFLOW) {
3869 if ((sc->tulip_cmdmode & TULIP_CMD_THRESHOLDCTL) != TULIP_CMD_THRSHLD160) {
3870 sc->tulip_cmdmode += TULIP_CMD_THRSHLD96;
3871 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3872 } else if (sc->tulip_features & TULIP_HAVE_STOREFWD) {
3873 sc->tulip_cmdmode |= TULIP_CMD_STOREFWD;
3874 sc->tulip_flags |= TULIP_NEWTXTHRESH;
3877 if (sc->tulip_flags & TULIP_NOMESSAGES) {
3878 sc->tulip_statusbits |= tmp;
3880 tulip_print_abnormal_interrupt(sc, tmp);
3881 sc->tulip_flags |= TULIP_NOMESSAGES;
3883 TULIP_CSR_WRITE(sc, csr_command, sc->tulip_cmdmode);
3885 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_TXPROBE_ACTIVE|TULIP_DOINGSETUP|TULIP_PROMISC)) {
3887 if ((sc->tulip_flags & TULIP_TXPROBE_ACTIVE) == 0)
3888 tulip_ifstart(&sc->tulip_if);
3891 if (sc->tulip_flags & TULIP_NEEDRESET) {
3895 TULIP_PERFEND(intr);
3902 tulip_softc_t * sc = arg;
3905 for (; sc != NULL; sc = sc->tulip_slaves) {
3906 #if defined(TULIP_DEBUG)
3907 sc->tulip_dbg.dbg_intrs++;
3909 tulip_intr_handler(sc, &progress);
3917 tulip_softc_t * sc = (tulip_softc_t *) arg;
3920 #if defined(TULIP_DEBUG)
3921 sc->tulip_dbg.dbg_intrs++;
3923 tulip_intr_handler(sc, &progress);
3926 static struct mbuf *
3927 tulip_mbuf_compress(
3931 #if MCLBYTES >= ETHERMTU + 18 && !defined(BIG_PACKET)
3932 MGETHDR(m0, MB_DONTWAIT, MT_DATA);
3934 if (m->m_pkthdr.len > MHLEN) {
3935 MCLGET(m0, MB_DONTWAIT);
3936 if ((m0->m_flags & M_EXT) == 0) {
3942 m_copydata(m, 0, m->m_pkthdr.len, mtod(m0, caddr_t));
3943 m0->m_pkthdr.len = m0->m_len = m->m_pkthdr.len;
3947 int len = m->m_pkthdr.len;
3948 struct mbuf **mp = &m0;
3951 if (mlen == MHLEN) {
3952 MGETHDR(*mp, MB_DONTWAIT, MT_DATA);
3954 MGET(*mp, MB_DONTWAIT, MT_DATA);
3962 MCLGET(*mp, MB_DONTWAIT);
3963 if (((*mp)->m_flags & M_EXT) == 0) {
3968 (*mp)->m_len = len <= MCLBYTES ? len : MCLBYTES;
3970 (*mp)->m_len = len <= mlen ? len : mlen;
3972 m_copydata(m, m->m_pkthdr.len - len,
3973 (*mp)->m_len, mtod((*mp), caddr_t));
3974 len -= (*mp)->m_len;
3975 mp = &(*mp)->m_next;
3983 static struct mbuf *
3985 tulip_softc_t * const sc,
3988 TULIP_PERFSTART(txput)
3989 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
3990 tulip_desc_t *eop, *nextout;
3993 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4000 #if defined(TULIP_DEBUG)
4001 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4002 printf("%s%d: txput%s: tx not running\n",
4003 sc->tulip_name, sc->tulip_unit,
4004 (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) ? "(probe)" : "");
4005 sc->tulip_flags |= TULIP_WANTTXSTART;
4006 sc->tulip_dbg.dbg_txput_finishes[0]++;
4012 * Now we try to fill in our transmit descriptors. This is
4013 * a bit reminiscent of going on the Ark two by two
4014 * since each descriptor for the TULIP can describe
4015 * two buffers. So we advance through packet filling
4016 * each of the two entries at a time to to fill each
4017 * descriptor. Clear the first and last segment bits
4018 * in each descriptor (actually just clear everything
4019 * but the end-of-ring or chain bits) to make sure
4020 * we don't get messed up by previously sent packets.
4022 * We may fail to put the entire packet on the ring if
4023 * there is either not enough ring entries free or if the
4024 * packet has more than MAX_TXSEG segments. In the former
4025 * case we will just wait for the ring to empty. In the
4026 * latter case we have to recopy.
4028 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4033 eop = nextout = ri->ri_nextout;
4037 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4039 * Reclaim some dma maps from if we are out.
4041 if (sc->tulip_txmaps_free == 0) {
4042 #if defined(TULIP_DEBUG)
4043 sc->tulip_dbg.dbg_no_txmaps++;
4045 free += tulip_tx_intr(sc);
4047 if (sc->tulip_txmaps_free > 0) {
4048 map = sc->tulip_txmaps[sc->tulip_txmaps_free-1];
4050 sc->tulip_flags |= TULIP_WANTTXSTART;
4051 #if defined(TULIP_DEBUG)
4052 sc->tulip_dbg.dbg_txput_finishes[1]++;
4056 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4058 if (error == EFBIG) {
4060 * The packet exceeds the number of transmit buffer
4061 * entries that we can use for one packet, so we have
4062 * to recopy it into one mbuf and then try again.
4064 m = tulip_mbuf_compress(m);
4066 #if defined(TULIP_DEBUG)
4067 sc->tulip_dbg.dbg_txput_finishes[2]++;
4071 error = bus_dmamap_load_mbuf(sc->tulip_dmatag, map, m, BUS_DMA_NOWAIT);
4074 printf("%s%d: unable to load tx map, "
4075 "error = %d\n", sc->tulip_name, sc->tulip_unit, error);
4076 #if defined(TULIP_DEBUG)
4077 sc->tulip_dbg.dbg_txput_finishes[3]++;
4082 if ((free -= (map->dm_nsegs + 1) / 2) <= 0
4084 * See if there's any unclaimed space in the transmit ring.
4086 && (free += tulip_tx_intr(sc)) <= 0) {
4088 * There's no more room but since nothing
4089 * has been committed at this point, just
4090 * show output is active, put back the
4093 sc->tulip_flags |= TULIP_WANTTXSTART;
4094 #if defined(TULIP_DEBUG)
4095 sc->tulip_dbg.dbg_txput_finishes[4]++;
4097 bus_dmamap_unload(sc->tulip_dmatag, map);
4100 for (; map->dm_nsegs - segcnt > 1; segcnt += 2) {
4102 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4103 eop->d_status = d_status;
4104 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4105 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4106 eop->d_addr2 = map->dm_segs[segcnt+1].ds_addr;
4107 eop->d_length2 = map->dm_segs[segcnt+1].ds_len;
4108 d_status = TULIP_DSTS_OWNER;
4109 if (++nextout == ri->ri_last)
4110 nextout = ri->ri_first;
4112 if (segcnt < map->dm_nsegs) {
4114 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4115 eop->d_status = d_status;
4116 eop->d_addr1 = map->dm_segs[segcnt].ds_addr;
4117 eop->d_length1 = map->dm_segs[segcnt].ds_len;
4120 if (++nextout == ri->ri_last)
4121 nextout = ri->ri_first;
4123 TULIP_TXMAP_PRESYNC(sc, map);
4126 --sc->tulip_txmaps_free; /* commit to using the dmamap */
4128 #else /* !TULIP_BUS_DMA */
4131 int len = m0->m_len;
4132 caddr_t addr = mtod(m0, caddr_t);
4133 unsigned clsize = PAGE_SIZE - (((uintptr_t) addr) & (PAGE_SIZE-1));
4136 unsigned slen = min(len, clsize);
4140 slen = 2040, partial = 1;
4143 if (segcnt > TULIP_MAX_TXSEG) {
4145 * The packet exceeds the number of transmit buffer
4146 * entries that we can use for one packet, so we have
4147 * recopy it into one mbuf and then try again.
4149 m = tulip_mbuf_compress(m);
4157 * See if there's any unclaimed space in the
4160 if ((free += tulip_tx_intr(sc)) == 0) {
4162 * There's no more room but since nothing
4163 * has been committed at this point, just
4164 * show output is active, put back the
4167 sc->tulip_flags |= TULIP_WANTTXSTART;
4168 #if defined(TULIP_DEBUG)
4169 sc->tulip_dbg.dbg_txput_finishes[1]++;
4175 if (++nextout == ri->ri_last)
4176 nextout = ri->ri_first;
4177 eop->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4178 eop->d_status = d_status;
4179 eop->d_addr1 = TULIP_KVATOPHYS(sc, addr);
4180 eop->d_length1 = slen;
4183 * Fill in second half of descriptor
4185 eop->d_addr2 = TULIP_KVATOPHYS(sc, addr);
4186 eop->d_length2 = slen;
4188 d_status = TULIP_DSTS_OWNER;
4197 } while ((m0 = m0->m_next) != NULL);
4198 #endif /* TULIP_BUS_DMA */
4200 BPF_MTAP(&sc->tulip_if, m);
4203 * The descriptors have been filled in. Now get ready
4206 IF_ENQUEUE(&sc->tulip_txq, m);
4210 * Make sure the next descriptor after this packet is owned
4211 * by us since it may have been set up above if we ran out
4212 * of room in the ring.
4214 nextout->d_status = 0;
4215 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4217 #if !defined(TULIP_BUS_DMA) || defined(TULIP_BUS_DMA_NOTX)
4219 * If we only used the first segment of the last descriptor,
4220 * make sure the second segment will not be used.
4226 #endif /* TULIP_BUS_DMA */
4229 * Mark the last and first segments, indicate we want a transmit
4230 * complete interrupt, and tell it to transmit!
4232 eop->d_flag |= TULIP_DFLAG_TxLASTSEG|TULIP_DFLAG_TxWANTINTR;
4235 * Note that ri->ri_nextout is still the start of the packet
4236 * and until we set the OWNER bit, we can still back out of
4237 * everything we have done.
4239 ri->ri_nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG;
4240 #if defined(TULIP_BUS_MAP) && !defined(TULIP_BUS_DMA_NOTX)
4241 if (eop < ri->ri_nextout) {
4242 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4243 (caddr_t) ri->ri_last - (caddr_t) ri->ri_nextout);
4244 TULIP_TXDESC_PRESYNC(sc, ri->ri_first,
4245 (caddr_t) (eop + 1) - (caddr_t) ri->ri_first);
4247 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout,
4248 (caddr_t) (eop + 1) - (caddr_t) ri->ri_nextout);
4251 ri->ri_nextout->d_status = TULIP_DSTS_OWNER;
4252 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4255 * This advances the ring for us.
4257 ri->ri_nextout = nextout;
4260 TULIP_PERFEND(txput);
4262 if (sc->tulip_flags & TULIP_TXPROBE_ACTIVE) {
4263 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4264 sc->tulip_if.if_flags |= IFF_OACTIVE;
4265 sc->tulip_if.if_start = tulip_ifstart;
4266 TULIP_PERFEND(txput);
4271 * switch back to the single queueing ifstart.
4273 sc->tulip_flags &= ~TULIP_WANTTXSTART;
4274 if (sc->tulip_txtimer == 0)
4275 sc->tulip_txtimer = TULIP_TXTIMER;
4276 #if defined(TULIP_DEBUG)
4277 sc->tulip_dbg.dbg_txput_finishes[5]++;
4281 * If we want a txstart, there must be not enough space in the
4282 * transmit ring. So we want to enable transmit done interrupts
4283 * so we can immediately reclaim some space. When the transmit
4284 * interrupt is posted, the interrupt handler will call tx_intr
4285 * to reclaim space and then txstart (since WANTTXSTART is set).
4286 * txstart will move the packet into the transmit ring and clear
4287 * WANTTXSTART thereby causing TXINTR to be cleared.
4290 #if defined(TULIP_DEBUG)
4291 sc->tulip_dbg.dbg_txput_finishes[6]++;
4293 if (sc->tulip_flags & (TULIP_WANTTXSTART|TULIP_DOINGSETUP)) {
4294 sc->tulip_if.if_flags |= IFF_OACTIVE;
4295 sc->tulip_if.if_start = tulip_ifstart;
4296 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4297 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4298 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4300 } else if ((sc->tulip_flags & TULIP_PROMISC) == 0) {
4301 if (sc->tulip_intrmask & TULIP_STS_TXINTR) {
4302 sc->tulip_intrmask &= ~TULIP_STS_TXINTR;
4303 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4306 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4307 TULIP_PERFEND(txput);
4313 tulip_softc_t * const sc)
4315 tulip_ringinfo_t * const ri = &sc->tulip_txinfo;
4316 tulip_desc_t *nextout;
4319 * We will transmit, at most, one setup packet per call to ifstart.
4322 #if defined(TULIP_DEBUG)
4323 if ((sc->tulip_cmdmode & TULIP_CMD_TXRUN) == 0) {
4324 printf("%s%d: txput_setup: tx not running\n",
4325 sc->tulip_name, sc->tulip_unit);
4326 sc->tulip_flags |= TULIP_WANTTXSTART;
4327 sc->tulip_if.if_start = tulip_ifstart;
4332 * Try to reclaim some free descriptors..
4334 if (ri->ri_free < 2)
4336 if ((sc->tulip_flags & TULIP_DOINGSETUP) || ri->ri_free == 1) {
4337 sc->tulip_flags |= TULIP_WANTTXSTART;
4338 sc->tulip_if.if_start = tulip_ifstart;
4341 bcopy(sc->tulip_setupdata, sc->tulip_setupbuf,
4342 sizeof(sc->tulip_setupbuf));
4344 * Clear WANTSETUP and set DOINGSETUP. Set know that WANTSETUP is
4345 * set and DOINGSETUP is clear doing an XOR of the two will DTRT.
4347 sc->tulip_flags ^= TULIP_WANTSETUP|TULIP_DOINGSETUP;
4349 nextout = ri->ri_nextout;
4350 nextout->d_flag &= TULIP_DFLAG_ENDRING|TULIP_DFLAG_CHAIN;
4351 nextout->d_flag |= TULIP_DFLAG_TxFIRSTSEG|TULIP_DFLAG_TxLASTSEG
4352 |TULIP_DFLAG_TxSETUPPKT|TULIP_DFLAG_TxWANTINTR;
4353 if (sc->tulip_flags & TULIP_WANTHASHPERFECT)
4354 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT;
4355 else if (sc->tulip_flags & TULIP_WANTHASHONLY)
4356 nextout->d_flag |= TULIP_DFLAG_TxHASHFILT|TULIP_DFLAG_TxINVRSFILT;
4358 nextout->d_length2 = 0;
4359 nextout->d_addr2 = 0;
4360 #if defined(TULIP_BUS_DMA) && !defined(TULIP_BUS_DMA_NOTX)
4361 nextout->d_length1 = sc->tulip_setupmap->dm_segs[0].ds_len;
4362 nextout->d_addr1 = sc->tulip_setupmap->dm_segs[0].ds_addr;
4363 if (sc->tulip_setupmap->dm_nsegs == 2) {
4364 nextout->d_length2 = sc->tulip_setupmap->dm_segs[1].ds_len;
4365 nextout->d_addr2 = sc->tulip_setupmap->dm_segs[1].ds_addr;
4367 TULIP_TXMAP_PRESYNC(sc, sc->tulip_setupmap);
4368 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(*nextout));
4370 nextout->d_length1 = sizeof(sc->tulip_setupbuf);
4371 nextout->d_addr1 = TULIP_KVATOPHYS(sc, sc->tulip_setupbuf);
4375 * Advance the ring for the next transmit packet.
4377 if (++ri->ri_nextout == ri->ri_last)
4378 ri->ri_nextout = ri->ri_first;
4381 * Make sure the next descriptor is owned by us since it
4382 * may have been set up above if we ran out of room in the
4385 ri->ri_nextout->d_status = 0;
4386 TULIP_TXDESC_PRESYNC(sc, ri->ri_nextout, sizeof(u_int32_t));
4387 nextout->d_status = TULIP_DSTS_OWNER;
4389 * Flush the ownwership of the current descriptor
4391 TULIP_TXDESC_PRESYNC(sc, nextout, sizeof(u_int32_t));
4392 TULIP_CSR_WRITE(sc, csr_txpoll, 1);
4393 if ((sc->tulip_intrmask & TULIP_STS_TXINTR) == 0) {
4394 sc->tulip_intrmask |= TULIP_STS_TXINTR;
4395 TULIP_CSR_WRITE(sc, csr_intr, sc->tulip_intrmask);
4407 TULIP_PERFSTART(ifioctl)
4408 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4409 struct ifaddr *ifa = (struct ifaddr *)data;
4410 struct ifreq *ifr = (struct ifreq *) data;
4417 ifp->if_flags |= IFF_UP;
4418 switch(ifa->ifa_addr->sa_family) {
4422 arp_ifinit(&(sc)->tulip_ac.ac_if, ifa);
4429 struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr);
4430 if (ipx_nullhost(*ina)) {
4431 ina->x_host = *(union ipx_host *)(sc->tulip_enaddr);
4433 ifp->if_flags &= ~IFF_RUNNING;
4434 bcopy((caddr_t)ina->x_host.c_host,
4435 (caddr_t)sc->tulip_enaddr,
4436 sizeof(sc->tulip_enaddr));
4445 * This magic copied from if_is.c; I don't use XNS,
4446 * so I have no way of telling if this actually
4450 struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
4451 if (ns_nullhost(*ina)) {
4452 ina->x_host = *(union ns_host *)(sc->tulip_enaddr);
4454 ifp->if_flags &= ~IFF_RUNNING;
4455 bcopy((caddr_t)ina->x_host.c_host,
4456 (caddr_t)sc->tulip_enaddr,
4457 sizeof(sc->tulip_enaddr));
4472 bcopy((caddr_t) sc->tulip_enaddr,
4473 (caddr_t) ((struct sockaddr *)&ifr->ifr_data)->sa_data,
4478 case SIOCSIFFLAGS: {
4479 tulip_addr_filter(sc); /* reinit multicast filter */
4485 case SIOCGIFMEDIA: {
4486 error = ifmedia_ioctl(ifp, ifr, &sc->tulip_ifmedia, cmd);
4491 case SIOCDELMULTI: {
4493 * Update multicast listeners
4495 tulip_addr_filter(sc); /* reset multicast filtering */
4503 * Set the interface MTU.
4505 if (ifr->ifr_mtu > ETHERMTU
4507 && sc->tulip_chipid != TULIP_21140
4508 && sc->tulip_chipid != TULIP_21140A
4509 && sc->tulip_chipid != TULIP_21041
4515 ifp->if_mtu = ifr->ifr_mtu;
4523 case SIOCGADDRROM: {
4524 error = copyout(sc->tulip_rombuf, ifr->ifr_data, sizeof(sc->tulip_rombuf));
4530 ifr->ifr_metric = (int) sc->tulip_chipid;
4541 TULIP_PERFEND(ifioctl);
4547 struct ifnet * const ifp)
4549 TULIP_PERFSTART(ifstart)
4550 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4552 if (sc->tulip_if.if_flags & IFF_RUNNING) {
4554 if ((sc->tulip_flags & (TULIP_WANTSETUP|TULIP_TXPROBE_ACTIVE)) == TULIP_WANTSETUP)
4555 tulip_txput_setup(sc);
4557 while (sc->tulip_if.if_snd.ifq_head != NULL) {
4559 IF_DEQUEUE(&sc->tulip_if.if_snd, m);
4560 if ((m = tulip_txput(sc, m)) != NULL) {
4561 IF_PREPEND(&sc->tulip_if.if_snd, m);
4567 TULIP_PERFEND(ifstart);
4574 TULIP_PERFSTART(ifwatchdog)
4575 tulip_softc_t * const sc = (tulip_softc_t *)ifp->if_softc;
4577 #if defined(TULIP_DEBUG)
4578 u_int32_t rxintrs = sc->tulip_dbg.dbg_rxintrs - sc->tulip_dbg.dbg_last_rxintrs;
4579 if (rxintrs > sc->tulip_dbg.dbg_high_rxintrs_hz)
4580 sc->tulip_dbg.dbg_high_rxintrs_hz = rxintrs;
4581 sc->tulip_dbg.dbg_last_rxintrs = sc->tulip_dbg.dbg_rxintrs;
4582 #endif /* TULIP_DEBUG */
4584 sc->tulip_if.if_timer = 1;
4586 * These should be rare so do a bulk test up front so we can just skip
4589 if (sc->tulip_flags & (TULIP_SYSTEMERROR|TULIP_RXBUFSLOW|TULIP_NOMESSAGES)) {
4591 * If the number of receive buffer is low, try to refill
4593 if (sc->tulip_flags & TULIP_RXBUFSLOW)
4596 if (sc->tulip_flags & TULIP_SYSTEMERROR) {
4597 printf("%s%d: %d system errors: last was %s\n",
4598 sc->tulip_name, sc->tulip_unit, sc->tulip_system_errors,
4599 tulip_system_errors[sc->tulip_last_system_error]);
4601 if (sc->tulip_statusbits) {
4602 tulip_print_abnormal_interrupt(sc, sc->tulip_statusbits);
4603 sc->tulip_statusbits = 0;
4606 sc->tulip_flags &= ~(TULIP_NOMESSAGES|TULIP_SYSTEMERROR);
4609 if (sc->tulip_txtimer)
4611 if (sc->tulip_txtimer && --sc->tulip_txtimer == 0) {
4612 printf("%s%d: transmission timeout\n", sc->tulip_name, sc->tulip_unit);
4613 if (TULIP_DO_AUTOSENSE(sc)) {
4614 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4615 sc->tulip_probe_state = TULIP_PROBE_INACTIVE;
4616 sc->tulip_flags &= ~(TULIP_WANTRXACT|TULIP_LINKUP);
4622 TULIP_PERFEND(ifwatchdog);
4623 TULIP_PERFMERGE(sc, perf_intr_cycles);
4624 TULIP_PERFMERGE(sc, perf_ifstart_cycles);
4625 TULIP_PERFMERGE(sc, perf_ifioctl_cycles);
4626 TULIP_PERFMERGE(sc, perf_ifwatchdog_cycles);
4627 TULIP_PERFMERGE(sc, perf_timeout_cycles);
4628 TULIP_PERFMERGE(sc, perf_ifstart_one_cycles);
4629 TULIP_PERFMERGE(sc, perf_txput_cycles);
4630 TULIP_PERFMERGE(sc, perf_txintr_cycles);
4631 TULIP_PERFMERGE(sc, perf_rxintr_cycles);
4632 TULIP_PERFMERGE(sc, perf_rxget_cycles);
4633 TULIP_PERFMERGE(sc, perf_intr);
4634 TULIP_PERFMERGE(sc, perf_ifstart);
4635 TULIP_PERFMERGE(sc, perf_ifioctl);
4636 TULIP_PERFMERGE(sc, perf_ifwatchdog);
4637 TULIP_PERFMERGE(sc, perf_timeout);
4638 TULIP_PERFMERGE(sc, perf_ifstart_one);
4639 TULIP_PERFMERGE(sc, perf_txput);
4640 TULIP_PERFMERGE(sc, perf_txintr);
4641 TULIP_PERFMERGE(sc, perf_rxintr);
4642 TULIP_PERFMERGE(sc, perf_rxget);
4646 * All printf's are real as of now!
4654 tulip_softc_t * const sc)
4656 struct ifnet * const ifp = &sc->tulip_if;
4658 callout_init(&sc->tulip_timer);
4659 callout_init(&sc->tulip_fast_timer);
4661 if_initname(ifp, sc->tulip_name, sc->tulip_unit);
4662 ifp->if_flags = IFF_BROADCAST|IFF_SIMPLEX|IFF_MULTICAST;
4663 ifp->if_ioctl = tulip_ifioctl;
4664 ifp->if_start = tulip_ifstart;
4665 ifp->if_watchdog = tulip_ifwatchdog;
4668 printf("%s%d: %s%s pass %d.%d%s\n",
4669 sc->tulip_name, sc->tulip_unit,
4671 tulip_chipdescs[sc->tulip_chipid],
4672 (sc->tulip_revinfo & 0xF0) >> 4,
4673 sc->tulip_revinfo & 0x0F,
4674 (sc->tulip_features & (TULIP_HAVE_ISVSROM|TULIP_HAVE_OKSROM))
4675 == TULIP_HAVE_ISVSROM ? " (invalid EESPROM checksum)" : "");
4677 #if defined(__alpha__)
4679 * In case the SRM console told us about a bogus media,
4680 * we need to check to be safe.
4682 if (sc->tulip_mediums[sc->tulip_media] == NULL)
4683 sc->tulip_media = TULIP_MEDIA_UNKNOWN;
4686 (*sc->tulip_boardsw->bd_media_probe)(sc);
4687 ifmedia_init(&sc->tulip_ifmedia, 0,
4688 tulip_ifmedia_change,
4689 tulip_ifmedia_status);
4690 sc->tulip_flags &= ~TULIP_DEVICEPROBE;
4691 tulip_ifmedia_add(sc);
4695 ether_ifattach(&(sc)->tulip_if, sc->tulip_enaddr);
4696 ifp->if_snd.ifq_maxlen = ifqmaxlen;
4699 #if defined(TULIP_BUS_DMA)
4700 #if !defined(TULIP_BUS_DMA_NOTX) || !defined(TULIP_BUS_DMA_NORX)
4702 tulip_busdma_allocmem(
4703 tulip_softc_t * const sc,
4705 bus_dmamap_t *map_p,
4706 tulip_desc_t **desc_p)
4708 bus_dma_segment_t segs[1];
4710 error = bus_dmamem_alloc(sc->tulip_dmatag, size, 1, PAGE_SIZE,
4711 segs, sizeof(segs)/sizeof(segs[0]),
4712 &nsegs, BUS_DMA_NOWAIT);
4715 error = bus_dmamem_map(sc->tulip_dmatag, segs, nsegs, size,
4716 (void *) &desc, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
4719 error = bus_dmamap_create(sc->tulip_dmatag, size, 1, size, 0,
4720 BUS_DMA_NOWAIT, &map);
4722 error = bus_dmamap_load(sc->tulip_dmatag, map, desc,
4723 size, NULL, BUS_DMA_NOWAIT);
4725 bus_dmamap_destroy(sc->tulip_dmatag, map);
4730 bus_dmamem_unmap(sc->tulip_dmatag, desc, size);
4733 bus_dmamem_free(sc->tulip_dmatag, segs, nsegs);
4743 tulip_softc_t * const sc)
4747 #if !defined(TULIP_BUS_DMA_NOTX)
4749 * Allocate dmamap for setup descriptor
4751 error = bus_dmamap_create(sc->tulip_dmatag, sizeof(sc->tulip_setupbuf), 2,
4752 sizeof(sc->tulip_setupbuf), 0, BUS_DMA_NOWAIT,
4753 &sc->tulip_setupmap);
4755 error = bus_dmamap_load(sc->tulip_dmatag, sc->tulip_setupmap,
4756 sc->tulip_setupbuf, sizeof(sc->tulip_setupbuf),
4757 NULL, BUS_DMA_NOWAIT);
4759 bus_dmamap_destroy(sc->tulip_dmatag, sc->tulip_setupmap);
4762 * Allocate space and dmamap for transmit ring
4765 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_TXDESCS,
4766 &sc->tulip_txdescmap,
4767 &sc->tulip_txdescs);
4771 * Allocate dmamaps for each transmit descriptors
4774 while (error == 0 && sc->tulip_txmaps_free < TULIP_TXDESCS) {
4776 if ((error = TULIP_TXMAP_CREATE(sc, &map)) == 0)
4777 sc->tulip_txmaps[sc->tulip_txmaps_free++] = map;
4780 while (sc->tulip_txmaps_free > 0)
4781 bus_dmamap_destroy(sc->tulip_dmatag,
4782 sc->tulip_txmaps[--sc->tulip_txmaps_free]);
4787 sc->tulip_txdescs = malloc(TULIP_TXDESCS * sizeof(tulip_desc_t),
4788 M_DEVBUF, M_INTWAIT);
4791 #if !defined(TULIP_BUS_DMA_NORX)
4793 * Allocate space and dmamap for receive ring
4796 error = tulip_busdma_allocmem(sc, sizeof(tulip_desc_t) * TULIP_RXDESCS,
4797 &sc->tulip_rxdescmap,
4798 &sc->tulip_rxdescs);
4802 * Allocate dmamaps for each receive descriptors
4805 while (error == 0 && sc->tulip_rxmaps_free < TULIP_RXDESCS) {
4807 if ((error = TULIP_RXMAP_CREATE(sc, &map)) == 0)
4808 sc->tulip_rxmaps[sc->tulip_rxmaps_free++] = map;
4811 while (sc->tulip_rxmaps_free > 0)
4812 bus_dmamap_destroy(sc->tulip_dmatag,
4813 sc->tulip_rxmaps[--sc->tulip_rxmaps_free]);
4818 sc->tulip_rxdescs = malloc(TULIP_RXDESCS * sizeof(tulip_desc_t),
4819 M_DEVBUF, M_INTWAIT);
4824 #endif /* TULIP_BUS_DMA */
4828 tulip_softc_t * const sc,
4829 tulip_csrptr_t csr_base,
4832 sc->tulip_csrs.csr_busmode = csr_base + 0 * csr_size;
4833 sc->tulip_csrs.csr_txpoll = csr_base + 1 * csr_size;
4834 sc->tulip_csrs.csr_rxpoll = csr_base + 2 * csr_size;
4835 sc->tulip_csrs.csr_rxlist = csr_base + 3 * csr_size;
4836 sc->tulip_csrs.csr_txlist = csr_base + 4 * csr_size;
4837 sc->tulip_csrs.csr_status = csr_base + 5 * csr_size;
4838 sc->tulip_csrs.csr_command = csr_base + 6 * csr_size;
4839 sc->tulip_csrs.csr_intr = csr_base + 7 * csr_size;
4840 sc->tulip_csrs.csr_missed_frames = csr_base + 8 * csr_size;
4841 sc->tulip_csrs.csr_9 = csr_base + 9 * csr_size;
4842 sc->tulip_csrs.csr_10 = csr_base + 10 * csr_size;
4843 sc->tulip_csrs.csr_11 = csr_base + 11 * csr_size;
4844 sc->tulip_csrs.csr_12 = csr_base + 12 * csr_size;
4845 sc->tulip_csrs.csr_13 = csr_base + 13 * csr_size;
4846 sc->tulip_csrs.csr_14 = csr_base + 14 * csr_size;
4847 sc->tulip_csrs.csr_15 = csr_base + 15 * csr_size;
4852 tulip_softc_t * const sc,
4853 tulip_ringinfo_t * const ri,
4854 tulip_desc_t *descs,
4857 ri->ri_max = ndescs;
4858 ri->ri_first = descs;
4859 ri->ri_last = ri->ri_first + ri->ri_max;
4860 bzero((caddr_t) ri->ri_first, sizeof(ri->ri_first[0]) * ri->ri_max);
4861 ri->ri_last[-1].d_flag = TULIP_DFLAG_ENDRING;
4865 * This is the PCI configuration support.
4868 #define PCI_CBIO 0x10 /* Configuration Base IO Address */
4869 #define PCI_CBMA 0x14 /* Configuration Base Memory Address */
4870 #define PCI_CFDA 0x40 /* Configuration Driver Area */
4873 tulip_pci_probe(device_t dev)
4875 const char *name = NULL;
4877 if (pci_get_vendor(dev) != DEC_VENDORID)
4881 * Some LanMedia WAN cards use the Tulip chip, but they have
4882 * their own driver, and we should not recognize them
4884 if (pci_get_subvendor(dev) == 0x1376)
4887 switch (pci_get_device(dev)) {
4889 name = "Digital 21040 Ethernet";
4892 name = "Digital 21041 Ethernet";
4895 if (pci_get_revid(dev) >= 0x20)
4896 name = "Digital 21140A Fast Ethernet";
4898 name = "Digital 21140 Fast Ethernet";
4901 if (pci_get_revid(dev) >= 0x20)
4902 name = "Digital 21143 Fast Ethernet";
4904 name = "Digital 21142 Fast Ethernet";
4908 device_set_desc(dev, name);
4915 tulip_shutdown(device_t dev)
4917 tulip_softc_t * const sc = device_get_softc(dev);
4918 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
4919 DELAY(10); /* Wait 10 microseconds (actually 50 PCI cycles but at
4920 33MHz that comes to two microseconds but wait a
4921 bit longer anyways) */
4926 tulip_pci_attach(device_t dev)
4929 #if defined(__alpha__)
4930 tulip_media_t media = TULIP_MEDIA_UNKNOWN;
4933 u_int32_t revinfo, cfdainfo, cfcsinfo;
4934 unsigned csroffset = TULIP_PCI_CSROFFSET;
4935 unsigned csrsize = TULIP_PCI_CSRSIZE;
4936 tulip_csrptr_t csr_base;
4937 tulip_chipid_t chipid = TULIP_CHIPID_UNKNOWN;
4938 struct resource *res;
4941 unit = device_get_unit(dev);
4943 if (unit >= TULIP_MAX_DEVICES) {
4944 printf("de%d", unit);
4945 printf(": not configured; limit of %d reached or exceeded\n",
4950 revinfo = pci_get_revid(dev);
4951 cfdainfo = pci_read_config(dev, PCI_CFDA, 4);
4952 cfcsinfo = pci_read_config(dev, PCIR_COMMAND, 4);
4954 /* turn busmaster on in case BIOS doesn't set it */
4955 if(!(cfcsinfo & PCIM_CMD_BUSMASTEREN)) {
4956 cfcsinfo |= PCIM_CMD_BUSMASTEREN;
4957 pci_write_config(dev, PCIR_COMMAND, cfcsinfo, 4);
4960 if (pci_get_vendor(dev) == DEC_VENDORID) {
4961 if (pci_get_device(dev) == CHIPID_21040)
4962 chipid = TULIP_21040;
4963 else if (pci_get_device(dev) == CHIPID_21041)
4964 chipid = TULIP_21041;
4965 else if (pci_get_device(dev) == CHIPID_21140)
4966 chipid = (revinfo >= 0x20) ? TULIP_21140A : TULIP_21140;
4967 else if (pci_get_device(dev) == CHIPID_21142)
4968 chipid = (revinfo >= 0x20) ? TULIP_21143 : TULIP_21142;
4970 if (chipid == TULIP_CHIPID_UNKNOWN)
4973 if (chipid == TULIP_21040 && revinfo < 0x20) {
4974 printf("de%d", unit);
4975 printf(": not configured; 21040 pass 2.0 required (%d.%d found)\n",
4976 revinfo >> 4, revinfo & 0x0f);
4978 } else if (chipid == TULIP_21140 && revinfo < 0x11) {
4979 printf("de%d: not configured; 21140 pass 1.1 required (%d.%d found)\n",
4980 unit, revinfo >> 4, revinfo & 0x0f);
4984 sc = device_get_softc(dev);
4985 sc->tulip_pci_busno = pci_get_bus(dev);
4986 sc->tulip_pci_devno = pci_get_slot(dev);
4987 sc->tulip_chipid = chipid;
4988 sc->tulip_flags |= TULIP_DEVICEPROBE;
4989 if (chipid == TULIP_21140 || chipid == TULIP_21140A)
4990 sc->tulip_features |= TULIP_HAVE_GPR|TULIP_HAVE_STOREFWD;
4991 if (chipid == TULIP_21140A && revinfo <= 0x22)
4992 sc->tulip_features |= TULIP_HAVE_RXBADOVRFLW;
4993 if (chipid == TULIP_21140)
4994 sc->tulip_features |= TULIP_HAVE_BROKEN_HASH;
4995 if (chipid != TULIP_21040 && chipid != TULIP_21140)
4996 sc->tulip_features |= TULIP_HAVE_POWERMGMT;
4997 if (chipid == TULIP_21041 || chipid == TULIP_21142 || chipid == TULIP_21143) {
4998 sc->tulip_features |= TULIP_HAVE_DUALSENSE;
4999 if (chipid != TULIP_21041 || revinfo >= 0x20)
5000 sc->tulip_features |= TULIP_HAVE_SIANWAY;
5001 if (chipid != TULIP_21041)
5002 sc->tulip_features |= TULIP_HAVE_SIAGP|TULIP_HAVE_RXBADOVRFLW|TULIP_HAVE_STOREFWD;
5003 if (chipid != TULIP_21041 && revinfo >= 0x20)
5004 sc->tulip_features |= TULIP_HAVE_SIA100;
5007 if (sc->tulip_features & TULIP_HAVE_POWERMGMT
5008 && (cfdainfo & (TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE))) {
5009 cfdainfo &= ~(TULIP_CFDA_SLEEP|TULIP_CFDA_SNOOZE);
5010 pci_write_config(dev, PCI_CFDA, cfdainfo, 4);
5013 #if defined(__alpha__)
5015 * The Alpha SRM console encodes a console set media in the driver
5016 * part of the CFDA register. Note that the Multia presents a
5017 * problem in that its BNC mode is really EXTSIA. So in that case
5020 switch ((cfdainfo >> 8) & 0xff) {
5021 case 1: media = chipid > TULIP_21040 ? TULIP_MEDIA_AUI : TULIP_MEDIA_AUIBNC; break;
5022 case 2: media = chipid > TULIP_21040 ? TULIP_MEDIA_BNC : TULIP_MEDIA_UNKNOWN; break;
5023 case 3: media = TULIP_MEDIA_10BASET; break;
5024 case 4: media = TULIP_MEDIA_10BASET_FD; break;
5025 case 5: media = TULIP_MEDIA_100BASETX; break;
5026 case 6: media = TULIP_MEDIA_100BASETX_FD; break;
5027 default: media = TULIP_MEDIA_UNKNOWN; break;
5031 sc->tulip_unit = unit;
5032 sc->tulip_name = "de";
5033 sc->tulip_revinfo = revinfo;
5034 sc->tulip_if.if_softc = sc;
5035 #if defined(TULIP_IOMAPPED)
5037 res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
5038 0, ~0, 1, RF_ACTIVE);
5041 res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
5042 0, ~0, 1, RF_ACTIVE);
5046 sc->tulip_csrs_bst = rman_get_bustag(res);
5047 sc->tulip_csrs_bsh = rman_get_bushandle(res);
5052 tulip_initcsrs(sc, csr_base + csroffset, csrsize);
5054 #if defined(TULIP_BUS_DMA)
5055 if ((retval = tulip_busdma_init(sc)) != 0) {
5056 printf("error initing bus_dma: %d\n", retval);
5060 sc->tulip_rxdescs = malloc(sizeof(tulip_desc_t) * TULIP_RXDESCS,
5061 M_DEVBUF, M_INTWAIT);
5062 sc->tulip_txdescs = malloc(sizeof(tulip_desc_t) * TULIP_TXDESCS,
5063 M_DEVBUF, M_INTWAIT);
5066 tulip_initring(sc, &sc->tulip_rxinfo, sc->tulip_rxdescs, TULIP_RXDESCS);
5067 tulip_initring(sc, &sc->tulip_txinfo, sc->tulip_txdescs, TULIP_TXDESCS);
5070 * Make sure there won't be any interrupts or such...
5072 TULIP_CSR_WRITE(sc, csr_busmode, TULIP_BUSMODE_SWRESET);
5073 DELAY(100); /* Wait 10 microseconds (actually 50 PCI cycles but at
5074 33MHz that comes to two microseconds but wait a
5075 bit longer anyways) */
5077 if ((retval = tulip_read_macaddr(sc)) < 0) {
5078 printf("%s%d", sc->tulip_name, sc->tulip_unit);
5079 printf(": can't read ENET ROM (why=%d) (", retval);
5080 for (idx = 0; idx < 32; idx++)
5081 printf("%02x", sc->tulip_rombuf[idx]);
5083 printf("%s%d: %s%s pass %d.%d\n",
5084 sc->tulip_name, sc->tulip_unit,
5085 sc->tulip_boardid, tulip_chipdescs[sc->tulip_chipid],
5086 (sc->tulip_revinfo & 0xF0) >> 4, sc->tulip_revinfo & 0x0F);
5087 printf("%s%d: address unknown\n", sc->tulip_name, sc->tulip_unit);
5090 void (*intr_rtn)(void *) = tulip_intr_normal;
5092 if (sc->tulip_features & TULIP_HAVE_SHAREDINTR)
5093 intr_rtn = tulip_intr_shared;
5095 if ((sc->tulip_features & TULIP_HAVE_SLAVEDINTR) == 0) {
5099 res = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
5100 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
5101 if (res == 0 || bus_setup_intr(dev, res, INTR_TYPE_NET,
5102 intr_rtn, sc, &ih)) {
5103 printf("%s%d: couldn't map interrupt\n",
5104 sc->tulip_name, sc->tulip_unit);
5105 free((caddr_t) sc->tulip_rxdescs, M_DEVBUF);
5106 free((caddr_t) sc->tulip_txdescs, M_DEVBUF);
5112 #if defined(__alpha__)
5113 sc->tulip_media = media;
5116 #if defined(__alpha__)
5117 if (sc->tulip_media != TULIP_MEDIA_UNKNOWN)
5118 tulip_linkup(sc, media);
5125 static device_method_t tulip_pci_methods[] = {
5126 /* Device interface */
5127 DEVMETHOD(device_probe, tulip_pci_probe),
5128 DEVMETHOD(device_attach, tulip_pci_attach),
5129 DEVMETHOD(device_shutdown, tulip_shutdown),
5132 static driver_t tulip_pci_driver = {
5135 sizeof(tulip_softc_t),
5137 static devclass_t tulip_devclass;
5139 DECLARE_DUMMY_MODULE(if_de);
5140 DRIVER_MODULE(if_de, pci, tulip_pci_driver, tulip_devclass, 0, 0);